Search in sources :

Example 6 with CollectionMetadata

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

the class AdvancedCollectionFieldMetadataProvider method addMetadataFromFieldType.

@Override
public MetadataProviderResponse addMetadataFromFieldType(AddMetadataFromFieldTypeRequest addMetadataFromFieldTypeRequest, Map<String, FieldMetadata> metadata) {
    if (!canHandleFieldForTypeMetadata(addMetadataFromFieldTypeRequest, metadata)) {
        return MetadataProviderResponse.NOT_HANDLED;
    }
    CollectionMetadata fieldMetadata = (CollectionMetadata) addMetadataFromFieldTypeRequest.getPresentationAttribute();
    if (StringUtils.isEmpty(fieldMetadata.getCollectionCeilingEntity())) {
        ParameterizedType listType = (ParameterizedType) addMetadataFromFieldTypeRequest.getRequestedField().getGenericType();
        Class<?> listClass = (Class<?>) listType.getActualTypeArguments()[0];
        fieldMetadata.setCollectionCeilingEntity(listClass.getName());
    }
    if (addMetadataFromFieldTypeRequest.getTargetClass() != null) {
        if (StringUtils.isEmpty(fieldMetadata.getInheritedFromType())) {
            fieldMetadata.setInheritedFromType(addMetadataFromFieldTypeRequest.getTargetClass().getName());
        }
        if (ArrayUtils.isEmpty(fieldMetadata.getAvailableToTypes())) {
            fieldMetadata.setAvailableToTypes(new String[] { addMetadataFromFieldTypeRequest.getTargetClass().getName() });
        }
    }
    // {@link BasicPersistenceModule#filterOutCollectionMetadata}
    if (addMetadataFromFieldTypeRequest.getForeignField() != null && addMetadataFromFieldTypeRequest.isPropertyForeignKey()) {
        FieldInfo info = buildFieldInfo(addMetadataFromFieldTypeRequest.getRequestedField());
        BasicFieldMetadata basicMetadata = new BasicFieldMetadata();
        basicMetadata.setName(info.getName());
        basicMetadata.setExcluded(false);
        // Don't show this anywhere on the form and ensure it's explicitly not required
        basicMetadata.setVisibility(VisibilityEnum.HIDDEN_ALL);
        basicMetadata.setRequired(false);
        setClassOwnership(addMetadataFromFieldTypeRequest.getReturnedClass(), addMetadataFromFieldTypeRequest.getTargetClass(), metadata, info);
        Map<String, FieldMetadata> fakedMd = new HashMap<String, FieldMetadata>();
        fakedMd.put(addMetadataFromFieldTypeRequest.getRequestedField().getName(), basicMetadata);
        // Fake out a request and some metadata to pass along as additional metadata within this metadata
        AddMetadataFromFieldTypeRequest fakedRequest = new AddMetadataFromFieldTypeRequest(addMetadataFromFieldTypeRequest.getRequestedField(), addMetadataFromFieldTypeRequest.getTargetClass(), addMetadataFromFieldTypeRequest.getForeignField(), addMetadataFromFieldTypeRequest.getAdditionalForeignFields(), addMetadataFromFieldTypeRequest.getMergedPropertyType(), addMetadataFromFieldTypeRequest.getComponentProperties(), addMetadataFromFieldTypeRequest.getIdProperty(), addMetadataFromFieldTypeRequest.getPrefix(), addMetadataFromFieldTypeRequest.getRequestedPropertyName(), addMetadataFromFieldTypeRequest.getType(), addMetadataFromFieldTypeRequest.isPropertyForeignKey(), addMetadataFromFieldTypeRequest.getAdditionalForeignKeyIndexPosition(), fakedMd, basicMetadata, addMetadataFromFieldTypeRequest.getExplicitType(), addMetadataFromFieldTypeRequest.getReturnedClass(), addMetadataFromFieldTypeRequest.getDynamicEntityDao());
        defaultMetadataProvider.addMetadataFromFieldType(fakedRequest, fakedMd);
        fieldMetadata.getAdditionalMetadata().put(FOREIGN_KEY_ADDITIONAL_METADATA_KEY, basicMetadata);
    }
    metadata.put(addMetadataFromFieldTypeRequest.getRequestedPropertyName(), fieldMetadata);
    return MetadataProviderResponse.HANDLED;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) CollectionMetadata(org.broadleafcommerce.openadmin.dto.CollectionMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FieldInfo(org.broadleafcommerce.openadmin.server.dao.FieldInfo) AddMetadataFromFieldTypeRequest(org.broadleafcommerce.openadmin.server.dao.provider.metadata.request.AddMetadataFromFieldTypeRequest)

Example 7 with CollectionMetadata

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

the class AdminEntityServiceImpl method getPagedRecordsForCollection.

@Override
public PersistenceResponse getPagedRecordsForCollection(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, FilterAndSortCriteria[] fascs, FetchPageRequest fetchPageRequest, String idValueOverride, List<SectionCrumb> sectionCrumbs) throws ServiceException {
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(collectionProperty.getMetadata(), sectionCrumbs).withFilterAndSortCriteria(fascs).withStartIndex(fetchPageRequest.getStartIndex()).withMaxIndex(fetchPageRequest.getMaxIndex()).withFirstId(fetchPageRequest.getFirstId()).withLastId(fetchPageRequest.getLastId()).withLowerCount(fetchPageRequest.getLowerCount()).withUpperCount(fetchPageRequest.getUpperCount()).withPageSize(fetchPageRequest.getPageSize()).withPresentationFetch(true);
    FilterAndSortCriteria fasc;
    FieldMetadata md = collectionProperty.getMetadata();
    String collectionCeilingClass = null;
    if (md instanceof BasicCollectionMetadata) {
        fasc = new FilterAndSortCriteria(ppr.getForeignKey().getManyToField());
        collectionCeilingClass = ((CollectionMetadata) md).getCollectionCeilingEntity();
    } else if (md instanceof AdornedTargetCollectionMetadata) {
        fasc = new FilterAndSortCriteria(ppr.getAdornedList().getCollectionFieldName());
        collectionCeilingClass = ((CollectionMetadata) md).getCollectionCeilingEntity();
    } else if (md instanceof MapMetadata) {
        fasc = new FilterAndSortCriteria(ppr.getForeignKey().getManyToField());
    } else {
        throw new IllegalArgumentException(String.format("The specified field [%s] for class [%s] was not a " + "collection field.", collectionProperty.getName(), containingClassMetadata.getCeilingType()));
    }
    String id;
    if (idValueOverride == null) {
        id = getContextSpecificRelationshipId(containingClassMetadata, containingEntity, collectionProperty.getName());
    } else {
        id = idValueOverride;
    }
    fasc.setFilterValue(id);
    ppr.addFilterAndSortCriteria(fasc);
    if (collectionCeilingClass != null) {
        ppr.setCeilingEntityClassname(collectionCeilingClass);
    }
    ppr.setSectionEntityField(collectionProperty.getName());
    return fetch(ppr);
}
Also used : BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) CollectionMetadata(org.broadleafcommerce.openadmin.dto.CollectionMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)

Aggregations

CollectionMetadata (org.broadleafcommerce.openadmin.dto.CollectionMetadata)7 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)6 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)6 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)5 Property (org.broadleafcommerce.openadmin.dto.Property)5 HashMap (java.util.HashMap)4 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)4 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)4 BLCSystemProperty (org.broadleafcommerce.common.util.BLCSystemProperty)3 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)3 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)3 PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)3 MapMetadata (org.broadleafcommerce.openadmin.dto.MapMetadata)2 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Map (java.util.Map)1 ManyToOne (javax.persistence.ManyToOne)1 OneToOne (javax.persistence.OneToOne)1