Search in sources :

Example 16 with BasicFieldMetadata

use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.

the class OfferCustomPersistenceHandler method buildAdvancedVisibilityOptionsFieldMetaData.

protected FieldMetadata buildAdvancedVisibilityOptionsFieldMetaData() {
    BasicFieldMetadata advancedLabelMetadata = new BasicFieldMetadata();
    advancedLabelMetadata.setFieldType(SupportedFieldType.BOOLEAN_LINK);
    advancedLabelMetadata.setForeignKeyCollection(false);
    advancedLabelMetadata.setMergedPropertyType(MergedPropertyType.PRIMARY);
    advancedLabelMetadata.setName("test");
    advancedLabelMetadata.setFriendlyName("OfferImpl_View_Visibility_Options");
    advancedLabelMetadata.setGroup(OfferAdminPresentation.GroupName.ActivityRange);
    advancedLabelMetadata.setOrder(5000);
    advancedLabelMetadata.setDefaultValue("true");
    return advancedLabelMetadata;
}
Also used : BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)

Example 17 with BasicFieldMetadata

use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.

the class OfferCustomPersistenceHandler method buildStackableFieldMetaData.

protected FieldMetadata buildStackableFieldMetaData() {
    BasicFieldMetadata qualifiersCanBeTargets = new BasicFieldMetadata();
    qualifiersCanBeTargets.setFieldType(SupportedFieldType.BOOLEAN);
    qualifiersCanBeTargets.setName(STACKABLE);
    qualifiersCanBeTargets.setFriendlyName("OfferImpl_Stackable");
    qualifiersCanBeTargets.setTooltip("OfferImpl_Stackable_tooltip");
    qualifiersCanBeTargets.setGroup(OfferAdminPresentation.GroupName.CombineStack);
    qualifiersCanBeTargets.setOrder(OfferAdminPresentation.FieldOrder.StackableWithOtherOffers);
    qualifiersCanBeTargets.setDefaultValue("false");
    return qualifiersCanBeTargets;
}
Also used : BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)

Example 18 with BasicFieldMetadata

use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.

the class SkuCustomPersistenceHandler method createExplicitEnumerationIndividualOptionField.

protected FieldMetadata createExplicitEnumerationIndividualOptionField(ProductOption option, int order) {
    BasicFieldMetadata metadata = new BasicFieldMetadata();
    List<ProductOptionValue> allowedValues = option.getAllowedValues();
    if (CollectionUtils.isNotEmpty(allowedValues)) {
        metadata.setFieldType(SupportedFieldType.EXPLICIT_ENUMERATION);
        metadata.setMutable(true);
        metadata.setInheritedFromType(SkuImpl.class.getName());
        metadata.setAvailableToTypes(getPolymorphicClasses(SkuImpl.class, em, skuMetadataCacheService.useCache()));
        metadata.setForeignKeyCollection(false);
        metadata.setMergedPropertyType(MergedPropertyType.PRIMARY);
        // Set up the enumeration based on the product option values
        String[][] optionValues = new String[allowedValues.size()][2];
        for (int i = 0; i < allowedValues.size(); i++) {
            ProductOptionValue value = option.getAllowedValues().get(i);
            optionValues[i][0] = value.getId().toString();
            optionValues[i][1] = value.getAttributeValue();
        }
        metadata.setEnumerationValues(optionValues);
        metadata.setName(PRODUCT_OPTION_FIELD_PREFIX + option.getId());
        metadata.setFriendlyName(option.getLabel());
        metadata.setGroup("productOption_group");
        metadata.setGroupOrder(-1);
        metadata.setOrder(order);
        metadata.setExplicitFieldType(SupportedFieldType.UNKNOWN);
        metadata.setProminent(false);
        metadata.setVisibility(VisibilityEnum.FORM_EXPLICITLY_SHOWN);
        metadata.setBroadleafEnumeration("");
        metadata.setReadOnly(false);
        metadata.setRequiredOverride(BooleanUtils.isFalse(option.getRequired()));
        return metadata;
    }
    return null;
}
Also used : ProductOptionValue(org.broadleafcommerce.core.catalog.domain.ProductOptionValue) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)

Example 19 with BasicFieldMetadata

use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.

the class DynamicFieldPersistenceHandlerHelper method buildDynamicProperty.

