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.repo.components.ShareObjectComponent.java
/** * Synchronize the selected values with the database. *//*ww w. jav a 2 s. com*/ private void syncShares() { Set<Object> selection = (Set<Object>) shareList.getValue(); if (selection.isEmpty()) { //not allowed new Notification("Warning", "Failed to update sharing information. At least one user must have access.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); return; } List<UserId> authorizedUsers; List<UserId> privilegedUsers; try { //obtain all users allowed to access the object with write access authorizedUsers = ResourceServiceLocal.getSingleton().getAuthorizedUsers( object.getSecurableResourceId(), Role.MEMBER, AuthorizationContext.factorySystemContext()); //obtain all users allowed to manage the object (add new shares)...this should be typically only one user privilegedUsers = ResourceServiceLocal.getSingleton().getAuthorizedUsers( object.getSecurableResourceId(), Role.MANAGER, AuthorizationContext.factorySystemContext()); } catch (EntityNotFoundException | UnauthorizedAccessAttemptException ex) { LOGGER.error("Failed to obtain authorized users. Committing sharing information failed.", ex); new Notification("Warning", "Failed to obtain authorized users. Updating sharing information failed.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); return; } List<UserId> newShares = new LinkedList<>(); //flag that tells us whether there is at least one privileged user (user with MANAGER role) left. boolean privilegedUserRemains = false; for (Object o : selection) { final UserId uid = new UserId(((String) o)); final UserId existing = (UserId) CollectionUtils.find(authorizedUsers, new Predicate() { @Override public boolean evaluate(Object o) { return ((UserId) o).getStringRepresentation().equals(uid.getStringRepresentation()); } }); if (existing == null) { //not shared with this user yet ... add newShares.add(uid); } else { //The object is already shared with this user and therefore the user should be in the list of authorized users. //As we use this list later for removal, remove the current user id from the list as nothing changes for this user. authorizedUsers.remove(existing); if (!privilegedUserRemains) { //check if the current user is a privileged user. If this is the case, the object is shared with at least one privileged user. UserId privilegedUser = (UserId) CollectionUtils.find(privilegedUsers, new Predicate() { @Override public boolean evaluate(Object o) { return ((UserId) o).getStringRepresentation() .equals(existing.getStringRepresentation()); } }); if (privilegedUser != null) { privilegedUserRemains = true; } } } } //At least one user with the role MANAGER must be left. However, normally only this one user should be able to change sharing information, //therefore this check is actually just to avoid removing yourself from the list of authorized users. if (!privilegedUserRemains) { new Notification("Warning", "Failed to update sharing information. Obviously you tried to remove the owner who has privileged permissions.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); return; } //finally, newShares contains all userIds that have to be added as authorized users, //and authorizedUsers contains all userIds that were authorized before but are currently //not in the selected list, so their sharing status will be dropped. for (UserId newShare : newShares) { try { ResourceServiceLocal.getSingleton().addGrant(object.getSecurableResourceId(), newShare, Role.MEMBER, AuthorizationContext.factorySystemContext()); } catch (EntityNotFoundException | EntityAlreadyExistsException | UnauthorizedAccessAttemptException ex) { LOGGER.error("Failed to grant access for user " + newShare + " to resource " + object.getSecurableResourceId(), ex); new Notification("Error", "Failed to update sharing information.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); return; } } //remove all users that have been authorized before but aren't in the "shared with" side of the list. for (UserId dropShare : authorizedUsers) { try { ResourceServiceLocal.getSingleton().revokeGrant(object.getSecurableResourceId(), dropShare, AuthorizationContext.factorySystemContext()); } catch (EntityNotFoundException | UnauthorizedAccessAttemptException ex) { LOGGER.error("Failed to revoke access for user " + dropShare + " to resource " + object.getSecurableResourceId(), ex); new Notification("Error", "Failed to update sharing information.", Notification.Type.WARNING_MESSAGE).show(Page.getCurrent()); return; } } new Notification("Information", "Successfully updated sharing information.", Notification.Type.TRAY_NOTIFICATION).show(Page.getCurrent()); }
From source file:hudson.plugins.clearcase.ucm.UcmHistoryAction.java
@Override protected List<HistoryEntry> runLsHistory(Date sinceTime, String viewPath, String viewTag, String[] branchNames, String[] viewPaths) throws IOException, InterruptedException { List<HistoryEntry> history = super.runLsHistory(sinceTime, viewPath, viewTag, branchNames, viewPaths); if (needsHistoryOnAllBranches()) { if (oldBaseline == null) { return history; }// w w w .j a v a 2s .c o m List<Baseline> oldBaselines = oldBaseline.getBaselines(); List<Baseline> newBaselines = newBaseline.getBaselines(); if (ObjectUtils.equals(oldBaselines, newBaselines)) { return history; } for (final Baseline oldBl : oldBaselines) { String bl1 = oldBl.getBaselineName(); final String comp1 = oldBl.getComponentName(); // Lookup the component in the set of new baselines Baseline newBl = (Baseline) CollectionUtils.find(newBaselines, new Predicate() { @Override public boolean evaluate(Object bl) { return StringUtils.equals(comp1, ((Baseline) bl).getComponentName()); } }); // If we cannot find a new baseline, log and skip if (newBl == null) { cleartool.getLauncher().getListener().getLogger().print("Old Baseline " + bl1 + " for component " + comp1 + " couldn't be found in the new set of baselines."); continue; } String bl2 = newBl.getBaselineName(); if (!StringUtils.equals(bl1, bl2)) { List<String> versions = UcmCommon.getDiffBlVersions(cleartool, viewPath, "baseline:" + bl1, "baseline:" + bl2); for (String version : versions) { try { parseLsHistory( new BufferedReader(cleartool.describe(getHistoryFormatHandler().getFormat() + OutputFormat.COMMENT + OutputFormat.LINEEND, version)), history); } catch (ParseException e) { /* empty by design */ } } } } } return history; }
From source file:edu.kit.dama.mdm.base.DigitalObjectTransition.java
/** * Add the single object-view input mapping. * * @param pObject The object part of the mapping. * @param pView The view part of the mapping. *//*from w w w . j a v a 2s. c om*/ public void addInputMapping(final DigitalObject pObject, String pView) { if (pObject == null || pObject.getDigitalObjectId() == null) { return; } ObjectViewMapping existing = (ObjectViewMapping) CollectionUtils.find(inputObjectViewMappings, new Predicate() { @Override public boolean evaluate(Object o) { return pObject.getDigitalObjectId() .equals(((ObjectViewMapping) o).getDigitalObject().getDigitalObjectId()); } }); if (existing == null) { inputObjectViewMappings.add(new ObjectViewMapping(pObject, pView)); } }
From source file:gov.nih.nci.caarray.domain.hybridization.Hybridization.java
/** * Return the factor value for the factor with given name in this hybridization. * If there is none, return null./*from www. j a va 2s . c om*/ * @param factorName name of factor for which to find a value. * @return the factor value for factor with given name or null if there is none. */ public AbstractFactorValue getFactorValue(final String factorName) { return (AbstractFactorValue) CollectionUtils.find(getFactorValues(), new Predicate() { public boolean evaluate(Object o) { AbstractFactorValue fv = (AbstractFactorValue) o; return factorName.equals(fv.getFactor().getName()); } }); }
From source file:de.hybris.platform.b2b.testframework.ModelFactory.java
public AddressModel createAddressByUniqueEmail(final String email, final ItemModel owner, final AddressModel addressData) { Assert.assertNotNull("Owner must be given for the address, it can not be null!", owner); Assert.assertNotNull("Email must be given for the address, since it is used as uid for it.", email); Assert.assertNotNull("Address data can contain no values but must be at least initialized!", addressData); AddressModel address = null;/*from w w w . j a v a 2 s . co m*/ try { final Collection<AddressModel> addresses = addressService.getAddressesForOwner(owner); if (CollectionUtils.isNotEmpty(addresses)) { address = (AddressModel) CollectionUtils.find(addresses, new Predicate() { @Override public boolean evaluate(final Object arg0) { final AddressModel a = (AddressModel) arg0; return StringUtils.equals(a.getEmail(), email); } }); } } catch (final Exception e) { // nothing found,create a new one } if (address == null) { address = new AddressModel(); address.setOwner(owner); address.setEmail(email); address.setFirstname(addressData.getFirstname()); address.setLastname(addressData.getLastname()); address.setStreetname(addressData.getStreetname()); address.setStreetnumber(addressData.getStreetnumber()); address.setPostalcode(addressData.getPostalcode()); address.setTown(addressData.getTown()); address.setPhone1(addressData.getPhone1()); modelService.save(address); } return address; }
From source file:com.appleframework.monitor.model.Project.java
public MetricDog findDog(String dogName) { return (MetricDog) CollectionUtils.find(metricDogs, new BeanPropertyValueEqualsPredicate("name", dogName)); }
From source file:edu.kit.dama.mdm.content.oaipmh.impl.SimpleOAIPMHRepository.java
@Override public void listMetadataFormats(OAIPMHBuilder builder) { LOGGER.debug("Performing listMetadataFormats()."); IMetaDataManager mdm = MetaDataManagement.getMetaDataManagement().getMetaDataManager(); mdm.setAuthorizationContext(getAuthorizationContext()); try {/*w ww . ja v a 2 s .com*/ List<MetaDataSchema> schemas; if (builder.getIdentifier() != null) { LOGGER.debug("Getting digital object for identifier {}.", builder.getIdentifier()); //get all schemas existing for identifier...first check identifier DigitalObject result = mdm.findSingleResult( "SELECT o FROM DigitalObject o WHERE o.digitalObjectIdentifier=?1", new Object[] { builder.getIdentifier() }, DigitalObject.class); if (result == null) { LOGGER.error( "No digital object found for identifier {}. Returning OAI-PMH error ID_DOES_NOT_EXIST.", builder.getIdentifier()); builder.addError(OAIPMHerrorcodeType.ID_DOES_NOT_EXIST, "No object for identifier " + builder.getIdentifier() + " found."); } //identifier exists...check metadata for this identifier LOGGER.debug("Digital object found. Getting metadata formats supported by this object."); schemas = mdm.findResultList( "SELECT t.schemaReference FROM MetadataIndexingTask t WHERE t.digitalObjectId=?1", new Object[] { builder.getIdentifier() }, MetaDataSchema.class); LOGGER.debug("Obtained {} metadata formats.", schemas.size()); } else { //get all schemas schemas = mdm.find(MetaDataSchema.class); } MetaDataSchema dcSchema = (MetaDataSchema) CollectionUtils.find(schemas, (Object o) -> { return "dc".equals(((MetaDataSchema) o).getSchemaIdentifier()); }); //add DC schema in every case if (dcSchema == null) { LOGGER.debug("Adding default format Dublin Core to schema list."); schemas.add(DC_SCHEMA); } //add the schemas LOGGER.debug("Adding metadata formats to response."); schemas.stream().forEach((schema) -> { builder.addMetadataFormat(schema.getSchemaIdentifier(), schema.getNamespace(), schema.getMetaDataSchemaUrl()); }); } catch (UnauthorizedAccessAttemptException ex) { //this error is only relevant if there is an object identifier...otherwise, it should not occur as the metadata schema entities are not secured entities. LOGGER.error("Failed to obtain metadata formats for object with identifier " + builder.getIdentifier() + ". Returning OAI-PMH error ID_DOES_NOT_EXIST."); builder.addError(OAIPMHerrorcodeType.ID_DOES_NOT_EXIST, "No object for identifier " + builder.getIdentifier() + " accessible."); } finally { mdm.close(); } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.teacher.professorship.CreateProfessorshipDispatchAction.java
private void setChoosedExecutionPeriod(HttpServletRequest request, List executionPeriodsNotClosed, DynaValidatorForm personExecutionCourseForm) { String executionPeriodIdValue = null; try {//from w ww. ja v a 2 s. c o m executionPeriodIdValue = (String) personExecutionCourseForm.get("executionPeriodId"); } catch (Exception e) { // do nothing } final String executionPeriodId = executionPeriodIdValue; InfoExecutionPeriod infoExecutionPeriod = null; if (executionPeriodId == null) { infoExecutionPeriod = (InfoExecutionPeriod) CollectionUtils.find(executionPeriodsNotClosed, new Predicate() { @Override public boolean evaluate(Object input) { InfoExecutionPeriod infoExecutionPeriod = (InfoExecutionPeriod) input; return infoExecutionPeriod.getState().equals(PeriodState.CURRENT); } }); } else { infoExecutionPeriod = (InfoExecutionPeriod) CollectionUtils.find(executionPeriodsNotClosed, new Predicate() { @Override public boolean evaluate(Object input) { InfoExecutionPeriod infoExecutionPeriod = (InfoExecutionPeriod) input; return infoExecutionPeriod.getExternalId().equals(executionPeriodId); } }); } request.setAttribute("infoExecutionPeriod", infoExecutionPeriod); }
From source file:de.hybris.platform.b2bacceleratorfacades.order.impl.DefaultB2BOrderFacade.java
protected void addCommentToWorkflowAction(final WorkflowActionModel workflowActionModel, final String comment) { final PrincipalModel principalAssigned = workflowActionModel.getPrincipalAssigned(); final B2BApprovalProcessModel attachment = (B2BApprovalProcessModel) CollectionUtils.find( workflowActionModel.getAttachmentItems(), PredicateUtils.instanceofPredicate(B2BApprovalProcessModel.class)); final OrderModel order = attachment.getOrder(); final Collection<B2BPermissionResultModel> b2bPermissionResults = order.getPermissionResults(); for (final B2BPermissionResultModel b2bPermissionResultModel : b2bPermissionResults) { if (b2bPermissionResultModel.getApprover().getUid().equals(principalAssigned.getUid())) { b2bPermissionResultModel.setNote(comment); getModelService().save(b2bPermissionResultModel); }/* www . ja va 2 s . c o m*/ } }
From source file:net.sourceforge.fenixedu.domain.teacher.TeacherService.java
public TeacherPastService getPastService() { return (TeacherPastService) CollectionUtils.find(getServiceItemsSet(), new Predicate() { @Override//from www.j a v a 2 s . c o m public boolean evaluate(Object arg0) { return arg0 instanceof TeacherPastService; } }); }