use of org.broadleafcommerce.openadmin.server.dao.FieldInfo in project BroadleafCommerce by BroadleafCommerce.
the class BasicFieldMetadataProvider method overrideViaXml.
@Override
public MetadataProviderResponse overrideViaXml(OverrideViaXmlRequest overrideViaXmlRequest, Map<String, FieldMetadata> metadata) {
Map<String, MetadataOverride> overrides = getTargetedOverride(overrideViaXmlRequest.getDynamicEntityDao(), overrideViaXmlRequest.getRequestedConfigKey(), overrideViaXmlRequest.getRequestedCeilingEntity());
if (overrides != null) {
for (String propertyName : overrides.keySet()) {
MetadataOverride localMetadata = overrides.get(propertyName);
if (localMetadata instanceof FieldMetadataOverride) {
FieldMetadataOverride localFieldMetadata = (FieldMetadataOverride) localMetadata;
for (String key : metadata.keySet()) {
if (key.equals(propertyName)) {
try {
if (metadata.get(key) instanceof BasicFieldMetadata) {
BasicFieldMetadata serverMetadata = (BasicFieldMetadata) metadata.get(key);
if (serverMetadata.getTargetClass() != null) {
Class<?> targetClass = Class.forName(serverMetadata.getTargetClass());
Class<?> parentClass = null;
if (serverMetadata.getOwningClass() != null) {
parentClass = Class.forName(serverMetadata.getOwningClass());
}
String fieldName = serverMetadata.getFieldName();
Field field = overrideViaXmlRequest.getDynamicEntityDao().getFieldManager().getField(targetClass, fieldName);
Map<String, FieldMetadata> temp = new HashMap<>(1);
temp.put(field.getName(), serverMetadata);
FieldInfo info = buildFieldInfo(field);
buildBasicMetadata(parentClass, targetClass, temp, info, localFieldMetadata, overrideViaXmlRequest.getDynamicEntityDao());
serverMetadata = (BasicFieldMetadata) temp.get(field.getName());
metadata.put(key, serverMetadata);
if (overrideViaXmlRequest.getParentExcluded()) {
if (LOG.isDebugEnabled()) {
LOG.debug("applyMetadataOverrides:Excluding " + key + "because the parent was excluded");
}
serverMetadata.setExcluded(true);
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
}
}
return MetadataProviderResponse.HANDLED;
}
use of org.broadleafcommerce.openadmin.server.dao.FieldInfo in project BroadleafCommerce by BroadleafCommerce.
the class BasicFieldMetadataProvider method addMetadata.
@Override
public MetadataProviderResponse addMetadata(AddFieldMetadataRequest addMetadataRequest, Map<String, FieldMetadata> metadata) {
if (!canHandleFieldForConfiguredMetadata(addMetadataRequest, metadata)) {
return MetadataProviderResponse.NOT_HANDLED;
}
AdminPresentation annot = addMetadataRequest.getRequestedField().getAnnotation(AdminPresentation.class);
FieldInfo info = buildFieldInfo(addMetadataRequest.getRequestedField());
FieldMetadataOverride override = constructBasicMetadataOverride(annot, addMetadataRequest.getRequestedField().getAnnotation(AdminPresentationToOneLookup.class), addMetadataRequest.getRequestedField().getAnnotation(AdminPresentationDataDrivenEnumeration.class));
buildBasicMetadata(addMetadataRequest.getParentClass(), addMetadataRequest.getTargetClass(), metadata, info, override, addMetadataRequest.getDynamicEntityDao());
setClassOwnership(addMetadataRequest.getParentClass(), addMetadataRequest.getTargetClass(), metadata, info);
return MetadataProviderResponse.HANDLED;
}
use of org.broadleafcommerce.openadmin.server.dao.FieldInfo in project BroadleafCommerce by BroadleafCommerce.
the class CollectionFieldMetadataProvider method buildAdminPresentationCollectionOverride.
protected void buildAdminPresentationCollectionOverride(String prefix, Boolean isParentExcluded, Map<String, FieldMetadata> mergedProperties, Map<String, AdminPresentationCollectionOverride> presentationCollectionOverrides, String propertyName, String key, DynamicEntityDao dynamicEntityDao) {
AdminPresentationCollectionOverride override = presentationCollectionOverrides.get(propertyName);
if (override != null) {
AdminPresentationCollection annot = override.value();
if (annot != null) {
String testKey = prefix + key;
if ((testKey.startsWith(propertyName + ".") || testKey.equals(propertyName)) && annot.excluded()) {
FieldMetadata metadata = mergedProperties.get(key);
if (LOG.isDebugEnabled()) {
LOG.debug("buildAdminPresentationCollectionOverride:Excluding " + key + "because an override annotation declared " + testKey + "to be excluded");
}
metadata.setExcluded(true);
return;
}
if ((testKey.startsWith(propertyName + ".") || testKey.equals(propertyName)) && !annot.excluded()) {
FieldMetadata metadata = mergedProperties.get(key);
if (!isParentExcluded) {
if (LOG.isDebugEnabled()) {
LOG.debug("buildAdminPresentationCollectionOverride:Showing " + key + "because an override annotation declared " + testKey + " to not be excluded");
}
metadata.setExcluded(false);
}
}
if (!(mergedProperties.get(key) instanceof BasicCollectionMetadata)) {
return;
}
BasicCollectionMetadata serverMetadata = (BasicCollectionMetadata) mergedProperties.get(key);
if (serverMetadata.getTargetClass() != null) {
try {
Class<?> targetClass = Class.forName(serverMetadata.getTargetClass());
Class<?> parentClass = null;
if (serverMetadata.getOwningClass() != null) {
parentClass = Class.forName(serverMetadata.getOwningClass());
}
String fieldName = serverMetadata.getFieldName();
Field field = dynamicEntityDao.getFieldManager().getField(targetClass, fieldName);
FieldMetadataOverride localMetadata = constructBasicCollectionMetadataOverride(annot);
// do not include the previous metadata - we want to construct a fresh metadata from the override annotation
Map<String, FieldMetadata> temp = new HashMap<String, FieldMetadata>(1);
FieldInfo info = buildFieldInfo(field);
buildCollectionMetadata(parentClass, targetClass, temp, info, localMetadata, prefix);
BasicCollectionMetadata result = (BasicCollectionMetadata) temp.get(field.getName());
result.setInheritedFromType(serverMetadata.getInheritedFromType());
result.setAvailableToTypes(serverMetadata.getAvailableToTypes());
mergedProperties.put(key, result);
if (isParentExcluded) {
if (LOG.isDebugEnabled()) {
LOG.debug("buildAdminPresentationCollectionOverride:Excluding " + key + "because the parent was excluded");
}
serverMetadata.setExcluded(true);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
}
use of org.broadleafcommerce.openadmin.server.dao.FieldInfo in project BroadleafCommerce by BroadleafCommerce.
the class CollectionFieldMetadataProvider method overrideViaXml.
@Override
public MetadataProviderResponse overrideViaXml(OverrideViaXmlRequest overrideViaXmlRequest, Map<String, FieldMetadata> metadata) {
Map<String, MetadataOverride> overrides = getTargetedOverride(overrideViaXmlRequest.getDynamicEntityDao(), overrideViaXmlRequest.getRequestedConfigKey(), overrideViaXmlRequest.getRequestedCeilingEntity());
if (overrides != null) {
for (String propertyName : overrides.keySet()) {
MetadataOverride localMetadata = overrides.get(propertyName);
if (localMetadata instanceof FieldMetadataOverride) {
FieldMetadataOverride localFieldMetadata = (FieldMetadataOverride) localMetadata;
for (String key : metadata.keySet()) {
if (key.equals(propertyName)) {
try {
if (metadata.get(key) instanceof BasicCollectionMetadata) {
BasicCollectionMetadata serverMetadata = (BasicCollectionMetadata) metadata.get(key);
if (serverMetadata.getTargetClass() != null) {
Class<?> targetClass = Class.forName(serverMetadata.getTargetClass());
Class<?> parentClass = null;
if (serverMetadata.getOwningClass() != null) {
parentClass = Class.forName(serverMetadata.getOwningClass());
}
String fieldName = serverMetadata.getFieldName();
Field field = overrideViaXmlRequest.getDynamicEntityDao().getFieldManager().getField(targetClass, fieldName);
Map<String, FieldMetadata> temp = new HashMap<String, FieldMetadata>(1);
temp.put(field.getName(), serverMetadata);
FieldInfo info = buildFieldInfo(field);
buildCollectionMetadata(parentClass, targetClass, temp, info, localFieldMetadata, overrideViaXmlRequest.getPrefix());
serverMetadata = (BasicCollectionMetadata) temp.get(field.getName());
metadata.put(key, serverMetadata);
if (overrideViaXmlRequest.getParentExcluded()) {
if (LOG.isDebugEnabled()) {
LOG.debug("applyCollectionMetadataOverrides:Excluding " + key + "because parent is marked as excluded.");
}
serverMetadata.setExcluded(true);
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
}
}
return MetadataProviderResponse.HANDLED;
}
use of org.broadleafcommerce.openadmin.server.dao.FieldInfo in project BroadleafCommerce by BroadleafCommerce.
the class DefaultFieldMetadataProvider method addMetadata.
@Override
public MetadataProviderResponse addMetadata(AddFieldMetadataRequest addMetadataRequest, Map<String, FieldMetadata> metadata) {
Map<String, Object> idMetadata = addMetadataRequest.getDynamicEntityDao().getIdMetadata(addMetadataRequest.getTargetClass());
if (idMetadata != null) {
String idField = (String) idMetadata.get("name");
boolean processField;
// allow id fields without AdminPresentation annotation to pass through
processField = idField.equals(addMetadataRequest.getRequestedField().getName());
if (!processField) {
List<String> propertyNames = addMetadataRequest.getDynamicEntityDao().getPropertyNames(addMetadataRequest.getTargetClass());
if (!CollectionUtils.isEmpty(propertyNames)) {
List<org.hibernate.type.Type> propertyTypes = addMetadataRequest.getDynamicEntityDao().getPropertyTypes(addMetadataRequest.getTargetClass());
int index = propertyNames.indexOf(addMetadataRequest.getRequestedField().getName());
if (index >= 0) {
Type myType = propertyTypes.get(index);
// allow OneToOne, ManyToOne and Embeddable fields to pass through
processField = myType.isCollectionType() || myType.isAssociationType() || myType.isComponentType() || myType.isEntityType();
}
}
}
if (processField) {
FieldInfo info = buildFieldInfo(addMetadataRequest.getRequestedField());
BasicFieldMetadata basicMetadata = new BasicFieldMetadata();
basicMetadata.setName(addMetadataRequest.getRequestedField().getName());
basicMetadata.setExcluded(false);
metadata.put(addMetadataRequest.getRequestedField().getName(), basicMetadata);
setClassOwnership(addMetadataRequest.getParentClass(), addMetadataRequest.getTargetClass(), metadata, info);
return MetadataProviderResponse.HANDLED;
}
}
return MetadataProviderResponse.NOT_HANDLED;
}
Aggregations