Coverage Report - org.kuali.student.lum.program.server.transform.VersionCredentialProgramFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
VersionCredentialProgramFilter
0%
0/23
0%
0/8
5
 
 1  
 package org.kuali.student.lum.program.server.transform;
 2  
 
 3  
 import java.util.Map;
 4  
 
 5  
 import org.kuali.student.core.assembly.data.Data;
 6  
 import org.kuali.student.core.assembly.data.Metadata;
 7  
 import org.kuali.student.lum.program.client.ProgramConstants;
 8  
 import org.kuali.student.lum.program.dto.CredentialProgramInfo;
 9  
 
 10  
 /**
 11  
  * When credential program is activated this filter sets the previous version to superseded and updates the end program
 12  
  * entry and and enroll terms. 
 13  
  * 
 14  
  * @author Will
 15  
  *
 16  
  */
 17  0
 public class VersionCredentialProgramFilter extends VersionProgramFilter {
 18  
 
 19  
         @Override
 20  
         public void applyOutboundDataFilter(Data data, Metadata metadata,
 21  
                         Map<String, Object> properties) throws Exception {
 22  0
                 Data previousVersionData = (Data)properties.get(VersionProgramFilter.PREVIOUS_VERSION_DATA);
 23  0
                 String versionFromId = data.query(ProgramConstants.VERSION_FROM_ID);
 24  
                 
 25  0
                 if (versionFromId != null){
 26  0
                         CredentialProgramInfo previousVersionCoreInfo = programService.getCredentialProgram(versionFromId);
 27  
                         
 28  0
                         if (previousVersionData == null){
 29  
                                 //This is an initial get. Create previous version data to send back to client 
 30  0
                                 previousVersionData = new Data();
 31  0
                                 previousVersionData.set(ProgramConstants.ID, previousVersionCoreInfo.getId());
 32  0
                                 previousVersionData.set(ProgramConstants.END_PROGRAM_ENTRY_TERM, previousVersionCoreInfo.getEndProgramEntryTerm());
 33  0
                                 previousVersionData.set(ProgramConstants.END_PROGRAM_ENROLL_TERM, previousVersionCoreInfo.getEndTerm());
 34  0
                                 previousVersionData.set(ProgramConstants.STATE, previousVersionCoreInfo.getState());
 35  
                         } else {
 36  
                                 //This is a save operation. Check state field change for previous version state, indicating an "Activate" action,
 37  
                                 //which requires updating previous program with new states and end terms and setting activated program
 38  
                                 //to be the current version.
 39  
                                 
 40  0
                                 String state = previousVersionData.get(ProgramConstants.STATE);
 41  0
                                 if (state!= null && !state.equals(previousVersionCoreInfo.getState())){
 42  
                                         //Update previous program version with new state and terms
 43  0
                                         String endEntryTerm = previousVersionData.get(ProgramConstants.END_PROGRAM_ENTRY_TERM); 
 44  0
                                         String endEnrollTerm = previousVersionData.get(ProgramConstants.END_PROGRAM_ENROLL_TERM);
 45  
 
 46  0
                                         previousVersionCoreInfo.setState(state);
 47  0
                                         previousVersionCoreInfo.setEndProgramEntryTerm(endEntryTerm);
 48  0
                                         previousVersionCoreInfo.setEndTerm(endEnrollTerm);
 49  
                                         
 50  0
                                         programService.updateCredentialProgram(previousVersionCoreInfo);
 51  
                                                                 
 52  
                                         //Set "activated" program to be the current version
 53  0
                                         String activatedCoreId = data.get(ProgramConstants.ID);
 54  0
                                         programService.setCurrentCredentialProgramVersion(activatedCoreId, null);
 55  
                                 }
 56  
 
 57  
                         }
 58  
                         
 59  0
                         data.set(PREVIOUS_VERSION_INFO, previousVersionData);
 60  
                 }                
 61  0
         }
 62  
 
 63  
 }