1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.lum.lu.ui.tools.server.gwt; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import org.kuali.student.common.assembly.data.AssemblyException; |
22 | |
import org.kuali.student.common.assembly.data.Data; |
23 | |
import org.kuali.student.common.exceptions.DataValidationErrorException; |
24 | |
import org.kuali.student.common.search.dto.SearchRequest; |
25 | |
import org.kuali.student.common.search.dto.SearchResult; |
26 | |
import org.kuali.student.common.search.dto.SearchResultCell; |
27 | |
import org.kuali.student.common.search.dto.SearchResultRow; |
28 | |
import org.kuali.student.common.ui.client.service.DataSaveResult; |
29 | |
import org.kuali.student.common.ui.client.service.exceptions.OperationFailedException; |
30 | |
import org.kuali.student.common.ui.server.gwt.DataGwtServlet; |
31 | |
import org.kuali.student.common.versionmanagement.dto.VersionDisplayInfo; |
32 | |
import org.kuali.student.lum.common.client.widgets.CluInformation; |
33 | |
import org.kuali.student.lum.common.client.widgets.CluSetInformation; |
34 | |
import org.kuali.student.lum.common.client.widgets.CluSetManagementRpcService; |
35 | |
import org.kuali.student.lum.lrc.dto.ResultComponentInfo; |
36 | |
import org.kuali.student.lum.lrc.service.LrcService; |
37 | |
import org.kuali.student.lum.lu.dto.*; |
38 | |
import org.kuali.student.lum.lu.service.LuService; |
39 | |
import org.kuali.student.lum.lu.service.LuServiceConstants; |
40 | |
|
41 | |
import org.apache.log4j.Logger; |
42 | |
|
43 | 0 | public class CluSetManagementRpcGwtServlet extends DataGwtServlet implements |
44 | |
CluSetManagementRpcService { |
45 | |
|
46 | |
private static final long serialVersionUID = 1L; |
47 | 0 | final static Logger LOG = Logger.getLogger(CluSetManagementRpcGwtServlet.class); |
48 | |
private LuService luService; |
49 | |
private LrcService lrcService; |
50 | |
|
51 | |
public LuService getLuService() { |
52 | 0 | return luService; |
53 | |
} |
54 | |
|
55 | |
public void setLuService(LuService luService) { |
56 | 0 | this.luService = luService; |
57 | 0 | } |
58 | |
|
59 | |
public LrcService getLrcService() { |
60 | 0 | return lrcService; |
61 | |
} |
62 | |
|
63 | |
public void setLrcService(LrcService lrcService) { |
64 | 0 | this.lrcService = lrcService; |
65 | 0 | } |
66 | |
|
67 | |
@Override |
68 | |
public Data getData(String id) throws OperationFailedException { |
69 | |
try{ |
70 | 0 | return getDataService().getData(id); |
71 | 0 | } catch (Exception e) { |
72 | 0 | LOG.error("Could not get Data ", e); |
73 | 0 | throw new OperationFailedException("Failed to get data"); |
74 | |
} |
75 | |
} |
76 | |
|
77 | |
@Override |
78 | |
public DataSaveResult saveData(Data data) throws OperationFailedException { |
79 | |
try{ |
80 | 0 | return getDataService().saveData(data); |
81 | 0 | } catch (Exception e) { |
82 | 0 | LOG.error("Could not save data ", e); |
83 | 0 | throw new OperationFailedException("Failed to save data"); |
84 | |
} |
85 | |
} |
86 | |
|
87 | |
private CluSetInfo getCluSetInfo(String cluSetId) throws OperationFailedException { |
88 | 0 | List<String> cluIds = null; |
89 | 0 | CluSetInfo cluSetInfo = null; |
90 | |
try { |
91 | |
|
92 | |
|
93 | |
|
94 | 0 | cluSetInfo = luService.getCluSetInfo(cluSetId); |
95 | 0 | cluSetInfo.setCluIds(null); |
96 | 0 | cluIds = luService.getCluIdsFromCluSet(cluSetId); |
97 | 0 | cluSetInfo.setCluIds(cluIds); |
98 | 0 | upWrap(cluSetInfo); |
99 | 0 | } catch (Exception e) { |
100 | 0 | throw new OperationFailedException("Failed to retrieve cluset info for " + cluSetId, e); |
101 | 0 | } |
102 | 0 | return cluSetInfo; |
103 | |
} |
104 | |
|
105 | |
private List<CluSetInfo> getCluSetInfos(List<String> cluSetIds) throws OperationFailedException { |
106 | 0 | List<CluSetInfo> clusetInfos = null; |
107 | 0 | if (cluSetIds != null) { |
108 | 0 | for (String cluSetId : cluSetIds) { |
109 | 0 | clusetInfos = (clusetInfos == null)? new ArrayList<CluSetInfo>() : clusetInfos; |
110 | 0 | clusetInfos.add(getCluSetInfo(cluSetId)); |
111 | |
} |
112 | |
} |
113 | 0 | return clusetInfos; |
114 | |
} |
115 | |
|
116 | |
private void upWrap(CluSetInfo cluSetInfo) throws AssemblyException { |
117 | 0 | List<String> cluSetIds = (cluSetInfo == null)? null : cluSetInfo.getCluSetIds(); |
118 | 0 | List<String> unWrappedCluSetIds = null; |
119 | 0 | List<CluSetInfo> wrappedCluSets = null; |
120 | 0 | List<CluSetInfo> subCluSets = null; |
121 | |
|
122 | |
try { |
123 | 0 | if (cluSetIds != null && !cluSetIds.isEmpty()) { |
124 | 0 | subCluSets = luService.getCluSetInfoByIdList(cluSetIds); |
125 | |
} |
126 | 0 | } catch (Exception e) { |
127 | 0 | LOG.error(e.getMessage(), e); |
128 | 0 | throw new AssemblyException("Failed to retrieve the sub clusets of cluset " + |
129 | |
cluSetInfo.getId()); |
130 | 0 | } |
131 | |
|
132 | 0 | if (subCluSets != null) { |
133 | 0 | for (CluSetInfo subCluSet : subCluSets) { |
134 | 0 | if (subCluSet.getIsReusable()) { |
135 | 0 | unWrappedCluSetIds = (unWrappedCluSetIds == null)? |
136 | |
new ArrayList<String>() : unWrappedCluSetIds; |
137 | 0 | unWrappedCluSetIds.add(subCluSet.getId()); |
138 | |
} else { |
139 | 0 | wrappedCluSets = (wrappedCluSets == null)? |
140 | |
new ArrayList<CluSetInfo>() : wrappedCluSets; |
141 | 0 | wrappedCluSets.add(subCluSet); |
142 | |
} |
143 | |
} |
144 | |
} |
145 | 0 | cluSetInfo.setCluSetIds(unWrappedCluSetIds); |
146 | 0 | if (wrappedCluSets != null) { |
147 | 0 | for (CluSetInfo wrappedCluSet : wrappedCluSets) { |
148 | 0 | MembershipQueryInfo mqInfo = wrappedCluSet.getMembershipQuery(); |
149 | 0 | if (wrappedCluSet.getCluIds() != null && !wrappedCluSet.getCluIds().isEmpty()) { |
150 | 0 | cluSetInfo.setCluIds(wrappedCluSet.getCluIds()); |
151 | |
} |
152 | 0 | if (mqInfo != null && mqInfo.getSearchTypeKey() != null && !mqInfo.getSearchTypeKey().isEmpty()) { |
153 | 0 | cluSetInfo.setMembershipQuery(mqInfo); |
154 | |
} |
155 | 0 | } |
156 | |
} |
157 | 0 | } |
158 | |
|
159 | |
private List<CluInformation> getCluInformations(List<String> cluIds) throws OperationFailedException { |
160 | 0 | List<CluInformation> result = new ArrayList<CluInformation>(); |
161 | 0 | if (cluIds != null) { |
162 | 0 | for (String cluId : cluIds) { |
163 | |
try { |
164 | 0 | VersionDisplayInfo versionInfo = luService.getCurrentVersion(LuServiceConstants.CLU_NAMESPACE_URI, cluId); |
165 | 0 | CluInfo cluInfo = luService.getClu(versionInfo.getId()); |
166 | 0 | if (cluInfo != null) { |
167 | |
|
168 | |
|
169 | 0 | String credits = ""; |
170 | 0 | List<CluResultInfo> cluResultInfos = luService.getCluResultByClu(versionInfo.getId()); |
171 | 0 | if (cluResultInfos != null) { |
172 | 0 | for (CluResultInfo cluResultInfo : cluResultInfos) { |
173 | 0 | String cluType = cluResultInfo.getType(); |
174 | |
|
175 | |
|
176 | 0 | if ((cluType == null) || (!cluType.equals("kuali.resultType.creditCourseResult"))) { |
177 | 0 | continue; |
178 | |
} |
179 | |
|
180 | |
|
181 | 0 | ResultComponentInfo resultComponentInfo = null; |
182 | 0 | List<String> resultValues = null; |
183 | 0 | String creditType = ""; |
184 | 0 | if (cluResultInfo.getResultOptions() != null) { |
185 | 0 | for (ResultOptionInfo resultOption : cluResultInfo.getResultOptions()) { |
186 | 0 | if (resultOption.getResultComponentId() != null) { |
187 | 0 | resultComponentInfo = lrcService.getResultComponent(resultOption.getResultComponentId()); |
188 | 0 | resultValues = resultComponentInfo.getResultValues(); |
189 | 0 | creditType = resultComponentInfo.getType(); |
190 | 0 | break; |
191 | |
} |
192 | |
} |
193 | |
} |
194 | 0 | if (resultValues == null) { |
195 | 0 | continue; |
196 | |
} |
197 | |
|
198 | 0 | if (!credits.isEmpty()) { |
199 | 0 | credits = credits + "; "; |
200 | |
} |
201 | |
|
202 | 0 | if (creditType.equals("kuali.resultComponentType.credit.degree.fixed")) { |
203 | 0 | credits = credits + resultValues.get(0); |
204 | 0 | } else if (creditType.equals("kuali.resultComponentType.credit.degree.multiple")) { |
205 | 0 | boolean firstValue = true; |
206 | 0 | for (String resultValue : resultValues) { |
207 | 0 | credits = credits + (firstValue ? "" :", ") + resultValue; |
208 | 0 | firstValue = false; |
209 | |
} |
210 | 0 | } else if (creditType.equals("kuali.resultComponentType.credit.degree.range")) { |
211 | 0 | credits = credits + resultComponentInfo.getAttributes().get("minCreditValue") + " - " + resultComponentInfo.getAttributes().get("maxCreditValue"); |
212 | |
} |
213 | 0 | } |
214 | |
} |
215 | |
|
216 | |
|
217 | 0 | CluInformation cluInformation = new CluInformation(); |
218 | 0 | if (cluInfo.getOfficialIdentifier() != null) { |
219 | 0 | cluInformation.setCode(cluInfo.getOfficialIdentifier().getCode()); |
220 | 0 | cluInformation.setTitle(cluInfo.getOfficialIdentifier().getShortName()); |
221 | 0 | cluInformation.setCredits(credits); |
222 | |
} |
223 | 0 | cluInformation.setVerIndependentId(cluInfo.getId()); |
224 | 0 | result.add(cluInformation); |
225 | |
} |
226 | 0 | } catch (Exception e) { |
227 | 0 | throw new OperationFailedException("Failed to get info for cluId " + cluId, e); |
228 | 0 | } |
229 | |
} |
230 | |
} |
231 | 0 | return result; |
232 | |
} |
233 | |
|
234 | |
@Override |
235 | |
public CluSetInformation getCluSetInformation(String cluSetId) throws OperationFailedException { |
236 | 0 | CluSetInformation result = new CluSetInformation(); |
237 | 0 | CluSetInfo cluSetInfo = getCluSetInfo(cluSetId); |
238 | 0 | List<String> allCluIds = cluSetInfo.getCluIds(); |
239 | 0 | List<String> cluSetIds = cluSetInfo.getCluSetIds(); |
240 | 0 | final MembershipQueryInfo membershipQueryInfo = cluSetInfo.getMembershipQuery(); |
241 | 0 | result.setId(cluSetId); |
242 | 0 | if (allCluIds != null) { |
243 | 0 | List<CluInformation> clus = getCluInformations(allCluIds); |
244 | 0 | result.setClus(clus); |
245 | |
} |
246 | 0 | if (cluSetIds != null) { |
247 | 0 | List<CluSetInfo> cluSetInfos = getCluSetInfos(cluSetIds); |
248 | 0 | result.setCluSets(cluSetInfos); |
249 | |
} |
250 | 0 | if (membershipQueryInfo != null) { |
251 | 0 | SearchRequest searchRequest = new SearchRequest(); |
252 | 0 | searchRequest.setSearchKey(membershipQueryInfo.getSearchTypeKey()); |
253 | 0 | searchRequest.setParams(membershipQueryInfo.getQueryParamValueList()); |
254 | 0 | SearchResult searchResult = null; |
255 | |
try { |
256 | 0 | searchResult = luService.search(searchRequest); |
257 | 0 | } catch (Exception e) { |
258 | 0 | throw new OperationFailedException("Failed to search for clus in clu range", e); |
259 | 0 | } |
260 | 0 | List<CluInformation> clusInRange = new ArrayList<CluInformation>(); |
261 | 0 | List<SearchResultRow> rows = searchResult.getRows(); |
262 | 0 | for(SearchResultRow row : rows) { |
263 | 0 | List<SearchResultCell> cells = row.getCells(); |
264 | 0 | CluInformation cluInformation = new CluInformation(); |
265 | 0 | for(SearchResultCell cell : cells) { |
266 | 0 | if(cell.getKey().equals("lu.resultColumn.cluId")) { |
267 | 0 | cluInformation.setVerIndependentId(cell.getValue()); |
268 | |
} |
269 | 0 | if (cell.getKey().equals("lu.resultColumn.luOptionalCode")) { |
270 | 0 | cluInformation.setCode(cell.getValue()); |
271 | |
} |
272 | 0 | if (cell.getKey().equals("lu.resultColumn.luOptionalShortName")) { |
273 | 0 | cluInformation.setTitle(cell.getValue()); |
274 | |
} |
275 | |
} |
276 | 0 | clusInRange.add(cluInformation); |
277 | 0 | } |
278 | 0 | result.setMembershipQueryInfo(membershipQueryInfo); |
279 | 0 | result.setClusInRange(clusInRange); |
280 | |
} |
281 | 0 | return result; |
282 | |
} |
283 | |
|
284 | |
} |