| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kim.web.struts.action; |
| 17 | |
|
| 18 | |
import javax.servlet.http.HttpServletRequest; |
| 19 | |
|
| 20 | |
import org.apache.commons.lang.StringUtils; |
| 21 | |
import org.apache.log4j.Logger; |
| 22 | |
import org.kuali.rice.kim.bo.entity.dto.KimPrincipalInfo; |
| 23 | |
import org.kuali.rice.kim.bo.types.dto.KimTypeInfo; |
| 24 | |
import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember; |
| 25 | |
import org.kuali.rice.kim.bo.ui.KimDocumentRoleQualifier; |
| 26 | |
import org.kuali.rice.kim.bo.ui.PersonDocumentRole; |
| 27 | |
import org.kuali.rice.kim.document.IdentityManagementPersonDocument; |
| 28 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
| 29 | |
import org.kuali.rice.kim.service.support.KimTypeService; |
| 30 | |
import org.kuali.rice.kim.util.KIMPropertyConstants; |
| 31 | |
import org.kuali.rice.kim.web.struts.form.IdentityManagementDocumentFormBase; |
| 32 | |
import org.kuali.rice.kim.web.struts.form.IdentityManagementPersonDocumentForm; |
| 33 | |
import org.kuali.rice.kns.datadictionary.AttributeDefinition; |
| 34 | |
import org.kuali.rice.kns.datadictionary.KimDataDictionaryAttributeDefinition; |
| 35 | |
import org.kuali.rice.kns.datadictionary.KimNonDataDictionaryAttributeDefinition; |
| 36 | |
import org.kuali.rice.kns.util.GlobalVariables; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | 0 | public class IdentityManagementPersonInquiry extends IdentityManagementBaseInquiryAction { |
| 45 | 0 | private static final Logger LOG = Logger.getLogger(IdentityManagementPersonInquiry.class); |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
@Override |
| 52 | |
protected void loadKimObject(HttpServletRequest request, |
| 53 | |
IdentityManagementDocumentFormBase form) { |
| 54 | 0 | IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form; |
| 55 | 0 | String principalId = request.getParameter(KIMPropertyConstants.Person.PRINCIPAL_ID); |
| 56 | 0 | String principalName = request.getParameter(KIMPropertyConstants.Person.PRINCIPAL_NAME); |
| 57 | 0 | if ( StringUtils.isBlank(principalId) && StringUtils.isNotBlank(principalName) ) { |
| 58 | 0 | KimPrincipalInfo principal = KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(principalName); |
| 59 | 0 | if ( principal != null ) { |
| 60 | 0 | principalId = principal.getPrincipalId(); |
| 61 | |
} |
| 62 | |
} |
| 63 | 0 | if ( principalId != null ) { |
| 64 | 0 | personDocumentForm.setPrincipalId(principalId); |
| 65 | 0 | getUiDocumentService().loadEntityToPersonDoc(personDocumentForm.getPersonDocument(), personDocumentForm.getPrincipalId() ); |
| 66 | 0 | personDocumentForm.setCanOverrideEntityPrivacyPreferences(getUiDocumentService().canOverrideEntityPrivacyPreferences(GlobalVariables.getUserSession().getPrincipalId(), personDocumentForm.getPrincipalId())); |
| 67 | 0 | populateRoleInformation( personDocumentForm.getPersonDocument() ); |
| 68 | |
} |
| 69 | 0 | } |
| 70 | |
|
| 71 | |
protected void populateRoleInformation( IdentityManagementPersonDocument personDoc ) { |
| 72 | 0 | for (PersonDocumentRole role : personDoc.getRoles()) { |
| 73 | 0 | KimTypeService kimTypeService = (KimTypeService)KIMServiceLocator.getService(getKimTypeServiceName(role.getKimRoleType())); |
| 74 | |
|
| 75 | |
|
| 76 | |
try { |
| 77 | 0 | role.setDefinitions(kimTypeService.getAttributeDefinitions(role.getKimTypeId())); |
| 78 | 0 | } catch (Exception ex) { |
| 79 | 0 | LOG.warn("Not able to retrieve KimTypeService from remote system for KIM Type Id: " + role.getKimTypeId(), ex); |
| 80 | 0 | } |
| 81 | |
|
| 82 | 0 | role.setNewRolePrncpl(new KimDocumentRoleMember()); |
| 83 | 0 | for (String key : role.getDefinitions().keySet()) { |
| 84 | 0 | KimDocumentRoleQualifier qualifier = new KimDocumentRoleQualifier(); |
| 85 | |
|
| 86 | 0 | setAttrDefnIdForQualifier(qualifier,role.getDefinitions().get(key)); |
| 87 | 0 | role.getNewRolePrncpl().getQualifiers().add(qualifier); |
| 88 | 0 | } |
| 89 | 0 | role.setAttributeEntry( getUiDocumentService().getAttributeEntries( role.getDefinitions() ) ); |
| 90 | 0 | } |
| 91 | 0 | } |
| 92 | |
|
| 93 | |
private void setAttrDefnIdForQualifier(KimDocumentRoleQualifier qualifier,AttributeDefinition definition) { |
| 94 | 0 | if (definition instanceof KimDataDictionaryAttributeDefinition) { |
| 95 | 0 | qualifier.setKimAttrDefnId(((KimDataDictionaryAttributeDefinition)definition).getKimAttrDefnId()); |
| 96 | 0 | qualifier.refreshReferenceObject("kimAttribute"); |
| 97 | |
} else { |
| 98 | 0 | qualifier.setKimAttrDefnId(((KimNonDataDictionaryAttributeDefinition)definition).getKimAttrDefnId()); |
| 99 | 0 | qualifier.refreshReferenceObject("kimAttribute"); |
| 100 | |
|
| 101 | |
} |
| 102 | 0 | } |
| 103 | |
private String getKimTypeServiceName (KimTypeInfo kimType) { |
| 104 | 0 | String serviceName = kimType.getKimTypeServiceName(); |
| 105 | 0 | if (StringUtils.isBlank(serviceName)) { |
| 106 | 0 | serviceName = "kimTypeService"; |
| 107 | |
} |
| 108 | 0 | return serviceName; |
| 109 | |
|
| 110 | |
} |
| 111 | |
|
| 112 | |
} |