Search in sources :

Example 21 with SectionCrumb

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);
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) Translation(org.broadleafcommerce.common.i18n.domain.Translation) TranslationImpl(org.broadleafcommerce.common.i18n.domain.TranslationImpl) TranslationForm(org.broadleafcommerce.openadmin.web.form.TranslationForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with SectionCrumb

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();
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb)

Example 23 with SectionCrumb

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));
            }
        })));
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Path(javax.persistence.criteria.Path) FieldPath(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPath) FilterMapping(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping) From(javax.persistence.criteria.From) FieldPathBuilder(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder) Predicate(javax.persistence.criteria.Predicate) SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) Restriction(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.Restriction) PredicateProvider(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.predicate.PredicateProvider) List(java.util.List) ArrayList(java.util.ArrayList)

Example 24 with SectionCrumb

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";
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) ClassTree(org.broadleafcommerce.openadmin.dto.ClassTree) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 25 with SectionCrumb

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);
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)42 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)32 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)28 Entity (org.broadleafcommerce.openadmin.dto.Entity)19 Property (org.broadleafcommerce.openadmin.dto.Property)19 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)15 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)13 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)12 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)9 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)9 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)8 EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)6 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)5 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)5 Map (java.util.Map)4 Translation (org.broadleafcommerce.common.i18n.domain.Translation)4