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:org.openmrs.module.metadatasharing.Package.java

/**
 * Imperfect check to see what modules are required for the items in this package (based on
 * looking for java package names like org.openmrs.module.XYZ).
 * /*ww w.  j  a  v  a2 s.  c om*/
 * @param pack
 * @return the requiredModules[moduleId, version]
 * @should get modules ids and versions
 * @since 1.0
 */
public Map<String, String> getRequiredModules() {
    Set<String> classNames = new HashSet<String>();

    Transformer getClassnameTransform = new Transformer() {

        @Override
        public Object transform(Object item) {
            try {
                return ((Item) item).getClassname();
            } catch (Exception ex) {
                throw new RuntimeException("Programming Error: expected ItemSummary or ImportedItem", ex);
            }
        }
    };

    CollectionUtils.collect(items, getClassnameTransform, classNames);
    CollectionUtils.collect(relatedItems, getClassnameTransform, classNames);

    // org.openmrs.module.(group 1: moduleId)[.more.packages].(group 2: SimpleClassName)
    Pattern regex = Pattern.compile("org\\.openmrs\\.module\\.(\\w+)[\\.\\w+]*\\.(\\w+)");

    Map<String, String> requiredModules = new HashMap<String, String>();
    for (String cn : classNames) {
        Matcher m = regex.matcher(cn);
        if (m.matches()) {
            String moduleId = m.group(1);
            requiredModules.put(moduleId, modules.get(moduleId));
        }
    }

    return requiredModules;
}

From source file:org.openo.sdnhub.overlayvpndriver.rest.IpSecROAResource.java

/**
 * Deletes IPSec VPN configuration using a specific controller.<br>
 *
 * @param ctrlUuidParam Controller UUID/*from  w  w w .j a  va  2 s  . c  o  m*/
 * @param deviceId device id
 * @param ipsecList collection of IPSec VPN configuration
 * @return ResultRsp object with IPSec VPN deleted configuration status data
 * @throws ServiceException when input validation fails
 * @since SDNHUB 0.5
 */
@POST
@Path("/device/{deviceid}/ipsecs/{extipsecid}/batch-delete-ipsec")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public ResultRsp<SbiNeIpSec> deleteIpSec(@HeaderParam(CTRL_HEADER_PARAM) String ctrlUuidParam,
        @PathParam("deviceid") String deviceId, List<SbiNeIpSec> ipsecList) throws ServiceException {

    long beginTime = System.currentTimeMillis();
    LOGGER.debug("Ipsec delete begin time = " + beginTime);

    String ctrlUuid = RequestHeaderUtil.readControllerUUID(ctrlUuidParam);
    if (!UuidUtil.validate(ctrlUuid)) {
        LOGGER.error(CONTROLLER_INV_UUID);
        throw new ParameterServiceException(CONTROLLER_INV_UUID);
    }

    if (CollectionUtils.isEmpty(ipsecList)) {
        LOGGER.error(REQ_BODY_NULL_OR_EMPTY);
        throw new ParameterServiceException(REQ_BODY_NULL_OR_EMPTY);
    }

    CheckStrUtil.checkUuidStr(deviceId);

    List<String> externalIds = new ArrayList<>(CollectionUtils.collect(ipsecList, new Transformer() {

        @Override
        public Object transform(Object arg0) {
            return ((SbiNeIpSec) arg0).getExternalId();
        }
    }));

    ipsecService.checkSeqNumber(externalIds);
    ResultRsp<SbiNeIpSec> response = ipsecService.batchDeleteIpsecConn(ctrlUuid, ipsecList);
    LOGGER.debug("delete Ipsec cost time = " + (System.currentTimeMillis() - beginTime));
    return response;
}

From source file:org.openo.sdnhub.servicechaindriverservice.db.ServiceChainInfoDao.java

/**
 * Allocate VLAN Id Resource.<br>/*  www  .j ava 2 s .  c om*/
 * 
 * @return VLAN Id allocated
 * @throws ServiceException when allocate VLAN id failed
 * @since SDNHUB 0.5
 */
public int allocVlanId() throws ServiceException {
    List<ServiceChainInfo> scInfoList = queryAllServiceChainInfo();
    if (scInfoList.isEmpty()) {
        return MIN_VLAN_ID;
    }

    @SuppressWarnings("unchecked")
    List<Integer> vlanIdList = new ArrayList<>(CollectionUtils.collect(scInfoList, new Transformer() {

        @Override
        public Object transform(Object arg0) {
            return ((ServiceChainInfo) arg0).getVlanId();
        }
    }));

    for (Integer vlanId = MIN_VLAN_ID; vlanId <= MAX_VLAN_ID; vlanId++) {
        if (!vlanIdList.contains(vlanId)) {
            return vlanId;
        }
    }

    return INVALID_VLAN_ID;
}

From source file:org.openvpms.archetype.rules.product.ProductPriceUpdater.java

/**
 * Updates any <em>productPrice.unitPrice</em> product prices associated with a product.
 *
 * @param product the product/*from w  w w  .  j  a v  a2  s . co m*/
 * @param save    if {@code true}, save updated prices
 * @return a list of updated prices
 * @throws ArchetypeServiceException    for any archetype service error
 * @throws ProductPriceUpdaterException if there is no practice
 */
