use of org.broadleafcommerce.openadmin.dto.FieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method update.
@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
// Fill out the Sku instance from the form
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Sku.class.getName(), persistencePerspective);
filterOutProductMetadata(adminProperties);
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
Sku adminInstance = (Sku) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
adminInstance = (Sku) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
// Verify that there isn't already a Sku for this particular product option value combo
Entity errorEntity = validateUniqueProductOptionValueCombination(adminInstance.getProduct(), getProductOptionProperties(entity), adminInstance);
if (errorEntity != null) {
entity.setPropertyValidationErrors(errorEntity.getPropertyValidationErrors());
return entity;
}
// Only modify product options if this ISN'T an update for inventory properties
if (!persistencePackage.containsCriteria(INVENTORY_ONLY_CRITERIA)) {
associateProductOptionValuesToSku(entity, adminInstance, dynamicEntityDao);
}
adminInstance = dynamicEntityDao.merge(adminInstance);
extensionManager.getProxy().skuUpdated(adminInstance);
// Fill out the DTO and add in the product option value properties to it
Entity result = helper.getRecord(adminProperties, adminInstance, null, null);
for (Property property : getProductOptionProperties(entity)) {
result.addProperty(property);
}
return result;
} catch (Exception e) {
throw new ServiceException("Unable to perform update for entity: " + Sku.class.getName(), e);
}
}
use of org.broadleafcommerce.openadmin.dto.FieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method add.
@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
// Fill out the Sku instance from the form
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Sku adminInstance = (Sku) Class.forName(entity.getType()[0]).newInstance();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Sku.class.getName(), persistencePerspective);
filterOutProductMetadata(adminProperties);
adminInstance = (Sku) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
// Verify that there isn't already a Sku for this particular product option value combo
Entity errorEntity = validateUniqueProductOptionValueCombination(adminInstance.getProduct(), getProductOptionProperties(entity), null);
if (errorEntity != null) {
entity.setPropertyValidationErrors(errorEntity.getPropertyValidationErrors());
return entity;
}
// persist the newly-created Sku
adminInstance = dynamicEntityDao.persist(adminInstance);
// associate the product option values
associateProductOptionValuesToSku(entity, adminInstance, dynamicEntityDao);
// After associating the product option values, save off the Sku
adminInstance = dynamicEntityDao.merge(adminInstance);
// Fill out the DTO and add in the product option value properties to it
Entity result = helper.getRecord(adminProperties, adminInstance, null, null);
for (Property property : getProductOptionProperties(entity)) {
result.addProperty(property);
}
return result;
} catch (Exception e) {
throw new ServiceException("Unable to perform fetch for entity: " + Sku.class.getName(), e);
}
}
use of org.broadleafcommerce.openadmin.dto.FieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class CategoryCustomPersistenceHandler method update.
@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
entity = validateParentCategory(entity, false);
if (entity.isValidationFailure()) {
return entity;
} else {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Category.class.getName(), persistencePerspective);
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
Category adminInstance = (Category) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
CategoryXref oldDefault = getCurrentDefaultXref(adminInstance);
adminInstance = (Category) 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;
}
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.FieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class CustomerPaymentCustomPersistenceHandler method inspect.
@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> properties = helper.getSimpleMergedProperties(CustomerPayment.class.getName(), persistencePerspective);
// Hide "Payment Gateway Type" column & create "Saved Payment Info" ListGrid column
FieldMetadata paymentGatewayType = properties.get("paymentGatewayType");
if (paymentGatewayType != null) {
((BasicFieldMetadata) paymentGatewayType).setProminent(false);
}
BasicFieldMetadata savedPaymentInfo = new BasicFieldMetadata();
savedPaymentInfo.setName(SAVED_PAYMENT_INFO);
savedPaymentInfo.setFriendlyName("CustomerPaymentImpl_Saved_Payment_Info");
savedPaymentInfo.setFieldType(SupportedFieldType.STRING);
savedPaymentInfo.setInheritedFromType(CustomerPaymentImpl.class.getName());
savedPaymentInfo.setAvailableToTypes(new String[] { CustomerPaymentImpl.class.getName() });
savedPaymentInfo.setProminent(true);
savedPaymentInfo.setGridOrder(2000);
savedPaymentInfo.setReadOnly(true);
savedPaymentInfo.setVisibility(VisibilityEnum.FORM_HIDDEN);
properties.put(SAVED_PAYMENT_INFO, savedPaymentInfo);
allMergedProperties.put(MergedPropertyType.PRIMARY, properties);
Class<?>[] entityClasses = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(CustomerPayment.class);
ClassMetadata mergedMetadata = helper.buildClassMetadata(entityClasses, persistencePackage, allMergedProperties);
return new DynamicResultSet(mergedMetadata, null, null);
}
use of org.broadleafcommerce.openadmin.dto.FieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class IndexFieldCustomPersistenceHandler method remove.
@Override
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(IndexField.class.getName(), persistencePerspective);
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
Serializable instance = dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
if (instance instanceof Status) {
((Status) instance).setArchived('Y');
dynamicEntityDao.merge(instance);
return;
}
} catch (Exception ex) {
throw new ServiceException("Unable to perform remove for entity: " + entity.getType()[0], ex);
}
super.remove(persistencePackage, dynamicEntityDao, helper);
}
Aggregations