Search in sources :

Example 6 with PersistenceModule

use of org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule in project BroadleafCommerce by BroadleafCommerce.

the class PersistenceManagerImpl method fetch.

@Override
public PersistenceResponse fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto) throws ServiceException {
    for (PersistenceManagerEventHandler handler : persistenceManagerEventHandlers) {
        PersistenceManagerEventHandlerResponse response = handler.preFetch(this, persistencePackage, cto);
        if (PersistenceManagerEventHandlerResponse.PersistenceManagerEventHandlerResponseStatus.HANDLED_BREAK == response.getStatus()) {
            break;
        }
    }
    // check to see if there is a custom handler registered
    for (CustomPersistenceHandler handler : getCustomPersistenceHandlers()) {
        if (handler.canHandleFetch(persistencePackage)) {
            if (!handler.willHandleSecurity(persistencePackage)) {
                adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.FETCH);
            }
            DynamicResultSet results = handler.fetch(persistencePackage, cto, dynamicEntityDao, (RecordHelper) getCompatibleModule(OperationType.BASIC));
            return executePostFetchHandlers(persistencePackage, cto, new PersistenceResponse().withDynamicResultSet(results));
        }
    }
    adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.FETCH);
    PersistenceModule myModule = getCompatibleModule(persistencePackage.getPersistencePerspective().getOperationTypes().getFetchType());
    try {
        DynamicResultSet results = myModule.fetch(persistencePackage, cto);
        return executePostFetchHandlers(persistencePackage, cto, new PersistenceResponse().withDynamicResultSet(results));
    } catch (ServiceException e) {
        if (e.getCause() instanceof NoPossibleResultsException) {
            DynamicResultSet drs = new DynamicResultSet(null, new Entity[] {}, 0);
            return executePostFetchHandlers(persistencePackage, cto, new PersistenceResponse().withDynamicResultSet(drs));
        }
        throw e;
    }
}
Also used : NoPossibleResultsException(org.broadleafcommerce.common.exception.NoPossibleResultsException) AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) ServiceException(org.broadleafcommerce.common.exception.ServiceException) CustomPersistenceHandler(org.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler) PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 7 with PersistenceModule

use of org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule in project BroadleafCommerce by BroadleafCommerce.

the class PersistenceManagerImpl method inspect.

@Override
public PersistenceResponse inspect(PersistencePackage persistencePackage) throws ServiceException, ClassNotFoundException {
    for (PersistenceManagerEventHandler handler : persistenceManagerEventHandlers) {
        PersistenceManagerEventHandlerResponse response = handler.preInspect(this, persistencePackage);
        if (PersistenceManagerEventHandlerResponse.PersistenceManagerEventHandlerResponseStatus.HANDLED_BREAK == response.getStatus()) {
            break;
        }
    }
    // check to see if there is a custom handler registered
    for (CustomPersistenceHandler handler : getCustomPersistenceHandlers()) {
        if (handler.canHandleInspect(persistencePackage)) {
            if (!handler.willHandleSecurity(persistencePackage)) {
                adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.INSPECT);
            }
            DynamicResultSet results = handler.inspect(persistencePackage, dynamicEntityDao, this);
            return executePostInspectHandlers(persistencePackage, new PersistenceResponse().withDynamicResultSet(results));
        }
    }
    adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.INSPECT);
    Class<?>[] entities = getPolymorphicEntities(persistencePackage.getCeilingEntityFullyQualifiedClassname());
    Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<>();
    for (PersistenceModule module : modules) {
        module.updateMergedProperties(persistencePackage, allMergedProperties);
    }
    ClassMetadata classMetadata = buildClassMetadata(entities, persistencePackage, allMergedProperties);
    DynamicResultSet results = new DynamicResultSet(classMetadata);
    return executePostInspectHandlers(persistencePackage, new PersistenceResponse().withDynamicResultSet(results));
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) HashMap(java.util.HashMap) CustomPersistenceHandler(org.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler) PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with PersistenceModule

use of org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule in project BroadleafCommerce by BroadleafCommerce.

the class PersistenceManagerImpl method postConstruct.

@PostConstruct
public void postConstruct() {
    for (PersistenceModule module : modules) {
        module.setPersistenceManager(this);
    }
    Collections.sort(persistenceManagerEventHandlers, new Comparator<PersistenceManagerEventHandler>() {

        @Override
        public int compare(PersistenceManagerEventHandler o1, PersistenceManagerEventHandler o2) {
            return Integer.valueOf(o1.getOrder()).compareTo(Integer.valueOf(o2.getOrder()));
        }
    });
    honorExplicitPersistenceHandlerSorting();
}
Also used : PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) PostConstruct(javax.annotation.PostConstruct)

Example 9 with PersistenceModule

use of org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule in project BroadleafCommerce by BroadleafCommerce.

