Search in sources :

Example 1 with PersistencePackageRequest

use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest 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 PersistencePackageRequest

use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest 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 PersistencePackageRequest

use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.

the class AdminEntityServiceImpl method updateSubCollectionEntity.

@Override
public PersistenceResponse updateSubCollectionEntity(EntityForm entityForm, ClassMetadata mainMetadata, Property field, Entity parentEntity, String collectionItemId, String alternateId, List<SectionCrumb> sectionCrumbs) throws ServiceException, ClassNotFoundException {
    List<Property> properties = getPropertiesFromEntityForm(entityForm);
    FieldMetadata md = field.getMetadata();
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs).withEntity(new Entity());
    if (md instanceof BasicCollectionMetadata) {
        BasicCollectionMetadata fmd = (BasicCollectionMetadata) md;
        ppr.setCeilingEntityClassname(fmd.getCollectionCeilingEntity());
        ppr.getEntity().setType(new String[] { fmd.getCollectionCeilingEntity() });
        Property fp = new Property();
        fp.setName(ppr.getForeignKey().getManyToField());
        fp.setValue(getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName()));
        if (!properties.contains(fp)) {
            properties.add(fp);
        }
    } else if (md instanceof AdornedTargetCollectionMetadata) {
        String adornedTargetEntityClassname = ppr.getAdornedList().getAdornedTargetEntityClassname();
        ppr.setCeilingEntityClassname(adornedTargetEntityClassname);
        ppr.getEntity().setType(new String[] { adornedTargetEntityClassname });
        for (Property property : properties) {
            if (property.getName().equals(ppr.getAdornedList().getLinkedObjectPath() + "." + ppr.getAdornedList().getLinkedIdProperty())) {
                break;
            }
        }
        if (!StringUtils.isEmpty(alternateId)) {
            Property p = new Property();
            p.setName(BasicPersistenceModule.ALTERNATE_ID_PROPERTY);
            p.setValue(alternateId);
            if (!properties.contains(p)) {
                properties.add(p);
            }
        }
    } else if (md instanceof MapMetadata) {
        ppr.getEntity().setType(new String[] { entityForm.getEntityType() });
        Property p = new Property();
        p.setName("symbolicId");
        p.setValue(getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName()));
        properties.add(p);
    } else {
        throw new IllegalArgumentException(String.format("The specified field [%s] for class [%s] was" + " not a collection field.", field.getName(), mainMetadata.getCeilingType()));
    }
    String sectionField = field.getName();
    if (sectionField.contains(".")) {
        sectionField = sectionField.substring(0, sectionField.lastIndexOf("."));
    }
    ppr.setSectionEntityField(sectionField);
    Property parentNameProp = parentEntity.getPMap().get(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY);
    if (parentNameProp != null) {
        ppr.setRequestingEntityName(parentNameProp.getValue());
    }
    Property p = new Property();
    p.setName(entityForm.getIdProperty());
    p.setValue(collectionItemId);
    if (!properties.contains(p)) {
        properties.add(p);
    }
    Property[] propArr = new Property[properties.size()];
    properties.toArray(propArr);
    ppr.getEntity().setProperties(propArr);
    return update(ppr);
}
Also used : AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)

Example 4 with PersistencePackageRequest

use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.

the class AdminEntityServiceImpl method addEntity.

