Coverage Report - org.kuali.rice.kim.lookup.PersonLookupableHelperServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PersonLookupableHelperServiceImpl
0%
0/83
0%
0/42
5.4
 
 1  
 /*
 2  
  * Copyright 2007-2008 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.lookup;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Iterator;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 import java.util.Properties;
 23  
 
 24  
 import org.apache.commons.lang.StringUtils;
 25  
 import org.kuali.rice.kew.util.KEWConstants;
 26  
 import org.kuali.rice.kim.bo.Person;
 27  
 import org.kuali.rice.kim.bo.impl.PersonImpl;
 28  
 import org.kuali.rice.kim.util.KIMPropertyConstants;
 29  
 import org.kuali.rice.kim.util.KimCommonUtilsInternal;
 30  
 import org.kuali.rice.kim.util.KimConstants;
 31  
 import org.kuali.rice.kns.bo.BusinessObject;
 32  
 import org.kuali.rice.kns.lookup.HtmlData;
 33  
 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
 34  
 import org.kuali.rice.kns.util.KNSConstants;
 35  
 import org.kuali.rice.kns.util.UrlFactory;
 36  
 import org.kuali.rice.kns.web.ui.Field;
 37  
 import org.kuali.rice.kns.web.ui.Row;
 38  
 
 39  
 /**
 40  
  * This is a description of what this class does - shyu don't forget to fill this in. 
 41  
  * 
 42  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 43  
  *
 44  
  */
 45  0
 public class PersonLookupableHelperServiceImpl  extends KimLookupableHelperServiceImpl {
 46  
         
 47  
         private static final long serialVersionUID = 1971744785776844579L;
 48  
         
 49  
         @Override
 50  
         public List<? extends BusinessObject> getSearchResults(
 51  
                         Map<String, String> fieldValues) {
 52  0
                 if (fieldValues != null && StringUtils.isNotEmpty(fieldValues.get(KIMPropertyConstants.Person.PRINCIPAL_NAME))) {
 53  0
                         fieldValues.put(KIMPropertyConstants.Person.PRINCIPAL_NAME, fieldValues.get(KIMPropertyConstants.Person.PRINCIPAL_NAME).toLowerCase());
 54  
                 }
 55  0
                 return super.getSearchResults(fieldValues);
 56  
         }
 57  
 
 58  
         @SuppressWarnings("unchecked")
 59  
         @Override
 60  
         public List<HtmlData> getCustomActionUrls(BusinessObject bo, List pkNames) {
 61  0
         List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>();
 62  0
                 if(allowsNewOrCopyAction(KimConstants.KimUIConstants.KIM_PERSON_DOCUMENT_TYPE_NAME)){
 63  0
                         String href = "";
 64  0
                         Properties parameters = new Properties();
 65  0
                 parameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.DOC_HANDLER_METHOD);
 66  0
                 parameters.put(KNSConstants.PARAMETER_COMMAND, KEWConstants.INITIATE_COMMAND);
 67  0
                 parameters.put(KNSConstants.DOCUMENT_TYPE_NAME, KimConstants.KimUIConstants.KIM_PERSON_DOCUMENT_TYPE_NAME);
 68  0
                 parameters.put(KimConstants.PrimaryKeyConstants.PRINCIPAL_ID, ((PersonImpl)bo).getPrincipalId());
 69  0
                 if (StringUtils.isNotBlank(getReturnLocation())) {
 70  0
                         parameters.put(KNSConstants.RETURN_LOCATION_PARAMETER, getReturnLocation());         
 71  
                         }
 72  0
                 href = UrlFactory.parameterizeUrl(KimCommonUtilsInternal.getKimBasePath()+KimConstants.KimUIConstants.KIM_PERSON_DOCUMENT_ACTION, parameters);
 73  
         
 74  0
                 AnchorHtmlData anchorHtmlData = new AnchorHtmlData(href, 
 75  
                                 KNSConstants.DOC_HANDLER_METHOD, KNSConstants.MAINTENANCE_EDIT_METHOD_TO_CALL);
 76  
         
 77  0
                     anchorHtmlDataList.add(anchorHtmlData);
 78  
                 }
 79  0
             return anchorHtmlDataList;
 80  
         }
 81  
 
 82  
         @Override
 83  
         public HtmlData getInquiryUrl(BusinessObject bo, String propertyName) {
 84  0
                 HtmlData inqUrl = super.getInquiryUrl(bo, propertyName);
 85  0
                 Properties parameters = new Properties();
 86  0
         parameters.put(KEWConstants.COMMAND_PARAMETER, KEWConstants.INITIATE_COMMAND);
 87  0
         parameters.put(KNSConstants.DOCUMENT_TYPE_NAME, KimConstants.KimUIConstants.KIM_PERSON_DOCUMENT_TYPE_NAME);
 88  0
         parameters.put(KimConstants.PrimaryKeyConstants.PRINCIPAL_ID, ((Person)bo).getPrincipalId());
 89  0
         String href = UrlFactory.parameterizeUrl(KimCommonUtilsInternal.getKimBasePath()+KimConstants.KimUIConstants.KIM_PERSON_INQUIRY_ACTION, parameters);
 90  0
             ((AnchorHtmlData)inqUrl).setHref(href);
 91  0
             return inqUrl;
 92  
         }
 93  
         
 94  
         /**
 95  
          * Checks for the special role lookup parameters and removes/marks read-only the fields in the search criteria.
 96  
          * If present, this method also has a side-effect of updating the title with the role name.
 97  
          * 
 98  
          * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getRows()
 99  
          */
 100  
         @Override
 101  
         public List<Row> getRows() {
 102  0
                 title.remove(); 
 103  0
                 List<Row> rows = super.getRows();
 104  0
                 Iterator<Row> i = rows.iterator();
 105  0
                 String roleName = null;
 106  0
                 String namespaceCode = null;
 107  0
                 while ( i.hasNext() ) {
 108  0
                         Row row = i.next();
 109  0
                         int numFieldsRemoved = 0;
 110  0
                         boolean rowIsBlank = true;
 111  
                         // Since multi-column lookups can be specified on Rice lookups, all the fields in each row must be iterated over as well,
 112  
                         // just in case the person lookup ever gets configured to have multiple columns per row.
 113  0
                         for (Iterator<Field> fieldIter = row.getFields().iterator(); fieldIter.hasNext();) {
 114  0
                             Field field = fieldIter.next();
 115  0
                             String propertyName = field.getPropertyName();
 116  0
                             if ( propertyName.equals("lookupRoleName") ) {
 117  0
                                     Object val = getParameters().get( propertyName );
 118  0
                                     String propVal = null;
 119  0
                                     if ( val != null ) {
 120  0
                                             propVal = (val instanceof String)?(String)val:((String[])val)[0];
 121  
                                     }
 122  0
                                     if ( StringUtils.isBlank( propVal ) ) {
 123  0
                                             fieldIter.remove();
 124  0
                                             numFieldsRemoved++;
 125  
                                     } else {
 126  0
                                             field.setReadOnly(true);
 127  0
                                             field.setDefaultValue( propVal );
 128  0
                                             roleName = propVal;
 129  0
                                             rowIsBlank = false;
 130  
                                     }
 131  0
                             } else if ( propertyName.equals("lookupRoleNamespaceCode") ) {
 132  0
                                     Object val = getParameters().get( propertyName );
 133  0
                                     String propVal = null;
 134  0
                                     if ( val != null ) {
 135  0
                                             propVal = (val instanceof String)?(String)val:((String[])val)[0];
 136  
                                     }
 137  0
                                     if ( StringUtils.isBlank( propVal ) ) {
 138  0
                                             fieldIter.remove();
 139  0
                                             numFieldsRemoved++;
 140  
                                     } else {
 141  0
                                             field.setReadOnly(true);
 142  0
                                             field.setDefaultValue( propVal );
 143  0
                                             namespaceCode = propVal;
 144  0
                                             rowIsBlank = false;
 145  
                                     }                                
 146  0
                             } else if (!Field.BLANK_SPACE.equals(field.getFieldType())) {
 147  0
                                     rowIsBlank = false;
 148  
                             }
 149  0
                         }
 150  
                         // Check if any fields were removed from the row.
 151  0
                         if (numFieldsRemoved > 0) {
 152  
                                 // If fields were removed, check whether or not the remainder of the row is empty or only has blank space fields.
 153  0
                                 if (rowIsBlank) {
 154  
                                         // If so, then remove the row entirely.
 155  0
                                         i.remove();
 156  
                                 } else {
 157  
                                         // Otherwise, add one blank space for each field that was removed, using a technique similar to FieldUtils.createBlankSpace.
 158  
                                         // It is safe to just add blank spaces as needed, since the two removable fields are the last of the visible ones in the list.
 159  0
                                         while (numFieldsRemoved > 0) {
 160  0
                                                 Field blankSpace = new Field();
 161  0
                                                 blankSpace.setFieldType(Field.BLANK_SPACE);
 162  0
                                                 blankSpace.setPropertyName(Field.BLANK_SPACE);
 163  0
                                                 row.getFields().add(blankSpace);
 164  0
                                                 numFieldsRemoved--;
 165  0
                                         }
 166  
                                 }
 167  
                         }
 168  0
                 }
 169  0
                 if ( roleName != null && namespaceCode != null ) {
 170  0
                         title.set( namespaceCode + " " + roleName + " Lookup" );
 171  
                 }
 172  0
                 return rows;
 173  
         }
 174  
         
 175  0
         private ThreadLocal<String> title = new ThreadLocal<String>();
 176  
         public String getTitle() {
 177  0
                 if ( title.get() == null ) {
 178  0
                         return super.getTitle();
 179  
                 }
 180  0
                 return title.get();
 181  
         }
 182  
 }