// create a new sub-module, and set its module code, submodule code and description private CoeusSubModule getCorrespondingCoeusSubModule( CoiDisclosureEventType remainingCoiEventType) { CoeusSubModule correspondingSubModule = new CoeusSubModule(); correspondingSubModule.setModuleCode(getCoiCoeusModuleCode()); correspondingSubModule.setSubModuleCode(remainingCoiEventType.getEventTypeCode()); correspondingSubModule.setDescription(remainingCoiEventType.getDescription()); return correspondingSubModule; }
// iterate through the list of disclosure event types and if one if found with a code matching the // given // submodule code then remove it from list and return it, else return null. private CoiDisclosureEventType extractCorrespondingCoiEventType( String subModuleCode, List<CoiDisclosureEventType> currentActiveCoiDisclosureEventTypes) { CoiDisclosureEventType retVal = null; for (CoiDisclosureEventType candidateEventType : currentActiveCoiDisclosureEventTypes) { if (StringUtils.equals(candidateEventType.getEventTypeCode(), subModuleCode)) { retVal = candidateEventType; break; } } currentActiveCoiDisclosureEventTypes.remove(retVal); return retVal; }
/** * @see * org.kuali.kra.coi.maintenance.CoiDisclosureEventTypeToCoeusSubModuleSynchronizerService#synchronizeCoeusSubModulesWithActiveCoiDisclosureEventTypes() */ @Override public void synchronizeCoeusSubModulesWithActiveCoiDisclosureEventTypes() { // get all the current coeus sub-modules for coi module List<CoeusSubModule> currentSubModulesForCoi = getCurrentCoeusSubModulesForCoiModule(); // get all the current active coi disclosure event types List<CoiDisclosureEventType> currentActiveCoiDisclosureEventTypes = getCurrentActiveCoiDisclosureEventTypes(); // iterate through the submodules, compare each to its corresponding event type (if any) and // delete or update the submodule if required. for (CoeusSubModule subModule : currentSubModulesForCoi) { // extract the corresponding event type, if any exists, from the currently active event list. CoiDisclosureEventType correspondingCoiEventType = extractCorrespondingCoiEventType( subModule.getSubModuleCode(), currentActiveCoiDisclosureEventTypes); if (correspondingCoiEventType != null) { // check and update submodule's description if needed if (!StringUtils.equals( subModule.getDescription(), correspondingCoiEventType.getDescription())) { subModule.setDescription(correspondingCoiEventType.getDescription()); getBusinessObjectService().save(subModule); } } else { // this submodule does not have a corresponding event type so delete it getBusinessObjectService().delete(subModule); } } // the remaining (i.e. unextracted) coi event types, if any, are all newly added, so create // corresponding submodules for them if (!currentActiveCoiDisclosureEventTypes.isEmpty()) { int nextId = getMaxCoeusSubModuleId() + 1; for (CoiDisclosureEventType remainingCoiEventType : currentActiveCoiDisclosureEventTypes) { CoeusSubModule correspondingSubModule = getCorrespondingCoeusSubModule(remainingCoiEventType); correspondingSubModule.setCoeusSubModuleId(nextId); getBusinessObjectService().save(correspondingSubModule); nextId++; } } }