Coverage Report - org.kuali.student.lum.program.server.CoreProgramDataService
 
Classes in this File Line Coverage Branch Coverage Complexity
CoreProgramDataService
0%
0/45
0%
0/26
2.778
 
 1  
 package org.kuali.student.lum.program.server;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.List;
 5  
 import java.util.Map;
 6  
 
 7  
 import org.kuali.student.common.exceptions.DoesNotExistException;
 8  
 import org.kuali.student.common.exceptions.InvalidParameterException;
 9  
 import org.kuali.student.common.exceptions.MissingParameterException;
 10  
 import org.kuali.student.common.exceptions.OperationFailedException;
 11  
 import org.kuali.student.common.exceptions.PermissionDeniedException;
 12  
 import org.kuali.student.common.search.dto.SearchParam;
 13  
 import org.kuali.student.common.search.dto.SearchRequest;
 14  
 import org.kuali.student.common.search.dto.SearchResult;
 15  
 import org.kuali.student.common.search.dto.SearchResultCell;
 16  
 import org.kuali.student.common.search.dto.SearchResultRow;
 17  
 import org.kuali.student.common.ui.server.gwt.AbstractDataService;
 18  
 import org.kuali.student.common.validation.dto.ValidationResultInfo;
 19  
 import org.kuali.student.lum.lu.service.LuService;
 20  
 import org.kuali.student.lum.program.client.ProgramClientConstants;
 21  
 import org.kuali.student.lum.program.dto.CoreProgramInfo;
 22  
 import org.kuali.student.lum.program.service.ProgramService;
 23  
 
 24  
 /**
 25  
  * @author Jim
 26  
  */
 27  0
 public class CoreProgramDataService extends AbstractDataService {
 28  
 
 29  
     private static final long serialVersionUID = 1L;
 30  
     
 31  
     private ProgramService programService;
 32  
     private LuService luService;
 33  
 
 34  
     @Override
 35  
     protected String getDefaultWorkflowDocumentType() {
 36  0
         return null;
 37  
     }
 38  
 
 39  
     @Override
 40  
     protected String getDefaultMetaDataState() {
 41  0
         return null;
 42  
     }
 43  
 
 44  
     @Override
 45  
     protected Object get(String id) throws Exception {
 46  0
             if (id==null || id.isEmpty()){
 47  0
             return findCurrentCoreProgram();
 48  
             } else {
 49  0
                     return programService.getCoreProgram(id);
 50  
             }
 51  
 
 52  
     }
 53  
 
 54  
     @Override
 55  
     protected Object save(Object dto, Map<String, Object> properties) throws Exception {
 56  0
         if (dto instanceof CoreProgramInfo) {
 57  0
             CoreProgramInfo cpInfo = (CoreProgramInfo) dto;
 58  0
             if (cpInfo.getId() == null && cpInfo.getVersionInfo() != null) {
 59  0
                     String coreVersionIndId = cpInfo.getVersionInfo().getVersionIndId();
 60  0
                     cpInfo = programService.createNewCoreProgramVersion(coreVersionIndId, "New core program version");
 61  0
             } else if (cpInfo.getId() == null) {
 62  0
                 cpInfo = programService.createCoreProgram(cpInfo);
 63  
             } else {
 64  0
                 cpInfo = programService.updateCoreProgram(cpInfo);
 65  
             }
 66  0
             return cpInfo;
 67  
         } else {
 68  0
             throw new InvalidParameterException("Only persistence of CoreProgram is supported by this DataService implementation.");
 69  
         }
 70  
     }
 71  
 
 72  
     @Override
 73  
         protected List<ValidationResultInfo> validate(Object dto) throws Exception {
 74  0
                 return programService.validateCoreProgram("OBJECT", (CoreProgramInfo)dto);
 75  
         }
 76  
     
 77  
     @Override
 78  
     protected Class<?> getDtoClass() {
 79  0
         return CoreProgramInfo.class;
 80  
     }
 81  
 
 82  
     private CoreProgramInfo findCurrentCoreProgram() throws MissingParameterException, InvalidParameterException, DoesNotExistException, PermissionDeniedException, OperationFailedException {
 83  0
                     SearchRequest request = new SearchRequest();
 84  
 
 85  
         //TODO find a better way to get this search, param and resultcolumn names
 86  
         
 87  0
         CoreProgramInfo core = new CoreProgramInfo();
 88  0
         String coreProgramId = null;
 89  0
             request.setSearchKey("lu.search.mostCurrent.union");
 90  
 
 91  0
         List<SearchParam> searchParams = new ArrayList<SearchParam>();
 92  0
         SearchParam qpv1 = new SearchParam();
 93  0
         qpv1.setKey("lu.queryParam.luOptionalType");
 94  0
         qpv1.setValue(ProgramClientConstants.CORE_PROGRAM);
 95  0
         searchParams.add(qpv1);
 96  
 
 97  0
         request.setParams(searchParams);
 98  
 
 99  0
         SearchResult searchResult = luService.search(request);
 100  0
         if (searchResult.getRows().size() > 0) {
 101  0
             for(SearchResultRow srrow : searchResult.getRows()){
 102  0
                 List<SearchResultCell> srCells = srrow.getCells();
 103  0
                 if(srCells != null && srCells.size() > 0){
 104  0
                     for(SearchResultCell srcell : srCells){
 105  0
                         if (srcell.getKey().equals("lu.resultColumn.cluId")) {
 106  0
                             coreProgramId = srcell.getValue();
 107  0
                             break;
 108  
                         }
 109  
                     }
 110  
                 }
 111  0
             }
 112  
         }
 113  0
         if (coreProgramId != null) {
 114  0
             core = programService.getCoreProgram(coreProgramId);
 115  
         }
 116  0
         return core;
 117  
     }
 118  
 
 119  
     public void setProgramService(ProgramService programService) {
 120  0
         this.programService = programService;
 121  0
     }
 122  
 
 123  
     public void setLuService(LuService luService) {
 124  0
         this.luService = luService;
 125  0
     }
 126  
 }