Skip to content

Commit f68eaa9

Browse files
author
jmiranda
committed
Added simple annotation converter implementation and configuration
Added JWT token implementation (required commons-codec library) Refactored annotator service (needs tests and a bit more love as I seem to have broken some of the API calls)
1 parent fbf53f2 commit f68eaa9

File tree

11 files changed

+435
-61
lines changed

11 files changed

+435
-61
lines changed

grails-app/conf/BuildConfig.groovy

+10-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ grails.project.dependency.resolution = {
1212
inherits("global") {
1313
// uncomment to disable ehcache
1414
// excludes 'ehcache'
15+
excludes 'commons-codec'
1516
}
1617
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
1718
repositories {
@@ -35,13 +36,15 @@ grails.project.dependency.resolution = {
3536

3637
// runtime 'mysql:mysql-connector-java:5.1.5'
3738
//compile "org.semweb4j:rdf2go.api:4.6.2"
38-
39-
compile "org.apache.marmotta:sesame-tools-rio-jsonld:3.0.0-incubating"
40-
compile "org.semweb4j:rdf2go.impl.sesame:4.8.2"
41-
compile "org.semweb4j:rdf2go.api:4.8.2"
42-
43-
runtime "org.semweb4j:rdf2go.impl.sesame:4.8.2"
44-
runtime "org.semweb4j:rdf2go.api:4.8.2"
39+
40+
//compile 'commons-codec:commons-codec:1.5'
41+
compile ("org.apache.marmotta:sesame-tools-rio-jsonld:3.0.0-incubating")
42+
compile ("org.semweb4j:rdf2go.impl.sesame:4.8.2")
43+
compile ("org.semweb4j:rdf2go.api:4.8.2")
44+
compile ("com.nimbusds:nimbus-jose-jwt:2.18")
45+
compile ("com.googlecode.jsontoken:jsontoken:1.0")
46+
//runtime "org.semweb4j:rdf2go.impl.sesame:4.8.2"
47+
//runtime "org.semweb4j:rdf2go.api:4.8.2"
4548
//compile "org.semweb4j:rdf2go.impl.base:4.6.2"
4649
//compile "org.openrdf:openrdf-sesame-onejar-osgi:2.1.2"
4750
//compile "org.openrdf.sesame:sesame-query:2.7.2"

grails-app/conf/Config.groovy

+11
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,14 @@ log4j = {
2222

2323
warn 'org.mortbay.log'
2424
}
25+
26+
// FIXME I do not think this needs to be added to each plugin Config.groovy, but I had to add it in order to keep from
27+
// getting the following error when running tests
28+
// Error Error executing script TestApp: java.lang.NullPointerException: Cannot invoke method newInstance() on null object (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
29+
// java.lang.NullPointerException: Cannot invoke method newInstance() on null object
30+
grails.plugins.springsecurity.userLookup.userDomainClassName = 'org.mindinformatics.ann.framework.module.security.users.User'
31+
grails.plugins.springsecurity.userLookup.authorityJoinClassName = 'org.mindinformatics.ann.framework.module.security.users.UserRole'
32+
grails.plugins.springsecurity.authority.className = 'org.mindinformatics.ann.framework.module.security.users.Role'
33+
grails.plugins.springsecurity.rememberMe.persistent = true
34+
grails.plugins.springsecurity.rememberMe.persistentToken.domainClassName = 'org.mindinformatics.ann.framework.module.security.PersistentLogin'
35+
grails.plugins.springsecurity.openid.domainClass = 'org.mindinformatics.ann.framework.module.security.OpenID'
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,76 @@
11
package org.mindinformatics.ann.framework.module.persistence
22

33
import grails.converters.JSON
4+
import org.codehaus.groovy.grails.web.json.JSONObject
45

56
class AnnotatorController {
67

7-
static allowedMethods = [create:'POST', destroy:'DELETE', update: 'PUT', search: 'GET', read: 'GET']
8+
def annotatorService
89

9-
def index() {}
10+
static allowedMethods = [create:'POST', destroy:'DELETE', update: 'PUT', search: 'GET', read: 'GET']
1011

12+
/**
13+
*
14+
* @return
15+
*/
16+
def index() {
17+
println "Index " + params
18+
def apiResponse = [
19+
"name": "Annotator Store API",
20+
"version": getGrailsApplication().metadata["app.version"]]
21+
render (apiResponse as JSON)
22+
}
1123

24+
/**
25+
*
26+
* https://github.com/okfn/annotator/wiki/Authentication
27+
* @return
28+
*/
1229
def token() {
13-
println "Get token: " + params
14-
def jsonObject = request.JSON
15-
println "JSON " + jsonObject.toString()
16-
17-
render(status: 200, text: "your-token-has-been-created")
30+
//println "Get token: " + params
31+
//def jsonObject = request.JSON
32+
//println "JSON " + jsonObject.toString()
33+
//response.status = 200
34+
render(status: 200, text: annotatorService.getToken())
35+
//render(status: 200, text: "your-token-has-been-created")
1836
//render(status: 503, text: 'Failed to create annotation' + annotation.errors)
1937
}
2038

2139
def read() {
22-
println "read annotation " + params
40+
println "Read " + params
2341
def jsonObject = request.JSON
42+
println "JSON " + jsonObject.toString()
43+
44+
def annotation = Annotation.get(params.id)
45+
if (annotation) {
46+
render annotation.toJSONObject() as JSON
47+
}
48+
else {
49+
def message = "Unable to locate annotation with ID ${params.id}"
50+
render([status: 503, text: message] as JSON)
51+
52+
}
2453

2554
}
2655

2756
def create() {
57+
println "Create " + params
58+
println "JSON = " + request.JSON
59+
def annotation = annotatorService.create(request.JSON)
60+
61+
// Need to find a way to handle errors
62+
if (!annotation.hasErrors()) {
63+
println "Saved annotation " + annotation.toJSONObject()
64+
//render annotation.toJSONObject() as JSON
65+
redirect(action: "read", id: annotation.id)
66+
}
67+
else {
68+
println "Annotation has errors " + annotation.errors
69+
render([status: 503, text: 'Unable to create annotation', errors: annotation.errors]as JSON)
70+
}
71+
72+
73+
/*
2874
println "create annotation " + params
2975
def jsonObject = request.JSON
3076
println "JSON = " + jsonObject
@@ -39,29 +85,28 @@ class AnnotatorController {
3985
}
4086
else {
4187
render([status: 503, text: 'Unable to create annotation', errors: annotation.errors]as JSON)
42-
}
88+
}*/
4389
}
4490

4591

46-
4792
def update() {
48-
println "update annotation " + params
93+
println "Update " + params
4994
def jsonObject = request.JSON
5095
println "JSON " + jsonObject.toString()
5196

97+
def annotation = annotatorService.update(jsonObject)
98+
//def annotation = Annotation.get(params.id)
99+
//annotation.text = jsonObject.text
100+
//annotation.quote = jsonObject.quote
101+
//annotation.json = jsonObject.toString()
102+
//annotation.save()
52103

53-
def annotation = Annotation.get(params.id)
54-
annotation.text = jsonObject.text
55-
annotation.quote = jsonObject.quote
56-
annotation.json = jsonObject
57-
annotation.save()
58-
59-
render annotation as JSON
60-
104+
//render annotation.toJSONObject() as JSON
105+
redirect(action: "read", id: annotation.id)
61106
}
62107

63108
def destroy() {
64-
println "destroy annotation " + params
109+
println "Destroy " + params
65110
def jsonObject = request.JSON
66111
println "JSON " + jsonObject.toString()
67112

@@ -70,19 +115,27 @@ class AnnotatorController {
70115
annotation.delete()
71116

72117
// Return the list of remaining annotations for this page
73-
def annotations = Annotation.findAllByUri(jsonObject.uri)
74-
println "annotations: " + annotations.size()
75-
render ([total: annotations.size, rows: annotations] as JSON)
118+
//def annotations = Annotation.findAllByUri(jsonObject.uri)
119+
//println "annotations: " + annotations.size()
120+
//render ([total: annotations.size, rows: annotations] as JSON)
121+
response.status = 204
122+
}
76123

124+
def list() {
125+
println "List " + params
126+
def results = Annotation.list().collect { it.toJSONObject() }
127+
render (results as JSON)
77128
}
78129

130+
def annotations() {
131+
redirect(action: "list")
132+
}
133+
134+
79135
def search() {
80-
println "search annotations " + params
136+
println "Search annotations " + params
81137
def jsonObject = request.JSON
82-
println "JSON = " + jsonObject.toString()
83-
84-
def annotations = Annotation.findAllByUri(params.uri)
85-
println "annotations: " + annotations.size()
86-
render ([total: annotations.size, rows: annotations] as JSON)
138+
def results = annotatorService.search(params.uri)
139+
render ([total: results.size(), rows: results] as JSON)
87140
}
88141
}

grails-app/domain/org.mindinformatics.ann.framework.module.persistence/Annotation.groovy

-25
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.mindinformatics.ann.framework.module.persistence
2+
3+
import org.codehaus.groovy.grails.web.json.JSONObject
4+
import org.mindinformatics.ann.framework.module.security.users.User
5+
6+
class Annotation {
7+
8+
String uri
9+
String json
10+
//String text
11+
//String quote
12+
13+
Date dateCreated
14+
Date lastUpdated
15+
16+
User owner
17+
18+
//static hasMany = [ranges : AnnotationRange]
19+
20+
static constraints = {
21+
uri(nullable: false)
22+
json(nullable: false)
23+
owner(nullable: true)
24+
//text(nullable: true)
25+
//quote(nullable: false)
26+
}
27+
28+
static mapping = {
29+
uri sqlType:"text"
30+
json sqlType:"text"
31+
//text sqlType:"text"
32+
//quote sqlType:"text"
33+
}
34+
35+
36+
JSONObject toJSONObject() {
37+
println "toJSONObject " + json
38+
if (!json) {
39+
throw new RuntimeException("Cannot convert to JSON when object is empty")
40+
}
41+
42+
def jsonObject = new JSONObject()
43+
jsonObject["id"] = id
44+
println "jsonObject: " + jsonObject
45+
return jsonObject
46+
47+
}
48+
49+
50+
}

grails-app/domain/org.mindinformatics.ann.framework.module.persistence/AnnotationRange.groovy grails-app/domain/org/mindinformatics/ann/framework/module/persistence/AnnotationRange.groovy

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class AnnotationRange {
77
Integer endOffset
88
Integer startOffset
99

10+
Date dateCreated
11+
Date lastUpdated
12+
1013
static belongsTo = [annotation:Annotation]
1114

1215
static constraints = {

0 commit comments

Comments
 (0)