glenrobson / SimpleAnnotationServer

A simple IIIF and Mirador compatible Annotation Server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Annotations not saved in mirador 2.1.4 or 2.1.1 or 2.20

mel-mason opened this issue · comments

If I draw an annotation on an image and save it, it disappears. Either immediately, on 2.1.1, or once I close the annotation icons or refresh on 2.1.4. It works with the 2.0.0 version the annotation server release (up to date as of November 2016) came with. I've tried it both with the mirador release copied to webapp/mirador, and with it referencing it from a different location.

Error:
POST http://iiif.bodleian.ox.ac.uk/annotation-server/annotation/create?APIKey=undefined 500 (java.util.ArrayList cannot be cast to java.lang.String)
(anonymous) @ VM156:2
send @ jquery.min.js:4
ajax @ jquery.min.js:4
a.ajax @ jquery-migrate-3.0.0.min.js:2
create @ simpleASEndpoint.js:163
(anonymous) @ window.js:389
dispatch @ jquery.min.js:3
q.handle @ jquery.min.js:3
trigger @ jquery.min.js:4
(anonymous) @ jquery.min.js:4
each @ jquery.min.js:2
each @ jquery.min.js:2
trigger @ jquery.min.js:4
n.publish @ pubsub.min.js:4
$.EventEmitter.(anonymous function) @ eventemitter.js:31
(anonymous) @ osd-svg-overlay.js:359
dispatch @ jquery.min.js:3
q.handle @ jquery.min.js:3
trigger @ jquery.min.js:4
(anonymous) @ jquery.min.js:4
each @ jquery.min.js:2
each @ jquery.min.js:2
trigger @ jquery.min.js:4
n.publish @ pubsub.min.js:4
$.EventEmitter.(anonymous function) @ eventemitter.js:31
onAnnotationCreated @ osd-svg-overlay.js:1058
(anonymous) @ annotationTooltip.js:97
dispatch @ jquery.min.js:3
q.handle @ jquery.min.js:3
window.js:399 There was an error saving this new annotation

Hi,

Thanks for reporting this. The annotation structure has changed quite a bit with the new version of mirador and my code currently doesn't handle the new structure. I've created a branch mirador-2.1.4 where I've fixed the first issue on the server side but its not returning a annotation that mirador can understand so more work to do.

Note to self an example mirador2 annotation:

{
    "@context": "http://iiif.io/api/presentation/2/context.json",
    "@type": "oa:Annotation",
    "motivation": [
        "oa:tagging",
        "oa:commenting"
    ],
    "resource": [
        {
            "@type": "oa:Tag",
            "chars": "tag"
        },
        {
            "@type": "dctypes:Text",
            "format": "text/html",
            "chars": "<p>content<\/p>"
        }
    ],
    "on": [{
        "@type": "oa:SpecificResource",
        "full": "http://dms-data.stanford.edu/data/manifests/BnF/jr903ng8662/canvas/canvas-13",
        "selector": {
            "@type": "oa:Choice",
            "default": {
                "@type": "oa:FragmentSelector",
                "value": "xywh=3002,587,371,332"
            },
            "item": {
                "@type": "oa:SvgSelector",
                "value": "<svg xmlns='http://www.w3.org/2000/svg'><path xmlns=\"http://www.w3.org/2000/svg\" d=\"M3002.02122,586.53692l185.50155,0l0,0l185.50155,0l0,166.0886l0,166.0886l-185.50155,0l-185.50155,0l0,-166.0886z\" data-paper-data=\"{&quot;defaultStrokeValue&quot;:1,&quot;editStrokeValue&quot;:5,&quot;currentStrokeValue&quot;:1,&quot;rotation&quot;:0,&quot;deleteIcon&quot;:null,&quot;rotationIcon&quot;:null,&quot;group&quot;:null,&quot;editable&quot;:true,&quot;annotation&quot;:null}\" id=\"rectangle_e17b2bc5-c17b-4cfb-a4cf-6bac5a37a6e0\" fill-opacity=\"0.00001\" fill=\"#00bfff\" fill-rule=\"nonzero\" stroke=\"#00bfff\" stroke-width=\"4.31399\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-miterlimit=\"10\" stroke-dasharray=\"\" stroke-dashoffset=\"0\" font-family=\"none\" font-weight=\"none\" font-size=\"none\" text-anchor=\"none\" style=\"mix-blend-mode: normal\"/><\/svg>"
            }
        },
        "within": {
            "@id": "http://dms-data.stanford.edu/data/manifests/BnF/jr903ng8662/manifest.json",
            "@type": "sc:Manifest"
        }
    }],
    "@id": "http://localhost:8888/annotation/1488244504042"
}

