Coverage Report - org.kuali.student.lum.program.server.MajorDisciplineDataService
 
Classes in this File Line Coverage Branch Coverage Complexity
MajorDisciplineDataService
0%
0/30
0%
0/18
2.333
 
 1  
 package org.kuali.student.lum.program.server;
 2  
 
 3  
 import java.util.List;
 4  
 import java.util.Map;
 5  
 
 6  
 import org.kuali.student.common.dto.DtoConstants;
 7  
 import org.kuali.student.common.exceptions.InvalidParameterException;
 8  
 import org.kuali.student.common.exceptions.OperationFailedException;
 9  
 import org.kuali.student.common.ui.server.gwt.AbstractDataService;
 10  
 import org.kuali.student.common.validation.dto.ValidationResultInfo;
 11  
 import org.kuali.student.lum.lu.service.LuService;
 12  
 import org.kuali.student.lum.program.client.ProgramClientConstants;
 13  
 import org.kuali.student.lum.program.dto.MajorDisciplineInfo;
 14  
 import org.kuali.student.lum.program.service.ProgramService;
 15  
 
 16  
 /**
 17  
  * @author Igor
 18  
  */
 19  0
 public class MajorDisciplineDataService extends AbstractDataService {
 20  
 
 21  
     private static final long serialVersionUID = 1L;
 22  
     
 23  
     private ProgramService programService;
 24  
     private LuService luService;
 25  
 
 26  
     @Override
 27  
     protected String getDefaultWorkflowDocumentType() {
 28  0
         return null;
 29  
     }
 30  
 
 31  
     @Override
 32  
     protected String getDefaultMetaDataState() {
 33  0
         return null;
 34  
     }
 35  
 
 36  
     @Override
 37  
     protected Object get(String id) throws Exception {
 38  
             //TODO Just Major Discipline for now - need to check for other types later
 39  
         MajorDisciplineInfo returnDTO;
 40  0
         if (null == id || id.length() == 0) {
 41  0
             returnDTO = new MajorDisciplineInfo();
 42  0
             returnDTO.setType(ProgramClientConstants.MAJOR_PROGRAM);
 43  0
             returnDTO.setState(DtoConstants.STATE_DRAFT);
 44  0
             returnDTO.setCredentialProgramId(getCredentialId());
 45  
         } else {
 46  0
             returnDTO = programService.getMajorDiscipline(id);
 47  
         }
 48  0
         return returnDTO;
 49  
     }
 50  
 
 51  
     @Override
 52  
     protected Object save(Object dto, Map<String, Object> properties) throws Exception {
 53  0
         if (dto instanceof MajorDisciplineInfo) {
 54  0
             MajorDisciplineInfo mdInfo = (MajorDisciplineInfo) dto;
 55  0
             if (mdInfo.getId() == null && mdInfo.getVersionInfo() != null) {
 56  0
                     String majorVersionIndId = mdInfo.getVersionInfo().getVersionIndId();
 57  0
                     mdInfo = programService.createNewMajorDisciplineVersion(majorVersionIndId, "New major discipline version");
 58  0
             } else if (mdInfo.getId() == null){
 59  0
                 mdInfo = programService.createMajorDiscipline(mdInfo);
 60  
             } else {
 61  0
                 mdInfo = programService.updateMajorDiscipline(mdInfo);
 62  
             }
 63  0
             return mdInfo;
 64  
         } else {
 65  0
             throw new InvalidParameterException("Only persistence of MajorDiscipline is supported by this DataService implementation.");
 66  
         }
 67  
     }  
 68  
 
 69  
     
 70  
     @Override
 71  
         protected List<ValidationResultInfo> validate(Object dto) throws Exception {
 72  0
                 return programService.validateMajorDiscipline("OBJECT", (MajorDisciplineInfo)dto);
 73  
         }
 74  
 
 75  
         @Override
 76  
     protected Class<?> getDtoClass() {
 77  0
         return MajorDisciplineInfo.class;
 78  
     }
 79  
 
 80  
     private String getCredentialId() throws Exception {
 81  
 
 82  0
             List<String> credIds = luService.getCluIdsByLuType(ProgramClientConstants.CREDENTIAL_BACCALAUREATE_PROGRAM, DtoConstants.STATE_ACTIVE);
 83  0
             if (null == credIds || credIds.size() != 1) {
 84  0
                 throw new OperationFailedException("A single credential program of type " + ProgramClientConstants.CREDENTIAL_BACCALAUREATE_PROGRAM + " is required; database contains " +
 85  
                                                     (null == credIds ? "0" : credIds.size() +
 86  
                                                     "."));
 87  
             }
 88  0
             return credIds.get(0);
 89  
     }
 90  
 
 91  
     public void setProgramService(ProgramService programService) {
 92  0
         this.programService = programService;
 93  0
     }
 94  
 
 95  
     public void setLuService(LuService luService) {
 96  0
         this.luService = luService;
 97  0
     }
 98  
 
 99  
 }