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