Search in sources :

Example 1 with SectionCrumb

use of org.broadleafcommerce.openadmin.dto.SectionCrumb in project BroadleafCommerce by BroadleafCommerce.

the class PersistencePackageFactoryImpl method create.

@Override
public PersistencePackage create(PersistencePackageRequest request) {
    PersistencePerspective persistencePerspective = new PersistencePerspective();
    persistencePerspective.setAdditionalForeignKeys(request.getAdditionalForeignKeys());
    persistencePerspective.setAdditionalNonPersistentProperties(new String[] {});
    if (request.getForeignKey() != null) {
        persistencePerspective.addPersistencePerspectiveItem(PersistencePerspectiveItemType.FOREIGNKEY, request.getForeignKey());
    }
    switch(request.getType()) {
        case STANDARD:
            persistencePerspective.setOperationTypes(getDefaultOperationTypes());
            break;
        case ADORNED:
            if (request.getAdornedList() == null) {
                throw new IllegalArgumentException("ADORNED type requires the adornedList to be set");
            }
            persistencePerspective.setOperationTypes(getOperationTypes(OperationType.ADORNEDTARGETLIST));
            persistencePerspective.addPersistencePerspectiveItem(PersistencePerspectiveItemType.ADORNEDTARGETLIST, request.getAdornedList());
            break;
        case MAP:
            if (request.getMapStructure() == null) {
                throw new IllegalArgumentException("MAP type requires the mapStructure to be set");
            }
            persistencePerspective.setOperationTypes(getOperationTypes(OperationType.MAP));
            persistencePerspective.addPersistencePerspectiveItem(PersistencePerspectiveItemType.MAPSTRUCTURE, request.getMapStructure());
            break;
    }
    if (request.getOperationTypesOverride() != null) {
        persistencePerspective.setOperationTypes(request.getOperationTypesOverride());
    }
    PersistencePackage pp = new PersistencePackage();
    pp.setCeilingEntityFullyQualifiedClassname(request.getCeilingEntityClassname());
    if (!StringUtils.isEmpty(request.getSecurityCeilingEntityClassname())) {
        pp.setSecurityCeilingEntityFullyQualifiedClassname(request.getSecurityCeilingEntityClassname());
    }
    if (!ArrayUtils.isEmpty(request.getSectionCrumbs())) {
        SectionCrumb[] converted = new SectionCrumb[request.getSectionCrumbs().length];
        int index = 0;
        for (SectionCrumb crumb : request.getSectionCrumbs()) {
            SectionCrumb temp = new SectionCrumb();
            String originalSectionIdentifier = crumb.getSectionIdentifier();
            String sectionAsClassName;
            try {
                sectionAsClassName = getClassNameForSection(crumb.getSectionIdentifier());
            } catch (Exception e) {
                sectionAsClassName = request.getCeilingEntityClassname();
            }
            if (sectionAsClassName != null && !sectionAsClassName.equals(originalSectionIdentifier)) {
                temp.setOriginalSectionIdentifier(originalSectionIdentifier);
            }
            temp.setSectionIdentifier(sectionAsClassName);
            temp.setSectionId(crumb.getSectionId());
            converted[index] = temp;
            index++;
        }
        pp.setSectionCrumbs(converted);
    } else {
        pp.setSectionCrumbs(new SectionCrumb[0]);
    }
    pp.setSectionEntityField(request.getSectionEntityField());
    pp.setFetchTypeFullyQualifiedClassname(null);
    pp.setPersistencePerspective(persistencePerspective);
    pp.setCustomCriteria(request.getCustomCriteria());
    pp.setCsrfToken(null);
    pp.setRequestingEntityName(request.getRequestingEntityName());
    pp.setValidateUnsubmittedProperties(request.isValidateUnsubmittedProperties());
    pp.setIsTreeCollection(request.isTreeCollection());
    pp.setAddOperationInspect(request.isAddOperationInspect());
    if (request.getEntity() != null) {
        pp.setEntity(request.getEntity());
    }
    for (Map.Entry<String, PersistencePackageRequest> subRequest : request.getSubRequests().entrySet()) {
        pp.getSubPackages().put(subRequest.getKey(), create(subRequest.getValue()));
    }
    return pp;
}
Also used : PersistencePackage(org.broadleafcommerce.openadmin.dto.PersistencePackage) SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) Map(java.util.Map)

