Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
b0ca0342
Commit
b0ca0342
authored
Jan 13, 2014
by
Matija Obreza
Browse files
Moved JSON classes to .....rest.model
parent
680fd109
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/service/BatchRESTService.java
View file @
b0ca0342
...
...
@@ -16,59 +16,18 @@
package
org.genesys2.server.service
;
import
java.text.MessageFormat
;
import
java.util.List
;
import
java.util.Map
;
import
org.genesys2.server.model.impl.AccessionIdentifier3
;
import
org.genesys2.server.model.impl.FaoInstitute
;
import
org.genesys2.server.servlet.controller.rest.model.AccessionNamesJson
;
import
org.genesys2.server.servlet.controller.rest.model.AccessionJson
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
public
interface
BatchRESTService
{
boolean
upsertAccessionData
(
FaoInstitute
institute
,
Map
<
Data
Json
,
ObjectNode
>
batch
);
boolean
upsertAccessionData
(
FaoInstitute
institute
,
Map
<
Accession
Json
,
ObjectNode
>
batch
);
void
upsertAccessionNames
(
FaoInstitute
institute
,
List
<
AcceNames
>
batch
);
public
static
class
DataJson
implements
AccessionIdentifier3
{
public
String
instCode
;
public
String
acceNumb
;
public
String
genus
;
@Override
public
String
getHoldingInstitute
()
{
return
instCode
;
}
@Override
public
String
getAccessionName
()
{
return
acceNumb
;
}
@Override
public
String
getGenus
()
{
return
genus
;
}
@Override
public
String
toString
()
{
return
MessageFormat
.
format
(
"AID3 instCode={0} acceNumb={1} genus={2}"
,
instCode
,
acceNumb
,
genus
);
}
}
public
static
class
AcceNames
extends
BatchRESTService
.
DataJson
{
public
List
<
AcceAlias
>
aliases
;
}
public
static
class
AcceAlias
{
public
String
name
;
public
String
instCode
;
public
int
type
=
0
;
@Override
public
String
toString
()
{
return
""
+
name
+
"@"
+
instCode
;
}
}
void
upsertAccessionNames
(
FaoInstitute
institute
,
List
<
AccessionNamesJson
>
batch
);
}
src/main/java/org/genesys2/server/service/impl/BatchRESTServiceImpl.java
View file @
b0ca0342
...
...
@@ -40,6 +40,9 @@ import org.genesys2.server.service.GeoService;
import
org.genesys2.server.service.InstituteService
;
import
org.genesys2.server.service.OrganizationService
;
import
org.genesys2.server.service.TaxonomyService
;
import
org.genesys2.server.servlet.controller.rest.model.AccessionAliasJson
;
import
org.genesys2.server.servlet.controller.rest.model.AccessionNamesJson
;
import
org.genesys2.server.servlet.controller.rest.model.AccessionJson
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.stereotype.Service
;
...
...
@@ -72,13 +75,13 @@ public class BatchRESTServiceImpl implements BatchRESTService {
@Override
@Transactional
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')"
)
public
boolean
upsertAccessionData
(
FaoInstitute
institute
,
Map
<
BatchRESTService
.
Data
Json
,
ObjectNode
>
batch
)
{
public
boolean
upsertAccessionData
(
FaoInstitute
institute
,
Map
<
Accession
Json
,
ObjectNode
>
batch
)
{
LOG
.
info
(
"Batch processing "
+
batch
.
size
()
+
" entries for "
+
institute
);
List
<
Accession
>
toSave
=
new
ArrayList
<
Accession
>();
List
<
AllAcqCollect
>
toSaveColl
=
new
ArrayList
<
AllAcqCollect
>();
List
<
AccessionGeo
>
toSaveGeo
=
new
ArrayList
<
AccessionGeo
>();
for
(
BatchRESTService
.
Data
Json
dataJson
:
batch
.
keySet
())
{
for
(
Accession
Json
dataJson
:
batch
.
keySet
())
{
if
(
LOG
.
isDebugEnabled
())
LOG
.
debug
(
"Loading accession "
+
dataJson
);
...
...
@@ -255,13 +258,13 @@ public class BatchRESTServiceImpl implements BatchRESTService {
@Override
@Transactional
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')"
)
public
void
upsertAccessionNames
(
FaoInstitute
institute
,
List
<
AcceNames
>
batch
)
{
public
void
upsertAccessionNames
(
FaoInstitute
institute
,
List
<
Acce
ssion
Names
Json
>
batch
)
{
LOG
.
info
(
"Batch processing "
+
batch
.
size
()
+
" entries for "
+
institute
);
List
<
AccessionAlias
>
toSave
=
new
ArrayList
<
AccessionAlias
>();
List
<
AccessionAlias
>
toRemove
=
new
ArrayList
<
AccessionAlias
>();
for
(
AcceNames
dataJson
:
batch
)
{
for
(
Acce
ssion
Names
Json
dataJson
:
batch
)
{
Accession
accession
=
genesysService
.
getAccession
(
institute
.
getCode
(),
dataJson
.
genus
,
dataJson
.
acceNumb
);
if
(
accession
==
null
)
{
LOG
.
warn
(
"No such accession "
+
dataJson
);
...
...
@@ -272,9 +275,9 @@ public class BatchRESTServiceImpl implements BatchRESTService {
List
<
AccessionAlias
>
existingAliases
=
genesysService
.
listAccessionAliases
(
accession
);
// Find aliases to remove
for
(
final
AccessionAlias
aa
:
existingAliases
)
{
if
(
null
==
CollectionUtils
.
find
(
dataJson
.
aliases
,
new
Predicate
<
AcceAlias
>()
{
if
(
null
==
CollectionUtils
.
find
(
dataJson
.
aliases
,
new
Predicate
<
Acce
ssion
Alias
Json
>()
{
@Override
public
boolean
evaluate
(
AcceAlias
alias
)
{
public
boolean
evaluate
(
Acce
ssion
Alias
Json
alias
)
{
return
StringUtils
.
equals
(
alias
.
name
,
aa
.
getName
());
}
}))
{
...
...
@@ -282,7 +285,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
}
}
// Add or update
for
(
final
AcceAlias
aa
:
dataJson
.
aliases
)
{
for
(
final
Acce
ssion
Alias
Json
aa
:
dataJson
.
aliases
)
{
AccessionAlias
accessionAlias
=
CollectionUtils
.
find
(
existingAliases
,
new
Predicate
<
AccessionAlias
>()
{
@Override
public
boolean
evaluate
(
AccessionAlias
alias
)
{
...
...
src/main/java/org/genesys2/server/servlet/controller/rest/AccessionController.java
View file @
b0ca0342
...
...
@@ -28,6 +28,8 @@ import org.genesys2.server.service.GenesysService;
import
org.genesys2.server.service.GeoService
;
import
org.genesys2.server.service.InstituteService
;
import
org.genesys2.server.service.TaxonomyService
;
import
org.genesys2.server.servlet.controller.rest.model.AccessionNamesJson
;
import
org.genesys2.server.servlet.controller.rest.model.AccessionJson
;
import
org.genesys2.spring.ResourceNotFoundException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
...
...
@@ -100,18 +102,18 @@ public class AccessionController extends RestController {
JsonNode
check
(
@PathVariable
(
"instCode"
)
String
instCode
,
@RequestBody
String
content
)
throws
JsonProcessingException
,
IOException
{
// TODO Check user's permissions to update this WIEWS institute.
JsonNode
json
=
mapper
.
readTree
(
content
);
Map
<
BatchRESTService
.
Data
Json
,
ObjectNode
>
batch
=
new
HashMap
<
BatchRESTService
.
Data
Json
,
ObjectNode
>();
Map
<
Accession
Json
,
ObjectNode
>
batch
=
new
HashMap
<
Accession
Json
,
ObjectNode
>();
if
(
json
.
isArray
())
{
for
(
JsonNode
j
:
json
)
{
BatchRESTService
.
Data
Json
dataJson
=
readAid3
(
j
);
Accession
Json
dataJson
=
readAid3
(
j
);
if
(!
instCode
.
equals
(
dataJson
.
instCode
))
{
throw
new
RuntimeException
(
"Accession does not belong to instCode="
+
instCode
+
" acn="
+
dataJson
);
}
batch
.
put
(
dataJson
,
(
ObjectNode
)
j
);
}
}
else
{
BatchRESTService
.
Data
Json
dataJson
=
readAid3
(
json
);
Accession
Json
dataJson
=
readAid3
(
json
);
if
(!
instCode
.
equals
(
dataJson
.
instCode
))
{
throw
new
RuntimeException
(
"Accession does not belong to instCode="
+
instCode
+
" acn="
+
dataJson
);
}
...
...
@@ -121,7 +123,7 @@ public class AccessionController extends RestController {
LOG
.
info
(
"Batch processing "
+
batch
.
size
()
+
" entries"
);
ArrayNode
rets
=
mapper
.
createArrayNode
();
for
(
BatchRESTService
.
Data
Json
dataJson
:
batch
.
keySet
())
{
for
(
Accession
Json
dataJson
:
batch
.
keySet
())
{
if
(
LOG
.
isDebugEnabled
())
LOG
.
debug
(
"Loading accession "
+
dataJson
);
...
...
@@ -164,18 +166,18 @@ public class AccessionController extends RestController {
}
JsonNode
json
=
mapper
.
readTree
(
content
);
Map
<
BatchRESTService
.
Data
Json
,
ObjectNode
>
batch
=
new
HashMap
<
BatchRESTService
.
Data
Json
,
ObjectNode
>();
Map
<
Accession
Json
,
ObjectNode
>
batch
=
new
HashMap
<
Accession
Json
,
ObjectNode
>();
if
(
json
.
isArray
())
{
for
(
JsonNode
j
:
json
)
{
BatchRESTService
.
Data
Json
dataJson
=
readAid3
(
j
);
Accession
Json
dataJson
=
readAid3
(
j
);
if
(!
instCode
.
equals
(
dataJson
.
instCode
))
{
throw
new
RuntimeException
(
"Accession does not belong to instCode="
+
instCode
+
" acn="
+
dataJson
);
}
batch
.
put
(
dataJson
,
(
ObjectNode
)
j
);
}
}
else
{
BatchRESTService
.
Data
Json
dataJson
=
readAid3
(
json
);
Accession
Json
dataJson
=
readAid3
(
json
);
if
(!
instCode
.
equals
(
dataJson
.
instCode
))
{
throw
new
RuntimeException
(
"Accession does not belong to instCode="
+
instCode
+
" acn="
+
dataJson
);
}
...
...
@@ -195,7 +197,7 @@ public class AccessionController extends RestController {
*/
@RequestMapping
(
value
=
"/{instCode}/names"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
PUT
},
consumes
=
{
MediaType
.
APPLICATION_JSON_VALUE
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
@ResponseBody
String
upsertAccessionNames
(
@PathVariable
(
"instCode"
)
String
instCode
,
@RequestBody
List
<
BatchRESTService
.
Acce
Names
>
batch
)
{
String
upsertAccessionNames
(
@PathVariable
(
"instCode"
)
String
instCode
,
@RequestBody
List
<
Accession
Names
Json
>
batch
)
{
// User's permission to WRITE to this WIEWS institute are checked in
// BatchRESTService.
FaoInstitute
institute
=
instituteService
.
getInstitute
(
instCode
);
...
...
@@ -207,8 +209,8 @@ public class AccessionController extends RestController {
return
JSON_OK
;
}
private
BatchRESTService
.
Data
Json
readAid3
(
JsonNode
json
)
{
BatchRESTService
.
DataJson
dataJson
=
new
BatchRESTService
.
Data
Json
();
private
Accession
Json
readAid3
(
JsonNode
json
)
{
AccessionJson
dataJson
=
new
Accession
Json
();
dataJson
.
instCode
=
json
.
has
(
"instCode"
)
?
json
.
get
(
"instCode"
).
textValue
()
:
null
;
dataJson
.
acceNumb
=
json
.
has
(
"acceNumb"
)
?
json
.
get
(
"acceNumb"
).
textValue
()
:
null
;
...
...
src/main/java/org/genesys2/server/servlet/controller/rest/model/AccessionAliasJson.java
0 → 100644
View file @
b0ca0342
package
org.genesys2.server.servlet.controller.rest.model
;
public
class
AccessionAliasJson
{
public
String
name
;
public
String
instCode
;
public
int
type
=
0
;
@Override
public
String
toString
()
{
return
""
+
name
+
"@"
+
instCode
;
}
}
\ No newline at end of file
src/main/java/org/genesys2/server/servlet/controller/rest/model/AccessionJson.java
0 → 100644
View file @
b0ca0342
package
org.genesys2.server.servlet.controller.rest.model
;
import
java.text.MessageFormat
;
import
org.genesys2.server.model.impl.AccessionIdentifier3
;
public
class
AccessionJson
implements
AccessionIdentifier3
{
public
String
instCode
;
public
String
acceNumb
;
public
String
genus
;
@Override
public
String
getHoldingInstitute
()
{
return
instCode
;
}
@Override
public
String
getAccessionName
()
{
return
acceNumb
;
}
@Override
public
String
getGenus
()
{
return
genus
;
}
@Override
public
String
toString
()
{
return
MessageFormat
.
format
(
"AID3 instCode={0} acceNumb={1} genus={2}"
,
instCode
,
acceNumb
,
genus
);
}
}
\ No newline at end of file
src/main/java/org/genesys2/server/servlet/controller/rest/model/AccessionNamesJson.java
0 → 100644
View file @
b0ca0342
package
org.genesys2.server.servlet.controller.rest.model
;
import
java.util.List
;
public
class
AccessionNamesJson
extends
AccessionJson
{
public
List
<
AccessionAliasJson
>
aliases
;
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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