public Property buildDynamicProperty(FieldDefinition definition, Class<?> inheritedType) {
    Property property = new Property();
    property.setName(definition.getName());
    BasicFieldMetadata fieldMetadata = new BasicFieldMetadata();
    property.setMetadata(fieldMetadata);
    fieldMetadata.setFieldType(definition.getFieldType());
    fieldMetadata.setMutable(true);
    fieldMetadata.setInheritedFromType(inheritedType.getName());
    fieldMetadata.setAvailableToTypes(new String[] { inheritedType.getName() });
    fieldMetadata.setForeignKeyCollection(false);
    fieldMetadata.setMergedPropertyType(MergedPropertyType.PRIMARY);
    fieldMetadata.setLength(definition.getMaxLength());
    if (definition.getDataDrivenEnumeration() != null && !CollectionUtils.isEmpty(definition.getDataDrivenEnumeration().getEnumValues())) {
        int count = definition.getDataDrivenEnumeration().getEnumValues().size();
        String[][] enumItems = new String[count][2];
        for (int j = 0; j < count; j++) {
            DataDrivenEnumerationValue item = definition.getDataDrivenEnumeration().getEnumValues().get(j);
            enumItems[j][0] = item.getKey();
            enumItems[j][1] = item.getDisplay();
        }
        fieldMetadata.setEnumerationValues(enumItems);
    }
    fieldMetadata.setName(definition.getName());
    fieldMetadata.setFriendlyName(definition.getFriendlyName());
    fieldMetadata.setSecurityLevel(definition.getSecurityLevel() == null ? "" : definition.getSecurityLevel());
    fieldMetadata.setVisibility(definition.getHiddenFlag() ? VisibilityEnum.HIDDEN_ALL : VisibilityEnum.VISIBLE_ALL);
    fieldMetadata.setTab("General");
    fieldMetadata.setTabOrder(100);
    fieldMetadata.setExplicitFieldType(SupportedFieldType.UNKNOWN);
    fieldMetadata.setLargeEntry(definition.getTextAreaFlag());
    fieldMetadata.setProminent(false);
    fieldMetadata.setColumnWidth(String.valueOf(definition.getColumnWidth()));
    fieldMetadata.setBroadleafEnumeration("");
    fieldMetadata.setReadOnly(false);
    fieldMetadata.setRequiredOverride(definition.getRequiredFlag());
    fieldMetadata.setHint(definition.getHint());
    fieldMetadata.setHelpText(definition.getHelpText());
    fieldMetadata.setTooltip(definition.getTooltip());
    fieldMetadata.setTranslatable(true);
    if (definition.getValidationRegEx() != null) {
        Map<String, String> itemMap = new HashMap<String, String>();
        itemMap.put("regularExpression", definition.getValidationRegEx());
        itemMap.put(ConfigurationItem.ERROR_MESSAGE, definition.getValidationErrorMesageKey());
        List<Map<String, String>> configurationItems = new ArrayList<Map<String, String>>();
        configurationItems.add(itemMap);
        fieldMetadata.getValidationConfigurations().put(RegexPropertyValidator.class.getName(), configurationItems);
    }
    if (definition.getFieldType().equals(SupportedFieldType.ADDITIONAL_FOREIGN_KEY)) {
        fieldMetadata.setForeignKeyClass(definition.getAdditionalForeignKeyClass());
        fieldMetadata.setOwningClass(definition.getAdditionalForeignKeyClass());
        fieldMetadata.setForeignKeyDisplayValueProperty("__adminMainEntity");
    }
    return property;
}
Also used : HashMap(java.util.HashMap) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) DataDrivenEnumerationValue(org.broadleafcommerce.common.enumeration.domain.DataDrivenEnumerationValue) ArrayList(java.util.ArrayList) RegexPropertyValidator(org.broadleafcommerce.openadmin.server.service.persistence.validation.RegexPropertyValidator) Property(org.broadleafcommerce.openadmin.dto.Property) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with BasicFieldMetadata

use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.

the class AdminBasicEntityController method getCollectionValueDetails.

@RequestMapping(value = "/{collectionField:.*}/details", method = RequestMethod.GET)
@ResponseBody
public Map<String, String> getCollectionValueDetails(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "collectionField") String collectionField, @RequestParam String ids, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
    String sectionKey = getSectionKey(pathVars);
    String sectionClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, null, null);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, requestParams, sectionCrumbs, pathVars);
    ClassMetadata mainMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    Property collectionProperty = mainMetadata.getPMap().get(collectionField);
    FieldMetadata md = collectionProperty.getMetadata();
    ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs);
    ppr.setStartIndex(getStartIndex(requestParams));
    ppr.setMaxIndex(getMaxIndex(requestParams));
    if (md instanceof BasicFieldMetadata) {
        String idProp = ((BasicFieldMetadata) md).getForeignKeyProperty();
        String displayProp = ((BasicFieldMetadata) md).getForeignKeyDisplayValueProperty();
        List<String> filterValues = BLCArrayUtils.asList(ids.split(FILTER_VALUE_SEPARATOR_REGEX));
        ppr.addFilterAndSortCriteria(new FilterAndSortCriteria(idProp, filterValues));
        DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
        Map<String, String> returnMap = new HashMap<>();
        for (Entity e : drs.getRecords()) {
            String id = e.getPMap().get(idProp).getValue();
            String disp = e.getPMap().get(displayProp).getDisplayValue();
            if (StringUtils.isBlank(disp)) {
                disp = e.getPMap().get(displayProp).getValue();
            }
            returnMap.put(id, disp);
        }
        return returnMap;
    }
    return null;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)66 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)33 Property (org.broadleafcommerce.openadmin.dto.Property)28 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)19 Map (java.util.Map)14 Entity (org.broadleafcommerce.openadmin.dto.Entity)11 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)10 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)9 FieldMetadataOverride (org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride)9 Field (java.lang.reflect.Field)8 PersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException)8 ServiceException (org.broadleafcommerce.common.exception.ServiceException)7 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)7 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)7 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)7 Serializable (java.io.Serializable)6 SecurityServiceException (org.broadleafcommerce.common.exception.SecurityServiceException)6 MetadataOverride (org.broadleafcommerce.openadmin.dto.override.MetadataOverride)6 FieldInfo (org.broadleafcommerce.openadmin.server.dao.FieldInfo)6