| 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 org.apache.commons.lang.StringUtils; |
| 19 | |
import org.apache.log4j.Logger; |
| 20 | |
import org.kuali.rice.core.api.util.RiceKeyConstants; |
| 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.api.type.KimType; |
| 24 | |
import org.kuali.rice.kim.api.type.KimTypeService; |
| 25 | |
import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember; |
| 26 | |
import org.kuali.rice.kim.bo.ui.KimDocumentRoleQualifier; |
| 27 | |
import org.kuali.rice.kim.bo.ui.PersonDocumentRole; |
| 28 | |
import org.kuali.rice.kim.document.IdentityManagementPersonDocument; |
| 29 | |
import org.kuali.rice.kim.impl.type.KimTypeBo; |
| 30 | |
import org.kuali.rice.kim.service.KIMServiceLocatorInternal; |
| 31 | |
import org.kuali.rice.kim.util.KIMPropertyConstants; |
| 32 | |
import org.kuali.rice.kim.web.struts.form.IdentityManagementDocumentFormBase; |
| 33 | |
import org.kuali.rice.kim.web.struts.form.IdentityManagementPersonDocumentForm; |
| 34 | |
import org.kuali.rice.krad.datadictionary.AttributeDefinition; |
| 35 | |
import org.kuali.rice.krad.datadictionary.KimAttributeDefinition; |
| 36 | |
import org.kuali.rice.krad.util.GlobalVariables; |
| 37 | |
import org.kuali.rice.krad.util.KRADConstants; |
| 38 | |
|
| 39 | |
import javax.servlet.http.HttpServletRequest; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | 0 | public class IdentityManagementPersonInquiry extends IdentityManagementBaseInquiryAction { |
| 49 | 0 | private static final Logger LOG = Logger.getLogger(IdentityManagementPersonInquiry.class); |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
@Override |
| 56 | |
protected void loadKimObject(HttpServletRequest request, |
| 57 | |
IdentityManagementDocumentFormBase form) { |
| 58 | 0 | IdentityManagementPersonDocumentForm personDocumentForm = (IdentityManagementPersonDocumentForm) form; |
| 59 | 0 | String principalId = request.getParameter(KIMPropertyConstants.Person.PRINCIPAL_ID); |
| 60 | 0 | String principalName = request.getParameter(KIMPropertyConstants.Person.PRINCIPAL_NAME); |
| 61 | 0 | if ( StringUtils.isBlank(principalId) && StringUtils.isNotBlank(principalName) ) { |
| 62 | 0 | Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalName); |
| 63 | 0 | if ( principal != null ) { |
| 64 | 0 | principalId = principal.getPrincipalId(); |
| 65 | |
} |
| 66 | |
} |
| 67 | 0 | if ( principalId != null ) { |
| 68 | 0 | Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(principalId); |
| 69 | 0 | if (principal != null) { |
| 70 | 0 | personDocumentForm.setPrincipalId(principalId); |
| 71 | 0 | getUiDocumentService().loadEntityToPersonDoc(personDocumentForm.getPersonDocument(), personDocumentForm.getPrincipalId() ); |
| 72 | 0 | personDocumentForm.setCanOverrideEntityPrivacyPreferences(getUiDocumentService().canOverrideEntityPrivacyPreferences(GlobalVariables.getUserSession().getPrincipalId(), personDocumentForm.getPrincipalId())); |
| 73 | 0 | populateRoleInformation( personDocumentForm.getPersonDocument() ); |
| 74 | |
} else { |
| 75 | 0 | LOG.error("No records found for Person Inquiry."); |
| 76 | 0 | GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_INQUIRY); |
| 77 | |
} |
| 78 | |
} |
| 79 | 0 | } |
| 80 | |
|
| 81 | |
protected void populateRoleInformation( IdentityManagementPersonDocument personDoc ) { |
| 82 | 0 | for (PersonDocumentRole role : personDoc.getRoles()) { |
| 83 | 0 | KimTypeService kimTypeService = (KimTypeService) KIMServiceLocatorInternal.getService(getKimTypeServiceName(KimTypeBo.to(role.getKimRoleType()))); |
| 84 | |
|
| 85 | |
|
| 86 | |
try { |
| 87 | 0 | role.setDefinitions(kimTypeService.getAttributeDefinitions(role.getKimTypeId())); |
| 88 | 0 | } catch (Exception ex) { |
| 89 | 0 | LOG.warn("Not able to retrieve KimTypeService from remote system for KIM Type Id: " + role.getKimTypeId(), ex); |
| 90 | 0 | } |
| 91 | |
|
| 92 | 0 | role.setNewRolePrncpl(new KimDocumentRoleMember()); |
| 93 | 0 | for (String key : role.getDefinitions().keySet()) { |
| 94 | 0 | KimDocumentRoleQualifier qualifier = new KimDocumentRoleQualifier(); |
| 95 | |
|
| 96 | 0 | setAttrDefnIdForQualifier(qualifier,role.getDefinitions().get(key)); |
| 97 | 0 | role.getNewRolePrncpl().getQualifiers().add(qualifier); |
| 98 | 0 | } |
| 99 | 0 | role.setAttributeEntry( getUiDocumentService().getAttributeEntries( role.getDefinitions() ) ); |
| 100 | 0 | } |
| 101 | 0 | } |
| 102 | |
|
| 103 | |
private void setAttrDefnIdForQualifier(KimDocumentRoleQualifier qualifier,AttributeDefinition definition) { |
| 104 | 0 | qualifier.setKimAttrDefnId(((KimAttributeDefinition)definition).getKimAttrDefnId()); |
| 105 | 0 | qualifier.refreshReferenceObject("kimAttribute"); |
| 106 | 0 | } |
| 107 | |
private String getKimTypeServiceName (KimType kimType) { |
| 108 | 0 | String serviceName = kimType.getName(); |
| 109 | 0 | if (StringUtils.isBlank(serviceName)) { |
| 110 | 0 | serviceName = "kimTypeService"; |
| 111 | |
} |
| 112 | 0 | return serviceName; |
| 113 | |
|
| 114 | |
} |
| 115 | |
|
| 116 | |
} |