Search in sources :

Example 36 with BasicFieldMetadata

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

the class OfferCustomPersistenceHandler method buildQualifiersCanBeTargetsFieldMetaData.

protected FieldMetadata buildQualifiersCanBeTargetsFieldMetaData() {
    BasicFieldMetadata qualifiersCanBeTargets = new BasicFieldMetadata();
    qualifiersCanBeTargets.setFieldType(SupportedFieldType.BOOLEAN);
    qualifiersCanBeTargets.setName(QUALIFIERS_CAN_BE_TARGETS);
    qualifiersCanBeTargets.setFriendlyName("OfferImpl_Qualifiers_Can_Be_Targets");
    qualifiersCanBeTargets.setGroup(OfferAdminPresentation.GroupName.QualifierRuleRestriction);
    qualifiersCanBeTargets.setOrder(OfferAdminPresentation.FieldOrder.QualifiersCanBeTargets);
    qualifiersCanBeTargets.setDefaultValue("false");
    return qualifiersCanBeTargets;
}
Also used : BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)

Example 37 with BasicFieldMetadata

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

the class ProductCustomPersistenceHandler method modifyParentCategoryMetadata.

protected void modifyParentCategoryMetadata(Map<String, FieldMetadata> md) {
    if (!isDefaultCategoryLegacyMode()) {
        md.remove("allParentCategoryXrefs");
        BasicFieldMetadata defaultCategory = ((BasicFieldMetadata) md.get("defaultCategory"));
        defaultCategory.setFriendlyName("ProductImpl_Parent_Category");
    }
}
Also used : BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)

Example 38 with BasicFieldMetadata

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

the class ProductCustomPersistenceHandler method update.

@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Product.class.getName(), persistencePerspective);
        BasicFieldMetadata defaultCategory = ((BasicFieldMetadata) adminProperties.get("defaultCategory"));
        defaultCategory.setFriendlyName("ProductImpl_Parent_Category");
        if (entity.findProperty("defaultCategory") != null && !StringUtils.isEmpty(entity.findProperty("defaultCategory").getValue())) {
            // Change the inherited type so that this property is disconnected from the entity and validation is temporarily skipped.
            // This is useful when the defaultCategory was previously completely empty for whatever reason. Without this, such
            // a case would fail the validation, even though the property was specified in the submission.
            defaultCategory.setInheritedFromType(String.class.getName());
        }
        Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
        Product adminInstance = (Product) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
        if (adminInstance instanceof ProductBundle) {
            removeBundleFieldRestrictions((ProductBundle) adminInstance, adminProperties, entity);
        }
        CategoryProductXref oldDefault = getCurrentDefaultXref(adminInstance);
        // so override required flag for that field during deployment
        if (BroadleafRequestContext.getBroadleafRequestContext().isProductionSandBox()) {
            ((BasicFieldMetadata) adminProperties.get("defaultCategory")).setRequiredOverride(false);
        }
        adminInstance = (Product) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
        adminInstance = dynamicEntityDao.merge(adminInstance);
        boolean handled = false;
        if (extensionManager != null) {
            ExtensionResultStatusType result = extensionManager.getProxy().manageParentCategoryForUpdate(persistencePackage, adminInstance);
            handled = ExtensionResultStatusType.NOT_HANDLED != result;
            extensionManager.getProxy().manageFields(persistencePackage, adminInstance);
        }
        if (!handled) {
            setupXref(adminInstance);
            removeOldDefault(adminInstance, oldDefault, entity);
        }
        return helper.getRecord(adminProperties, adminInstance, null, null);
    } catch (Exception e) {
        throw new ServiceException("Unable to update entity for " + entity.getType()[0], e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) CategoryProductXref(org.broadleafcommerce.core.catalog.domain.CategoryProductXref) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) Product(org.broadleafcommerce.core.catalog.domain.Product) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ServiceException(org.broadleafcommerce.common.exception.ServiceException) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) CriteriaTransferObject(org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)

Example 39 with BasicFieldMetadata

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

the class SkuCustomPersistenceHandler method createToOneIndividualOptionField.

/**
 * Using a ToOne lookup performs much better for large product option value lists, speeds up initial page load,
 * and is generally more accurate in relation to option value updates and how they impact available selections and cache.
 *
 * @param option
 * @param order
 * @return
 */
