Search in sources :

Example 6 with PersistenceResponse

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

the class DynamicEntityRemoteService method fetch.

@Override
public PersistenceResponse fetch(final PersistencePackage persistencePackage, final CriteriaTransferObject cto) 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] = nonTransactionalFetch(persistencePackage, cto);
            }
        }, 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 7 with PersistenceResponse

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

the class DynamicEntityRemoteService method update.

@Override
public PersistenceResponse update(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] = nonTransactionalUpdate(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 8 with PersistenceResponse

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

the class AdminBasicEntityController method updateCollectionItem.

/**
 * Updates the specified collection item
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param id
 * @param collectionField
 * @param collectionItemId the collection primary key value (in the case of adorned target collection, this is the primary key value of the target entity)
 * @param entityForm
 * @param alternateId in the case of adorned target collections, this is the primary key value of the collection member
 * @param result
 * @return the return view path
 * @throws Exception
 */
@RequestMapping(value = "/{id}/{collectionField:.*}/{collectionItemId}/{alternateId}", method = RequestMethod.POST)
public String updateCollectionItem(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @PathVariable(value = "collectionField") String collectionField, @PathVariable(value = "collectionItemId") String collectionItemId, @ModelAttribute(value = "entityForm") EntityForm entityForm, @PathVariable(value = "alternateId") String alternateId, 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);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars);
    Entity entity = service.getRecord(ppr, id, mainMetadata, false).getDynamicResultSet().getRecords()[0];
    // First, we must save the collection entity
    PersistenceResponse persistenceResponse = service.updateSubCollectionEntity(entityForm, mainMetadata, collectionProperty, entity, collectionItemId, alternateId, sectionCrumbs);
    Entity savedEntity = persistenceResponse.getEntity();
    entityFormValidator.validate(entityForm, savedEntity, result);
    if (result.hasErrors()) {
        return showViewUpdateCollection(request, model, pathVars, id, collectionField, collectionItemId, alternateId, ModalHeaderType.UPDATE_COLLECTION_ITEM.getType(), entityForm, savedEntity);
    }
    // Next, we must get the new list grid that represents this collection
    // We return the new list grid so that it can replace the currently visible one
    ListGrid listGrid = getCollectionListGrid(mainMetadata, entity, collectionProperty, null, sectionKey, persistenceResponse, sectionCrumbs);
    model.addAttribute("listGrid", listGrid);
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    setModelAttributes(model, sectionKey);
    return "views/standaloneListGrid";
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) Property(org.broadleafcommerce.openadmin.dto.Property) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with PersistenceResponse

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

the class AdminBasicEntityController method removeCollectionItem.

/**
 * Removes the requested collection item
 *
 * Note that the request must contain a parameter called "key" when attempting to remove a collection item from a
 * map collection.
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param id
 * @param collectionField
 * @param collectionItemId
 * @return the return view path
 * @throws Exception
 */
@RequestMapping(value = "/{id}/{collectionField:.*}/{collectionItemId}/{alternateId}/delete", method = RequestMethod.POST)
public String removeCollectionItem(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @PathVariable(value = "collectionField") String collectionField, @PathVariable(value = "collectionItemId") String collectionItemId, @PathVariable(value = "alternateId") String alternateId) 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);
    String priorKey = request.getParameter("key");
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars);
    declareShouldIgnoreAdditionStatusFilter();
    Entity entity = service.getRecord(ppr, id, mainMetadata, false).getDynamicResultSet().getRecords()[0];
    // First, we must remove the collection entity
    PersistenceResponse persistenceResponse = service.removeSubCollectionEntity(mainMetadata, collectionProperty, entity, collectionItemId, alternateId, priorKey, sectionCrumbs);
    if (persistenceResponse.getEntity() != null && persistenceResponse.getEntity().isValidationFailure()) {
        String error = "There was an error removing the whatever";
        if (MapUtils.isNotEmpty(persistenceResponse.getEntity().getPropertyValidationErrors())) {
            // If we failed, we'll return some JSON with the first error
            error = persistenceResponse.getEntity().getPropertyValidationErrors().values().iterator().next().get(0);
        } else if (CollectionUtils.isNotEmpty(persistenceResponse.getEntity().getGlobalValidationErrors())) {
            error = persistenceResponse.getEntity().getGlobalValidationErrors().get(0);
        }
        return new JsonResponse(response).with("status", "error").with("message", BLCMessageUtils.getMessage(error)).done();
    }
    // Next, we must get the new list grid that represents this collection
    // We return the new list grid so that it can replace the currently visible one
    ListGrid listGrid = getCollectionListGrid(mainMetadata, entity, collectionProperty, null, sectionKey, persistenceResponse, sectionCrumbs);
    model.addAttribute("listGrid", listGrid);
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    setModelAttributes(model, sectionKey);
    return "views/standaloneListGrid";
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) Property(org.broadleafcommerce.openadmin.dto.Property) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) JsonResponse(org.broadleafcommerce.common.web.JsonResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with PersistenceResponse

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

the class AdminEntityServiceImpl method getClassMetadata.

@Override
public PersistenceResponse getClassMetadata(PersistencePackageRequest request) throws ServiceException {
    PersistenceResponse response = inspect(request);
    ClassMetadata cmd = response.getDynamicResultSet().getClassMetaData();
    cmd.setCeilingType(request.getCeilingEntityClassname());
    cmd.setSecurityCeilingType(request.getSecurityCeilingEntityClassname());
    return response;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)

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