Coverage Report - org.kuali.student.lum.program.server.transform.VersionProgramFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
VersionProgramFilter
0%
0/51
0%
0/10
1.714
 
 1  
 package org.kuali.student.lum.program.server.transform;
 2  
 
 3  
 import java.util.Map;
 4  
 
 5  
 import org.kuali.student.common.assembly.data.Data;
 6  
 import org.kuali.student.common.assembly.data.Data.DataType;
 7  
 import org.kuali.student.common.assembly.data.Data.StringKey;
 8  
 import org.kuali.student.common.assembly.data.Metadata;
 9  
 import org.kuali.student.common.assembly.data.QueryPath;
 10  
 import org.kuali.student.common.assembly.dictionary.MetadataServiceImpl;
 11  
 import org.kuali.student.common.assembly.transform.AbstractDataFilter;
 12  
 import org.kuali.student.common.assembly.transform.MetadataFilter;
 13  
 import org.kuali.student.common.ui.client.mvc.DataModelDefinition;
 14  
 import org.kuali.student.lum.program.client.ProgramConstants;
 15  
 import org.kuali.student.lum.program.dto.MajorDisciplineInfo;
 16  
 import org.kuali.student.lum.program.service.ProgramService;
 17  
 
 18  
 /**
 19  
  * Generating metadata and populating data model values for previous end term and enroll term
 20  
  * fields to be displayed on activate dialog.  These values do not exist in the MajorDiscipline
 21  
  * object. 
 22  
  * so we need to g
 23  
  * 
 24  
  * 
 25  
  * 
 26  
  * @author Will
 27  
  *
 28  
  */
 29  0
 public class VersionProgramFilter extends AbstractDataFilter implements MetadataFilter{
 30  
         public static final String PREVIOUS_VERSION_DATA = "VersionProgramFilter.PreviousVersionData";
 31  
         public static final String PREVIOUS_VERSION_INFO = "proposal";
 32  
         
 33  
         private Metadata previousVersionMetadata;
 34  
         protected ProgramService programService; 
 35  
         protected MetadataServiceImpl metadataService; 
 36  
         protected String proposalObjectType;
 37  
         /**
 38  
          * Save previousVersionInfo from incoming data to be used by outbound filter
 39  
          */
 40  
         @Override
 41  
         public void applyInboundDataFilter(Data data, Metadata metadata,
 42  
                         Map<String, Object> properties) throws Exception {
 43  0
                 Data previousVersionData = data.query(PREVIOUS_VERSION_INFO);
 44  
 
 45  0
                 if (previousVersionData != null){        
 46  0
                         if(!"kuali.proposal.type.majorDiscipline.modify".equals(previousVersionData.query("type"))){
 47  0
                                 data.remove(new StringKey(PREVIOUS_VERSION_INFO));
 48  
                         }
 49  0
                         properties.put(PREVIOUS_VERSION_DATA, previousVersionData);
 50  
                 }                        
 51  0
         }
 52  
 
 53  
         /**
 54  
          * Adds previous version information to the data if it exists and updates the previous version state
 55  
          * if state changed (this happens when program is activated)
 56  
          */
 57  
         @Override
 58  
         public void applyOutboundDataFilter(Data data, Metadata metadata,
 59  
                         Map<String, Object> properties) throws Exception {
 60  0
                 Data previousVersionData = (Data)properties.get(PREVIOUS_VERSION_DATA);
 61  0
                 String versionFromId = data.query(ProgramConstants.VERSION_FROM_ID);
 62  
                 
 63  0
                 if (versionFromId != null){
 64  0
                         if (previousVersionData == null){
 65  0
                                 MajorDisciplineInfo previousVersionMajorInfo = programService.getMajorDiscipline(versionFromId);
 66  
                                 
 67  
                                 //This is an initial get. Create previous version data to send back to client 
 68  0
                                 previousVersionData = new Data();
 69  0
                                 previousVersionData.set(ProgramConstants.ID, previousVersionMajorInfo.getId());
 70  0
                                 previousVersionData.set(ProgramConstants.PREV_END_PROGRAM_ENTRY_TERM, previousVersionMajorInfo.getEndProgramEntryTerm());
 71  0
                                 previousVersionData.set(ProgramConstants.PREV_END_PROGRAM_ENROLL_TERM, previousVersionMajorInfo.getEndTerm());
 72  0
                                 previousVersionData.set(ProgramConstants.PREV_END_INST_ADMIN_TERM, previousVersionMajorInfo.getEndTerm());
 73  0
                                 previousVersionData.set(ProgramConstants.PREV_START_TERM, previousVersionMajorInfo.getStartTerm());
 74  
                         }  
 75  
                         
 76  0
                         data.set(PREVIOUS_VERSION_INFO, previousVersionData);
 77  
                 }                
 78  0
         }
 79  
 
 80  
         /**
 81  
          * Adds previousVersionInfo metadata to metadata returned to client
 82  
          */
 83  
         @Override
 84  
         public void applyMetadataFilter(String dtoName, Metadata metadata,
 85  
                         Map<String, Object> filterProperties) {                
 86  0
                 metadata.getProperties().put(PREVIOUS_VERSION_INFO, getPreviousVersionMetadata(metadata));
 87  0
         }
 88  
 
 89  
         /**
 90  
          * This generates a phantom "previousVersionInfo" metadata using dictionary definitions for fields already
 91  
          * defined for majorDisicplineInfo.
 92  
          * 
 93  
          * @param metadata
 94  
          * @return
 95  
          */
 96  
         protected Metadata getPreviousVersionMetadata(Metadata metadata){
 97  
                 //FIXME possible synchronization issue here with instance variable previousVersionMetadata
 98  0
                 if (previousVersionMetadata == null){
 99  
                         //Get proposal metadata
 100  0
                         Metadata proposalMetadata = metadataService.getMetadata(proposalObjectType);
 101  
                         
 102  
                         //Pull in metadata for specific fields (some from proposal definition and some from program
 103  0
                         DataModelDefinition modelDef = new DataModelDefinition(metadata);
 104  0
                         Metadata programIdMeta = modelDef.getMetadata(QueryPath.parse(ProgramConstants.ID));
 105  0
                         Metadata startTermMeta = proposalMetadata.getProperties().get(ProgramConstants.PREV_START_TERM);
 106  0
                         Metadata endEntryTermMeta = proposalMetadata.getProperties().get(ProgramConstants.PREV_END_PROGRAM_ENTRY_TERM);
 107  0
                         Metadata endEnrollTermMeta = proposalMetadata.getProperties().get(ProgramConstants.PREV_END_PROGRAM_ENROLL_TERM);
 108  0
                         Metadata endInstAdminMeta = proposalMetadata.getProperties().get(ProgramConstants.PREV_END_INST_ADMIN_TERM);
 109  
                         
 110  0
                         endEntryTermMeta.getConstraints().get(0).setRequiredForNextState(true);
 111  0
                         endEnrollTermMeta.getConstraints().get(0).setRequiredForNextState(true);
 112  0
                         endInstAdminMeta.getConstraints().get(0).setRequiredForNextState(true);
 113  
                         
 114  0
                         endEntryTermMeta.getConstraints().get(0).setMinOccurs(1);
 115  0
                         endEnrollTermMeta.getConstraints().get(0).setMinOccurs(1);
 116  0
                         endInstAdminMeta.getConstraints().get(0).setMinOccurs(1);
 117  
                         
 118  0
                         previousVersionMetadata = new Metadata();
 119  0
                         previousVersionMetadata.setDataType(DataType.DATA);
 120  
                                         
 121  0
                         Map<String, Metadata> properties = previousVersionMetadata.getProperties();
 122  0
                         properties.put(ProgramConstants.ID, programIdMeta);
 123  0
                         properties.put(ProgramConstants.PREV_START_TERM, startTermMeta);
 124  0
                         properties.put(ProgramConstants.PREV_END_PROGRAM_ENTRY_TERM, endEntryTermMeta);
 125  0
                         properties.put(ProgramConstants.PREV_END_PROGRAM_ENROLL_TERM, endEnrollTermMeta);
 126  0
                         properties.put(ProgramConstants.PREV_END_INST_ADMIN_TERM, endInstAdminMeta);
 127  
                 }
 128  
                 
 129  0
                 return previousVersionMetadata;
 130  
         }
 131  
         
 132  
         public void setProgramService(ProgramService programService) {
 133  0
                 this.programService = programService;
 134  0
         }
 135  
 
 136  
         public void setMetadataService(MetadataServiceImpl metadataService) {
 137  0
                 this.metadataService = metadataService;
 138  0
         }
 139  
 
 140  
         public void setProposalObjectType(String proposalObjectType) {
 141  0
                 this.proposalObjectType = proposalObjectType;
 142  0
         }        
 143  
 }