Search in sources :

Example 1 with ClassTree

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

the class DynamicEntityDaoImpl method addClassToTree.

protected void addClassToTree(Class<?> clazz, ClassTree tree) {
    Class<?> testClass;
    try {
        testClass = Class.forName(tree.getFullyQualifiedClassname());
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    if (clazz.equals(testClass)) {
        return;
    }
    if (clazz.getSuperclass().equals(testClass)) {
        ClassTree myTree = new ClassTree(clazz.getName(), isExcludeClassFromPolymorphism(clazz));
        createClassTreeFromAnnotation(clazz, myTree);
        tree.setChildren(ArrayUtils.add(tree.getChildren(), myTree));
    } else {
        for (ClassTree child : tree.getChildren()) {
            addClassToTree(clazz, child);
        }
    }
}
Also used : ClassTree(org.broadleafcommerce.openadmin.dto.ClassTree)

Example 2 with ClassTree

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

the class PageTemplateCustomPersistenceHandler method inspect.

@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
    String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
    try {
        List<FieldGroup> fieldGroups = getFieldGroups(persistencePackage, dynamicEntityDao);
        ClassMetadata metadata = new ClassMetadata();
        metadata.setCeilingType(PageTemplate.class.getName());
        ClassTree entities = new ClassTree(PageTemplateImpl.class.getName());
        metadata.setPolymorphicEntities(entities);
        Property[] properties = dynamicFieldUtil.buildDynamicPropertyList(fieldGroups, PageTemplate.class);
        metadata.setProperties(properties);
        DynamicResultSet results = new DynamicResultSet(metadata);
        return results;
    } catch (Exception e) {
        throw new ServiceException("Unable to perform inspect for entity: " + ceilingEntityFullyQualifiedClassname, e);
    }
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) ServiceException(org.broadleafcommerce.common.exception.ServiceException) FieldGroup(org.broadleafcommerce.cms.field.domain.FieldGroup) PageTemplate(org.broadleafcommerce.cms.page.domain.PageTemplate) ClassTree(org.broadleafcommerce.openadmin.dto.ClassTree) PageTemplateImpl(org.broadleafcommerce.cms.page.domain.PageTemplateImpl) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException)

Example 3 with ClassTree

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

the class FormBuilderServiceImpl method populateEntityForm.

@Override
public void populateEntityForm(ClassMetadata cmd, Entity entity, Map<String, DynamicResultSet> collectionRecords, EntityForm ef, List<SectionCrumb> sectionCrumbs) throws ServiceException {
    // Get the form with values for this entity
    populateEntityForm(cmd, entity, ef, sectionCrumbs);
    // Attach the sub-collection list grids and specialty UI support
    for (Property p : cmd.getProperties()) {
        if (p.getMetadata() instanceof BasicFieldMetadata) {
            continue;
        }
        if (!ArrayUtils.contains(p.getMetadata().getAvailableToTypes(), entity.getType()[0])) {
            continue;
        }
        if (collectionRecords != null) {
            DynamicResultSet subCollectionEntities = collectionRecords.get(p.getName());
            String containingEntityId = entity.getPMap().get(ef.getIdProperty()).getValue();
            ListGrid listGrid = buildCollectionListGrid(containingEntityId, subCollectionEntities, p, ef.getSectionKey(), sectionCrumbs);
            CollectionMetadata md = ((CollectionMetadata) p.getMetadata());
            if (md instanceof BasicCollectionMetadata) {
                PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs);
                ClassMetadata collectionCmd = adminEntityService.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
                if (collectionCmd.getPolymorphicEntities().getChildren().length != 0) {
                    List<ClassTree> entityTypes = collectionCmd.getPolymorphicEntities().getCollapsedClassTrees();
                    ListGridActionGroup actionGroup = new ListGridActionGroup().withName("Add");
                    for (ClassTree entityType : entityTypes) {
                        ListGridAction ADD = new ListGridAction(ListGridAction.ADD).withButtonClass(AddMethodType.PERSIST_EMPTY == ((BasicCollectionMetadata) md).getAddMethodType() ? "sub-list-grid-add-empty" : "sub-list-grid-add").withActionTargetEntity(entityType.getFullyQualifiedClassname()).withUrlPostfix("/add").withIconClass("fa fa-plus").withDisplayText(BLCMessageUtils.getMessage(entityType.getFriendlyName()));
                        actionGroup.getListGridActions().add(0, ADD);
                    }
                    listGrid.addToolbarActionGroup(actionGroup);
                } else {
                    listGrid.getToolbarActions().add(0, AddMethodType.PERSIST_EMPTY == ((BasicCollectionMetadata) md).getAddMethodType() ? DefaultListGridActions.ADD_EMPTY : DefaultListGridActions.ADD);
                }
            } else {
                listGrid.getToolbarActions().add(0, DefaultListGridActions.ADD);
            }
            if (subCollectionEntities.getUnselectedTabMetadata().get(md.getTab()) != null) {
                ef.addListGrid(cmd, listGrid, md.getTab(), md.getTabOrder(), md.getGroup(), true);
            } else {
                ef.addListGrid(cmd, listGrid, md.getTab(), md.getTabOrder(), md.getGroup(), false);
            }
        }
    }
    if (CollectionUtils.isEmpty(ef.getActions())) {
        ef.addAction(DefaultEntityFormActions.SAVE);
    }
    addDeleteActionIfAllowed(ef, cmd, entity);
    setReadOnlyState(ef, cmd, entity);
    // check for fields that should be hidden based on annotations
    setVisibilityBasedOnShowIfFieldEquals(cmd, entity, ef);
    extensionManager.getProxy().modifyDetailEntityForm(ef);
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) ListGridAction(org.broadleafcommerce.openadmin.web.form.component.ListGridAction) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata) CollectionMetadata(org.broadleafcommerce.openadmin.dto.CollectionMetadata) ClassTree(org.broadleafcommerce.openadmin.dto.ClassTree) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) ListGridActionGroup(org.broadleafcommerce.openadmin.web.form.component.ListGridActionGroup) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 4 with ClassTree

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

