Example usage for org.apache.commons.collections Transformer Transformer

List of usage examples for org.apache.commons.collections Transformer Transformer

Introduction

In this page you can find the example usage for org.apache.commons.collections Transformer Transformer.

Prototype

Transformer

Source Link

Usage

From source file:fr.itldev.koya.alfservice.KoyaNodeService.java

/**
 *
 * @param parent//  w w w  .j  ava2s .c om
 * @param skipCount
 * @param maxItems
 * @param onlyFolders
 * @return
 * @throws KoyaServiceException
 */
public Pair<List<SecuredItem>, Pair<Integer, Integer>> listChildrenPaginated(NodeRef parent,
        final Integer skipCount, final Integer maxItems, final boolean onlyFolders, final String namePattern)
        throws KoyaServiceException {

    Integer skip = skipCount;
    Integer max = maxItems;
    if (skipCount == null) {
        skip = Integer.valueOf(0);
    }
    if (maxItems == null) {
        max = Integer.MAX_VALUE;
    }
    List<Pair<QName, Boolean>> sortProps = new ArrayList() {
        private static final long serialVersionUID = 1L;

        {
            add(new Pair<>(GetChildrenCannedQuery.SORT_QNAME_NODE_IS_FOLDER, false));
            add(new Pair<>(ContentModel.PROP_TITLE, true));
        }
    };

    PagingRequest pr = new PagingRequest(skip, max);
    pr.setRequestTotalCountMax(Integer.MAX_VALUE);

    PagingResults<FileInfo> results = fileFolderService.list(parent, !onlyFolders, true, namePattern, null,
            sortProps, pr);

    List children = results.getPage();

    /**
     * Transform List<FileInfo> as List<SecuredItem>
     */
    CollectionUtils.transform(children, new Transformer() {
        @Override
        public Object transform(Object input) {
            try {
                return getSecuredItem(((FileInfo) input).getNodeRef());
            } catch (KoyaServiceException ex) {
                return null;
            }
        }
    });

    return new Pair<List<SecuredItem>, Pair<Integer, Integer>>(children, results.getTotalResultCount());
}

From source file:edu.jhuapl.openessence.web.util.ControllerUtils.java

/**
 * Return a Collection of string ids from dimensions.
 *//*w w  w  . j a  va 2s .  c o  m*/
@SuppressWarnings("unchecked")
public static Collection<String> getDimensionIdsFromCollection(Collection<Dimension> dims) {
    Collection<String> ids = (Collection<String>) CollectionUtils.collect(dims, new Transformer() {
        @Override
        public Object transform(Object input) {
            Dimension dim = (Dimension) input;
            return dim.getId();
        }
    });
    return ids;
}

From source file:net.sourceforge.fenixedu.domain.StudentCurricularPlan.java

final public boolean isCurricularCourseApproved(CurricularCourse curricularCourse) {
    List studentApprovedEnrollments = getStudentEnrollmentsWithApprovedState();

    List<CurricularCourse> result = (List<CurricularCourse>) CollectionUtils.collect(studentApprovedEnrollments,
            new Transformer() {
                @Override//from   w  w  w . ja v  a  2  s  . c om
                final public Object transform(Object obj) {
                    Enrolment enrollment = (Enrolment) obj;

                    return enrollment.getCurricularCourse();

                }
            });

    return isApproved(curricularCourse, result);
}

From source file:net.sourceforge.fenixedu.domain.StudentCurricularPlan.java

final public boolean isEquivalentAproved(CurricularCourse curricularCourse) {
    List studentApprovedEnrollments = getStudentEnrollmentsWithApprovedState();

    List<CurricularCourse> result = (List) CollectionUtils.collect(studentApprovedEnrollments,
            new Transformer() {
                @Override//from  w w w.  j  a  va 2s .co  m
                final public Object transform(Object obj) {
                    Enrolment enrollment = (Enrolment) obj;

                    return enrollment.getCurricularCourse();

                }
            });

    return isThisCurricularCoursesInTheList(curricularCourse, result)
            || hasEquivalenceInNotNeedToEnroll(curricularCourse);
}

From source file:net.sourceforge.fenixedu.domain.StudentCurricularPlan.java

final public boolean isCurricularCourseEnrolled(CurricularCourse curricularCourse) {
    List result = (List) CollectionUtils.collect(getStudentEnrollmentsWithEnrolledState(), new Transformer() {
        @Override/*from   ww w . j av a  2  s  .co m*/
        final public Object transform(Object obj) {
            Enrolment enrollment = (Enrolment) obj;
            return enrollment.getCurricularCourse();
        }
    });

    return result.contains(curricularCourse);
}

From source file:net.sourceforge.fenixedu.domain.StudentCurricularPlan.java

private List<CurricularCourse> getStudentNotNeedToEnrollCurricularCourses() {
    return (List<CurricularCourse>) CollectionUtils.collect(getNotNeedToEnrollCurricularCoursesSet(),
            new Transformer() {
                @Override//from www.  j  a v  a2  s  . c  o m
                final public Object transform(Object obj) {
                    NotNeedToEnrollInCurricularCourse notNeedToEnrollInCurricularCourse = (NotNeedToEnrollInCurricularCourse) obj;
                    return notNeedToEnrollInCurricularCourse.getCurricularCourse();
                }
            });
}

From source file:nl.strohalm.cyclos.services.accounts.guarantees.CertificationServiceImpl.java

