From 3320f9b2231d8498c267a9e548c6bad2bb5cfe81 Mon Sep 17 00:00:00 2001 From: Pratik Prakash Giri <32401726+PratikGiri@users.noreply.github.com> Date: Mon, 6 Feb 2023 16:59:34 -0700 Subject: [PATCH 01/10] [CITE-178] Resolving Conflicts --- .../core/service/ICitationManager.java | 4 ++ .../core/service/impl/CitationManager.java | 16 +++++ .../citesphere/web/user/ItemController.java | 21 ++++++ .../webapp/WEB-INF/views/auth/group/item.html | 71 ++++++++++++++++++- .../service/impl/CitationManagerTest.java | 19 +++++ 5 files changed, 130 insertions(+), 1 deletion(-) diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/core/service/ICitationManager.java b/citesphere/src/main/java/edu/asu/diging/citesphere/core/service/ICitationManager.java index ebd5edac7..594e180a5 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/core/service/ICitationManager.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/core/service/ICitationManager.java @@ -85,4 +85,8 @@ CloseableIterator getAllGroupItems(IUser user, String groupId, String void deleteLocalGroupCitations(String groupId); + void deleteFile(IUser user, String zoteroGroupId, String itemId, String documentId) + throws GroupDoesNotExistException, CannotFindCitationException, ZoteroHttpStatusException, + ZoteroConnectionException, CitationIsOutdatedException, ZoteroItemCreationFailedException; + } \ No newline at end of file diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/core/service/impl/CitationManager.java b/citesphere/src/main/java/edu/asu/diging/citesphere/core/service/impl/CitationManager.java index b0b83137b..be36becfa 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/core/service/impl/CitationManager.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/core/service/impl/CitationManager.java @@ -3,6 +3,7 @@ import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Optional; @@ -43,6 +44,7 @@ import edu.asu.diging.citesphere.model.bib.ICitation; import edu.asu.diging.citesphere.model.bib.ICitationCollection; import edu.asu.diging.citesphere.model.bib.ICitationGroup; +import edu.asu.diging.citesphere.model.bib.IGilesUpload; import edu.asu.diging.citesphere.model.bib.ItemType; import edu.asu.diging.citesphere.model.bib.impl.BibField; import edu.asu.diging.citesphere.model.bib.impl.CitationGroup; @@ -494,4 +496,18 @@ public CitationPage getPrevAndNextCitation(IUser user, String groupId, String co public void deleteLocalGroupCitations(String groupId) { citationStore.deleteCitationByGroupId(groupId); } + + @Override + public void deleteFile(IUser user, String zoteroGroupId, String itemId, String documentId) + throws GroupDoesNotExistException, CannotFindCitationException, ZoteroHttpStatusException, + ZoteroConnectionException, CitationIsOutdatedException, ZoteroItemCreationFailedException { + ICitation citation = getCitation(user, zoteroGroupId, itemId); + + for (Iterator gileUpload = citation.getGilesUploads().iterator(); gileUpload.hasNext();) { + IGilesUpload g = gileUpload.next(); + if (g.getDocumentId() != null && g.getDocumentId().equals(documentId)) + gileUpload.remove(); + } + updateCitation(user, zoteroGroupId, citation); + } } diff --git a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/ItemController.java b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/ItemController.java index a2b6a692b..b83c56e79 100644 --- a/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/ItemController.java +++ b/citesphere/src/main/java/edu/asu/diging/citesphere/web/user/ItemController.java @@ -2,24 +2,33 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.security.core.Authentication; +import org.springframework.social.zotero.exception.ZoteroConnectionException; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; 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.bind.annotation.RequestParam; import edu.asu.diging.citesphere.core.exceptions.CannotFindCitationException; +import edu.asu.diging.citesphere.core.exceptions.CitationIsOutdatedException; import edu.asu.diging.citesphere.core.exceptions.GroupDoesNotExistException; import edu.asu.diging.citesphere.core.exceptions.ZoteroHttpStatusException; +import edu.asu.diging.citesphere.core.exceptions.ZoteroItemCreationFailedException; import edu.asu.diging.citesphere.core.search.service.SearchEngine; import edu.asu.diging.citesphere.core.service.ICitationManager; import edu.asu.diging.citesphere.core.service.impl.CitationPage; +import edu.asu.diging.citesphere.core.service.impl.async.AsyncDeleteCitationsResponse; import edu.asu.diging.citesphere.model.bib.ICitation; import edu.asu.diging.citesphere.user.IUser; +import edu.asu.diging.citesphere.model.bib.IGilesUpload; @Controller public class ItemController { @@ -54,6 +63,7 @@ public String getItem(Authentication authentication, Model model, @PathVariable( List notes = citationManager.getNotes((IUser)authentication.getPrincipal(), zoteroGroupId, itemId); model.addAttribute("notes", notes); model.addAttribute("citation", citation); + model.addAttribute("itemId", itemId); List fields = new ArrayList<>(); citationManager.getItemTypeFields((IUser)authentication.getPrincipal(), citation.getItemType()).forEach(f -> fields.add(f.getFilename())); model.addAttribute("fields", fields); @@ -66,4 +76,15 @@ public String getItem(Authentication authentication, Model model, @PathVariable( } return "auth/group/item"; } + + @RequestMapping(value = "/auth/group/{zoteroGroupId}/file/delete", method = RequestMethod.POST) + public ResponseEntity deleteFile(Authentication authentication, + @PathVariable("zoteroGroupId") String zoteroGroupId, + @RequestParam(value = "documentId", required = false) String documentId, + @RequestParam(value = "itemId", required = false) String itemId) + throws GroupDoesNotExistException, CannotFindCitationException, ZoteroHttpStatusException, + ZoteroConnectionException, CitationIsOutdatedException, ZoteroItemCreationFailedException { + citationManager.deleteFile((IUser) authentication.getPrincipal(), zoteroGroupId, itemId, documentId); + return new ResponseEntity<>(HttpStatus.OK); + } } diff --git a/citesphere/src/main/webapp/WEB-INF/views/auth/group/item.html b/citesphere/src/main/webapp/WEB-INF/views/auth/group/item.html index 428bfe38b..50a62f1c2 100644 --- a/citesphere/src/main/webapp/WEB-INF/views/auth/group/item.html +++ b/citesphere/src/main/webapp/WEB-INF/views/auth/group/item.html @@ -1,5 +1,7 @@ + + @@ -360,10 +410,11 @@

Files

    -
  • +
  • [[${upload.uploadedFile?.filename}]] + File is being processed... ([[${upload.progressId}]]) @@ -479,6 +530,24 @@ + +