Coverage Report - org.kuali.student.lum.program.server.CredentialProgramDataService
 
Classes in this File Line Coverage Branch Coverage Complexity
CredentialProgramDataService
0%
0/25
0%
0/16
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.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.CredentialProgramInfo;
 14  
 import org.kuali.student.lum.program.dto.MajorDisciplineInfo;
 15  
 import org.kuali.student.lum.program.service.ProgramService;
 16  
 
 17  
 /**
 18  
  * @author Igor
 19  
  */
 20  0
 public class CredentialProgramDataService extends AbstractDataService {
 21  
 
 22  
     private static final long serialVersionUID = 1L;
 23  
     
 24  
     private ProgramService programService;
 25  
     private LuService luService;
 26  
     
 27  
     @Override
 28  
     protected String getDefaultWorkflowDocumentType() {
 29  0
         return null;
 30  
     }
 31  
 
 32  
     @Override
 33  
     protected String getDefaultMetaDataState() {
 34  0
         return null;
 35  
     }
 36  
 
 37  
     @Override
 38  
     protected Object get(String id) throws Exception {
 39  0
             if (ProgramClientConstants.CREDENTIAL_PROGRAM_TYPES.contains(id)){
 40  0
             List<String> credIds = luService.getCluIdsByLuType(id, DtoConstants.STATE_ACTIVE);
 41  0
             if (null == credIds || credIds.size() != 1) {
 42  0
                 throw new OperationFailedException("A single credential program of type " + id + " is required; database contains " +
 43  
                                                     (null == credIds ? "0" : credIds.size() +
 44  
                                                     "."));
 45  
             }
 46  0
             return programService.getCredentialProgram(credIds.get(0));
 47  
         } else {
 48  0
                 return programService.getCredentialProgram(id);
 49  
         }
 50  
     }
 51  
 
 52  
     @Override
 53  
     protected Object save(Object dto, Map<String, Object> properties) throws Exception {
 54  0
         if (dto instanceof CredentialProgramInfo) {
 55  0
             CredentialProgramInfo cpInfo = (CredentialProgramInfo) dto;
 56  0
             if (cpInfo.getId() == null && cpInfo.getVersionInfo() != null) {
 57  0
                     String credentialVersionIndId = cpInfo.getVersionInfo().getVersionIndId();
 58  0
                     cpInfo = programService.createNewCredentialProgramVersion(credentialVersionIndId, "New credential program version");
 59  0
             } else if (cpInfo.getId() == null) {
 60  0
                 cpInfo = programService.createCredentialProgram(cpInfo);
 61  
             } else {
 62  0
                 cpInfo = programService.updateCredentialProgram(cpInfo);
 63  
             }
 64  0
             return cpInfo;
 65  
         } else {
 66  0
             throw new InvalidParameterException("Only persistence of CredentialProgram is supported by this DataService implementation.");
 67  
         }
 68  
     }
 69  
 
 70  
     @Override
 71  
         protected List<ValidationResultInfo> validate(Object dto) throws Exception {
 72  0
                 return programService.validateCredentialProgram("OBJECT", (CredentialProgramInfo)dto);
 73  
         }
 74  
     
 75  
     @Override
 76  
     protected Class<?> getDtoClass() {
 77  0
         return CredentialProgramInfo.class;
 78  
     }
 79  
 
 80  
     public void setProgramService(ProgramService programService) {
 81  0
         this.programService = programService;
 82  0
     }
 83  
 
 84  
     public void setLuService(LuService luService) {
 85  0
         this.luService = luService;
 86  0
     }
 87  
 }