List of usage examples for org.apache.commons.collections CollectionUtils find
public static Object find(Collection collection, Predicate predicate)
From source file:net.sourceforge.fenixedu.presentationTier.Action.department.ReadPersonProfessorshipsByExecutionYearAction.java
private void prepareConstants(User userView, InfoPerson infoPerson, HttpServletRequest request) throws FenixServiceException { List executionYears = ReadNotClosedExecutionYears.run(); InfoExecutionYear infoExecutionYear = (InfoExecutionYear) CollectionUtils.find(executionYears, new Predicate() { @Override/*w w w . j a v a 2s . c o m*/ public boolean evaluate(Object arg0) { InfoExecutionYear infoExecutionYearElem = (InfoExecutionYear) arg0; if (infoExecutionYearElem.getState().equals(PeriodState.CURRENT)) { return true; } return false; } }); Person person = (Person) FenixFramework.getDomainObject(infoPerson.getExternalId()); InfoDepartment teacherDepartment = null; if (person.getTeacher() != null) { Department department = person.getTeacher().getCurrentWorkingDepartment(); teacherDepartment = InfoDepartment.newInfoFromDomain(department); if (userView == null || !userView.getPerson().hasRole(RoleType.CREDITS_MANAGER)) { final Collection<Department> departmentList = userView.getPerson() .getManageableDepartmentCreditsSet(); request.setAttribute("isDepartmentManager", (departmentList.contains(department) || department == null)); } else { request.setAttribute("isDepartmentManager", Boolean.FALSE); } } else { request.setAttribute("isDepartmentManager", Boolean.TRUE); } request.setAttribute("teacherDepartment", teacherDepartment); request.setAttribute("executionYear", infoExecutionYear); request.setAttribute("executionYears", executionYears); }
From source file:edu.harvard.med.screensaver.model.libraries.Library.java
/** * Get the copy with the given copy name * * @param copyName the copy name of the copy to get * @return the copy with the given copy name *//*from w w w.j ava 2 s.com*/ @Transient public Copy getCopy(final String copyName) { return (Copy) CollectionUtils.find(_copies, new Predicate() { public boolean evaluate(Object e) { return ((Copy) e).getName().equals(copyName); }; }); }
From source file:com.exxonmobile.ace.hybris.storefront.controllers.pages.AccountPageController.java
@RequestMapping(value = "/profile", method = RequestMethod.GET) @RequireHardLogIn/*from w w w. j av a 2 s.co m*/ 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 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:edu.kit.dama.rest.sharing.services.impl.SharingRestServiceImpl.java
@Override public IEntityWrapper<? extends IDefaultGrant> createGrant(String pDomain, String pDomainUniqueId, final String pUserId, String pGroupId, String pRole, HttpContext hc) { IAuthorizationContext ctx = RestUtils.authorize(hc, new GroupId(pGroupId)); try {// ww w . j av a 2s .co m SecurableResourceId resId = factoryResourceId(pDomain, pDomainUniqueId); LOGGER.debug("Checking whether grants are allowed."); if (!ResourceServiceLocal.getSingleton().grantsAllowed(resId, ctx)) { LOGGER.debug("Grants are not allowed. Enabling grants with max. role MANAGER."); //allow grants with max. role MANAGER. //@TODO check whether this should be solved in a configurable way. ResourceServiceLocal.getSingleton().allowGrants(resId, Role.MANAGER, ctx); LOGGER.debug("Grants are now allowed."); } else { LOGGER.debug("Grants are already allowed."); } LOGGER.debug("Adding grant for user {} on resource {}", resId, pUserId); //add grant ResourceServiceLocal.getSingleton().addGrant(resId, new UserId(pUserId), Role.valueOf(pRole), ctx); LOGGER.debug("Obtaining grant information for resource {} from database.", resId); //get all grants as addGrant does not return anything. List<Grant> grants = ResourceServiceLocal.getSingleton().getGrants(resId, ctx); LOGGER.debug("Searching for grantee {}.", pUserId); //search for appropriate grant Grant grant = (Grant) CollectionUtils.find(grants, new Predicate() { @Override public boolean evaluate(Object o) { return ((Grant) o).getGrantee().getUserId().equals(pUserId); } }); if (grant != null) { LOGGER.debug("Grant information successfully obtained. Returning result."); } else { LOGGER.warn("No grant information obtained. Returning empty result."); } //return RestUtils.transformObject(IMPL_CLASSES, Constants.REST_DEFAULT_OBJECT_GRAPH, new GrantWrapper(grant)); return new GrantWrapper(grant); } catch (UnauthorizedAccessAttemptException ex) { LOGGER.error("Failed to create grant", ex); throw new WebApplicationException(401); } catch (EntityNotFoundException ex) { LOGGER.error( "EntityNotFoundException caught while adding Grant. Probably, the resource " + new SecurableResourceId(pDomain, pDomainUniqueId) + " was not registered before.", ex); throw new WebApplicationException(404); } catch (EntityAlreadyExistsException ex) { LOGGER.error( "EntityAlreadyExistsException caught while adding Grant. Probably, there is already a grant for resource " + new SecurableResourceId(pDomain, pDomainUniqueId) + " and user " + pUserId + ".", ex); throw new WebApplicationException(409); } }
From source file:edu.kit.dama.mdm.base.Investigation.java
/** * Check if the investigation contains the provided participant. * * @param pParticipant The participant to check for. * * @return TRUE if the investigation contains the participant. */// w w w .ja va 2 s . co m private boolean containsParticipant(final Participant pParticipant) { return CollectionUtils.find(participants, new Predicate() { @Override public boolean evaluate(Object o) { Participant toCheck = (Participant) o; Task t = pParticipant.getTask(); UserData user = pParticipant.getUser(); boolean result = user.equals(toCheck.getUser()); if (result) { result = (t == null && toCheck.getTask() == null) || (t != null && t.equals(toCheck.getTask())); } return result; } }) != null; }
From source file:net.sourceforge.fenixedu.dataTransferObject.gesdis.InfoSiteCourseInformation.java
private InfoLesson getFilteredInfoLessonByType(List<InfoLesson> infoLessons, ShiftType type) { final ShiftType lessonType = type; InfoLesson infoLesson = (InfoLesson) CollectionUtils.find(infoLessons, new Predicate() { @Override/*from w w w . ja va2 s . co m*/ public boolean evaluate(Object o) { InfoLesson infoLesson = (InfoLesson) o; if (infoLesson.getInfoShift().getShift().getCourseLoadsSet().size() == 1) { return infoLesson.getInfoShift().getShift().containsType(lessonType); } return false; } }); return infoLesson; }
From source file:com.linkedin.pinot.common.query.gen.AvroQueryGenerator.java
private static org.apache.avro.Schema extractSchemaFromUnionIfNeeded(org.apache.avro.Schema fieldSchema) { if ((fieldSchema).getType() == Type.UNION) { fieldSchema = ((org.apache.avro.Schema) CollectionUtils.find(fieldSchema.getTypes(), new Predicate() { @Override//from ww w . j a va 2s .c om public boolean evaluate(Object object) { return ((org.apache.avro.Schema) object).getType() != Type.NULL; } })); } return fieldSchema; }
From source file:edu.kit.dama.staging.services.impl.download.DownloadInformationServiceLocal.java
@Override @SecuredMethod(roleRequired = Role.MEMBER) public DownloadInformation scheduleDownload(DigitalObjectId pDigitalObjectId, IFileTree pFileTree, Map<String, String> pProperties, IAuthorizationContext pSecurityContext) throws TransferPreparationException { LOGGER.info("Executing scheduleDownload({}, {})", new Object[] { pDigitalObjectId, pProperties }); if (null == pDigitalObjectId) { throw new IllegalArgumentException("Argument 'pDigitalObjectId' must not be null"); }/*from w w w .ja v a2 s. c om*/ LOGGER.debug("Checking for digital object with id '{}'", pDigitalObjectId); checkObject(pDigitalObjectId, pSecurityContext); LOGGER.debug("Searching for default staging processors for group '{}'", pSecurityContext.getGroupId()); List<StagingProcessor> processors = StagingConfigurationPersistence.getSingleton() .findStagingProcessorsForGroup(pSecurityContext.getGroupId().getStringRepresentation()); LOGGER.debug("Checking {} staging processor(s)", processors.size()); List<StagingProcessor> defaultProcessors = new ArrayList<>(); for (StagingProcessor processor : processors) { if (processor.isDefaultOn() && processor.isDownloadProcessingSupported() && !processor.isDisabled()) { LOGGER.debug(" - Adding default download staging processor " + processor.getUniqueIdentifier()); defaultProcessors.add(processor); } } TransferClientProperties props = TransferClientPropertiesUtils.mapToProperties(pProperties); final IFileTree tmpTree; if (pFileTree != null) { //download the provided selection only tmpTree = pFileTree; } else { //download entire object try { tmpTree = DataOrganizationServiceLocal.getSingleton().loadFileTree(pDigitalObjectId, pSecurityContext); } catch (EntityNotFoundException enfe) { throw new TransferPreparationException("Unable to prepare download for digital object '" + pDigitalObjectId + "'. No data organization content found.", enfe); } } LOGGER.debug("Converting temporary tree to persistable version"); IFileTree treeToDownload = DataOrganizationUtils.copyTree(tmpTree); final String accessPointId = props.getStagingAccessPointId(); DownloadInformation existingEntity = null; if (accessPointId != null) { List<DownloadInformation> existingEntities = persistenceImpl .getEntitiesByDigitalObjectId(pDigitalObjectId, pSecurityContext); LOGGER.debug("Searching for download associated with access point {}", accessPointId); existingEntity = (DownloadInformation) CollectionUtils.find(existingEntities, new Predicate() { @Override public boolean evaluate(Object o) { return accessPointId.equals(((DownloadInformation) o).getAccessPointId()); } }); } else { LOGGER.warn("AccessPointId is null, skipping search for download with access point."); } DownloadInformation activeDownload; if (existingEntity != null) { LOGGER.debug("Existing download found. Removing local data."); StagingService.getSingleton().flushDownload(existingEntity.getId(), pSecurityContext); LOGGER.debug("Setting download to SCHEDULED"); //reset status and error message existingEntity.setStatusEnum(DOWNLOAD_STATUS.SCHEDULED); existingEntity.setErrorMessage(null); existingEntity.setClientAccessUrl(null); //reset expire timer existingEntity.setExpiresAt(System.currentTimeMillis() + DownloadInformation.DEFAULT_LIFETIME); existingEntity.setAccessPointId(props.getStagingAccessPointId()); LOGGER.debug("Merging processors of transfer properties with processors of existing entity."); Collection<StagingProcessor> mergedProcessors = mergeStagingProcessors(props.getProcessors(), existingEntity.getStagingProcessors()); LOGGER.debug("Merging in default processors."); mergedProcessors = mergeStagingProcessors(mergedProcessors, defaultProcessors); existingEntity.clearStagingProcessors(); for (final StagingProcessor proc : mergedProcessors) { LOGGER.debug("Adding staging processor with id {} to download.", proc.getId()); existingEntity.addStagingProcessor(proc); } //merge the entity with the database activeDownload = persistenceImpl.mergeEntity(existingEntity, pSecurityContext); } else { LOGGER.debug("No entity found for ID '{}'.", pDigitalObjectId); LOGGER.debug("Merging processors of transfer properties with default processors."); Collection<StagingProcessor> merged = mergeStagingProcessors(props.getProcessors(), defaultProcessors); LOGGER.debug("Creating new download entity. "); //no entity for pDigitalObjectId found...create a new one activeDownload = persistenceImpl.createEntity(pDigitalObjectId, props.getStagingAccessPointId(), merged, pSecurityContext); } LOGGER.debug("Creating DownloadPreparationHandler"); DownloadPreparationHandler handler = new DownloadPreparationHandler(persistenceImpl, activeDownload, treeToDownload); LOGGER.debug("Scheduling download"); handler.prepareTransfer(TransferClientPropertiesUtils.mapToProperties(pProperties), pSecurityContext); LOGGER.debug("Download scheduling finished. Obtaining updated entity."); activeDownload = persistenceImpl.getEntityById(activeDownload.getId(), pSecurityContext); LOGGER.debug("Returning download entity."); return activeDownload; }
From source file:net.sourceforge.fenixedu.domain.candidacyProcess.mobility.MobilityApplicationProcess.java
public MobilityCoordinator getCoordinatorForTeacherAndDegree(final Teacher teacher, final Degree degree) { List<MobilityCoordinator> coordinators = getErasmusCoordinatorForTeacher(teacher); return (MobilityCoordinator) CollectionUtils.find(coordinators, new Predicate() { @Override/*from w w w. j a v a 2s . c o m*/ public boolean evaluate(Object arg0) { MobilityCoordinator coordinator = (MobilityCoordinator) arg0; return coordinator.getDegree() == degree; } }); }
From source file:edu.kit.dama.staging.services.impl.ingest.IngestInformationServiceLocal.java
private List<StagingProcessor> mergeStagingProcessors(Collection<StagingProcessor> assignedProcessors, List<StagingProcessor> defaultProcessors) { LOGGER.debug("Checking default staging processors."); if (assignedProcessors == null || assignedProcessors.isEmpty()) { //return defaultProcessors (can't be null, so we do not have to check result) LOGGER.debug("No staging processors assigned, using only default processors."); return defaultProcessors; }/* w ww.j a v a 2 s. c o m*/ LOGGER.debug("Adding all assigned processors to result list."); List<StagingProcessor> result = new ArrayList<>(assignedProcessors); if (defaultProcessors == null || defaultProcessors.isEmpty()) { //return empty list LOGGER.debug("No default processors provided, using only assigned processors."); return result; } LOGGER.debug("Merging {} existing and {} default processor(s)", assignedProcessors.size(), defaultProcessors.size()); for (final StagingProcessor processor : defaultProcessors) { LOGGER.debug("Searching for default processor with id {}", processor.getUniqueIdentifier()); StagingProcessor exists = (StagingProcessor) CollectionUtils.find(assignedProcessors, new Predicate() { @Override public boolean evaluate(Object o) { return Long.compare(((StagingProcessor) o).getId(), processor.getId()) == 0; } }); if (exists == null) { LOGGER.debug("Default processor with id {} is not assigned, yet. Adding it.", processor.getId()); //add as it not exists result.add(processor); } } return result; }