Search in sources :

Example 46 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator in project entando-core by entando.

the class AbstractWidgetExecutorService method extractDecorators.

protected List<IFrameDecoratorContainer> extractDecorators(RequestContext reqCtx) throws ApsSystemException {
    HttpServletRequest request = reqCtx.getRequest();
    WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request);
    List<IFrameDecoratorContainer> containters = new ArrayList<IFrameDecoratorContainer>();
    try {
        String[] beanNames = wac.getBeanNamesForType(IFrameDecoratorContainer.class);
        for (int i = 0; i < beanNames.length; i++) {
            IFrameDecoratorContainer container = (IFrameDecoratorContainer) wac.getBean(beanNames[i]);
            containters.add(container);
        }
        BeanComparator comparator = new BeanComparator("order");
        Collections.sort(containters, comparator);
    } catch (Throwable t) {
        _logger.error("Error extracting widget decorators", t);
        throw new ApsSystemException("Error extracting widget decorators", t);
    }
    return containters;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IFrameDecoratorContainer(com.agiletec.aps.tags.util.IFrameDecoratorContainer) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BeanComparator(org.apache.commons.beanutils.BeanComparator) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 47 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator in project coprhd-controller by CoprHD.

the class EditCatalog method loadImageOptions.

private static List<Option> loadImageOptions() {
    VirtualFile imageDir = Play.getVirtualFile("public/img/serviceCatalog");
    List<Option> images = Lists.newArrayList();
    for (VirtualFile f : imageDir.list()) {
        String label = f.getName().replaceAll("(icon_|.png)", "");
        images.add(new Option(f.getName(), label));
    }
    for (CatalogImageRestRep image : CatalogImageUtils.getCatalogImages()) {
        String filename = StringUtils.substringBeforeLast(image.getName(), ".");
        images.add(new Option(image.getId().toString(), filename));
    }
    Collections.sort(images, new BeanComparator("value", new StringComparator(false)));
    return images;
}
Also used : VirtualFile(play.vfs.VirtualFile) EnumOption(util.EnumOption) Option(com.emc.vipr.model.catalog.Option) AssetOption(com.emc.vipr.model.catalog.AssetOption) CatalogImageRestRep(com.emc.vipr.model.catalog.CatalogImageRestRep) BeanComparator(org.apache.commons.beanutils.BeanComparator) StringComparator(util.StringComparator)

Example 48 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator in project entando-core by entando.

the class ApsEntityManager method getOrderedAttributeRoles.

private List<AttributeRole> getOrderedAttributeRoles() {
    List<AttributeRole> roles = new ArrayList<>(this.attributeRoles.size());
    Iterator<AttributeRole> iter = this.attributeRoles.values().iterator();
    while (iter.hasNext()) {
        AttributeRole role = iter.next();
        roles.add(role.clone());
    }
    BeanComparator comparator = new BeanComparator("name");
    Collections.sort(roles, comparator);
    return roles;
}
Also used : ArrayList(java.util.ArrayList) BeanComparator(org.apache.commons.beanutils.BeanComparator) AttributeRole(com.agiletec.aps.system.common.entity.model.attribute.AttributeRole)

Example 49 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator in project BroadleafCommerce by BroadleafCommerce.

the class FulfillmentGroupOfferProcessorImpl method applyAllFulfillmentGroupOffers.

