Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in method getCompleteness of ModelUtilities #166

Open
Ludovic99 opened this issue Dec 10, 2021 · 0 comments
Open

Bug in method getCompleteness of ModelUtilities #166

Ludovic99 opened this issue Dec 10, 2021 · 0 comments

Comments

@Ludovic99
Copy link

Method addCanvas of class Range fails with message:

Exception in thread "main" java.lang.IllegalArgumentException: Member resource must only have an identifier and no other field. Use add<Resource>(URI first, URI... rest) for convenience.
	at de.digitalcollections.iiif.model.sharedcanvas.Range.checkIdOnly(Range.java:98)
	at de.digitalcollections.iiif.model.sharedcanvas.Range.addCanvas(Range.java:113)

It can be reproduced with:

import de.digitalcollections.iiif.model.sharedcanvas.Range;
class Test {
  public static void main(String[] args) {
    Range range = new Range("http://test/foo");
    range.addCanvas("http://test/baz");
  }
}

The cause is in method getCompleteness of ModelUtilities: the method getClass of Object is not filtered.
It could be replaced by:

  public static Completeness getCompleteness(Object res, Class<?> type) {
    Set<Method> getters =
        ReflectionUtils.getAllMethods(
            type, ReflectionUtils.withModifier(Modifier.PUBLIC), ReflectionUtils.withPrefix("get"));
    Set<String> gettersWithValues =
        getters.stream()
            .filter(g -> !g.getName().equals("getClass"))
            .filter(g -> g.getAnnotation(JsonIgnore.class) == null) // Only JSON-serializable fields
            .filter(g -> returnsValue(g, res))
            .map(Method::getName)
            .collect(Collectors.toSet());

    if (gettersWithValues.isEmpty()) {
      return Completeness.EMPTY;
    } else if (containsOnly(gettersWithValues, "getType", "getIdentifier")) {
      return Completeness.ID_AND_TYPE;
    } else if (containsOnly(gettersWithValues, "getType", "getIdentifier", "getLabels")) {
      return Completeness.ID_AND_TYPE_AND_LABEL;
    } else if (containsOnly(gettersWithValues, "getIdentifier")) {
      return Completeness.ID_ONLY;
    } else {
      return Completeness.COMPLEX;
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant