Improve error handling

(cherry picked from commit d5cd90814a)
This commit is contained in:
George Kalampokis 2021-07-06 13:33:58 +03:00 committed by Diamantis Tziotzios
parent e5a929f259
commit faabd343a9
3 changed files with 9 additions and 9 deletions

View File

@ -243,7 +243,6 @@ public class DMPs extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(cloneId)); 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") @RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<DMP>> delete(@PathVariable UUID id, Principal principal) { 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}"}) @RequestMapping(method = RequestMethod.POST, value = {"/finalize/{id}"})
public ResponseEntity<ResponseItem<DMP>> makeFinalize(@PathVariable String id, Principal principal, @RequestBody DatasetsToBeFinalized datasetsToBeFinalized) { public ResponseEntity<ResponseItem<DMP>> makeFinalize(@PathVariable String id, Principal principal, @RequestBody DatasetsToBeFinalized datasetsToBeFinalized) {
try { try {
@ -291,7 +289,6 @@ public class DMPs extends BaseController {
} }
} }
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/unfinalize/{id}"}) @RequestMapping(method = RequestMethod.POST, value = {"/unfinalize/{id}"})
public ResponseEntity<ResponseItem<DMP>> undoFinalize(@PathVariable String id, Principal principal) { public ResponseEntity<ResponseItem<DMP>> undoFinalize(@PathVariable String id, Principal principal) {
try { try {
@ -304,7 +301,6 @@ public class DMPs extends BaseController {
} }
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/updateusers/{id}"}) @RequestMapping(method = RequestMethod.POST, value = {"/updateusers/{id}"})
public ResponseEntity<ResponseItem<DMP>> updateUsers(@PathVariable String id, @RequestBody List<UserInfoListingModel> users, Principal principal) { public ResponseEntity<ResponseItem<DMP>> updateUsers(@PathVariable String id, @RequestBody List<UserInfoListingModel> users, Principal principal) {
try { try {
@ -320,7 +316,6 @@ public class DMPs extends BaseController {
* DOI Generation * DOI Generation
* */ * */
@Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/createZenodoDoi/{id}"}) @RequestMapping(method = RequestMethod.POST, value = {"/createZenodoDoi/{id}"})
public ResponseEntity<ResponseItem<String>> createZenodoDoi(@PathVariable String id, Principal principal) { public ResponseEntity<ResponseItem<String>> createZenodoDoi(@PathVariable String id, Principal principal) {
try { 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)); 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) { } catch (Exception e) {
logger.error(e.getMessage(), 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()));
} }
} }

View File

@ -1407,7 +1407,7 @@ public class DataManagementPlanManager {
return fileEnvelope; 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)); 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())) if (!dmp.isPublic() && dmp.getUsers().stream().noneMatch(userInfo -> userInfo.getUser().getId() == principal.getId()))
throw new UnauthorisedException(); throw new UnauthorisedException();
@ -2091,7 +2091,12 @@ public class DataManagementPlanManager {
restTemplate.put(addFileUrl, addFileMapRequest); restTemplate.put(addFileUrl, addFileMapRequest);
Files.deleteIfExists(file.getFile().toPath()); 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(); UUID jsonFileUUID = UUID.randomUUID();
File tempJsonFile = new File(this.environment.getProperty("temp.temp") + jsonFileUUID.toString() + ".json"); File tempJsonFile = new File(this.environment.getProperty("temp.temp") + jsonFileUUID.toString() + ".json");
try (FileOutputStream jsonFos = new FileOutputStream(tempJsonFile)) { try (FileOutputStream jsonFos = new FileOutputStream(tempJsonFile)) {

View File

@ -36,7 +36,7 @@ public class DmpRDAMapper {
} }
Map<String, Object> extraProperties; Map<String, Object> extraProperties;
if (dmp.getExtraProperties() == null) { 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 { } else {
extraProperties = new org.json.JSONObject(dmp.getExtraProperties()).toMap(); extraProperties = new org.json.JSONObject(dmp.getExtraProperties()).toMap();
if (extraProperties.get("language") == null) { if (extraProperties.get("language") == null) {