Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ksclarke committed Sep 2, 2024
1 parent 668965d commit f42e9ed
Show file tree
Hide file tree
Showing 19 changed files with 897 additions and 450 deletions.
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>> myWebAnnotations;

/** 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 @@ -186,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>> getWebAnnotations() {
if (myWebAnnotations == null) {
myWebAnnotations = new ArrayList<>();
}

return myWebAnnotations;
}

/**
* Gets the canvas' annotation pages for painting annotations.
*
Expand Down Expand Up @@ -229,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 Down Expand Up @@ -308,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 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 canvas' painting pages.
*
Expand Down Expand Up @@ -408,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 @@ -429,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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

package info.freelibrary.iiif.presentation.v3;

import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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
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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,4 @@ public final Canvas supplementWith(final String aCanvasRegion, final ContentReso
public final Canvas 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
@@ -1,7 +1,6 @@

package info.freelibrary.iiif.presentation.v3;

import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -67,13 +66,15 @@ public class Collection extends NavigableResource<Collection> implements Resourc
*/
public Collection(final String aID, final Label aLabel) {
super(ResourceTypes.COLLECTION, aID, aLabel, CollectionBehavior.class);
getContextList(); // Initializes the context list
}

/**
* Creates a new collection. This is used by Jackson's deserialization processes.
*/
private Collection() {
super(ResourceTypes.COLLECTION, CollectionBehavior.class);
getContextList(); // Initializes the context list
}

@Override
Expand Down Expand Up @@ -124,17 +125,6 @@ public List<AnnotationPage<WebAnnotation>> getAnnotations() {
return myAnnotations;
}

/**
* Gets the primary collection context.
*
* @return The collection context
*/
@Override
@JsonIgnore
public URI getContext() {
return PRESENTATION_CONTEXT_URI;
}

/**
* Gets the items associated with this collection.
*
Expand Down
Loading

0 comments on commit f42e9ed

Please sign in to comment.