@SuppressWarnings("unchecked") private String checkForUniqueExternalMappings( EventExternalEventMappingVoCollection externalMappings) { ArrayList<String> names = new ArrayList<String>(); ArrayList<Serializable> values = new ArrayList<Serializable>(); DomainFactory factory = getDomainFactory(); StringBuffer ids = new StringBuffer(); StringBuffer exclude = new StringBuffer(); exclude.append(externalMappings.get(0).getEvent().getID_Event()); String errors = new String(); for (int i = 0; i < externalMappings.size(); i++) { if (externalMappings.get(i).getStatus().equals(PreActiveActiveInactiveStatus.ACTIVE)) { if (i > 0 && i < externalMappings.size()) { ids.append(" , "); } ids.append(externalMappings.get(i).getExternalEventMapping().getID_ExternalEventMapping()); } } if (ids.length() == 0) return null; names.add("id_status"); values.add(PreActiveActiveInactiveStatus.ACTIVE.getID()); List eventsMappings = factory.find( "select ext.event.id, ext.externalEventMapping.id, event.id, event.name, event.status, event.status.id, external.id, external.group, external.detail, external.specialty, mosname.name.surname, mosname.name.forename, external.clinicCode, provider.systemName from EventExternalEventMapping as ext left join ext.event as event left join ext.externalEventMapping as external left join external.consultant as consult left join consult.mos as mosname left join external.providerSystem as provider where ext.externalEventMapping.id in (" + ids + ") and event.id <> " + exclude + " and event.status.id = :id_status ", names, values); Iterator eventsMappingsList = eventsMappings.iterator(); while (eventsMappingsList.hasNext()) { Object[] obj = (Object[]) eventsMappingsList.next(); errors += ("External system " + ((String) obj[13]).toUpperCase() + ", " + ((LookupInstance) obj[7]).getText() + ", " + ((LookupInstance) obj[8]).getText() + ", " + ((LookupInstance) obj[9]).getText() + (((String) obj[10]) != null ? ", " + ((String) obj[10]) + " " : "") + (((String) obj[11]) != null ? ((String) obj[11]) + " , " : "") + (((String) obj[12]) != null ? ((String) obj[12]) : "") + " is already linked to event " + ((String) obj[3]).toUpperCase() + "\n"); } return errors; }
private void checkForUniqRecords( EventVo event, EventExternalEventMappingVoCollection externalToBeAdded, EventRTTEventVoCollection rttToBeAdded) throws UniqueKeyViolationException { // Check for UNIQ only for ACTIVE records if (event.getStatusIsNotNull() && event.getStatus().equals(PreActiveActiveInactiveStatus.ACTIVE)) { // Check Event if (checkForUniqEvent(event).size() > 0) throw new UniqueKeyViolationException("Event Name must be unique!"); // Check External Mappings if (externalToBeAdded != null && externalToBeAdded.size() > 0) { String err = checkForUniqueExternalMappings(externalToBeAdded); if (err != null && err.trim().length() > 0) { throw new UniqueKeyViolationException(err); } } // Check RTT Event if (rttToBeAdded != null && rttToBeAdded.size() > 0) { String err = checkForUniqueRTT(rttToBeAdded); if (err != null && err.trim().length() > 0) { throw new UniqueKeyViolationException(err); } } } }
private void saveExternal( EventVo event, EventExternalEventMappingVoCollection externalToBeAdded, EventExternalEventMappingVoCollection externalToBeDeleted, DomainFactory factory, Event domainRecord) throws StaleObjectException, ForeignKeyViolationException { // Save External if (externalToBeAdded != null) { for (int i = 0; i < externalToBeAdded.size(); i++) { EventExternalEventMapping domainExternal = EventExternalEventMappingVoAssembler.extractEventExternalEventMapping( factory, externalToBeAdded.get(i)); domainExternal.setEvent(domainRecord); if (domainExternal.getStatus().equals(getDomLookup(PreActiveActiveInactiveStatus.ACTIVE)) && domainExternal.getActivatedDateTime() == null) { domainExternal.setStatus(getDomLookup(PreActiveActiveInactiveStatus.ACTIVE)); domainExternal.setActivatedBy(getUser()); domainExternal.setActivatedDateTime(new Date()); } else if (domainExternal .getStatus() .equals(getDomLookup(PreActiveActiveInactiveStatus.INACTIVE))) { if (domainExternal.getInactivatedBy() == null) { domainExternal.setInactivatedBy(getUser()); domainExternal.setInactivatedDateTime(new Date()); } } factory.save(domainExternal); } } if (externalToBeDeleted != null) { for (int i = 0; i < externalToBeDeleted.size(); i++) { EventExternalEventMapping domainExternal = EventExternalEventMappingVoAssembler.extractEventExternalEventMapping( factory, externalToBeDeleted.get(i)); factory.delete(domainExternal); } } }