the class CriteriaTranslatorImpl method determineRoot.

/**
 * Determines the appropriate entity in this current class tree to use as the ceiling entity for the query. Because
 * we filter with AND instead of OR, we throw an exception if an attempt to utilize properties from mutually exclusive
 * class trees is made as it would be impossible for such a query to return results.
 *
 * @param dynamicEntityDao
 * @param ceilingMarker
 * @param filterMappings
 * @return the root class
 * @throws NoPossibleResultsException
 */
@SuppressWarnings("unchecked")
protected Class<Serializable> determineRoot(DynamicEntityDao dynamicEntityDao, Class<Serializable> ceilingMarker, List<FilterMapping> filterMappings) throws NoPossibleResultsException {
    Class<?>[] polyEntities = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(ceilingMarker);
    ClassTree root = dynamicEntityDao.getClassTree(polyEntities);
    List<ClassTree> parents = new ArrayList<ClassTree>();
    for (FilterMapping mapping : filterMappings) {
        if (mapping.getInheritedFromClass() != null) {
            root = determineRootInternal(root, parents, mapping.getInheritedFromClass());
            if (root == null) {
                throw new NoPossibleResultsException("AND filter on different class hierarchies produces no results");
            }
        }
    }
    for (Class<?> clazz : polyEntities) {
        if (clazz.getName().equals(root.getFullyQualifiedClassname())) {
            return (Class<Serializable>) clazz;
        }
    }
    throw new IllegalStateException("Class didn't match - this should not occur");
}
Also used : NoPossibleResultsException(org.broadleafcommerce.common.exception.NoPossibleResultsException) ClassTree(org.broadleafcommerce.openadmin.dto.ClassTree) ArrayList(java.util.ArrayList)

Example 5 with ClassTree

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

Aggregations

ClassTree (org.broadleafcommerce.openadmin.dto.ClassTree)9 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)5 Property (org.broadleafcommerce.openadmin.dto.Property)5 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)3 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)3 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)2 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)2 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)2 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)2 ValidationException (org.broadleafcommerce.openadmin.server.service.ValidationException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 FieldGroup (org.broadleafcommerce.cms.field.domain.FieldGroup)1 PageTemplate (org.broadleafcommerce.cms.page.domain.PageTemplate)1 PageTemplateImpl (org.broadleafcommerce.cms.page.domain.PageTemplateImpl)1 StructuredContentType (org.broadleafcommerce.cms.structure.domain.StructuredContentType)1 StructuredContentTypeImpl (org.broadleafcommerce.cms.structure.domain.StructuredContentTypeImpl)1 NoPossibleResultsException (org.broadleafcommerce.common.exception.NoPossibleResultsException)1 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)1