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