Example 2 with SectionCrumb

use of org.broadleafcommerce.openadmin.dto.SectionCrumb in project BroadleafCommerce by BroadleafCommerce.

the class AdminProductController method showUpdateAdditionalSku.

protected String showUpdateAdditionalSku(HttpServletRequest request, Model model, String id, String collectionItemId, Map<String, String> pathVars, EntityForm entityForm) throws Exception {
    String collectionField = "additionalSkus";
    // Find out metadata for the additionalSkus property
    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();
    // Find the metadata and the entity for the selected sku
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs).withCustomCriteria(new String[] { id });
    ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    if (collectionMetadata.getCeilingType().equals(SkuImpl.class.getName())) {
        collectionMetadata.setCeilingType(Sku.class.getName());
    }
    Entity entity = service.getRecord(ppr, collectionItemId, collectionMetadata, true).getDynamicResultSet().getRecords()[0];
    String currentTabName = getCurrentTabName(pathVars, collectionMetadata);
    Map<String, DynamicResultSet> subRecordsMap = service.getRecordsForSelectedTab(collectionMetadata, entity, sectionCrumbs, currentTabName);
    if (entityForm == null) {
        entityForm = formService.createEntityForm(collectionMetadata, entity, subRecordsMap, sectionCrumbs);
    } else {
        entityForm.clearFieldsMap();
        formService.populateEntityForm(collectionMetadata, entity, subRecordsMap, entityForm, sectionCrumbs);
        // remove all the actions since we're not trying to redisplay them on the form
        entityForm.removeAllActions();
    }
    entityForm.removeAction(DefaultEntityFormActions.DELETE);
    // Ensure that operations on the Sku subcollections go to the proper URL
    for (ListGrid lg : entityForm.getAllListGrids()) {
        lg.setSectionKey("org.broadleafcommerce.core.catalog.domain.Sku");
        lg.setSectionCrumbs(sectionCrumbs);
    }
    model.addAttribute("entityForm", entityForm);
    model.addAttribute("viewType", "modal/simpleEditEntity");
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    model.addAttribute("modalHeaderType", ModalHeaderType.UPDATE_COLLECTION_ITEM.getType());
    model.addAttribute("collectionProperty", collectionProperty);
    setModelAttributes(model, SECTION_KEY);
    return "modules/modalContainer";
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 3 with SectionCrumb

use of org.broadleafcommerce.openadmin.dto.SectionCrumb in project BroadleafCommerce by BroadleafCommerce.

the class AdminNavigationServiceImpl method getSectionCrumbs.

