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

Optional updates #197

Merged
merged 8 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<jackson.version>2.17.2</jackson.version>
<jackson.databind.version>2.17.2</jackson.databind.version>
<throwing.function.version>1.5.1</throwing.function.version>
<freelib.utils.version>5.0.4</freelib.utils.version>
<freelib.utils.version>5.0.5</freelib.utils.version>
<jsoup.version>1.18.1</jsoup.version>
<combinatorics.version>3.3.0</combinatorics.version>
<media.fragments.uri.version>2.4</media.fragments.uri.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ abstract class AbstractCanvas<T extends AbstractCanvas<T>> extends NavigableReso
/** The canvas' optional minter. */
private Minter myMinter;

/** The canvas' other canvases (other than painting or supplementing). */
private List<AnnotationPage<WebAnnotation>> myOtherAnnotations;

/** The painting annotations on the canvas. */
private List<AnnotationPage<PaintingAnnotation>> myPaintingPageList;

/** The supplementing annotations on the canvas. */
private List<AnnotationPage<SupplementingAnnotation>> mySupplementingPageList;

/** The canvas' other canvases (other than painting or supplementing). */
private List<AnnotationPage<WebAnnotation>> myWebAnnotations;

/** The canvas' width. */
private int myWidth;

Expand Down Expand Up @@ -149,8 +149,7 @@ public boolean equals(final Object aObject) {
other = (AbstractCanvas<T>) aObject;

return Objects.equals(myDuration, other.myDuration) && Objects.equals(myHeight, other.myHeight) &&
Objects.equals(myWidth, other.myWidth) &&
Objects.equals(myOtherAnnotations, other.myOtherAnnotations) &&
Objects.equals(myWidth, other.myWidth) && Objects.equals(myWebAnnotations, other.myWebAnnotations) &&
Objects.equals(myPaintingPageList, other.myPaintingPageList) &&
Objects.equals(mySupplementingPageList, other.mySupplementingPageList) && super.equals(other);
}
Expand Down Expand Up @@ -187,20 +186,6 @@ public Optional<Minter> getMinter() {
return Optional.ofNullable(myMinter);
}

/**
* Gets the canvas' annotation pages that aren't related to painting.
*
* @return The canvas' non-painting annotation pages
*/
@JsonIgnore
public List<AnnotationPage<WebAnnotation>> getOtherAnnotations() {
if (myOtherAnnotations == null) {
myOtherAnnotations = new ArrayList<>();
}

return myOtherAnnotations;
}

/**
* Gets the canvas' annotation pages for painting annotations.
*
Expand Down Expand Up @@ -230,6 +215,20 @@ public List<AnnotationPage<SupplementingAnnotation>> getSupplementingPages() {
return mySupplementingPageList;
}

/**
* Gets the canvas' annotation pages that aren't related to painting.
*
* @return The canvas' non-painting annotation pages
*/
@JsonIgnore
public List<AnnotationPage<WebAnnotation>> getWebAnnotations() {
if (myWebAnnotations == null) {
myWebAnnotations = new ArrayList<>();
}

return myWebAnnotations;
}

/**
* Gets the width of the canvas.
*
Expand All @@ -243,7 +242,7 @@ public int getWidth() {

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), myDuration, myHeight, myWidth, myOtherAnnotations, myPaintingPageList,
return Objects.hash(super.hashCode(), myDuration, myHeight, myWidth, myWebAnnotations, myPaintingPageList,
mySupplementingPageList);
}

Expand Down Expand Up @@ -309,36 +308,6 @@ public T setMinter(final Minter aMinter) {
return (T) this;
}

/**
* Sets the canvas' annotation pages from an array.
*
* @param aAnnotationArray An array of annotation pages
* @return The canvas
*/
@JsonIgnore
@SafeVarargs
public final T setOtherAnnotations(final AnnotationPage<WebAnnotation>... aAnnotationArray) {
return setOtherAnnotations(Arrays.asList(aAnnotationArray));
}

/**
* Sets the canvas annotation pages from a list.
*
* @param aAnnotationList A list of annotation pages
* @return The canvas
*/
@JsonIgnore
@SuppressWarnings({ JDK.UNCHECKED })
public T setOtherAnnotations(final List<AnnotationPage<WebAnnotation>> aAnnotationList) {
final List<AnnotationPage<WebAnnotation>> annotations = getOtherAnnotations();

Objects.requireNonNull(aAnnotationList);
annotations.clear();
annotations.addAll(aAnnotationList);

return (T) this;
}

