Skip to content

Commit

Permalink
Fix for metaType filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgonzalez committed Mar 31, 2021
1 parent 613a640 commit c80d90e
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,32 @@ protected void visit(final Resource resource) {
collectMetadataProperty(fieldLabel, propertyName, metadata);
}

private boolean isWidget(Resource resource) {
if (resource == null) {
private boolean isWidget(Resource widgetResource) {
if (widgetResource == null) {
return false;
}

if (metadataFieldResourceTypes != null && metadataFieldResourceTypes.size() > 0) {
// Overriding the allowed field resource types; only match these.
return metadataFieldResourceTypes.stream().anyMatch(metaType -> checkMetaDataType(resource, metaType));
return metadataFieldResourceTypes.stream().anyMatch(metaType -> checkMetaDataType(widgetResource, metaType));
} else {
// Default use the Granite UI (foundation and coral) Field resourceTypes
return Arrays.stream(RT_FIELDS).anyMatch(resourceType -> resource.isResourceType(resourceType));
return Arrays.stream(RT_FIELDS).anyMatch(resourceType -> widgetResource.isResourceType(resourceType));
}
}

private boolean checkMetaDataType(Resource resource, String metaType) {
return Arrays.stream(METADATA_TYPES_PROPERTIES).anyMatch(metaTypeProperty-> resource.getValueMap().containsKey(metaTypeProperty)
&& resource.getValueMap().get(metaTypeProperty).equals(metaType));
private boolean checkMetaDataType(Resource widgetResource, String metaType) {
final ValueMap properties = widgetResource.getValueMap();
for (final String propertyName : METADATA_TYPES_PROPERTIES) {

final String metaTypeCandidate = properties.get("granite:data/" + propertyName, properties.get(propertyName, String.class));

if (StringUtils.equals(metaType, metaTypeCandidate)) {
return true;
}
}

return false;
}
}

Expand Down

0 comments on commit c80d90e

Please sign in to comment.