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