use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.
the class CategoryCustomPersistenceHandler method add.
@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
entity = validateParentCategory(entity, true);
if (entity.isValidationFailure()) {
return entity;
} else {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Category adminInstance = (Category) Class.forName(entity.getType()[0]).newInstance();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Category.class.getName(), persistencePerspective);
adminInstance = (Category) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
adminInstance = dynamicEntityDao.merge(adminInstance);
boolean handled = false;
if (extensionManager != null) {
ExtensionResultStatusType result = extensionManager.getProxy().manageParentCategoryForAdd(persistencePackage, adminInstance);
handled = ExtensionResultStatusType.NOT_HANDLED != result;
}
if (!handled) {
setupXref(adminInstance);
}
adminInstance = dynamicEntityDao.merge(adminInstance);
return helper.getRecord(adminProperties, adminInstance, null, null);
}
} catch (Exception e) {
throw new ServiceException("Unable to add entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.
the class CustomerCustomPersistenceHandler method add.
@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Customer adminInstance = (Customer) Class.forName(entity.getType()[0]).newInstance();
adminInstance.setId(customerService.findNextCustomerId());
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Customer.class.getName(), persistencePerspective);
adminInstance = (Customer) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
if (useEmailForLogin) {
adminInstance.setUsername(adminInstance.getEmailAddress());
}
if (!entity.isPreAdd()) {
Entity errorEntity = validateUniqueUsername(entity, adminInstance);
if (errorEntity != null) {
return errorEntity;
}
}
adminInstance = dynamicEntityDao.merge(adminInstance);
customerService.createRegisteredCustomerRoles(adminInstance);
Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
return adminEntity;
} catch (Exception e) {
LOG.error("Unable to execute persistence activity", e);
throw new ServiceException("Unable to add entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.
the class CustomerCustomPersistenceHandler method remove.
@Override
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
Long customerId = Long.parseLong(entity.findProperty("id").getValue());
Customer customer = customerService.readCustomerById(customerId);
if (Status.class.isAssignableFrom(customer.getClass())) {
((Status) customer).setArchived('Y');
// If the customer has a conditional weave on ArchiveStatus, nothing triggers the delete so other
// normally-cascaded deletes don't happen (like CustomerAddress)
List<CustomerAddress> addressList = customer.getCustomerAddresses();
for (CustomerAddress address : addressList) {
address.setArchived('Y');
}
customer = customerService.saveCustomer(customer);
return;
}
// Remove the customer roles for the customer since it's not cascaded
roleDao.removeCustomerRolesByCustomerId(customerId);
helper.getCompatibleModule(OperationType.BASIC).remove(persistencePackage);
} catch (Exception e) {
LOG.error("Unable to execute persistence activity", e);
throw new ServiceException("Unable to remove entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.
the class CustomerCustomPersistenceHandler 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(Customer.class.getName(), persistencePerspective);
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
Customer adminInstance = (Customer) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
String passwordBefore = adminInstance.getPassword();
adminInstance.setPassword(null);
adminInstance = (Customer) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
adminInstance.setPassword(passwordBefore);
if (useEmailForLogin) {
adminInstance.setUsername(adminInstance.getEmailAddress());
}
adminInstance = customerService.saveCustomer(adminInstance);
Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
return adminEntity;
} catch (Exception e) {
throw new ServiceException("Unable to update entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.
the class IndexFieldCustomPersistenceHandler method getEntity.
protected Entity getEntity(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper, Entity entity, Map<String, FieldMetadata> adminProperties, IndexField adminInstance) throws ServiceException {
adminInstance = (IndexField) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
adminInstance = dynamicEntityDao.merge(adminInstance);
ExtensionResultStatusType result = ExtensionResultStatusType.NOT_HANDLED;
if (extensionManager != null) {
result = extensionManager.getProxy().addtoSearchableFields(persistencePackage, adminInstance);
}
if (result.equals(ExtensionResultStatusType.NOT_HANDLED)) {
// If there is no searchable field types then we need to add a default as String
if (CollectionUtils.isEmpty(adminInstance.getFieldTypes())) {
IndexFieldType indexFieldType = new IndexFieldTypeImpl();
indexFieldType.setFieldType(FieldType.TEXT);
indexFieldType.setIndexField(adminInstance);
adminInstance.getFieldTypes().add(indexFieldType);
adminInstance = dynamicEntityDao.merge(adminInstance);
}
}
Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
return adminEntity;
}
Aggregations