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