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