public List<ProductPrice> update(final Product product, boolean save) {
    List<ProductPrice> result = Collections.emptyList();
    if (needsUpdate(product)) {
        EntityBean bean = new EntityBean(product, service);
        List<EntityRelationship> relationships = bean.getNodeRelationships("suppliers");
        Transformer transformer = new Transformer() {
            public Object transform(Object object) {
                ProductSupplier ps = new ProductSupplier((EntityRelationship) object, service);
                return update(product, ps, false);
            }
        };
        result = collect(relationships, transformer, save);
    }
    return result;
}

From source file:org.openvpms.archetype.rules.product.ProductPriceUpdater.java

/**
 * Updates an <em>productPrice.unitPrice</em> product prices associated with products for the specified supplier.
 *
 * @param supplier the supplier//ww  w  . ja  v  a2  s .co  m
 * @param save     if {@code true}, save updated prices
 * @return a list of updated prices
 * @throws ArchetypeServiceException    for any archetype service error
 * @throws ProductPriceUpdaterException if there is no practice
 */
public List<ProductPrice> update(Party supplier, boolean save) {
    EntityBean bean = new EntityBean(supplier, service);
    List<EntityRelationship> products = bean.getNodeRelationships("products");
    Transformer transformer = new Transformer() {
        public Object transform(Object object) {
            ProductSupplier ps = new ProductSupplier((EntityRelationship) object, service);
            return update(ps, false);
        }
    };
    return collect(products, transformer, save);
}

From source file:org.openvpms.web.component.im.relationship.RelationshipStateResultSet.java

/**
 * Sorts the set. This resets the iterator.
 *
 * @param sort the sort criteria. May be <tt>null</tt>
 *//*from w  w w  . j  a  va  2  s . c o  m*/
public void sort(SortConstraint[] sort) {
    if (sort != null && sort.length != 0 && !getObjects().isEmpty()) {
        sortAscending = sort[0].isAscending();
        SortConstraint s = sort[0];
        if (s instanceof NodeSortConstraint) {
            NodeSortConstraint n = (NodeSortConstraint) s;
            String name = n.getNodeName();
            if (name.equals(RelationshipStateTableModel.NAME_NODE)
                    || name.equals(RelationshipStateTableModel.DESCRIPTION_NODE)
                    || name.equals(RelationshipStateTableModel.DETAIL_NODE)) {
                Collections.sort(getObjects(), getComparator(n));
            } else {
                Transformer transformer = new Transformer() {
                    public Object transform(Object input) {
                        return ((RelationshipState) input).getRelationship();
                    }
                };
                IMObjectSorter.sort(getObjects(), sort, transformer);
            }
        }
        this.sort = sort;
    }
    reset();
}

From source file:org.openvpms.web.component.im.relationship.RelationshipStateResultSet.java

/**
 * Helper to return a comparator for a node sort constraint.
 *
 * @param sort the node sort constraint//from ww w.jav a  2  s  . c om
 * @return a comparator for the constraint, or <tt>null</tt> if the
 *         node is not supported
 */
private Comparator getComparator(NodeSortConstraint sort) {
    Transformer transformer = null;
    String name = sort.getNodeName();
    if (RelationshipStateTableModel.NAME_NODE.equals(name)) {
        transformer = new Transformer() {
            public Object transform(Object input) {
                RelationshipState state = ((RelationshipState) input);
                return (source) ? state.getTargetName() : state.getSourceName();
            }
        };
    } else if (RelationshipStateTableModel.DESCRIPTION_NODE.equals(name)) {
        transformer = new Transformer() {
            public Object transform(Object input) {
                RelationshipState state = ((RelationshipState) input);
                return (source) ? state.getTargetDescription() : state.getSourceDescription();
            }
        };
    } else if (RelationshipStateTableModel.DETAIL_NODE.equals(name)) {
        transformer = new Transformer() {
            public Object transform(Object input) {
                RelationshipState state = ((RelationshipState) input);
                return state.getRelationship().getDescription();
            }
        };
    }
    Comparator comparator = null;
    if (transformer != null) {
        comparator = IMObjectSorter.getComparator(sortAscending);
        comparator = new TransformingComparator(transformer, comparator);
    }
    return comparator;
}

From source file:org.orbeon.oxf.cache.MemoryCacheImpl.java

public Iterator<CacheKey> iterateCacheKeys() {
    return new TransformIterator(linkedList.iterator(), new Transformer() {
        public Object transform(Object o) {
            return ((CacheEntry) o).key;
        }//  ww  w.ja va2 s .c o m
    });
}

From source file:org.orbeon.oxf.cache.MemoryCacheImpl.java

public Iterator<Object> iterateCacheObjects() {
    return new TransformIterator(linkedList.iterator(), new Transformer() {
        public Object transform(Object o) {
            return ((CacheEntry) o).cacheable;
        }//w w w  .  j av a2 s .co  m
    });
}

From source file:org.oztrack.view.OaiPmhRecordWriter.java

