Clover Coverage Report - Kuali Student 1.1.0-SNAPSHOT (Aggregated)
Coverage timestamp: Tue Feb 15 2011 04:04:07 EST
../../../../../../../../../img/srcFileCovDistChart0.png 48% of files have more coverage
135   286   53   12.27
60   239   0.39   11
11     4.82  
1    
 
  CluSetManagementRpcGwtServlet       Line # 43 135 0% 53 206 0% 0.0
 
No Tests
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
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.ui.client.service.DataSaveResult;
22    import org.kuali.student.common.ui.client.service.exceptions.OperationFailedException;
23    import org.kuali.student.common.ui.server.gwt.DataGwtServlet;
24    import org.kuali.student.core.assembly.data.AssemblyException;
25    import org.kuali.student.core.assembly.data.Data;
26    import org.kuali.student.core.exceptions.DataValidationErrorException;
27    import org.kuali.student.core.search.dto.SearchRequest;
28    import org.kuali.student.core.search.dto.SearchResult;
29    import org.kuali.student.core.search.dto.SearchResultCell;
30    import org.kuali.student.core.search.dto.SearchResultRow;
31    import org.kuali.student.core.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    public class CluSetManagementRpcGwtServlet extends DataGwtServlet implements
44    CluSetManagementRpcService {
45   
46    private static final long serialVersionUID = 1L;
47    final static Logger LOG = Logger.getLogger(CluSetManagementRpcGwtServlet.class);
48    private LuService luService;
49    private LrcService lrcService;
50   
 
51  0 toggle public LuService getLuService() {
52  0 return luService;
53    }
54   
 
55  0 toggle public void setLuService(LuService luService) {
56  0 this.luService = luService;
57    }
58   
 
59  0 toggle public LrcService getLrcService() {
60  0 return lrcService;
61    }
62   
 
63  0 toggle public void setLrcService(LrcService lrcService) {
64  0 this.lrcService = lrcService;
65    }
66   
 
67  0 toggle @Override
68    public Data getData(String id) throws OperationFailedException {
69  0 try{
70  0 return getDataService().getData(id);
71    } 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  0 toggle @Override
78    public DataSaveResult saveData(Data data) throws OperationFailedException {
79  0 try{
80  0 return getDataService().saveData(data);
81    }catch (DataValidationErrorException dvee){
82  0 return new DataSaveResult(dvee.getValidationResults(), null);
83    } catch (Exception e) {
84  0 LOG.error("Could not save data ", e);
85  0 throw new OperationFailedException("Failed to save data");
86    }
87    }
88   
 
89  0 toggle private CluSetInfo getCluSetInfo(String cluSetId) throws OperationFailedException {
90  0 List<String> cluIds = null;
91  0 CluSetInfo cluSetInfo = null;
92  0 try {
93    // note: the cluIds returned by luService.getCluSetInfo also contains the clus
94    // that are the result of query parameter search. Set to null here and
95    // retrieve the clus that are direct members.
96  0 cluSetInfo = luService.getCluSetInfo(cluSetId);
97  0 cluSetInfo.setCluIds(null);
98  0 cluIds = luService.getCluIdsFromCluSet(cluSetId);
99  0 cluSetInfo.setCluIds(cluIds);
100  0 upWrap(cluSetInfo);
101    } catch (Exception e) {
102  0 throw new OperationFailedException("Failed to retrieve cluset info for " + cluSetId, e);
103    }
104  0 return cluSetInfo;
105    }
106   
 
107  0 toggle private List<CluSetInfo> getCluSetInfos(List<String> cluSetIds) throws OperationFailedException {
108  0 List<CluSetInfo> clusetInfos = null;
109  0 if (cluSetIds != null) {
110  0 for (String cluSetId : cluSetIds) {
111  0 clusetInfos = (clusetInfos == null)? new ArrayList<CluSetInfo>() : clusetInfos;
112  0 clusetInfos.add(getCluSetInfo(cluSetId));
113    }
114    }
115  0 return clusetInfos;
116    }
117   
 
118  0 toggle private void upWrap(CluSetInfo cluSetInfo) throws AssemblyException {
119  0 List<String> cluSetIds = (cluSetInfo == null)? null : cluSetInfo.getCluSetIds();
120  0 List<String> unWrappedCluSetIds = null;
121  0 List<CluSetInfo> wrappedCluSets = null;
122  0 List<CluSetInfo> subCluSets = null;
123   
124  0 try {
125  0 if (cluSetIds != null && !cluSetIds.isEmpty()) {
126  0 subCluSets = luService.getCluSetInfoByIdList(cluSetIds);
127    }
128    } catch (Exception e) {
129  0 LOG.error(e.getMessage(), e);
130  0 throw new AssemblyException("Failed to retrieve the sub clusets of cluset " +
131    cluSetInfo.getId());
132    }
133    // goes through the list of sub clusets and ignore the ones that are not reusable
134  0 if (subCluSets != null) {
135  0 for (CluSetInfo subCluSet : subCluSets) {
136  0 if (subCluSet.getIsReusable()) {
137  0 unWrappedCluSetIds = (unWrappedCluSetIds == null)?
138    new ArrayList<String>() : unWrappedCluSetIds;
139  0 unWrappedCluSetIds.add(subCluSet.getId());
140    } else {
141  0 wrappedCluSets = (wrappedCluSets == null)?
142    new ArrayList<CluSetInfo>() : wrappedCluSets;
143  0 wrappedCluSets.add(subCluSet);
144    }
145    }
146    }
147  0 cluSetInfo.setCluSetIds(unWrappedCluSetIds);
148  0 if (wrappedCluSets != null) {
149  0 for (CluSetInfo wrappedCluSet : wrappedCluSets) {
150  0 MembershipQueryInfo mqInfo = wrappedCluSet.getMembershipQuery();
151  0 if (wrappedCluSet.getCluIds() != null && !wrappedCluSet.getCluIds().isEmpty()) {
152  0 cluSetInfo.setCluIds(wrappedCluSet.getCluIds());
153    }
154  0 if (mqInfo != null && mqInfo.getSearchTypeKey() != null && !mqInfo.getSearchTypeKey().isEmpty()) {
155  0 cluSetInfo.setMembershipQuery(mqInfo);
156    }
157    }
158    }
159    }
160   
 
161  0 toggle private List<CluInformation> getCluInformations(List<String> cluIds) throws OperationFailedException {
162  0 List<CluInformation> result = new ArrayList<CluInformation>();
163  0 if (cluIds != null) {
164  0 for (String cluId : cluIds) {
165  0 try {
166  0 VersionDisplayInfo versionInfo = luService.getCurrentVersion(LuServiceConstants.CLU_NAMESPACE_URI, cluId);
167  0 CluInfo cluInfo = luService.getClu(versionInfo.getId());
168  0 if (cluInfo != null) {
169   
170    //retrieve credits
171  0 String credits = "";
172  0 List<CluResultInfo> cluResultInfos = luService.getCluResultByClu(versionInfo.getId());
173  0 if (cluResultInfos != null) {
174  0 for (CluResultInfo cluResultInfo : cluResultInfos) {
175  0 String cluType = cluResultInfo.getType();
176   
177    //ignore non-credit results
178  0 if ((cluType == null) || (!cluType.equals("kuali.resultType.creditCourseResult"))) {
179  0 continue;
180    }
181   
182    //retrieve credit type and credit values
183  0 ResultComponentInfo resultComponentInfo = null;
184  0 List<String> resultValues = null;
185  0 String creditType = "";
186  0 if (cluResultInfo.getResultOptions() != null) {
187  0 for (ResultOptionInfo resultOption : cluResultInfo.getResultOptions()) {
188  0 if (resultOption.getResultComponentId() != null) {
189  0 resultComponentInfo = lrcService.getResultComponent(resultOption.getResultComponentId());
190  0 resultValues = resultComponentInfo.getResultValues();
191  0 creditType = resultComponentInfo.getType();
192  0 break;
193    }
194    }
195    }
196  0 if (resultValues == null) {
197  0 continue;
198    }
199   
200  0 if (!credits.isEmpty()) {
201  0 credits = credits + "; ";
202    }
203   
204  0 if (creditType.equals("kuali.resultComponentType.credit.degree.fixed")) {
205  0 credits = credits + resultValues.get(0);
206  0 } else if (creditType.equals("kuali.resultComponentType.credit.degree.multiple")) {
207  0 boolean firstValue = true;
208  0 for (String resultValue : resultValues) {
209  0 credits = credits + (firstValue ? "" :", ") + resultValue;
210  0 firstValue = false;
211    }
212  0 } else if (creditType.equals("kuali.resultComponentType.credit.degree.range")) {
213  0 credits = credits + resultComponentInfo.getAttributes().get("minCreditValue") + " - " + resultComponentInfo.getAttributes().get("maxCreditValue");
214    }
215    }
216    }
217   
218   
219  0 CluInformation cluInformation = new CluInformation();
220  0 if (cluInfo.getOfficialIdentifier() != null) {
221  0 cluInformation.setCode(cluInfo.getOfficialIdentifier().getCode());
222  0 cluInformation.setTitle(cluInfo.getOfficialIdentifier().getShortName());
223  0 cluInformation.setCredits(credits);
224    }
225  0 cluInformation.setVerIndependentId(cluInfo.getVersionInfo().getVersionIndId());
226  0 result.add(cluInformation);
227    }
228    } catch (Exception e) {
229  0 throw new OperationFailedException("Failed to get info for cluId " + cluId, e);
230    }
231    }
232    }
233  0 return result;
234    }
235   
 
236  0 toggle @Override
237    public CluSetInformation getCluSetInformation(String cluSetId) throws OperationFailedException {
238  0 CluSetInformation result = new CluSetInformation();
239  0 CluSetInfo cluSetInfo = getCluSetInfo(cluSetId);
240  0 List<String> allCluIds = cluSetInfo.getCluIds();
241  0 List<String> cluSetIds = cluSetInfo.getCluSetIds();
242  0 final MembershipQueryInfo membershipQueryInfo = cluSetInfo.getMembershipQuery();
243  0 result.setId(cluSetId);
244  0 if (allCluIds != null) {
245  0 List<CluInformation> clus = getCluInformations(allCluIds);
246  0 result.setClus(clus);
247    }
248  0 if (cluSetIds != null) {
249  0 List<CluSetInfo> cluSetInfos = getCluSetInfos(cluSetIds);
250  0 result.setCluSets(cluSetInfos);
251    }
252  0 if (membershipQueryInfo != null) {
253  0 SearchRequest searchRequest = new SearchRequest();
254  0 searchRequest.setSearchKey(membershipQueryInfo.getSearchTypeKey());
255  0 searchRequest.setParams(membershipQueryInfo.getQueryParamValueList());
256  0 SearchResult searchResult = null;
257  0 try {
258  0 searchResult = luService.search(searchRequest);
259    } catch (Exception e) {
260  0 throw new OperationFailedException("Failed to search for clus in clu range", e);
261    }
262  0 List<CluInformation> clusInRange = new ArrayList<CluInformation>();
263  0 List<SearchResultRow> rows = searchResult.getRows();
264  0 for(SearchResultRow row : rows) {
265  0 List<SearchResultCell> cells = row.getCells();
266  0 CluInformation cluInformation = new CluInformation();
267  0 for(SearchResultCell cell : cells) {
268  0 if(cell.getKey().equals("lu.resultColumn.luOptionalVersionIndId")) {
269  0 cluInformation.setVerIndependentId(cell.getValue());
270    }
271  0 if (cell.getKey().equals("lu.resultColumn.luOptionalCode")) {
272  0 cluInformation.setCode(cell.getValue());
273    }
274  0 if (cell.getKey().equals("lu.resultColumn.luOptionalShortName")) {
275  0 cluInformation.setTitle(cell.getValue());
276    }
277    }
278  0 clusInRange.add(cluInformation);
279    }
280  0 result.setMembershipQueryInfo(membershipQueryInfo);
281  0 result.setClusInRange(clusInRange);
282    }
283  0 return result;
284    }
285   
286    }