Search in sources :

Example 31 with ClassMetadata

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

the class CustomPersistenceHandlerAdapter method getResultSet.

/**
 * This is a helper method that can be invoked as the last step in a custom inspect phase. It will assemble the
 * appropriate DynamicResultSet from the given parameters.
 */
protected DynamicResultSet getResultSet(PersistencePackage persistencePackage, InspectHelper helper, Map<String, FieldMetadata> metadata) throws ServiceException {
    String entityName = persistencePackage.getCeilingEntityFullyQualifiedClassname();
    try {
        if (helper instanceof PersistenceManager) {
            Class<?>[] entities = ((PersistenceManager) helper).getPolymorphicEntities(entityName);
            Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
            allMergedProperties.put(MergedPropertyType.PRIMARY, metadata);
            ClassMetadata mergedMetadata = helper.buildClassMetadata(entities, persistencePackage, allMergedProperties);
            DynamicResultSet results = new DynamicResultSet(mergedMetadata);
            return results;
        }
    } catch (ClassNotFoundException e) {
        throw new ServiceException(e);
    }
    return new DynamicResultSet();
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistenceManager(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceManager) HashMap(java.util.HashMap) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) ServiceException(org.broadleafcommerce.common.exception.ServiceException) HashMap(java.util.HashMap) Map(java.util.Map) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 32 with ClassMetadata

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

the class SkuBundleItemCustomPersistenceHandler method inspect.

@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
        // retrieve the default properties for Inventory
        Map<String, FieldMetadata> properties = helper.getSimpleMergedProperties(SkuBundleItem.class.getName(), persistencePerspective);
        // add in the consolidated product options field
        FieldMetadata options = skuPersistenceHandler.createConsolidatedOptionField(SkuBundleItemImpl.class);
        options.setOrder(3);
        properties.put(SkuCustomPersistenceHandler.CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME, options);
        allMergedProperties.put(MergedPropertyType.PRIMARY, properties);
        Class<?>[] entityClasses = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(SkuBundleItem.class);
        ClassMetadata mergedMetadata = helper.buildClassMetadata(entityClasses, persistencePackage, allMergedProperties);
        return new DynamicResultSet(mergedMetadata, null, null);
    } catch (Exception e) {
        String className = persistencePackage.getCeilingEntityFullyQualifiedClassname();
        ServiceException ex = new ServiceException("Unable to retrieve inspection results for " + className, e);
        LOG.error("Unable to retrieve inspection results for " + className, ex);
        throw ex;
    }
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) HashMap(java.util.HashMap) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) ServiceException(org.broadleafcommerce.common.exception.ServiceException) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) SkuBundleItem(org.broadleafcommerce.core.catalog.domain.SkuBundleItem) HashMap(java.util.HashMap) Map(java.util.Map) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 33 with ClassMetadata

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

the class CustomerPaymentCustomPersistenceHandler method inspect.

@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
    Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
    PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
    Map<String, FieldMetadata> properties = helper.getSimpleMergedProperties(CustomerPayment.class.getName(), persistencePerspective);
    // Hide "Payment Gateway Type" column & create "Saved Payment Info" ListGrid column
    FieldMetadata paymentGatewayType = properties.get("paymentGatewayType");
    if (paymentGatewayType != null) {
        ((BasicFieldMetadata) paymentGatewayType).setProminent(false);
    }
    BasicFieldMetadata savedPaymentInfo = new BasicFieldMetadata();
    savedPaymentInfo.setName(SAVED_PAYMENT_INFO);
    savedPaymentInfo.setFriendlyName("CustomerPaymentImpl_Saved_Payment_Info");
    savedPaymentInfo.setFieldType(SupportedFieldType.STRING);
    savedPaymentInfo.setInheritedFromType(CustomerPaymentImpl.class.getName());
    savedPaymentInfo.setAvailableToTypes(new String[] { CustomerPaymentImpl.class.getName() });
    savedPaymentInfo.setProminent(true);
    savedPaymentInfo.setGridOrder(2000);
    savedPaymentInfo.setReadOnly(true);
    savedPaymentInfo.setVisibility(VisibilityEnum.FORM_HIDDEN);
    properties.put(SAVED_PAYMENT_INFO, savedPaymentInfo);
    allMergedProperties.put(MergedPropertyType.PRIMARY, properties);
    Class<?>[] entityClasses = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(CustomerPayment.class);
    ClassMetadata mergedMetadata = helper.buildClassMetadata(entityClasses, persistencePackage, allMergedProperties);
    return new DynamicResultSet(mergedMetadata, null, null);
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) CustomerPayment(org.broadleafcommerce.profile.core.domain.CustomerPayment) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) CustomerPaymentImpl(org.broadleafcommerce.profile.core.domain.CustomerPaymentImpl) HashMap(java.util.HashMap) Map(java.util.Map) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 34 with ClassMetadata

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

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

ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)52 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)36 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)32 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)26 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)26 Property (org.broadleafcommerce.openadmin.dto.Property)25 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)22 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)21 Entity (org.broadleafcommerce.openadmin.dto.Entity)19 HashMap (java.util.HashMap)16 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)11 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)11 Map (java.util.Map)10 EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)10 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)9 ArrayList (java.util.ArrayList)8 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)8 PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)8 MergedPropertyType (org.broadleafcommerce.openadmin.dto.MergedPropertyType)7 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)7