View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may	obtain a copy of the License at
7    *
8    * 	http://www.osedu.org/licenses/ECL-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.student.ui.admin.lrc;
17  
18  
19  import org.kuali.rice.core.api.criteria.Predicate;
20  import org.kuali.rice.core.api.criteria.PredicateFactory;
21  import org.kuali.rice.core.api.criteria.QueryByCriteria;
22  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
23  import org.kuali.rice.krad.lookup.LookupForm;
24  import org.kuali.rice.krad.lookup.LookupableImpl;
25  import org.kuali.student.common.util.ContextBuilder;
26  import org.kuali.student.r2.common.dto.ContextInfo;
27  import org.kuali.student.r2.lum.lrc.dto.ResultScaleInfo;
28  import org.kuali.student.r2.lum.lrc.service.LRCService;
29  import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
30  
31  import javax.xml.namespace.QName;
32  import java.util.ArrayList;
33  import java.util.List;
34  import java.util.Map;
35  
36  
37  public class ResultScaleInfoAdminLookupableImpl extends LookupableImpl
38  {
39  	private transient LRCService lRCService;
40      private static final long serialVersionUID = 1L;
41  	@Override
42  	public List<ResultScaleInfo> performSearch(LookupForm lookupForm, Map<String, String> searchCriteria, boolean bounded)
43  	{
44  		QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
45  		List<Predicate> pList = new ArrayList<Predicate>();
46          //Code Changed for JIRA-8997 - SONAR Critical issues - Performance - Inefficient use of keySet iterator instead of entrySet iterator
47  		for(Map.Entry<String, String> entry: searchCriteria.entrySet()) {
48              String fieldName = entry.getKey();
49              String value = entry.getValue();
50              if (value != null && !value.isEmpty())
51              {
52                  if (fieldName.equals("maxResultsToReturn"))
53                  {
54                      qBuilder.setMaxResults (Integer.parseInt(value));
55                      continue;
56                  }
57                  pList.add(PredicateFactory.equal(fieldName, value));
58              }
59          }
60  		if (!pList.isEmpty())
61  		{
62  			qBuilder.setPredicates(PredicateFactory.and(pList.toArray(new Predicate[pList.size()])));
63  		}
64  		try
65  		{
66  			List<ResultScaleInfo> list = this.getLRCService().searchForResultScales(qBuilder.build(), getContextInfo());
67  			return list;
68  		}
69  		catch (Exception ex) {
70  		    throw new RuntimeException(ex);
71  		}
72  	}
73  
74  	public void setLRCService(LRCService lRCService)
75  	{
76  		    this.lRCService = lRCService;
77  	}
78  
79  	public LRCService getLRCService()
80  	{
81  		if (lRCService == null)
82  		{
83  			QName qname = new QName(LrcServiceConstants.NAMESPACE,LrcServiceConstants.SERVICE_NAME_LOCAL_PART);
84  			lRCService = (LRCService) GlobalResourceLoader.getService(qname);
85  		}
86  		return this.lRCService;
87  	}
88  
89  	private ContextInfo getContextInfo() {
90  	    return ContextBuilder.loadContextInfo();
91  	}
92  }
93