use of org.broadleafcommerce.openadmin.dto.SectionCrumb in project BroadleafCommerce by BroadleafCommerce.
the class AdminTranslationController method updateTranslation.
/**
* Updates the given translation id to the new locale code and translated value
*
* @param request
* @param response
* @param model
* @param entityForm
* @param result
* @return the result of a call to {@link #viewTranslation}, which renders the list grid
* @throws Exception
*/
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String updateTranslation(HttpServletRequest request, HttpServletResponse response, Model model, @ModelAttribute(value = "entityForm") EntityForm entityForm, BindingResult result) throws Exception {
final TranslationForm form = getTranslationForm(entityForm);
adminRemoteSecurityService.securityCheck(form.getCeilingEntity(), EntityOperationType.UPDATE);
SectionCrumb sectionCrumb = new SectionCrumb();
sectionCrumb.setSectionIdentifier(TranslationImpl.class.getName());
sectionCrumb.setSectionId(String.valueOf(form.getTranslationId()));
List<SectionCrumb> sectionCrumbs = Arrays.asList(sectionCrumb);
entityForm.setCeilingEntityClassname(Translation.class.getName());
entityForm.setEntityType(TranslationImpl.class.getName());
Field id = new Field();
id.setName("id");
id.setValue(String.valueOf(form.getTranslationId()));
entityForm.getFields().put("id", id);
entityForm.setId(String.valueOf(form.getTranslationId()));
String[] sectionCriteria = customCriteriaService.mergeSectionCustomCriteria(Translation.class.getName(), getSectionCustomCriteria());
service.updateEntity(entityForm, sectionCriteria, sectionCrumbs).getEntity();
return viewTranslation(request, response, model, form, result);
}
use of org.broadleafcommerce.openadmin.dto.SectionCrumb in project BroadleafCommerce by BroadleafCommerce.
the class EntityForm method getSectionCrumbs.
public String getSectionCrumbs() {
StringBuilder sb = new StringBuilder();
int index = 0;
for (SectionCrumb section : sectionCrumbs) {
sb.append(section.getSectionIdentifier());
sb.append("--");
sb.append(section.getSectionId());
if (index < sectionCrumbs.size() - 1) {
sb.append(",");
}
index++;
}
return sb.toString();
}
use of org.broadleafcommerce.openadmin.dto.SectionCrumb in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method applySkuBundleItemValueCriteria.
/**
* Add filter restriction such that a ProductBundle cannot add its own default sku as a Sku Bundle Item
*/
private void applySkuBundleItemValueCriteria(List<FilterMapping> filterMappings, CriteriaTransferObject cto, PersistencePackage persistencePackage) {
SectionCrumb[] sectionCrumbs = persistencePackage.getSectionCrumbs();
if (isSkuBundleItemLookup(persistencePackage, sectionCrumbs)) {
final Long defaultSkuId = getOwningProductBundlesDefaultSkuId(sectionCrumbs[0]);
filterMappings.add(new FilterMapping().withDirectFilterValues(Collections.singletonList(defaultSkuId)).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider() {
@Override
public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) {
return builder.notEqual(root, directValues.get(0));
}
})));
}
}
use of org.broadleafcommerce.openadmin.dto.SectionCrumb in project BroadleafCommerce by BroadleafCommerce.
the class AdminProductController method showAddAdditionalSku.
protected String showAddAdditionalSku(HttpServletRequest request, HttpServletResponse response, Model model, String id, Map<String, String> pathVars) throws Exception {
String collectionField = "additionalSkus";
String mainClassName = getClassNameForSection(SECTION_KEY);
List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, SECTION_KEY, id);
ClassMetadata mainMetadata = service.getClassMetadata(getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars)).getDynamicResultSet().getClassMetaData();
Property collectionProperty = mainMetadata.getPMap().get(collectionField);
FieldMetadata md = collectionProperty.getMetadata();
PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs).withCustomCriteria(new String[] { id });
BasicCollectionMetadata fmd = (BasicCollectionMetadata) md;
ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
// If the entity type isn't specified, we need to determine if there are various polymorphic types
// for this entity.
String entityType = null;
if (request.getParameter("entityType") != null) {
entityType = request.getParameter("entityType");
}
if (StringUtils.isBlank(entityType)) {
if (cmd.getPolymorphicEntities().getChildren().length == 0) {
entityType = cmd.getPolymorphicEntities().getFullyQualifiedClassname();
} else {
entityType = getDefaultEntityType();
}
} else {
entityType = URLDecoder.decode(entityType, "UTF-8");
}
if (StringUtils.isBlank(entityType)) {
List<ClassTree> entityTypes = getAddEntityTypes(cmd.getPolymorphicEntities());
model.addAttribute("entityTypes", entityTypes);
model.addAttribute("viewType", "modal/entityTypeSelection");
model.addAttribute("entityFriendlyName", cmd.getPolymorphicEntities().getFriendlyName());
String requestUri = request.getRequestURI();
if (!request.getContextPath().equals("/") && requestUri.startsWith(request.getContextPath())) {
requestUri = requestUri.substring(request.getContextPath().length() + 1, requestUri.length());
}
model.addAttribute("currentUri", requestUri);
model.addAttribute("modalHeaderType", ModalHeaderType.ADD_ENTITY.getType());
setModelAttributes(model, SECTION_KEY);
return "modules/modalContainer";
} else {
ppr = ppr.withCeilingEntityClassname(entityType);
}
ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
EntityForm entityForm = formService.createEntityForm(collectionMetadata, sectionCrumbs);
entityForm.setCeilingEntityClassname(ppr.getCeilingEntityClassname());
entityForm.setEntityType(ppr.getCeilingEntityClassname());
formService.removeNonApplicableFields(collectionMetadata, entityForm, ppr.getCeilingEntityClassname());
entityForm.removeAction(DefaultEntityFormActions.DELETE);
model.addAttribute("entityForm", entityForm);
model.addAttribute("viewType", "modal/simpleAddEntity");
model.addAttribute("currentUrl", request.getRequestURL().toString());
model.addAttribute("modalHeaderType", ModalHeaderType.ADD_COLLECTION_ITEM.getType());
model.addAttribute("collectionProperty", collectionProperty);
setModelAttributes(model, SECTION_KEY);
return "modules/modalContainer";
}
use of org.broadleafcommerce.openadmin.dto.SectionCrumb in project BroadleafCommerce by BroadleafCommerce.
the class AdminProductController method viewEntityListSelectize.
@Override
@RequestMapping(value = "/selectize", method = RequestMethod.GET)
@ResponseBody
public Map<String, Object> viewEntityListSelectize(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
String sectionKey = getSectionKey(pathVars);
String sectionClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> crumbs = getSectionCrumbs(request, null, null);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, requestParams, crumbs, pathVars).withStartIndex(getStartIndex(requestParams)).withMaxIndex(getMaxIndex(requestParams)).withCustomCriteria(getCustomCriteria(requestParams));
FilterAndSortCriteria[] fascs = getCriteria(requestParams);
for (FilterAndSortCriteria fasc : fascs) {
if (SELECTIZE_NAME_PROPERTY.equals(fasc.getPropertyId())) {
fasc.setPropertyId(DEFAULT_SKU_NAME);
break;
}
}
ppr.withFilterAndSortCriteria(fascs);
ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
return constructSelectizeOptionMap(drs, cmd);
}
Aggregations