Search in sources :

Example 6 with CompareToBuilder

use of org.apache.commons.lang3.builder.CompareToBuilder in project BroadleafCommerce by BroadleafCommerce.

the class PersistenceManagerImpl method processMergedProperties.

public Property[] processMergedProperties(Class<?>[] entities, Map<MergedPropertyType, Map<String, FieldMetadata>> mergedProperties) {
    List<Property> propertiesList = new ArrayList<>();
    for (PersistenceModule module : modules) {
        module.extractProperties(entities, mergedProperties, propertiesList);
    }
    Property[] properties = new Property[propertiesList.size()];
    properties = propertiesList.toArray(properties);
    Arrays.sort(properties, new Comparator<Property>() {

        @Override
        public int compare(Property o1, Property o2) {
            Integer tabOrder1 = o1.getMetadata().getTabOrder() == null ? 99999 : o1.getMetadata().getTabOrder();
            Integer tabOrder2 = o2.getMetadata().getTabOrder() == null ? 99999 : o2.getMetadata().getTabOrder();
            Integer groupOrder1 = null;
            Integer groupOrder2 = null;
            if (o1.getMetadata() instanceof BasicFieldMetadata) {
                BasicFieldMetadata b1 = (BasicFieldMetadata) o1.getMetadata();
                groupOrder1 = b1.getGroupOrder();
            }
            groupOrder1 = groupOrder1 == null ? 99999 : groupOrder1;
            if (o2.getMetadata() instanceof BasicFieldMetadata) {
                BasicFieldMetadata b2 = (BasicFieldMetadata) o2.getMetadata();
                groupOrder2 = b2.getGroupOrder();
            }
            groupOrder2 = groupOrder2 == null ? 99999 : groupOrder2;
            Integer fieldOrder1 = o1.getMetadata().getOrder() == null ? 99999 : o1.getMetadata().getOrder();
            Integer fieldOrder2 = o2.getMetadata().getOrder() == null ? 99999 : o2.getMetadata().getOrder();
            String friendlyName1 = o1.getMetadata().getFriendlyName() == null ? "zzzz" : o1.getMetadata().getFriendlyName();
            String friendlyName2 = o2.getMetadata().getFriendlyName() == null ? "zzzz" : o2.getMetadata().getFriendlyName();
            String name1 = o1.getName() == null ? "zzzzz" : o1.getName();
            String name2 = o2.getName() == null ? "zzzzz" : o2.getName();
            return new CompareToBuilder().append(tabOrder1, tabOrder2).append(groupOrder1, groupOrder2).append(fieldOrder1, fieldOrder2).append(friendlyName1, friendlyName2).append(name1, name2).toComparison();
        }
    });
    return properties;
}
Also used : BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) ArrayList(java.util.ArrayList) PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) Property(org.broadleafcommerce.openadmin.dto.Property) CompareToBuilder(org.apache.commons.lang3.builder.CompareToBuilder)

Example 7 with CompareToBuilder

use of org.apache.commons.lang3.builder.CompareToBuilder in project BroadleafCommerce by BroadleafCommerce.

the class ContentProcessor method populateModelVariables.