Thanks

Glen

Hi,

Would it be useful to document somewhere that SimpleAnnotationStore supports at max Mirador 2.0.0 currently? I lost quite a bit of time before I worked out the above issue when I was trying to remotely talk to SimpleAnnotationServer. (Not blaming! Thanks for all the hard work.)

Cheers
--J.

cc @rsinghal @aeschylus

I think this issue derives from the changes introduced in Mirador 2.1.3:

I guess Rashmi made the choice to require the target of an annotation (on) to always be an array, because Mirador does support the creation and display of annotations with multiple targets (which allow users to draw multiple shapes on the canvas associated them with one single annotation).
The code that causes this issue with SAS is here (I guess): https://github.com/ProjectMirador/mirador/blob/develop/js/src/annotations/miradorDualStrategy.js#L17

That being said, I am not sure what would be the best way to fix this issue...
Circumvent it by adding an else condition to the Mirador code to handle annotations with on as a single object (and not only an array of objects as it is now)? This way we could at least display in Mirador single-target annotations stored in SAS... (maybe the majority of use cases)
Or change SAS to conform to the structure of the annotations that Mirador expects to display them properly? (i.e. by always giving an array in on in the json responses, even if there is one target)

A further step would be to conform to the structure of the annotations that Mirador creates and thus make SAS aware of annotations with multiple targets too.

Thanks Regis I think you've found it! I changed SAS to always return an array even if there is only one 'on' and its now working. I also tested multiple on's and they now seem to work. For future reference the two on annotation looks like:

{
  "@id" : "http://localhost:8888/annotation/1500335957389",
  "@type" : "oa:Annotation",
  "dcterms:created" : "2017-07-18T00:59:17",
  "resource" : [ {
    "@id" : "_:b6",
    "@type" : "dctypes:Text",
    "http://dev.llgc.org.uk/sas/full_text" : "Two boxes.&nbsp;",
    "format" : "text/html",
    "chars" : "<p>Two boxes.&nbsp;</p>"
  } ],
  "on" : [ {
    "@id" : "_:b3",
    "@type" : "oa:SpecificResource",
    "within" : {
      "@id" : "http://dams.llgc.org.uk/iiif/2.0/4574752/manifest.json",
      "@type" : "sc:Manifest"
    },
    "selector" : {
      "@id" : "_:b1",
      "@type" : "oa:Choice",
      "default" : {
        "@id" : "_:b0",
        "@type" : "oa:FragmentSelector",
        "value" : "xywh=2155,3081,504,191"
      },
      "item" : {
        "@id" : "_:b2",
        "@type" : "oa:SvgSelector",
        "value" : "<svg xmlns='http://www.w3.org/2000/svg'><path xmlns=\"http://www.w3.org/2000/svg\" d=\"M2154.87534,3080.721l251.93705,0l0,0l251.93705,0l0,95.56233l0,95.56233l-251.93705,0l-251.93705,0l0,-95.56233z\" data-paper-data=\"{&quot;defaultStrokeValue&quot;:1,&quot;editStrokeValue&quot;:5,&quot;currentStrokeValue&quot;:1,&quot;rotation&quot;:0,&quot;deleteIcon&quot;:null,&quot;rotationIcon&quot;:null,&quot;group&quot;:null,&quot;editable&quot;:true,&quot;annotation&quot;:null}\" id=\"rectangle_242272a8-5790-4189-912d-3198b8657d88\" fill-opacity=\"0\" fill=\"#00bfff\" fill-rule=\"nonzero\" stroke=\"#00bfff\" stroke-width=\"8.68748\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-miterlimit=\"10\" stroke-dasharray=\"\" stroke-dashoffset=\"0\" font-family=\"none\" font-weight=\"none\" font-size=\"none\" text-anchor=\"none\" style=\"mix-blend-mode: normal\"/></svg>"
      }
    },
    "full" : "http://dams.llgc.org.uk/iiif/2.0/4574752/canvas/4574755.json"
  }, {
    "@id" : "_:b4",
    "@type" : "oa:SpecificResource",
    "within" : "http://dams.llgc.org.uk/iiif/2.0/4574752/manifest.json",
    "selector" : {
      "@id" : "_:b5",
      "@type" : "oa:Choice",
      "default" : {
        "@id" : "_:b7",
        "@type" : "oa:FragmentSelector",
        "value" : "xywh=1486,2994,469,217"
      },
      "item" : {
        "@id" : "_:b8",
        "@type" : "oa:SvgSelector",
        "value" : "<svg xmlns='http://www.w3.org/2000/svg'><path xmlns=\"http://www.w3.org/2000/svg\" d=\"M1485.93904,2993.84615l234.56208,0l0,0l234.56208,0l0,108.59356l0,108.59356l-234.56208,0l-234.56208,0l0,-108.59356z\" data-paper-data=\"{&quot;defaultStrokeValue&quot;:1,&quot;editStrokeValue&quot;:5,&quot;currentStrokeValue&quot;:1,&quot;rotation&quot;:0,&quot;deleteIcon&quot;:null,&quot;rotationIcon&quot;:null,&quot;group&quot;:null,&quot;editable&quot;:true,&quot;annotation&quot;:null}\" id=\"rectangle_42dea0b7-04a9-43f2-89f1-df5b99a663c6\" fill-opacity=\"0\" fill=\"#00bfff\" fill-rule=\"nonzero\" stroke=\"#00bfff\" stroke-width=\"8.68748\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-miterlimit=\"10\" stroke-dasharray=\"\" stroke-dashoffset=\"0\" font-family=\"none\" font-weight=\"none\" font-size=\"none\" text-anchor=\"none\" style=\"mix-blend-mode: normal\"/></svg>"
      }
    },
    "full" : "http://dams.llgc.org.uk/iiif/2.0/4574752/canvas/4574755.json"
  } ],
  "motivation" : [ "oa:commenting" ],
  "@context" : "http://iiif.io/api/presentation/2/context.json"
}

