use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicEntityController method getCollectionFieldRecords.
/**
* Returns the records for a given collectionField filtered by a particular criteria
*
* @param request
* @param response
* @param model
* @param pathVars
* @param collectionField
* @param requestParams
* @return the return view path
* @throws Exception
*/
@RequestMapping(value = "/{id}/{collectionField:.*}", method = RequestMethod.GET)
public String getCollectionFieldRecords(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @PathVariable(value = "collectionField") String collectionField, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
String sectionKey = getSectionKey(pathVars);
String mainClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, sectionKey, id);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(mainClassName, requestParams, sectionCrumbs, pathVars);
ClassMetadata mainMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
Property collectionProperty = mainMetadata.getPMap().get(collectionField);
ppr = getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars);
Entity entity = service.getRecord(ppr, id, mainMetadata, false).getDynamicResultSet().getRecords()[0];
// Next, we must get the new list grid that represents this collection
ListGrid listGrid = getCollectionListGrid(mainMetadata, entity, collectionProperty, requestParams, sectionKey, sectionCrumbs);
model.addAttribute("listGrid", listGrid);
model.addAttribute("currentParams", new ObjectMapper().writeValueAsString(requestParams));
// We return the new list grid so that it can replace the currently visible one
setModelAttributes(model, sectionKey);
return "views/standaloneListGrid";
}
use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicEntityController method buildDirtyList.
public List<String> buildDirtyList(Map<String, String> pathVars, HttpServletRequest request, String id) throws ServiceException {
List<String> dirtyList = new ArrayList<>();
String sectionKey = getSectionKey(pathVars);
String sectionClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, sectionKey, id);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, sectionCrumbs, pathVars);
ClassMetadata cmd = null;
Entity entity = null;
cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
entity = service.getRecord(ppr, id, cmd, false).getDynamicResultSet().getRecords()[0];
for (Property p : entity.getProperties()) {
if (p.getIsDirty()) {
dirtyList.add(p.getName());
}
}
return dirtyList;
}
use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest 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";
}
use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicEntityController method viewEntityTab.
/**
* Attempts to get the List Grid for the selected tab.
*
* @param request
* @param response
* @param model
* @param pathVars
* @param id
* @param tabName
* @param entityForm
* @param entity
* @return the return view path
* @throws Exception
*/
@RequestMapping(value = "/{id}/{tab:[0-9]+}/{tabName}", method = RequestMethod.POST)
public String viewEntityTab(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @PathVariable(value = "tabName") String tabName, @ModelAttribute(value = "entityForm") EntityForm entityForm, @ModelAttribute(value = "entity") Entity entity) throws Exception {
String sectionKey = getSectionKey(pathVars);
String sectionClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> crumbs = getSectionCrumbs(request, sectionKey, id);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, crumbs, pathVars);
ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
entity = service.getRecord(ppr, id, cmd, false).getDynamicResultSet().getRecords()[0];
Map<String, DynamicResultSet> subRecordsMap = getViewSubRecords(request, pathVars, cmd, entity, crumbs);
entityForm = formService.createEntityForm(cmd, entity, subRecordsMap, crumbs);
if (isAddRequest(entity)) {
modifyAddEntityForm(entityForm, pathVars);
} else {
modifyEntityForm(entityForm, pathVars);
}
model.addAttribute("entity", entity);
model.addAttribute("entityForm", entityForm);
model.addAttribute("currentUrl", request.getRequestURL().toString());
setModelAttributes(model, sectionKey);
model.addAttribute("useAjaxUpdate", true);
model.addAttribute("viewType", "entityEdit");
return "modules/defaultContainer";
}
use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest 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";
}
Aggregations