Search in sources :

Example 1 with PersistenceResponse

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

the class AdminEntityServiceImpl method getRecordsForSelectedTab.

@Override
public Map<String, DynamicResultSet> getRecordsForSelectedTab(ClassMetadata cmd, Entity containingEntity, List<SectionCrumb> sectionCrumb, String currentTabName) throws ServiceException {
    Map<String, DynamicResultSet> map = new HashMap<String, DynamicResultSet>();
    for (Property p : cmd.getProperties()) {
        if (ArrayUtils.contains(p.getMetadata().getAvailableToTypes(), containingEntity.getType()[0]) && p.getMetadata() instanceof CollectionMetadata) {
            CollectionMetadata collectionMetadata = (CollectionMetadata) p.getMetadata();
            // Give preference to the Group since EntityForm.addListGrid() gives preference to the Group
            TabMetadata tabMetadata = cmd.getTabMetadataUsingGroupKey(collectionMetadata.getGroup());
            if (tabMetadata == null) {
                tabMetadata = cmd.getTabMetadataUsingTabKey(collectionMetadata.getTab());
            }
            String tabName = tabMetadata == null ? collectionMetadata.getTab() : tabMetadata.getTabName();
            int tabOrder = tabMetadata == null ? collectionMetadata.getTabOrder() : tabMetadata.getTabOrder();
            updateTabInfo(collectionMetadata, cmd, tabName, tabOrder);
            if (collectionMetadata.getLazyFetch() != null && collectionMetadata.getLazyFetch() && tabName.toUpperCase().startsWith(currentTabName.toUpperCase()) && !collectionMetadata.getManualFetch()) {
                PersistenceResponse response2 = getRecordsForCollection(cmd, containingEntity, p, null, null, null, sectionCrumb);
                map.put(p.getName(), response2.getDynamicResultSet());
            } else if (collectionMetadata.getLazyFetch() != null && !collectionMetadata.getLazyFetch() && !collectionMetadata.getManualFetch()) {
                PersistenceResponse response2 = getRecordsForCollection(cmd, containingEntity, p, null, null, null, sectionCrumb);
                map.put(p.getName(), response2.getDynamicResultSet());
            } else {
                DynamicResultSet drs = new DynamicResultSet();
                Map<String, Tab> tabMap = new HashMap<String, Tab>();
                Tab tab = new Tab();
                tab.setKey(tabName);
                tab.setTitle(BLCMessageUtils.getMessage(tabName));
                tab.setOrder(tabOrder);
                tabMap.put(tab.getTitle(), tab);
                drs.setUnselectedTabMetadata(tabMap);
                drs.setTotalRecords(0);
                drs.setStartIndex(0);
                drs.setBatchId(1);
                drs.setClassMetaData(null);
                drs.setPageSize(1);
                drs.setRecords(new Entity[0]);
                map.put(p.getName(), drs);
            }
        }
    }
    return map;
}
Also used : AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) CollectionMetadata(org.broadleafcommerce.openadmin.dto.CollectionMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata) HashMap(java.util.HashMap) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) Tab(org.broadleafcommerce.openadmin.web.form.entity.Tab) TabMetadata(org.broadleafcommerce.openadmin.dto.TabMetadata) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with PersistenceResponse

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

the class AdminEntityServiceImpl method getAdvancedCollectionRecord.

@Override
public PersistenceResponse getAdvancedCollectionRecord(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, String collectionItemId, List<SectionCrumb> sectionCrumbs, String alternateId, String[] customCriteria) throws ServiceException {
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(collectionProperty.getMetadata(), sectionCrumbs);
    ppr.addCustomCriteria(customCriteria);
    FieldMetadata md = collectionProperty.getMetadata();
    String containingEntityId = getContextSpecificRelationshipId(containingClassMetadata, containingEntity, collectionProperty.getName());
    ppr.setSectionEntityField(collectionProperty.getName());
    PersistenceResponse response;
    if (md instanceof AdornedTargetCollectionMetadata) {
        FilterAndSortCriteria fasc = new FilterAndSortCriteria(ppr.getAdornedList().getCollectionFieldName());
        fasc.setFilterValue(containingEntityId);
        ppr.addFilterAndSortCriteria(fasc);
        fasc = new FilterAndSortCriteria(ppr.getAdornedList().getCollectionFieldName() + "Target");
        fasc.setFilterValue(collectionItemId);
        ppr.addFilterAndSortCriteria(fasc);
        if (!StringUtils.isEmpty(alternateId)) {
            fasc = new FilterAndSortCriteria(ppr.getAdornedList().getIdProperty());
            fasc.setFilterValue(alternateId);
            ppr.addFilterAndSortCriteria(fasc);
        }
        response = fetch(ppr);
        Entity[] entities = response.getDynamicResultSet().getRecords();
        if (ArrayUtils.isEmpty(entities)) {
            throw new EntityNotFoundException();
        }
    } else if (md instanceof MapMetadata) {
        MapMetadata mmd = (MapMetadata) md;
        FilterAndSortCriteria fasc = new FilterAndSortCriteria(ppr.getForeignKey().getManyToField());
        fasc.setFilterValue(containingEntityId);
        ppr.addFilterAndSortCriteria(fasc);
        response = fetch(ppr);
        Entity[] entities = response.getDynamicResultSet().getRecords();
        for (Entity e : entities) {
            String idProperty = getIdProperty(containingClassMetadata);
            if (mmd.isSimpleValue()) {
                idProperty = "key";
            }
            Property p = e.getPMap().get(idProperty);
            if (p.getValue().equals(collectionItemId)) {
                response.setEntity(e);
                break;
            }
        }
    } else {
        throw new IllegalArgumentException(String.format("The specified field [%s] for class [%s] was not an " + "advanced collection field.", collectionProperty.getName(), containingClassMetadata.getCeilingType()));
    }
    return response;
}
Also used : AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) EntityNotFoundException(org.broadleafcommerce.openadmin.exception.EntityNotFoundException) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)

