Search in sources :

Example 36 with FieldMetadata

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

the class TimeDTOCustomPersistenceHandler method inspect.

@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
    String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
    try {
        Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
        Map<String, FieldMetadata> mergedProperties = dynamicEntityDao.getSimpleMergedProperties(ceilingEntityFullyQualifiedClassname, persistencePackage.getPersistencePerspective());
        allMergedProperties.put(MergedPropertyType.PRIMARY, mergedProperties);
        ClassMetadata mergedMetadata = helper.buildClassMetadata(new Class<?>[] { Class.forName(ceilingEntityFullyQualifiedClassname) }, persistencePackage, allMergedProperties);
        DynamicResultSet results = new DynamicResultSet(mergedMetadata);
        return results;
    } catch (Exception e) {
        ServiceException ex = new ServiceException("Unable to retrieve inspection results for " + persistencePackage.getCeilingEntityFullyQualifiedClassname(), e);
        throw ex;
    }
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) ServiceException(org.broadleafcommerce.common.exception.ServiceException) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 37 with FieldMetadata

use of org.broadleafcommerce.openadmin.dto.FieldMetadata 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 38 with FieldMetadata

use of org.broadleafcommerce.openadmin.dto.FieldMetadata 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 39 with FieldMetadata

use of org.broadleafcommerce.openadmin.dto.FieldMetadata 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)

Example 40 with FieldMetadata

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

the class AdminEntityServiceImpl method getAllRecordsForAllSubCollections.

@Override
public Map<String, DynamicResultSet> getAllRecordsForAllSubCollections(ClassMetadata cmd, Entity containingEntity, List<SectionCrumb> sectionCrumb) throws ServiceException {
    Map<String, DynamicResultSet> map = new HashMap<>();
    for (Property p : cmd.getProperties()) {
        FieldMetadata fieldMetadata = p.getMetadata();
        boolean fieldAvailable = ArrayUtils.contains(fieldMetadata.getAvailableToTypes(), containingEntity.getType()[0]);
        if (fieldAvailable && fieldMetadata instanceof CollectionMetadata) {
            FetchPageRequest pageRequest = new FetchPageRequest().withPageSize(Integer.MAX_VALUE);
            PersistenceResponse resp = getPagedRecordsForCollection(cmd, containingEntity, p, null, pageRequest, null, sectionCrumb);
            map.put(p.getName(), resp.getDynamicResultSet());
        }
    }
    return map;
}
Also used : BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) CollectionMetadata(org.broadleafcommerce.openadmin.dto.CollectionMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) FetchPageRequest(org.broadleafcommerce.openadmin.server.domain.FetchPageRequest) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property)

Aggregations

FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)114 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)80 Entity (org.broadleafcommerce.openadmin.dto.Entity)51 ServiceException (org.broadleafcommerce.common.exception.ServiceException)46 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)44 HashMap (java.util.HashMap)39 Property (org.broadleafcommerce.openadmin.dto.Property)38 Map (java.util.Map)28 ArrayList (java.util.ArrayList)23 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)22 Field (java.lang.reflect.Field)19 SecurityServiceException (org.broadleafcommerce.common.exception.SecurityServiceException)19 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)19 Serializable (java.io.Serializable)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)18 CriteriaTransferObject (org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)17 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)15 FieldMetadataOverride (org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride)15 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)13