| 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.Collection; |
| 20 | |
import java.util.Collections; |
| 21 | |
import java.util.Comparator; |
| 22 | |
import java.util.HashMap; |
| 23 | |
import java.util.List; |
| 24 | |
import java.util.Map; |
| 25 | |
import java.util.Properties; |
| 26 | |
|
| 27 | |
import org.apache.commons.lang.StringUtils; |
| 28 | |
import org.kuali.rice.core.util.KeyValue; |
| 29 | |
import org.kuali.rice.core.util.ConcreteKeyValue; |
| 30 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 31 | |
import org.kuali.rice.kim.bo.impl.RoleImpl; |
| 32 | |
import org.kuali.rice.kim.bo.types.dto.AttributeDefinitionMap; |
| 33 | |
import org.kuali.rice.kim.bo.types.dto.KimTypeInfo; |
| 34 | |
import org.kuali.rice.kim.dao.KimRoleDao; |
| 35 | |
import org.kuali.rice.kim.service.KIMServiceLocatorWeb; |
| 36 | |
import org.kuali.rice.kim.util.KimCommonUtilsInternal; |
| 37 | |
import org.kuali.rice.kim.util.KimConstants; |
| 38 | |
import org.kuali.rice.kim.web.struts.form.IdentityManagementRoleDocumentForm; |
| 39 | |
import org.kuali.rice.kns.authorization.BusinessObjectRestrictions; |
| 40 | |
import org.kuali.rice.kns.bo.BusinessObject; |
| 41 | |
import org.kuali.rice.kns.datadictionary.AttributeDefinition; |
| 42 | |
import org.kuali.rice.kns.datadictionary.BusinessObjectEntry; |
| 43 | |
import org.kuali.rice.kns.datadictionary.KimDataDictionaryAttributeDefinition; |
| 44 | |
import org.kuali.rice.kns.datadictionary.KimNonDataDictionaryAttributeDefinition; |
| 45 | |
import org.kuali.rice.kns.lookup.HtmlData; |
| 46 | |
import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData; |
| 47 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
| 48 | |
import org.kuali.rice.kns.service.ModuleService; |
| 49 | |
import org.kuali.rice.kns.util.BeanPropertyComparator; |
| 50 | |
import org.kuali.rice.kns.util.GlobalVariables; |
| 51 | |
import org.kuali.rice.kns.util.KNSConstants; |
| 52 | |
import org.kuali.rice.kns.util.UrlFactory; |
| 53 | |
import org.kuali.rice.kns.web.struts.form.KualiForm; |
| 54 | |
import org.kuali.rice.kns.web.struts.form.LookupForm; |
| 55 | |
import org.kuali.rice.kns.web.ui.Field; |
| 56 | |
import org.kuali.rice.kns.web.ui.Row; |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | 0 | public class RoleLookupableHelperServiceImpl extends KimLookupableHelperServiceImpl { |
| 65 | |
|
| 66 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RoleLookupableHelperServiceImpl.class); |
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | 0 | private List<Row> roleRows = new ArrayList<Row>(); |
| 72 | 0 | private List<Row> attrRows = new ArrayList<Row>(); |
| 73 | |
private KimRoleDao roleDao; |
| 74 | |
private String typeId; |
| 75 | |
private AttributeDefinitionMap attrDefinitions; |
| 76 | |
|
| 77 | |
@Override |
| 78 | |
public List<HtmlData> getCustomActionUrls(BusinessObject bo, List pkNames) { |
| 79 | 0 | RoleImpl roleImpl = (RoleImpl) bo; |
| 80 | 0 | List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>(); |
| 81 | 0 | if(allowsNewOrCopyAction(KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_TYPE_NAME)){ |
| 82 | 0 | anchorHtmlDataList.add(getEditRoleUrl(roleImpl)); |
| 83 | |
} |
| 84 | 0 | return anchorHtmlDataList; |
| 85 | |
} |
| 86 | |
|
| 87 | |
protected HtmlData getEditRoleUrl(RoleImpl roleImpl) { |
| 88 | 0 | String href = ""; |
| 89 | |
|
| 90 | 0 | Properties parameters = new Properties(); |
| 91 | 0 | parameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.DOC_HANDLER_METHOD); |
| 92 | 0 | parameters.put(KNSConstants.PARAMETER_COMMAND, KEWConstants.INITIATE_COMMAND); |
| 93 | 0 | parameters.put(KNSConstants.DOCUMENT_TYPE_NAME, KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_TYPE_NAME); |
| 94 | 0 | parameters.put(KimConstants.PrimaryKeyConstants.ROLE_ID, roleImpl.getRoleId()); |
| 95 | 0 | if (StringUtils.isNotBlank(getReturnLocation())) { |
| 96 | 0 | parameters.put(KNSConstants.RETURN_LOCATION_PARAMETER, getReturnLocation()); |
| 97 | |
} |
| 98 | 0 | href = UrlFactory.parameterizeUrl(KimCommonUtilsInternal.getKimBasePath()+KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_ACTION, parameters); |
| 99 | |
|
| 100 | 0 | AnchorHtmlData anchorHtmlData = new AnchorHtmlData(href, |
| 101 | |
KNSConstants.DOC_HANDLER_METHOD, KNSConstants.MAINTENANCE_EDIT_METHOD_TO_CALL); |
| 102 | 0 | return anchorHtmlData; |
| 103 | |
} |
| 104 | |
|
| 105 | |
@Override |
| 106 | |
protected HtmlData getReturnAnchorHtmlData(BusinessObject businessObject, Properties parameters, LookupForm lookupForm, List returnKeys, BusinessObjectRestrictions businessObjectRestrictions){ |
| 107 | 0 | RoleImpl roleImpl = (RoleImpl) businessObject; |
| 108 | 0 | HtmlData anchorHtmlData = super.getReturnAnchorHtmlData(businessObject, parameters, lookupForm, returnKeys, businessObjectRestrictions); |
| 109 | |
|
| 110 | |
|
| 111 | 0 | KualiForm myForm = (KualiForm) GlobalVariables.getUserSession().retrieveObject(getDocFormKey()); |
| 112 | 0 | if (myForm == null || !(myForm instanceof IdentityManagementRoleDocumentForm)){ |
| 113 | 0 | if(KimTypeLookupableHelperServiceImpl.hasDerivedRoleTypeService(roleImpl.getKimRoleType())){ |
| 114 | 0 | ((AnchorHtmlData)anchorHtmlData).setHref(""); |
| 115 | |
} |
| 116 | |
} |
| 117 | 0 | return anchorHtmlData; |
| 118 | |
} |
| 119 | |
|
| 120 | |
@Override |
| 121 | |
public List<? extends BusinessObject> getSearchResults(java.util.Map<String,String> fieldValues) { |
| 122 | 0 | for (Map.Entry<String,String> entry : fieldValues.entrySet()) { |
| 123 | 0 | if (entry.getKey().equals(KimConstants.PrimaryKeyConstants.KIM_TYPE_ID)) { |
| 124 | 0 | entry.getValue(); |
| 125 | 0 | break; |
| 126 | |
} |
| 127 | |
} |
| 128 | |
|
| 129 | 0 | List<RoleImpl> baseLookup = (List<RoleImpl>)super.getSearchResults(fieldValues); |
| 130 | |
|
| 131 | 0 | return baseLookup; |
| 132 | |
} |
| 133 | |
|
| 134 | |
private List<KeyValue> getRoleTypeOptions() { |
| 135 | 0 | List<KeyValue> options = new ArrayList<KeyValue>(); |
| 136 | 0 | options.add(new ConcreteKeyValue("", "")); |
| 137 | |
|
| 138 | 0 | Collection<KimTypeInfo> kimGroupTypes = KIMServiceLocatorWeb.getTypeInfoService().getAllTypes(); |
| 139 | |
|
| 140 | 0 | for (KimTypeInfo kimType : kimGroupTypes) { |
| 141 | 0 | if (KimTypeLookupableHelperServiceImpl.hasRoleTypeService(kimType)) { |
| 142 | 0 | String value = kimType.getNamespaceCode().trim() + KNSConstants.FIELD_CONVERSION_PAIR_SEPARATOR + kimType.getName().trim(); |
| 143 | 0 | options.add(new ConcreteKeyValue(kimType.getKimTypeId(), value)); |
| 144 | 0 | } |
| 145 | |
} |
| 146 | 0 | Collections.sort(options, new Comparator<KeyValue>() { |
| 147 | |
@Override |
| 148 | |
public int compare(KeyValue k1, KeyValue k2) { |
| 149 | 0 | return k1.getValue().compareTo(k2.getValue()); |
| 150 | |
} |
| 151 | |
}); |
| 152 | 0 | return options; |
| 153 | |
} |
| 154 | |
|
| 155 | |
private String getAttrDefnId(AttributeDefinition definition) { |
| 156 | 0 | if (definition instanceof KimDataDictionaryAttributeDefinition) { |
| 157 | 0 | return ((KimDataDictionaryAttributeDefinition)definition).getKimAttrDefnId(); |
| 158 | |
} else { |
| 159 | 0 | return ((KimNonDataDictionaryAttributeDefinition)definition).getKimAttrDefnId(); |
| 160 | |
|
| 161 | |
} |
| 162 | |
} |
| 163 | |
|
| 164 | |
public List<Row> getRoleRows() { |
| 165 | 0 | return this.roleRows; |
| 166 | |
} |
| 167 | |
|
| 168 | |
public void setRoleRows(List<Row> roleRows) { |
| 169 | 0 | this.roleRows = roleRows; |
| 170 | 0 | } |
| 171 | |
|
| 172 | |
public KimRoleDao getRoleDao() { |
| 173 | 0 | return this.roleDao; |
| 174 | |
} |
| 175 | |
|
| 176 | |
public void setRoleDao(KimRoleDao roleDao) { |
| 177 | 0 | this.roleDao = roleDao; |
| 178 | 0 | } |
| 179 | |
|
| 180 | |
public AttributeDefinitionMap getAttrDefinitions() { |
| 181 | 0 | return this.attrDefinitions; |
| 182 | |
} |
| 183 | |
|
| 184 | |
public void setAttrDefinitions(AttributeDefinitionMap attrDefinitions) { |
| 185 | 0 | this.attrDefinitions = attrDefinitions; |
| 186 | 0 | } |
| 187 | |
|
| 188 | |
public List<Row> getAttrRows() { |
| 189 | 0 | return this.attrRows; |
| 190 | |
} |
| 191 | |
|
| 192 | |
public void setAttrRows(List<Row> attrRows) { |
| 193 | 0 | this.attrRows = attrRows; |
| 194 | 0 | } |
| 195 | |
|
| 196 | |
public String getTypeId() { |
| 197 | 0 | return this.typeId; |
| 198 | |
} |
| 199 | |
|
| 200 | |
public void setTypeId(String typeId) { |
| 201 | 0 | this.typeId = typeId; |
| 202 | 0 | } |
| 203 | |
|
| 204 | |
@Override |
| 205 | |
public List<Row> getRows() { |
| 206 | 0 | new ArrayList<Row>(); |
| 207 | 0 | if (getRoleRows().isEmpty()) { |
| 208 | 0 | List<Row> rows = super.getRows(); |
| 209 | 0 | List<Row> returnRows = new ArrayList<Row>(); |
| 210 | 0 | for (Row row : rows) { |
| 211 | 0 | for (int i = row.getFields().size() - 1; i >= 0; i--) { |
| 212 | 0 | Field field = row.getFields().get(i); |
| 213 | 0 | if (field.getPropertyName().equals("kimTypeId")) { |
| 214 | 0 | Field typeField = new Field(); |
| 215 | 0 | typeField.setFieldLabel("Type"); |
| 216 | 0 | typeField.setPropertyName("kimTypeId"); |
| 217 | 0 | typeField.setFieldValidValues(getRoleTypeOptions()); |
| 218 | 0 | typeField.setFieldType(Field.DROPDOWN); |
| 219 | 0 | typeField.setMaxLength(100); |
| 220 | 0 | typeField.setSize(40); |
| 221 | |
|
| 222 | |
|
| 223 | 0 | row.getFields().set(i, typeField); |
| 224 | |
} |
| 225 | |
} |
| 226 | 0 | returnRows.add(row); |
| 227 | |
} |
| 228 | 0 | setRoleRows(returnRows); |
| 229 | |
|
| 230 | |
} |
| 231 | 0 | if (getAttrRows().isEmpty()) { |
| 232 | |
|
| 233 | 0 | return getRoleRows(); |
| 234 | |
} else { |
| 235 | 0 | List<Row> fullRows = new ArrayList<Row>(); |
| 236 | 0 | fullRows.addAll(getRoleRows()); |
| 237 | |
|
| 238 | 0 | return fullRows; |
| 239 | |
} |
| 240 | |
|
| 241 | |
} |
| 242 | |
|
| 243 | |
@Override |
| 244 | |
protected List<? extends BusinessObject> getSearchResultsHelper( |
| 245 | |
Map<String, String> fieldValues, boolean unbounded) { |
| 246 | |
List searchResults; |
| 247 | 0 | Map<String,String> nonBlankFieldValues = new HashMap<String, String>(); |
| 248 | 0 | boolean includeAttr = false; |
| 249 | 0 | for (String fieldName : fieldValues.keySet()) { |
| 250 | 0 | if (StringUtils.isNotBlank(fieldValues.get(fieldName)) ) { |
| 251 | 0 | nonBlankFieldValues.put(fieldName, fieldValues.get(fieldName)); |
| 252 | 0 | if (fieldName.contains(".")) { |
| 253 | 0 | includeAttr = true; |
| 254 | |
} |
| 255 | |
} |
| 256 | |
} |
| 257 | |
|
| 258 | 0 | if (includeAttr) { |
| 259 | 0 | ModuleService eboModuleService = KNSServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService( getBusinessObjectClass() ); |
| 260 | 0 | BusinessObjectEntry ddEntry = eboModuleService.getExternalizableBusinessObjectDictionaryEntry(getBusinessObjectClass()); |
| 261 | 0 | Map<String,String> filteredFieldValues = new HashMap<String, String>(); |
| 262 | 0 | for (String fieldName : nonBlankFieldValues.keySet()) { |
| 263 | 0 | if (ddEntry.getAttributeNames().contains(fieldName) || fieldName.contains(".")) { |
| 264 | 0 | filteredFieldValues.put(fieldName, nonBlankFieldValues.get(fieldName)); |
| 265 | |
} |
| 266 | |
} |
| 267 | 0 | searchResults = eboModuleService.getExternalizableBusinessObjectsListForLookup(getBusinessObjectClass(), (Map)filteredFieldValues, unbounded); |
| 268 | |
|
| 269 | 0 | } else { |
| 270 | 0 | searchResults = super.getSearchResultsHelper(fieldValues, unbounded); |
| 271 | |
} |
| 272 | 0 | List defaultSortColumns = getDefaultSortColumns(); |
| 273 | 0 | if (defaultSortColumns.size() > 0) { |
| 274 | 0 | Collections.sort(searchResults, new BeanPropertyComparator(defaultSortColumns, true)); |
| 275 | |
} |
| 276 | 0 | return searchResults; |
| 277 | |
|
| 278 | |
} |
| 279 | |
|
| 280 | |
private static final String ROLE_ID_URL_KEY = "&"+KimConstants.PrimaryKeyConstants.ROLE_ID+"="; |
| 281 | |
|
| 282 | |
|
| 283 | |
|
| 284 | |
@Override |
| 285 | |
public HtmlData getInquiryUrl(BusinessObject bo, String propertyName) { |
| 286 | 0 | AnchorHtmlData inquiryHtmlData = (AnchorHtmlData)super.getInquiryUrl(bo, propertyName); |
| 287 | 0 | if(inquiryHtmlData!=null && StringUtils.isNotBlank(inquiryHtmlData.getHref()) && inquiryHtmlData.getHref().contains(ROLE_ID_URL_KEY)) { |
| 288 | 0 | inquiryHtmlData.setHref(getCustomRoleInquiryHref(getBackLocation(), inquiryHtmlData.getHref())); |
| 289 | |
} |
| 290 | 0 | return inquiryHtmlData; |
| 291 | |
} |
| 292 | |
|
| 293 | |
public static String getCustomRoleInquiryHref(String href){ |
| 294 | 0 | return getCustomRoleInquiryHref("", href); |
| 295 | |
} |
| 296 | |
|
| 297 | |
static String getCustomRoleInquiryHref(String backLocation, String href){ |
| 298 | 0 | Properties parameters = new Properties(); |
| 299 | 0 | String hrefPart = ""; |
| 300 | 0 | String docTypeAction = ""; |
| 301 | 0 | if(StringUtils.isBlank(backLocation) || backLocation.contains(KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_ACTION) |
| 302 | |
|| !backLocation.contains(KimConstants.KimUIConstants.KIM_GROUP_DOCUMENT_ACTION)){ |
| 303 | 0 | docTypeAction = KimConstants.KimUIConstants.KIM_ROLE_INQUIRY_ACTION; |
| 304 | |
} else{ |
| 305 | 0 | docTypeAction = KimConstants.KimUIConstants.KIM_GROUP_DOCUMENT_ACTION; |
| 306 | |
} |
| 307 | 0 | if (StringUtils.isNotBlank(href) && href.contains(ROLE_ID_URL_KEY)) { |
| 308 | 0 | int idx1 = href.indexOf("&"+KimConstants.PrimaryKeyConstants.ROLE_ID+"="); |
| 309 | 0 | int idx2 = href.indexOf("&", idx1+1); |
| 310 | 0 | if (idx2 < 0) { |
| 311 | 0 | idx2 = href.length(); |
| 312 | |
} |
| 313 | 0 | parameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.PARAM_MAINTENANCE_VIEW_MODE_INQUIRY); |
| 314 | 0 | hrefPart = href.substring(idx1, idx2); |
| 315 | |
} |
| 316 | 0 | return UrlFactory.parameterizeUrl(KimCommonUtilsInternal.getKimBasePath()+docTypeAction, parameters)+hrefPart; |
| 317 | |
} |
| 318 | |
|
| 319 | |
} |