Coverage Report - org.kuali.student.lum.program.server.MajorDisciplineProposalDataService
 
Classes in this File Line Coverage Branch Coverage Complexity
MajorDisciplineProposalDataService
0%
0/55
0%
0/34
2.818
 
 1  
 package org.kuali.student.lum.program.server;
 2  
 
 3  
 import java.util.HashMap;
 4  
 import java.util.List;
 5  
 import java.util.Map;
 6  
 
 7  
 import org.kuali.student.common.dto.DtoConstants;
 8  
 import org.kuali.student.common.exceptions.InvalidParameterException;
 9  
 import org.kuali.student.common.exceptions.OperationFailedException;
 10  
 import org.kuali.student.common.ui.server.gwt.AbstractDataService;
 11  
 import org.kuali.student.common.validation.dto.ValidationResultInfo;
 12  
 import org.kuali.student.common.versionmanagement.dto.VersionDisplayInfo;
 13  
 import org.kuali.student.core.assembly.transform.ProposalWorkflowFilter;
 14  
 import org.kuali.student.core.atp.dto.AtpInfo;
 15  
 import org.kuali.student.core.atp.service.AtpService;
 16  
 import org.kuali.student.lum.lu.service.LuService;
 17  
 import org.kuali.student.lum.program.client.ProgramClientConstants;
 18  
 import org.kuali.student.lum.program.client.ProgramConstants;
 19  
 import org.kuali.student.lum.program.dto.MajorDisciplineInfo;
 20  
 import org.kuali.student.lum.program.dto.ProgramVariationInfo;
 21  
 import org.kuali.student.lum.program.service.ProgramService;
 22  
 import org.kuali.student.lum.program.service.ProgramServiceConstants;
 23  
 
 24  
 /**
 25  
  * @author Igor
 26  
  */
 27  0
 public class MajorDisciplineProposalDataService extends AbstractDataService {
 28  
 
 29  
     private static final long serialVersionUID = 1L;
 30  
     
 31  
     private ProgramService programService;
 32  
     private LuService luService;
 33  
     private AtpService atpService; 
 34  
 
 35  
     @Override
 36  
     protected String getDefaultWorkflowDocumentType() {
 37  0
         return null;
 38  
     }
 39  
 
 40  
     @Override
 41  
     protected String getDefaultMetaDataState() {
 42  0
         return null;
 43  
     }
 44  
 
 45  
     @Override
 46  
     protected Object get(String id) throws Exception {
 47  
             //TODO Just Major Discipline for now - need to check for other types later
 48  
         MajorDisciplineInfo returnDTO;
 49  0
         if (null == id || id.length() == 0) {
 50  0
             returnDTO = new MajorDisciplineInfo();
 51  0
             returnDTO.setType(ProgramClientConstants.MAJOR_PROGRAM);
 52  0
             returnDTO.setState(DtoConstants.STATE_DRAFT);
 53  0
             returnDTO.setCredentialProgramId(getCredentialId());
 54  
         } else {
 55  0
             returnDTO = programService.getMajorDiscipline(id);
 56  
         }
 57  0
         return returnDTO;
 58  
     }
 59  
 
 60  
     @Override
 61  
     protected Object save(Object dto, Map<String, Object> properties) throws Exception {
 62  0
         if (dto instanceof MajorDisciplineInfo) {
 63  0
             MajorDisciplineInfo mdInfo = (MajorDisciplineInfo) dto;
 64  0
             if (mdInfo.getId() == null && mdInfo.getVersionInfo() != null) {
 65  
                     
 66  0
                     String majorVersionIndId = mdInfo.getVersionInfo().getVersionIndId();
 67  
                     
 68  
                     //Get the current Major Dicipline from the service
 69  0
                     VersionDisplayInfo mdVersionInfo = programService.getCurrentVersion(ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI, majorVersionIndId);
 70  0
                     mdInfo = programService.getMajorDiscipline(mdVersionInfo.getId());
 71  
                     
 72  
                     //set the prev start term to be the most recent of the major and all variations
 73  0
                                 AtpInfo latestStartAtp = atpService.getAtp(mdInfo.getStartTerm());
 74  0
                                 for (ProgramVariationInfo variation:mdInfo.getVariations()){
 75  0
                                         AtpInfo variationAtp = atpService.getAtp(variation.getStartTerm());
 76  0
                                         if(variationAtp!=null && variationAtp.getStartDate()!=null && variationAtp.getStartDate().compareTo(latestStartAtp.getStartDate())>0){
 77  0
                                                 latestStartAtp = variationAtp;
 78  
                                         }
 79  0
                                 }
 80  
 
 81  
                                 //Save the start and end terms from the old version and put into filter properties
 82  0
                                 String startTerm = latestStartAtp.getId();
 83  0
                             String endTerm = mdInfo.getEndTerm();
 84  0
                             String endProgramEntryTerm = mdInfo.getEndProgramEntryTerm();
 85  0
                             String endInstAdmitTerm = mdInfo.getAttributes().get(ProgramConstants.END_INSTITUTIONAL_ADMIT_TERM);
 86  0
                             Map<String,String> proposalAttributes = new HashMap<String,String>();
 87  0
                             if(startTerm!=null)
 88  0
                                     proposalAttributes.put("prevStartTerm",startTerm);
 89  0
                             if(endTerm!=null)
 90  0
                                     proposalAttributes.put("prevEndTerm",endTerm);
 91  0
                             if(endProgramEntryTerm!=null)
 92  0
                                     proposalAttributes.put("prevEndProgramEntryTerm",endProgramEntryTerm);
 93  0
                             if(endInstAdmitTerm!=null)
 94  0
                                     proposalAttributes.put("prevEndInstAdmitTerm",endInstAdmitTerm);
 95  0
                             properties.put(ProposalWorkflowFilter.PROPOSAL_ATTRIBUTES, proposalAttributes);
 96  
                     
 97  0
                     mdInfo = programService.createNewMajorDisciplineVersion(majorVersionIndId, "New major discipline version");
 98  0
             } else if (mdInfo.getId() == null){
 99  0
                 mdInfo = programService.createMajorDiscipline(mdInfo);
 100  
             } else {
 101  0
                 mdInfo = programService.updateMajorDiscipline(mdInfo);
 102  
             }
 103  0
             return mdInfo;
 104  
         } else {
 105  0
             throw new InvalidParameterException("Only persistence of MajorDiscipline is supported by this DataService implementation.");
 106  
         }
 107  
     }  
 108  
 
 109  
     
 110  
     @Override
 111  
         protected List<ValidationResultInfo> validate(Object dto) throws Exception {
 112  0
                 return programService.validateMajorDiscipline("OBJECT", (MajorDisciplineInfo)dto);
 113  
         }
 114  
 
 115  
         @Override
 116  
     protected Class<?> getDtoClass() {
 117  0
         return MajorDisciplineInfo.class;
 118  
     }
 119  
 
 120  
     private String getCredentialId() throws Exception {
 121  
 
 122  0
             List<String> credIds = luService.getCluIdsByLuType(ProgramClientConstants.CREDENTIAL_BACCALAUREATE_PROGRAM, DtoConstants.STATE_ACTIVE);
 123  0
             if (null == credIds || credIds.size() != 1) {
 124  0
                 throw new OperationFailedException("A single credential program of type " + ProgramClientConstants.CREDENTIAL_BACCALAUREATE_PROGRAM + " is required; database contains " +
 125  
                                                     (null == credIds ? "0" : credIds.size() +
 126  
                                                     "."));
 127  
             }
 128  0
             return credIds.get(0);
 129  
     }
 130  
 
 131  
     public void setProgramService(ProgramService programService) {
 132  0
         this.programService = programService;
 133  0
     }
 134  
 
 135  
     public void setLuService(LuService luService) {
 136  0
         this.luService = luService;
 137  0
     }
 138  
 
 139  
         public void setAtpService(AtpService atpService) {
 140  0
                 this.atpService = atpService;
 141  0
         }
 142  
 
 143  
         @Override
 144  
         protected boolean checkDocumentLevelPermissions() {
 145  
                 // TODO Auto-generated method stub
 146  0
                 return  true;
 147  
         }
 148  
 
 149  
 }