private void loadNeededTerms() throws Exception { AtpInfo atp = new AtpInfo(); atp.setTypeKey(AtpServiceConstants.ATP_FALL_TYPE_KEY); atp.setId("2011FA"); FA2011_ATP = atpService.createAtp( atp.getTypeKey(), atp, getContext(PermissionAndRoleServiceDataLoader.CENTRAL_ADMIN1)); atp = new AtpInfo(); atp.setTypeKey(AtpServiceConstants.ATP_FALL_TYPE_KEY); atp.setId("2012FA"); FA2012_ATP = atpService.createAtp( atp.getTypeKey(), atp, getContext(PermissionAndRoleServiceDataLoader.CENTRAL_ADMIN1)); MockAcalTestDataLoader acalLoader = new MockAcalTestDataLoader(this.acalService); SP2011_TERM = acalLoader.loadTerm( "2011SP", "Spring 2011", "2011-03-01 00:00:00.0", "2011-05-31 00:00:00.0", AtpServiceConstants.ATP_SPRING_TYPE_KEY, AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, "Spring Term 2011"); FA2011_TERM = acalLoader.loadTerm( "2011FA", "Fall 2011", "2011-09-01 00:00:00.0", "2011-12-31 00:00:00.0", AtpServiceConstants.ATP_FALL_TYPE_KEY, AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, "Fall Term 2011"); SP2012_TERM = acalLoader.loadTerm( "2012SP", "Spring 2012", "2012-03-01 00:00:00.0", "2012-05-31 00:00:00.0", AtpServiceConstants.ATP_SPRING_TYPE_KEY, AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, "Spring Term 2012"); FA2012_TERM = acalLoader.loadTerm( "2012FA", "Fall 2012", "2012-09-01 00:00:00.0", "2012-12-31 00:00:00.0", AtpServiceConstants.ATP_FALL_TYPE_KEY, AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, "Fall Term 2012"); SP2013_TERM = acalLoader.loadTerm( "2013SP", "Spring 2013", "2013-03-01 00:00:00.0", "2013-05-31 00:00:00.0", AtpServiceConstants.ATP_SPRING_TYPE_KEY, AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, "Spring Term 2013"); FA2013_TERM = acalLoader.loadTerm( "2013FA", "Fall 2013", "2013-09-01 00:00:00.0", "2013-12-31 00:00:00.0", AtpServiceConstants.ATP_FALL_TYPE_KEY, AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, "Fall Term 2013"); }
@Override protected Object save(Object dto, Map<String, Object> properties, ContextInfo contextInfo) throws Exception { if (dto instanceof MajorDisciplineInfo) { MajorDisciplineInfo mdInfo = (MajorDisciplineInfo) dto; if (mdInfo.getId() == null && mdInfo.getVersion() != null) { String majorVersionIndId = mdInfo.getVersion().getVersionIndId(); // Get the current Major Dicipline from the service VersionDisplayInfo mdVersionInfo = programService.getCurrentVersion( ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI, majorVersionIndId, ContextUtils.getContextInfo()); mdInfo = programService.getMajorDiscipline(mdVersionInfo.getId(), ContextUtils.getContextInfo()); // set the prev start term to be the most recent of the major and all variations AtpInfo latestStartAtp = atpService.getAtp(mdInfo.getStartTerm(), contextInfo); for (ProgramVariationInfo variation : mdInfo.getVariations()) { AtpInfo variationAtp = atpService.getAtp(variation.getStartTerm(), contextInfo); if (variationAtp != null && variationAtp.getStartDate() != null && variationAtp.getStartDate().compareTo(latestStartAtp.getStartDate()) > 0) { latestStartAtp = variationAtp; } } // Save the start and end terms from the old version and put into filter properties String startTerm = latestStartAtp.getId(); String endTerm = mdInfo.getEndTerm(); String endProgramEntryTerm = mdInfo.getEndProgramEntryTerm(); String endInstAdmitTerm = mdInfo.getAttributeValue(ProgramConstants.END_INSTITUTIONAL_ADMIT_TERM); // Map<String, String> proposalAttributes = new HashMap<String, String>(); if (startTerm != null) proposalAttributes.put("prevStartTerm", startTerm); if (endTerm != null) proposalAttributes.put("prevEndTerm", endTerm); if (endProgramEntryTerm != null) proposalAttributes.put("prevEndProgramEntryTerm", endProgramEntryTerm); if (endInstAdmitTerm != null) proposalAttributes.put("prevEndInstAdmitTerm", endInstAdmitTerm); properties.put(ProposalWorkflowFilter.PROPOSAL_ATTRIBUTES, proposalAttributes); mdInfo = programService.createNewMajorDisciplineVersion( majorVersionIndId, "New major discipline version", ContextUtils.getContextInfo()); } else if (mdInfo.getId() == null) { mdInfo = programService.createMajorDiscipline( mdInfo.getId(), mdInfo, ContextUtils.getContextInfo()); } else { mdInfo = programService.updateMajorDiscipline(null, mdInfo, ContextUtils.getContextInfo()); } return mdInfo; } else { throw new InvalidParameterException( "Only persistence of MajorDiscipline is supported by this DataService implementation."); } }