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;
}
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];
}
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];
}
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;
}
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();
}
Aggregations