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