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;
}
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);
}
Aggregations