Coverage Report - org.kuali.student.lum.program.service.impl.ProgramServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ProgramServiceImpl
58%
268/457
46%
71/154
2.92
 
 1  
 package org.kuali.student.lum.program.service.impl;
 2  
 
 3  
 import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
 4  
 
 5  
 import java.util.ArrayList;
 6  
 import java.util.Date;
 7  
 import java.util.List;
 8  
 
 9  
 import org.apache.log4j.Logger;
 10  
 import org.kuali.student.common.validator.ServerDateParser;
 11  
 import org.kuali.student.common.validator.Validator;
 12  
 import org.kuali.student.common.validator.ValidatorFactory;
 13  
 import org.kuali.student.common.validator.ValidatorUtils;
 14  
 import org.kuali.student.core.assembly.BaseDTOAssemblyNode;
 15  
 import org.kuali.student.core.assembly.BaseDTOAssemblyNode.NodeOperation;
 16  
 import org.kuali.student.core.assembly.BusinessServiceMethodInvoker;
 17  
 import org.kuali.student.core.assembly.data.AssemblyException;
 18  
 import org.kuali.student.core.atp.dto.AtpInfo;
 19  
 import org.kuali.student.core.atp.service.AtpService;
 20  
 import org.kuali.student.core.dictionary.dto.DataType;
 21  
 import org.kuali.student.core.dictionary.dto.ObjectStructureDefinition;
 22  
 import org.kuali.student.core.dictionary.service.DictionaryService;
 23  
 import org.kuali.student.core.document.dto.RefDocRelationInfo;
 24  
 import org.kuali.student.core.document.service.DocumentService;
 25  
 import org.kuali.student.core.dto.StatusInfo;
 26  
 import org.kuali.student.core.exceptions.AlreadyExistsException;
 27  
 import org.kuali.student.core.exceptions.CircularReferenceException;
 28  
 import org.kuali.student.core.exceptions.CircularRelationshipException;
 29  
 import org.kuali.student.core.exceptions.DataValidationErrorException;
 30  
 import org.kuali.student.core.exceptions.DependentObjectsExistException;
 31  
 import org.kuali.student.core.exceptions.DoesNotExistException;
 32  
 import org.kuali.student.core.exceptions.IllegalVersionSequencingException;
 33  
 import org.kuali.student.core.exceptions.InvalidParameterException;
 34  
 import org.kuali.student.core.exceptions.MissingParameterException;
 35  
 import org.kuali.student.core.exceptions.OperationFailedException;
 36  
 import org.kuali.student.core.exceptions.PermissionDeniedException;
 37  
 import org.kuali.student.core.exceptions.UnsupportedActionException;
 38  
 import org.kuali.student.core.exceptions.VersionMismatchException;
 39  
 import org.kuali.student.core.search.dto.SearchCriteriaTypeInfo;
 40  
 import org.kuali.student.core.search.dto.SearchRequest;
 41  
 import org.kuali.student.core.search.dto.SearchResult;
 42  
 import org.kuali.student.core.search.dto.SearchResultTypeInfo;
 43  
 import org.kuali.student.core.search.dto.SearchTypeInfo;
 44  
 import org.kuali.student.core.search.service.SearchManager;
 45  
 import org.kuali.student.core.statement.dto.ReqCompFieldInfo;
 46  
 import org.kuali.student.core.statement.dto.ReqComponentInfo;
 47  
 import org.kuali.student.core.statement.dto.StatementTreeViewInfo;
 48  
 import org.kuali.student.core.validation.dto.ValidationResultInfo;
 49  
 import org.kuali.student.core.versionmanagement.dto.VersionDisplayInfo;
 50  
 import org.kuali.student.lum.course.dto.LoDisplayInfo;
 51  
 import org.kuali.student.lum.lu.dto.CluCluRelationInfo;
 52  
 import org.kuali.student.lum.lu.dto.CluInfo;
 53  
 import org.kuali.student.lum.lu.dto.CluSetInfo;
 54  
 import org.kuali.student.lum.lu.dto.LuTypeInfo;
 55  
 import org.kuali.student.lum.lu.service.LuService;
 56  
 import org.kuali.student.lum.lu.service.LuServiceConstants;
 57  
 import org.kuali.student.lum.program.dto.CoreProgramInfo;
 58  
 import org.kuali.student.lum.program.dto.CredentialProgramInfo;
 59  
 import org.kuali.student.lum.program.dto.HonorsProgramInfo;
 60  
 import org.kuali.student.lum.program.dto.MajorDisciplineInfo;
 61  
 import org.kuali.student.lum.program.dto.MinorDisciplineInfo;
 62  
 import org.kuali.student.lum.program.dto.ProgramRequirementInfo;
 63  
 import org.kuali.student.lum.program.dto.ProgramVariationInfo;
 64  
 import org.kuali.student.lum.program.service.ProgramService;
 65  
 import org.kuali.student.lum.program.service.ProgramServiceConstants;
 66  
 import org.kuali.student.lum.program.service.assembler.CoreProgramAssembler;
 67  
 import org.kuali.student.lum.program.service.assembler.CredentialProgramAssembler;
 68  
 import org.kuali.student.lum.program.service.assembler.MajorDisciplineAssembler;
 69  
 import org.kuali.student.lum.program.service.assembler.ProgramAssemblerConstants;
 70  
 import org.kuali.student.lum.statement.typekey.ReqComponentFieldTypes;
 71  
 import org.springframework.transaction.annotation.Transactional;
 72  
 
 73  
 @Transactional(noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 74  2
 public class ProgramServiceImpl implements ProgramService {
 75  1
         final static Logger LOG = Logger.getLogger(ProgramServiceImpl.class);
 76  
 
 77  
     private LuService luService;
 78  
     private ValidatorFactory validatorFactory;
 79  
     private BusinessServiceMethodInvoker programServiceMethodInvoker;
 80  
     private DictionaryService dictionaryService;
 81  
     private SearchManager searchManager;
 82  
     private MajorDisciplineAssembler majorDisciplineAssembler;
 83  
     private ProgramRequirementAssembler programRequirementAssembler;
 84  
     private CredentialProgramAssembler credentialProgramAssembler;
 85  
     private CoreProgramAssembler coreProgramAssembler;
 86  
 //    private StatementService statementService;
 87  
     private AtpService atpService;
 88  
     private DocumentService documentService;
 89  
     
 90  
     
 91  
     @Override
 92  
     public CredentialProgramInfo createCredentialProgram(
 93  
             CredentialProgramInfo credentialProgramInfo)
 94  
             throws AlreadyExistsException, DataValidationErrorException,
 95  
             InvalidParameterException, MissingParameterException,
 96  
             OperationFailedException, PermissionDeniedException {
 97  
 
 98  1
         checkForMissingParameter(credentialProgramInfo, "CredentialProgramInfo");
 99  
 
 100  
         // Validate
 101  1
         List<ValidationResultInfo> validationResults = validateCredentialProgram("OBJECT", credentialProgramInfo);
 102  1
         if (null != validationResults && validationResults.size() > 0) {
 103  0
             throw new DataValidationErrorException("Validation error!", validationResults);
 104  
         }
 105  
 
 106  
         try {
 107  1
             return processCredentialProgramInfo(credentialProgramInfo, NodeOperation.CREATE);
 108  0
         } catch (AssemblyException e) {
 109  0
             LOG.error("Error disassembling Credential Program", e);
 110  0
             throw new OperationFailedException("Error disassembling Credential Program");
 111  
         }
 112  
     }
 113  
 
 114  
     @Override
 115  
     public HonorsProgramInfo createHonorsProgram(
 116  
             HonorsProgramInfo honorsProgramInfo) throws AlreadyExistsException,
 117  
             DataValidationErrorException, InvalidParameterException,
 118  
             MissingParameterException, OperationFailedException,
 119  
             PermissionDeniedException {
 120  
         // TODO Auto-generated method stub
 121  1
         return null;
 122  
     }
 123  
 
 124  
     @Override
 125  
     public ProgramRequirementInfo createProgramRequirement(
 126  
             ProgramRequirementInfo programRequirementInfo)
 127  
             throws AlreadyExistsException, DataValidationErrorException,
 128  
             InvalidParameterException, MissingParameterException,
 129  
             OperationFailedException, PermissionDeniedException {
 130  7
         checkForMissingParameter(programRequirementInfo, "programRequirementInfo");
 131  
 
 132  
         // Validate
 133  6
         List<ValidationResultInfo> validationResults = validateProgramRequirement("OBJECT", programRequirementInfo);
 134  6
         if (isNotEmpty(validationResults)) {
 135  0
                 throw new DataValidationErrorException("Validation error!", validationResults);
 136  
         }
 137  
 
 138  
         try {
 139  6
             return processProgramRequirement(programRequirementInfo, NodeOperation.CREATE);
 140  0
         } catch (AssemblyException e) {
 141  0
             LOG.error("Error disassembling Program Requirement", e);
 142  0
             throw new OperationFailedException("Error disassembling Program Requirement", e);
 143  
         }
 144  
     }
 145  
 
 146  
     @Override
 147  
     public MajorDisciplineInfo createMajorDiscipline(
 148  
             MajorDisciplineInfo majorDisciplineInfo)
 149  
             throws AlreadyExistsException, DataValidationErrorException,
 150  
             InvalidParameterException, MissingParameterException,
 151  
             OperationFailedException, PermissionDeniedException {
 152  
 
 153  3
         checkForMissingParameter(majorDisciplineInfo, "MajorDisciplineInfo");
 154  
 
 155  
         // Validate
 156  3
         List<ValidationResultInfo> validationResults = validateMajorDiscipline("OBJECT", majorDisciplineInfo);
 157  3
         if (null != validationResults && validationResults.size() > 0) {
 158  0
             throw new DataValidationErrorException("Validation error!", validationResults);
 159  
         }
 160  
 
 161  
         try {
 162  3
             return processMajorDisciplineInfo(majorDisciplineInfo, NodeOperation.CREATE);
 163  0
         } catch (AssemblyException e) {
 164  0
             LOG.error("Error creating Major Discipline", e);
 165  0
             throw new OperationFailedException("Error creating Major Discipline");
 166  
         }
 167  
     }
 168  
     
 169  
     @Override
 170  
         public MajorDisciplineInfo createNewMajorDisciplineVersion(
 171  
                         String majorDisciplineVerIndId, String versionComment)
 172  
                         throws DoesNotExistException, InvalidParameterException,
 173  
                         MissingParameterException, OperationFailedException,
 174  
                         PermissionDeniedException, VersionMismatchException, DataValidationErrorException {
 175  
                 //step one, get the original
 176  2
                 VersionDisplayInfo currentVersion = luService.getCurrentVersion(LuServiceConstants.CLU_NAMESPACE_URI, majorDisciplineVerIndId);
 177  2
                 MajorDisciplineInfo originalMajorDicipline = getMajorDiscipline(currentVersion.getId());
 178  
 
 179  
                 //Version the Clu
 180  2
                 CluInfo newVersionClu = luService.createNewCluVersion(majorDisciplineVerIndId, versionComment);
 181  
 
 182  
                 try {
 183  
                 BaseDTOAssemblyNode<MajorDisciplineInfo, CluInfo> results;
 184  
 
 185  
                 //Integrate changes into the original. (should this just be just the id?)
 186  2
                         majorDisciplineAssembler.assemble(newVersionClu, originalMajorDicipline, true);
 187  
 
 188  
                         //Clear Ids from the original so it will make a copy and do other processing
 189  2
                         processCopy(originalMajorDicipline, currentVersion.getId());
 190  
 
 191  
                         //Disassemble the new
 192  2
                         results = majorDisciplineAssembler.disassemble(originalMajorDicipline, NodeOperation.UPDATE);
 193  
 
 194  
                         // Use the results to make the appropriate service calls here
 195  2
                         programServiceMethodInvoker.invokeServiceCalls(results);
 196  
 
 197  2
                         return results.getBusinessDTORef();
 198  0
                 } catch(AssemblyException e) {
 199  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 200  0
                 } catch (AlreadyExistsException e) {
 201  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 202  0
                 } catch (DependentObjectsExistException e) {
 203  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 204  0
                 } catch (CircularRelationshipException e) {
 205  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 206  0
                 } catch (UnsupportedActionException e) {
 207  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 208  0
                 } catch (CircularReferenceException e) {
 209  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 210  
                 }
 211  
         }
 212  
     
 213  
     
 214  
         /**
 215  
          * Recurses through the statement tree and clears out ids so the tree can be copied.
 216  
          * Also creates copies of clusets since they are single use
 217  
          * 
 218  
          * @param statementTreeView
 219  
          * @throws OperationFailedException
 220  
          */
 221  
         private void clearStatementTreeViewIdsRecursively(StatementTreeViewInfo statementTreeView) throws OperationFailedException{
 222  0
                 if(statementTreeView!=null){
 223  0
                         statementTreeView.setId(null);
 224  0
                         for(ReqComponentInfo reqComp:statementTreeView.getReqComponents()){
 225  0
                                 reqComp.setId(null);
 226  0
                                 for(ReqCompFieldInfo field:reqComp.getReqCompFields()){
 227  0
                                         field.setId(null);
 228  
                                         //copy any clusets that are adhoc'd and set the field value to the new cluset
 229  0
                                         if(ReqComponentFieldTypes.COURSE_CLUSET_KEY.getId().equals(field.getType())||
 230  
                                            ReqComponentFieldTypes.PROGRAM_CLUSET_KEY.getId().equals(field.getType())||
 231  
                                            ReqComponentFieldTypes.CLUSET_KEY.getId().equals(field.getType())){
 232  
                                                 try {
 233  0
                                                         CluSetInfo cluSet = luService.getCluSetInfo(field.getValue());
 234  0
                                                         cluSet.setId(null);
 235  0
                                                         cluSet = luService.createCluSet(cluSet.getType(), cluSet);
 236  0
                                                         field.setValue(cluSet.getId());
 237  0
                                                 } catch (Exception e) {
 238  0
                                                         throw new OperationFailedException("Error copying clusets.", e);
 239  0
                                                 }
 240  
                                         }
 241  
                                         
 242  
                                 }
 243  
                         }
 244  
                         //Recurse through the children
 245  0
                         for(StatementTreeViewInfo child: statementTreeView.getStatements()){
 246  0
                                 clearStatementTreeViewIdsRecursively(child);
 247  
                         }
 248  
                 }
 249  0
         }
 250  
 
 251  
         /**
 252  
      * Clears out any ids so that a subsequent call to create will copy complex structures. 
 253  
      * Also updates VersionInfo on variations to match VersionInfo on parent.
 254  
      * 
 255  
      * @param majorDiscipline
 256  
          * @throws PermissionDeniedException 
 257  
          * @throws OperationFailedException 
 258  
          * @throws MissingParameterException 
 259  
          * @throws InvalidParameterException 
 260  
          * @throws DoesNotExistException 
 261  
          * @throws DataValidationErrorException 
 262  
          * @throws AlreadyExistsException 
 263  
          * @throws VersionMismatchException 
 264  
          * @throws CircularRelationshipException 
 265  
      */
 266  
     private void processCopy(MajorDisciplineInfo majorDiscipline,String originalId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, AlreadyExistsException, DataValidationErrorException, VersionMismatchException, CircularRelationshipException {
 267  
                 //Clear Los
 268  2
                 for(LoDisplayInfo lo:majorDiscipline.getLearningObjectives()){
 269  4
                         resetLoRecursively(lo);
 270  
                 }
 271  
                 //Clear OrgCoreProgram
 272  2
                 if(majorDiscipline.getOrgCoreProgram()!=null){
 273  0
                         majorDiscipline.getOrgCoreProgram().setId(null);
 274  
                 
 275  0
                         if(majorDiscipline.getOrgCoreProgram().getLearningObjectives()!=null){
 276  0
                                 for(LoDisplayInfo lo:majorDiscipline.getOrgCoreProgram().getLearningObjectives()){
 277  0
                                         resetLoRecursively(lo);
 278  
                                 }
 279  
                         }
 280  
                 }
 281  
                 //Clear Variations
 282  2
                 for(ProgramVariationInfo variation:majorDiscipline.getVariations()){
 283  
                         //Create new variation version
 284  4
                         String variationVersionIndId = variation.getVersionInfo().getVersionIndId();
 285  4
                         CluInfo newVariationClu = luService.createNewCluVersion(variationVersionIndId, "Variation version for MajorDiscipline version " + majorDiscipline.getVersionInfo().getSequenceNumber());        
 286  
                         
 287  
                         //Create relation b/w new major discipline and new variation
 288  4
                         CluCluRelationInfo relation = new CluCluRelationInfo();
 289  4
                 relation.setCluId(majorDiscipline.getId());
 290  4
                 relation.setRelatedCluId(newVariationClu.getId());
 291  4
                 relation.setType(ProgramAssemblerConstants.HAS_PROGRAM_VARIATION);
 292  4
                 relation.setState(ProgramAssemblerConstants.ACTIVE);
 293  4
                         luService.createCluCluRelation(relation.getCluId(), relation.getRelatedCluId(), relation.getType(), relation);
 294  
                 
 295  
                         //Set variation id & versionInfo to new variation clu
 296  4
                         variation.setId(newVariationClu.getId());
 297  4
                         variation.setMetaInfo(newVariationClu.getMetaInfo());
 298  
                                                 
 299  
                         //Set state to parent program's state
 300  4
                         variation.setState(majorDiscipline.getState());
 301  
                         //Clear Los
 302  4
                         for(LoDisplayInfo lo:variation.getLearningObjectives()){
 303  8
                                 resetLoRecursively(lo);
 304  
                         }
 305  
                         //Copy Requirements for variation
 306  4
                         copyProgramRequirements(variation.getProgramRequirements(),majorDiscipline.getState());
 307  4
                 }
 308  
                 
 309  
                 //Copy requirements for majorDicipline
 310  2
                 copyProgramRequirements(majorDiscipline.getProgramRequirements(),majorDiscipline.getState());
 311  
 
 312  
                 //Copy documents(create new relations to the new version)
 313  2
                 List<RefDocRelationInfo> docRelations = documentService.getRefDocRelationsByRef("kuali.org.RefObjectType.ProposalInfo", originalId);
 314  2
                 if(docRelations!=null){
 315  0
                         for(RefDocRelationInfo docRelation:docRelations){
 316  0
                                 docRelation.setId(null);
 317  0
                                 docRelation.setRefObjectId(majorDiscipline.getId());
 318  0
                                 documentService.createRefDocRelation("kuali.org.RefObjectType.ProposalInfo", majorDiscipline.getId(), docRelation.getDocumentId(), docRelation.getType(), docRelation);
 319  
                         }
 320  
                 }
 321  2
         }
 322  
 
 323  
         private void processCopy(CredentialProgramInfo originaCredentialProgram,
 324  
                         String originalId) throws OperationFailedException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, PermissionDeniedException, DoesNotExistException {
 325  
                 //Clear Los
 326  0
                 if (originaCredentialProgram.getLearningObjectives() != null){
 327  0
                         for(LoDisplayInfo lo:originaCredentialProgram.getLearningObjectives()){
 328  0
                                 resetLoRecursively(lo);
 329  
                         }
 330  
                 }
 331  
 
 332  
                 //Copy requirements for majorDicipline
 333  0
                 copyProgramRequirements(originaCredentialProgram.getProgramRequirements(),originaCredentialProgram.getState());
 334  
 
 335  
                 //Copy documents(create new relations to the new version)
 336  0
                 List<RefDocRelationInfo> docRelations = documentService.getRefDocRelationsByRef("kuali.org.RefObjectType.ProposalInfo", originalId);
 337  0
                 if(docRelations!=null){
 338  0
                         for(RefDocRelationInfo docRelation:docRelations){
 339  0
                                 docRelation.setId(null);
 340  0
                                 docRelation.setRefObjectId(originaCredentialProgram.getId());
 341  0
                                 documentService.createRefDocRelation("kuali.org.RefObjectType.ProposalInfo", originaCredentialProgram.getId(), docRelation.getDocumentId(), docRelation.getType(), docRelation);
 342  
                         }
 343  
                 }
 344  0
         }
 345  
     
 346  
     private void processCopy(CoreProgramInfo originalCoreProgram, String originalId) throws OperationFailedException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, PermissionDeniedException, DoesNotExistException {
 347  
                 //Clear Los
 348  2
                 for(LoDisplayInfo lo:originalCoreProgram.getLearningObjectives()){
 349  4
                         resetLoRecursively(lo);
 350  
                 }
 351  
                 //Copy requirements for majorDicipline
 352  2
                 copyProgramRequirements(originalCoreProgram.getProgramRequirements(),originalCoreProgram.getState());
 353  
 
 354  
                 //Copy documents(create new relations to the new version)
 355  2
                 List<RefDocRelationInfo> docRelations = documentService.getRefDocRelationsByRef("kuali.org.RefObjectType.ProposalInfo", originalId);
 356  2
                 if(docRelations!=null){
 357  0
                         for(RefDocRelationInfo docRelation:docRelations){
 358  0
                                 docRelation.setId(null);
 359  0
                                 docRelation.setRefObjectId(originalCoreProgram.getId());
 360  0
                                 documentService.createRefDocRelation("kuali.org.RefObjectType.ProposalInfo", originalCoreProgram.getId(), docRelation.getDocumentId(), docRelation.getType(), docRelation);
 361  
                         }
 362  
                 }
 363  2
         }
 364  
     
 365  
     /**
 366  
      * Copy requirements (these exist external to the program save process and are referenced by id)
 367  
      * @param originalProgramRequirementIds
 368  
      * @param state
 369  
      * @throws OperationFailedException
 370  
      * @throws AlreadyExistsException
 371  
      * @throws DataValidationErrorException
 372  
      * @throws InvalidParameterException
 373  
      * @throws MissingParameterException
 374  
      * @throws PermissionDeniedException
 375  
      * @throws DoesNotExistException
 376  
      */
 377  
     private void copyProgramRequirements(List<String> originalProgramRequirementIds,String state) throws OperationFailedException, AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, PermissionDeniedException, DoesNotExistException{
 378  
                 //Pull out the current requirement ids to be replaced by the ids of the new copies 
 379  8
                 List<String> programRequirementIds = new ArrayList<String>(originalProgramRequirementIds);
 380  8
                 originalProgramRequirementIds.clear();
 381  
                 
 382  8
                 for(String programRequirementId:programRequirementIds){
 383  
                         //Grab the original 
 384  0
                         ProgramRequirementInfo programRequirementInfo = getProgramRequirement(programRequirementId, null, null);
 385  
                         //Clear the id
 386  0
                         programRequirementInfo.setId(null);
 387  
                         
 388  0
                         programRequirementInfo.setState(state);
 389  
                         //Clear statement tree ids
 390  0
                         clearStatementTreeViewIdsRecursively(programRequirementInfo.getStatement());
 391  
                         //Clear learning objectives
 392  0
                         for(LoDisplayInfo lo:programRequirementInfo.getLearningObjectives()){
 393  0
                                 resetLoRecursively(lo);
 394  
                         }
 395  
                         //Create the new copy
 396  0
                         ProgramRequirementInfo createdProgramRequirement = createProgramRequirement(programRequirementInfo);
 397  
                         //add the copy's id back to the majorDicipline's list of requirements
 398  0
                         originalProgramRequirementIds.add(createdProgramRequirement.getId());
 399  0
                 }
 400  8
     }
 401  
     
 402  
         /**
 403  
          * Recursively clears out the ids in a Lo and in its child Los
 404  
          * @param lo
 405  
          */
 406  
         private void resetLoRecursively(LoDisplayInfo lo){
 407  112
                 lo.getLoInfo().setId(null);
 408  112
                 for(LoDisplayInfo nestedLo:lo.getLoDisplayInfoList()){
 409  96
                         resetLoRecursively(nestedLo);
 410  
                 }
 411  112
         }
 412  
 
 413  
         @Override
 414  
         public StatusInfo setCurrentMajorDisciplineVersion(
 415  
                         String majorDisciplineId, Date currentVersionStart)
 416  
                         throws DoesNotExistException, InvalidParameterException,
 417  
                         MissingParameterException, IllegalVersionSequencingException,
 418  
                         OperationFailedException, PermissionDeniedException {
 419  1
                 StatusInfo status = luService.setCurrentCluVersion(majorDisciplineId, currentVersionStart);
 420  
                 
 421  
                 //Update the variations to be current as well
 422  1
                 List<ProgramVariationInfo> variationList = getVariationsByMajorDisciplineId(majorDisciplineId);
 423  1
                 for (ProgramVariationInfo variationInfo:variationList){
 424  2
                         String variationId = variationInfo.getId();
 425  
                         //If null set to current (non-null value means version is first and is already current)
 426  2
                         if (variationInfo.getVersionInfo().getCurrentVersionStart() == null){
 427  2
                                 luService.setCurrentCluVersion(variationId, currentVersionStart);
 428  
                         }
 429  2
                 }
 430  
                 
 431  1
                 return status;
 432  
         }
 433  
 
 434  
         @Override
 435  
     public MinorDisciplineInfo createMinorDiscipline(
 436  
             MinorDisciplineInfo minorDisciplineInfo)
 437  
             throws AlreadyExistsException, DataValidationErrorException,
 438  
             InvalidParameterException, MissingParameterException,
 439  
             OperationFailedException, PermissionDeniedException {
 440  
         // TODO Auto-generated method stub
 441  1
         return null;
 442  
     }
 443  
 
 444  
     @Override
 445  
     public StatusInfo deleteCredentialProgram(String credentialProgramId)
 446  
             throws DoesNotExistException, InvalidParameterException,
 447  
             MissingParameterException, OperationFailedException,
 448  
             PermissionDeniedException {
 449  
 
 450  
 //        try {
 451  
 //                CredentialProgramInfo credentialProgram = getCredentialProgram(credentialProgramId);
 452  
 //
 453  
 //            processCredentialProgramInfo(credentialProgram, NodeOperation.DELETE);
 454  
 //
 455  
 //            return getStatus();
 456  
 //
 457  
 //        } catch (AssemblyException e) {
 458  
 //            LOG.error("Error disassembling CredentialProgram", e);
 459  
 //            throw new OperationFailedException("Error disassembling CredentialProgram");
 460  
 //        }
 461  1
             throw new OperationFailedException("Deletion of CredentialProgram is not supported."); 
 462  
     }
 463  
 
 464  
     @Override
 465  
     public StatusInfo deleteHonorsProgram(String honorsProgramId)
 466  
             throws DoesNotExistException, InvalidParameterException,
 467  
             MissingParameterException, OperationFailedException,
 468  
             PermissionDeniedException {
 469  
         // TODO Auto-generated method stub
 470  1
         return null;
 471  
     }
 472  
 
 473  
     @Override
 474  
     public StatusInfo deleteMajorDiscipline(String majorDisciplineId)
 475  
             throws DoesNotExistException, InvalidParameterException,
 476  
             MissingParameterException, OperationFailedException,
 477  
             PermissionDeniedException {
 478  
 
 479  
         try {
 480  0
             MajorDisciplineInfo majorDiscipline = getMajorDiscipline(majorDisciplineId);
 481  
 
 482  0
             processMajorDisciplineInfo(majorDiscipline, NodeOperation.DELETE);
 483  
 
 484  0
             return getStatus();
 485  
 
 486  0
         } catch (AssemblyException e) {
 487  0
             LOG.error("Error disassembling MajorDiscipline", e);
 488  0
             throw new OperationFailedException("Error disassembling MajorDiscipline");
 489  
         }
 490  
     }
 491  
 
 492  
     @Override
 493  
     public StatusInfo deleteMinorDiscipline(String minorDisciplineId)
 494  
             throws DoesNotExistException, InvalidParameterException,
 495  
             MissingParameterException, OperationFailedException,
 496  
             PermissionDeniedException {
 497  
         // TODO Auto-generated method stub
 498  1
         return null;
 499  
     }
 500  
 
 501  
     @Override
 502  
     public StatusInfo deleteProgramRequirement(String programRequirementId)
 503  
             throws DoesNotExistException, InvalidParameterException,
 504  
             MissingParameterException, OperationFailedException,
 505  
             PermissionDeniedException {
 506  2
             checkForMissingParameter(programRequirementId, "programRequirementId");
 507  
         try {
 508  2
                 ProgramRequirementInfo programRequirement = getProgramRequirement(programRequirementId, null, null);
 509  
 
 510  2
                 processProgramRequirement(programRequirement, NodeOperation.DELETE);
 511  
 
 512  2
             return getStatus();
 513  
 
 514  0
         } catch (AssemblyException e) {
 515  0
             LOG.error("Error disassembling MajorDiscipline", e);
 516  0
             throw new OperationFailedException("Error disassembling ProgramRequirement", e);
 517  
         }
 518  
 
 519  
     }
 520  
 
 521  
     @Override
 522  
     public CredentialProgramInfo getCredentialProgram(String credentialProgramId)
 523  
             throws DoesNotExistException, InvalidParameterException,
 524  
             MissingParameterException, OperationFailedException,
 525  
             PermissionDeniedException {
 526  
 
 527  4
             CredentialProgramInfo credentialProgramInfo = null;
 528  
 
 529  
         try {
 530  4
             CluInfo clu = luService.getClu(credentialProgramId);
 531  
 
 532  4
             if ( ! ProgramAssemblerConstants.CREDENTIAL_PROGRAM_TYPES.contains(clu.getType()) ) {
 533  0
                 throw new DoesNotExistException("Specified CLU is not a Credential Program");
 534  
             }
 535  
 
 536  4
             credentialProgramInfo = credentialProgramAssembler.assemble(clu, null, false);
 537  0
         } catch (AssemblyException e) {
 538  0
             LOG.error("Error assembling CredentialProgram", e);
 539  0
             throw new OperationFailedException("Error assembling CredentialProgram");
 540  4
         }
 541  4
         return credentialProgramInfo;
 542  
 
 543  
                 // comment out the above, and uncomment below to get auto-generated data
 544  
         // (and vice-versa)
 545  
 //                try {
 546  
 //                        return new CredentialProgramDataGenerator(ProgramAssemblerConstants.BACCALAUREATE_PROGRAM).getCPTestData();
 547  
 //                } catch (Exception e) {
 548  
 //                        return null;
 549  
 //                }
 550  
     }
 551  
 
 552  
     @Override
 553  
     public LuTypeInfo getCredentialProgramType(String credentialProgramTypeKey)
 554  
             throws DoesNotExistException, InvalidParameterException,
 555  
             MissingParameterException, OperationFailedException {
 556  
         // TODO Auto-generated method stub
 557  1
         return null;
 558  
     }
 559  
 
 560  
     @Override
 561  
     public List<LuTypeInfo> getCredentialProgramTypes()
 562  
             throws OperationFailedException {
 563  
         // TODO Auto-generated method stub
 564  1
         return null;
 565  
     }
 566  
 
 567  
     @Override
 568  
     public List<String> getHonorsByCredentialProgramType(String programType)
 569  
             throws DoesNotExistException, InvalidParameterException,
 570  
             MissingParameterException, OperationFailedException {
 571  
         // TODO Auto-generated method stub
 572  1
         return null;
 573  
     }
 574  
 
 575  
     @Override
 576  
     public HonorsProgramInfo getHonorsProgram(String honorsProgramId)
 577  
             throws DoesNotExistException, InvalidParameterException,
 578  
             MissingParameterException, OperationFailedException,
 579  
             PermissionDeniedException {
 580  
         // TODO Auto-generated method stub
 581  1
         return null;
 582  
     }
 583  
 
 584  
     @Override
 585  
     public MajorDisciplineInfo getMajorDiscipline(String majorDisciplineId)
 586  
             throws DoesNotExistException, InvalidParameterException,
 587  
             MissingParameterException, OperationFailedException,
 588  
             PermissionDeniedException {
 589  
 
 590  
 
 591  15
         MajorDisciplineInfo majorDiscipline = null;
 592  
 
 593  
         try {
 594  15
             CluInfo clu = luService.getClu(majorDisciplineId);
 595  15
             if ( ! ProgramAssemblerConstants.MAJOR_DISCIPLINE.equals(clu.getType()) ) {
 596  1
                 throw new DoesNotExistException("Specified CLU is not a Major Discipline");
 597  
             }
 598  14
             majorDiscipline = majorDisciplineAssembler.assemble(clu, null, false);
 599  0
         } catch (AssemblyException e) {
 600  0
             LOG.error("Error assembling MajorDiscipline", e);
 601  0
             throw new OperationFailedException("Error assembling MajorDiscipline");
 602  14
         }
 603  14
         return majorDiscipline;
 604  
                 // comment out the above, and uncomment below to get auto-generated data
 605  
         // (and vice-versa)
 606  
 //                try {
 607  
 //                        return new MajorDisciplineDataGenerator().getMajorDisciplineInfoTestData();
 608  
 //                } catch (Exception e) {
 609  
 //                        return null;
 610  
 //                }
 611  
         }
 612  
 
 613  
         @Override
 614  
         public List<String> getMajorIdsByCredentialProgramType(String programType)
 615  
                         throws DoesNotExistException, InvalidParameterException,
 616  
                         MissingParameterException, OperationFailedException {
 617  
                 // TODO Auto-generated method stub
 618  1
                 return null;
 619  
         }
 620  
 
 621  
         @Override
 622  
         public MinorDisciplineInfo getMinorDiscipline(String minorDisciplineId)
 623  
                         throws DoesNotExistException, InvalidParameterException,
 624  
                         MissingParameterException, OperationFailedException,
 625  
                         PermissionDeniedException {
 626  
                 // TODO Auto-generated method stub
 627  1
                 return null;
 628  
         }
 629  
 
 630  
         @Override
 631  
         public List<String> getMinorsByCredentialProgramType(String programType)
 632  
                         throws DoesNotExistException, InvalidParameterException,
 633  
                         MissingParameterException, OperationFailedException {
 634  
                 // TODO Auto-generated method stub
 635  1
                 return null;
 636  
         }
 637  
 
 638  
         @Override
 639  
         public ProgramRequirementInfo getProgramRequirement(String programRequirementId, String nlUsageTypeKey, String language) throws DoesNotExistException,
 640  
                         InvalidParameterException, MissingParameterException,
 641  
                         OperationFailedException, PermissionDeniedException {
 642  
 
 643  8
                 checkForMissingParameter(programRequirementId, "programRequirementId");
 644  
 
 645  7
                 CluInfo clu = luService.getClu(programRequirementId);
 646  5
                 if (!ProgramAssemblerConstants.PROGRAM_REQUIREMENT.equals(clu.getType())) {
 647  0
                         throw new DoesNotExistException("Specified CLU is not a Program Requirement");
 648  
                 }
 649  
                 try {
 650  5
                         ProgramRequirementInfo progReqInfo = programRequirementAssembler.assemble(clu, null, false);
 651  5
                         StatementTreeViewInfo statement = progReqInfo.getStatement();
 652  
 //                        if (nlUsageTypeKey != null && language != null) {
 653  
 //                                statement.setNaturalLanguageTranslation(statementService.getNaturalLanguageForStatement(statement.getId(), nlUsageTypeKey, language));
 654  
 //                        }
 655  5
                         return progReqInfo;
 656  0
                 } catch (AssemblyException e) {
 657  0
             LOG.error("Error assembling program requirement", e);
 658  0
             throw new OperationFailedException("Error assembling program requirement: " + e.getMessage(), e);
 659  
                 }
 660  
         }
 661  
 
 662  
         @Override
 663  
         public List<ProgramVariationInfo> getVariationsByMajorDisciplineId(
 664  
                         String majorDisciplineId) throws DoesNotExistException,
 665  
                         InvalidParameterException, MissingParameterException,
 666  
                         OperationFailedException {
 667  5
             List<ProgramVariationInfo> pvInfos = new ArrayList<ProgramVariationInfo>();
 668  
 
 669  
             try {
 670  5
                             List<CluInfo> clus = luService.getRelatedClusByCluId(majorDisciplineId, ProgramAssemblerConstants.HAS_PROGRAM_VARIATION);
 671  
 
 672  5
                         if(clus != null && clus.size() > 0){
 673  5
                                 for(CluInfo clu : clus){
 674  12
                                         ProgramVariationInfo pvInfo = majorDisciplineAssembler.getProgramVariationAssembler().assemble(clu, null, false);
 675  12
                                         if(pvInfo != null){
 676  12
                                                 pvInfos.add(pvInfo);
 677  
                                         }
 678  12
                                 }
 679  
                         }
 680  0
                     } catch (AssemblyException e) {
 681  0
                         LOG.error("Error assembling ProgramVariation", e);
 682  0
                         throw new OperationFailedException("Error assembling ProgramVariation");
 683  5
                     }
 684  
 
 685  5
         return pvInfos;
 686  
     }
 687  
 
 688  
     @Override
 689  
     public CredentialProgramInfo updateCredentialProgram(
 690  
             CredentialProgramInfo credentialProgramInfo)
 691  
             throws DataValidationErrorException, DoesNotExistException,
 692  
             InvalidParameterException, MissingParameterException,
 693  
             VersionMismatchException, OperationFailedException,
 694  
             PermissionDeniedException {
 695  
 
 696  1
         checkForMissingParameter(credentialProgramInfo, "CredentialProgramInfo");
 697  
 
 698  
         // Validate
 699  1
         List<ValidationResultInfo> validationResults = validateCredentialProgram("OBJECT", credentialProgramInfo);
 700  1
         if (null != validationResults && validationResults.size() > 0) {
 701  0
             throw new DataValidationErrorException("Validation error!", validationResults);
 702  
         }
 703  
 
 704  
         try {
 705  
 
 706  1
             return processCredentialProgramInfo(credentialProgramInfo, NodeOperation.UPDATE);
 707  
 
 708  0
         } catch (AssemblyException e) {
 709  0
             LOG.error("Error disassembling Credential Program", e);
 710  0
             throw new OperationFailedException("Error disassembling Credential Program");
 711  
         }
 712  
     }
 713  
 
 714  
     @Override
 715  
     public HonorsProgramInfo updateHonorsProgram(
 716  
             HonorsProgramInfo honorsProgramInfo)
 717  
             throws DataValidationErrorException, DoesNotExistException,
 718  
             InvalidParameterException, MissingParameterException,
 719  
             VersionMismatchException, OperationFailedException,
 720  
             PermissionDeniedException {
 721  
         // TODO Auto-generated method stub
 722  1
         return null;
 723  
     }
 724  
 
 725  
     @Override
 726  
     public MajorDisciplineInfo updateMajorDiscipline(
 727  
             MajorDisciplineInfo majorDisciplineInfo)
 728  
             throws DataValidationErrorException, DoesNotExistException,
 729  
             InvalidParameterException, MissingParameterException,
 730  
             VersionMismatchException, OperationFailedException,
 731  
             PermissionDeniedException {
 732  
 
 733  6
         checkForMissingParameter(majorDisciplineInfo, "MajorDisciplineInfo");
 734  
 
 735  
         // Validate
 736  6
         List<ValidationResultInfo> validationResults = validateMajorDiscipline("OBJECT", majorDisciplineInfo);
 737  6
         if (null != validationResults && validationResults.size() > 0) {
 738  0
             throw new DataValidationErrorException("Validation error!", validationResults);
 739  
         }
 740  
 
 741  
         try {
 742  
 
 743  6
             return processMajorDisciplineInfo(majorDisciplineInfo, NodeOperation.UPDATE);
 744  
 
 745  0
         } catch (AssemblyException e) {
 746  0
             LOG.error("Error disassembling majorDiscipline", e);
 747  0
             throw new OperationFailedException("Error disassembling majorDiscipline");
 748  
         }
 749  
     }
 750  
 
 751  
     @Override
 752  
     public MinorDisciplineInfo updateMinorDiscipline(
 753  
             MinorDisciplineInfo minorDisciplineInfo)
 754  
             throws DataValidationErrorException, DoesNotExistException,
 755  
             InvalidParameterException, MissingParameterException,
 756  
             VersionMismatchException, OperationFailedException,
 757  
             PermissionDeniedException {
 758  
         // TODO Auto-generated method stub
 759  1
         return null;
 760  
     }
 761  
 
 762  
     @Override
 763  
     public ProgramRequirementInfo updateProgramRequirement(
 764  
             ProgramRequirementInfo programRequirementInfo)
 765  
             throws DataValidationErrorException, DoesNotExistException,
 766  
             InvalidParameterException, MissingParameterException,
 767  
             VersionMismatchException, OperationFailedException,
 768  
             PermissionDeniedException {
 769  1
             checkForMissingParameter(programRequirementInfo, "programRequirementInfo");
 770  
         // Validate
 771  1
         List<ValidationResultInfo> validationResults = validateProgramRequirement("OBJECT", programRequirementInfo);
 772  1
         if (isNotEmpty(validationResults)) {
 773  0
                 throw new DataValidationErrorException("Validation error!", validationResults);
 774  
         }
 775  
 
 776  
         try {
 777  1
                         return processProgramRequirement(programRequirementInfo, NodeOperation.UPDATE);
 778  0
                 } catch (AssemblyException e) {
 779  0
                         throw new OperationFailedException("Unable to update ProgramRequirement", e);
 780  
                 }
 781  
     }
 782  
 
 783  
     @Override
 784  
     public List<ValidationResultInfo> validateCredentialProgram(
 785  
             String validationType, CredentialProgramInfo credentialProgramInfo)
 786  
             throws InvalidParameterException,
 787  
             MissingParameterException, OperationFailedException {
 788  
 
 789  2
         List<ValidationResultInfo> validationResults = new ArrayList<ValidationResultInfo>();
 790  2
         if ( ! ProgramAssemblerConstants.DRAFT.equals(credentialProgramInfo.getState()) ) {
 791  1
             ObjectStructureDefinition objStructure = this.getObjectStructure(CredentialProgramInfo.class.getName());
 792  1
             Validator validator = validatorFactory.getValidator();
 793  1
             validationResults.addAll(validator.validateObject(credentialProgramInfo, objStructure));
 794  
         }
 795  
 
 796  2
         return validationResults;
 797  
     }
 798  
 
 799  
     @Override
 800  
     public List<ValidationResultInfo> validateHonorsProgram(
 801  
             String validationType, HonorsProgramInfo honorsProgramInfo)
 802  
             throws InvalidParameterException,
 803  
             MissingParameterException, OperationFailedException {
 804  
         // TODO Auto-generated method stub
 805  1
         return null;
 806  
     }
 807  
 
 808  
     @Override
 809  
     public List<ValidationResultInfo> validateMajorDiscipline(
 810  
             String validationType, MajorDisciplineInfo majorDisciplineInfo)
 811  
             throws InvalidParameterException,
 812  
             MissingParameterException, OperationFailedException {
 813  
 
 814  9
         List<ValidationResultInfo> validationResults = new ArrayList<ValidationResultInfo>();
 815  9
         if ( ! ProgramAssemblerConstants.DRAFT.equalsIgnoreCase(majorDisciplineInfo.getState()) ) {
 816  6
             ObjectStructureDefinition objStructure = this.getObjectStructure(MajorDisciplineInfo.class.getName());
 817  6
             Validator validator = validatorFactory.getValidator();
 818  6
             validationResults.addAll(validator.validateObject(majorDisciplineInfo, objStructure));
 819  
         }
 820  9
         validateMajorDisciplineAtps(majorDisciplineInfo,validationResults);
 821  9
         return validationResults;
 822  
     }
 823  
 
 824  
     @Override
 825  
     public List<ValidationResultInfo> validateMinorDiscipline(
 826  
             String validationType, MinorDisciplineInfo minorDisciplineInfo)
 827  
             throws InvalidParameterException,
 828  
             MissingParameterException, OperationFailedException {
 829  
         // TODO Auto-generated method stub
 830  1
         return null;
 831  
     }
 832  
 
 833  
     @Override
 834  
     public List<ValidationResultInfo> validateProgramRequirement(
 835  
             String validationType, ProgramRequirementInfo programRequirementInfo)
 836  
             throws InvalidParameterException,
 837  
             MissingParameterException, OperationFailedException {
 838  
 
 839  7
         ObjectStructureDefinition objStructure = this.getObjectStructure(ProgramRequirementInfo.class.getName());
 840  7
         Validator validator = validatorFactory.getValidator();
 841  7
         List<ValidationResultInfo> validationResults = validator.validateObject(programRequirementInfo, objStructure);
 842  
 
 843  7
         return validationResults;
 844  
     }
 845  
 
 846  
     @Override
 847  
     public ObjectStructureDefinition getObjectStructure(String objectTypeKey) {
 848  16
         return dictionaryService.getObjectStructure(objectTypeKey);
 849  
     }
 850  
 
 851  
     @Override
 852  
     public List<String> getObjectTypes() {
 853  1
         return dictionaryService.getObjectTypes();
 854  
     }
 855  
 
 856  
     @Override
 857  
     public SearchCriteriaTypeInfo getSearchCriteriaType(
 858  
             String searchCriteriaTypeKey) throws DoesNotExistException,
 859  
             InvalidParameterException, MissingParameterException,
 860  
             OperationFailedException {
 861  
         // TODO Auto-generated method stub
 862  1
         return null;
 863  
     }
 864  
 
 865  
     @Override
 866  
     public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes()
 867  
             throws OperationFailedException {
 868  
         // TODO Auto-generated method stub
 869  1
         return null;
 870  
     }
 871  
 
 872  
     @Override
 873  
     public SearchResultTypeInfo getSearchResultType(String searchResultTypeKey)
 874  
             throws DoesNotExistException, InvalidParameterException,
 875  
             MissingParameterException, OperationFailedException {
 876  
         // TODO Auto-generated method stub
 877  1
         return null;
 878  
     }
 879  
 
 880  
     @Override
 881  
     public List<SearchResultTypeInfo> getSearchResultTypes()
 882  
             throws OperationFailedException {
 883  
         // TODO Auto-generated method stub
 884  1
         return null;
 885  
     }
 886  
 
 887  
     @Override
 888  
     public SearchTypeInfo getSearchType(String searchTypeKey)
 889  
             throws DoesNotExistException, InvalidParameterException,
 890  
             MissingParameterException, OperationFailedException {
 891  
         // TODO Auto-generated method stub
 892  1
         return null;
 893  
     }
 894  
 
 895  
     @Override
 896  
     public List<SearchTypeInfo> getSearchTypes()
 897  
             throws OperationFailedException {
 898  
         // TODO Auto-generated method stub
 899  1
         return null;
 900  
     }
 901  
 
 902  
     @Override
 903  
     public List<SearchTypeInfo> getSearchTypesByCriteria(
 904  
             String searchCriteriaTypeKey) throws DoesNotExistException,
 905  
             InvalidParameterException, MissingParameterException,
 906  
             OperationFailedException {
 907  
         // TODO Auto-generated method stub
 908  1
         return null;
 909  
     }
 910  
 
 911  
     @Override
 912  
     public List<SearchTypeInfo> getSearchTypesByResult(
 913  
             String searchResultTypeKey) throws DoesNotExistException,
 914  
             InvalidParameterException, MissingParameterException,
 915  
             OperationFailedException {
 916  
         // TODO Auto-generated method stub
 917  1
         return null;
 918  
     }
 919  
 
 920  
     @Override
 921  
     public SearchResult search(SearchRequest searchRequest)
 922  
             throws MissingParameterException {
 923  
         // TODO Auto-generated method stub
 924  1
         return null;
 925  
     }
 926  
 
 927  
     /**
 928  
      * Check for missing parameter and throw localized exception if missing
 929  
      *
 930  
      * @param param
 931  
      * @param parameter name
 932  
      * @throws MissingParameterException
 933  
      */
 934  
     private void checkForMissingParameter(Object param, String paramName)
 935  
             throws MissingParameterException {
 936  33
         if (param == null) {
 937  2
             throw new MissingParameterException(paramName + " can not be null");
 938  
         }
 939  31
     }
 940  
 
 941  
     // TODO - when CRUD for a second ProgramInfo is implemented, pull common code up from its process*() and this
 942  
 
 943  
     private MajorDisciplineInfo processMajorDisciplineInfo(MajorDisciplineInfo majorDisciplineInfo, NodeOperation operation) throws AssemblyException {
 944  
 
 945  9
         BaseDTOAssemblyNode<MajorDisciplineInfo, CluInfo> results = majorDisciplineAssembler.disassemble(majorDisciplineInfo, operation);
 946  9
         invokeServiceCalls(results);
 947  9
         return results.getBusinessDTORef();
 948  
     }
 949  
 
 950  
     private CredentialProgramInfo processCredentialProgramInfo(CredentialProgramInfo credentialProgramInfo, NodeOperation operation) throws AssemblyException {
 951  
 
 952  2
         BaseDTOAssemblyNode<CredentialProgramInfo, CluInfo> results = credentialProgramAssembler.disassemble(credentialProgramInfo, operation);
 953  2
         invokeServiceCalls(results);
 954  2
         return results.getBusinessDTORef();
 955  
     }
 956  
 
 957  
     private ProgramRequirementInfo processProgramRequirement(ProgramRequirementInfo programRequirementInfo, NodeOperation operation) throws AssemblyException {
 958  9
         BaseDTOAssemblyNode<ProgramRequirementInfo, CluInfo> results = programRequirementAssembler.disassemble(programRequirementInfo, operation);
 959  9
         invokeServiceCalls(results);
 960  9
         return results.getBusinessDTORef();
 961  
     }
 962  
 
 963  
         private void invokeServiceCalls(BaseDTOAssemblyNode<?, CluInfo> results) throws AssemblyException{
 964  
         // Use the results to make the appropriate service calls here
 965  
         try {
 966  24
             programServiceMethodInvoker.invokeServiceCalls(results);
 967  0
         } catch (AssemblyException e) {
 968  0
                 throw e;
 969  0
         } catch (Exception e) {
 970  0
             throw new AssemblyException(e);
 971  24
         }
 972  24
     }
 973  
 
 974  
     //Spring setters. Used by spring container to inject corresponding dependencies.
 975  
 
 976  
     public void setLuService(LuService luService) {
 977  1
         this.luService = luService;
 978  1
     }
 979  
 
 980  
     public LuService getLuService() {
 981  0
                 return luService;
 982  
         }
 983  
 
 984  
         public void setDictionaryService(DictionaryService dictionaryService) {
 985  1
         this.dictionaryService = dictionaryService;
 986  1
     }
 987  
 
 988  
     public DictionaryService getDictionaryService() {
 989  0
                 return dictionaryService;
 990  
         }
 991  
 
 992  
     public void setSearchManager(SearchManager searchManager) {
 993  0
         this.searchManager = searchManager;
 994  0
     }
 995  
     
 996  
         public SearchManager getSearchManager() {
 997  0
                 return searchManager;
 998  
         }
 999  
 
 1000  
         public void setMajorDisciplineAssembler(MajorDisciplineAssembler majorDisciplineAssembler) {
 1001  1
         this.majorDisciplineAssembler = majorDisciplineAssembler;
 1002  1
     }
 1003  
 
 1004  
         public MajorDisciplineAssembler getMajorDisciplineAssembler() {
 1005  0
                 return majorDisciplineAssembler;
 1006  
         }
 1007  
 
 1008  
         public void setCredentialProgramAssembler(
 1009  
                         CredentialProgramAssembler credentialProgramAssembler) {
 1010  1
                 this.credentialProgramAssembler = credentialProgramAssembler;
 1011  1
         }
 1012  
 
 1013  
         public CredentialProgramAssembler getCredentialProgramAssembler() {
 1014  0
                 return credentialProgramAssembler;
 1015  
         }
 1016  
 
 1017  
         public void setProgramRequirementAssembler(ProgramRequirementAssembler programRequirementAssembler) {
 1018  1
         this.programRequirementAssembler = programRequirementAssembler;
 1019  1
     }
 1020  
 
 1021  
     public ProgramRequirementAssembler getProgramRequirementAssembler() {
 1022  0
                 return programRequirementAssembler;
 1023  
         }
 1024  
 
 1025  
         public void setProgramServiceMethodInvoker(BusinessServiceMethodInvoker serviceMethodInvoker) {
 1026  1
         this.programServiceMethodInvoker = serviceMethodInvoker;
 1027  1
     }
 1028  
 
 1029  
     public BusinessServiceMethodInvoker getProgramServiceMethodInvoker() {
 1030  0
                 return programServiceMethodInvoker;
 1031  
         }
 1032  
 
 1033  
         public void setValidatorFactory(ValidatorFactory validatorFactory) {
 1034  1
         this.validatorFactory = validatorFactory;
 1035  1
     }
 1036  
 
 1037  
         public ValidatorFactory getValidatorFactory() {
 1038  0
                 return validatorFactory;
 1039  
         }
 1040  
         
 1041  
         public void setCoreProgramAssembler(CoreProgramAssembler coreProgramAssembler) {
 1042  1
                 this.coreProgramAssembler = coreProgramAssembler;
 1043  1
         }
 1044  
 
 1045  
         public CoreProgramAssembler getCoreProgramAssembler() {
 1046  0
                 return coreProgramAssembler;
 1047  
         }
 1048  
 
 1049  
         private StatusInfo getStatus(){
 1050  2
         StatusInfo status = new StatusInfo();
 1051  2
         status.setSuccess(true);
 1052  2
         return status;
 1053  
         }
 1054  
 
 1055  
     private CoreProgramInfo processCoreProgramInfo(CoreProgramInfo coreProgramInfo, NodeOperation operation) throws AssemblyException {
 1056  
 
 1057  4
         BaseDTOAssemblyNode<CoreProgramInfo, CluInfo> results = coreProgramAssembler.disassemble(coreProgramInfo, operation);
 1058  4
         invokeServiceCalls(results);
 1059  4
         return results.getBusinessDTORef();
 1060  
     }
 1061  
 
 1062  
     @Override
 1063  
     public CoreProgramInfo createCoreProgram(CoreProgramInfo coreProgramInfo) throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 1064  3
         checkForMissingParameter(coreProgramInfo, "CoreProgramInfo");
 1065  
         
 1066  
         // Validate
 1067  3
         List<ValidationResultInfo> validationResults = validateCoreProgram("OBJECT", coreProgramInfo);
 1068  3
         if (null != validationResults && validationResults.size() > 0) {
 1069  0
             throw new DataValidationErrorException("Validation error!", validationResults);
 1070  
         }
 1071  
 
 1072  
         try {
 1073  3
             return processCoreProgramInfo(coreProgramInfo, NodeOperation.CREATE);
 1074  0
         } catch (AssemblyException e) {
 1075  0
             LOG.error("Error disassembling CoreProgram", e);
 1076  0
             throw new OperationFailedException("Error disassembling CoreProgram");
 1077  
         }
 1078  
     }
 1079  
 
 1080  
         @Override
 1081  
         public CoreProgramInfo createNewCoreProgramVersion(
 1082  
                         String coreProgramId, String versionComment)
 1083  
                         throws DoesNotExistException, InvalidParameterException,
 1084  
                         MissingParameterException, OperationFailedException,
 1085  
                         PermissionDeniedException, VersionMismatchException,
 1086  
                         DataValidationErrorException {
 1087  
                 //step one, get the original
 1088  2
                 VersionDisplayInfo currentVersion = luService.getCurrentVersion(LuServiceConstants.CLU_NAMESPACE_URI, coreProgramId);
 1089  2
                 CoreProgramInfo originalCoreProgram = getCoreProgram(currentVersion.getId());
 1090  
 
 1091  
                 //Version the Clu
 1092  2
                 CluInfo newVersionClu = luService.createNewCluVersion(coreProgramId, versionComment);
 1093  
 
 1094  
                 try {
 1095  
                 BaseDTOAssemblyNode<CoreProgramInfo, CluInfo> results;
 1096  
 
 1097  
                 //Integrate changes into the original. (should this just be just the id?)
 1098  2
                         coreProgramAssembler.assemble(newVersionClu, originalCoreProgram, true);
 1099  
 
 1100  
                         //Clear Ids from the original so it will make a copy and do other processing
 1101  2
                         processCopy(originalCoreProgram, currentVersion.getId());
 1102  
 
 1103  
                         //Disassemble the new
 1104  2
                         results = coreProgramAssembler.disassemble(originalCoreProgram, NodeOperation.UPDATE);
 1105  
 
 1106  
                         // Use the results to make the appropriate service calls here
 1107  2
                         programServiceMethodInvoker.invokeServiceCalls(results);
 1108  
 
 1109  2
                         return results.getBusinessDTORef();
 1110  0
                 } catch(AssemblyException e) {
 1111  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 1112  0
                 } catch (AlreadyExistsException e) {
 1113  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 1114  0
                 } catch (DependentObjectsExistException e) {
 1115  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 1116  0
                 } catch (CircularRelationshipException e) {
 1117  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 1118  0
                 } catch (UnsupportedActionException e) {
 1119  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 1120  0
                 } catch (CircularReferenceException e) {
 1121  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 1122  
                 }
 1123  
         }
 1124  
     
 1125  
 
 1126  
 
 1127  
         @Override
 1128  
     public StatusInfo deleteCoreProgram(String coreProgramId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 1129  
 //        try {
 1130  
 //                CoreProgramInfo coreProgramInfo = getCoreProgram(coreProgramId);
 1131  
 //
 1132  
 //            processCoreProgramInfo(coreProgramInfo, NodeOperation.DELETE);
 1133  
 //
 1134  
 //            return getStatus();
 1135  
 //
 1136  
 //        } catch (AssemblyException e) {
 1137  
 //            LOG.error("Error disassembling CoreProgram", e);
 1138  
 //            throw new OperationFailedException("Error disassembling CoreProgram");
 1139  
 //        }
 1140  1
             throw new OperationFailedException("Deletion of CoreProgram is not supported."); 
 1141  
     }
 1142  
 
 1143  
     @Override
 1144  
     public CoreProgramInfo getCoreProgram(String coreProgramId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 1145  7
             CoreProgramInfo coreProgramInfo = null;
 1146  
 
 1147  
         try {
 1148  7
             CluInfo clu = luService.getClu(coreProgramId);
 1149  7
             if ( ! ProgramAssemblerConstants.CORE_PROGRAM.equals(clu.getType()) ) {
 1150  1
                 throw new DoesNotExistException("Specified CLU is not a CoreProgram");
 1151  
             }
 1152  6
             coreProgramInfo = coreProgramAssembler.assemble(clu, null, false);
 1153  0
         } catch (AssemblyException e) {
 1154  0
             LOG.error("Error assembling CoreProgram", e);
 1155  0
             throw new OperationFailedException("Error assembling CoreProgram");
 1156  6
         }
 1157  6
         return coreProgramInfo;
 1158  
                 // comment out the above, and uncomment below to get auto-generated data
 1159  
         // (and vice-versa)
 1160  
 //                try {
 1161  
 //                        return new CoreProgramDataGenerator().getCoreProgramInfoTestData();
 1162  
 //                } catch (Exception e) {
 1163  
 //                        return null;
 1164  
 //                }
 1165  
     }
 1166  
 
 1167  
     @Override
 1168  
     public CoreProgramInfo updateCoreProgram(CoreProgramInfo coreProgramInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, VersionMismatchException, OperationFailedException, PermissionDeniedException {
 1169  1
         checkForMissingParameter(coreProgramInfo, "CoreProgramInfo");
 1170  
         
 1171  
         // Validate
 1172  1
         List<ValidationResultInfo> validationResults = validateCoreProgram("OBJECT", coreProgramInfo);
 1173  1
         if (null != validationResults && validationResults.size() > 0) {
 1174  0
             throw new DataValidationErrorException("Validation error!", validationResults);
 1175  
         }
 1176  
 
 1177  
         try {
 1178  
 
 1179  1
             return processCoreProgramInfo(coreProgramInfo, NodeOperation.UPDATE);
 1180  
 
 1181  0
         } catch (AssemblyException e) {
 1182  0
             LOG.error("Error disassembling CoreProgram", e);
 1183  0
             throw new OperationFailedException("Error disassembling CoreProgram");
 1184  
         }
 1185  
     }
 1186  
 
 1187  
     @Override
 1188  
     public List<ValidationResultInfo> validateCoreProgram(String validationType, CoreProgramInfo coreProgramInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException {
 1189  4
         List<ValidationResultInfo> validationResults = new ArrayList<ValidationResultInfo>();
 1190  4
         if ( ! ProgramAssemblerConstants.DRAFT.equals(coreProgramInfo.getState()) ) {
 1191  1
                 ObjectStructureDefinition objStructure = this.getObjectStructure(CoreProgramInfo.class.getName());
 1192  1
                 Validator validator = validatorFactory.getValidator();
 1193  1
             validationResults.addAll(validator.validateObject(coreProgramInfo, objStructure));
 1194  
         }
 1195  4
         return validationResults;
 1196  
     }
 1197  
         
 1198  
         
 1199  
         @Override
 1200  
         public CredentialProgramInfo createNewCredentialProgramVersion(
 1201  
                         String credentialProgramId, String versionComment)
 1202  
                         throws DoesNotExistException, InvalidParameterException,
 1203  
                         MissingParameterException, OperationFailedException,
 1204  
                         PermissionDeniedException, VersionMismatchException,
 1205  
                         DataValidationErrorException {
 1206  
                 //step one, get the original
 1207  0
                 VersionDisplayInfo currentVersion = luService.getCurrentVersion(LuServiceConstants.CLU_NAMESPACE_URI, credentialProgramId);
 1208  0
                 CredentialProgramInfo originaCredentialProgram = getCredentialProgram(currentVersion.getId());
 1209  
 
 1210  
                 //Version the Clu
 1211  0
                 CluInfo newVersionClu = luService.createNewCluVersion(credentialProgramId, versionComment);
 1212  
 
 1213  
                 try {
 1214  
                 BaseDTOAssemblyNode<CredentialProgramInfo, CluInfo> results;
 1215  
 
 1216  
                 //Integrate changes into the original. (should this just be just the id?)
 1217  0
                         credentialProgramAssembler.assemble(newVersionClu, originaCredentialProgram, true);
 1218  
 
 1219  
                         //Clear Ids from the original so it will make a copy and do other processing
 1220  0
                         processCopy(originaCredentialProgram, currentVersion.getId());
 1221  
 
 1222  
                         //Disassemble the new
 1223  0
                         results = credentialProgramAssembler.disassemble(originaCredentialProgram, NodeOperation.UPDATE);
 1224  
 
 1225  
                         // Use the results to make the appropriate service calls here
 1226  0
                         programServiceMethodInvoker.invokeServiceCalls(results);
 1227  
 
 1228  0
                         return results.getBusinessDTORef();
 1229  0
                 } catch(AssemblyException e) {
 1230  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 1231  0
                 } catch (AlreadyExistsException e) {
 1232  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 1233  0
                 } catch (DependentObjectsExistException e) {
 1234  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 1235  0
                 } catch (CircularRelationshipException e) {
 1236  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 1237  0
                 } catch (UnsupportedActionException e) {
 1238  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 1239  0
                 } catch (CircularReferenceException e) {
 1240  0
                         throw new OperationFailedException("Error creating new MajorDiscipline version",e);
 1241  
                 }
 1242  
         }
 1243  
 
 1244  
 
 1245  
         @Override
 1246  
         public StatusInfo setCurrentCoreProgramVersion(String coreProgramId,
 1247  
                         Date currentVersionStart) throws DoesNotExistException,
 1248  
                         InvalidParameterException, MissingParameterException,
 1249  
                         IllegalVersionSequencingException, OperationFailedException,
 1250  
                         PermissionDeniedException {
 1251  1
                 StatusInfo status = luService.setCurrentCluVersion(coreProgramId, currentVersionStart);
 1252  
                 
 1253  1
                 return status;
 1254  
         }
 1255  
 
 1256  
         @Override
 1257  
         public StatusInfo setCurrentCredentialProgramVersion(
 1258  
                         String credentialProgramId, Date currentVersionStart)
 1259  
                         throws DoesNotExistException, InvalidParameterException,
 1260  
                         MissingParameterException, IllegalVersionSequencingException,
 1261  
                         OperationFailedException, PermissionDeniedException {
 1262  0
                 StatusInfo status = luService.setCurrentCluVersion(credentialProgramId, currentVersionStart);
 1263  
                 
 1264  0
                 return status;
 1265  
         }
 1266  
 
 1267  
         @Override
 1268  
         public VersionDisplayInfo getCurrentVersion(String refObjectTypeURI,
 1269  
                         String refObjectId) throws DoesNotExistException,
 1270  
                         InvalidParameterException, MissingParameterException,
 1271  
                         OperationFailedException, PermissionDeniedException {
 1272  1
                 if(ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI.equals(refObjectTypeURI)){
 1273  0
                         return luService.getCurrentVersion(LuServiceConstants.CLU_NAMESPACE_URI, refObjectId);
 1274  
                 }
 1275  1
                 throw new InvalidParameterException("Object type: " + refObjectTypeURI + " is not known to this implementation");
 1276  
         }
 1277  
 
 1278  
         @Override
 1279  
         public VersionDisplayInfo getCurrentVersionOnDate(String refObjectTypeURI,
 1280  
                         String refObjectId, Date date) throws DoesNotExistException,
 1281  
                         InvalidParameterException, MissingParameterException,
 1282  
                         OperationFailedException, PermissionDeniedException {
 1283  1
                 if(ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI.equals(refObjectTypeURI)){
 1284  0
                         return luService.getCurrentVersionOnDate(LuServiceConstants.CLU_NAMESPACE_URI, refObjectId, date);
 1285  
                 }
 1286  1
                 throw new InvalidParameterException("Object type: " + refObjectTypeURI + " is not known to this implementation");
 1287  
         }
 1288  
 
 1289  
         @Override
 1290  
         public VersionDisplayInfo getFirstVersion(String refObjectTypeURI,
 1291  
                         String refObjectId) throws DoesNotExistException,
 1292  
                         InvalidParameterException, MissingParameterException,
 1293  
                         OperationFailedException, PermissionDeniedException {
 1294  1
                 if(ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI.equals(refObjectTypeURI)){
 1295  0
                         return luService.getFirstVersion(LuServiceConstants.CLU_NAMESPACE_URI, refObjectId);
 1296  
                 }
 1297  1
                 throw new InvalidParameterException("Object type: " + refObjectTypeURI + " is not known to this implementation");
 1298  
 
 1299  
         }
 1300  
 
 1301  
         @Override
 1302  
         public VersionDisplayInfo getLatestVersion(String refObjectTypeURI,
 1303  
                         String refObjectId) throws DoesNotExistException,
 1304  
                         InvalidParameterException, MissingParameterException,
 1305  
                         OperationFailedException, PermissionDeniedException {
 1306  0
                 if(ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI.equals(refObjectTypeURI)){
 1307  0
                         return luService.getLatestVersion(LuServiceConstants.CLU_NAMESPACE_URI, refObjectId);
 1308  
                 }
 1309  0
                 throw new InvalidParameterException("Object type: " + refObjectTypeURI + " is not known to this implementation");
 1310  
 
 1311  
         }
 1312  
 
 1313  
         @Override
 1314  
         public VersionDisplayInfo getVersionBySequenceNumber(
 1315  
                         String refObjectTypeURI, String refObjectId, Long sequence)
 1316  
                         throws DoesNotExistException, InvalidParameterException,
 1317  
                         MissingParameterException, OperationFailedException,
 1318  
                         PermissionDeniedException {
 1319  1
                 if(ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI.equals(refObjectTypeURI)){
 1320  0
                         return luService.getVersionBySequenceNumber(LuServiceConstants.CLU_NAMESPACE_URI, refObjectId, sequence);
 1321  
                 }
 1322  1
                 throw new InvalidParameterException("Object type: " + refObjectTypeURI + " is not known to this implementation");
 1323  
         }
 1324  
 
 1325  
         @Override
 1326  
         public List<VersionDisplayInfo> getVersions(String refObjectTypeURI,
 1327  
                         String refObjectId) throws DoesNotExistException,
 1328  
                         InvalidParameterException, MissingParameterException,
 1329  
                         OperationFailedException, PermissionDeniedException {
 1330  1
                 if(ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI.equals(refObjectTypeURI)){
 1331  0
                         return luService.getVersions(LuServiceConstants.CLU_NAMESPACE_URI, refObjectId);
 1332  
                 }
 1333  1
                 throw new InvalidParameterException("Object type: " + refObjectTypeURI + " is not known to this implementation");
 1334  
         }
 1335  
 
 1336  
         @Override
 1337  
         public List<VersionDisplayInfo> getVersionsInDateRange(
 1338  
                         String refObjectTypeURI, String refObjectId, Date from, Date to)
 1339  
                         throws DoesNotExistException, InvalidParameterException,
 1340  
                         MissingParameterException, OperationFailedException,
 1341  
                         PermissionDeniedException {
 1342  1
                 if(ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI.equals(refObjectTypeURI)){
 1343  0
                         return luService.getVersionsInDateRange(LuServiceConstants.CLU_NAMESPACE_URI, refObjectId, from, to);
 1344  
                 }
 1345  1
                 throw new InvalidParameterException("Object type: " + refObjectTypeURI + " is not known to this implementation");
 1346  
         }
 1347  
 
 1348  
         public void setAtpService(AtpService atpService) {
 1349  1
                 this.atpService = atpService;
 1350  1
         }
 1351  
 
 1352  
         public AtpService getAtpService() {
 1353  0
                 return atpService;
 1354  
         }
 1355  
 
 1356  
         private void validateMajorDisciplineAtps(MajorDisciplineInfo majorDisciplineInfo, List<ValidationResultInfo> validationResults) throws InvalidParameterException, MissingParameterException, OperationFailedException{
 1357  
                 
 1358  9
                 String startTerm = majorDisciplineInfo.getStartTerm();
 1359  
                 
 1360  9
                 if(!isEmpty(majorDisciplineInfo.getAttributes().get("endInstAdmitTerm"))){
 1361  0
                         compareAtps(startTerm, majorDisciplineInfo.getAttributes().get("endInstAdmitTerm"), validationResults, "End Inst Admin Term", "endInstAdmitTerm");
 1362  
                 }
 1363  
                 
 1364  9
                 if(!isEmpty(majorDisciplineInfo.getEndProgramEntryTerm())){
 1365  9
                         compareAtps(startTerm, majorDisciplineInfo.getEndProgramEntryTerm(), validationResults, "End Program Entry Term", "endProgramEntryTerm");
 1366  
                 }
 1367  
                 
 1368  9
                 if(!isEmpty(majorDisciplineInfo.getEndTerm())){
 1369  9
                         compareAtps(startTerm, majorDisciplineInfo.getEndTerm(), validationResults, "End Program Enroll Term", "endTerm");
 1370  
                 }                
 1371  
                 
 1372  9
                 List<ProgramVariationInfo> variations = majorDisciplineInfo.getVariations();
 1373  9
                 if(variations != null && !variations.isEmpty()){
 1374  9
                         int idx = 0;
 1375  9
                         for(ProgramVariationInfo variation : variations){
 1376  19
                                 validateVariationAtps(variation, validationResults, idx);
 1377  19
                                 idx ++;
 1378  
                         }
 1379  
                 }
 1380  9
         }
 1381  
 
 1382  
         private void validateVariationAtps(ProgramVariationInfo programVariationInfo, List<ValidationResultInfo> validationResults, int idx) throws InvalidParameterException, MissingParameterException, OperationFailedException{
 1383  
                 
 1384  19
                 String startTerm = programVariationInfo.getStartTerm();
 1385  
                 
 1386  19
                 if(!isEmpty(programVariationInfo.getAttributes().get("endInstAdmitTerm"))){
 1387  0
                         compareAtps(startTerm, programVariationInfo.getAttributes().get("endInstAdmitTerm"), validationResults, "End Inst Admin Term",  "variations/" + idx + "/endInstAdmitTerm");
 1388  
                 }
 1389  
         
 1390  19
                 if(!isEmpty(programVariationInfo.getEndProgramEntryTerm())){
 1391  19
                         compareAtps(startTerm, programVariationInfo.getEndProgramEntryTerm(), validationResults, "End Program Entry Term", "variations/" + idx + "/endProgramEntryTerm");
 1392  
                 }
 1393  
                 
 1394  19
                 if(!isEmpty(programVariationInfo.getEndTerm())){
 1395  19
                         compareAtps(startTerm, programVariationInfo.getEndTerm(), validationResults, "End Program Enroll Term", "variations/" + idx + "/endTerm");
 1396  
                 }
 1397  19
         }
 1398  
         
 1399  
         private AtpInfo getAtpInfo(String atpKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException{
 1400  56
                 return atpService.getAtp(atpKey);
 1401  
         }
 1402  
         
 1403  
         private void compareAtps(String aptKey1, String aptKey2, List<ValidationResultInfo> validationResults, String field, String path) throws InvalidParameterException, MissingParameterException, OperationFailedException{
 1404  56
                 AtpInfo atpInfo1 = null;
 1405  56
                 AtpInfo atpInfo2 = null;
 1406  
                 
 1407  
                 try{
 1408  56
                         atpInfo1 = getAtpInfo(aptKey1);
 1409  0
                         atpInfo2 = getAtpInfo(aptKey2);
 1410  0
                 }catch(DoesNotExistException e){}
 1411  
                 
 1412  56
                 if(atpInfo1 != null && atpInfo1 != null){
 1413  0
                         if(atpInfo1.getStartDate()!= null && atpInfo2.getStartDate() != null){                        
 1414  0
                                 boolean compareResult = ValidatorUtils.compareValues(atpInfo2.getStartDate(), atpInfo1.getStartDate(), DataType.DATE, "greater_than", true, new ServerDateParser());
 1415  0
                                 if(!compareResult){
 1416  0
                                         ValidationResultInfo vri = new ValidationResultInfo();
 1417  0
                                         vri.setElement(path);
 1418  0
                                         vri.setError(field + " should be greater than Start Term");
 1419  0
                                         validationResults.add(vri);
 1420  
                                 }
 1421  
                         }
 1422  
                 }
 1423  
                         
 1424  56
         }
 1425  
         
 1426  
         private boolean isEmpty(String value){
 1427  84
                 return value == null || (value != null && "".equals(value));
 1428  
         }
 1429  
 
 1430  
         public void setDocumentService(DocumentService documentService) {
 1431  1
                 this.documentService = documentService;
 1432  1
         }
 1433  
 
 1434  
         public DocumentService getDocumentService() {
 1435  0
                 return documentService;
 1436  
         }
 1437  
 
 1438  
 }