List of usage examples for org.apache.commons.collections Predicate Predicate
Predicate
From source file:net.sf.wickedshell.facade.descriptor.XMLShellDescriptor.java
/** * @see net.sf.wickedshell.facade.descriptor.IShellDescriptor#isExecutable(java.io.File) *//*ww w . j a va 2 s .c o m*/ public boolean isExecutable(final File file) { return CollectionUtils.exists(Arrays.asList(getExecutableFiles(false)), new Predicate() { /** * @see org.apache.commons.collections.Predicate#evaluate(java.lang.Object) */ public boolean evaluate(Object object) { IExecutableFile executableFile = (IExecutableFile) object; return file.getName().endsWith(executableFile.getExtension()); } }); }
From source file:edu.kit.dama.mdm.admin.UserPropertyCollection.java
/** * Set the value of property with key pKey to pValue. If there is no property * with the provided key, a new property is added. If the provided value is * null, the property with the provided key will be removed. * * @param pKey The property key. This value must not be null. * @param pValue The property value. If pValue is null, the property will be * removed.// ww w . j a v a 2 s .c o m * * @return TRUE if a property has been modified/added/removed, FALSE if the * removal failed. */ public boolean setStringProperty(final String pKey, String pValue) { if (pKey == null) { throw new IllegalArgumentException("Argument pKey must not be null"); } boolean result = true; if (pValue == null) { LOGGER.debug("Provided property value is null. Removing property."); return removeProperty(pKey); } LOGGER.debug("Setting property with key {} to value {}", new Object[] { pKey, pValue }); UserProperty existingProp = (UserProperty) CollectionUtils.find(properties, new Predicate() { @Override public boolean evaluate(Object o) { return ((UserProperty) o).getPropertyKey().equals(pKey); } }); if (existingProp == null) { LOGGER.debug("Adding new property"); properties.add(new UserProperty(pKey, pValue)); } else { LOGGER.debug("Updating existing property"); existingProp.setPropertyValue(pValue); } return result; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.department.ReadTeacherProfessorshipsByExecutionYearAction.java
private void prepareConstants(User userView, InfoTeacher infoTeacher, HttpServletRequest request) throws FenixServiceException { List executionYears = ReadNotClosedExecutionYears.run(); InfoExecutionYear infoExecutionYear = (InfoExecutionYear) CollectionUtils.find(executionYears, new Predicate() { @Override/*w w w .j av a2 s . com*/ public boolean evaluate(Object arg0) { InfoExecutionYear infoExecutionYearElem = (InfoExecutionYear) arg0; if (infoExecutionYearElem.getState().equals(PeriodState.CURRENT)) { return true; } return false; } }); Department department = infoTeacher.getTeacher().getCurrentWorkingDepartment(); InfoDepartment teacherDepartment = InfoDepartment.newInfoFromDomain(department); if (userView == null || !userView.getPerson().hasRole(RoleType.CREDITS_MANAGER)) { final Collection<Department> departmentList = userView.getPerson().getManageableDepartmentCreditsSet(); request.setAttribute("isDepartmentManager", Boolean.valueOf(departmentList.contains(department))); } else { request.setAttribute("isDepartmentManager", Boolean.FALSE); } request.setAttribute("teacherDepartment", teacherDepartment); request.setAttribute("executionYear", infoExecutionYear); request.setAttribute("executionYears", executionYears); }
From source file:com.linkedin.pinot.common.data.Schema.java
@JsonIgnore(true) public DimensionFieldSpec getDimensionSpec(final String dimensionName) { return (DimensionFieldSpec) CollectionUtils.find(dimensionFieldSpecs, new Predicate() { @Override//ww w . j av a2 s .c o m public boolean evaluate(Object object) { if (object instanceof DimensionFieldSpec) { DimensionFieldSpec spec = (DimensionFieldSpec) object; return spec.getName().equals(dimensionName); } return false; } }); }
From source file:edu.kit.dama.ui.repo.components.ShareObjectComponent.java
/** * Synchronize the selected values with the database. *///from w w w .j ava 2 s.co m 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; }//from ww w. j a v a 2 s. com 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:com.perceptive.epm.perkolcentral.bl.EmployeeBL.java
@TriggersRemove(cacheName = { "EmployeeCache", "GroupCache", "EmployeeKeyedByGroupCache" }, when = When.AFTER_METHOD_INVOCATION, removeAll = true, keyGenerator = @KeyGenerator(name = "HashCodeCacheKeyGenerator", properties = @Property(name = "includeMethod", value = "false"))) @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE, rollbackFor = ExceptionWrapper.class) public void updateEmployeeLicenseMap(String employeeId, ArrayList<String> licenseIds) throws ExceptionWrapper { try {// ww w . j a v a 2 s . c om ArrayList<Employeelicensemapping> employeelicensemappingArrayList = employeeDataAccessor .getEmployeeLicenseMapByEmployeeId(employeeId); for (Object item : employeelicensemappingArrayList) { final Employeelicensemapping employeelicensemapping = (Employeelicensemapping) item; if (!CollectionUtils.exists(licenseIds, new Predicate() { @Override public boolean evaluate(Object o) { return ((String) o).trim().equalsIgnoreCase( employeelicensemapping.getLicensemaster().getLicenseTypeId().toString()); } })) { employeeDataAccessor.deleteEmployeeLicenseMap(employeelicensemapping); } } for (Object item : licenseIds) { final String licenseTypeId = (String) item; if (licenseTypeId.trim().equalsIgnoreCase("")) continue; if (!CollectionUtils.exists(employeelicensemappingArrayList, new Predicate() { @Override public boolean evaluate(Object o) { return ((Employeelicensemapping) o).getLicensemaster().getLicenseTypeId().toString() .equalsIgnoreCase(licenseTypeId.trim()); } })) { employeeDataAccessor.addEmployeeLicenseMap(employeeId, licenseTypeId); } } } catch (Exception ex) { throw new ExceptionWrapper(ex); } }
From source file:net.sourceforge.fenixedu.domain.candidacyProcess.mobility.MobilityIndividualApplication.java
public List<ApprovedLearningAgreementDocumentFile> getActiveApprovedLearningAgreements() { List<ApprovedLearningAgreementDocumentFile> activeDocuments = new ArrayList<ApprovedLearningAgreementDocumentFile>(); CollectionUtils.select(getApprovedLearningAgreementsSet(), new Predicate() { @Override// w w w. j a va 2 s .c o m public boolean evaluate(Object arg0) { ApprovedLearningAgreementDocumentFile document = (ApprovedLearningAgreementDocumentFile) arg0; return document.getCandidacyFileActive(); } }, activeDocuments); return activeDocuments; }
From source file:com.perceptive.epm.perkolcentral.action.ImageNowLicenseAction.java
private void getSpecificGroupsThatRequireINLicense() throws ExceptionWrapper { try {//from w w w. j a v a2s. c o m if (rallyGroups == null) return; ArrayList<GroupBO> groupBOArrayList = new ArrayList<GroupBO>(groupsBL.getAllGroups().values()); CollectionUtils.filter(groupBOArrayList, new Predicate() { @Override public boolean evaluate(Object o) { return ((GroupBO) o).getGroupId().trim().equalsIgnoreCase("22"); } }); for (GroupBO groupBO : groupBOArrayList) { rallyGroups.add(groupBO); } } catch (Exception ex) { throw new ExceptionWrapper(ex); } }
From source file:net.sourceforge.fenixedu.domain.teacher.TeacherService.java
public List<DegreeTeachingService> getDegreeTeachingServices() { return (List<DegreeTeachingService>) CollectionUtils.select(getServiceItemsSet(), new Predicate() { @Override// w w w.j a v a 2 s.c o m public boolean evaluate(Object arg0) { return arg0 instanceof DegreeTeachingService; } }); }