diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/interfaces/IAnnotation.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/interfaces/IAnnotation.java index d8957a0d393696650cc86ad0216d05ea68bcfa65..9ae417fdd7cc9e5ea1b6b1bd4511993b2af1096a 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/interfaces/IAnnotation.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/interfaces/IAnnotation.java @@ -3,6 +3,7 @@ package unipotsdam.gf.interfaces; import unipotsdam.gf.modules.annotation.model.Annotation; import unipotsdam.gf.modules.annotation.model.AnnotationPatchRequest; import unipotsdam.gf.modules.annotation.model.AnnotationPostRequest; +import unipotsdam.gf.modules.peer2peerfeedback.Category; import java.util.ArrayList; @@ -44,12 +45,13 @@ public interface IAnnotation { Annotation getAnnotation(String annotationId); /** - * Returns all annotations from a target + * Returns all annotations for a specific target id and category * - * @param targetId the target id - * @return Returns all annotations + * @param targetId The if of the target + * @param targetCategory The category of the target + * @return Returns all annotations for a target */ - ArrayList<Annotation> getAnnotations(int targetId); + ArrayList<Annotation> getAnnotations(int targetId, Category targetCategory); /** * Checks if an annotation id already exists in the database diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/controller/AnnotationController.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/controller/AnnotationController.java index ce29362c3f10354b41d3802bd945d638e62b52c9..91f9625c83d388e6fb64c958a23316a6150f7950 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/controller/AnnotationController.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/controller/AnnotationController.java @@ -7,6 +7,7 @@ import unipotsdam.gf.modules.annotation.model.Annotation; import unipotsdam.gf.modules.annotation.model.AnnotationBody; import unipotsdam.gf.modules.annotation.model.AnnotationPatchRequest; import unipotsdam.gf.modules.annotation.model.AnnotationPostRequest; +import unipotsdam.gf.modules.peer2peerfeedback.Category; import java.time.ZonedDateTime; import java.util.ArrayList; @@ -27,8 +28,8 @@ public class AnnotationController implements IAnnotation { connection.connect(); // build and execute request - String request = "INSERT INTO annotations (`id`, `userToken`, `targetId`, `title`, `comment`, `startCharacter`, `endCharacter`) VALUES (?,?,?,?,?,?,?);"; - connection.issueInsertOrDeleteStatement(request, uuid, annotationPostRequest.getUserToken(), annotationPostRequest.getTargetId(), annotationPostRequest.getBody().getTitle(), annotationPostRequest.getBody().getComment(),annotationPostRequest.getBody().getStartCharacter(), annotationPostRequest.getBody().getEndCharacter()); + String request = "INSERT INTO annotations (`id`, `userToken`, `targetId`, `targetCategory`, `title`, `comment`, `startCharacter`, `endCharacter`) VALUES (?,?,?,?,?,?,?,?);"; + connection.issueInsertOrDeleteStatement(request, uuid, annotationPostRequest.getUserToken(), annotationPostRequest.getTargetId(), annotationPostRequest.getTargetCategory().toString().toUpperCase(), annotationPostRequest.getBody().getTitle(), annotationPostRequest.getBody().getComment(),annotationPostRequest.getBody().getStartCharacter(), annotationPostRequest.getBody().getEndCharacter()); // close connection connection.close(); @@ -104,7 +105,7 @@ public class AnnotationController implements IAnnotation { } @Override - public ArrayList<Annotation> getAnnotations(int targetId) { + public ArrayList<Annotation> getAnnotations(int targetId, Category category) { // declare annotation ArrayList ArrayList<Annotation> annotations = new ArrayList<>(); @@ -114,8 +115,8 @@ public class AnnotationController implements IAnnotation { connection.connect(); // build and execute request - String request = "SELECT * FROM annotations WHERE targetId = ?;"; - VereinfachtesResultSet rs = connection.issueSelectStatement(request, targetId); + String request = "SELECT * FROM annotations WHERE targetId = ? AND targetCategory = ?;"; + VereinfachtesResultSet rs = connection.issueSelectStatement(request, targetId, category.toString().toUpperCase()); while (rs.next()) { annotations.add(getAnnotationFromResultSet(rs)); @@ -172,6 +173,7 @@ public class AnnotationController implements IAnnotation { long timestamp = rs.getTimestamp(2).getTime(); String userToken = rs.getString("userToken"); int targetId = rs.getInt("targetId"); + Category targetCategory = Category.valueOf(rs.getString("targetCategory")); // initialize new annotation body String title = rs.getString("title"); @@ -180,7 +182,7 @@ public class AnnotationController implements IAnnotation { int endCharacter = rs.getInt("endCharacter"); AnnotationBody body = new AnnotationBody(title, comment, startCharacter, endCharacter); - return new Annotation(id, timestamp, userToken, targetId, body); + return new Annotation(id, timestamp, userToken, targetId, targetCategory, body); } } diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/Annotation.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/Annotation.java index 699ec3eda8ad469fda08b6688311fabb9a17bc5b..13dbd82071abda17602b788c87a828096c62bb21 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/Annotation.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/Annotation.java @@ -1,5 +1,7 @@ package unipotsdam.gf.modules.annotation.model; +import unipotsdam.gf.modules.peer2peerfeedback.Category; + /** * @author Sven Kästle * skaestle@uni-potsdam.de @@ -11,14 +13,16 @@ public class Annotation { private long timestamp; private String userToken; private int targetId; + private Category targetCategory; private AnnotationBody body; // constructor - public Annotation(String id, long timestamp, String userToken, int targetId, AnnotationBody body) { + public Annotation(String id, long timestamp, String userToken, int targetId, Category targetCategory, AnnotationBody body) { this.id = id; this.timestamp = timestamp; this.userToken = userToken; this.targetId = targetId; + this.targetCategory = targetCategory; this.body = body; } @@ -55,6 +59,14 @@ public class Annotation { this.targetId = targetId; } + public Category getTargetCategory() { + return targetCategory; + } + + public void setTargetCategory(Category targetCategory) { + this.targetCategory = targetCategory; + } + public AnnotationBody getBody() { return body; } @@ -70,6 +82,7 @@ public class Annotation { ", timestamp=" + timestamp + ", userToken='" + userToken + '\'' + ", targetId=" + targetId + + ", targetCategory=" + targetCategory + ", body=" + body + '}'; } diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationMessage.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationMessage.java index 60d895b66b293668f4b505684a46d75ebea88dbe..f8e3f913afcdae8ec44cfe720eb26165bcd296f4 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationMessage.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationMessage.java @@ -1,9 +1,12 @@ package unipotsdam.gf.modules.annotation.model; +import unipotsdam.gf.modules.peer2peerfeedback.Category; + public class AnnotationMessage { // variables private String from; private String targetId; + private Category targetCategory; private AnnotationMessageType type; private String annotationId; @@ -30,6 +33,14 @@ public class AnnotationMessage { this.targetId = targetId; } + public Category getTargetCategory() { + return targetCategory; + } + + public void setTargetCategory(Category targetCategory) { + this.targetCategory = targetCategory; + } + public AnnotationMessageType getType() { return type; } @@ -51,8 +62,10 @@ public class AnnotationMessage { return "AnnotationMessage{" + "from='" + from + '\'' + ", targetId='" + targetId + '\'' + + ", targetCategory=" + targetCategory + ", type=" + type + ", annotationId='" + annotationId + '\'' + '}'; } + } diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationPostRequest.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationPostRequest.java index 5dfe6e206f1f014eb3ce88fbc22e401323b2c422..f49676950341f2bac2e68ff6a9ff7546a84c8aab 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationPostRequest.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationPostRequest.java @@ -1,5 +1,7 @@ package unipotsdam.gf.modules.annotation.model; +import unipotsdam.gf.modules.peer2peerfeedback.Category; + /** * @author Sven Kästle * skaestle@uni-potsdam.de @@ -9,12 +11,14 @@ public class AnnotationPostRequest { // variables private String userToken; private int targetId; + private Category targetCategory; private AnnotationBody body; // constructors - public AnnotationPostRequest(String userToken, int targetId, AnnotationBody body) { + public AnnotationPostRequest(String userToken, int targetId, Category targetCategory, AnnotationBody body) { this.userToken = userToken; this.targetId = targetId; + this.targetCategory = targetCategory; this.body = body; } @@ -38,6 +42,14 @@ public class AnnotationPostRequest { this.targetId = targetId; } + public Category getTargetCategory() { + return targetCategory; + } + + public void setTargetCategory(Category targetCategory) { + this.targetCategory = targetCategory; + } + public AnnotationBody getBody() { return body; } @@ -51,8 +63,9 @@ public class AnnotationPostRequest { return "AnnotationPostRequest{" + "userToken='" + userToken + '\'' + ", targetId=" + targetId + - ", body=" + body.toString() + + ", targetCategory=" + targetCategory + + ", body=" + body + '}'; } - + } diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/view/AnnotationService.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/view/AnnotationService.java index 1072cd55891857bc8fa1d2d9ece561f5b105da81..2504955171b3f1293246ae0dafda871fb2e43890 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/view/AnnotationService.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/view/AnnotationService.java @@ -6,6 +6,7 @@ import unipotsdam.gf.modules.annotation.model.Annotation; import unipotsdam.gf.modules.annotation.model.AnnotationPatchRequest; import unipotsdam.gf.modules.annotation.model.AnnotationPostRequest; import unipotsdam.gf.modules.annotation.model.AnnotationResponse; +import unipotsdam.gf.modules.peer2peerfeedback.Category; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; @@ -108,12 +109,12 @@ public class AnnotationService { } @GET - @Path("/target/{id}") - public Response getAnnotations(@PathParam("id") int targetId) { + @Path("/targetid/{id}/targetcategory/{category}") + public Response getAnnotations(@PathParam("id") int targetId, @PathParam("category") String category) { // receive the annotation AnnotationController controller = new AnnotationController(); - ArrayList<Annotation> annotations = controller.getAnnotations(targetId); + ArrayList<Annotation> annotations = controller.getAnnotations(targetId, Category.valueOf(category.toUpperCase())); if (!annotations.isEmpty()) { return Response.ok(annotations).build(); diff --git a/gemeinsamforschen/src/scripts/dbschema/fltrail.sql b/gemeinsamforschen/src/scripts/dbschema/fltrail.sql index 978bd4b9bcaa80fc3c20db0201cdf2f07a0b7a27..2ceb83f7d35fcb3ac250943353cca3de23b34342 100644 --- a/gemeinsamforschen/src/scripts/dbschema/fltrail.sql +++ b/gemeinsamforschen/src/scripts/dbschema/fltrail.sql @@ -114,6 +114,7 @@ CREATE TABLE if not exists `annotations` ( `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `userToken` varchar(120) DEFAULT NULL, `targetId` int(11) DEFAULT NULL, + `targetCategory` VARCHAR(30) NOT NULL, `title` varchar(120) DEFAULT NULL, `comment` varchar(400) DEFAULT NULL, `startCharacter` int(11) DEFAULT NULL, diff --git a/gemeinsamforschen/src/test/java/unipotsdam/gf/interfaces/AnnotationTest.java b/gemeinsamforschen/src/test/java/unipotsdam/gf/interfaces/AnnotationTest.java index d0fde6c5871fd1533cc8e37308ec2e3068343327..2dda63f5fb34ed1ccb47611f00eeeaebff0d2c37 100644 --- a/gemeinsamforschen/src/test/java/unipotsdam/gf/interfaces/AnnotationTest.java +++ b/gemeinsamforschen/src/test/java/unipotsdam/gf/interfaces/AnnotationTest.java @@ -7,6 +7,7 @@ import unipotsdam.gf.modules.annotation.model.Annotation; import unipotsdam.gf.modules.annotation.model.AnnotationBody; import unipotsdam.gf.modules.annotation.model.AnnotationPatchRequest; import unipotsdam.gf.modules.annotation.model.AnnotationPostRequest; +import unipotsdam.gf.modules.peer2peerfeedback.Category; import java.util.ArrayList; @@ -37,7 +38,7 @@ public class AnnotationTest { String comment = "comment_testAddAnnotation"; // prepare and execute request - AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest("userToken", 1, new AnnotationBody(title, comment, 1, 2)); + AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest("userToken", 1, Category.TITEL, new AnnotationBody(title, comment, 1, 2)); Annotation response = controller.addAnnotation(annotationPostRequest); // the new annotation should be found in the database @@ -58,7 +59,7 @@ public class AnnotationTest { String commentNew = "commentNew_testAlterAnnotation"; // save new annotation in database - AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest("userToken", 0, new AnnotationBody(titleOld, commentOld, 1, 2)); + AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest("userToken", 0, Category.TITEL, new AnnotationBody(titleOld, commentOld, 1, 2)); Annotation response = controller.addAnnotation(annotationPostRequest); // the new annotation should be found in the database @@ -96,7 +97,7 @@ public class AnnotationTest { String comment = "comment_testDeleteAnnotation"; // prepare and execute request - AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest("userToken", 1, new AnnotationBody(title, comment, 1, 2)); + AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest("userToken", 1, Category.TITEL, new AnnotationBody(title, comment, 1, 2)); Annotation response = controller.addAnnotation(annotationPostRequest); // the new annotation should be found in the database @@ -118,7 +119,7 @@ public class AnnotationTest { String comment = "comment_testGetAnnotation"; // prepare and execute request - AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest("userToken", 1, new AnnotationBody(title, comment, 1, 2)); + AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest("userToken", 1, Category.TITEL, new AnnotationBody(title, comment, 1, 2)); Annotation response = controller.addAnnotation(annotationPostRequest); // receive the new annotation @@ -148,21 +149,21 @@ public class AnnotationTest { targetIds.add(-2); // save new annotations in database - AnnotationPostRequest request1 = new AnnotationPostRequest("userToken", targetIds.get(0), new AnnotationBody(title, comment, 1, 2)); - AnnotationPostRequest request2 = new AnnotationPostRequest("userToken", targetIds.get(1), new AnnotationBody(title, comment, 1, 2)); - AnnotationPostRequest request3 = new AnnotationPostRequest("userToken", targetIds.get(1), new AnnotationBody(title, comment, 1, 2)); + AnnotationPostRequest request1 = new AnnotationPostRequest("userToken", targetIds.get(0), Category.TITEL, new AnnotationBody(title, comment, 1, 2)); + AnnotationPostRequest request2 = new AnnotationPostRequest("userToken", targetIds.get(1), Category.TITEL, new AnnotationBody(title, comment, 1, 2)); + AnnotationPostRequest request3 = new AnnotationPostRequest("userToken", targetIds.get(1), Category.TITEL, new AnnotationBody(title, comment, 1, 2)); controller.addAnnotation(request1); controller.addAnnotation(request2); controller.addAnnotation(request3); // receive the new annotations with targetId = -2 - ArrayList<Annotation> getResponse = controller.getAnnotations(targetIds.get(1)); + ArrayList<Annotation> getResponse = controller.getAnnotations(targetIds.get(1), Category.TITEL); // the size of the getResponse should be 2 assertEquals("The size of the response should be 2 but was " + getResponse.size(), 2, getResponse.size()); // receive the new annotations with targetId = -1 - ArrayList<Annotation> getResponseNew = controller.getAnnotations(targetIds.get(0)); + ArrayList<Annotation> getResponseNew = controller.getAnnotations(targetIds.get(0), Category.TITEL); // the size of the getResponse should be 1 assertEquals("The size of the response should be 1 but was " + getResponseNew.size(), 1, getResponseNew.size()); @@ -183,7 +184,7 @@ public class AnnotationTest { String badId = "badId"; // save new annotation in database - AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest("userToken", 0, new AnnotationBody(title, comment, 1, 2)); + AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest("userToken", 0, Category.TITEL, new AnnotationBody(title, comment, 1, 2)); Annotation response = controller.addAnnotation(annotationPostRequest); // the annotation shouldn't be found in the database