@Override
@SuppressWarnings("unchecked")
public List<CertificationDTO> searchWithUsedAmount(final CertificationQuery queryParameters) {
    final List<Certification> certifications = certificationDao.seach(queryParameters);

    final Transformer transformer = new Transformer() {
        @Override//from  w  ww.j a v  a  2 s  .c  om
        public Object transform(final Object input) {
            final Certification certification = (Certification) input;
            return new CertificationDTO(certification, getUsedAmount(certification, false));
        }
    };

    List<CertificationDTO> result = (List<CertificationDTO>) CollectionUtils.collect(certifications,
            transformer, new ArrayList<CertificationDTO>());
    if (certifications instanceof Page) {
        final Page<Certification> original = (Page<Certification>) certifications;
        final PageParameters pageParameters = new PageParameters(original.getPageSize(),
                original.getCurrentPage());
        result = new PageImpl<CertificationDTO>(pageParameters, original.getTotalCount(), result);
    }

    return result;
}

From source file:nl.surfnet.coin.api.ApiController.java

@SuppressWarnings("unchecked")
private Group20Entry addLinkedSurfTeamGroupsForExternalGroups(String userId, Group20Entry group20Entry,
        List<Group20> listOfAllExternalGroups, List<GroupProvider> allGroupProviders) {
    List<String> grouperTeamIds = new ArrayList<String>();
    Collection<String> identifiers = CollectionUtils.collect(listOfAllExternalGroups, new Transformer() {
        @Override/*from  ww  w. j a  v a  2 s . c  o  m*/
        public Object transform(Object input) {
            return ((Group20) input).getId();
        }
    });
    List<TeamExternalGroup> externalGroupIdentifiers = teamExternalGroupDao
            .getByExternalGroupIdentifiers(identifiers);
    for (TeamExternalGroup teamExternalGroup : externalGroupIdentifiers) {
        grouperTeamIds.add(teamExternalGroup.getGrouperTeamId());
    }
    if (!grouperTeamIds.isEmpty()) {
        Group20Entry linkedTeams = groupService.getGroups20ByIds(userId,
                grouperTeamIds.toArray(new String[grouperTeamIds.size()]), 0, 0);
        linkedTeams = groupProviderConfiguration.addUrnPartForGrouper(allGroupProviders, linkedTeams);

        group20Entry.getEntry().addAll(linkedTeams.getEntry());
        // remove duplicates: convert to set and back.
        group20Entry.setEntry(new ArrayList<Group20>(new HashSet<Group20>(group20Entry.getEntry())));
    }
    return group20Entry;
}

From source file:nl.surfnet.coin.api.service.PersonServiceImpl.java

@SuppressWarnings("unchecked")
@Override/*from   w  w  w . ja v  a2s.c om*/
public GroupMembersEntry getGroupMembers(String groupId, String onBehalfOf, String spEntityId, Integer count,
        Integer startIndex, String sortBy) {

    /*
     * first get all members from grouper. Note that we don't support sortBy but
     * we do support count and startIndex. See
     * https://jira.surfconext.nl/jira/browse/BACKLOG-438
     */
    GroupMembersEntry entry = apiGrouperDao.findAllMembers(groupId, startIndex, count);
    List<Person> persons = entry.getEntry();
    if (!CollectionUtils.isEmpty(persons)) {
        Collection<String> identifiers = CollectionUtils.collect(persons, new Transformer() {
            @Override
            public Object transform(Object input) {
                return ((Person) input).getId();
            }
        });
        // Now enrich the information
        List<Person> enrichedPersons = ldapClient.findPersons(identifiers);

        for (Person person : enrichedPersons) {
            person.setVoot_membership_role(getVootMembersShip(person.getId(), persons));
        }

        // Apply ARP
        ARP arp = clientDetailsService.getArp(spEntityId);
        LOG.debug("ARP for SP {} is: {}", spEntityId, arp);
        List<Person> arpEnforcedPersons = enforceArp(spEntityId, enrichedPersons);

        entry.setEntry(arpEnforcedPersons);
    }
    return entry;
}

From source file:nl.surfnet.coin.janus.JanusRestClient.java

/**
 * {@inheritDoc}//from  www  . jav a2 s. c om
 */
@Override
public EntityMetadata getMetadataByEntityId(String entityId) {
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("entityid", entityId);
    final Collection metadataAsStrings = CollectionUtils.collect(Arrays.asList(Metadata.values()),
            new Transformer() {
                @Override
                public Object transform(Object input) {
                    return ((Metadata) input).val();
                }
            });

    parameters.put("keys", StringUtils.join(metadataAsStrings, ','));

    URI signedUri;
    try {
        signedUri = sign("getMetadata", parameters);

        if (LOG.isTraceEnabled()) {
            LOG.trace("Signed Janus-request is: {}", signedUri);
        }

        @SuppressWarnings("unchecked")
        final Map<String, Object> restResponse = restTemplate.getForObject(signedUri, Map.class);
        Assert.notNull(restResponse, "Rest response from Janus should not be null");

        if (LOG.isTraceEnabled()) {
            LOG.trace("Janus-request returned: {}", restResponse.toString());
        }

        final EntityMetadata entityMetadata = EntityMetadata.fromMetadataMap(restResponse);

        entityMetadata.setAppEntityId(entityId);
        return entityMetadata;
    } catch (IOException e) {
        LOG.error("While doing Janus-request", e);
    }
    return null;
}