Commit 0097c5d8 authored by Matija Obreza's avatar Matija Obreza

Use Spring's mappers instead of parsing Strings

parent cc7b1af0
......@@ -132,12 +132,13 @@ public class OAuthManagementController extends BaseController {
@PreAuthorize("hasAnyRole('VETTEDUSER','ADMINISTRATOR')")
@RequestMapping(value = "/save-client", method = RequestMethod.POST, params = "newClient=new")
public String createClientEntry(Model model, @RequestParam("title") String title, @RequestParam("description") String description,
@RequestParam(value = "redirectUris", required = false) String redirectUris, @RequestParam("accessTokenValiditySeconds") Integer accessTokenValiditySeconds,
@RequestParam("refreshTokenValiditySeconds") Integer refreshTokenValiditySeconds, @RequestParam(value = "clientType", required = false) String clientType) {
@RequestParam(value = "redirectUris", required = false) String redirectUris, @RequestParam(name = "accessTokenValidity", required = false) Integer accessTokenValiditySeconds,
@RequestParam(name = "refreshTokenValidity", required = false) Integer refreshTokenValiditySeconds, @RequestParam(name = "clientType", required = false) String clientType) {
OAuthClient oauthClient = clientDetailsService.addClient(title, description, redirectUris, accessTokenValiditySeconds, refreshTokenValiditySeconds);
_logger.info("Created OAuth client with clientId=" + oauthClient.getClientId());
return "redirect:" + CONTROLLER_PATH + "/" + oauthClient.getId() + "/edit";
return "redirect:" + CONTROLLER_PATH + "/";
}
@PreAuthorize("hasAnyRole('VETTEDUSER','ADMINISTRATOR')")
......
......@@ -133,14 +133,13 @@ public class AccessionController extends RestController {
* @throws NonUniqueAccessionException
*/
@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, RESTApiValueException,
public @ResponseBody JsonNode check(@PathVariable("instCode") String instCode, @RequestBody JsonNode json) throws JsonProcessingException, IOException, RESTApiValueException,
NonUniqueAccessionException {
final FaoInstitute institute = instituteService.getInstitute(instCode);
if (institute == null) {
throw new ResourceNotFoundException("No institute " + instCode);
}
final JsonNode json = mapper.readTree(content);
final List<String> batch = new ArrayList<String>();
if (json.isArray()) {
......@@ -194,8 +193,10 @@ public class AccessionController extends RestController {
* @throws RESTApiException
*/
@RequestMapping(value = "/{instCode}/upsert", method = { RequestMethod.POST, RequestMethod.PUT }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Object upsertInstituteAccession(@PathVariable("instCode") String instCode, @RequestBody String content) throws JsonProcessingException, IOException,
public @ResponseBody Object upsertInstituteAccession(@PathVariable("instCode") String instCode, @RequestBody JsonNode json) throws JsonProcessingException, IOException,
RESTApiException {
LOG.debug("Received:\n" + json);
// User's permission to WRITE to this WIEWS institute are checked in
// BatchRESTService.
......@@ -204,7 +205,7 @@ public class AccessionController extends RestController {
throw new ResourceNotFoundException();
}
final JsonNode json = mapper.readTree(content);
// final JsonNode json = mapper.readTree(content);
final Map<AccessionHeaderJson, ObjectNode> batch = new HashMap<AccessionHeaderJson, ObjectNode>();
if (json.isArray()) {
......
......@@ -160,7 +160,7 @@ public class DatasetController extends RestController {
*/
@RequestMapping(value = "/{metadataId:.+}/data", method = { RequestMethod.PUT, RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
Object upsertMetadataData(@PathVariable("metadataId") Long metadataId, @RequestBody String data) throws AuthorizationException, IOException, NonUniqueAccessionException {
Object upsertMetadataData(@PathVariable("metadataId") Long metadataId, @RequestBody JsonNode json) throws AuthorizationException, IOException, NonUniqueAccessionException {
final Metadata metadata = datasetService.getDataset(metadataId);
if (metadata == null) {
throw new ResourceNotFoundException();
......@@ -169,17 +169,7 @@ public class DatasetController extends RestController {
// Check for 'WRITE' permission
datasetService.touch(metadata);
LOG.debug(data);
final ObjectMapper objectMapper = new ObjectMapper();
JsonNode json = null;
try {
json = objectMapper.readTree(data);
LOG.debug(json);
} catch (final IOException e) {
LOG.error(e);
throw e;
}
LOG.debug(json);
if (json.isArray()) {
for (final JsonNode jo : json) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment