List of usage examples for org.apache.commons.collections4 CollectionUtils find
@Deprecated public static <T> T find(final Iterable<T> collection, final Predicate<? super T> predicate)
From source file:org.apache.syncope.core.provisioning.java.sync.DBPasswordSyncActions.java
private String getCipherAlgorithm(final ConnInstance connInstance) { ConnConfProperty cipherAlgorithm = CollectionUtils.find(connInstance.getConfiguration(), new Predicate<ConnConfProperty>() { @Override// w ww .j a v a2 s .c o m public boolean evaluate(final ConnConfProperty property) { return "cipherAlgorithm".equals(property.getSchema().getName()) && property.getValues() != null && !property.getValues().isEmpty(); } }); return cipherAlgorithm == null ? CLEARTEXT : (String) cipherAlgorithm.getValues().get(0); }
From source file:org.apache.syncope.core.provisioning.java.sync.LDAPMembershipSyncActions.java
/** * Allows easy subclassing for the ConnId AD connector bundle. * * @param connector A Connector instance to query for the groupMemberAttribute property name * @return the name of the attribute used to keep track of group memberships */// w w w . j a v a 2s. c o m protected String getGroupMembershipAttrName(final Connector connector) { ConnConfProperty groupMembership = CollectionUtils .find(connector.getActiveConnInstance().getConfiguration(), new Predicate<ConnConfProperty>() { @Override public boolean evaluate(final ConnConfProperty property) { return "groupMemberAttribute".equals(property.getSchema().getName()) && property.getValues() != null && !property.getValues().isEmpty(); } }); return groupMembership == null ? "uniquemember" : (String) groupMembership.getValues().get(0); }
From source file:org.apache.syncope.fit.core.reference.RealmITCase.java
private RealmTO getRealm(final String fullPath) { return CollectionUtils.find(realmService.list(fullPath), new Predicate<RealmTO>() { @Override// www . ja v a 2 s. co m public boolean evaluate(final RealmTO object) { return fullPath.equals(object.getFullPath()); } }); }
From source file:org.broadleafcommerce.core.order.service.OrderTest.java
/** * From the list of all Skus in the database, gets a Sku that is active * @return/*w ww .ja v a2 s . co m*/ */ public Sku getFirstActiveSku() { List<Sku> skus = skuDao.readAllSkus(); return CollectionUtils.find(skus, new Predicate<Sku>() { @Override public boolean evaluate(Sku sku) { return sku.isActive(); } }); }
From source file:org.craftercms.profile.services.impl.ProfileServiceImpl.java
protected AttributeDefinition findAttributeDefinition(final List<AttributeDefinition> attributeDefinitions, final String name) { return CollectionUtils.find(attributeDefinitions, new Predicate<AttributeDefinition>() { @Override//www.j ava 2s.com public boolean evaluate(AttributeDefinition definition) { return definition.getName().equals(name); } }); }
From source file:org.kuali.coeus.common.budget.impl.struts.BudgetPersonnelAction.java
/** * This method is used to add a new Personnel Budget Line Item * @param mapping//from www . ja v a 2s .c om * @param form * @param request * @param response * @return mapping forward * @throws Exception */ public ActionForward addPersonnelLineItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { BudgetForm budgetForm = (BudgetForm) form; Budget budget = budgetForm.getBudget(); Integer budgetCategoryTypeIndex = Integer.parseInt(getBudgetCategoryTypeIndex(request)); BudgetLineItem newBudgetLineItem = budgetForm.getNewBudgetLineItems().get(budgetCategoryTypeIndex); final BudgetPersonnelDetails budgetPersonDetails = budgetForm.getNewBudgetPersonnelDetails(); budgetPersonDetails.setBudgetId(budget.getBudgetId()); budgetPersonDetails.setPeriodTypeCode(this.getParameterService().getParameterValueAsString(Budget.class, Constants.BUDGET_PERSON_DETAILS_DEFAULT_PERIODTYPE)); budgetPersonDetails.setCostElement(newBudgetLineItem.getCostElement()); budgetPersonDetails .setBudgetPerson(CollectionUtils.find(budget.getBudgetPersons(), new Predicate<BudgetPerson>() { @Override public boolean evaluate(BudgetPerson object) { return object != null && object.getBudgetId().equals(budgetPersonDetails.getBudgetId()) && object.getPersonSequenceNumber() .equals(budgetPersonDetails.getPersonSequenceNumber()); } })); String groupErrorKey = ""; if (StringUtils.isNotEmpty(newBudgetLineItem.getGroupName())) { groupErrorKey = "newBudgetLineItems[" + budgetCategoryTypeIndex + "].costElement"; } if (StringUtils.isEmpty(newBudgetLineItem.getGroupName())) { newBudgetLineItem.setGroupName(budgetForm.getNewGroupName()); groupErrorKey = "newGroupName"; } //if the group name is empty or still the default group name(JS error?) then set the group name to the empty string. if (StringUtils.isEmpty(newBudgetLineItem.getGroupName()) || StringUtils.equals(newBudgetLineItem.getGroupName(), DEFAULT_GROUP_NAME)) { newBudgetLineItem.setGroupName(EMPTY_GROUP_NAME); } if (getKcBusinessRulesEngine().applyRules( new AddPersonnelBudgetEvent(budget, budget.getBudgetPeriod(budgetForm.getViewBudgetPeriod() - 1), newBudgetLineItem, budgetPersonDetails, groupErrorKey))) { Map<String, Object> primaryKeys = new HashMap<String, Object>(); primaryKeys.put("budgetId", budget.getBudgetId()); primaryKeys.put("budgetPeriod", budgetForm.getViewBudgetPeriod().toString()); List<BudgetPeriod> budgetPeriods = (List<BudgetPeriod>) getBusinessObjectService() .findMatching(BudgetPeriod.class, primaryKeys); BudgetPeriod budgetPeriod = null; if (CollectionUtils.isNotEmpty(budgetPeriods)) { budgetPeriod = budgetPeriods.get(0); } BudgetCategory newBudgetCategory = new BudgetCategory(); newBudgetCategory.setBudgetCategoryTypeCode(getSelectedBudgetCategoryType(request)); newBudgetCategory.refreshNonUpdateableReferences(); boolean existingCeGroupCombo = false; int openTabLineItemIndex = -1; List<BudgetLineItem> existingPersonnelLineItems = new ArrayList<BudgetLineItem>(); List<BudgetLineItem> existingLineItems = budget.getBudgetPeriod(budgetPeriod.getBudgetPeriod() - 1) .getBudgetLineItems(); if (GlobalVariables.getMessageMap().hasNoErrors()) { for (BudgetLineItem budgetLineItem : existingLineItems) { budgetLineItem.refreshNonUpdateableReferences(); if (budgetLineItem.getBudgetCategory().getBudgetCategoryTypeCode() .equalsIgnoreCase(newBudgetCategory.getBudgetCategoryTypeCode())) { existingPersonnelLineItems.add(budgetLineItem); if (newBudgetLineItem.getCostElement().equalsIgnoreCase(budgetLineItem.getCostElement()) && (StringUtils.equals(newBudgetLineItem.getGroupName(), budgetLineItem.getGroupName()) || (StringUtils.isEmpty(newBudgetLineItem.getGroupName()) && StringUtils.isEmpty(budgetLineItem.getGroupName())))) { //Existing ObjCode / Group Name combo - add the new Person to the Line Item's Person List if (budgetPersonDetails.getPersonSequenceNumber().intValue() != -1) { //This is NOT a Summary entry if (getKcBusinessRulesEngine().applyRules(new AddPersonnelLineItemBudgetEvent( budget, "newBudgetPersonnelDetails", budgetLineItem))) { addBudgetPersonnelDetails(budgetForm, budgetPeriod, budgetLineItem, budgetPersonDetails); } } else if (!getKcBusinessRulesEngine() .applyRules(new AddSummaryPersonnelLineItemBudgetEvent(budget, "newBudgetPersonnelDetails", budgetLineItem))) { existingCeGroupCombo = true; break; } openTabLineItemIndex = budgetLineItem.getLineItemNumber(); setLineItemQuantity(budgetLineItem); //set some flag to indicate path of progress existingCeGroupCombo = true; break; } } } //If flag not set, then create a new Budget Line Item - ObjCode / Group Name combo is new if (!existingCeGroupCombo) { newBudgetLineItem.setBudgetPeriod(budgetPeriod.getBudgetPeriod()); newBudgetLineItem.setBudgetPeriodId(budgetPeriod.getBudgetPeriodId()); newBudgetLineItem.setBudgetPeriodBO(budgetPeriod); newBudgetLineItem.setBudgetCategory(newBudgetCategory); newBudgetLineItem.setStartDate( budget.getBudgetPeriod(budgetPeriod.getBudgetPeriod() - 1).getStartDate()); newBudgetLineItem .setEndDate(budget.getBudgetPeriod(budgetPeriod.getBudgetPeriod() - 1).getEndDate()); newBudgetLineItem.setStartDate(newBudgetLineItem.getStartDate()); newBudgetLineItem.setEndDate(newBudgetLineItem.getEndDate()); newBudgetLineItem.setBudgetId(budget.getBudgetId()); newBudgetLineItem.setLineItemNumber(budgetForm.getBudgetDocument() .getHackedDocumentNextValue(Constants.BUDGET_LINEITEM_NUMBER)); newBudgetLineItem.setApplyInRateFlag(true); newBudgetLineItem.refreshReferenceObject("costElementBO"); // on/off campus flag enhancement String onOffCampusFlag = budget.getOnOffCampusFlag(); if (onOffCampusFlag.equalsIgnoreCase(BudgetConstants.DEFAULT_CAMPUS_FLAG)) { newBudgetLineItem .setOnOffCampusFlag(newBudgetLineItem.getCostElementBO().getOnOffCampusFlag()); } else { newBudgetLineItem .setOnOffCampusFlag(onOffCampusFlag.equalsIgnoreCase(Constants.ON_CAMUS_FLAG)); } newBudgetLineItem .setBudgetCategoryCode(newBudgetLineItem.getCostElementBO().getBudgetCategoryCode()); newBudgetLineItem.setLineItemSequence(newBudgetLineItem.getLineItemNumber()); if (budgetPersonDetails.getPersonSequenceNumber().intValue() != -1) { addBudgetPersonnelDetails(budgetForm, budgetPeriod, newBudgetLineItem, budgetPersonDetails); } setLineItemQuantity(newBudgetLineItem); budget.getBudgetPeriod(budgetPeriod.getBudgetPeriod() - 1).getBudgetLineItems() .add(newBudgetLineItem); recalculateBudgetPeriod(budgetForm, budget, budget.getBudgetPeriod(budgetPeriod.getBudgetPeriod() - 1)); getCalculationService().populateCalculatedAmount(budget, newBudgetLineItem); openTabLineItemIndex = newBudgetLineItem.getLineItemNumber(); } BudgetLineItem newLineItemToAdd = budget.getNewBudgetLineItem(); budgetForm.getNewBudgetLineItems().set(budgetCategoryTypeIndex, newLineItemToAdd); request.setAttribute("openTabLineItemIndex", openTabLineItemIndex); budgetForm.setNewBudgetPersonnelDetails(newLineItemToAdd.getNewBudgetPersonnelLineItem()); } } return mapping.findForward(Constants.MAPPING_BASIC); }
From source file:org.kuali.coeus.common.impl.unit.UnitServiceImpl.java
protected List<Unit> getParentUnitsInclusive(List<Unit> units, final String unit) { if (CollectionUtils.isNotEmpty(units)) { final Unit matched = CollectionUtils.find(units, new Predicate<Unit>() { @Override//from www . ja va 2 s. c o m public boolean evaluate(Unit input) { return input.getUnitNumber() != null && input.getUnitNumber().equals(unit); } }); if (matched != null) { final List<Unit> totalMatched = new ArrayList<>(); totalMatched.add(matched); totalMatched.addAll(getParentUnitsInclusive(units, matched.getParentUnitNumber())); return totalMatched; } else if (unit != null) { LOGGER.error("Invalid parent found " + unit); } } return Collections.emptyList(); }
From source file:org.malaguna.cmdit.service.reflection.ReflectionUtils.java
public boolean compareAndUpdateAttribute(Object oldObj, Object newObj, String atributo, boolean update, StringBuffer msgBuffer, String msgContext) { boolean result = false; if (oldObj != null && newObj != null) { oldObj = hpu.unproxy(oldObj);/*w w w .j a v a 2 s . c o m*/ newObj = hpu.unproxy(newObj); if (!isHibernateProxy(oldObj) && !isHibernateProxy(newObj)) { PropertyDescriptor desc = null; try { String firstAttribute = null; String restAttribute = null; int pos = atributo.indexOf("."); if (pos >= 0) { firstAttribute = atributo.substring(0, pos); restAttribute = atributo.substring(pos + 1); } else { firstAttribute = atributo; } desc = PropertyUtils.getPropertyDescriptor(oldObj, firstAttribute); if (desc != null) { Object oldValue = hpu.unproxy(desc.getReadMethod().invoke(oldObj)); Object newValue = hpu.unproxy(desc.getReadMethod().invoke(newObj)); if (restAttribute == null && !isHibernateProxy(oldValue) && !isHibernateProxy(newValue)) { String auxChangeMsg = null; result = (oldValue != null) ? compareObjects(desc, oldValue, newValue) : (newValue == null); if (!result) { if (msgBuffer != null) { auxChangeMsg = buildChangeMessage(desc, firstAttribute, oldValue, newValue, msgContext); } if (update) { updateOldValue(oldObj, desc, oldValue, newValue); } } if (msgBuffer != null) msgBuffer.append(getAppendMsg(auxChangeMsg, msgBuffer)); } if (restAttribute != null) { if (Collection.class.isAssignableFrom(desc.getPropertyType())) { Collection<?> oldSetAux = (Collection<?>) oldValue; Collection<?> newSetAux = (Collection<?>) newValue; if (oldValue != null && newValue != null) { Collection<?> intersection = CollectionUtils.intersection(oldSetAux, newSetAux); for (Object obj : intersection) { RUPredicate rup = new RUPredicate(obj.hashCode()); Object oldElement = CollectionUtils.find(oldSetAux, rup); Object newElement = CollectionUtils.find(newSetAux, rup); String context = (msgContext != null) ? msgContext + firstAttribute : firstAttribute; context += "([" + oldElement.toString() + "])."; compareAndUpdateAttribute(oldElement, newElement, restAttribute, update, msgBuffer, context); } } } else { compareAndUpdateAttribute(oldValue, newValue, restAttribute, update, msgBuffer); } } } } catch (NoSuchMethodException e) { String error = "Error in compareAndUpdateAttribute, class type [%s] has no property [%s]"; throw new RuntimeException(String.format(error, oldObj.getClass(), atributo), e); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return result; }
From source file:org.molasdin.wbase.transaction.profiles.ProfilesManager.java
public TransactionProfile profileFor(final String dbName) { String key = CollectionUtils.find(profiles.keySet(), new Predicate<String>() { @Override/*ww w . j ava 2 s . c om*/ public boolean evaluate(String object) { return StringUtils.containsIgnoreCase(dbName, object); } }); if (key == null) { return commonTransactionProfile; } return profiles.get(key); }
From source file:org.peercast.pecaport.NetworkDeviceManager.java
@Nullable public NetworkInterfaceInfo getActiveInterface() { return CollectionUtils.find(getAllInterfaces(), new Predicate<NetworkInterfaceInfo>() { @Override//from ww w .j ava2 s . com public boolean evaluate(NetworkInterfaceInfo iface) { return iface.isActive(); } }); }