@Override
public List<SectionCrumb> getSectionCrumbs(String crumbList) {
    List<SectionCrumb> myCrumbs = new ArrayList<SectionCrumb>();
    if (!StringUtils.isEmpty(crumbList)) {
        String[] crumbParts = crumbList.split(",");
        for (String part : crumbParts) {
            SectionCrumb crumb = new SectionCrumb();
            String[] crumbPieces = part.split("--");
            crumb.setSectionIdentifier(crumbPieces[0]);
            crumb.setSectionId(crumbPieces[1]);
            if (!myCrumbs.contains(crumb)) {
                myCrumbs.add(crumb);
            }
        }
    }
    return myCrumbs;
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ArrayList(java.util.ArrayList)

Example 4 with SectionCrumb

use of org.broadleafcommerce.openadmin.dto.SectionCrumb in project BroadleafCommerce by BroadleafCommerce.

the class AdminBasicEntityController method viewAddEntityForm.

/**
 * Renders the modal form that is used to add a new parent level entity. Note that this form cannot render any
 * subcollections as operations on those collections require the parent level entity to first be saved and have
 * and id. Once the entity is initially saved, we will redirect the user to the normal manage entity screen where
 * they can then perform operations on sub collections.
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param entityType
 * @return the return view path
 * @throws Exception
 */
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String viewAddEntityForm(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @RequestParam(defaultValue = "") String entityType) throws Exception {
    String sectionKey = getSectionKey(pathVars);
    String sectionClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, null, null);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, sectionCrumbs, pathVars);
    ppr.setAddOperationInspect(true);
    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.
    if (StringUtils.isBlank(entityType)) {
        if (cmd.getPolymorphicEntities().getChildren().length == 0) {
            entityType = cmd.getPolymorphicEntities().getFullyQualifiedClassname();
        } else {
            entityType = getDefaultEntityType();
        }
    } else {
        entityType = URLDecoder.decode(entityType, "UTF-8");
    }
    EntityForm entityForm = formService.createEntityForm(cmd, sectionCrumbs);
    // We need to make sure that the ceiling entity is set to the interface and the specific entity type
    // is set to the type we're going to be creating.
    entityForm.setCeilingEntityClassname(cmd.getCeilingType());
    entityForm.setEntityType(entityType);
    // When we initially build the class metadata (and thus, the entity form), we had all of the possible
    // polymorphic fields built out. Now that we have a concrete entity type to render, we can remove the
    // fields that are not applicable for this given entity type.
    formService.removeNonApplicableFields(cmd, entityForm, entityType);
    modifyAddEntityForm(entityForm, pathVars);
    model.addAttribute("entityForm", entityForm);
    model.addAttribute("viewType", "modal/entityAdd");
    model.addAttribute("entityFriendlyName", cmd.getPolymorphicEntities().getFriendlyName());
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    model.addAttribute("modalHeaderType", ModalHeaderType.ADD_ENTITY.getType());
    setModelAttributes(model, sectionKey);
    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) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with SectionCrumb

use of org.broadleafcommerce.openadmin.dto.SectionCrumb in project BroadleafCommerce by BroadleafCommerce.

the class AdminBasicEntityController method getCollectionValueDetails.

@RequestMapping(value = "/{collectionField:.*}/details", method = RequestMethod.GET)
@ResponseBody
public Map<String, String> getCollectionValueDetails(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "collectionField") String collectionField, @RequestParam String ids, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
    String sectionKey = getSectionKey(pathVars);
    String sectionClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, null, null);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, requestParams, sectionCrumbs, pathVars);
    ClassMetadata mainMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    Property collectionProperty = mainMetadata.getPMap().get(collectionField);
    FieldMetadata md = collectionProperty.getMetadata();
    ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs);
    ppr.setStartIndex(getStartIndex(requestParams));
    ppr.setMaxIndex(getMaxIndex(requestParams));
    if (md instanceof BasicFieldMetadata) {
        String idProp = ((BasicFieldMetadata) md).getForeignKeyProperty();
        String displayProp = ((BasicFieldMetadata) md).getForeignKeyDisplayValueProperty();
        List<String> filterValues = BLCArrayUtils.asList(ids.split(FILTER_VALUE_SEPARATOR_REGEX));
        ppr.addFilterAndSortCriteria(new FilterAndSortCriteria(idProp, filterValues));
        DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
        Map<String, String> returnMap = new HashMap<>();
        for (Entity e : drs.getRecords()) {
            String id = e.getPMap().get(idProp).getValue();
            String disp = e.getPMap().get(displayProp).getDisplayValue();
            if (StringUtils.isBlank(disp)) {
                disp = e.getPMap().get(displayProp).getValue();
            }
            returnMap.put(id, disp);
        }
        return returnMap;
    }
    return null;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) Property(org.broadleafcommerce.openadmin.dto.Property) 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