Mathijs den Burger pushed to branch feature/CC-CHANNELMGR-1520 at cms-community / hippo-addon-channel-manager
Commits: 8635de59 by Mathijs den Burger at 2018-02-02T13:06:34+01:00 CHANNELMGR-1520 Recognize compound fields explicitly Instead of assuming that everything that's not a choice field is a compound, we now explicit recognize compounds fields: one of their required supertypes is always "hippo:compound". That prevents the code from recognizing compound-like types like hippogallerypicker:imagelink as a compound. These will now be parsed an UNKNOWN types instead, which makes it possible to later recognize them as unknown required types. - - - - - 6461285b by Mathijs den Burger at 2018-02-02T13:10:21+01:00 CHANNELMGR-1520 Fix reporting of unsupported field types They were not included anymore because FieldTypeUtils#determineFieldType returned "Unknown" instead of an empty string for unsupported fields. Don't include the 'unsupportedFieldTypes' property in the JSON output unless it's not empty, otherwise the frontend will erroneously report a usage statistic about it with an empty array of type names (an empty array is truthy in JavaScript). - - - - - 2 changed files: - content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/FieldTypeUtils.java - content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/model/DocumentType.java Changes: ===================================== content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/FieldTypeUtils.java ===================================== --- a/content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/FieldTypeUtils.java +++ b/content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/field/FieldTypeUtils.java @@ -32,6 +32,7 @@ import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; import org.hippoecm.repository.HippoStdNodeType; +import org.hippoecm.repository.api.HippoNodeType; import org.hippoecm.repository.util.JcrUtils; import org.onehippo.cms.channelmanager.content.document.model.FieldValue; import org.onehippo.cms.channelmanager.content.document.util.FieldPath; @@ -58,6 +59,8 @@ import org.onehippo.cms.channelmanager.content.error.ErrorInfo.Reason; import org.onehippo.cms.channelmanager.content.error.ErrorWithPayloadException; import org.onehippo.cms.channelmanager.content.error.InternalServerErrorException; import org.onehippo.cms7.services.contenttype.ContentTypeItem; +import org.onehippo.cms7.services.contenttype.EffectiveNodeTypeChild; +import org.onehippo.cms7.services.contenttype.EffectiveNodeTypeItem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -231,11 +234,29 @@ public class FieldTypeUtils { } if (item.isProperty()) { - // Unsupported type + // All known property fields are part of the FIELD_TYPE_MAP, so this one is unknown return FIELD_TYPE_UNKNOWN; } - return ChoiceFieldUtils.isChoiceField(context) ? FIELD_TYPE_CHOICE : FIELD_TYPE_COMPOUND; + if (ChoiceFieldUtils.isChoiceField(context)) { + return FIELD_TYPE_CHOICE; + } + + if (isCompound(item)) { + return FIELD_TYPE_COMPOUND; + } + + return FIELD_TYPE_UNKNOWN; + } + + private static boolean isCompound(final ContentTypeItem item) { + final EffectiveNodeTypeItem effectiveItem = item.getEffectiveNodeTypeItem(); + + if (effectiveItem instanceof EffectiveNodeTypeChild) { + EffectiveNodeTypeChild effectiveChild = (EffectiveNodeTypeChild) effectiveItem; + return effectiveChild.getRequiredPrimaryTypes().contains(HippoNodeType.NT_COMPOUND); + } + return false; } private static boolean usesDefaultFieldPlugin(final FieldTypeContext context, final TypeDescriptor descriptor) { @@ -253,7 +274,7 @@ public class FieldTypeUtils { public static Set<String> getUnsupportedFieldTypes(final ContentTypeContext context) { return NamespaceUtils.retrieveFieldSorter(context.getContentTypeRoot()) .map(fieldSorter -> fieldSorter.sortFields(context).stream() - .filter(fieldTypeContext -> determineFieldType(fieldTypeContext).isEmpty()) + .filter(fieldTypeContext -> determineFieldType(fieldTypeContext).equals(FIELD_TYPE_UNKNOWN)) .map(FieldTypeUtils::mapFieldTypeName) .collect(Collectors.toCollection(TreeSet::new)) ) ===================================== content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/model/DocumentType.java ===================================== --- a/content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/model/DocumentType.java +++ b/content-service/src/main/java/org/onehippo/cms/channelmanager/content/documenttype/model/DocumentType.java @@ -38,6 +38,8 @@ public class DocumentType { private boolean allFieldsIncluded; private boolean allRequiredFieldsIncluded; private final List<FieldType> fields; // ordered list of fields + + @JsonInclude(Include.NON_EMPTY) private Set<String> unsupportedFieldTypes = null; // for reporting purposes public DocumentType() { View it on GitLab: https://code.onehippo.org/cms-community/hippo-addon-channel-manager/compare/0d4ea076ce139a28ed6250cb9d30aa03df8c5932...6461285bddc59addca880c640c12612fd14bf412 --- View it on GitLab: https://code.onehippo.org/cms-community/hippo-addon-channel-manager/compare/0d4ea076ce139a28ed6250cb9d30aa03df8c5932...6461285bddc59addca880c640c12612fd14bf412 You're receiving this email because of your account on code.onehippo.org.
_______________________________________________ Hippocms-svn mailing list Hippocms-svn@lists.onehippo.org https://lists.onehippo.org/mailman/listinfo/hippocms-svn