@Override
@SuppressWarnings("unchecked")
public boolean applyAllFulfillmentGroupOffers(List<PromotableCandidateFulfillmentGroupOffer> qualifiedFGOffers, PromotableOrder order) {
    Map<FulfillmentGroupOfferPotential, List<PromotableCandidateFulfillmentGroupOffer>> offerMap = new HashMap<FulfillmentGroupOfferPotential, List<PromotableCandidateFulfillmentGroupOffer>>();
    for (PromotableCandidateFulfillmentGroupOffer candidate : qualifiedFGOffers) {
        FulfillmentGroupOfferPotential potential = new FulfillmentGroupOfferPotential();
        potential.setOffer(candidate.getOffer());
        if (offerMap.get(potential) == null) {
            offerMap.put(potential, new ArrayList<PromotableCandidateFulfillmentGroupOffer>());
        }
        offerMap.get(potential).add(candidate);
    }
    List<FulfillmentGroupOfferPotential> potentials = new ArrayList<FulfillmentGroupOfferPotential>();
    for (FulfillmentGroupOfferPotential potential : offerMap.keySet()) {
        List<PromotableCandidateFulfillmentGroupOffer> fgOffers = offerMap.get(potential);
        Collections.sort(fgOffers, new ReverseComparator(new BeanComparator("discountedAmount", new NullComparator())));
        Collections.sort(fgOffers, new BeanComparator("priority", new NullComparator()));
        if (potential.getOffer().isLimitedUsePerOrder() && fgOffers.size() > potential.getOffer().getMaxUsesPerOrder()) {
            for (int j = potential.getOffer().getMaxUsesPerOrder(); j < fgOffers.size(); j++) {
                fgOffers.remove(j);
            }
        }
        filterOffersByQualifyingAndSubtotalRequirements(order, fgOffers);
        for (PromotableCandidateFulfillmentGroupOffer candidate : fgOffers) {
            if (potential.getTotalSavings().getAmount().equals(BankersRounding.zeroAmount())) {
                BroadleafCurrency currency = order.getOrderCurrency();
                if (currency != null) {
                    potential.setTotalSavings(new Money(BigDecimal.ZERO, currency.getCurrencyCode()));
                } else {
                    potential.setTotalSavings(new Money(BigDecimal.ZERO));
                }
            }
            Money priceBeforeAdjustments = candidate.getFulfillmentGroup().calculatePriceWithoutAdjustments();
            Money discountedPrice = candidate.getDiscountedPrice();
            potential.setTotalSavings(potential.getTotalSavings().add(priceBeforeAdjustments.subtract(discountedPrice)));
            potential.setPriority(candidate.getOffer().getPriority());
        }
        potentials.add(potential);
    }
    // Sort fg potentials by priority and discount
    Collections.sort(potentials, new BeanComparator("totalSavings", Collections.reverseOrder()));
    Collections.sort(potentials, new BeanComparator("priority"));
    potentials = removeTrailingNotCombinableFulfillmentGroupOffers(potentials);
    boolean fgOfferApplied = false;
    for (FulfillmentGroupOfferPotential potential : potentials) {
        Offer offer = potential.getOffer();
        boolean alreadyContainsTotalitarianOffer = order.isTotalitarianOfferApplied();
        List<PromotableCandidateFulfillmentGroupOffer> candidates = offerMap.get(potential);
        for (PromotableCandidateFulfillmentGroupOffer candidate : candidates) {
            applyFulfillmentGroupOffer(candidate.getFulfillmentGroup(), candidate);
            fgOfferApplied = true;
        }
        for (PromotableFulfillmentGroup fg : order.getFulfillmentGroups()) {
            fg.chooseSaleOrRetailAdjustments();
        }
        if ((offer.isTotalitarianOffer() != null && offer.isTotalitarianOffer()) || alreadyContainsTotalitarianOffer) {
            fgOfferApplied = compareAndAdjustFulfillmentGroupOffers(order, fgOfferApplied);
            if (fgOfferApplied) {
                break;
            }
        } else if (!offer.isCombinableWithOtherOffers()) {
            break;
        }
    }
    return fgOfferApplied;
}
Also used : HashMap(java.util.HashMap) NullComparator(org.apache.commons.collections.comparators.NullComparator) FulfillmentGroupOfferPotential(org.broadleafcommerce.core.offer.service.discount.FulfillmentGroupOfferPotential) ArrayList(java.util.ArrayList) ReverseComparator(org.apache.commons.collections.comparators.ReverseComparator) BeanComparator(org.apache.commons.beanutils.BeanComparator) Money(org.broadleafcommerce.common.money.Money) BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency) PromotableCandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) PromotableFulfillmentGroup(org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup) ArrayList(java.util.ArrayList) List(java.util.List) PromotableCandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer)

Example 50 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator in project BroadleafCommerce by BroadleafCommerce.

the class AdminNavigationServiceImpl method populateAdminMenu.

protected void populateAdminMenu(AdminUser adminUser, AdminMenu adminMenu, List<AdminModule> modules) {
    for (AdminModule module : modules) {
        List<AdminSection> authorizedSections = buildAuthorizedSectionsList(adminUser, module);
        if (authorizedSections != null && authorizedSections.size() > 0) {
            AdminModuleDTO adminModuleDto = ((AdminModuleImpl) module).getAdminModuleDTO();
            adminMenu.getAdminModules().add(adminModuleDto);
            adminModuleDto.setSections(authorizedSections);
        }
    }
    // Sort the authorized modules
    BeanComparator displayComparator = new BeanComparator("displayOrder");
    Collections.sort(adminMenu.getAdminModules(), displayComparator);
}
Also used : AdminModule(org.broadleafcommerce.openadmin.server.security.domain.AdminModule) AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) AdminModuleDTO(org.broadleafcommerce.openadmin.server.security.domain.AdminModuleDTO) AdminModuleImpl(org.broadleafcommerce.openadmin.server.security.domain.AdminModuleImpl) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Aggregations

BeanComparator (org.apache.commons.beanutils.BeanComparator)50 ArrayList (java.util.ArrayList)25 SelectItem (com.agiletec.aps.util.SelectItem)6 NullComparator (org.apache.commons.collections.comparators.NullComparator)6 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)5 Group (com.agiletec.aps.system.services.group.Group)5 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)4 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)3 Comparator (java.util.Comparator)3 HashMap (java.util.HashMap)3 List (java.util.List)3 ComparatorChain (org.apache.commons.collections.comparators.ComparatorChain)3 ReverseComparator (org.apache.commons.collections.comparators.ReverseComparator)3 Role (com.agiletec.aps.system.services.role.Role)2 WebApplicationContext (org.springframework.web.context.WebApplicationContext)2 SmallEntityType (com.agiletec.aps.system.common.entity.model.SmallEntityType)1 AbstractListAttribute (com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute)1 AttributeRole (com.agiletec.aps.system.common.entity.model.attribute.AttributeRole)1 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)1