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.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 | |
|
25 | |
|
26 | 0 | public class CoreProgramDataService extends AbstractDataService { |
27 | |
|
28 | |
private static final long serialVersionUID = 1L; |
29 | |
|
30 | |
private ProgramService programService; |
31 | |
private LuService luService; |
32 | |
|
33 | |
@Override |
34 | |
protected String getDefaultWorkflowDocumentType() { |
35 | 0 | return null; |
36 | |
} |
37 | |
|
38 | |
@Override |
39 | |
protected String getDefaultMetaDataState() { |
40 | 0 | return null; |
41 | |
} |
42 | |
|
43 | |
@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 | |
|
53 | |
@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 | |
|
71 | |
@Override |
72 | |
protected Class<?> getDtoClass() { |
73 | 0 | return CoreProgramInfo.class; |
74 | |
} |
75 | |
|
76 | |
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 | 0 | } |
106 | |
} |
107 | 0 | if (coreProgramId != null) { |
108 | 0 | core = programService.getCoreProgram(coreProgramId); |
109 | |
} |
110 | 0 | return core; |
111 | |
} |
112 | |
|
113 | |
public void setProgramService(ProgramService programService) { |
114 | 0 | this.programService = programService; |
115 | 0 | } |
116 | |
|
117 | |
public void setLuService(LuService luService) { |
118 | 0 | this.luService = luService; |
119 | 0 | } |
120 | |
} |