1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.common.kitchensink;
18
19 import org.hsqldb.lib.StringUtil;
20 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
21 import org.kuali.rice.kim.api.identity.Person;
22 import org.kuali.rice.kim.api.identity.PersonService;
23 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
24 import org.kuali.rice.kim.impl.KIMPropertyConstants;
25 import org.kuali.rice.krad.uif.field.LinkField;
26 import org.kuali.rice.krad.uif.service.impl.ViewHelperServiceImpl;
27 import org.kuali.rice.krad.uif.view.View;
28 import org.kuali.rice.krad.util.BeanPropertyComparator;
29 import org.kuali.rice.krad.util.GlobalVariables;
30 import org.kuali.student.r2.core.acal.dto.TermInfo;
31 import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
32 import org.kuali.student.r2.common.dto.ContextInfo;
33
34 import javax.xml.namespace.QName;
35 import java.text.MessageFormat;
36 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.Collections;
39 import java.util.HashMap;
40 import java.util.List;
41 import java.util.Map;
42
43
44
45
46
47
48 public class KitchenSinkHelper extends ViewHelperServiceImpl {
49
50 private AcademicCalendarService academicCalendarService;
51
52
53 public TermInfo termInfoAjaxQuery(String termCode) {
54 TermInfo termInfo = new TermInfo();
55 if (!StringUtil.isEmpty(termCode)) {
56 try {
57 List<TermInfo> termInfoList = new ArrayList();
58 termInfoList = getAcademicCalendarService().getTermsByCode(termCode, getContextInfo());
59 if (termInfoList.size() > 0) {
60
61 int firstTermInfo = 0;
62 termInfo = termInfoList.get(firstTermInfo);
63 }
64
65
66 }
67 catch (Exception e) {
68 e.printStackTrace();
69 }
70 }
71 return termInfo;
72 }
73
74 public void delete(int selectedIndex, KitchenSinkForm form) throws Exception{
75 form.getCollection().remove(selectedIndex);
76 }
77
78 public List<Person> getPersonsForSuggest(String personName) {
79 Map<String, String> searchCriteria = new HashMap<String, String>();
80 searchCriteria.put(KIMPropertyConstants.Person.LAST_NAME, personName+"*");
81 PersonService personService = KimApiServiceLocator.getPersonService();
82 List<Person> personList = personService.findPeople(searchCriteria);
83
84
85 if ((personList != null) && (personList.size() > 1)) {
86 Collections.sort((List<?>) personList, new BeanPropertyComparator(Arrays.asList("lastName","firstName")));
87 }
88
89 return personList;
90 }
91
92 public void setSourceLinkText(LinkField linkField, Object model) {
93 linkField.setLinkText(linkField.getHref());
94 }
95
96 public void setDirectLinkUrl(LinkField linkField, Object model, String methodToCall) {
97 if (StringUtil.isEmpty(methodToCall)) {
98 methodToCall = "start";
99 }
100
101 String url = MessageFormat.format("{0}?viewId={1}&methodToCall={2}",
102 ((KitchenSinkForm) model).getFormPostUrl(),
103 ((KitchenSinkForm) model).getViewId() + "-Bare", methodToCall);
104 linkField.setLinkText(url);
105 linkField.setHref(url);
106 }
107 public void setDirectLinkUrl(LinkField linkField, Object model) {
108 setDirectLinkUrl(linkField, model, null);
109 }
110
111 @Override
112 public void processCollectionSaveLine(View view, Object model, String collectionPath, int lineIndex) {
113
114
115
116
117 if (view.getId().startsWith("KS-KitchenSink-CollectionAsForm-View")) {
118
119 GlobalVariables.getMessageMap().addGrowlMessage("NOTE", "kitchensink.saveLine", String.valueOf(lineIndex));
120 }
121 super.processCollectionSaveLine(view, model, collectionPath, lineIndex);
122 }
123
124 @Override
125 public void processCollectionDeleteLine(View view, Object model, String collectionPath, int lineIndex) {
126
127
128
129
130 if (view.getId().startsWith("KS-KitchenSink-CollectionAsForm-View")) {
131
132 GlobalVariables.getMessageMap().addGrowlMessage("NOTE", "kitchensink.deleteLine", String.valueOf(lineIndex));
133 }
134 super.processCollectionDeleteLine(view, model, collectionPath, lineIndex);
135 }
136
137
138
139 private AcademicCalendarService getAcademicCalendarService() {
140 if(academicCalendarService == null) {
141 academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/acal", "AcademicCalendarService"));
142 }
143 return academicCalendarService;
144 }
145
146
147 private ContextInfo getContextInfo() {
148 return new ContextInfo();
149 }
150
151 }