Search in sources :

Example 21 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class FormBuilderServiceImpl method createListGrid.

/**
 * Populate a ListGrid with ListGridRecords.
 *
 * @param className
 * @param headerFields
 * @param type
 * @param drs
 * @param sectionKey
 * @param order
 * @param idProperty
 * @param sectionCrumbs
 * @param sortPropery
 * @return
 */
protected ListGrid createListGrid(String className, List<Field> headerFields, ListGrid.Type type, DynamicResultSet drs, String sectionKey, Integer order, String idProperty, List<SectionCrumb> sectionCrumbs, String sortPropery) {
    // Create the list grid and set some basic attributes
    ListGrid listGrid = new ListGrid();
    listGrid.setClassName(className);
    listGrid.getHeaderFields().addAll(headerFields);
    listGrid.setListGridType(type);
    listGrid.setSectionCrumbs(sectionCrumbs);
    listGrid.setSectionKey(sectionKey);
    listGrid.setOrder(order);
    listGrid.setIdProperty(idProperty);
    listGrid.setStartIndex(drs.getStartIndex());
    listGrid.setTotalRecords(drs.getTotalRecords());
    listGrid.setPageSize(drs.getPageSize());
    String sectionIdentifier = extractSectionIdentifierFromCrumb(sectionCrumbs);
    AdminSection section = navigationService.findAdminSectionByClassAndSectionId(className, sectionIdentifier);
    if (section != null) {
        listGrid.setExternalEntitySectionKey(section.getUrl());
    }
    // format date list grid cells
    SimpleDateFormat formatter = new SimpleDateFormat("MMM d, Y @ hh:mma");
    DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault());
    symbols.setAmPmStrings(new String[] { "am", "pm" });
    formatter.setDateFormatSymbols(symbols);
    // that are used for the header fields.
    for (Entity e : drs.getRecords()) {
        ListGridRecord record = new ListGridRecord();
        record.setListGrid(listGrid);
        record.setDirty(e.isDirty());
        record.setEntity(e);
        if (StringUtils.isNotBlank(sortPropery) && e.findProperty(sortPropery) != null) {
            Property sort = e.findProperty(sortPropery);
            record.setDisplayOrder(sort.getValue());
        }
        if (e.findProperty("hasError") != null) {
            Boolean hasError = Boolean.parseBoolean(e.findProperty("hasError").getValue());
            record.setIsError(hasError);
            if (hasError) {
                ExtensionResultStatusType messageResultStatus = listGridErrorExtensionManager.getProxy().determineErrorMessageForEntity(e, record);
                if (ExtensionResultStatusType.NOT_HANDLED.equals(messageResultStatus)) {
                    record.setErrorKey("listgrid.record.error");
                }
            }
        }
        if (e.findProperty("progressStatus") != null) {
            ExtensionResultStatusType messageResultStatus = listGridErrorExtensionManager.getProxy().determineStatusMessageForEntity(e, record);
            if (ExtensionResultStatusType.NOT_HANDLED.equals(messageResultStatus)) {
                record.setStatus(e.findProperty("progressStatus").getValue());
                record.setStatusCssClass("listgrid.record.status");
            }
        }
        if (e.findProperty(idProperty) != null) {
            record.setId(e.findProperty(idProperty).getValue());
        }
        for (Field headerField : headerFields) {
            Property p = e.findProperty(headerField.getName());
            if (p != null) {
                Field recordField = new Field().withName(headerField.getName()).withFriendlyName(headerField.getFriendlyName()).withOrder(p.getMetadata().getOrder());
                if (headerField instanceof ComboField) {
                    recordField.setValue(((ComboField) headerField).getOption(p.getValue()));
                    recordField.setDisplayValue(p.getDisplayValue());
                } else {
                    if (headerField.getFieldType().equals("DATE")) {
                        try {
                            Date date = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").parse(p.getValue());
                            String newValue = formatter.format(date);
                            recordField.setValue(newValue);
                        } catch (Exception ex) {
                            recordField.setValue(p.getValue());
                        }
                    } else {
                        recordField.setValue(p.getValue());
                    }
                    recordField.setDisplayValue(p.getDisplayValue());
                }
                recordField.setDerived(isDerivedField(headerField, recordField, p));
                record.getFields().add(recordField);
            }
        }
        if (e.findProperty(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY) != null) {
            Field hiddenField = new Field().withName(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY);
            hiddenField.setValue(e.findProperty(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY).getValue());
            record.getHiddenFields().add(hiddenField);
        }
        if (e.findProperty(BasicPersistenceModule.ALTERNATE_ID_PROPERTY) != null) {
            record.setAltId(e.findProperty(BasicPersistenceModule.ALTERNATE_ID_PROPERTY).getValue());
        }
        extensionManager.getProxy().modifyListGridRecord(className, record, e);
        listGrid.getRecords().add(record);
    }
    if (drs.getFirstId() != null) {
        listGrid.setFirstId(drs.getFirstId());
    }
    if (drs.getLastId() != null) {
        listGrid.setLastId(drs.getLastId());
    }
    if (drs.getUpperCount() != null) {
        listGrid.setUpperCount(drs.getUpperCount());
    }
    if (drs.getLowerCount() != null) {
        listGrid.setLowerCount(drs.getLowerCount());
    }
    if (drs.getFetchType() != null) {
        listGrid.setFetchType(drs.getFetchType().toString());
    }
    if (drs.getTotalCountLessThanPageSize() != null) {
        listGrid.setTotalCountLessThanPageSize(drs.getTotalCountLessThanPageSize());
    }
    if (drs.getPromptSearch() != null) {
        listGrid.setPromptSearch(drs.getPromptSearch());
    }
    return listGrid;
}
Also used : AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) ListGridRecord(org.broadleafcommerce.openadmin.web.form.component.ListGridRecord) AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) Date(java.util.Date) ServiceException(org.broadleafcommerce.common.exception.ServiceException) IOException(java.io.IOException) NoSuchMessageException(org.springframework.context.NoSuchMessageException) ParseException(java.text.ParseException) SecurityServiceException(org.broadleafcommerce.common.exception.SecurityServiceException) CodeField(org.broadleafcommerce.openadmin.web.form.entity.CodeField) RuleBuilderField(org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) ComboField(org.broadleafcommerce.openadmin.web.form.entity.ComboField) MediaField(org.broadleafcommerce.openadmin.web.form.component.MediaField) ComboField(org.broadleafcommerce.openadmin.web.form.entity.ComboField) DateFormatSymbols(java.text.DateFormatSymbols) SimpleDateFormat(java.text.SimpleDateFormat) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 22 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class SolrSearchServiceImpl method getQueryFields.

