Skip to content
Snippets Groups Projects
Commit 0296407a authored by Sven Kästle's avatar Sven Kästle
Browse files

feat: Add 'targetCategory' to annotation object

parent e7308d12
No related branches found
No related tags found
No related merge requests found
Showing with 73 additions and 27 deletions
......@@ -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
......
......@@ -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);
}
}
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 +
'}';
}
......
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 + '\'' +
'}';
}
}
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 +
'}';
}
}
......@@ -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();
......
......@@ -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,
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment