Search in sources :

Example 6 with AdornedTargetList

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

the class AdornedTargetListPersistenceModule method remove.

@Override
public void remove(PersistencePackage persistencePackage) throws ServiceException {
    String[] customCriteria = persistencePackage.getCustomCriteria();
    if (customCriteria != null && customCriteria.length > 0) {
        LOG.warn("custom persistence handlers and custom criteria not supported for remove types other than BASIC");
    }
    PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
    Entity entity = persistencePackage.getEntity();
    try {
        AdornedTargetList adornedTargetList = (AdornedTargetList) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST);
        if (!adornedTargetList.getMutable()) {
            throw new SecurityServiceException("Field is not mutable");
        }
        Class<?>[] entities = persistenceManager.getPolymorphicEntities(adornedTargetList.getAdornedTargetEntityClassname());
        Map<String, FieldMetadata> mergedProperties = persistenceManager.getDynamicEntityDao().getMergedProperties(adornedTargetList.getAdornedTargetEntityClassname(), entities, null, new String[] {}, new ForeignKey[] {}, MergedPropertyType.ADORNEDTARGETLIST, false, new String[] {}, new String[] {}, null, "");
        CriteriaTransferObject ctoInserted = new CriteriaTransferObject();
        FilterAndSortCriteria filterCriteriaInsertedLinked = ctoInserted.get(adornedTargetList.getCollectionFieldName());
        filterCriteriaInsertedLinked.setFilterValue(entity.findProperty(adornedTargetList.getLinkedObjectPath() + "." + adornedTargetList.getLinkedIdProperty()).getValue());
        FilterAndSortCriteria filterCriteriaInsertedTarget = ctoInserted.get(adornedTargetList.getCollectionFieldName() + "Target");
        filterCriteriaInsertedTarget.setFilterValue(entity.findProperty(adornedTargetList.getTargetObjectPath() + "." + adornedTargetList.getTargetIdProperty()).getValue());
        List<FilterMapping> filterMappings = getAdornedTargetFilterMappings(persistencePerspective, ctoInserted, mergedProperties, adornedTargetList);
        List<Serializable> recordsInserted = getPersistentRecords(adornedTargetList.getAdornedTargetEntityClassname(), filterMappings, ctoInserted.getFirstResult(), ctoInserted.getMaxResults());
        Assert.isTrue(!CollectionUtils.isEmpty(recordsInserted), "Entity not found");
        persistenceManager.getDynamicEntityDao().remove(recordsInserted.get(0));
    } catch (Exception e) {
        throw new ServiceException("Problem removing entity : " + e.getMessage(), e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) SecurityServiceException(org.broadleafcommerce.common.exception.SecurityServiceException) Serializable(java.io.Serializable) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FilterMapping(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping) ServiceException(org.broadleafcommerce.common.exception.ServiceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecurityServiceException(org.broadleafcommerce.common.exception.SecurityServiceException) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) SecurityServiceException(org.broadleafcommerce.common.exception.SecurityServiceException) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) AdornedTargetList(org.broadleafcommerce.openadmin.dto.AdornedTargetList) CriteriaTransferObject(org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)

Example 7 with AdornedTargetList

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

the class AdminEntityServiceImpl method removeSubCollectionEntity.

@Override
public PersistenceResponse removeSubCollectionEntity(ClassMetadata mainMetadata, Property field, Entity parentEntity, String itemId, String alternateId, String priorKey, List<SectionCrumb> sectionCrumbs) throws ServiceException {
    List<Property> properties = new ArrayList<Property>();
    Property p;
    String parentId = getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName());
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(field.getMetadata(), sectionCrumbs).withEntity(new Entity());
    if (field.getMetadata() instanceof BasicCollectionMetadata) {
        BasicCollectionMetadata fmd = (BasicCollectionMetadata) field.getMetadata();
        p = new Property();
        p.setName("id");
        p.setValue(itemId);
        properties.add(p);
        p = new Property();
        p.setName(ppr.getForeignKey().getManyToField());
        p.setValue(parentId);
        properties.add(p);
        ppr.getEntity().setType(new String[] { fmd.getCollectionCeilingEntity() });
    } else if (field.getMetadata() instanceof AdornedTargetCollectionMetadata) {
        AdornedTargetList adornedList = ppr.getAdornedList();
        p = new Property();
        p.setName(adornedList.getLinkedObjectPath() + "." + adornedList.getLinkedIdProperty());
        p.setValue(parentId);
        properties.add(p);
        p = new Property();
        p.setName(adornedList.getTargetObjectPath() + "." + adornedList.getTargetIdProperty());
        p.setValue(itemId);
        properties.add(p);
        if (!StringUtils.isEmpty(alternateId)) {
            p = new Property();
            p.setName(BasicPersistenceModule.ALTERNATE_ID_PROPERTY);
            p.setValue(alternateId);
            properties.add(p);
        }
        ppr.getEntity().setType(new String[] { adornedList.getAdornedTargetEntityClassname() });
    } else if (field.getMetadata() instanceof MapMetadata) {
        MapMetadata fmd = (MapMetadata) field.getMetadata();
        p = new Property();
        p.setName("id");
        p.setValue(itemId);
        properties.add(p);
        p = new Property();
        p.setName("symbolicId");
        p.setValue(getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName()));
        properties.add(p);
        p = new Property();
        p.setName("priorKey");
        p.setValue(priorKey);
        properties.add(p);
        MapStructure mapStructure = ppr.getMapStructure();
        p = new Property();
        p.setName(mapStructure.getKeyPropertyName());
        p.setValue(itemId);
        properties.add(p);
        ppr.getEntity().setType(new String[] { fmd.getTargetClass() });
    }
    ppr.setCeilingEntityClassname(ppr.getEntity().getType()[0]);
    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[] propArr = new Property[properties.size()];
    properties.toArray(propArr);
    ppr.getEntity().setProperties(propArr);
    return remove(ppr);
}
Also used : MapStructure(org.broadleafcommerce.openadmin.dto.MapStructure) AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) ArrayList(java.util.ArrayList) 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) AdornedTargetList(org.broadleafcommerce.openadmin.dto.AdornedTargetList) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)

Example 8 with AdornedTargetList

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

the class ArchiveStatusPersistenceEventHandler method preFetch.