/**
 * This helper method gathers the query fields for the given field and stores them in the List parameter.
 * @param currentField the current field
 * @param query
 * @param queryFields the query fields for this query
 * @param searchCriteria
 */
protected void getQueryFields(SolrQuery query, final List<String> queryFields, IndexField indexField, SearchCriteria searchCriteria) {
    if (indexField != null && BooleanUtils.isTrue(indexField.getSearchable())) {
        List<IndexFieldType> fieldTypes = indexField.getFieldTypes();
        for (IndexFieldType indexFieldType : fieldTypes) {
            FieldType fieldType = indexFieldType.getFieldType();
            // this will hold the list of query fields for our given field
            ExtensionResultHolder<List<String>> queryFieldResult = new ExtensionResultHolder<>();
            queryFieldResult.setResult(queryFields);
            // here we try to get the query field's for this search field
            ExtensionResultStatusType result = extensionManager.getProxy().getQueryField(query, searchCriteria, indexFieldType, queryFieldResult);
            if (Objects.equals(ExtensionResultStatusType.NOT_HANDLED, result)) {
                // if we didn't get any query fields we just add a default one
                String solrFieldName = shs.getPropertyNameForIndexField(indexFieldType.getIndexField(), fieldType);
                queryFields.add(solrFieldName);
            }
        }
    }
}
Also used : IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) List(java.util.List) ArrayList(java.util.ArrayList) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder) IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) FieldType(org.broadleafcommerce.core.search.domain.solr.FieldType)

Example 23 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class SolrSearchServiceImpl method getSearchFacets.

