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;
}
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);
}
}
}
}
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);
}
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;
}
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;
}
Aggregations