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