Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.kuali.rice.kim.lookup;
 
 
 import java.sql.Date;
 import java.util.List;
 import java.util.Map;
 
 import static org.kuali.rice.core.api.criteria.PredicateFactory.*;
 
 
 	// need this so kimtypeId value can be retained in 'rows'
 	// 1st pass populate the grprows
 	// 2nd pass for jsp, no populate, so return the existing one.
     private static final String KIM_TYPE_ID_PROPERTY_NAME = "kimTypeId";
 	private List<RowgrpRows = new ArrayList<Row>();
 	private List<RowattrRows = new ArrayList<Row>();
 	private String typeId = "";
 	private final Map<StringStringgroupTypeValuesCache = new HashMap<StringString>();
 
     @Override
     public List<HtmlDatagetCustomActionUrls(BusinessObject boList pkNames) {
     	GroupBo groupImpl = (GroupBobo;
         List<HtmlDataanchorHtmlDataList = new ArrayList<HtmlData>();
         	anchorHtmlDataList.add(getEditGroupUrl(groupImpl));	
         }
    	return anchorHtmlDataList;
    }
    
    protected HtmlData getEditGroupUrl(GroupBo groupBo) {
    	String href = "";
        Properties parameters = new Properties();
        parameters.put(..groupBo.getId());
        if (StringUtils.isNotBlank(getReturnLocation())) {
		}
        href = UrlFactory.parameterizeUrl(KimCommonUtilsInternal.getKimBasePath()+..parameters);
        
        HtmlData.AnchorHtmlData anchorHtmlData = new HtmlData.AnchorHtmlData(href,
        return anchorHtmlData;
    }

    
Converts GroupInfo objects to GroupBo objects.

Parameters:
fieldValues names and values returned by the Group Lookup screen
Returns:
groupImplList a list of GroupImpl objects
    @Override
    public List<GroupBogetSearchResults(java.util.Map<String,StringfieldValues)  {
        Map<StringStringcriteriaMap = new HashMap<StringString>(fieldValues);
        QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
        criteriaMap.remove(.);
        criteriaMap.remove(.);
        criteriaMap.remove(.);
        String refToRef = criteriaMap.get(.);
        if (StringUtils.isNotBlank(refToRef) && refToRef.equalsIgnoreCase("GroupBo")) {
            criteriaMap.remove(.);
        }
        if (!criteriaMap.isEmpty()) {
            List<Predicatepredicates = new ArrayList<Predicate>();
            //principalId doesn't exist on 'Group'.  Lets do this predicate conversion separately
            if (StringUtils.isNotBlank(criteriaMap.get(..))) {
                QueryByCriteria.Builder principalCriteria = QueryByCriteria.Builder.create();
                Predicate principalPred = like("principalName"criteriaMap.get(..));
                principalCriteria.setPredicates(principalPred);
                //String principalId = KimApiServiceLocator.getIdentityService()
                //        .getPrincipalByPrincipalName(criteriaMap.get(KimConstants.UniqueKeyConstants.PRINCIPAL_NAME)).getPrincipalId();
                PrincipalQueryResults principals = KimApiServiceLocator.getIdentityService()
                        .findPrincipals(principalCriteria.build());
                List<StringprincipalIds = new ArrayList<String>();
                for (Principal principal : principals.getResults()) {
                    principalIds.add(principal.getPrincipalId());
                }
                if (CollectionUtils.isNotEmpty(principalIds)) {
                    Timestamp currentTime = new Timestamp(Calendar.getInstance().getTimeInMillis());
                    predicates.addand(
                                    in("members.memberId"principalIds.toArray(
                                            new String[principalIds.size()])),
                                    equal("members.typeCode"...getCode()),
                                    and(
                                            or(isNull("members.activeFromDateValue"), lessThanOrEqual("members.activeFromDateValue"currentTime)),
                                            or(isNull("members.activeToDateValue"), greaterThan("members.activeToDateValue"currentTime))
                                    )
                                ));
                }
            }
            criteriaMap.remove(..);
            predicates.add(PredicateUtils.convertMapToPredicate(criteriaMap));
            criteria.setPredicates(and(predicates.toArray(new Predicate[predicates.size()])));
        }
    	GroupQueryResults groupResults = KimApiServiceLocator.getGroupService().findGroups(criteria.build());
    	List<Groupgroups = groupResults.getResults();
        //have to convert back to Bos :(
        Map<StringGroupBogroupBos = new HashMap<StringGroupBo>(groups.size());
        for (Group group : groups) {
            if (groupBos.get(group.getId()) == null) {
                groupBos.put(group.getId(), GroupBo.from(group));
            }
        }
    	return new ArrayList<GroupBo>(groupBos.values());
    }
    @Override
    public boolean checkForAdditionalFields(Map<StringStringfieldValues) {
        List<RowattributeRows = setupAttributeRows(fieldValues);
        if (attributeRows.isEmpty()) {
            setAttrRows(attributeRows);
        } else if (CollectionUtils.isEmpty(getAttrRows())) {
            setAttrRows(attributeRows);
        }
        if (getAttrRows().size() > 0) {
            return true;
        }
        return false;
    }
	public List<RowgetRows() {
		if (getGrpRows().isEmpty()) {
			List<Rowrows = super.getRows();
			List<RowreturnRows = new ArrayList<Row>();
			for (Row row : rows) {
				for (int i = row.getFields().size() - 1; i >= 0; i--) {
					Field field = row.getFields().get(i);
						Field typeField = new Field();
						typeField.setFieldLabel("Type");
						row.getFields().set(itypeField);
					}
				}
				returnRows.add(row);
			}
			// principalName
			Field typeField = new Field();
			typeField.setFieldLabel("Principal Name");
			typeField.setMaxLength(40);
			typeField.setSize(20);
			typeField.setQuickFinderClassNameImpl("org.kuali.rice.kim.api.identity.Person");
			typeField.setFieldConversions"principalName:principalName" );
			typeField.setLookupParameters"principalName:principalName" );
			// Identify the best spot to insert the "Principal Name" search field. Note that the code below assumes that the final row of the
			// group search fields is not a row with hidden fields; if this ever becomes the case in the future, this fix may need to
			// be modified accordingly.
			List<Fieldfields = (returnRows.isEmpty()) ? new ArrayList<Field>() : returnRows.get(returnRows.size() - 1).getFields();
			if (!fields.isEmpty() && fields.get(fields.size() - 1).getFieldType().equals(.)) {
				// If the last row in the list has a BLANK_SPACE field coming after any non-BLANK_SPACE fields, add the new field to that row.
				int insertLoc = fields.size() - 1;
				while (insertLoc >= 0 && fields.get(insertLoc).getFieldType().equals(.)) {
					insertLoc--;
				}
				fields.set(insertLoc + 1, typeField);
				returnRows.get(returnRows.size() - 1).setFields(fields);
else {
				// Otherwise, add a new row containing that field.
				int fieldLen = fields.size();
				fields = new ArrayList<Field>();
				fields.add(typeField);
				for (int i = 1; i < fieldLeni++) {
					Field blankSpace = new Field();
					fields.add(blankSpace);
				}
				returnRows.add(new Row(fields));
			}
			setGrpRows(returnRows);
		}
		if (getAttrRows().isEmpty()) {
			return getGrpRows();
		List<RowfullRows = new ArrayList<Row>();
		fullRows.addAll(getGrpRows());
		fullRows.addAll(getAttrRows());
		return fullRows;
	}
	public List<ColumngetColumns() {
		List<Columncolumns =  super.getColumns();
        for (Row row : ) {
            for (Field field : row.getFields()) {
                Column newColumn = new Column();
                newColumn.setColumnTitle(field.getFieldLabel());
                newColumn.setMaxLength(getColumnMaxLength(field.getPropertyName()));
                newColumn.setPropertyName(field.getPropertyName());
                newColumn.setFormatter(field.getFormatter());
                columns.add(newColumn);
            }
        }
        return columns;
	}
    @Override
	public Collection<GroupBoperformLookup(LookupForm lookupFormCollection resultTableboolean bounded) {
        List<GroupBodisplayList;
        // call search method to get results
        if (bounded) {
            displayList = getSearchResults(lookupForm.getFieldsForLookup());
        }
        else {
            displayList = (List<GroupBo>)getSearchResultsUnbounded(lookupForm.getFieldsForLookup());
        }
        HashMap<String,ClasspropertyTypes = new HashMap<StringClass>();
        boolean hasReturnableRow = false;
        List returnKeys = getReturnKeys();
        Person user = GlobalVariables.getUserSession().getPerson();
        // iterate through result list and wrap rows with return url and action urls
        for (Iterator iter = displayList.iterator(); iter.hasNext();) {
            BusinessObject element = (BusinessObjectiter.next();
            if(element instanceof PersistableBusinessObject){
                lookupForm.setLookupObjectId(((PersistableBusinessObject)element).getObjectId());
            }
            BusinessObjectRestrictions businessObjectRestrictions = getBusinessObjectAuthorizationService().getLookupResultRestrictions(elementuser);
            HtmlData returnUrl = getReturnUrl(elementlookupFormreturnKeysbusinessObjectRestrictions);
            String actionUrls = getActionUrls(elementpkNamesbusinessObjectRestrictions);
            //Fix for JIRA - KFSMI-2417
            if("".equals(actionUrls)){
                actionUrls = ;
            }
            List<Columncolumns = getColumns();
            for (Object element2 : columns) {
                Column col = (Columnelement2;
                Formatter formatter = col.getFormatter();
                // pick off result column from result list, do formatting
                String propValue = .;
                Object prop = null;
                if (col.getPropertyName().matches("\\w+\\.\\d+$")) {
                    String id = col.getPropertyName().substring(col.getPropertyName().lastIndexOf('.') + 1); //.split("\\d+$"))[1];
                    prop = ((GroupBo)element).getGroupAttributeValueById(id);
                }
                if (prop == null) {
                    prop = ObjectUtils.getPropertyValue(elementcol.getPropertyName());
                } else {
                }
                // set comparator and formatter based on property type
                Class propClass = propertyTypes.get(col.getPropertyName());
                if ( propClass == null /*&& !skipPropTypeCheck*/) {
                    try {
                        propClass = ObjectUtils.getPropertyTypeelementcol.getPropertyName(), getPersistenceStructureService() );
                        propertyTypes.putcol.getPropertyName(), propClass );
                    } catch (Exception e) {
                        throw new RuntimeException("Cannot access PropertyType for property " + "'" + col.getPropertyName() + "' " + " on an instance of '" + element.getClass().getName() + "'."e);
                    }
                }
                // formatters
                if (prop != null) {
                    // for Booleans, always use BooleanFormatter
                    if (prop instanceof Boolean) {
                        formatter = new BooleanFormatter();
                    }
                    // for Dates, always use DateFormatter
                    if (prop instanceof Date) {
                        formatter = new DateFormatter();
                    }
                    // for collection, use the list formatter if a formatter hasn't been defined yet
                    if (prop instanceof Collection && formatter == null) {
                    formatter = new CollectionFormatter();
                    }
                    if (formatter != null) {
                        propValue = (Stringformatter.format(prop);
                    }
                    else {
                        propValue = prop.toString();
                        if (col.getPropertyName().equals()) {
                            propValue = .get(prop.toString());
                        }
                    }
                }
                // comparator
                col.setComparator(CellComparatorHelper.getAppropriateComparatorForPropertyClass(propClass));
                col.setValueComparator(CellComparatorHelper.getAppropriateValueComparatorForPropertyClass(propClass));
                propValue = maskValueIfNecessary(element.getClass(), col.getPropertyName(), propValuebusinessObjectRestrictions);
                col.setPropertyValue(propValue);
                if (StringUtils.isNotBlank(propValue)) {
                    col.setColumnAnchor(getInquiryUrl(elementcol.getPropertyName()));
                }
            }
            ResultRow row = new ResultRow(columnsreturnUrl.constructCompleteHtmlTag(), actionUrls);
            row.setRowId(returnUrl.getName());
            row.setReturnUrlHtmlData(returnUrl);
            // because of concerns of the BO being cached in session on the ResultRow,
            // let's only attach it when needed (currently in the case of export)
                row.setBusinessObject(element);
            }
            if(element instanceof PersistableBusinessObject){
                row.setObjectId((((PersistableBusinessObject)element).getObjectId()));
            }
            boolean rowReturnable = isResultReturnable(element);
            row.setRowReturnable(rowReturnable);
            if (rowReturnable) {
                hasReturnableRow = true;
            }
            resultTable.add(row);
        }
        lookupForm.setHasReturnableRow(hasReturnableRow);
        return displayList;
    }
		List<KeyValueoptions = new ArrayList<KeyValue>();
		options.add(new ConcreteKeyValue(""""));
		Collection<KimTypekimGroupTypes = KimApiServiceLocator.getKimTypeInfoService().findAllKimTypes();
		// get the distinct list of type IDs from all groups in the system
        for (KimType kimType : kimGroupTypes) {
            if (KimTypeLookupableHelperServiceImpl.hasGroupTypeService(kimType) && .get(kimType.getId()) == null) {
                String value = kimType.getNamespaceCode().trim() + . + kimType.getName().trim();
                options.add(new ConcreteKeyValue(kimType.getId(), value));
            }
        }
        Collections.sort(optionsnew Comparator<KeyValue>() {
           @Override
           public int compare(KeyValue k1KeyValue k2) {
               return k1.getValue().compareTo(k2.getValue());
           }
        });
		return options;
	}
	private List<RowsetupAttributeRows(Map fieldValues) {
		List<RowreturnRows = new ArrayList<Row>();
		for (Row row : getGrpRows()) {
			Field field = row.getFields().get(0);
				if (!StringUtils.isBlank(getTypeId()) || !getTypeId().equals(field.getPropertyValue())) {
					KimTypeService kimTypeService = KimFrameworkServiceLocator.getKimTypeService(kimType);
			        List<KimAttributeFielddefinitions = kimTypeService.getAttributeDefinitions(kimType.getId());
			        setAttrDefinitions(definitions);
		            for (KimAttributeField d  : definitions) {
				        final AttributeDefinition definition  = DataDictionaryTypeServiceHelper
                                .toKimAttributeDefinition(d);
                        List<Fieldfields = new ArrayList<Field>();
						Field typeField = new Field();
						String attrDefnId = d.getId();
						typeField.setFieldLabel(definition.getLabel());
						typeField.setPropertyName("attributes(" + definition.getName()+")");
						typeField.setPropertyValue(fieldValues.get(typeField.getPropertyName()));
						if (definition.getControl().isSelect()) {
                            typeField.setFieldValidValues(definition.getOptionsFinder().getKeyValues());
                            typeField.setFieldType(.);
else if (definition.getControl().isText()){
							typeField.setMaxLength(definition.getMaxLength());
							if (definition.getControl().getSize() != null) {
							    typeField.setSize(definition.getControl().getSize());
							}
						    typeField.setFieldType(.);
else if (definition.getControl().isRadio()) {
                            typeField.setFieldValidValues(definition.getOptionsFinder().getKeyValues());
                            typeField.setFieldType(.);
else if (definition.getControl().isCheckbox()) {
						    KeyValuesFinder finder = new IndicatorValuesFinder();
                            typeField.setFieldValidValues(finder.getKeyValues());
                            typeField.setFieldType(.);
						    //typeField.setFieldType(Field.CHECKBOX);
else if (definition.getControl().isHidden()) {
						    typeField.setFieldType(.);
else if (definition.getControl().isLookupReadonly()) {
else if (definition.getControl().isTextarea()) {
						    typeField.setMaxLength(definition.getMaxLength());
                            if (definition.getControl().getSize() != null) {
                                typeField.setSize(definition.getControl().getSize());
                            }
                            typeField.setFieldType(.);
						}
						fields.add(typeField);
						returnRows.add(new Row(fields));
		            }
else {
					return getAttrRows();
				}
else if (field.getPropertyName().equals() && StringUtils.isBlank(field.getPropertyValue())) {
			}
		}
		return returnRows;
	}
	public List<RowgetGrpRows() {
		return this.;
	}
	public void setGrpRows(List<RowgrpRows) {
		this. = grpRows;
	}
		return this.;
	}
	public void setAttrDefinitions(List<KimAttributeFieldattrDefinitions) {
		this. = attrDefinitions;
	}
	public List<RowgetAttrRows() {
		return this.;
	}
	public void setAttrRows(List<RowattrRows) {
		this. = attrRows;
	}
	public String getTypeId() {
		return this.;
	}
	public void setTypeId(String typeId) {
		this. = typeId;
	}
    @Override
    public void performClear(LookupForm lookupForm) {
        super.performClear(lookupForm);
        this. = new ArrayList<Row>();
    }
New to GrepCode? Check out our FAQ X