Search in sources :

Example 1 with AdornedTargetCollectionMetadata

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

the class AdornedTargetCollectionFieldMetadataProvider method addMetadataFromFieldType.

@Override
public MetadataProviderResponse addMetadataFromFieldType(AddMetadataFromFieldTypeRequest addMetadataFromFieldTypeRequest, Map<String, FieldMetadata> metadata) {
    if (!canHandleFieldForTypeMetadata(addMetadataFromFieldTypeRequest, metadata)) {
        return MetadataProviderResponse.NOT_HANDLED;
    }
    super.addMetadataFromFieldType(addMetadataFromFieldTypeRequest, metadata);
    // add additional adorned target support
    AdornedTargetCollectionMetadata fieldMetadata = (AdornedTargetCollectionMetadata) addMetadataFromFieldTypeRequest.getPresentationAttribute();
    if (StringUtils.isEmpty(fieldMetadata.getCollectionCeilingEntity())) {
        fieldMetadata.setCollectionCeilingEntity(addMetadataFromFieldTypeRequest.getType().getReturnedClass().getName());
        AdornedTargetList targetList = ((AdornedTargetList) fieldMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST));
        targetList.setAdornedTargetEntityClassname(fieldMetadata.getCollectionCeilingEntity());
    }
    return MetadataProviderResponse.HANDLED;
}
Also used : AdornedTargetList(org.broadleafcommerce.openadmin.dto.AdornedTargetList) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata) AdminPresentationAdornedTargetCollectionOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationAdornedTargetCollectionOverride) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) AdminPresentationMergeOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride)

Example 2 with AdornedTargetCollectionMetadata

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

the class AdornedTargetCollectionFieldMetadataProvider method buildAdornedTargetCollectionMetadata.