private void writeOaiDcRepositoryMetadataElement(OaiPmhRecord record) throws XMLStreamException {
    out.writeStartElement(OAI_DC.nsPrefix, "dc", OAI_DC.nsUri);

    // Every metadata part must include xmlns attributes for its metadata formats.
    // http://www.openarchives.org/OAI/2.0/openarchivesprotocol.htm#Record
    out.setPrefix(OAI_DC.nsPrefix, OAI_DC.nsUri);
    out.writeNamespace(OAI_DC.nsPrefix, OAI_DC.nsUri);
    out.setPrefix(DC.nsPrefix, DC.nsUri);
    out.writeNamespace(DC.nsPrefix, DC.nsUri);

    // Every metadata part must include the attributes xmlns:xsi (namespace URI for XML schema) and
    // xsi:schemaLocation (namespace URI and XML schema URL for validating metadata that follows).
    // http://www.openarchives.org/OAI/2.0/openarchivesprotocol.htm#Record
    out.setPrefix(XSI.nsPrefix, XSI.nsUri);
    out.writeNamespace(XSI.nsPrefix, XSI.nsUri);
    out.writeAttribute(XSI.nsUri, "schemaLocation", OAI_DC.nsUri + " " + OAI_DC.xsdUri);

    if (StringUtils.isNotBlank(record.getObjectIdentifier())) {
        out.writeStartElement(DC.nsUri, "identifier");
        out.writeCharacters(record.getObjectIdentifier());
        out.writeEndElement(); // identifier
    }//  w  ww .  j a  v a2s . c o  m
    Transformer namePartToTextTransformer = new Transformer() {
        @Override
        public Object transform(Object input) {
            return ((OaiPmhRecord.Name.NamePart) input).getNamePartText();
        }
    };
    String title = StringUtils
            .join(CollectionUtils.collect(record.getName().getNameParts(), namePartToTextTransformer), " ");
    if (StringUtils.isNotBlank(title)) {
        out.writeStartElement(DC.nsUri, "title");
        out.writeCharacters(title);
        out.writeEndElement(); // title
    }
    if (StringUtils.isNotBlank(record.getDescription())) {
        out.writeStartElement(DC.nsUri, "description");
        out.writeCharacters(record.getDescription());
        out.writeEndElement(); // description
    }
    if (StringUtils.isNotBlank(record.getCreator())) {
        out.writeStartElement(DC.nsUri, "creator");
        out.writeCharacters(record.getCreator());
        out.writeEndElement(); // creator
    }
    if (record.getRecordCreateDate() != null) {
        out.writeStartElement(DC.nsUri, "created");
        out.writeCharacters(utcDateTimeFormat.format(record.getRecordCreateDate()));
        out.writeEndElement(); // created
    }
    if (record.getRecordUpdateDate() != null) {
        out.writeStartElement(DC.nsUri, "date");
        out.writeCharacters(utcDateTimeFormat.format(record.getRecordUpdateDate()));
        out.writeEndElement(); // date
    }
    if (record.getSpatialCoverage() != null) {
        out.writeStartElement(DC.nsUri, "coverage");
        out.writeCharacters("North " + record.getSpatialCoverage().getMaxY() + ", ");
        out.writeCharacters("East " + record.getSpatialCoverage().getMaxX() + ", ");
        out.writeCharacters("South " + record.getSpatialCoverage().getMinY() + ", ");
        out.writeCharacters("West " + record.getSpatialCoverage().getMinX() + ".");
        out.writeEndElement(); // coverage
    }
    if (StringUtils.isNotBlank(record.getAccessRights())) {
        out.writeStartElement(DC.nsUri, "accessRights");
        out.writeCharacters(record.getAccessRights());
        out.writeEndElement(); // accessRights
    }
    if ((record.getLicence() != null) && StringUtils.isNotBlank(record.getLicence().getLicenceText())) {
        out.writeStartElement(DC.nsUri, "license");
        out.writeCharacters(record.getLicence().getLicenceText());
        out.writeEndElement(); // license
    }
    if (StringUtils.isNotBlank(record.getRightsStatement())) {
        out.writeStartElement(DC.nsUri, "rights");
        out.writeCharacters(record.getRightsStatement());
        out.writeEndElement(); // rights
    }
    if (record.getRelations() != null) {
        for (OaiPmhRecord.Relation relation : record.getRelations()) {
            out.writeStartElement(DC.nsUri, "relation");
            out.writeAttribute("type", relation.getRelationType());
            out.writeCharacters(relation.getRelatedObjectIdentifier());
            out.writeEndElement(); // relation
        }
    }
    if (record.getSubjects() != null) {
        for (OaiPmhRecord.Subject subject : record.getSubjects()) {
            if (subject.getSubjectType().equals("local")) {
                out.writeStartElement(DC.nsUri, "subject");
                out.writeCharacters(subject.getSubjectText());
                out.writeEndElement(); // subject
            }
        }
    }
    if (StringUtils.isNotBlank(record.getDcType())) {
        out.writeStartElement(DC.nsUri, "type");
        out.writeCharacters(record.getDcType());
        out.writeEndElement(); // type
    }

    out.writeEndElement(); // dc
}