@Override
public PersistenceManagerEventHandlerResponse preFetch(PersistenceManager persistenceManager, PersistencePackage persistencePackage, CriteriaTransferObject cto) throws ServiceException {
    try {
        Class<?>[] entityClasses = persistenceManager.getDynamicEntityDao().getAllPolymorphicEntitiesFromCeiling(Class.forName(persistencePackage.getCeilingEntityFullyQualifiedClassname()));
        AtomicBoolean isArchivable = new AtomicBoolean(false);
        for (Class<?> entity : entityClasses) {
            AtomicBoolean test = new AtomicBoolean(true);
            extensionManager.getProxy().isArchivable(entity, test);
            if (!test.get()) {
                isArchivable.set(false);
                break;
            }
            if (Status.class.isAssignableFrom(entity)) {
                isArchivable.set(true);
            }
        }
        if (isArchivable.get() && !persistencePackage.getPersistencePerspective().getShowArchivedFields()) {
            String targetPropertyName = "archiveStatus.archived";
            if (persistencePackage.getPersistencePerspectiveItems().containsKey(PersistencePerspectiveItemType.ADORNEDTARGETLIST)) {
                AdornedTargetList atl = (AdornedTargetList) persistencePackage.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST);
                targetPropertyName = atl.getTargetObjectPath() + "." + targetPropertyName;
            }
            FilterMapping filterMapping = new FilterMapping().withFieldPath(new FieldPath().withTargetProperty(targetPropertyName)).withDirectFilterValues(new EmptyFilterValues()).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider<Character, Character>() {

                @Override
                public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path<Character> explicitPath, List<Character> directValues) {
                    return builder.or(builder.equal(explicitPath, 'N'), builder.isNull(explicitPath));
                }
            }));
            cto.getAdditionalFilterMappings().add(filterMapping);
        }
        return new PersistenceManagerEventHandlerResponse().withStatus(PersistenceManagerEventHandlerResponse.PersistenceManagerEventHandlerResponseStatus.HANDLED);
    } catch (ClassNotFoundException e) {
        LOG.error("Could not find the class " + persistencePackage.getCeilingEntityFullyQualifiedClassname() + " to " + "compute polymorphic entity types for. Assuming that the entity is not archivable");
        return new PersistenceManagerEventHandlerResponse().withStatus(PersistenceManagerEventHandlerResponse.PersistenceManagerEventHandlerResponseStatus.NOT_HANDLED);
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) FieldPath(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPath) Path(javax.persistence.criteria.Path) FieldPath(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPath) FilterMapping(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping) From(javax.persistence.criteria.From) FieldPathBuilder(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EmptyFilterValues(org.broadleafcommerce.openadmin.server.service.persistence.module.EmptyFilterValues) Restriction(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.Restriction) PredicateProvider(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.predicate.PredicateProvider) AdornedTargetList(org.broadleafcommerce.openadmin.dto.AdornedTargetList) List(java.util.List) AdornedTargetList(org.broadleafcommerce.openadmin.dto.AdornedTargetList)

Example 9 with AdornedTargetList

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

the class FormBuilderServiceImpl method buildSelectizeCollectionInfo.

@Override
public Map<String, Object> buildSelectizeCollectionInfo(String containingEntityId, DynamicResultSet drs, Property field, String sectionKey, List<SectionCrumb> sectionCrumbs) throws ServiceException {
    FieldMetadata fmd = field.getMetadata();
    // Get the class metadata for this particular field
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(fmd, sectionCrumbs);
    if (field != null) {
        ppr.setSectionEntityField(field.getName());
    }
    ClassMetadata cmd = adminEntityService.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    Map<String, Object> result = constructSelectizeOptionMap(drs, cmd);
    AdornedTargetList adornedList = ppr.getAdornedList();
    if (adornedList != null && adornedList.getLinkedObjectPath() != null && adornedList.getTargetObjectPath() != null && adornedList.getLinkedIdProperty() != null && adornedList.getTargetIdProperty() != null) {
        result.put("linkedObjectPath", adornedList.getLinkedObjectPath() + "." + adornedList.getLinkedIdProperty());
        result.put("linkedObjectId", containingEntityId);
        result.put("targetObjectPath", adornedList.getTargetObjectPath() + "." + adornedList.getTargetIdProperty());
    }
    return result;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) JSONObject(org.codehaus.jettison.json.JSONObject) AdornedTargetList(org.broadleafcommerce.openadmin.dto.AdornedTargetList)

Example 10 with AdornedTargetList

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

the class FormBuilderServiceImpl method buildCollectionListGrid.

@Override
public ListGrid buildCollectionListGrid(String containingEntityId, DynamicResultSet drs, Property field, String sectionKey, List<SectionCrumb> sectionCrumbs) throws ServiceException {
    FieldMetadata fmd = field.getMetadata();
    // Get the class metadata for this particular field
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(fmd, sectionCrumbs);
    if (field != null) {
        ppr.setSectionEntityField(field.getName());
    }
    ClassMetadata cmd = adminEntityService.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    List<Field> headerFields = new ArrayList<>();
    ListGrid.Type type = null;
    boolean editable = false;
    boolean sortable = false;
    boolean readOnly = false;
    boolean hideIdColumn = false;
    boolean canFilterAndSort = true;
    boolean modalSingleSelectable = false;
    boolean modalMultiSelectable = false;
    boolean selectize = false;
    boolean isMedia = false;
    boolean isLookup = false;
    String sortProperty = null;
    FieldWrapper wrapper = new FieldWrapper();
    ArrayList<FieldDTO> defaultWrapperFields = new ArrayList<>();
    String idProperty = "id";
    for (Property property : cmd.getProperties()) {
        if (property.getMetadata() instanceof BasicFieldMetadata && SupportedFieldType.ID == ((BasicFieldMetadata) property.getMetadata()).getFieldType() && // make sure it's a property for this entity - not an association
        !property.getName().contains(".")) {
            idProperty = property.getName();
            break;
        }
    }
    // kind of field this is.
    if (fmd instanceof BasicFieldMetadata) {
        readOnly = ((BasicFieldMetadata) fmd).getReadOnly();
        modalSingleSelectable = true;
        for (Property p : cmd.getProperties()) {
            if (p.getMetadata() instanceof BasicFieldMetadata) {
                BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
                if (SupportedFieldType.ID.equals(md.getFieldType())) {
                    idProperty = md.getName();
                }
                if (md.isProminent() != null && md.isProminent() && !ArrayUtils.contains(getGridHiddenVisibilities(), md.getVisibility())) {
                    Field hf = createHeaderField(p, md);
                    headerFields.add(hf);
                    defaultWrapperFields.add(constructFieldDTOFromFieldData(hf, md));
                }
                if (md.getIsFilter() != null && md.getIsFilter()) {
                    Field f = createHeaderField(p, md);
                    wrapper.getFields().add(constructFieldDTOFromFieldData(f, md));
                }
            }
        }
        type = ListGrid.Type.TO_ONE;
    } else if (fmd instanceof BasicCollectionMetadata) {
        BasicCollectionMetadata bcm = (BasicCollectionMetadata) fmd;
        readOnly = !bcm.isMutable();
        if (AddMethodType.LOOKUP.equals(bcm.getAddMethodType())) {
            isLookup = true;
        }
        if (AddMethodType.SELECTIZE_LOOKUP.equals(bcm.getAddMethodType())) {
            Property p = cmd.getPMap().get(bcm.getSelectizeVisibleField());
            if (p != null) {
                BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
                Field hf = createHeaderField(p, md);
                headerFields.add(hf);
                wrapper.getFields().add(constructFieldDTOFromFieldData(hf, md));
            }
        } else {
            for (Property p : cmd.getProperties()) {
                if (p.getMetadata() instanceof BasicFieldMetadata) {
                    BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
                    if (md.isProminent() != null && md.isProminent() && !ArrayUtils.contains(getGridHiddenVisibilities(), md.getVisibility())) {
                        Field hf = createHeaderField(p, md);
                        headerFields.add(hf);
                        defaultWrapperFields.add(constructFieldDTOFromFieldData(hf, md));
                    }
                    if (md.getIsFilter() != null && md.getIsFilter()) {
                        Field f = createHeaderField(p, md);
                        wrapper.getFields().add(constructFieldDTOFromFieldData(f, md));
                    }
                }
            }
        }
        type = ListGrid.Type.BASIC;
        if (AddMethodType.PERSIST.equals(bcm.getAddMethodType()) || AddMethodType.PERSIST_EMPTY.equals(bcm.getAddMethodType())) {
            editable = true;
        } else if (AddMethodType.SELECTIZE_LOOKUP.equals(bcm.getAddMethodType())) {
            selectize = true;
            modalSingleSelectable = true;
        } else {
            modalSingleSelectable = true;
        }
        sortable = StringUtils.isNotBlank(bcm.getSortProperty());
        if (sortable) {
            sortProperty = bcm.getSortProperty();
        }
    } else if (fmd instanceof AdornedTargetCollectionMetadata) {
        modalSingleSelectable = true;
        readOnly = !((AdornedTargetCollectionMetadata) fmd).isMutable();
        AdornedTargetCollectionMetadata atcmd = (AdornedTargetCollectionMetadata) fmd;
        if (AdornedTargetAddMethodType.LOOKUP.equals(atcmd.getAdornedTargetAddMethodType())) {
            isLookup = true;
        }
        if (AdornedTargetAddMethodType.SELECTIZE_LOOKUP.equals(atcmd.getAdornedTargetAddMethodType())) {
            selectize = true;
            Property p = cmd.getPMap().get(atcmd.getSelectizeVisibleField());
            if (p != null) {
                BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
                Field hf = createHeaderField(p, md);
                headerFields.add(hf);
                wrapper.getFields().add(constructFieldDTOFromFieldData(hf, md));
            }
        } else {
            for (String fieldName : atcmd.getGridVisibleFields()) {
                Property p = cmd.getPMap().get(fieldName);
                if (p != null) {
                    BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
                    Field hf = createHeaderField(p, md);
                    headerFields.add(hf);
                    wrapper.getFields().add(constructFieldDTOFromFieldData(hf, md));
                }
            }
        }
        type = ListGrid.Type.ADORNED;
        if (atcmd.getMaintainedAdornedTargetFields().length > 0) {
            editable = true;
        }
        AdornedTargetList adornedList = (AdornedTargetList) atcmd.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST);
        sortable = StringUtils.isNotBlank(adornedList.getSortField());
        if (sortable) {
            sortProperty = adornedList.getSortField();
        }
    } else if (fmd instanceof MapMetadata) {
        readOnly = !((MapMetadata) fmd).isMutable();
        MapMetadata mmd = (MapMetadata) fmd;
        Property p2 = cmd.getPMap().get("key");
        BasicFieldMetadata keyMd = (BasicFieldMetadata) p2.getMetadata();
        keyMd.setFriendlyName(getMapKeyFriendlyName(p2));
        Field hf = createHeaderField(p2, keyMd);
        headerFields.add(hf);
        wrapper.getFields().add(constructFieldDTOFromFieldData(hf, keyMd));
        if (mmd.isSimpleValue()) {
            Property valueProperty = cmd.getPMap().get("value");
            BasicFieldMetadata valueMd = (BasicFieldMetadata) valueProperty.getMetadata();
            valueMd.setFriendlyName("Value");
            hf = createHeaderField(valueProperty, valueMd);
            headerFields.add(hf);
            wrapper.getFields().add(constructFieldDTOFromFieldData(hf, valueMd));
            idProperty = "key";
            hideIdColumn = true;
        } else {
            for (Property p : cmd.getProperties()) {
                if (p.getMetadata() instanceof BasicFieldMetadata) {
                    BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
                    String valueClassName = mmd.getValueClassName();
                    if (!StringUtils.isEmpty(mmd.getToOneTargetProperty())) {
                        Class<?> clazz;
                        try {
                            clazz = Class.forName(mmd.getValueClassName());
                        } catch (ClassNotFoundException e) {
                            throw ExceptionHelper.refineException(e);
                        }
                        java.lang.reflect.Field nestedField = FieldManager.getSingleField(clazz, mmd.getToOneTargetProperty());
                        ManyToOne manyToOne = nestedField.getAnnotation(ManyToOne.class);
                        if (manyToOne != null && !manyToOne.targetEntity().getName().equals(void.class.getName())) {
                            valueClassName = manyToOne.targetEntity().getName();
                        } else {
                            OneToOne oneToOne = nestedField.getAnnotation(OneToOne.class);
                            if (oneToOne != null && !oneToOne.targetEntity().getName().equals(void.class.getName())) {
                                valueClassName = oneToOne.targetEntity().getName();
                            }
                        }
                    }
                    if (md.getTargetClass().equals(valueClassName)) {
                        if (md.isProminent() != null && md.isProminent() && !ArrayUtils.contains(getGridHiddenVisibilities(), md.getVisibility())) {
                            hf = createHeaderField(p, md);
                            headerFields.add(hf);
                            defaultWrapperFields.add(constructFieldDTOFromFieldData(hf, md));
                            // Is this a media listgrid
                            if (hf.getFieldType().equals("ASSET_LOOKUP")) {
                                isMedia = true;
                            }
                        }
                        if (md.getIsFilter() != null && md.getIsFilter()) {
                            wrapper.getFields().add(constructFieldDTOFromFieldData(hf, md));
                        }
                    }
                }
            }
        }
        type = ListGrid.Type.MAP;
        editable = true;
        canFilterAndSort = false;
    }
    String ceilingType = "";
    if (fmd instanceof BasicFieldMetadata) {
        ceilingType = cmd.getCeilingType();
    } else if (fmd instanceof CollectionMetadata) {
        ceilingType = ((CollectionMetadata) fmd).getCollectionCeilingEntity();
    }
    if (CollectionUtils.isEmpty(headerFields)) {
        String message = "There are no listgrid header fields configured for the class " + ceilingType + " and property '" + StringUtil.sanitize(field.getName()) + "'.";
        if (selectize && (type == ListGrid.Type.ADORNED || type == ListGrid.Type.ADORNED_WITH_FORM)) {
            message += " Please configure 'selectizeVisibleField' in your @AdminPresentationAdornedTargetCollection configuration";
        } else if (type == ListGrid.Type.ADORNED || type == ListGrid.Type.ADORNED_WITH_FORM) {
            message += " Please configure 'gridVisibleFields' in your @AdminPresentationAdornedTargetCollection configuration";
        } else if (selectize && type == ListGrid.Type.BASIC) {
            message += " Please configure 'selectizeVisibleField' in your @AdminPresentationCollection configuration";
        } else {
            message += " Please mark some @AdminPresentation fields with 'prominent = true'";
        }
        LOG.error(message);
    }
    ListGrid listGrid = createListGrid(ceilingType, headerFields, type, drs, sectionKey, fmd.getOrder(), idProperty, sectionCrumbs, sortProperty);
    listGrid.setSubCollectionFieldName(field.getName());
    listGrid.setFriendlyName(field.getMetadata().getFriendlyName());
    if (StringUtils.isEmpty(listGrid.getFriendlyName())) {
        listGrid.setFriendlyName(field.getName());
    }
    listGrid.setContainingEntityId(containingEntityId);
    listGrid.setIsReadOnly(readOnly);
    listGrid.setHideIdColumn(hideIdColumn);
    listGrid.setCanFilterAndSort(canFilterAndSort);
    // Set up the filter builder params
    Date c = new Date();
    String friendlyName = field.getMetadata().getFriendlyName();
    String jsonFriendlyName = friendlyName.replaceAll(" ", "_");
    listGrid.setJsonFieldName(jsonFriendlyName + c.getTime() + "Json");
    listGrid.setFriendlyName(friendlyName);
    listGrid.setFieldBuilder("RULE_SIMPLE");
    if (CollectionUtils.isEmpty(wrapper.getFields())) {
        wrapper.setFields(defaultWrapperFields);
    }
    listGrid.setFieldWrapper(wrapper);
    String blankJsonString = "{\"data\":[]}";
    listGrid.setJson(blankJsonString);
    DataWrapper dw = convertJsonToDataWrapper(blankJsonString);
    if (dw != null) {
        listGrid.setDataWrapper(dw);
    }
    if (editable) {
        listGrid.getRowActions().add(DefaultListGridActions.UPDATE);
    }
    if (readOnly) {
        listGrid.getRowActions().add(DefaultListGridActions.VIEW);
    }
    if (sortable) {
        listGrid.setCanFilterAndSort(false);
        listGrid.setIsSortable(true);
    }
    if (modalSingleSelectable) {
        if (readOnly) {
            listGrid.addModalRowAction(DefaultListGridActions.SINGLE_SELECT.clone().withForListGridReadOnly(true));
        } else {
            listGrid.addModalRowAction(DefaultListGridActions.SINGLE_SELECT);
        }
    }
    listGrid.setSelectType(ListGrid.SelectType.SINGLE_SELECT);
    if (selectize) {
        listGrid.setSelectizeUrl(buildSelectizeUrl(listGrid));
        listGrid.setSelectType(ListGrid.SelectType.SELECTIZE);
    }
    if (modalMultiSelectable) {
        listGrid.addModalRowAction(DefaultListGridActions.MULTI_SELECT);
        listGrid.setSelectType(ListGrid.SelectType.MULTI_SELECT);
    }
    listGrid.getRowActions().add(DefaultListGridActions.REMOVE);
    if (fmd.getManualFetch()) {
        listGrid.setManualFetch(true);
        listGrid.getToolbarActions().add(DefaultListGridActions.MANUAL_FETCH);
    }
    if (isMedia) {
        listGrid.setListGridType(ListGrid.Type.ASSET_GRID);
    }
    extensionManager.getProxy().modifyListGrid(listGrid.getClassName(), listGrid);
    // If someone has replaced RowLevelSecurityService, check here to make sure the replacement implements the expected interface
    if (rowLevelSecurityService instanceof ExceptionAwareRowLevelSecurityProvider) {
        EntityFormModifierConfiguration entityFormModifierConfiguration = ((ExceptionAwareRowLevelSecurityProvider) rowLevelSecurityService).getUpdateDenialExceptions();
        for (EntityFormModifierData<EntityFormModifierDataPoint> data : entityFormModifierConfiguration.getData()) {
            for (EntityFormModifier modifier : entityFormModifierConfiguration.getModifier()) {
                if (modifier.isQualified(data.getModifierType())) {
                    modifier.modifyListGrid(new EntityFormModifierRequest().withListGrid(listGrid).withConfiguration(data).withCurrentUser(adminRemoteSecurityService.getPersistentAdminUser()).withRowLevelSecurityService(rowLevelSecurityService));
                }
            }
        }
    }
    return listGrid;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) ArrayList(java.util.ArrayList) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) EntityFormModifier(org.broadleafcommerce.openadmin.server.security.service.EntityFormModifier) ManyToOne(javax.persistence.ManyToOne) EntityFormModifierConfiguration(org.broadleafcommerce.openadmin.server.security.service.EntityFormModifierConfiguration) DataWrapper(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper) CodeField(org.broadleafcommerce.openadmin.web.form.entity.CodeField) RuleBuilderField(org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) ComboField(org.broadleafcommerce.openadmin.web.form.entity.ComboField) MediaField(org.broadleafcommerce.openadmin.web.form.component.MediaField) OneToOne(javax.persistence.OneToOne) FieldWrapper(org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldWrapper) Property(org.broadleafcommerce.openadmin.dto.Property) AdornedTargetList(org.broadleafcommerce.openadmin.dto.AdornedTargetList) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) FieldDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldDTO) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata) CollectionMetadata(org.broadleafcommerce.openadmin.dto.CollectionMetadata) EntityFormModifierDataPoint(org.broadleafcommerce.openadmin.server.security.service.EntityFormModifierDataPoint) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) Date(java.util.Date) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) EntityFormModifierRequest(org.broadleafcommerce.openadmin.server.security.service.EntityFormModifierRequest) ExceptionAwareRowLevelSecurityProvider(org.broadleafcommerce.openadmin.server.security.service.ExceptionAwareRowLevelSecurityProvider) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)

Aggregations

AdornedTargetList (org.broadleafcommerce.openadmin.dto.AdornedTargetList)14 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)8 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)8 Entity (org.broadleafcommerce.openadmin.dto.Entity)6 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 SecurityServiceException (org.broadleafcommerce.common.exception.SecurityServiceException)5 ServiceException (org.broadleafcommerce.common.exception.ServiceException)5 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)5 Serializable (java.io.Serializable)4 ArrayList (java.util.ArrayList)4 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)4 FilterMapping (org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping)4 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)3 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)3 Property (org.broadleafcommerce.openadmin.dto.Property)3 Field (java.lang.reflect.Field)2 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 ManyToOne (javax.persistence.ManyToOne)2