1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.lookup; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collections; |
20 | |
import java.util.Iterator; |
21 | |
import java.util.List; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
import org.apache.commons.lang.StringUtils; |
25 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
26 | |
import org.kuali.rice.kim.api.entity.principal.Principal; |
27 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
28 | |
import org.kuali.rice.kns.bo.BusinessObject; |
29 | |
import org.kuali.rice.kim.bo.Person; |
30 | |
|
31 | |
import org.kuali.rice.kim.util.KIMPropertyConstants; |
32 | |
import org.kuali.rice.kns.document.authorization.PessimisticLock; |
33 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
34 | |
import org.kuali.rice.kns.service.PessimisticLockService; |
35 | |
import org.kuali.rice.kns.util.BeanPropertyComparator; |
36 | |
import org.kuali.rice.kns.util.FieldUtils; |
37 | |
import org.kuali.rice.kns.util.GlobalVariables; |
38 | |
import org.kuali.rice.kns.util.KNSConstants; |
39 | |
import org.kuali.rice.kns.util.KNSPropertyConstants; |
40 | |
import org.kuali.rice.kns.util.ObjectUtils; |
41 | |
import org.kuali.rice.kns.web.ui.Field; |
42 | |
import org.kuali.rice.kns.web.ui.Row; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | 0 | public class PessimisticLockLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl { |
51 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PessimisticLockLookupableHelperServiceImpl.class); |
52 | |
|
53 | |
private static final long serialVersionUID = -5839142187907211804L; |
54 | |
private static final String OWNER_PRINCIPAL_ID_PROPERTY_NAME = "ownedByPrincipalIdentifier"; |
55 | |
private static final String OWNER_PRINCIPAL_NAME_PROPERTY_NAME = "ownedByUser.principalName"; |
56 | |
|
57 | |
private List<Row> localRows; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
@Override |
65 | |
public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) { |
66 | 0 | PessimisticLock lock = (PessimisticLock)businessObject; |
67 | 0 | if ( (lock.isOwnedByUser(GlobalVariables.getUserSession().getPerson())) || (KNSServiceLocatorWeb.getPessimisticLockService().isPessimisticLockAdminUser(GlobalVariables.getUserSession().getPerson())) ) { |
68 | 0 | List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>(); |
69 | 0 | anchorHtmlDataList.add(getUrlData(businessObject, KNSConstants.DELETE_METHOD, pkNames)); |
70 | 0 | return anchorHtmlDataList; |
71 | |
} else { |
72 | 0 | return super.getEmptyActionUrls(); |
73 | |
} |
74 | |
} |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
@Override |
82 | |
public List<Row> getRows() { |
83 | 0 | Person currentUser = GlobalVariables.getUserSession().getPerson(); |
84 | 0 | if (KNSServiceLocatorWeb.getPessimisticLockService().isPessimisticLockAdminUser(currentUser)) { |
85 | 0 | return super.getRows(); |
86 | |
} else { |
87 | 0 | if ( (ObjectUtils.isNull(localRows)) || localRows.isEmpty() ) { |
88 | 0 | List<Field> fieldList = new ArrayList<Field>(); |
89 | 0 | int numColumns = -1; |
90 | |
|
91 | 0 | for (Iterator<Row> iterator = super.getRows().iterator(); iterator.hasNext();) { |
92 | 0 | Row row = (Row) iterator.next(); |
93 | 0 | if (numColumns == -1) { |
94 | 0 | numColumns = row.getFields().size(); |
95 | |
} |
96 | 0 | for (Iterator<Field> iterator2 = row.getFields().iterator(); iterator2.hasNext();) { |
97 | 0 | Field field = (Field) iterator2.next(); |
98 | 0 | if (!(KNSPropertyConstants.OWNED_BY_USER + "." + KIMPropertyConstants.Person.PRINCIPAL_NAME).equals(field.getPropertyName()) && |
99 | |
!Field.BLANK_SPACE.equals(field.getFieldType())) { |
100 | 0 | fieldList.add(field); |
101 | |
} |
102 | 0 | } |
103 | 0 | } |
104 | |
|
105 | 0 | localRows = FieldUtils.wrapFields(fieldList, numColumns); |
106 | |
} |
107 | 0 | return localRows; |
108 | |
} |
109 | |
} |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
@Override |
117 | |
public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) { |
118 | |
|
119 | 0 | LookupUtils.removeHiddenCriteriaFields( getBusinessObjectClass(), fieldValues ); |
120 | |
|
121 | 0 | Person currentUser = GlobalVariables.getUserSession().getPerson(); |
122 | 0 | if (!KNSServiceLocatorWeb.getPessimisticLockService().isPessimisticLockAdminUser(currentUser)) { |
123 | 0 | fieldValues.put(KNSPropertyConstants.OWNED_BY_PRINCIPAL_ID,GlobalVariables.getUserSession().getPerson().getPrincipalId()); |
124 | |
} |
125 | |
|
126 | |
|
127 | 0 | String principalName = fieldValues.get(OWNER_PRINCIPAL_NAME_PROPERTY_NAME); |
128 | 0 | if (!StringUtils.isEmpty(principalName)) { |
129 | 0 | Principal principal = KimApiServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(principalName); |
130 | 0 | if (principal != null) { |
131 | 0 | fieldValues.put(OWNER_PRINCIPAL_ID_PROPERTY_NAME, principal.getPrincipalId()); |
132 | |
} |
133 | 0 | fieldValues.remove(OWNER_PRINCIPAL_NAME_PROPERTY_NAME); |
134 | |
} |
135 | |
|
136 | 0 | setBackLocation(fieldValues.get(KNSConstants.BACK_LOCATION)); |
137 | 0 | setDocFormKey(fieldValues.get(KNSConstants.DOC_FORM_KEY)); |
138 | 0 | setReferencesToRefresh(fieldValues.get(KNSConstants.REFERENCES_TO_REFRESH)); |
139 | 0 | if (LOG.isInfoEnabled()) { |
140 | 0 | LOG.info("Search Criteria: " + fieldValues); |
141 | |
} |
142 | |
|
143 | |
|
144 | |
List searchResults; |
145 | 0 | searchResults = (List) getLookupService().findCollectionBySearchHelper(getBusinessObjectClass(), fieldValues, true); |
146 | |
|
147 | 0 | List defaultSortColumns = getDefaultSortColumns(); |
148 | 0 | if (defaultSortColumns.size() > 0) { |
149 | 0 | Collections.sort(searchResults, new BeanPropertyComparator(getDefaultSortColumns(), true)); |
150 | |
} |
151 | 0 | return searchResults; |
152 | |
} |
153 | |
|
154 | |
@Override |
155 | |
public void validateSearchParameters(Map fieldValues) { |
156 | 0 | super.validateSearchParameters(fieldValues); |
157 | 0 | if (StringUtils.isNotEmpty((String)fieldValues.get(OWNER_PRINCIPAL_NAME_PROPERTY_NAME))) { |
158 | 0 | Person person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName((String)fieldValues.get(OWNER_PRINCIPAL_NAME_PROPERTY_NAME)); |
159 | 0 | if (person == null) { |
160 | 0 | String attributeLabel = getDataDictionaryService().getAttributeLabel(getBusinessObjectClass(), OWNER_PRINCIPAL_NAME_PROPERTY_NAME); |
161 | 0 | GlobalVariables.getMessageMap().putError(OWNER_PRINCIPAL_NAME_PROPERTY_NAME, RiceKeyConstants.ERROR_EXISTENCE, attributeLabel); |
162 | |
} |
163 | |
} |
164 | 0 | } |
165 | |
|
166 | |
} |
167 | |
|