Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
45
Issues
45
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
2d343e50
Commit
2d343e50
authored
Feb 27, 2014
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
REST /acn/{instcode}/check does not require genus or instCode
parent
5fd05216
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
28 deletions
+32
-28
src/main/java/org/genesys2/server/servlet/controller/rest/AccessionController.java
...2/server/servlet/controller/rest/AccessionController.java
+32
-28
No files found.
src/main/java/org/genesys2/server/servlet/controller/rest/AccessionController.java
View file @
2d343e50
...
...
@@ -17,6 +17,7 @@
package
org.genesys2.server.servlet.controller.rest
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -29,6 +30,7 @@ import org.genesys2.server.service.GeoService;
import
org.genesys2.server.service.InstituteService
;
import
org.genesys2.server.service.TaxonomyService
;
import
org.genesys2.server.service.impl.RESTApiException
;
import
org.genesys2.server.service.impl.RESTApiValueException
;
import
org.genesys2.server.servlet.controller.rest.model.AccessionJson
;
import
org.genesys2.server.servlet.controller.rest.model.AccessionNamesJson
;
import
org.genesys2.spring.ResourceNotFoundException
;
...
...
@@ -97,53 +99,55 @@ public class AccessionController extends RestController {
* @return
* @throws IOException
* @throws JsonProcessingException
* @throws RESTApiValueException
*/
@RequestMapping
(
value
=
"/{instCode}/check"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
PUT
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
@ResponseBody
JsonNode
check
(
@PathVariable
(
"instCode"
)
String
instCode
,
@RequestBody
String
content
)
throws
JsonProcessingException
,
IOException
{
// TODO Check user's permissions to update this WIEWS institute.
JsonNode
check
(
@PathVariable
(
"instCode"
)
String
instCode
,
@RequestBody
String
content
)
throws
JsonProcessingException
,
IOException
,
RESTApiValueException
{
FaoInstitute
institute
=
instituteService
.
getInstitute
(
instCode
);
if
(
institute
==
null
)
{
throw
new
ResourceNotFoundException
(
"No institute "
+
instCode
);
}
JsonNode
json
=
mapper
.
readTree
(
content
);
Map
<
AccessionJson
,
ObjectNode
>
batch
=
new
HashMap
<
AccessionJson
,
ObjectNode
>();
List
<
String
>
batch
=
new
ArrayList
<
String
>();
if
(
json
.
isArray
())
{
for
(
JsonNode
j
:
json
)
{
AccessionJson
dataJson
=
readAid3
(
j
);
if
(!
instCode
.
equals
(
dataJson
.
instCode
))
{
throw
new
RuntimeException
(
"Accession does not belong to instCode="
+
instCode
+
" acn="
+
dataJson
);
if
(
j
.
isNull
()
||
!
j
.
isTextual
())
{
throw
new
RESTApiValueException
(
"acceNumb must be a non-null String"
);
}
batch
.
put
(
dataJson
,
(
ObjectNode
)
j
);
batch
.
add
(
j
.
textValue
()
);
}
}
else
{
AccessionJson
dataJson
=
readAid3
(
json
);
if
(!
instCode
.
equals
(
dataJson
.
instCode
))
{
throw
new
RuntimeException
(
"Accession does not belong to instCode="
+
instCode
+
" acn="
+
dataJson
);
if
(
json
.
isNull
()
||
!
json
.
isTextual
())
{
throw
new
RESTApiValueException
(
"acceNumb must be a non-null String"
);
}
batch
.
put
(
dataJson
,
(
ObjectNode
)
json
);
batch
.
add
(
json
.
textValue
()
);
}
LOG
.
info
(
"Batch processing "
+
batch
.
size
()
+
" entries"
);
ArrayNode
rets
=
mapper
.
createArrayNode
();
for
(
AccessionJson
dataJson
:
batch
.
keySet
()
)
{
for
(
String
acceNumb
:
batch
)
{
if
(
LOG
.
isDebugEnabled
())
LOG
.
debug
(
"Loading accession "
+
dataJson
);
ObjectNode
ret
=
mapper
.
createObjectNode
();
ret
.
put
(
"instCode"
,
dataJson
.
instCode
);
ret
.
put
(
"genus"
,
dataJson
.
genus
);
ret
.
put
(
"acceNumb"
,
dataJson
.
acceNumb
);
Accession
accession
=
genesysService
.
getAccession
(
dataJson
.
instCode
,
dataJson
.
acceNumb
,
dataJson
.
genus
);
if
(
accession
!=
null
)
{
ret
.
put
(
"id"
,
accession
.
getId
());
// Give them back the UUID
if
(
accession
.
getUuid
()
!=
null
)
{
ret
.
put
(
"uuid"
,
accession
.
getUuid
());
LOG
.
debug
(
"Loading accession "
+
acceNumb
+
" from "
+
instCode
);
if
(
institute
.
hasUniqueAcceNumbs
())
{
Accession
accession
=
genesysService
.
getAccession
(
instCode
,
acceNumb
);
rets
.
add
(
accession
==
null
?
null
:
accession
.
getId
());
}
else
{
List
<
Accession
>
accessions
=
genesysService
.
listAccessions
(
institute
,
acceNumb
);
if
(
accessions
.
size
()==
1
)
{
rets
.
add
(
accessions
.
get
(
0
).
getId
());
}
else
{
ArrayNode
ret
=
rets
.
arrayNode
();
for
(
Accession
accession
:
accessions
)
{
ret
.
add
(
accession
.
getId
());
}
rets
.
add
(
ret
);
}
}
rets
.
add
(
ret
);
}
return
rets
;
...
...
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