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