Search in sources :

Example 41 with PersistencePerspective

use of org.broadleafcommerce.openadmin.dto.PersistencePerspective 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);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Property(org.broadleafcommerce.openadmin.dto.Property) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 42 with PersistencePerspective

use of org.broadleafcommerce.openadmin.dto.PersistencePerspective 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);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) Category(org.broadleafcommerce.core.catalog.domain.Category) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 43 with PersistencePerspective

use of org.broadleafcommerce.openadmin.dto.PersistencePerspective 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);
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) CustomerPayment(org.broadleafcommerce.profile.core.domain.CustomerPayment) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) CustomerPaymentImpl(org.broadleafcommerce.profile.core.domain.CustomerPaymentImpl) HashMap(java.util.HashMap) Map(java.util.Map) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 44 with PersistencePerspective

use of org.broadleafcommerce.openadmin.dto.PersistencePerspective 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);
}
Also used : Status(org.broadleafcommerce.common.persistence.Status) Entity(org.broadleafcommerce.openadmin.dto.Entity) Serializable(java.io.Serializable) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) CriteriaTransferObject(org.broadleafcommerce.openadmin.dto.CriteriaTransferObject) IndexField(org.broadleafcommerce.core.search.domain.IndexField) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 45 with PersistencePerspective

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

the class IndexFieldCustomPersistenceHandler method add.

@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        IndexField adminInstance = (IndexField) Class.forName(entity.getType()[0]).newInstance();
        Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(IndexField.class.getName(), persistencePerspective);
        return getEntity(persistencePackage, dynamicEntityDao, helper, entity, adminProperties, adminInstance);
    } catch (Exception e) {
        throw new ServiceException("Unable to perform add for entity: " + IndexField.class.getName(), e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) IndexField(org.broadleafcommerce.core.search.domain.IndexField) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Aggregations

PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)51 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)44 ServiceException (org.broadleafcommerce.common.exception.ServiceException)39 Entity (org.broadleafcommerce.openadmin.dto.Entity)34 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)27 Serializable (java.io.Serializable)16 InvocationTargetException (java.lang.reflect.InvocationTargetException)16 SecurityServiceException (org.broadleafcommerce.common.exception.SecurityServiceException)16 CriteriaTransferObject (org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)16 ForeignKey (org.broadleafcommerce.openadmin.dto.ForeignKey)14 Map (java.util.Map)10 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)9 ValidationException (org.broadleafcommerce.openadmin.server.service.ValidationException)9 FilterMapping (org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping)7 HashMap (java.util.HashMap)6 AdornedTargetList (org.broadleafcommerce.openadmin.dto.AdornedTargetList)6 MapStructure (org.broadleafcommerce.openadmin.dto.MapStructure)6 SimpleValueMapStructure (org.broadleafcommerce.openadmin.dto.SimpleValueMapStructure)6 ParentEntityPersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.ParentEntityPersistenceException)6 PersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException)6