Search in sources :

Example 1 with BeanComparator

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

the class AbstractContentAction method getGroups.

/**
 * Restituisce la lista ordinata dei gruppi presenti nel sistema.
 * @return La lista dei gruppi presenti nel sistema.
 */
public List<Group> getGroups() {
    List<Group> groups = this.getGroupManager().getGroups();
    BeanComparator c = new BeanComparator("description");
    Collections.sort(groups, c);
    return groups;
}
Also used : Group(com.agiletec.aps.system.services.group.Group) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 2 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator in project ma-core-public by infiniteautomation.

the class DeltamationCommon method beanSort.

/**
 * Sorts a list of Bean objects by multiple SortOptions
 * @param list
 * @param sort
 */
@SuppressWarnings("unchecked")
public static void beanSort(List<?> list, SortOption... sort) {
    ComparatorChain cc = new ComparatorChain();
    // always sort so that the offset/limit work as intended
    if (sort.length == 0) {
        sort = new SortOption[] { new SortOption("id", false) };
    }
    // TODO catch exceptions?
    NullComparator nullComparator = new NullComparator();
    for (SortOption option : sort) {
        if (option == null)
            continue;
        cc.addComparator(new BeanComparator(option.getAttribute(), nullComparator), option.isDesc());
    }
    Collections.sort(list, cc);
}
Also used : ComparatorChain(org.apache.commons.collections.comparators.ComparatorChain) NullComparator(org.apache.commons.collections.comparators.NullComparator) SortOption(com.infiniteautomation.mango.db.query.SortOption) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 3 with BeanComparator

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

the class RatingServiceImpl method readReviews.

@Override
@SuppressWarnings("unchecked")
public List<ReviewDetail> readReviews(String itemId, RatingType type, int start, int finish, RatingSortType sortBy) {
    RatingSummary summary = this.readRatingSummary(itemId, type);
    if (summary != null) {
        List<ReviewDetail> reviews = summary.getReviews();
        List<ReviewDetail> reviewsToReturn = new ArrayList<ReviewDetail>();
        int i = 0;
        for (ReviewDetail review : reviews) {
            if (i > finish) {
                break;
            }
            if (i >= start) {
                reviewsToReturn.add(review);
            }
            i++;
        }
        String sortByBeanProperty = "reviewSubmittedDate";
        if (sortBy == RatingSortType.MOST_HELPFUL) {
            sortByBeanProperty = "helpfulCount";
        }
        Collections.sort(reviewsToReturn, new BeanComparator(sortByBeanProperty));
        return reviewsToReturn;
    } else {
        return new ArrayList<ReviewDetail>();
    }
}
Also used : RatingSummary(org.broadleafcommerce.core.rating.domain.RatingSummary) ReviewDetail(org.broadleafcommerce.core.rating.domain.ReviewDetail) ArrayList(java.util.ArrayList) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 4 with BeanComparator

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

the class PageServiceImpl method buildPageDTOListUsingCache.

@SuppressWarnings("unchecked")
protected List<PageDTO> buildPageDTOListUsingCache(List<Page> pageList, String identifier, Locale locale, boolean secure) {
    List<PageDTO> dtoList = getCachedPageDTOList(pageList, identifier, locale, secure);
    if (dtoList == null || dtoList.isEmpty()) {
        addPageListToPageDTOList(pageList, secure, dtoList);
        if (dtoList != null && !dtoList.isEmpty()) {
            Collections.sort(dtoList, new BeanComparator("priority"));
            addPageListToCache(dtoList, identifier, locale, secure);
        }
    }
    return dtoList;
}
Also used : NullPageDTO(org.broadleafcommerce.common.page.dto.NullPageDTO) PageDTO(org.broadleafcommerce.common.page.dto.PageDTO) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 5 with BeanComparator

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

the class PromotableOfferUtility method determineOfferUnitValue.

@SuppressWarnings("unchecked")
public static BigDecimal determineOfferUnitValue(Offer offer, PromotableCandidateItemOffer promotableCandidateItemOffer) {
    if (offer instanceof AdvancedOffer) {
        AdvancedOffer advancedOffer = (AdvancedOffer) offer;
        if (advancedOffer.isTieredOffer()) {
            int quantity = promotableCandidateItemOffer.calculateTargetQuantityForTieredOffer();
            List<OfferTier> offerTiers = advancedOffer.getOfferTiers();
            Collections.sort(offerTiers, new BeanComparator("minQuantity"));
            OfferTier maxTier = null;
            // assuming that promotableOffer.getOffer()).getOfferTiers() is sorted already
            for (OfferTier currentTier : offerTiers) {
                if (quantity >= currentTier.getMinQuantity()) {
                    maxTier = currentTier;
                } else {
                    break;
                }
            }
            if (maxTier != null) {
                return maxTier.getAmount();
            }
            if (OfferDiscountType.FIX_PRICE.equals(offer.getDiscountType())) {
                // so the offer will not get selected.
                return BigDecimal.valueOf(Integer.MAX_VALUE);
            } else {
                return BigDecimal.ZERO;
            }
        }
    }
    return offer.getValue();
}
Also used : OfferTier(org.broadleafcommerce.core.offer.domain.OfferTier) BeanComparator(org.apache.commons.beanutils.BeanComparator) AdvancedOffer(org.broadleafcommerce.core.offer.domain.AdvancedOffer)

Aggregations

BeanComparator (org.apache.commons.beanutils.BeanComparator)53 ArrayList (java.util.ArrayList)26 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 PageSearchDto (org.entando.entando.aps.system.services.page.model.PageSearchDto)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