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