protected void buildAdornedTargetCollectionMetadata(Class<?> parentClass, Class<?> targetClass, Map<String, FieldMetadata> attributes, FieldInfo field, FieldMetadataOverride adornedTargetCollectionMetadata, DynamicEntityDao dynamicEntityDao) {
    AdornedTargetCollectionMetadata serverMetadata = (AdornedTargetCollectionMetadata) attributes.get(field.getName());
    Class<?> resolvedClass = parentClass == null ? targetClass : parentClass;
    AdornedTargetCollectionMetadata metadata;
    if (serverMetadata != null) {
        metadata = serverMetadata;
    } else {
        metadata = new AdornedTargetCollectionMetadata();
    }
    metadata.setTargetClass(targetClass.getName());
    metadata.setFieldName(field.getName());
    if (adornedTargetCollectionMetadata.getReadOnly() != null) {
        metadata.setMutable(!adornedTargetCollectionMetadata.getReadOnly());
    }
    if (adornedTargetCollectionMetadata.getShowIfProperty() != null) {
        metadata.setShowIfProperty(adornedTargetCollectionMetadata.getShowIfProperty());
    }
    if (adornedTargetCollectionMetadata.getShowIfFieldEquals() != null) {
        metadata.setShowIfFieldEquals(adornedTargetCollectionMetadata.getShowIfFieldEquals());
    }
    org.broadleafcommerce.openadmin.dto.OperationTypes dtoOperationTypes = new org.broadleafcommerce.openadmin.dto.OperationTypes(OperationType.ADORNEDTARGETLIST, OperationType.ADORNEDTARGETLIST, OperationType.ADORNEDTARGETLIST, OperationType.ADORNEDTARGETLIST, OperationType.BASIC);
    if (adornedTargetCollectionMetadata.getAddType() != null) {
        dtoOperationTypes.setAddType(adornedTargetCollectionMetadata.getAddType());
    }
    if (adornedTargetCollectionMetadata.getRemoveType() != null) {
        dtoOperationTypes.setRemoveType(adornedTargetCollectionMetadata.getRemoveType());
    }
    if (adornedTargetCollectionMetadata.getFetchType() != null) {
        dtoOperationTypes.setFetchType(adornedTargetCollectionMetadata.getFetchType());
    }
    if (adornedTargetCollectionMetadata.getInspectType() != null) {
        dtoOperationTypes.setInspectType(adornedTargetCollectionMetadata.getInspectType());
    }
    if (adornedTargetCollectionMetadata.getUpdateType() != null) {
        dtoOperationTypes.setUpdateType(adornedTargetCollectionMetadata.getUpdateType());
    }
    // don't allow additional non-persistent properties or additional foreign keys for an advanced collection datasource - they don't make sense in this context
    PersistencePerspective persistencePerspective;
    if (serverMetadata != null) {
        persistencePerspective = metadata.getPersistencePerspective();
        persistencePerspective.setOperationTypes(dtoOperationTypes);
    } else {
        persistencePerspective = new PersistencePerspective(dtoOperationTypes, new String[] {}, new ForeignKey[] {});
        metadata.setPersistencePerspective(persistencePerspective);
    }
    String parentObjectProperty = null;
    if (serverMetadata != null) {
        parentObjectProperty = ((AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST)).getLinkedObjectPath();
    }
    if (!StringUtils.isEmpty(adornedTargetCollectionMetadata.getParentObjectProperty())) {
        parentObjectProperty = adornedTargetCollectionMetadata.getParentObjectProperty();
    }
    if (parentObjectProperty == null && !StringUtils.isEmpty(field.getOneToManyMappedBy())) {
        parentObjectProperty = field.getOneToManyMappedBy();
    }
    if (parentObjectProperty == null && !StringUtils.isEmpty(field.getManyToManyMappedBy())) {
        parentObjectProperty = field.getManyToManyMappedBy();
    }
    if (StringUtils.isEmpty(parentObjectProperty)) {
        throw new IllegalArgumentException("Unable to infer a parentObjectProperty for the @AdminPresentationAdornedTargetCollection annotated field(" + field.getName() + "). If not using the mappedBy property of @OneToMany or @ManyToMany, please make sure to explicitly define the parentObjectProperty property");
    }
    String sortProperty = null;
    if (serverMetadata != null) {
        sortProperty = ((AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST)).getSortField();
    }
    if (!StringUtils.isEmpty(adornedTargetCollectionMetadata.getSortProperty())) {
        sortProperty = adornedTargetCollectionMetadata.getSortProperty();
    }
    metadata.setParentObjectClass(resolvedClass.getName());
    if (adornedTargetCollectionMetadata.getMaintainedAdornedTargetFields() != null) {
        metadata.setMaintainedAdornedTargetFields(adornedTargetCollectionMetadata.getMaintainedAdornedTargetFields());
    }
    if (adornedTargetCollectionMetadata.getGridVisibleFields() != null) {
        metadata.setGridVisibleFields(adornedTargetCollectionMetadata.getGridVisibleFields());
    }
    if (adornedTargetCollectionMetadata.getSelectizeVisibleField() != null) {
        metadata.setSelectizeVisibleField(adornedTargetCollectionMetadata.getSelectizeVisibleField());
    }
    String parentObjectIdProperty = null;
    if (serverMetadata != null) {
        parentObjectIdProperty = ((AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST)).getLinkedIdProperty();
    }
    if (adornedTargetCollectionMetadata.getParentObjectIdProperty() != null) {
        parentObjectIdProperty = adornedTargetCollectionMetadata.getParentObjectIdProperty();
    }
    String targetObjectProperty = null;
    if (serverMetadata != null) {
        targetObjectProperty = ((AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST)).getTargetObjectPath();
    }
    if (adornedTargetCollectionMetadata.getTargetObjectProperty() != null) {
        targetObjectProperty = adornedTargetCollectionMetadata.getTargetObjectProperty();
    }
    if (StringUtils.isEmpty(parentObjectIdProperty)) {
        throw new IllegalArgumentException("targetObjectProperty not defined");
    }
    String joinEntityClass = null;
    if (serverMetadata != null) {
        joinEntityClass = ((AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST)).getJoinEntityClass();
    }
    if (adornedTargetCollectionMetadata.getJoinEntityClass() != null) {
        joinEntityClass = adornedTargetCollectionMetadata.getJoinEntityClass();
    }
    Class<?> collectionTarget = null;
    try {
        checkCeiling: {
            try {
                ParameterizedType pt = (ParameterizedType) field.getGenericType();
                java.lang.reflect.Type collectionType = pt.getActualTypeArguments()[0];
                collectionTarget = (Class<?>) collectionType;
                // Hibernate class is from that
                if (collectionTarget.isInterface()) {
                    collectionTarget = entityConfiguration.lookupEntityClass(collectionTarget.getName());
                }
                break checkCeiling;
            } catch (NoSuchBeanDefinitionException e) {
            // We weren't successful at looking at entity configuration to find the type of this collection.
            // We will continue and attempt to find it via the Hibernate annotations
            }
            if (!StringUtils.isEmpty(field.getOneToManyTargetEntity()) && !void.class.getName().equals(field.getOneToManyTargetEntity())) {
                collectionTarget = Class.forName(field.getOneToManyTargetEntity());
                break checkCeiling;
            }
            if (!StringUtils.isEmpty(field.getManyToManyTargetEntity()) && !void.class.getName().equals(field.getManyToManyTargetEntity())) {
                collectionTarget = Class.forName(field.getManyToManyTargetEntity());
                break checkCeiling;
            }
        }
        if (StringUtils.isNotBlank(joinEntityClass)) {
            collectionTarget = Class.forName(joinEntityClass);
        }
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    if (collectionTarget == null) {
        throw new IllegalArgumentException("Unable to infer the type of the collection from the targetEntity property of a OneToMany or ManyToMany collection.");
    }
    Field collectionTargetField = dynamicEntityDao.getFieldManager().getField(collectionTarget, targetObjectProperty);
    ManyToOne manyToOne = collectionTargetField.getAnnotation(ManyToOne.class);
    String ceiling = null;
    checkCeiling: {
        if (manyToOne != null && manyToOne.targetEntity() != void.class) {
            ceiling = manyToOne.targetEntity().getName();
            break checkCeiling;
        }
        ceiling = collectionTargetField.getType().getName();
    }
    if (!StringUtils.isEmpty(ceiling)) {
        metadata.setCollectionCeilingEntity(ceiling);
    }
    String targetObjectIdProperty = null;
    if (serverMetadata != null) {
        targetObjectIdProperty = ((AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST)).getTargetIdProperty();
    }
    if (adornedTargetCollectionMetadata.getTargetObjectIdProperty() != null) {
        targetObjectIdProperty = adornedTargetCollectionMetadata.getTargetObjectIdProperty();
    }
    Boolean isAscending = true;
    if (serverMetadata != null) {
        isAscending = ((AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST)).getSortAscending();
    }
    if (adornedTargetCollectionMetadata.isSortAscending() != null) {
        isAscending = adornedTargetCollectionMetadata.isSortAscending();
    }
    if (serverMetadata != null) {
        AdornedTargetList adornedTargetList = (AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST);
        adornedTargetList.setCollectionFieldName(field.getName());
        adornedTargetList.setLinkedObjectPath(parentObjectProperty);
        adornedTargetList.setLinkedIdProperty(parentObjectIdProperty);
        adornedTargetList.setTargetObjectPath(targetObjectProperty);
        adornedTargetList.setTargetIdProperty(targetObjectIdProperty);
        adornedTargetList.setJoinEntityClass(joinEntityClass);
        adornedTargetList.setIdProperty((String) dynamicEntityDao.getIdMetadata(collectionTarget).get("name"));
        adornedTargetList.setAdornedTargetEntityClassname(collectionTarget.getName());
        adornedTargetList.setSortField(sortProperty);
        adornedTargetList.setSortAscending(isAscending);
        adornedTargetList.setMutable(metadata.isMutable());
    } else {
        AdornedTargetList adornedTargetList = new AdornedTargetList(field.getName(), parentObjectProperty, parentObjectIdProperty, targetObjectProperty, targetObjectIdProperty, collectionTarget.getName(), sortProperty, isAscending);
        adornedTargetList.setJoinEntityClass(joinEntityClass);
        adornedTargetList.setIdProperty((String) dynamicEntityDao.getIdMetadata(collectionTarget).get("name"));
        adornedTargetList.setMutable(metadata.isMutable());
        persistencePerspective.addPersistencePerspectiveItem(PersistencePerspectiveItemType.ADORNEDTARGETLIST, adornedTargetList);
    }
    if (adornedTargetCollectionMetadata.getExcluded() != null) {
        if (LOG.isDebugEnabled()) {
            if (adornedTargetCollectionMetadata.getExcluded()) {
                LOG.debug("buildAdornedTargetCollectionMetadata:Excluding " + field.getName() + " because it was explicitly declared in config");
            } else {
                LOG.debug("buildAdornedTargetCollectionMetadata:Showing " + field.getName() + " because it was explicitly declared in config");
            }
        }
        metadata.setExcluded(adornedTargetCollectionMetadata.getExcluded());
    }
    if (adornedTargetCollectionMetadata.getLazyFetch() != null) {
        metadata.setLazyFetch(adornedTargetCollectionMetadata.getLazyFetch());
    }
    if (adornedTargetCollectionMetadata.getManualFetch() != null) {
        metadata.setManualFetch(adornedTargetCollectionMetadata.getManualFetch());
    }
    if (adornedTargetCollectionMetadata.getFriendlyName() != null) {
        metadata.setFriendlyName(adornedTargetCollectionMetadata.getFriendlyName());
    }
    if (adornedTargetCollectionMetadata.getSecurityLevel() != null) {
        metadata.setSecurityLevel(adornedTargetCollectionMetadata.getSecurityLevel());
    }
    if (adornedTargetCollectionMetadata.getOrder() != null) {
        metadata.setOrder(adornedTargetCollectionMetadata.getOrder());
    }
    if (adornedTargetCollectionMetadata.getTab() != null) {
        metadata.setTab(adornedTargetCollectionMetadata.getTab());
    }
    if (adornedTargetCollectionMetadata.getTabOrder() != null) {
        metadata.setTabOrder(adornedTargetCollectionMetadata.getTabOrder());
    }
    if (adornedTargetCollectionMetadata.getGroup() != null) {
        metadata.setGroup(adornedTargetCollectionMetadata.getGroup());
    }
    if (adornedTargetCollectionMetadata.getCustomCriteria() != null) {
        metadata.setCustomCriteria(adornedTargetCollectionMetadata.getCustomCriteria());
    }
    if (adornedTargetCollectionMetadata.getUseServerSideInspectionCache() != null) {
        persistencePerspective.setUseServerSideInspectionCache(adornedTargetCollectionMetadata.getUseServerSideInspectionCache());
    }
    if (adornedTargetCollectionMetadata.isIgnoreAdornedProperties() != null) {
        metadata.setIgnoreAdornedProperties(adornedTargetCollectionMetadata.isIgnoreAdornedProperties());
    }
    if (adornedTargetCollectionMetadata.getAdornedTargetAddMethodType() != null) {
        metadata.setAdornedTargetAddMethodType(adornedTargetCollectionMetadata.getAdornedTargetAddMethodType());
    }
    if (adornedTargetCollectionMetadata.getCurrencyCodeField() != null) {
        metadata.setCurrencyCodeField(adornedTargetCollectionMetadata.getCurrencyCodeField());
    }
    attributes.put(field.getName(), metadata);
}
Also used : ForeignKey(org.broadleafcommerce.openadmin.dto.ForeignKey) ManyToOne(javax.persistence.ManyToOne) ParameterizedType(java.lang.reflect.ParameterizedType) Field(java.lang.reflect.Field) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) AdminPresentationOperationTypes(org.broadleafcommerce.common.presentation.AdminPresentationOperationTypes) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) AdornedTargetList(org.broadleafcommerce.openadmin.dto.AdornedTargetList) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)

Example 3 with AdornedTargetCollectionMetadata

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

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

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

Aggregations

AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)16 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)12 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)9 Property (org.broadleafcommerce.openadmin.dto.Property)9 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)9 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)8 MapMetadata (org.broadleafcommerce.openadmin.dto.MapMetadata)8 HashMap (java.util.HashMap)6 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)6 Entity (org.broadleafcommerce.openadmin.dto.Entity)6 AdornedTargetList (org.broadleafcommerce.openadmin.dto.AdornedTargetList)5 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)5 Field (java.lang.reflect.Field)4 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)4 AdminPresentationAdornedTargetCollectionOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationAdornedTargetCollectionOverride)4 BLCSystemProperty (org.broadleafcommerce.common.util.BLCSystemProperty)4 FieldMetadataOverride (org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 AdminPresentationMergeOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride)3