Example 3 with PersistenceResponse

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

the class AdminEntityServiceImpl method getAllRecordsForAllSubCollections.

@Override
public Map<String, DynamicResultSet> getAllRecordsForAllSubCollections(ClassMetadata cmd, Entity containingEntity, List<SectionCrumb> sectionCrumb) throws ServiceException {
    Map<String, DynamicResultSet> map = new HashMap<>();
    for (Property p : cmd.getProperties()) {
        FieldMetadata fieldMetadata = p.getMetadata();
        boolean fieldAvailable = ArrayUtils.contains(fieldMetadata.getAvailableToTypes(), containingEntity.getType()[0]);
        if (fieldAvailable && fieldMetadata instanceof CollectionMetadata) {
            FetchPageRequest pageRequest = new FetchPageRequest().withPageSize(Integer.MAX_VALUE);
            PersistenceResponse resp = getPagedRecordsForCollection(cmd, containingEntity, p, null, pageRequest, null, sectionCrumb);
            map.put(p.getName(), resp.getDynamicResultSet());
        }
    }
    return map;
}
Also used : BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) CollectionMetadata(org.broadleafcommerce.openadmin.dto.CollectionMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) FetchPageRequest(org.broadleafcommerce.openadmin.server.domain.FetchPageRequest) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 4 with PersistenceResponse

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

the class AdminEntityServiceImpl method getRecordsForAllSubCollections.

@Override
public Map<String, DynamicResultSet> getRecordsForAllSubCollections(PersistencePackageRequest ppr, Entity containingEntity, Integer startIndex, Integer maxIndex, List<SectionCrumb> sectionCrumb) throws ServiceException {
    Map<String, DynamicResultSet> map = new HashMap<String, DynamicResultSet>();
    PersistenceResponse response = getClassMetadata(ppr);
    ClassMetadata cmd = response.getDynamicResultSet().getClassMetaData();
    for (Property p : cmd.getProperties()) {
        if (ArrayUtils.contains(p.getMetadata().getAvailableToTypes(), containingEntity.getType()[0]) && p.getMetadata() instanceof CollectionMetadata) {
            PersistenceResponse response2 = getRecordsForCollection(cmd, containingEntity, p, null, startIndex, maxIndex, sectionCrumb);
            map.put(p.getName(), response2.getDynamicResultSet());
        }
    }
    return map;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) CollectionMetadata(org.broadleafcommerce.openadmin.dto.CollectionMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata) HashMap(java.util.HashMap) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 5 with PersistenceResponse

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

the class DynamicEntityRemoteService method add.

@Override
public PersistenceResponse add(final PersistencePackage persistencePackage) throws ServiceException {
    final PersistenceResponse[] response = new PersistenceResponse[1];
    try {
        PlatformTransactionManager transactionManager = identifyTransactionManager(persistencePackage);
        transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {

            @Override
            public void execute() throws Throwable {
                response[0] = nonTransactionalAdd(persistencePackage);
            }

            @Override
            public boolean shouldRetryOnTransactionLockAcquisitionFailure() {
                return super.shouldRetryOnTransactionLockAcquisitionFailure();
            }
        }, RuntimeException.class, transactionManager);
    } catch (RuntimeException e) {
        if (e.getCause() instanceof ServiceException) {
            throw (ServiceException) e.getCause();
        }
        throw e;
    }
    return response[0];
}
Also used : ServiceException(org.broadleafcommerce.common.exception.ServiceException) StreamCapableTransactionalOperationAdapter(org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager)

Aggregations

PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)17 Property (org.broadleafcommerce.openadmin.dto.Property)10 Entity (org.broadleafcommerce.openadmin.dto.Entity)9 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)8 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)7 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)7 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)6 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)6 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 HashMap (java.util.HashMap)5 ServiceException (org.broadleafcommerce.common.exception.ServiceException)5 StreamCapableTransactionalOperationAdapter (org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter)5 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)5 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)5 BLCSystemProperty (org.broadleafcommerce.common.util.BLCSystemProperty)4 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)3 CollectionMetadata (org.broadleafcommerce.openadmin.dto.CollectionMetadata)3 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)3 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)3