From dd3374f168db55ef4fb9b44d6c1f950ab5081020 Mon Sep 17 00:00:00 2001 From: PradnyaC11 Date: Tue, 18 Mar 2025 17:08:26 -0700 Subject: [PATCH 1/8] [CITE-232] Added catch blocks where it throws error --- .../citesphere/api/v1/user/AddNewItemController.java | 8 ++++++-- .../diging/citesphere/api/v1/user/ItemTextController.java | 4 +++- .../diging/citesphere/web/user/EditItemController.java | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java b/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java index 4804dc24d..35b46f6a2 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java @@ -145,9 +145,11 @@ public ResponseEntity createNewItem(Principal principal, try { citation = citationManager.createCitation(user, zoteroGroupId, collectionIds, citation); - } catch (ZoteroItemCreationFailedException | ZoteroConnectionException | ZoteroHttpStatusException e) { + } catch (ZoteroItemCreationFailedException | ZoteroHttpStatusException e) { logger.error("Zotero Item creation failed. ", e); return new ResponseEntity<>("Error: Zetero Item creation failed. " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } catch (ZoteroConnectionException e) { + //TODO: add error logging } catch (GroupDoesNotExistException e) { logger.error("Group " + zoteroGroupId +" does not exists. ", e); return new ResponseEntity<>("Error: Group " + zoteroGroupId +" does not exists. ", HttpStatus.BAD_REQUEST); @@ -170,9 +172,11 @@ public ResponseEntity createNewItem(Principal principal, } catch (IOException e) { logger.error("Could not read file from the request. ", e); return new ResponseEntity<>("Error: Could not read file from the request.", HttpStatus.BAD_REQUEST); - } catch (ZoteroHttpStatusException | ZoteroConnectionException | ZoteroItemCreationFailedException e) { + } catch (ZoteroHttpStatusException | ZoteroItemCreationFailedException e) { logger.error("Zotero exception occured ", e); return new ResponseEntity<>("Error: Zotero Exception occured: "+ e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } catch (ZoteroConnectionException e) { + //TODO: add error logging } catch (HttpClientErrorException.Unauthorized e) { logger.error("Unauthorized to upload files to Giles ", e); return new ResponseEntity<>("Error: Unauthorized to upload files to Giles.", HttpStatus.UNAUTHORIZED); diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/ItemTextController.java b/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/ItemTextController.java index 6cebd355d..19153fe61 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/ItemTextController.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/ItemTextController.java @@ -85,9 +85,11 @@ public ResponseEntity addItemFile(@PathVariable("groupId") String groupI try { job = jobManager.createGilesJob(user, files[i], files[i].getBytes(), groupId, citation.getKey()); - } catch (ZoteroHttpStatusException | ZoteroConnectionException | ZoteroItemCreationFailedException e) { + } catch (ZoteroHttpStatusException | ZoteroItemCreationFailedException e) { logger.error("Zotero could not process the file. ", e); return new ResponseEntity<>("Error: Zotero could not process the file: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } catch (ZoteroConnectionException e) { + //TODO: add error logging } catch (GroupDoesNotExistException e) { logger.error("Could not create job because group does not exist.", e); return new ResponseEntity<>("Error: Could not create job because group does not exist.", HttpStatus.NOT_FOUND); diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/EditItemController.java b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/EditItemController.java index bd526ef6d..42d50b78a 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/EditItemController.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/EditItemController.java @@ -126,7 +126,7 @@ public String storeItem(@ModelAttribute CitationForm form, Authentication authen @RequestParam(defaultValue = "1", required = false, value = "page") int page, @RequestParam(value = "collectionId", required = false) String collectionId, @RequestParam(defaultValue = "title", required = false, value = "sortBy") String sortBy) - throws ZoteroConnectionException, GroupDoesNotExistException, CannotFindCitationException, + throws GroupDoesNotExistException, CannotFindCitationException, ZoteroHttpStatusException, ZoteroItemCreationFailedException { ICitation citation = citationManager.getCitation((IUser) authentication.getPrincipal(), zoteroGroupId, itemId); // load authors and editors before detaching @@ -161,6 +161,8 @@ public String storeItem(@ModelAttribute CitationForm form, Authentication authen model.addAttribute("collectionId", collectionId); model.addAttribute("sortBy", sortBy); return "auth/group/editConflict"; + } catch (ZoteroConnectionException e) { + //TODO: add error logging } return "redirect:/auth/group/{zoteroGroupId}/items/{itemId}?index=" + index +"&page="+page +"&sortBy="+sortBy +"&collectionId="+collectionId; } From 6d6c899a4125aa58e3f80ecd58df048dd1e6a9e4 Mon Sep 17 00:00:00 2001 From: PradnyaC11 Date: Thu, 20 Mar 2025 12:10:42 -0700 Subject: [PATCH 2/8] [CITE-232] Added handling for ZoteroConnectionException --- .../citesphere/api/v1/user/AddNewItemController.java | 4 ++-- .../citesphere/api/v1/user/ItemTextController.java | 2 +- .../diging/citesphere/web/user/AddItemController.java | 10 +++++++++- .../citesphere/web/user/AddReferenceController.java | 2 +- .../diging/citesphere/web/user/EditItemController.java | 8 +++++++- .../citesphere/web/user/RevertCitationController.java | 5 ++++- .../citesphere/web/user/UploadItemFileController.java | 7 +++++-- .../src/main/webapp/WEB-INF/views/error/500.html | 6 +++--- 8 files changed, 32 insertions(+), 12 deletions(-) diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java b/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java index 35b46f6a2..3699b2859 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java @@ -149,7 +149,7 @@ public ResponseEntity createNewItem(Principal principal, logger.error("Zotero Item creation failed. ", e); return new ResponseEntity<>("Error: Zetero Item creation failed. " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } catch (ZoteroConnectionException e) { - //TODO: add error logging + return new ResponseEntity<>("Error: Zetero Item creation failed. Please check Zoetro Key Permissions. " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } catch (GroupDoesNotExistException e) { logger.error("Group " + zoteroGroupId +" does not exists. ", e); return new ResponseEntity<>("Error: Group " + zoteroGroupId +" does not exists. ", HttpStatus.BAD_REQUEST); @@ -176,7 +176,7 @@ public ResponseEntity createNewItem(Principal principal, logger.error("Zotero exception occured ", e); return new ResponseEntity<>("Error: Zotero Exception occured: "+ e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } catch (ZoteroConnectionException e) { - //TODO: add error logging + return new ResponseEntity<>("Error: Zetero Item creation failed. Please check Zoetro Key Permissions. " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } catch (HttpClientErrorException.Unauthorized e) { logger.error("Unauthorized to upload files to Giles ", e); return new ResponseEntity<>("Error: Unauthorized to upload files to Giles.", HttpStatus.UNAUTHORIZED); diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/ItemTextController.java b/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/ItemTextController.java index 19153fe61..6b2e42c58 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/ItemTextController.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/ItemTextController.java @@ -89,7 +89,7 @@ public ResponseEntity addItemFile(@PathVariable("groupId") String groupI logger.error("Zotero could not process the file. ", e); return new ResponseEntity<>("Error: Zotero could not process the file: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } catch (ZoteroConnectionException e) { - //TODO: add error logging + return new ResponseEntity<>("Error: Could not add file to citation. Please check Zoetro Key Permissions. " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } catch (GroupDoesNotExistException e) { logger.error("Could not create job because group does not exist.", e); return new ResponseEntity<>("Error: Could not create job because group does not exist.", HttpStatus.NOT_FOUND); diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/AddItemController.java b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/AddItemController.java index 3140e9987..05d4d62e2 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/AddItemController.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/AddItemController.java @@ -89,7 +89,7 @@ public String show(Model model, Authentication authentication, @RequestMapping(value = "/auth/group/{zoteroGroupId}/items/create", method = RequestMethod.POST) public String create(@ModelAttribute CitationForm form, Authentication authentication, Model model, @PathVariable("zoteroGroupId") String zoteroGroupId) - throws ZoteroConnectionException, GroupDoesNotExistException, ZoteroHttpStatusException { + throws GroupDoesNotExistException, ZoteroHttpStatusException { ICitation citation = new Citation(); List collectionIds = new ArrayList<>(); if (form.getCollectionId() != null && !form.getCollectionId().trim().isEmpty()) { @@ -110,6 +110,14 @@ public String create(@ModelAttribute CitationForm form, Authentication authentic : "Sorry, item creation failed."; model.addAttribute("alert_msg", msg); return "auth/group/editItem"; + } catch (ZoteroConnectionException e) { + model.addAttribute("form", form); + model.addAttribute("zoteroGroupId", zoteroGroupId); + model.addAttribute("show_alert", true); + model.addAttribute("alert_type", "danger"); + String msg = "Sorry, item creation failed. Please check the Zotero Key permissions."; + model.addAttribute("alert_msg", msg); + return "auth/group/editItem"; } return "redirect:/auth/group/{zoteroGroupId}/items/" + citation.getKey(); diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/AddReferenceController.java b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/AddReferenceController.java index f2e4e115a..e5995a44c 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/AddReferenceController.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/AddReferenceController.java @@ -53,7 +53,7 @@ public ResponseEntity addReference(Authentication authentication, logger.error("Zotero threw exception.", e); return new ResponseEntity<>("{\"error\": \"" + e.getMessage() + "\"}", HttpStatus.INTERNAL_SERVER_ERROR); } catch (ZoteroConnectionException e) { - logger.error("Zotero connection failed.", e); + logger.error("Zotero connection failed. Please check Zotero Key permissions. ", e); return new ResponseEntity<>("{\"error\": \"" + e.getMessage() + "\"}", HttpStatus.INTERNAL_SERVER_ERROR); } catch (CitationIsOutdatedException e) { logger.error("Citation is outdated.", e); diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/EditItemController.java b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/EditItemController.java index 42d50b78a..d1a03c30d 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/EditItemController.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/EditItemController.java @@ -162,7 +162,13 @@ public String storeItem(@ModelAttribute CitationForm form, Authentication authen model.addAttribute("sortBy", sortBy); return "auth/group/editConflict"; } catch (ZoteroConnectionException e) { - //TODO: add error logging + model.addAttribute("form", form); + model.addAttribute("zoteroGroupId", zoteroGroupId); + model.addAttribute("show_alert", true); + model.addAttribute("alert_type", "danger"); + String msg = "Sorry, item updation failed. Please check the Zotero Key permissions."; + model.addAttribute("alert_msg", msg); + return "auth/group/editItem"; } return "redirect:/auth/group/{zoteroGroupId}/items/{itemId}?index=" + index +"&page="+page +"&sortBy="+sortBy +"&collectionId="+collectionId; } diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/RevertCitationController.java b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/RevertCitationController.java index 9b0af9546..56cb4670e 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/RevertCitationController.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/RevertCitationController.java @@ -36,10 +36,13 @@ public String revertCitationVersion(Authentication authentication, Model model, citationVersionManager.revertCitationVersion((IUser) authentication.getPrincipal(), zoteroGroupId, itemId, version); return "redirect:/auth/group/" + zoteroGroupId + "/items/" + itemId; - } catch (GroupDoesNotExistException | ZoteroConnectionException | CitationIsOutdatedException + } catch (GroupDoesNotExistException | CitationIsOutdatedException | ZoteroHttpStatusException | CannotFindCitationVersionException | CannotFindCitationException | ZoteroItemCreationFailedException e) { logger.error("Error while restoring citation version", e); return "error/404"; + } catch (ZoteroConnectionException e) { + logger.error("Error while restoring citation version. Please check the Zotero Key permissions", e); + return "error/500"; } } diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/UploadItemFileController.java b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/UploadItemFileController.java index e9b045bd0..5ea57439c 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/UploadItemFileController.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/UploadItemFileController.java @@ -48,7 +48,7 @@ public class UploadItemFileController { public ResponseEntity uploadFile(Principal principal, @PathVariable String zoteroGroupId, @PathVariable String itemId, @RequestParam("files") MultipartFile[] files) throws AccessForbiddenException, CannotFindCitationException, ZoteroHttpStatusException, - ZoteroConnectionException, CitationIsOutdatedException, ZoteroItemCreationFailedException { + CitationIsOutdatedException, ZoteroItemCreationFailedException { User user = null; if (principal instanceof UsernamePasswordAuthenticationToken) { user = (User) ((UsernamePasswordAuthenticationToken) principal).getPrincipal(); @@ -68,12 +68,15 @@ public ResponseEntity uploadFile(Principal principal, @PathVariable Stri } } - IGilesUpload job; + IGilesUpload job = null; try { job = jobManager.createGilesJob(user, files[0], fileBytes.get(0), zoteroGroupId, itemId); } catch (GroupDoesNotExistException e) { logger.error("Could not create job because group does not exist.", e); return new ResponseEntity(HttpStatus.BAD_REQUEST); + } catch (ZoteroConnectionException e) { + logger.error("Could not create job. Please check Zotero Key permissions. ", e); + return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); } ObjectMapper mapper = new ObjectMapper(); diff --git a/citesphere/src/main/webapp/WEB-INF/views/error/500.html b/citesphere/src/main/webapp/WEB-INF/views/error/500.html index cb2f11f53..86b3d73b0 100644 --- a/citesphere/src/main/webapp/WEB-INF/views/error/500.html +++ b/citesphere/src/main/webapp/WEB-INF/views/error/500.html @@ -1,7 +1,7 @@ - -
+ +
- + \ No newline at end of file From 34526093ee0be6cd7a6c55dd711078a9f105b8e2 Mon Sep 17 00:00:00 2001 From: PradnyaC11 Date: Fri, 21 Mar 2025 16:24:06 -0700 Subject: [PATCH 3/8] [CITE-232] Fixed the edit & add item controller error pages --- .../citesphere/web/user/AddItemController.java | 15 ++++++++------- .../citesphere/web/user/EditItemController.java | 16 ++++++++-------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/AddItemController.java b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/AddItemController.java index 05d4d62e2..4242572a1 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/AddItemController.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/AddItemController.java @@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; import edu.asu.diging.citesphere.core.exceptions.GroupDoesNotExistException; import edu.asu.diging.citesphere.core.exceptions.ZoteroHttpStatusException; @@ -88,7 +89,7 @@ public String show(Model model, Authentication authentication, @RequestMapping(value = "/auth/group/{zoteroGroupId}/items/create", method = RequestMethod.POST) public String create(@ModelAttribute CitationForm form, Authentication authentication, Model model, - @PathVariable("zoteroGroupId") String zoteroGroupId) + @PathVariable("zoteroGroupId") String zoteroGroupId, RedirectAttributes redirectAttributes) throws GroupDoesNotExistException, ZoteroHttpStatusException { ICitation citation = new Citation(); List collectionIds = new ArrayList<>(); @@ -111,13 +112,13 @@ public String create(@ModelAttribute CitationForm form, Authentication authentic model.addAttribute("alert_msg", msg); return "auth/group/editItem"; } catch (ZoteroConnectionException e) { - model.addAttribute("form", form); - model.addAttribute("zoteroGroupId", zoteroGroupId); - model.addAttribute("show_alert", true); - model.addAttribute("alert_type", "danger"); + redirectAttributes.addFlashAttribute("form", form); + redirectAttributes.addFlashAttribute("zoteroGroupId", zoteroGroupId); + redirectAttributes.addFlashAttribute("show_alert", true); + redirectAttributes.addFlashAttribute("alert_type", "danger"); String msg = "Sorry, item creation failed. Please check the Zotero Key permissions."; - model.addAttribute("alert_msg", msg); - return "auth/group/editItem"; + redirectAttributes.addFlashAttribute("alert_msg", msg); + return "redirect:/auth/group/{zoteroGroupId}/items/create"; } return "redirect:/auth/group/{zoteroGroupId}/items/" + citation.getKey(); diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/EditItemController.java b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/EditItemController.java index d1a03c30d..3a32edd3c 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/EditItemController.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/EditItemController.java @@ -125,7 +125,8 @@ public String storeItem(@ModelAttribute CitationForm form, Authentication authen @RequestParam(required = false, value = "index") String index, @RequestParam(defaultValue = "1", required = false, value = "page") int page, @RequestParam(value = "collectionId", required = false) String collectionId, - @RequestParam(defaultValue = "title", required = false, value = "sortBy") String sortBy) + @RequestParam(defaultValue = "title", required = false, value = "sortBy") String sortBy, + RedirectAttributes redirectAttributes) throws GroupDoesNotExistException, CannotFindCitationException, ZoteroHttpStatusException, ZoteroItemCreationFailedException { ICitation citation = citationManager.getCitation((IUser) authentication.getPrincipal(), zoteroGroupId, itemId); @@ -162,13 +163,12 @@ public String storeItem(@ModelAttribute CitationForm form, Authentication authen model.addAttribute("sortBy", sortBy); return "auth/group/editConflict"; } catch (ZoteroConnectionException e) { - model.addAttribute("form", form); - model.addAttribute("zoteroGroupId", zoteroGroupId); - model.addAttribute("show_alert", true); - model.addAttribute("alert_type", "danger"); - String msg = "Sorry, item updation failed. Please check the Zotero Key permissions."; - model.addAttribute("alert_msg", msg); - return "auth/group/editItem"; + redirectAttributes.addFlashAttribute("form", form); + redirectAttributes.addFlashAttribute("zoteroGroupId", zoteroGroupId); + redirectAttributes.addFlashAttribute("show_alert", true); + redirectAttributes.addFlashAttribute("alert_type", "danger"); + redirectAttributes.addFlashAttribute("alert_msg", "Sorry, item updation failed. Please check the Zotero Key permissions."); + return "redirect:/auth/group/{zoteroGroupId}/items/{itemId}/edit?index=" + index +"&page="+page +"&sortBy="+sortBy +"&collectionId="+collectionId; } return "redirect:/auth/group/{zoteroGroupId}/items/{itemId}?index=" + index +"&page="+page +"&sortBy="+sortBy +"&collectionId="+collectionId; } From 22a95ca4fdd7a370eecc41ac9fcc569c3eacc7c7 Mon Sep 17 00:00:00 2001 From: PradnyaC11 Date: Fri, 21 Mar 2025 16:34:15 -0700 Subject: [PATCH 4/8] [CITE-232] Resovled code factor issue --- .../api/v1/user/AddNewItemController.java | 60 ++++++++----------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java b/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java index 3699b2859..da2bb92c4 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java @@ -145,43 +145,33 @@ public ResponseEntity createNewItem(Principal principal, try { citation = citationManager.createCitation(user, zoteroGroupId, collectionIds, citation); - } catch (ZoteroItemCreationFailedException | ZoteroHttpStatusException e) { - logger.error("Zotero Item creation failed. ", e); - return new ResponseEntity<>("Error: Zetero Item creation failed. " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); - } catch (ZoteroConnectionException e) { - return new ResponseEntity<>("Error: Zetero Item creation failed. Please check Zoetro Key Permissions. " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); - } catch (GroupDoesNotExistException e) { - logger.error("Group " + zoteroGroupId +" does not exists. ", e); - return new ResponseEntity<>("Error: Group " + zoteroGroupId +" does not exists. ", HttpStatus.BAD_REQUEST); - } - - if (itemWithGiles.getFiles() != null && itemWithGiles.getFiles().length > 0) { - ObjectMapper mapper = new ObjectMapper(); - ObjectNode root = mapper.createObjectNode(); - for (MultipartFile file: itemWithGiles.getFiles()) { - try { - IGilesUpload job = jobManager.createGilesJob(user, file, file.getBytes(), zoteroGroupId, - citation.getKey()); - gilesUtil.createJobObjectNode(root, job); - } catch (GroupDoesNotExistException e) { - logger.error("Could not create job because group does not exist.", e); - return new ResponseEntity<>("Error: Could not create job because group does not exist.", HttpStatus.BAD_REQUEST); - } catch (CannotFindCitationException | CitationIsOutdatedException e) { - logger.error("Error with newly created citation.", e); - return new ResponseEntity<>("Error: Error with newly created citation." + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); - } catch (IOException e) { - logger.error("Could not read file from the request. ", e); - return new ResponseEntity<>("Error: Could not read file from the request.", HttpStatus.BAD_REQUEST); - } catch (ZoteroHttpStatusException | ZoteroItemCreationFailedException e) { - logger.error("Zotero exception occured ", e); - return new ResponseEntity<>("Error: Zotero Exception occured: "+ e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); - } catch (ZoteroConnectionException e) { - return new ResponseEntity<>("Error: Zetero Item creation failed. Please check Zoetro Key Permissions. " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); - } catch (HttpClientErrorException.Unauthorized e) { - logger.error("Unauthorized to upload files to Giles ", e); - return new ResponseEntity<>("Error: Unauthorized to upload files to Giles.", HttpStatus.UNAUTHORIZED); + + if (itemWithGiles.getFiles() != null && itemWithGiles.getFiles().length > 0) { + ObjectMapper mapper = new ObjectMapper(); + ObjectNode root = mapper.createObjectNode(); + for (MultipartFile file: itemWithGiles.getFiles()) { + IGilesUpload job = jobManager.createGilesJob(user, file, file.getBytes(), zoteroGroupId, + citation.getKey()); + gilesUtil.createJobObjectNode(root, job); } } + } catch (GroupDoesNotExistException e) { + logger.error("Could not create job because group does not exist.", e); + return new ResponseEntity<>("Error: Could not create job because group does not exist.", HttpStatus.BAD_REQUEST); + } catch (CannotFindCitationException | CitationIsOutdatedException e) { + logger.error("Error with newly created citation.", e); + return new ResponseEntity<>("Error: Error with newly created citation." + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } catch (IOException e) { + logger.error("Could not read file from the request. ", e); + return new ResponseEntity<>("Error: Could not read file from the request.", HttpStatus.BAD_REQUEST); + } catch (ZoteroHttpStatusException | ZoteroItemCreationFailedException e) { + logger.error("Zotero exception occured ", e); + return new ResponseEntity<>("Error: Zotero Exception occured: "+ e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } catch (ZoteroConnectionException e) { + return new ResponseEntity<>("Error: Zetero Item creation failed. Please check Zoetro Key Permissions. " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } catch (HttpClientErrorException.Unauthorized e) { + logger.error("Unauthorized to upload files to Giles ", e); + return new ResponseEntity<>("Error: Unauthorized to upload files to Giles.", HttpStatus.UNAUTHORIZED); } return new ResponseEntity<>(citation, HttpStatus.OK); } From 289af4811c5a6c9059d3261fd012affdd4baac85 Mon Sep 17 00:00:00 2001 From: PradnyaC11 Date: Fri, 21 Mar 2025 16:36:10 -0700 Subject: [PATCH 5/8] [CITE-232] Resovled code factor issue --- .../diging/citesphere/api/v1/user/AddNewItemController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java b/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java index da2bb92c4..f82101891 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/api/v1/user/AddNewItemController.java @@ -150,9 +150,9 @@ public ResponseEntity createNewItem(Principal principal, ObjectMapper mapper = new ObjectMapper(); ObjectNode root = mapper.createObjectNode(); for (MultipartFile file: itemWithGiles.getFiles()) { - IGilesUpload job = jobManager.createGilesJob(user, file, file.getBytes(), zoteroGroupId, - citation.getKey()); - gilesUtil.createJobObjectNode(root, job); + IGilesUpload job = jobManager.createGilesJob(user, file, file.getBytes(), zoteroGroupId, + citation.getKey()); + gilesUtil.createJobObjectNode(root, job); } } } catch (GroupDoesNotExistException e) { From 41697ec067e90089387aa2578f0590de4ccdd84b Mon Sep 17 00:00:00 2001 From: Rajvi Patel Date: Thu, 17 Jul 2025 16:35:57 -0700 Subject: [PATCH 6/8] [CITE-232] Implement custom Zotero OAuth with specific permissions --- .../citesphere/config/core/ZoteroConfig.java | 7 ++- .../zotero/custom/CustomOAuth1Operations.java | 50 +++++++++++++++++++ .../custom/CustomZoteroConnectionFactory.java | 17 +++++++ 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomOAuth1Operations.java create mode 100644 citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomZoteroConnectionFactory.java diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/config/core/ZoteroConfig.java b/citesphere/src/main/java/edu/asu/diging/citesphere/config/core/ZoteroConfig.java index 220bd496b..513d0f2db 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/config/core/ZoteroConfig.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/config/core/ZoteroConfig.java @@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.social.zotero.connect.ZoteroConnectionFactory; +import edu.asu.diging.citesphere.core.zotero.custom.CustomZoteroConnectionFactory; @Configuration @PropertySource("classpath:/config.properties") @@ -18,7 +19,9 @@ public class ZoteroConfig { @Bean - public ZoteroConnectionFactory zoteroConnectionFactory() { - return new ZoteroConnectionFactory(zoteroKey, zoteroSecret); + public CustomZoteroConnectionFactory zoteroConnectionFactory( + @Value("${_zotero_client_key}") String zoteroKey, + @Value("${_zotero_client_secret}") String zoteroSecret) { + return new CustomZoteroConnectionFactory(zoteroKey, zoteroSecret); } } diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomOAuth1Operations.java b/citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomOAuth1Operations.java new file mode 100644 index 000000000..c17258627 --- /dev/null +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomOAuth1Operations.java @@ -0,0 +1,50 @@ +package edu.asu.diging.citesphere.core.zotero.custom; + +import org.springframework.social.oauth1.OAuth1Operations; +import org.springframework.social.oauth1.OAuth1Parameters; +import org.springframework.social.oauth1.OAuthToken; +import org.springframework.social.oauth1.AuthorizedRequestToken; +import org.springframework.util.MultiValueMap; + +public class CustomOAuth1Operations implements OAuth1Operations { + private final OAuth1Operations delegate; + + public CustomOAuth1Operations(OAuth1Operations delegate) { + this.delegate = delegate; + } + + @Override + public String buildAuthorizeUrl(String requestToken, OAuth1Parameters parameters) { + if (parameters == null) { + parameters = new OAuth1Parameters(); + } + parameters.set("write_access", "1"); + parameters.set("all_groups", "write"); + return delegate.buildAuthorizeUrl(requestToken, parameters); + } + + @Override + public String buildAuthenticateUrl(String requestToken, OAuth1Parameters parameters) { + if (parameters == null) { + parameters = new OAuth1Parameters(); + } + parameters.set("write_access", "1"); + parameters.set("all_groups", "write"); + return delegate.buildAuthenticateUrl(requestToken, parameters); + } + + @Override + public OAuthToken fetchRequestToken(String callbackUrl, MultiValueMap additionalParameters) { + return delegate.fetchRequestToken(callbackUrl, additionalParameters); + } + + @Override + public OAuthToken exchangeForAccessToken(AuthorizedRequestToken requestToken, MultiValueMap additionalParameters) { + return delegate.exchangeForAccessToken(requestToken, additionalParameters); + } + + @Override + public org.springframework.social.oauth1.OAuth1Version getVersion() { + return delegate.getVersion(); + } +} \ No newline at end of file diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomZoteroConnectionFactory.java b/citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomZoteroConnectionFactory.java new file mode 100644 index 000000000..fde86777c --- /dev/null +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomZoteroConnectionFactory.java @@ -0,0 +1,17 @@ +package edu.asu.diging.citesphere.core.zotero.custom; + +import org.springframework.social.zotero.connect.ZoteroConnectionFactory; +import org.springframework.social.oauth1.OAuth1Operations; + +public class CustomZoteroConnectionFactory extends ZoteroConnectionFactory { + + public CustomZoteroConnectionFactory(String consumerKey, String consumerSecret) { + super(consumerKey, consumerSecret); + } + + @Override + public OAuth1Operations getOAuthOperations() { + OAuth1Operations ops = super.getOAuthOperations(); + return new CustomOAuth1Operations(ops); + } +} \ No newline at end of file From b41aac9b94c4d85256a5810e8749f6c2ec4f3a17 Mon Sep 17 00:00:00 2001 From: Rajvi Patel Date: Fri, 18 Jul 2025 16:27:33 -0700 Subject: [PATCH 7/8] [CITE-232] Fix CustomOAuth1Operations compilation errors --- .../zotero/custom/CustomOAuth1Operations.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomOAuth1Operations.java b/citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomOAuth1Operations.java index c17258627..74a7e6e06 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomOAuth1Operations.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomOAuth1Operations.java @@ -23,16 +23,6 @@ public String buildAuthorizeUrl(String requestToken, OAuth1Parameters parameters return delegate.buildAuthorizeUrl(requestToken, parameters); } - @Override - public String buildAuthenticateUrl(String requestToken, OAuth1Parameters parameters) { - if (parameters == null) { - parameters = new OAuth1Parameters(); - } - parameters.set("write_access", "1"); - parameters.set("all_groups", "write"); - return delegate.buildAuthenticateUrl(requestToken, parameters); - } - @Override public OAuthToken fetchRequestToken(String callbackUrl, MultiValueMap additionalParameters) { return delegate.fetchRequestToken(callbackUrl, additionalParameters); @@ -43,6 +33,11 @@ public OAuthToken exchangeForAccessToken(AuthorizedRequestToken requestToken, Mu return delegate.exchangeForAccessToken(requestToken, additionalParameters); } + @Override + public String buildAuthenticateUrl(String requestToken, OAuth1Parameters parameters) { + return delegate.buildAuthenticateUrl(requestToken, parameters); + } + @Override public org.springframework.social.oauth1.OAuth1Version getVersion() { return delegate.getVersion(); From ec9feaff22d89bafa4aa28065f1e5596473d4dcf Mon Sep 17 00:00:00 2001 From: Rajvi Patel Date: Wed, 23 Jul 2025 11:10:53 -0700 Subject: [PATCH 8/8] [CITE-232] Fix buildAuthenticateUrl method --- .../zotero/custom/CustomOAuth1Operations.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomOAuth1Operations.java b/citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomOAuth1Operations.java index 74a7e6e06..c17258627 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomOAuth1Operations.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/core/zotero/custom/CustomOAuth1Operations.java @@ -23,6 +23,16 @@ public String buildAuthorizeUrl(String requestToken, OAuth1Parameters parameters return delegate.buildAuthorizeUrl(requestToken, parameters); } + @Override + public String buildAuthenticateUrl(String requestToken, OAuth1Parameters parameters) { + if (parameters == null) { + parameters = new OAuth1Parameters(); + } + parameters.set("write_access", "1"); + parameters.set("all_groups", "write"); + return delegate.buildAuthenticateUrl(requestToken, parameters); + } + @Override public OAuthToken fetchRequestToken(String callbackUrl, MultiValueMap additionalParameters) { return delegate.fetchRequestToken(callbackUrl, additionalParameters); @@ -33,11 +43,6 @@ public OAuthToken exchangeForAccessToken(AuthorizedRequestToken requestToken, Mu return delegate.exchangeForAccessToken(requestToken, additionalParameters); } - @Override - public String buildAuthenticateUrl(String requestToken, OAuth1Parameters parameters) { - return delegate.buildAuthenticateUrl(requestToken, parameters); - } - @Override public org.springframework.social.oauth1.OAuth1Version getVersion() { return delegate.getVersion();