Loading src/main/java/it/inaf/oats/vospace/CollectionsController.java +5 −3 Original line number Original line Diff line number Diff line Loading @@ -15,9 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController; /** /** Loading Loading @@ -59,14 +59,16 @@ public class CollectionsController { } } // delete collection by id // delete collection by id @DeleteMapping(value = "/collections") @DeleteMapping(value = "/collections/{collectionId}") public ResponseEntity<String> deleteCollection( public ResponseEntity<String> deleteCollection( @RequestParam("id") Long id, User principal) { @PathVariable("collectionId") Long id, User principal) { LOG.debug("delete collection called with id {} for user {}", LOG.debug("delete collection called with id {} for user {}", id, principal.getName()); id, principal.getName()); collectionsService.deleteCollectionById(id, principal.getName()); collectionsService.deleteCollectionById(id, principal.getName()); // TODO: manage case collection not found or request by someone who isn't // the owner return ResponseEntity.ok("Collection deleted"); return ResponseEntity.ok("Collection deleted"); } } Loading src/main/java/it/inaf/oats/vospace/CollectionsService.java +3 −2 Original line number Original line Diff line number Diff line Loading @@ -52,8 +52,9 @@ public class CollectionsService { public void deleteCollectionById(Long collectionId, String userId) { public void deleteCollectionById(Long collectionId, String userId) { if(isUserAuthenticated(userId)) if(isUserAuthenticated(userId)) { { // TODO: Implement delete collectionsDAO.deleteCollection(collectionId, userId); throw new UnsupportedOperationException("delete collection"); // TODO: throw exceptions if collection not found or deletion requested // by someone who is not the owner } else { } else { throw new PermissionDeniedException("Authentication required"); throw new PermissionDeniedException("Authentication required"); } } Loading src/main/java/it/inaf/oats/vospace/persistence/CollectionsDAO.java +3 −4 Original line number Original line Diff line number Diff line Loading @@ -83,11 +83,10 @@ public class CollectionsDAO { return nc; return nc; } } public void deleteCollection(Long collectionId) { public void deleteCollection(Long collectionId, String userId) { // TODO: this is just a stub for development. String sql = "DELETE FROM collections WHERE collection_id = ? AND owner_id = ?"; String sql = "DELETE FROM collections WHERE collection_id = ?"; jdbcTemplate.update(sql, collectionId); jdbcTemplate.update(sql, collectionId, userId); } } private NodeCollection getNodeCollectionFromResultset(ResultSet rs) private NodeCollection getNodeCollectionFromResultset(ResultSet rs) Loading src/test/java/it/inaf/oats/vospace/persistence/CollectionsDAOTest.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -52,7 +52,7 @@ public class CollectionsDAOTest { for(NodeCollection nc : ncl) { for(NodeCollection nc : ncl) { collectionsDAO.deleteCollection( collectionsDAO.deleteCollection( nc.getId() nc.getId(), "pippo" ); ); } } Loading Loading
src/main/java/it/inaf/oats/vospace/CollectionsController.java +5 −3 Original line number Original line Diff line number Diff line Loading @@ -15,9 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController; /** /** Loading Loading @@ -59,14 +59,16 @@ public class CollectionsController { } } // delete collection by id // delete collection by id @DeleteMapping(value = "/collections") @DeleteMapping(value = "/collections/{collectionId}") public ResponseEntity<String> deleteCollection( public ResponseEntity<String> deleteCollection( @RequestParam("id") Long id, User principal) { @PathVariable("collectionId") Long id, User principal) { LOG.debug("delete collection called with id {} for user {}", LOG.debug("delete collection called with id {} for user {}", id, principal.getName()); id, principal.getName()); collectionsService.deleteCollectionById(id, principal.getName()); collectionsService.deleteCollectionById(id, principal.getName()); // TODO: manage case collection not found or request by someone who isn't // the owner return ResponseEntity.ok("Collection deleted"); return ResponseEntity.ok("Collection deleted"); } } Loading
src/main/java/it/inaf/oats/vospace/CollectionsService.java +3 −2 Original line number Original line Diff line number Diff line Loading @@ -52,8 +52,9 @@ public class CollectionsService { public void deleteCollectionById(Long collectionId, String userId) { public void deleteCollectionById(Long collectionId, String userId) { if(isUserAuthenticated(userId)) if(isUserAuthenticated(userId)) { { // TODO: Implement delete collectionsDAO.deleteCollection(collectionId, userId); throw new UnsupportedOperationException("delete collection"); // TODO: throw exceptions if collection not found or deletion requested // by someone who is not the owner } else { } else { throw new PermissionDeniedException("Authentication required"); throw new PermissionDeniedException("Authentication required"); } } Loading
src/main/java/it/inaf/oats/vospace/persistence/CollectionsDAO.java +3 −4 Original line number Original line Diff line number Diff line Loading @@ -83,11 +83,10 @@ public class CollectionsDAO { return nc; return nc; } } public void deleteCollection(Long collectionId) { public void deleteCollection(Long collectionId, String userId) { // TODO: this is just a stub for development. String sql = "DELETE FROM collections WHERE collection_id = ? AND owner_id = ?"; String sql = "DELETE FROM collections WHERE collection_id = ?"; jdbcTemplate.update(sql, collectionId); jdbcTemplate.update(sql, collectionId, userId); } } private NodeCollection getNodeCollectionFromResultset(ResultSet rs) private NodeCollection getNodeCollectionFromResultset(ResultSet rs) Loading
src/test/java/it/inaf/oats/vospace/persistence/CollectionsDAOTest.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -52,7 +52,7 @@ public class CollectionsDAOTest { for(NodeCollection nc : ncl) { for(NodeCollection nc : ncl) { collectionsDAO.deleteCollection( collectionsDAO.deleteCollection( nc.getId() nc.getId(), "pippo" ); ); } } Loading