Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
O
openebench-rest-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
INB
ELIXIR
OpenEBench
openebench-rest-api
Commits
b4bf835c
Commit
b4bf835c
authored
Jan 21, 2021
by
redmitry@list.ru
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add json path to get partial object
parent
b5a54112
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
7 deletions
+63
-7
src/main/java/es/bsc/inb/elixir/openebench/rest/OpenEBenchService.java
.../es/bsc/inb/elixir/openebench/rest/OpenEBenchService.java
+29
-5
src/main/java/es/bsc/inb/elixir/openebench/rest/dao/AbstractDatabase.java
.../bsc/inb/elixir/openebench/rest/dao/AbstractDatabase.java
+34
-2
No files found.
src/main/java/es/bsc/inb/elixir/openebench/rest/OpenEBenchService.java
View file @
b4bf835c
...
...
@@ -175,20 +175,44 @@ public abstract class OpenEBenchService {
@GET
@Path
(
"/{collection}/{id : .*}"
)
@Path
(
"/Reference/{id : .*}"
)
@PermitAll
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
Response
getObject
(
@Context
SecurityContext
sc
,
@PathParam
(
"id"
)
@Parameter
(
description
=
"reference id"
,
example
=
"doi.org:10.7490/f1000research.1116968.1"
)
@Encoded
final
String
id
)
{
final
String
object
=
dao
().
getObject
(
id
,
"Reference"
,
sc
);
if
(
object
==
null
)
{
return
Response
.
status
(
Status
.
NOT_FOUND
).
build
();
}
if
(
"{}"
.
equals
(
object
))
{
return
Response
.
status
(
Status
.
UNAUTHORIZED
).
build
();
}
return
Response
.
ok
(
object
,
MediaType
.
APPLICATION_JSON
).
build
();
}
@GET
@Path
(
"/{collection}/{id:.[^/]*}{path : .*}"
)
@PermitAll
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
Response
getObject
(
@Context
SecurityContext
sc
,
@PathParam
(
"collection"
)
@Parameter
(
description
=
"OpenEBench collection"
,
example
=
"Contact"
)
@Encoded
final
String
collection
,
final
String
collection
,
@PathParam
(
"id"
)
@Parameter
(
description
=
"object id"
,
example
=
"OEBD00200001FO"
)
@Encoded
final
String
id
)
{
@Encoded
final
String
id
,
@PathParam
(
"path"
)
@Parameter
(
description
=
"JSON path "
,
example
=
""
)
final
String
path
)
{
final
String
object
=
dao
().
getObject
(
id
,
collection
,
sc
);
final
String
object
=
dao
().
getObject
(
id
,
collection
,
path
,
sc
);
if
(
object
==
null
)
{
return
Response
.
status
(
Status
.
NOT_FOUND
).
build
();
}
...
...
@@ -196,5 +220,5 @@ public abstract class OpenEBenchService {
return
Response
.
status
(
Status
.
UNAUTHORIZED
).
build
();
}
return
Response
.
ok
(
object
,
MediaType
.
APPLICATION_JSON
).
build
();
}
}
}
src/main/java/es/bsc/inb/elixir/openebench/rest/dao/AbstractDatabase.java
View file @
b4bf835c
...
...
@@ -37,11 +37,18 @@ import com.mongodb.client.model.Projections;
import
es.bsc.inb.elixir.openebench.rest.auth.AbstractAuthorization
;
import
es.bsc.inb.elixir.openebench.rest.auth.Authorization
;
import
es.bsc.inb.elixir.openebench.rest.auth.CollectionAuthorizationFilter
;
import
java.io.StringReader
;
import
java.io.Writer
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
javax.annotation.PreDestroy
;
import
javax.inject.Inject
;
import
javax.json.Json
;
import
javax.json.JsonException
;
import
javax.json.JsonPointer
;
import
javax.json.JsonReader
;
import
javax.json.JsonStructure
;
import
javax.json.JsonValue
;
import
javax.servlet.ServletContext
;
import
javax.ws.rs.core.SecurityContext
;
import
org.bson.AbstractBsonWriter
;
...
...
@@ -140,6 +147,11 @@ public abstract class AbstractDatabase {
}
public
String
getObject
(
final
String
id
,
final
String
collection
,
final
SecurityContext
sc
)
{
return
getObject
(
id
,
collection
,
null
,
sc
);
}
public
String
getObject
(
final
String
id
,
final
String
collection
,
final
String
path
,
final
SecurityContext
sc
)
{
final
AbstractAuthorization
authz
=
authorization
.
getAuthorization
(
sc
,
collection
);
if
(
authz
==
null
)
{
...
...
@@ -155,8 +167,28 @@ public abstract class AbstractDatabase {
if
(
iterator
.
hasNext
())
{
final
Document
doc
=
iterator
.
next
();
if
(
doc
!=
null
)
{
doc
.
remove
(
PROVENANCE_PROPERTY
);
return
doc
.
toJson
();
if
(
path
==
null
||
path
.
isEmpty
())
{
doc
.
remove
(
PROVENANCE_PROPERTY
);
return
doc
.
toJson
();
}
JsonPointer
pointer
;
try
{
pointer
=
Json
.
createPointer
(
path
);
}
catch
(
Exception
ex
)
{
Logger
.
getLogger
(
AbstractDatabase
.
class
.
getName
()).
log
(
Level
.
INFO
,
null
,
ex
);
return
null
;
}
try
(
JsonReader
reader
=
Json
.
createReader
(
new
StringReader
(
doc
.
toJson
())))
{
final
JsonStructure
structure
=
reader
.
read
();
if
(
pointer
.
containsValue
(
structure
))
{
return
pointer
.
getValue
(
structure
).
toString
();
}
}
catch
(
JsonException
ex
)
{
Logger
.
getLogger
(
AbstractDatabase
.
class
.
getName
()).
log
(
Level
.
INFO
,
null
,
ex
);
}
return
null
;
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment