1 package org.kuali.student.enrollment.class1.util;
2
3 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
4 import org.kuali.rice.core.api.util.ConcreteKeyValue;
5 import org.kuali.rice.core.api.util.KeyValue;
6 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
7 import org.kuali.rice.krad.uif.view.ViewModel;
8 import org.kuali.student.mock.utilities.TestHelper;
9 import org.kuali.student.r2.common.dto.ContextInfo;
10 import org.kuali.student.r2.core.constants.OrganizationServiceConstants;
11 import org.kuali.student.r2.core.class1.type.dto.TypeInfo;
12 import org.kuali.student.r2.core.organization.dto.OrgInfo;
13 import org.kuali.student.r2.core.organization.service.OrganizationService;
14
15 import javax.xml.namespace.QName;
16 import java.io.Serializable;
17 import java.util.ArrayList;
18 import java.util.List;
19
20
21
22
23
24
25 public class OrgInfoNameKeyValues extends UifKeyValuesFinderBase implements Serializable {
26
27 private static final long serialVersionUID = 1L;
28
29 private transient OrganizationService orgService;
30
31 @Override
32 public List<KeyValue> getKeyValues(ViewModel model) {
33 List<KeyValue> keyValues = new ArrayList<KeyValue>();
34 List<TypeInfo> orgTypes = new ArrayList<TypeInfo>();
35
36
37 ContextInfo context = TestHelper.getContext1();
38
39 try {
40 orgTypes = getOrganizationService().getOrgTypes(context);
41 for(TypeInfo type : orgTypes) {
42 List<String> orgIds = (getOrganizationService().getOrgIdsByType(type.getKey(), context));
43 if(!orgIds.isEmpty()) {
44 List<OrgInfo> orgInfo = getOrganizationService().getOrgsByIds(orgIds, context);
45 for (OrgInfo org : orgInfo) {
46 ConcreteKeyValue keyValue = new ConcreteKeyValue();
47 keyValue.setKey(org.getId());
48 keyValue.setValue(org.getShortName());
49 keyValues.add(keyValue);
50 }
51 }
52 }
53 } catch (Exception e) {
54 throw new RuntimeException(e);
55 }
56 return keyValues;
57 }
58
59 protected OrganizationService getOrganizationService(){
60 if(orgService == null) {
61 orgService = (OrganizationService) GlobalResourceLoader.getService(new QName(OrganizationServiceConstants.NAMESPACE, OrganizationServiceConstants.SERVICE_NAME_LOCAL_PART));
62 }
63 return orgService;
64 }
65 }