@Override
public List<SearchFacetDTO> getSearchFacets() {
    List<SearchFacet> searchFacets = new ArrayList<>();
    ExtensionResultStatusType status = extensionManager.getProxy().getSearchFacets(searchFacets);
    if (Objects.equals(ExtensionResultStatusType.NOT_HANDLED, status)) {
        if (useSku) {
            return buildSearchFacetDTOs(searchFacetDao.readAllSearchFacets(FieldEntity.SKU));
        }
        return buildSearchFacetDTOs(searchFacetDao.readAllSearchFacets(FieldEntity.PRODUCT));
    }
    return buildSearchFacetDTOs(searchFacets);
}
Also used : CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) SearchFacet(org.broadleafcommerce.core.search.domain.SearchFacet) ArrayList(java.util.ArrayList) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Example 24 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class I18nSolrIndexServiceExtensionHandler method addPropertyValues.

@Override
public ExtensionResultStatusType addPropertyValues(Indexable indexable, Field field, FieldType fieldType, Map<String, Object> values, String propertyName, List<Locale> locales) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    Set<String> processedLocaleCodes = new HashSet<String>();
    ExtensionResultStatusType result = ExtensionResultStatusType.NOT_HANDLED;
    if (field.getTranslatable()) {
        result = ExtensionResultStatusType.HANDLED;
        TranslationConsiderationContext.setTranslationConsiderationContext(getTranslationEnabled());
        TranslationConsiderationContext.setTranslationService(translationService);
        BroadleafRequestContext tempContext = BroadleafRequestContext.getBroadleafRequestContext();
        if (tempContext == null) {
            tempContext = new BroadleafRequestContext();
            BroadleafRequestContext.setBroadleafRequestContext(tempContext);
        }
        Locale originalLocale = tempContext.getLocale();
        try {
            for (Locale locale : locales) {
                String localeCode = locale.getLocaleCode();
                if (Boolean.FALSE.equals(locale.getUseCountryInSearchIndex())) {
                    int pos = localeCode.indexOf("_");
                    if (pos > 0) {
                        localeCode = localeCode.substring(0, pos);
                        if (processedLocaleCodes.contains(localeCode)) {
                            continue;
                        } else {
                            locale = localeService.findLocaleByCode(localeCode);
                        }
                    }
                }
                processedLocaleCodes.add(localeCode);
                tempContext.setLocale(locale);
                Object propertyValue = shs.getPropertyValue(indexable, propertyName);
                values.put(localeCode, propertyValue);
            }
        } finally {
            // Reset the original locale.
            tempContext.setLocale(originalLocale);
        }
    }
    return result;
}
Also used : Locale(org.broadleafcommerce.common.locale.domain.Locale) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) HashSet(java.util.HashSet)

Example 25 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class SolrHelperServiceImpl method getSearchableIndexFields.

@Override
public List<IndexField> getSearchableIndexFields() {
    List<IndexField> fields = new ArrayList<>();
    ExtensionResultStatusType status = searchExtensionManager.getProxy().getSearchableIndexFields(fields);
    if (ExtensionResultStatusType.NOT_HANDLED.equals(status)) {
        if (useSku) {
            fields = indexFieldDao.readSearchableFieldsByEntityType(FieldEntity.SKU);
        } else {
            fields = indexFieldDao.readSearchableFieldsByEntityType(FieldEntity.PRODUCT);
        }
    }
    return fields;
}
Also used : ArrayList(java.util.ArrayList) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) IndexField(org.broadleafcommerce.core.search.domain.IndexField)

Aggregations

ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)59 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)35 ArrayList (java.util.ArrayList)11 Product (org.broadleafcommerce.core.catalog.domain.Product)9 Category (org.broadleafcommerce.core.catalog.domain.Category)7 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)7 ServiceException (org.broadleafcommerce.common.exception.ServiceException)6 Sku (org.broadleafcommerce.core.catalog.domain.Sku)6 Entity (org.broadleafcommerce.openadmin.dto.Entity)6 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)6 FieldNotAvailableException (org.broadleafcommerce.openadmin.server.service.persistence.module.FieldNotAvailableException)5 List (java.util.List)4 Query (javax.persistence.Query)4 TypedQuery (javax.persistence.TypedQuery)4 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)4 IndexFieldType (org.broadleafcommerce.core.search.domain.IndexFieldType)4 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)4 PersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 File (java.io.File)3