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