Improve error handling

(cherry picked from commit d5cd90814a)
master 1.0.13
George Kalampokis 3 years ago committed by Diamantis Tziotzios
parent e5a929f259
commit faabd343a9

@ -243,7 +243,6 @@ public class DMPs extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(cloneId));
}
@Transactional
@RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<DMP>> delete(@PathVariable UUID id, Principal principal) {
@ -279,7 +278,6 @@ public class DMPs extends BaseController {
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/finalize/{id}"})
public ResponseEntity<ResponseItem<DMP>> makeFinalize(@PathVariable String id, Principal principal, @RequestBody DatasetsToBeFinalized datasetsToBeFinalized) {
try {
@ -291,7 +289,6 @@ public class DMPs extends BaseController {
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/unfinalize/{id}"})
public ResponseEntity<ResponseItem<DMP>> undoFinalize(@PathVariable String id, Principal principal) {
try {
@ -304,7 +301,6 @@ public class DMPs extends BaseController {
}
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/updateusers/{id}"})
public ResponseEntity<ResponseItem<DMP>> updateUsers(@PathVariable String id, @RequestBody List<UserInfoListingModel> users, Principal principal) {
try {
@ -320,7 +316,6 @@ public class DMPs extends BaseController {
* DOI Generation
* */
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/createZenodoDoi/{id}"})
public ResponseEntity<ResponseItem<String>> createZenodoDoi(@PathVariable String id, Principal principal) {
try {
@ -328,7 +323,7 @@ public class DMPs extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully created DOI for Data Datamanagement Plan in question.").payload(zenodoDOI));
} catch (Exception e) {
logger.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<String>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to create DOI for the Data Management Plan."));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<String>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to create DOI for the Data Management Plan: " + e.getMessage()));
}
}

@ -1407,7 +1407,7 @@ public class DataManagementPlanManager {
return fileEnvelope;
}
public ResponseEntity<byte[]> getRDAJsonDocument(String id, DatasetManager datasetManager, Principal principal) throws IOException {
public ResponseEntity<byte[]> getRDAJsonDocument(String id, DatasetManager datasetManager, Principal principal) throws Exception {
eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (!dmp.isPublic() && dmp.getUsers().stream().noneMatch(userInfo -> userInfo.getUser().getId() == principal.getId()))
throw new UnauthorisedException();
@ -2091,7 +2091,12 @@ public class DataManagementPlanManager {
restTemplate.put(addFileUrl, addFileMapRequest);
Files.deleteIfExists(file.getFile().toPath());
ResponseEntity<byte[]> jsonFile = getRDAJsonDocument(id.toString(), datasetManager, principal);
ResponseEntity<byte[]> jsonFile;
try {
jsonFile = getRDAJsonDocument(id.toString(), datasetManager, principal);
} catch (Exception e) {
throw e;
}
UUID jsonFileUUID = UUID.randomUUID();
File tempJsonFile = new File(this.environment.getProperty("temp.temp") + jsonFileUUID.toString() + ".json");
try (FileOutputStream jsonFos = new FileOutputStream(tempJsonFile)) {

@ -36,7 +36,7 @@ public class DmpRDAMapper {
}
Map<String, Object> extraProperties;
if (dmp.getExtraProperties() == null) {
throw new IllegalArgumentException("DMP is missing required Data for RDA export");
throw new IllegalArgumentException("DMP is missing language and contact properties");
} else {
extraProperties = new org.json.JSONObject(dmp.getExtraProperties()).toMap();
if (extraProperties.get("language") == null) {

Loading…
Cancel
Save