Search in sources :

Example 71 with Entity

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

the class ProductCustomPersistenceHandler method remove.

@Override
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        Product adminInstance = getAdminInstance(persistencePackage, dynamicEntityDao, helper, entity);
        removeProduct(persistencePackage, adminInstance, helper);
    } catch (ClassNotFoundException e) {
        throw new ServiceException("Unable to remove entity for " + entity.getType()[0], e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Product(org.broadleafcommerce.core.catalog.domain.Product)

Example 72 with Entity

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

the class SearchFacetCustomPersistenceHandler method remove.

@Override
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        SearchFacet adminInstance = getAdminInstance(persistencePackage, dynamicEntityDao, helper, entity);
        if (Status.class.isAssignableFrom(adminInstance.getClass())) {
            ((Status) adminInstance).setArchived('Y');
            dynamicEntityDao.merge(adminInstance);
        }
    } catch (Exception e) {
        throw new ServiceException("Unable to remove entity for " + entity.getType()[0], e);
    }
}
Also used : Status(org.broadleafcommerce.common.persistence.Status) Entity(org.broadleafcommerce.openadmin.dto.Entity) SearchFacet(org.broadleafcommerce.core.search.domain.SearchFacet) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 73 with Entity

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

the class SearchFacetRangeCustomPersistenceHandler method remove.

@Override
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        SearchFacetRange adminInstance = getAdminInstance(persistencePackage, dynamicEntityDao, helper, entity);
        if (Status.class.isAssignableFrom(adminInstance.getClass())) {
            ((Status) adminInstance).setArchived('Y');
            dynamicEntityDao.merge(adminInstance);
        }
    } catch (Exception e) {
        throw new ServiceException("Unable to remove entity for " + entity.getType()[0], e);
    }
}
Also used : Status(org.broadleafcommerce.common.persistence.Status) Entity(org.broadleafcommerce.openadmin.dto.Entity) ServiceException(org.broadleafcommerce.common.exception.ServiceException) SearchFacetRange(org.broadleafcommerce.core.search.domain.SearchFacetRange) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 74 with Entity

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

the class SkuCustomPersistenceHandler method fetch.

@SuppressWarnings("unchecked")
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        // get the default properties from Sku and its subclasses
        Map<String, FieldMetadata> originalProps = helper.getSimpleMergedProperties(Sku.class.getName(), persistencePerspective);
        // Pull back the Skus based on the criteria from the client
        List<FilterMapping> filterMappings = helper.getFilterMappings(persistencePerspective, cto, ceilingEntityFullyQualifiedClassname, originalProps);
        // allow subclasses to provide additional criteria before executing the query
        applyProductOptionValueCriteria(filterMappings, cto, persistencePackage, null);
        applySkuBundleItemValueCriteria(filterMappings, cto, persistencePackage);
        applyAdditionalFetchCriteria(filterMappings, cto, persistencePackage);
        List<Serializable> records = helper.getPersistentRecords(persistencePackage.getCeilingEntityFullyQualifiedClassname(), filterMappings, cto.getFirstResult(), cto.getMaxResults());
        // Convert Skus into the client-side Entity representation
        Entity[] payload = helper.getRecords(originalProps, records);
        int totalRecords = helper.getTotalRecords(persistencePackage.getCeilingEntityFullyQualifiedClassname(), filterMappings);
        // Now fill out the relevant properties for the product options for the Skus that were returned
        updateProductOptionFieldsForFetch(records, payload);
        return new DynamicResultSet(payload, totalRecords);
    } catch (Exception e) {
        throw new ServiceException("Unable to perform fetch for entity: " + ceilingEntityFullyQualifiedClassname, e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) Serializable(java.io.Serializable) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FilterMapping(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping) ServiceException(org.broadleafcommerce.common.exception.ServiceException) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Sku(org.broadleafcommerce.core.catalog.domain.Sku) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 75 with Entity

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

Aggregations

Entity (org.broadleafcommerce.openadmin.dto.Entity)112 Property (org.broadleafcommerce.openadmin.dto.Property)62 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)51 ServiceException (org.broadleafcommerce.common.exception.ServiceException)48 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)36 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)34 ArrayList (java.util.ArrayList)25 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)24 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)24 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)20 Serializable (java.io.Serializable)19 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)19 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)19 ValidationException (org.broadleafcommerce.openadmin.server.service.ValidationException)17 Map (java.util.Map)16 CriteriaTransferObject (org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)16 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)16 HashMap (java.util.HashMap)15 SecurityServiceException (org.broadleafcommerce.common.exception.SecurityServiceException)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14