Coverage Report - org.kuali.rice.kim.web.struts.action.IdentityManagementPersonInquiry
 
Classes in this File Line Coverage Branch Coverage Complexity
IdentityManagementPersonInquiry
0%
0/40
0%
0/16
3.25
 
 1  
 /*
 2  
  * Copyright 2007-2009 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * This is a description of what this class does - jonathan don't forget to fill this in. 
 40  
  * 
 41  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 42  
  *
 43  
  */
 44  0
 public class IdentityManagementPersonInquiry extends IdentityManagementBaseInquiryAction {
 45  0
     private static final Logger LOG = Logger.getLogger(IdentityManagementPersonInquiry.class);        
 46  
         /**
 47  
          * This overridden method ...
 48  
          * 
 49  
          * @see org.kuali.rice.kim.web.struts.action.IdentityManagementBaseInquiryAction#loadKimObject(javax.servlet.http.HttpServletRequest, org.kuali.rice.kim.web.struts.form.IdentityManagementDocumentFormBase)
 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  
                 //it is possible that the the kimTypeService is coming from a remote application 
 75  
                 // and therefore it can't be guarenteed that it is up and working, so using a try/catch to catch this possibility.
 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  
                 // when post again, it will need this during populate
 82  0
             role.setNewRolePrncpl(new KimDocumentRoleMember());
 83  0
             for (String key : role.getDefinitions().keySet()) {
 84  0
                     KimDocumentRoleQualifier qualifier = new KimDocumentRoleQualifier();
 85  
                     //qualifier.setQualifierKey(key);
 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  
 }