1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.lookup;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.kew.api.KewApiConstants;
20 import org.kuali.rice.kim.api.KimConstants;
21 import org.kuali.rice.kim.api.identity.Person;
22 import org.kuali.rice.kim.impl.KIMPropertyConstants;
23 import org.kuali.rice.kim.impl.identity.PersonImpl;
24 import org.kuali.rice.kim.util.KimCommonUtilsInternal;
25 import org.kuali.rice.kns.lookup.HtmlData;
26 import org.kuali.rice.kns.web.ui.Field;
27 import org.kuali.rice.kns.web.ui.Row;
28 import org.kuali.rice.krad.bo.BusinessObject;
29 import org.kuali.rice.krad.util.KRADConstants;
30 import org.kuali.rice.krad.util.UrlFactory;
31
32 import java.util.ArrayList;
33 import java.util.Iterator;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.Properties;
37
38
39
40
41
42
43
44 public class PersonLookupableHelperServiceImpl extends KimLookupableHelperServiceImpl {
45
46 private static final long serialVersionUID = 1971744785776844579L;
47
48 @Override
49 public List<? extends BusinessObject> getSearchResults(
50 Map<String, String> fieldValues) {
51 if (fieldValues != null && StringUtils.isNotEmpty(fieldValues.get(KIMPropertyConstants.Person.PRINCIPAL_NAME))) {
52 fieldValues.put(KIMPropertyConstants.Person.PRINCIPAL_NAME, fieldValues.get(KIMPropertyConstants.Person.PRINCIPAL_NAME).toLowerCase());
53 }
54 return super.getSearchResults(fieldValues);
55 }
56
57 @SuppressWarnings("unchecked")
58 @Override
59 public List<HtmlData> getCustomActionUrls(BusinessObject bo, List pkNames) {
60 List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>();
61 if(allowsNewOrCopyAction(KimConstants.KimUIConstants.KIM_PERSON_DOCUMENT_TYPE_NAME)){
62 String href = "";
63 Properties parameters = new Properties();
64 parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.DOC_HANDLER_METHOD);
65 parameters.put(KRADConstants.PARAMETER_COMMAND, KewApiConstants.INITIATE_COMMAND);
66 parameters.put(KRADConstants.DOCUMENT_TYPE_NAME, KimConstants.KimUIConstants.KIM_PERSON_DOCUMENT_TYPE_NAME);
67 parameters.put(KimConstants.PrimaryKeyConstants.PRINCIPAL_ID, ((PersonImpl)bo).getPrincipalId());
68 if (StringUtils.isNotBlank(getReturnLocation())) {
69 parameters.put(KRADConstants.RETURN_LOCATION_PARAMETER, getReturnLocation());
70 }
71 href = UrlFactory.parameterizeUrl(KimCommonUtilsInternal.getKimBasePath()+KimConstants.KimUIConstants.KIM_PERSON_DOCUMENT_ACTION, parameters);
72
73 HtmlData.AnchorHtmlData anchorHtmlData = new HtmlData.AnchorHtmlData(href,
74 KRADConstants.DOC_HANDLER_METHOD, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL);
75
76 anchorHtmlDataList.add(anchorHtmlData);
77 }
78 return anchorHtmlDataList;
79 }
80
81 @Override
82 public HtmlData getInquiryUrl(BusinessObject bo, String propertyName) {
83 HtmlData inqUrl = super.getInquiryUrl(bo, propertyName);
84 Properties parameters = new Properties();
85 parameters.put(KewApiConstants.COMMAND_PARAMETER, KewApiConstants.INITIATE_COMMAND);
86 parameters.put(KRADConstants.DOCUMENT_TYPE_NAME, KimConstants.KimUIConstants.KIM_PERSON_DOCUMENT_TYPE_NAME);
87 parameters.put(KimConstants.PrimaryKeyConstants.PRINCIPAL_ID, ((Person)bo).getPrincipalId());
88 String href = UrlFactory.parameterizeUrl(KimCommonUtilsInternal.getKimBasePath()+ KimConstants.KimUIConstants.KIM_PERSON_INQUIRY_ACTION, parameters);
89 ((HtmlData.AnchorHtmlData)inqUrl).setHref(href);
90 return inqUrl;
91 }
92
93
94
95
96
97
98
99 @Override
100 public List<Row> getRows() {
101 title.remove();
102 List<Row> rows = super.getRows();
103 Iterator<Row> i = rows.iterator();
104 String roleName = null;
105 String namespaceCode = null;
106 while ( i.hasNext() ) {
107 Row row = i.next();
108 int numFieldsRemoved = 0;
109 boolean rowIsBlank = true;
110
111
112 for (Iterator<Field> fieldIter = row.getFields().iterator(); fieldIter.hasNext();) {
113 Field field = fieldIter.next();
114 String propertyName = field.getPropertyName();
115 if ( propertyName.equals("lookupRoleName") ) {
116 Object val = getParameters().get( propertyName );
117 String propVal = null;
118 if ( val != null ) {
119 propVal = (val instanceof String)?(String)val:((String[])val)[0];
120 }
121 if ( StringUtils.isBlank( propVal ) ) {
122 fieldIter.remove();
123 numFieldsRemoved++;
124 } else {
125 field.setReadOnly(true);
126 field.setDefaultValue( propVal );
127 roleName = propVal;
128 rowIsBlank = false;
129 }
130 } else if ( propertyName.equals("lookupRoleNamespaceCode") ) {
131 Object val = getParameters().get( propertyName );
132 String propVal = null;
133 if ( val != null ) {
134 propVal = (val instanceof String)?(String)val:((String[])val)[0];
135 }
136 if ( StringUtils.isBlank( propVal ) ) {
137 fieldIter.remove();
138 numFieldsRemoved++;
139 } else {
140 field.setReadOnly(true);
141 field.setDefaultValue( propVal );
142 namespaceCode = propVal;
143 rowIsBlank = false;
144 }
145 } else if (!Field.BLANK_SPACE.equals(field.getFieldType())) {
146 rowIsBlank = false;
147 }
148 }
149
150 if (numFieldsRemoved > 0) {
151
152 if (rowIsBlank) {
153
154 i.remove();
155 } else {
156
157
158 while (numFieldsRemoved > 0) {
159 Field blankSpace = new Field();
160 blankSpace.setFieldType(Field.BLANK_SPACE);
161 blankSpace.setPropertyName(Field.BLANK_SPACE);
162 row.getFields().add(blankSpace);
163 numFieldsRemoved--;
164 }
165 }
166 }
167 }
168 if ( roleName != null && namespaceCode != null ) {
169 title.set( namespaceCode + " " + roleName + " Lookup" );
170 }
171 return rows;
172 }
173
174 private ThreadLocal<String> title = new ThreadLocal<String>();
175 public String getTitle() {
176 if ( title.get() == null ) {
177 return super.getTitle();
178 }
179 return title.get();
180 }
181 }