Coverage Report - org.kuali.rice.krad.uif.control.UserControl
 
Classes in this File Line Coverage Branch Coverage Complexity
UserControl
0%
0/44
0%
0/20
2.25
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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/ecl1.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.krad.uif.control;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 20  
 import org.kuali.rice.kim.service.PersonService;
 21  
 import org.kuali.rice.krad.uif.container.View;
 22  
 import org.kuali.rice.krad.uif.core.Component;
 23  
 import org.kuali.rice.krad.uif.core.MethodInvokerConfig;
 24  
 import org.kuali.rice.krad.uif.field.AttributeField;
 25  
 import org.kuali.rice.krad.uif.field.AttributeQuery;
 26  
 import org.kuali.rice.krad.uif.widget.QuickFinder;
 27  
 
 28  
 /**
 29  
  * Represents a user control, which is a special control to handle
 30  
  * the input of a Person
 31  
  *
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  */
 34  
 public class UserControl extends TextControl {
 35  
 
 36  
     private static final long serialVersionUID = 7468340793076585869L;
 37  
     private String principalIdPropertyName;
 38  
     private String personNamePropertyName;
 39  
     private String personObjectPropertyName;
 40  
 
 41  
     public UserControl() {
 42  0
                 super();
 43  0
         }
 44  
 
 45  
     @Override
 46  
     public void performApplyModel(View view, Object model, Component parent) {
 47  0
         super.performApplyModel(view, model, parent);
 48  
 
 49  0
         if (parent instanceof AttributeField) {
 50  0
             AttributeField field = (AttributeField) parent;
 51  0
             field.getHiddenPropertyNames().add(principalIdPropertyName);
 52  
 
 53  0
             if (!field.isReadOnly())
 54  
             {
 55  0
                 if (StringUtils.isNotBlank(personNamePropertyName)) {
 56  0
                     field.getInformationalDisplayPropertyNames().add(personNamePropertyName);
 57  
                 }
 58  
                 else
 59  
                 {
 60  0
                     field.getInformationalDisplayPropertyNames().add(personObjectPropertyName + ".name");
 61  
                 }
 62  
             }
 63  
 
 64  0
             if (field.isReadOnly() && StringUtils.isBlank(field.getAdditionalDisplayPropertyName())) {
 65  0
                 field.setAdditionalDisplayPropertyName(personObjectPropertyName + ".name");
 66  
             }
 67  
 
 68  0
             AttributeQuery attributeQuery = new AttributeQuery();
 69  0
             MethodInvokerConfig methodInvokerConfig = new MethodInvokerConfig();
 70  0
             PersonService personService = KimApiServiceLocator.getPersonService();
 71  0
             methodInvokerConfig.setTargetObject(personService);
 72  0
             attributeQuery.setQueryMethodInvokerConfig(methodInvokerConfig);
 73  0
             attributeQuery.setQueryMethodToCall("getPersonByPrincipalName");
 74  0
             attributeQuery.getQueryMethodArgumentFieldList().add(field.getPropertyName());
 75  0
             attributeQuery.getReturnFieldMapping().put("principalId", principalIdPropertyName);
 76  
 
 77  0
             if (StringUtils.isNotBlank(personNamePropertyName)) {
 78  0
                 attributeQuery.getReturnFieldMapping().put("name", personNamePropertyName);
 79  
             }
 80  
             else {
 81  0
                 attributeQuery.getReturnFieldMapping().put("name", personObjectPropertyName + ".name");
 82  
             }
 83  
 
 84  0
             field.setFieldAttributeQuery(attributeQuery);
 85  
 
 86  0
             QuickFinder quickFinder = field.getFieldLookup();
 87  
 
 88  0
             if (quickFinder.isRender()) {
 89  0
                 if (StringUtils.isBlank(quickFinder.getDataObjectClassName())) {
 90  0
                     quickFinder.setDataObjectClassName("org.kuali.rice.kim.bo.Person");
 91  
                 }
 92  
 
 93  0
                 if (quickFinder.getFieldConversions().isEmpty()) {
 94  0
                     quickFinder.getFieldConversions().put("principalId", principalIdPropertyName);
 95  
 
 96  0
                     if (StringUtils.isNotBlank(personNamePropertyName)) {
 97  0
                         quickFinder.getFieldConversions().put("name", personNamePropertyName);
 98  
                     }
 99  
                     else {
 100  0
                         quickFinder.getFieldConversions().put("name", personObjectPropertyName + ".name");
 101  
                     }
 102  
 
 103  0
                     quickFinder.getFieldConversions().put("principalName", field.getPropertyName());
 104  
                 }
 105  
             }
 106  
         }
 107  0
     }
 108  
 
 109  
     /**
 110  
          * The name of the property on the parent object that holds the principal id
 111  
          *
 112  
          * @return String principalIdPropertyName
 113  
          */
 114  
     public String getPrincipalIdPropertyName() {
 115  0
         return principalIdPropertyName;
 116  
     }
 117  
 
 118  
     /**
 119  
      * Setter for the name of the property on the parent object that holds the principal id
 120  
      *
 121  
      * @param principalIdPropertyName
 122  
      */
 123  
     public void setPrincipalIdPropertyName(String principalIdPropertyName) {
 124  0
         this.principalIdPropertyName = principalIdPropertyName;
 125  0
     }
 126  
 
 127  
     /**
 128  
          * The name of the property on the parent object that holds the person name
 129  
          *
 130  
          * @return String personNamePropertyName
 131  
          */
 132  
     public String getPersonNamePropertyName() {
 133  0
         return personNamePropertyName;
 134  
     }
 135  
 
 136  
     /**
 137  
      * Setter for the name of the property on the parent object that holds the person name
 138  
      *
 139  
      * @param personNamePropertyName
 140  
      */
 141  
     public void setPersonNamePropertyName(String personNamePropertyName) {
 142  0
         this.personNamePropertyName = personNamePropertyName;
 143  0
     }
 144  
 
 145  
     /**
 146  
          * The name of the property on the parent object that holds the person object
 147  
          *
 148  
          * @return String personObjectPropertyName
 149  
          */
 150  
     public String getPersonObjectPropertyName() {
 151  0
         return personObjectPropertyName;
 152  
     }
 153  
 
 154  
     /**
 155  
      * Setter for the name of the property on the parent object that holds the person object
 156  
      *
 157  
      * @param personObjectPropertyName
 158  
      */
 159  
     public void setPersonObjectPropertyName(String personObjectPropertyName) {
 160  0
         this.personObjectPropertyName = personObjectPropertyName;
 161  0
     }
 162  
 }