@Override
public PersistenceResponse addEntity(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumb) throws ServiceException {
    PersistencePackageRequest ppr = getRequestForEntityForm(entityForm, customCriteria, sectionCrumb);
    // based on the criteria specific in the PersistencePackage.
    for (Entry<String, EntityForm> entry : entityForm.getDynamicForms().entrySet()) {
        DynamicEntityFormInfo info = entityForm.getDynamicFormInfo(entry.getKey());
        if (info.getCustomCriteriaOverride() != null) {
            customCriteria = info.getCustomCriteriaOverride();
        } else {
            String propertyName = info.getPropertyName();
            String propertyValue;
            if (entityForm.getFields().containsKey(propertyName)) {
                propertyValue = entityForm.findField(propertyName).getValue();
            } else {
                propertyValue = info.getPropertyValue();
            }
            customCriteria = new String[] { info.getCriteriaName(), entityForm.getId(), propertyName, propertyValue };
        }
        PersistencePackageRequest subRequest = getRequestForEntityForm(entry.getValue(), customCriteria, sectionCrumb);
        ppr.addSubRequest(info.getPropertyName(), subRequest);
    }
    return add(ppr);
}
Also used : EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) DynamicEntityFormInfo(org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo)

Example 5 with PersistencePackageRequest

use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.

the class AdminEntityServiceImpl method getAdvancedCollectionRecord.

@Override
public PersistenceResponse getAdvancedCollectionRecord(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, String collectionItemId, List<SectionCrumb> sectionCrumbs, String alternateId, String[] customCriteria) throws ServiceException {
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(collectionProperty.getMetadata(), sectionCrumbs);
    ppr.addCustomCriteria(customCriteria);
    FieldMetadata md = collectionProperty.getMetadata();
    String containingEntityId = getContextSpecificRelationshipId(containingClassMetadata, containingEntity, collectionProperty.getName());
    ppr.setSectionEntityField(collectionProperty.getName());
    PersistenceResponse response;
    if (md instanceof AdornedTargetCollectionMetadata) {
        FilterAndSortCriteria fasc = new FilterAndSortCriteria(ppr.getAdornedList().getCollectionFieldName());
        fasc.setFilterValue(containingEntityId);
        ppr.addFilterAndSortCriteria(fasc);
        fasc = new FilterAndSortCriteria(ppr.getAdornedList().getCollectionFieldName() + "Target");
        fasc.setFilterValue(collectionItemId);
        ppr.addFilterAndSortCriteria(fasc);
        if (!StringUtils.isEmpty(alternateId)) {
            fasc = new FilterAndSortCriteria(ppr.getAdornedList().getIdProperty());
            fasc.setFilterValue(alternateId);
            ppr.addFilterAndSortCriteria(fasc);
        }
        response = fetch(ppr);
        Entity[] entities = response.getDynamicResultSet().getRecords();
        if (ArrayUtils.isEmpty(entities)) {
            throw new EntityNotFoundException();
        }
    } else if (md instanceof MapMetadata) {
        MapMetadata mmd = (MapMetadata) md;
        FilterAndSortCriteria fasc = new FilterAndSortCriteria(ppr.getForeignKey().getManyToField());
        fasc.setFilterValue(containingEntityId);
        ppr.addFilterAndSortCriteria(fasc);
        response = fetch(ppr);
        Entity[] entities = response.getDynamicResultSet().getRecords();
        for (Entity e : entities) {
            String idProperty = getIdProperty(containingClassMetadata);
            if (mmd.isSimpleValue()) {
                idProperty = "key";
            }
            Property p = e.getPMap().get(idProperty);
            if (p.getValue().equals(collectionItemId)) {
                response.setEntity(e);
                break;
            }
        }
    } else {
        throw new IllegalArgumentException(String.format("The specified field [%s] for class [%s] was not an " + "advanced collection field.", collectionProperty.getName(), containingClassMetadata.getCeilingType()));
    }
    return response;
}
Also used : AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) EntityNotFoundException(org.broadleafcommerce.openadmin.exception.EntityNotFoundException) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)

Aggregations

PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)48 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)36 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)29 Property (org.broadleafcommerce.openadmin.dto.Property)26 Entity (org.broadleafcommerce.openadmin.dto.Entity)24 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)20 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)19 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)16 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)13 EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)12 ArrayList (java.util.ArrayList)10 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)10 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)10 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)9 MapMetadata (org.broadleafcommerce.openadmin.dto.MapMetadata)8 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)7 PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)7 HashMap (java.util.HashMap)6