protected FieldMetadata createToOneIndividualOptionField(ProductOption option, int order) {
    PersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
    FilterMapping filterMapping = new FilterMapping().withDirectFilterValues(sandBoxHelper.mergeCloneIds(ProductOptionImpl.class, option.getId())).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider() {

        @Override
        public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) {
            return root.get("productOption").get("id").in(directValues);
        }
    }));
    List<FilterMapping> mappings = new ArrayList<>();
    mappings.add(filterMapping);
    TypedQuery<Serializable> countQuery = criteriaTranslator.translateCountQuery(persistenceManager.getDynamicEntityDao(), ProductOptionValueImpl.class.getName(), mappings);
    Long count = (Long) countQuery.getSingleResult();
    BasicFieldMetadata metadata = null;
    if (count > 0) {
        metadata = new BasicFieldMetadata();
        metadata.setFieldType(SupportedFieldType.ADDITIONAL_FOREIGN_KEY);
        metadata.setSecondaryType(SupportedFieldType.INTEGER);
        metadata.setForeignKeyProperty("id");
        metadata.setForeignKeyClass(ProductOptionValueImpl.class.getName());
        metadata.setForeignKeyDisplayValueProperty("attributeValue");
        metadata.setLookupDisplayProperty("attributeValue");
        metadata.setForeignKeyCollection(false);
        metadata.setCustomCriteria(new String[] { "option=" + String.valueOf(option.getId()) });
        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.ADDITIONAL_FOREIGN_KEY);
        metadata.setProminent(false);
        metadata.setVisibility(VisibilityEnum.FORM_EXPLICITLY_SHOWN);
        metadata.setReadOnly(false);
        // these may not be actually required, but the CPH has this as a requirement for parsing the data, so we'll stick with it here
        metadata.setRequiredOverride(true);
        metadata.setLookupType(LookupType.STANDARD);
        metadata.setMutable(true);
        metadata.setInheritedFromType(SkuImpl.class.getName());
        metadata.setAvailableToTypes(getPolymorphicClasses(SkuImpl.class, em, skuMetadataCacheService.useCache()));
        metadata.setMergedPropertyType(MergedPropertyType.PRIMARY);
        metadata.setTargetClass(SkuImpl.class.getName());
        metadata.setFieldName(PRODUCT_OPTION_FIELD_PREFIX + option.getId());
    }
    return metadata;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Path(javax.persistence.criteria.Path) FieldPath(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPath) Serializable(java.io.Serializable) PersistenceManager(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceManager) ArrayList(java.util.ArrayList) FilterMapping(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping) From(javax.persistence.criteria.From) FieldPathBuilder(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder) Restriction(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.Restriction) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) PredicateProvider(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.predicate.PredicateProvider) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) List(java.util.List) ArrayList(java.util.ArrayList) ProductOptionValueImpl(org.broadleafcommerce.core.catalog.domain.ProductOptionValueImpl)

Example 40 with BasicFieldMetadata

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

the class SkuCustomPersistenceHandler method createConsolidatedOptionField.

/**
 * Creates the metadata necessary for displaying all of the product option values in a single field. The display of this
 * field is a single string with every product option value appended to it separated by a semicolon. This method should
 * be invoked on an inspect for whatever is utilizing this so that the property will be ready to be populated on fetch.
 *
 * The metadata that is returned will also be set to prominent by default so that it will be ready to display on whatever
 * grid is being inspected. If you do not want this behavior you will need to override this functionality in the metadata
 * that is returned.
 *
 * @param inheritedFromType which type this should appear on. This would normally be SkuImpl.class, but if you want to
 * display this field with a different entity then this should be that entity
 * @return
 */
public FieldMetadata createConsolidatedOptionField(Class<?> inheritedFromType) {
    BasicFieldMetadata metadata = new BasicFieldMetadata();
    metadata.setFieldType(SupportedFieldType.STRING);
    metadata.setMutable(false);
    metadata.setInheritedFromType(inheritedFromType.getName());
    metadata.setAvailableToTypes(getPolymorphicClasses(SkuImpl.class, em, skuMetadataCacheService.useCache()));
    metadata.setForeignKeyCollection(false);
    metadata.setMergedPropertyType(MergedPropertyType.PRIMARY);
    metadata.setName(CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME);
    metadata.setFriendlyName(CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME);
    metadata.setGroup("");
    metadata.setExplicitFieldType(SupportedFieldType.UNKNOWN);
    metadata.setProminent(true);
    metadata.setVisibility(VisibilityEnum.FORM_HIDDEN);
    metadata.setBroadleafEnumeration("");
    metadata.setReadOnly(true);
    metadata.setRequiredOverride(false);
    metadata.setGridOrder(Integer.MAX_VALUE);
    return metadata;
}
Also used : SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)

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