the class PersistenceManagerImpl method processMergedProperties.

public Property[] processMergedProperties(Class<?>[] entities, Map<MergedPropertyType, Map<String, FieldMetadata>> mergedProperties) {
    List<Property> propertiesList = new ArrayList<>();
    for (PersistenceModule module : modules) {
        module.extractProperties(entities, mergedProperties, propertiesList);
    }
    Property[] properties = new Property[propertiesList.size()];
    properties = propertiesList.toArray(properties);
    Arrays.sort(properties, new Comparator<Property>() {

        @Override
        public int compare(Property o1, Property o2) {
            Integer tabOrder1 = o1.getMetadata().getTabOrder() == null ? 99999 : o1.getMetadata().getTabOrder();
            Integer tabOrder2 = o2.getMetadata().getTabOrder() == null ? 99999 : o2.getMetadata().getTabOrder();
            Integer groupOrder1 = null;
            Integer groupOrder2 = null;
            if (o1.getMetadata() instanceof BasicFieldMetadata) {
                BasicFieldMetadata b1 = (BasicFieldMetadata) o1.getMetadata();
                groupOrder1 = b1.getGroupOrder();
            }
            groupOrder1 = groupOrder1 == null ? 99999 : groupOrder1;
            if (o2.getMetadata() instanceof BasicFieldMetadata) {
                BasicFieldMetadata b2 = (BasicFieldMetadata) o2.getMetadata();
                groupOrder2 = b2.getGroupOrder();
            }
            groupOrder2 = groupOrder2 == null ? 99999 : groupOrder2;
            Integer fieldOrder1 = o1.getMetadata().getOrder() == null ? 99999 : o1.getMetadata().getOrder();
            Integer fieldOrder2 = o2.getMetadata().getOrder() == null ? 99999 : o2.getMetadata().getOrder();
            String friendlyName1 = o1.getMetadata().getFriendlyName() == null ? "zzzz" : o1.getMetadata().getFriendlyName();
            String friendlyName2 = o2.getMetadata().getFriendlyName() == null ? "zzzz" : o2.getMetadata().getFriendlyName();
            String name1 = o1.getName() == null ? "zzzzz" : o1.getName();
            String name2 = o2.getName() == null ? "zzzzz" : o2.getName();
            return new CompareToBuilder().append(tabOrder1, tabOrder2).append(groupOrder1, groupOrder2).append(fieldOrder1, fieldOrder2).append(friendlyName1, friendlyName2).append(name1, name2).toComparison();
        }
    });
    return properties;
}
Also used : BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) ArrayList(java.util.ArrayList) PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) Property(org.broadleafcommerce.openadmin.dto.Property) CompareToBuilder(org.apache.commons.lang3.builder.CompareToBuilder)

Example 10 with PersistenceModule

use of org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule in project BroadleafCommerce by BroadleafCommerce.

the class CustomerPaymentCustomPersistenceHandler method fetch.

@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    OperationType fetchType = persistencePackage.getPersistencePerspective().getOperationTypes().getFetchType();
    PersistenceModule persistenceModule = helper.getCompatibleModule(fetchType);
    DynamicResultSet drs = persistenceModule.fetch(persistencePackage, cto);
    for (Entity entity : drs.getRecords()) {
        Property customerPaymentId = entity.findProperty("id");
        if (customerPaymentId != null) {
            CustomerPayment customerPayment = customerPaymentService.readCustomerPaymentById(Long.parseLong(customerPaymentId.getValue()));
            if (customerPayment != null) {
                String savedPaymentDisplayValue = buildSavedPaymentDisplayValue(customerPayment);
                Property derivedLabel = new Property();
                derivedLabel.setName(SAVED_PAYMENT_INFO);
                derivedLabel.setValue(savedPaymentDisplayValue);
                entity.addProperty(derivedLabel);
            }
        }
    }
    return drs;
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) CustomerPayment(org.broadleafcommerce.profile.core.domain.CustomerPayment) OperationType(org.broadleafcommerce.common.presentation.client.OperationType) PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) Property(org.broadleafcommerce.openadmin.dto.Property)

Aggregations

PersistenceModule (org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule)11 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)5 CustomPersistenceHandler (org.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler)5 Entity (org.broadleafcommerce.openadmin.dto.Entity)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)3 PersistencePackage (org.broadleafcommerce.openadmin.dto.PersistencePackage)2 Property (org.broadleafcommerce.openadmin.dto.Property)2 ValidationException (org.broadleafcommerce.openadmin.server.service.ValidationException)2 RecordHelper (org.broadleafcommerce.openadmin.server.service.persistence.module.RecordHelper)2 Serializable (java.io.Serializable)1 PostConstruct (javax.annotation.PostConstruct)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 From (javax.persistence.criteria.From)1 Path (javax.persistence.criteria.Path)1 Predicate (javax.persistence.criteria.Predicate)1