/**
* Sets the canvas' painting pages.
*
Expand Down Expand Up @@ -409,6 +378,36 @@ public T setSupplementingPages(final List<AnnotationPage<SupplementingAnnotation
return (T) this;
}

/**
* Sets the canvas' annotation pages from an array.
*
* @param aAnnotationArray An array of annotation pages
* @return The canvas
*/
@JsonIgnore
@SafeVarargs
public final T setWebAnnotations(final AnnotationPage<WebAnnotation>... aAnnotationArray) {
return setWebAnnotations(Arrays.asList(aAnnotationArray));
}

/**
* Sets the canvas annotation pages from a list.
*
* @param aAnnotationList A list of annotation pages
* @return The canvas
*/
@JsonIgnore
@SuppressWarnings({ JDK.UNCHECKED })
public T setWebAnnotations(final List<AnnotationPage<WebAnnotation>> aAnnotationList) {
final List<AnnotationPage<WebAnnotation>> annotations = getWebAnnotations();

Objects.requireNonNull(aAnnotationList);
annotations.clear();
annotations.addAll(aAnnotationList);

return (T) this;
}

/**
* Sets the width and height of the canvas.
*
Expand All @@ -430,17 +429,6 @@ public T setWidthHeight(final int aWidth, final int aHeight) {
return (T) this;
}

/**
* Gets the manifest context. The manifest can either have a single context or an array of contexts (Cf.
* https://iiif.io/api/presentation/3.0/#46-linked-data-context-and-extensions)
*
* @return The manifest context
*/
@Override
@JsonGetter(JsonKeys.CONTEXT)
@JsonInclude(Include.NON_NULL)
protected abstract Object getJsonContext();