If I commit this it means SAS will no longer work with older versions of mirador. Perhaps I should pass in a Mirador version along with the annotation something like:

"generator": {
    "id": "http://example.org/client1",
    "type": "Software",
    "name": "Code v2.1",
    "homepage": "http://example.org/client1/homepage1"
  },

then I could support both. Ill commit this fix to the mirador-2.1.4 SAS branch for now.

Also as per @jorisvanzundert suggestion also updated the main readme file to reference this issue.

Thanks Glen :) It is great if SAS supports multiple on, I will test the mirador-2.1.4 branch as soon as possible!

I just tested the updated mirador-2.1.4 branch and I had an issue while saving an annotation.
The Java error is:

SEVERE [http-nio-8080-exec-21] org.apache.catalina.core.StandardWrapperValve.invoke "Servlet.service()" pour la servlet Create a généré une exception
 java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map
	at uk.org.llgc.annotation.store.adapters.SesameStore.addAnnotationSafe(SesameStore.java:81)
	at uk.org.llgc.annotation.store.adapters.AbstractStoreAdapter.addAnnotation(AbstractStoreAdapter.java:90)

I have commented these two lines in SesameStore.java and now it seems to work like a charm:

//Map<String,Object> tOn = (Map<String,Object>)pJson.get("on");
//tOn.remove("scope");

Do we still need those lines? At first glance it does not seem to be the case since we do not need to get rid of the scope property anymore (at least in this branch).

Thanks Regis, I've committed a fix to the mirador-2.1.4. Your right that its not used in the latest mirador but rather than break older versions I've wrapped the scope removal in an if statement.

I've been thinking about the fix for the original issue and I wonder if I should change the simpleASEndpoint.js to convert the object into an array rather than the SAS code so that the SAS code can support earlier versions of mirador (we have a few still running in NLW). What do you think?

I am inclined to think it would be easier to handle that in the JS adapter rather than in the server code... (seems appropriate if the idea is to force Mirador to conform to what SAS expects) but on the other hand it tends to restrain SAS to communicate with Mirador (but are there any other IIIF compatible annotation clients in the wild?)

Fixed this in SAS and merged the mirador-2.1.4 branch in to master. It should now be possible to annotate using any version of Mirador. Let me know if you find any issues.