List of usage examples for org.apache.commons.collections CollectionUtils find
public static Object find(Collection collection, Predicate predicate)
From source file:edu.kit.dama.ui.admin.ServiceAccessTokenDialog.java
private ServiceAccessToken getToken(String userId) throws SecretEncryptionException { String value = (String) authenticatorSelection.getValue(); AbstractAuthenticator selection = (AbstractAuthenticator) CollectionUtils.find(authenticators, (Object o) -> ((AbstractAuthenticator) o).getAuthenticatorId().equals(value)); Map<String, String> credentialMap = new HashMap<>(); if (tokenField == null) { //no credential information } else {/*from ww w . ja v a 2 s .com*/ //token field visible, use caption as key and value as secret credentialMap.put(tokenField.getCaption(), tokenField.getValue()); if (secretField != null) { //secret is also visible, use caption as key and value as secret credentialMap.put(secretField.getCaption(), secretField.getValue()); } } //let the AbstractAuthenticator create the access token as only its implementation 'knows' how the information is stored return selection.generateServiceAccessToken(new UserId(userId), credentialMap); }
From source file:com.epam.cme.storefront.controllers.pages.AccountPageController.java
@RequestMapping(value = "/profile", method = RequestMethod.GET) public String profile(final Model model) throws CMSItemNotFoundException { final List<TitleData> titles = userFacade.getTitles(); final CustomerData customerData = customerFacade.getCurrentCustomer(); if (customerData.getTitleCode() != null) { model.addAttribute("title", CollectionUtils.find(titles, new Predicate() { @Override/*w w w .j av a2s . c o m*/ public boolean evaluate(final Object object) { if (object instanceof TitleData) { return customerData.getTitleCode().equals(((TitleData) object).getCode()); } return false; } })); } model.addAttribute("customerData", customerData); storeCmsPageInModel(model, getContentPageForLabelOrId(PROFILE_CMS_PAGE)); setUpMetaDataForContentPage(model, getContentPageForLabelOrId(PROFILE_CMS_PAGE)); model.addAttribute("breadcrumbs", accountBreadcrumbBuilder.getBreadcrumbs("text.account.profile")); model.addAttribute("metaRobots", "no-index,no-follow"); return ControllerConstants.Views.Pages.Account.AccountProfilePage; }
From source file:com.iggroup.oss.restdoclet.plugin.mojo.RestDocumentationMojo.java
/** * Generates services from the documentation of controllers and * data-binders./* w ww . ja v a 2s. c o m*/ * * @throws BeansNotFoundException if a bean with an identifier or Java type * can't be found. * @throws IOException if services can't be marshaled. * @throws JavadocNotFoundException if a controller's documentation can't be * found. * @throws JiBXException if a JiBX exception occurs. */ private void services() throws IOException, JavadocNotFoundException, JiBXException { LOG.info("Generating services"); DirectoryBuilder dirs = new DirectoryBuilder(baseDirectory, outputDirectory); int identifier = 1; List<Service> services = new ArrayList<Service>(); LOG.info("Looking for mappings"); HashMap<String, ArrayList<Method>> uriMethodMappings = new HashMap<String, ArrayList<Method>>(); HashMap<String, Controller> uriControllerMappings = new HashMap<String, Controller>(); HashMap<String, Collection<Uri>> multiUriMappings = new HashMap<String, Collection<Uri>>(); for (Controller controller : controllers) { LOG.info(new StringBuilder().append("- Controller ").append(controller.getType()).toString()); for (Method method : controller.getMethods()) { LOG.info(new StringBuilder().append("... for Method ").append(method.toString())); if (excludeMethod(method)) { continue; } // Collate multiple uris into one string key. Collection<Uri> uris = method.getUris(); if (!uris.isEmpty()) { String multiUri = ""; for (Uri uri : uris) { multiUri = multiUri + ", " + uri; } multiUriMappings.put(multiUri, uris); ArrayList<Method> methodList = uriMethodMappings.get(multiUri); if (methodList == null) { methodList = new ArrayList<Method>(); uriMethodMappings.put(multiUri, methodList); } methodList.add(method); uriControllerMappings.put(multiUri, controller); } } } LOG.info("Processing controllers..."); for (String uri : uriControllerMappings.keySet()) { LOG.info(new StringBuilder().append("Processing controllers for ").append(uri).toString()); Controller controller = uriControllerMappings.get(uri); LOG.info(new StringBuilder().append("Found controller ") .append(uriControllerMappings.get(uri).getType()).toString()); ArrayList<Method> matches = uriMethodMappings.get(uri); LOG.info(new StringBuilder().append("Found methods ").append(matches.toString()).append(" ") .append(matches.size()).toString()); Service service = new Service(identifier, multiUriMappings.get(uri), new Controller(controller.getType(), controller.getJavadoc(), matches)); services.add(service); service.assertValid(); JiBXUtils.marshallService(service, ServiceUtils.serviceFile(dirs, identifier)); identifier++; } LOG.info("Processing services..."); Services list = new Services(); for (Service service : services) { org.apache.commons.collections.Predicate predicate = new ControllerTypePredicate( service.getController().getType()); if (CollectionUtils.exists(list.getControllers(), predicate)) { ControllerSummary controller = (ControllerSummary) CollectionUtils.find(list.getControllers(), predicate); controller.addService(service); } else { ControllerSummary controller = new ControllerSummary(service.getController().getType(), service.getController().getJavadoc()); controller.addService(service); list.addController(controller); } } LOG.info("Marshalling services..."); list.assertValid(); JiBXUtils.marshallServices(list, ServiceUtils.servicesFile(dirs)); }
From source file:de.hybris.platform.b2bacceleratorfacades.company.impl.DefaultB2BCommerceUserFacade.java
@Override public SearchPageData<B2BUserGroupData> getPagedB2BUserGroupsForCustomer(final PageableData pageableData, final String user) { final SearchPageData<B2BUserGroupModel> userGroups = getB2BCommerceB2BUserGroupService() .getPagedB2BUserGroups(pageableData); final SearchPageData<B2BUserGroupData> searchPageData = convertPageData(userGroups, getB2BUserGroupConverter()); final CustomerData customer = this.getCustomerDataForUid(user); validateParameterNotNull(customer, String.format("No customer found for uid %s", user)); for (final B2BUserGroupData userGroupData : searchPageData.getResults()) { userGroupData.setSelected(CollectionUtils.find(customer.getPermissionGroups(), new BeanPropertyValueEqualsPredicate(B2BUserGroupModel.UID, userGroupData.getUid())) != null); }/*from w w w. j av a 2 s . com*/ return searchPageData; }
From source file:com.dp2345.entity.Cart.java
/** * ??//www .ja v a 2 s . c om * * @return ? */ @Transient public Set<GiftItem> getGiftItems() { Set<GiftItem> giftItems = new HashSet<GiftItem>(); for (Promotion promotion : getPromotions()) { if (promotion.getGiftItems() != null) { for (final GiftItem giftItem : promotion.getGiftItems()) { GiftItem target = (GiftItem) CollectionUtils.find(giftItems, new Predicate() { public boolean evaluate(Object object) { GiftItem other = (GiftItem) object; return other != null && other.getGift().equals(giftItem.getGift()); } }); if (target != null) { target.setQuantity(target.getQuantity() + giftItem.getQuantity()); } else { giftItems.add(giftItem); } } } } return giftItems; }
From source file:net.sourceforge.fenixedu.domain.teacher.TeacherService.java
public ReductionService getReductionService() { return (ReductionService) CollectionUtils.find(getServiceItemsSet(), new Predicate() { @Override/*from w ww . j ava 2 s. c o m*/ public boolean evaluate(Object arg0) { return arg0 instanceof ReductionService; } }); }
From source file:net.sourceforge.fenixedu.domain.teacher.TeacherService.java
public TeacherServiceNotes getTeacherServiceNotes() { return (TeacherServiceNotes) CollectionUtils.find(getServiceItemsSet(), new Predicate() { @Override/* w w w .j a v a2s . c om*/ public boolean evaluate(Object arg0) { return arg0 instanceof TeacherServiceNotes; } }); }
From source file:edu.kit.dama.mdm.dataworkflow.ExecutionEnvironmentConfiguration.java
/** * Check whether this execution environment is applicable for executing the * provided configuration. The check will compare the provided * ExecutionEnvironmentProperties with the required ones defined in the * DataWorkflowConfiguration. True is returned, if the environment provides * all required properties./*from www . ja v a 2 s . com*/ * * @param pConfiguration The configuration to check. * * @return TRUE if all required properties are provided. */ public boolean canExecute(DataWorkflowTaskConfiguration pConfiguration) { Set<? extends IDefaultEnvironmentProperty> required = pConfiguration.getRequiredEnvironmentProperties(); boolean result = true; for (final IDefaultEnvironmentProperty property : required) { IDefaultEnvironmentProperty providedProperty = (IDefaultEnvironmentProperty) CollectionUtils .find(providedEnvironmentProperties, new Predicate() { @Override public boolean evaluate(Object o) { return Long.compare(((IDefaultEnvironmentProperty) o).getId(), property.getId()) == 0; } }); if (providedProperty == null) { //not applicable ... Log this LOGGER.error( "Execution environment with id {} cannot handle task configuration with id {}. Property {} not supported.", getId(), pConfiguration.getId(), property); result = false; break; } } //all available return result; }
From source file:edu.kit.dama.mdm.admin.UserPropertyCollection.java
/** * Remove the property with the provided key. * * @param pKey The key of the property.//from w w w. j a va 2 s.c o m * * @return TRUE if the property has been removed, FALSE if there is no * property with the provided key. */ public boolean removeProperty(final String pKey) { if (pKey == null) { throw new IllegalArgumentException("Argument pKey must not be null"); } LOGGER.debug("Removing property with key {}", pKey); UserProperty existingProp = (UserProperty) CollectionUtils.find(properties, new Predicate() { @Override public boolean evaluate(Object o) { return ((UserProperty) o).getPropertyKey().equals(pKey); } }); boolean result = true; if (existingProp != null) { properties.remove(existingProp); LOGGER.debug("Property removed"); } else { LOGGER.debug("No property found for key {}", pKey); result = false; } return result; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.enrollments.ShiftStudentEnrollmentManagerLookupDispatchAction.java
private SchoolClass searchSchoolClassFrom(final List<SchoolClass> schoolClassesToEnrol, final String classId) { return (SchoolClass) CollectionUtils.find(schoolClassesToEnrol, new Predicate() { @Override// ww w. jav a 2s. c o m public boolean evaluate(Object object) { return ((SchoolClass) object).getExternalId().equals(classId); } }); }