@Override
public Map<String, Object> populateModelVariables(String tagName, Map<String, String> tagAttributes, BroadleafTemplateContext context) {
    String contentType = tagAttributes.get("contentType");
    String contentName = tagAttributes.get("contentName");
    String maxResultsStr = tagAttributes.get("maxResults");
    if (StringUtils.isEmpty(contentType) && StringUtils.isEmpty(contentName)) {
        throw new IllegalArgumentException("The content processor must have a non-empty attribute value for 'contentType' or 'contentName'");
    }
    Integer maxResults = null;
    if (maxResultsStr != null) {
        maxResults = Ints.tryParse(maxResultsStr);
    }
    if (maxResults == null) {
        maxResults = Integer.MAX_VALUE;
    }
    String contentListVar = getAttributeValue(tagAttributes, "contentListVar", "contentList");
    String contentItemVar = getAttributeValue(tagAttributes, "contentItemVar", "contentItem");
    String numResultsVar = getAttributeValue(tagAttributes, "numResultsVar", "numResults");
    String fieldFilters = tagAttributes.get("fieldFilters");
    final String sorts = tagAttributes.get("sorts");
    BroadleafRequestContext blcContext = BroadleafRequestContext.getBroadleafRequestContext();
    HttpServletRequest request = blcContext.getRequest();
    Map<String, Object> mvelParameters = buildMvelParameters(blcContext.getRequest(), tagAttributes, context);
    SandBox currentSandbox = blcContext.getSandBox();
    List<StructuredContentDTO> contentItems;
    StructuredContentType structuredContentType = null;
    if (contentType != null) {
        structuredContentType = structuredContentService.findStructuredContentTypeByName(contentType);
    }
    Locale locale = blcContext.getLocale();
    Map<String, Object> newModelVars = new HashMap<>();
    contentItems = getContentItems(contentName, maxResults, request, mvelParameters, currentSandbox, structuredContentType, locale, tagName, tagAttributes, newModelVars, context);
    if (contentItems.size() > 0) {
        // sort the resulting list by the configured property sorts on the tag
        if (StringUtils.isNotEmpty(sorts)) {
            final BroadleafTemplateContext finalContext = context;
            // In order to use the context in a comparator it needs to be final
            Collections.sort(contentItems, new Comparator<StructuredContentDTO>() {

                @Override
                public int compare(StructuredContentDTO o1, StructuredContentDTO o2) {
                    List<BroadleafAssignation> sortAssignments = finalContext.getAssignationSequence(sorts, false);
                    CompareToBuilder compareBuilder = new CompareToBuilder();
                    for (BroadleafAssignation sortAssignment : sortAssignments) {
                        String property = sortAssignment.getLeftStringRepresentation(finalContext);
                        Object val1 = o1.getPropertyValue(property);
                        Object val2 = o2.getPropertyValue(property);
                        if (sortAssignment.parseRight(finalContext).equals("ASCENDING")) {
                            compareBuilder.append(val1, val2);
                        } else {
                            compareBuilder.append(val2, val1);
                        }
                    }
                    return compareBuilder.toComparison();
                }
            });
        }
        List<Map<String, Object>> contentItemFields = new ArrayList<>();
        for (StructuredContentDTO item : contentItems) {
            if (StringUtils.isNotEmpty(fieldFilters)) {
                List<BroadleafAssignation> assignments = context.getAssignationSequence(fieldFilters, false);
                boolean valid = true;
                for (BroadleafAssignation assignment : assignments) {
                    if (ObjectUtils.notEqual(assignment.parseRight(context), item.getValues().get(assignment.getLeftStringRepresentation(context)))) {
                        LOG.info("Excluding content " + item.getId() + " based on the property value of " + assignment.getLeftStringRepresentation(context));
                        valid = false;
                        break;
                    }
                }
                if (valid) {
                    contentItemFields.add(item.getValues());
                }
            } else {
                contentItemFields.add(item.getValues());
            }
        }
        Map<String, Object> contentItem = null;
        if (contentItemFields.size() > 0) {
            contentItem = contentItemFields.get(0);
        }
        newModelVars.put(contentItemVar, contentItem);
        newModelVars.put(contentListVar, contentItemFields);
        newModelVars.put(numResultsVar, contentItems.size());
    } else {
        if (LOG.isInfoEnabled()) {
            LOG.info("**************************The contentItems is null*************************");
        }
        newModelVars.put(contentItemVar, null);
        newModelVars.put(contentListVar, null);
        newModelVars.put(numResultsVar, 0);
    }
    String deepLinksVar = tagAttributes.get("deepLinks");
    if (StringUtils.isNotBlank(deepLinksVar) && contentItems.size() > 0) {
        List<DeepLink> links = contentDeepLinkService.getLinks(contentItems.get(0));
        extensionManager.getProxy().addExtensionFieldDeepLink(links, tagName, tagAttributes, context);
        extensionManager.getProxy().postProcessDeepLinks(links);
        newModelVars.put(deepLinksVar, links);
    }
    return newModelVars;
}
Also used : Locale(org.broadleafcommerce.common.locale.domain.Locale) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) ArrayList(java.util.ArrayList) List(java.util.List) CompareToBuilder(org.apache.commons.lang3.builder.CompareToBuilder) BroadleafTemplateContext(org.broadleafcommerce.presentation.model.BroadleafTemplateContext) SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) StructuredContentDTO(org.broadleafcommerce.common.structure.dto.StructuredContentDTO) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) DeepLink(org.broadleafcommerce.common.web.deeplink.DeepLink) StructuredContentType(org.broadleafcommerce.cms.structure.domain.StructuredContentType) BroadleafAssignation(org.broadleafcommerce.presentation.model.BroadleafAssignation) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with CompareToBuilder

use of org.apache.commons.lang3.builder.CompareToBuilder in project collect by openforis.

the class Code method compareTo.

public int compareTo(Value o) {
    if (o instanceof Code) {
        CompareToBuilder compareToBuilder = new CompareToBuilder();
        compareToBuilder.append(code, ((Code) o).code);
        compareToBuilder.append(qualifier, ((Code) o).qualifier);
        return compareToBuilder.toComparison();
    } else {
        throw new IllegalArgumentException("Cannot compare boolean value with " + o.getClass());
    }
}
Also used : CompareToBuilder(org.apache.commons.lang3.builder.CompareToBuilder)

Aggregations

CompareToBuilder (org.apache.commons.lang3.builder.CompareToBuilder)8 ArrayList (java.util.ArrayList)3 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 Row (org.apache.poi.ss.usermodel.Row)1 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)1 StructuredContentType (org.broadleafcommerce.cms.structure.domain.StructuredContentType)1 Locale (org.broadleafcommerce.common.locale.domain.Locale)1 SandBox (org.broadleafcommerce.common.sandbox.domain.SandBox)1 StructuredContentDTO (org.broadleafcommerce.common.structure.dto.StructuredContentDTO)1 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)1 DeepLink (org.broadleafcommerce.common.web.deeplink.DeepLink)1 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)1 Property (org.broadleafcommerce.openadmin.dto.Property)1 PersistenceModule (org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule)1