/**
* Paints a canvas, that has been initialized with a minter, with the supplied content resources. If the canvas was
* not initialized with a minter, a {@code MintingException} is thrown.
Expand Down Expand Up @@ -731,7 +719,7 @@ private List<AnnotationPage<?>> getAnnotations() {
final List<AnnotationPage<?>> annotations = new ArrayList<>();

getSupplementingPages().forEach(annotations::add);
getOtherAnnotations().forEach(annotations::add);
getWebAnnotations().forEach(annotations::add);

return annotations;
}
Expand Down Expand Up @@ -908,7 +896,7 @@ private Minter getMinter(final String aMessageCode) {
@JsonSetter(JsonKeys.ANNOTATIONS)
private <A extends Annotation<A>> AbstractCanvas<T> setAnnotations(final Object aObject) {
final List<AnnotationPage<SupplementingAnnotation>> supplementingPages = getSupplementingPages();
final List<AnnotationPage<WebAnnotation>> otherAnnotations = getOtherAnnotations();
final List<AnnotationPage<WebAnnotation>> otherAnnotations = getWebAnnotations();
final List<AnnotationPage<A>> annotationList = getDeserializedPageList(aObject);

supplementingPages.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public List<AnnotationPage<WebAnnotation>> getAnnotations() {
*
* @return The media type format of the content resource
*/
@JsonInclude(Include.NON_EMPTY)
@JsonSerialize(contentUsing = MediaTypeSerializer.class, keyUsing = MediaTypeKeySerializer.class)
public Optional<MediaType> getFormat() {
return Optional.ofNullable(myFormat);
Expand Down Expand Up @@ -189,7 +188,6 @@ public T setFormat(final MediaType aMediaType) {
* @return A form of language ready to be serialized
*/
@JsonGetter(JsonKeys.LANGUAGE)
@JsonInclude(Include.NON_EMPTY)
private Object getLanguage() {
final List<String> languages = getLanguages();
return languages.size() == SINGLE_INSTANCE ? languages.get(0) : languages;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@

package info.freelibrary.iiif.presentation.v3;

import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

Expand Down Expand Up @@ -54,9 +53,6 @@
JsonKeys.ITEMS, JsonKeys.SERVICE, JsonKeys.STRUCTURES, JsonKeys.SERVICES, JsonKeys.NAV_DATE, JsonKeys.ANNOTATIONS })
abstract class AbstractResource<T extends AbstractResource<T>> implements Resource<T> {

/** The IIIF Presentation context URI. */
protected static final URI PRESENTATION_CONTEXT_URI = URI.create("http://iiif.io/api/presentation/3/context.json");

/** The logger used by abstract resources. */
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractResource.class, MessageCodes.BUNDLE);

Expand Down Expand Up @@ -229,9 +225,9 @@ public String getID() {
* @return The label
*/
@Override
@JsonUnwrapped
public Label getLabel() {
return myLabel;
@JsonGetter(JsonKeys.LABEL)
public Optional<Label> getLabel() {
return Optional.ofNullable(myLabel);
}

/**
Expand Down Expand Up @@ -297,8 +293,8 @@ public List<Rendering> getRenderings() {
*/
@Override
@JsonGetter(JsonKeys.REQUIRED_STATEMENT)
public RequiredStatement getRequiredStatement() {
return myRequiredStatement;
public Optional<RequiredStatement> getRequiredStatement() {
return Optional.ofNullable(myRequiredStatement);
}

/**
Expand All @@ -308,8 +304,8 @@ public RequiredStatement getRequiredStatement() {
*/
@Override
@JsonProperty
public String getRights() {
return myRights;
public Optional<String> getRights() {
return Optional.ofNullable(myRights);
}

/**
Expand Down Expand Up @@ -348,9 +344,9 @@ public List<Service> getServices() {
* @return The summary
*/
@Override
@JsonUnwrapped
public Summary getSummary() {
return mySummary;
@JsonGetter(JsonKeys.SUMMARY)
public Optional<Summary> getSummary() {
return Optional.ofNullable(mySummary);
}

/**
Expand Down Expand Up @@ -672,6 +668,7 @@ public T setServices(final Service... aServiceArray) {
* @return The resource
*/
@Override
@JsonSetter(JsonKeys.SUMMARY)
@SuppressWarnings(JDK.UNCHECKED)
public T setSummary(final Summary aSummary) {
Objects.requireNonNull(aSummary);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,4 @@ public final AccompanyingCanvas supplementWith(final String aCanvasRegion,
final List<ContentResource> aContentList) {
return super.supplement(this, new MediaFragmentSelector(aCanvasRegion), false, aContentList);
}

@Override
protected Object getJsonContext() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public <T extends Annotation<T>> Optional<AnnotationPage<T>> getLastPage() {
* @return The viewing direction
*/
@JsonGetter(JsonKeys.VIEWING_DIRECTION)
public ViewingDirection getViewingDirection() {
return myViewingDirection;
public Optional<ViewingDirection> getViewingDirection() {
return Optional.ofNullable(myViewingDirection);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonSetter;

import info.freelibrary.util.Logger;
Expand All @@ -33,6 +35,7 @@
* @param <A> The type of annotation encapsulated on the page
*/
@SuppressWarnings({ PMD.GOD_CLASS, PMD.EXCESSIVE_IMPORTS, PMD.COUPLING_BETWEEN_OBJECTS })
@JsonInclude(Include.NON_EMPTY)
public class AnnotationPage<A extends Annotation<A>> extends AbstractResource<AnnotationPage<A>>
implements Resource<AnnotationPage<A>> {

Expand Down Expand Up @@ -256,13 +259,14 @@ public <T extends Annotation<T>> AnnotationPage<A> setNextPage(final AnnotationP
}

/**
* Gets the context when the annotation page is intended to be used outside of a manifest.
* Gets the context only when the annotation page is intended to be used outside of a manifest, as indicated by
* using {@code AnnotationPage#setExternalContext()}.
*
* @return The context URI
*/
@JsonGetter(JsonKeys.CONTEXT)
private URI getExternalContext() {
return isExternal ? PRESENTATION_CONTEXT_URI : null;
private Optional<URI> getExternalContext() {
return isExternal ? Optional.of(ContextList.PRESENTATION_CONTEXT_URI) : Optional.empty();
}

/**
Expand Down Expand Up @@ -293,7 +297,7 @@ private String getListIDs(final List<A> aAnnotationList) {
*/
@JsonSetter(JsonKeys.CONTEXT)
private AnnotationPage<A> setExternalContext(final String aContextURI) {
if (PRESENTATION_CONTEXT_URI.toString().equalsIgnoreCase(aContextURI)) {
if (ContextList.PRESENTATION_CONTEXT_URI.toString().equalsIgnoreCase(aContextURI)) {
setExternalContext();
}

Expand Down
Loading
Loading