Search in sources :

Example 36 with Transformer

use of org.apache.commons.collections.Transformer in project opencast by opencast.

the class DublinCoreCatalog method get.

@Override
@SuppressWarnings("unchecked")
public List<String> get(EName property, final String language) {
    RequireUtil.notNull(property, "property");
    RequireUtil.notNull(language, "language");
    if (LANGUAGE_ANY.equals(language)) {
        return (List<String>) CollectionUtils.collect(getValuesAsList(property), new Transformer() {

            @Override
            public Object transform(Object o) {
                return ((CatalogEntry) o).getValue();
            }
        });
    } else {
        final List<String> values = new ArrayList<String>();
        final boolean langUndef = LANGUAGE_UNDEFINED.equals(language);
        CollectionUtils.forAllDo(getValuesAsList(property), new Closure() {

            @Override
            public void execute(Object o) {
                CatalogEntry c = (CatalogEntry) o;
                String lang = c.getAttribute(XML_LANG_ATTR);
                if ((langUndef && lang == null) || (language.equals(lang)))
                    values.add(c.getValue());
            }
        });
        return values;
    }
}
Also used : Transformer(org.apache.commons.collections.Transformer) Closure(org.apache.commons.collections.Closure) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 37 with Transformer

use of org.apache.commons.collections.Transformer in project BroadleafCommerce by BroadleafCommerce.

the class SkuCustomPersistenceHandler method getConsolidatedOptionProperty.

/**
 * Returns a {@link Property} filled out with a delimited list of the <b>values</b> that are passed in. This should be
 * invoked on a fetch and the returned property should be added to the fetched {@link Entity} dto.
 *
 * @param values
 * @return
 * @see {@link #createConsolidatedOptionField(Class)};
 */
public Property getConsolidatedOptionProperty(Collection<ProductOptionValue> values) {
    Property optionValueProperty = new Property();
    optionValueProperty.setName(CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME);
    // order the values by the display order of their correspond product option
    // Collections.sort(values, new Comparator<ProductOptionValue>() {
    // 
    // @Override
    // public int compare(ProductOptionValue value1, ProductOptionValue value2) {
    // return new CompareToBuilder().append(value1.getProductOption().getDisplayOrder(),
    // value2.getProductOption().getDisplayOrder()).toComparison();
    // }
    // });
    ArrayList<String> stringValues = new ArrayList<>();
    CollectionUtils.collect(values, new Transformer() {

        @Override
        public Object transform(Object input) {
            return ((ProductOptionValue) input).getAttributeValue();
        }
    }, stringValues);
    optionValueProperty.setValue(StringUtils.join(stringValues, CONSOLIDATED_PRODUCT_OPTIONS_DELIMETER));
    return optionValueProperty;
}
Also used : Transformer(org.apache.commons.collections.Transformer) TypedTransformer(org.broadleafcommerce.common.util.TypedTransformer) ArrayList(java.util.ArrayList) CriteriaTransferObject(org.broadleafcommerce.openadmin.dto.CriteriaTransferObject) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 38 with Transformer

use of org.apache.commons.collections.Transformer in project BroadleafCommerce by BroadleafCommerce.

the class OfferServiceImpl method getUniqueOffersFromOrder.

@Override
@SuppressWarnings("unchecked")
public Set<Offer> getUniqueOffersFromOrder(Order order) {
    HashSet<Offer> result = new HashSet<Offer>();
    Transformer adjustmentToOfferTransformer = new Transformer() {

        @Override
        public Object transform(Object input) {
            return ((Adjustment) input).getOffer();
        }
    };
    result.addAll(CollectionUtils.collect(order.getOrderAdjustments(), adjustmentToOfferTransformer));
    if (order.getOrderItems() != null) {
        for (OrderItem item : order.getOrderItems()) {
            result.addAll(CollectionUtils.collect(item.getOrderItemAdjustments(), adjustmentToOfferTransformer));
            // record usage for price details on the item as well
            if (item.getOrderItemPriceDetails() != null) {
                for (OrderItemPriceDetail detail : item.getOrderItemPriceDetails()) {
                    result.addAll(CollectionUtils.collect(detail.getOrderItemPriceDetailAdjustments(), adjustmentToOfferTransformer));
                }
            }
        }
    }
    if (order.getFulfillmentGroups() != null) {
        for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
            result.addAll(CollectionUtils.collect(fg.getFulfillmentGroupAdjustments(), adjustmentToOfferTransformer));
        }
    }
    return result;
}
Also used : Transformer(org.apache.commons.collections.Transformer) OrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment) Adjustment(org.broadleafcommerce.core.offer.domain.Adjustment) PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) PromotableCandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer) PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) OrderItemPriceDetail(org.broadleafcommerce.core.order.domain.OrderItemPriceDetail) HashSet(java.util.HashSet)

Aggregations

Transformer (org.apache.commons.collections.Transformer)38 ChainedTransformer (org.apache.commons.collections.functors.ChainedTransformer)20 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)16 SearchControls (javax.naming.directory.SearchControls)16 DefaultLdapUserRoleListService (org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService)16 GenericLdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch)16 LdapSearchParamsFactoryImpl (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactoryImpl)16 SearchResultToAttrValueList (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList)16 LdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearch)13 LdapSearchParamsFactory (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactory)13 UnionizingLdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.UnionizingLdapSearch)13 List (java.util.List)11 Map (java.util.Map)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 ConstantTransformer (org.apache.commons.collections.functors.ConstantTransformer)5 GrantedAuthorityToString (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.GrantedAuthorityToString)5 StringToGrantedAuthority (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.StringToGrantedAuthority)5 Resource (org.apache.sling.api.resource.Resource)4