Search in sources :

Example 11 with PersistenceResponse

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

the class AdminEntityServiceImpl method getRecord.

@Override
public PersistenceResponse getRecord(PersistencePackageRequest request, String id, ClassMetadata cmd, boolean isCollectionRequest) throws ServiceException {
    String idProperty = getIdProperty(cmd);
    FilterAndSortCriteria fasc = new FilterAndSortCriteria(idProperty);
    fasc.setFilterValue(id);
    request.addFilterAndSortCriteria(fasc);
    PersistenceResponse response = fetch(request);
    Entity[] entities = response.getDynamicResultSet().getRecords();
    if (ArrayUtils.isEmpty(entities)) {
        throw new EntityNotFoundException();
    }
    return response;
}
Also used : AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) EntityNotFoundException(org.broadleafcommerce.openadmin.exception.EntityNotFoundException)

Example 12 with PersistenceResponse

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

the class DynamicEntityRemoteService method inspect.

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

            @Override
            public void execute() throws Throwable {
                response[0] = nonTransactionalInspect(persistencePackage);
            }
        }, RuntimeException.class, true, TransactionDefinition.PROPAGATION_REQUIRED, TransactionDefinition.ISOLATION_DEFAULT, true, 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)

Example 13 with PersistenceResponse

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

the class DynamicEntityRemoteService method remove.

@Override
public PersistenceResponse remove(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] = nonTransactionalRemove(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)

Example 14 with PersistenceResponse

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

the class AdminBasicEntityController method addSelectizeCollectionItem.

/**
 * Adds the requested collection item via Selectize
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param id
 * @param collectionField
 * @param entityForm
 * @return the return view path
 * @throws Exception
 */
@RequestMapping(value = "/{id}/{collectionField:.*}/selectize-add", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> addSelectizeCollectionItem(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @PathVariable(value = "collectionField") String collectionField, @ModelAttribute(value = "entityForm") EntityForm entityForm, BindingResult result) throws Exception {
    Map<String, Object> returnVal = new HashMap<>();
    String sectionKey = getSectionKey(pathVars);
    String mainClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, sectionKey, id);
    ClassMetadata mainMetadata = service.getClassMetadata(getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars)).getDynamicResultSet().getClassMetaData();
    Property collectionProperty = mainMetadata.getPMap().get(collectionField);
    if (StringUtils.isBlank(entityForm.getEntityType())) {
        FieldMetadata fmd = collectionProperty.getMetadata();
        if (fmd instanceof BasicCollectionMetadata) {
            entityForm.setEntityType(((BasicCollectionMetadata) fmd).getCollectionCeilingEntity());
        }
    }
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars);
    ppr.addCustomCriteria(buildSelectizeCustomCriteria());
    declareShouldIgnoreAdditionStatusFilter();
    Entity entity = service.getRecord(ppr, id, mainMetadata, false).getDynamicResultSet().getRecords()[0];
    // First, we must save the collection entity
    PersistenceResponse persistenceResponse = service.addSubCollectionEntity(entityForm, mainMetadata, collectionProperty, entity, sectionCrumbs);
    Entity savedEntity = persistenceResponse.getEntity();
    entityFormValidator.validate(entityForm, savedEntity, result);
    if (result.hasErrors()) {
        returnVal.put("error", result.getFieldError());
        return returnVal;
    }
    if (savedEntity.findProperty(ALTERNATE_ID_PROPERTY) != null) {
        returnVal.put("alternateId", savedEntity.findProperty(ALTERNATE_ID_PROPERTY).getValue());
    }
    return returnVal;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) Property(org.broadleafcommerce.openadmin.dto.Property) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 15 with PersistenceResponse

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

the class AdminBasicEntityController method addEmptyCollectionItem.

@RequestMapping(value = "/{id}/{collectionField:.*}/addEmpty", method = RequestMethod.POST)
@ResponseBody
public String addEmptyCollectionItem(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @PathVariable(value = "collectionField") String collectionField, @ModelAttribute(value = "entityForm") EntityForm entityForm, BindingResult result) throws Exception {
    String sectionKey = getSectionKey(pathVars);
    String mainClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, sectionKey, id);
    ClassMetadata mainMetadata = service.getClassMetadata(getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars)).getDynamicResultSet().getClassMetaData();
    Property collectionProperty = mainMetadata.getPMap().get(collectionField);
    if (StringUtils.isBlank(entityForm.getEntityType())) {
        FieldMetadata fmd = collectionProperty.getMetadata();
        if (fmd instanceof BasicCollectionMetadata) {
            entityForm.setEntityType(((BasicCollectionMetadata) fmd).getCollectionCeilingEntity());
        }
    }
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars);
    Entity entity = service.getRecord(ppr, id, mainMetadata, false).getDynamicResultSet().getRecords()[0];
    entity.setIsPreAdd(true);
    // First, we must save the collection entity
    PersistenceResponse persistenceResponse = service.addSubCollectionEntity(entityForm, mainMetadata, collectionProperty, entity, sectionCrumbs);
    Entity savedEntity = persistenceResponse.getEntity();
    return new JsonResponse(response).with("status", "complete").with("id", savedEntity.findProperty(entityForm.getIdProperty()).getValue()).done();
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) 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) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) Property(org.broadleafcommerce.openadmin.dto.Property) JsonResponse(org.broadleafcommerce.common.web.JsonResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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