From be2978a1c2722c1d40640abaa0af0d724dbb8816 Mon Sep 17 00:00:00 2001
From: Christian <chgottsc@uni-potsdam.de>
Date: Thu, 26 Jul 2018 13:10:43 +0200
Subject: [PATCH] feat. dozentenbewertung in db speichern

---
 .../controller/model/Assessment.java          | 94 +++++++++++++++---
 .../controller/view/AssessmentView.java       | 33 ++++++-
 .../assets/js/AlertAssessmentOutlier.js       | 96 +++++++------------
 .../main/webapp/pages/project-docent_CG.jsp   |  2 +-
 .../modules/assessment/TestAddAssessment.java | 11 ++-
 5 files changed, 160 insertions(+), 76 deletions(-)

diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/model/Assessment.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/model/Assessment.java
index 1e6abcd3..5e3278f8 100644
--- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/model/Assessment.java
+++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/model/Assessment.java
@@ -1,5 +1,6 @@
 package unipotsdam.gf.modules.assessment.controller.model;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import unipotsdam.gf.core.database.mysql.MysqlConnect;
 import unipotsdam.gf.core.database.mysql.VereinfachtesResultSet;
 import unipotsdam.gf.core.management.project.Project;
@@ -15,46 +16,67 @@ import java.util.ArrayList;
 
 import javax.xml.bind.annotation.XmlRootElement;
 import java.util.ArrayList;
+import java.util.Date;
 
 @XmlRootElement
 
 public class Assessment {
-    private StudentIdentifier student;
+    private StudentIdentifier student;// gemeint als Ziel der Bewertung, kann auch gruppe sein
+    @JsonIgnore
     private Performance performance;
+
     private StudentIdentifier bewertender;
+    private String projektId;
+    private int bewertung;
+    private boolean adressat;
+    private Date deadline;
 
     public Assessment(StudentIdentifier student, Performance performance) {
         this.student = student;
         this.performance = performance;
     }
 
-    public Assessment(){}
+    public Assessment(boolean adressat,StudentIdentifier student, Date deadline, StudentIdentifier bewertender, String projektId, int bewertung) {
+        this.student = student;
+        this.deadline = deadline;
+        this.bewertender = bewertender;
+        this.projektId = projektId;
+        this.bewertung = bewertung;
+        this.adressat=adressat;
+    }
+
+    public Assessment() {
+    }
 
-    public ArrayList<Performance> getTotalAssessment() { return null; }
+    public ArrayList<Performance> getTotalAssessment() {
+        return null;
+    }
 
     public StudentIdentifier getStudent() {
         return student;
     }
 
+    public StudentIdentifier getBewertender() {
+        return bewertender;
+    }
+
+    public void setBewertender(StudentIdentifier bewertender) {
+        this.bewertender = bewertender;
+    }
+
     public void setStudent(StudentIdentifier student) {
         this.student = student;
     }
 
+    @JsonIgnore
     public Performance getPerformance() {
         return performance;
     }
-
+    @JsonIgnore
     public void setPerformance(Performance performance) {
         this.performance = performance;
     }
 
-    public void setAssessment(User user, Assessment assessment){
-        MysqlConnect connect = new MysqlConnect();
-        connect.connect();
-        String mysqlRequest = "INSERT INTO assessments ( `BewertenderId`, `BewerteterId`, `Bewertung`,`StuoGrp`) values (?,?,?,?)";
-        connect.issueInsertOrDeleteStatement(mysqlRequest, "tom" ,user.getName() , assessment.getPerformance().getWorkRating()[0], user.getStudent());
-        connect.close();
-    }
     @Override
     public String toString() {
         return "Assessment{" +
@@ -62,4 +84,52 @@ public class Assessment {
                 ", performance=" + performance +
                 '}';
     }
-}
+
+    public int getBewertung() {
+        return bewertung;
+    }
+
+    public void setBewertung(int bewertung) {
+        this.bewertung = bewertung;
+    }
+
+    public String getProjektId() {
+        return projektId;
+    }
+
+    public void setProjektId(String projektId) {
+        this.projektId = projektId;
+    }
+
+
+    public void setAssessment(Assessment assessment) {
+        MysqlConnect connect = new MysqlConnect();
+        connect.connect();
+        String mysqlRequest = "INSERT INTO assessments ( `Adressat`, `Deadline`, `ErstellerId`,`EmpfängerId`, `ProjektId`, `Bewertung`) values (?,?,?,?,?,?)";
+        connect.issueInsertOrDeleteStatement(mysqlRequest,
+                assessment.isAdressat(),
+                assessment.getDeadline(),
+                assessment.getBewertender().getStudentId(),
+                assessment.getStudent().getStudentId(),
+                assessment.getProjektId(),
+                assessment.getBewertung()
+        );
+        connect.close();
+    }
+
+    public boolean isAdressat() {
+        return adressat;
+    }
+
+    public void setAdressat(boolean adressat) {
+        this.adressat = adressat;
+    }
+
+    public Date getDeadline() {
+        return deadline;
+    }
+
+    public void setDeadline(Date deadline) {
+        this.deadline = deadline;
+    }
+}
\ No newline at end of file
diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/view/AssessmentView.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/view/AssessmentView.java
index f71b4144..f533477f 100644
--- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/view/AssessmentView.java
+++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/assessment/controller/view/AssessmentView.java
@@ -12,19 +12,48 @@ import javax.annotation.PostConstruct;
 import javax.ws.rs.*;
 import javax.ws.rs.core.MediaType;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
-@Path("/assessments")
+@Path("/assessments2")
 public class AssessmentView implements IPeerAssessment{
     private static IPeerAssessment peer =  new PeerAssessmentDummy();
     @POST
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
-    @Path("/calculate2")
+    @Path("/calculate3")
     @Override
     public List<Grading> calculateAssessment(ArrayList<Performance> totalPerformance) {
         return peer.calculateAssessment(totalPerformance);
     }
+
+    @POST
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.TEXT_PLAIN)
+    @Path("/calculate2")
+    public String testDesReturn(Assessment assessment){
+        Assessment shuttle = new Assessment();  //neues Objekt, dass dann bearbeitet werden kann
+        //System.out.println(assessment.getBewertung());
+        shuttle.setAssessment(assessment);      //inhalte werden in die DB geschrieben und es wird erfolg zurückgemeldet
+        return "1";
+    }
+    /*}
+    @GET
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Path("dummy/calculate2")
+    public Assessment dummyAssessment(){
+        StudentIdentifier student = new StudentIdentifier("projectID", "StudentId");
+        Performance performance;
+        StudentIdentifier bewertender;
+        String projektId;
+        int bewertung;
+         boolean adressat;
+        Date deadline;
+        Assessment shuttle = new Assessment(student, )
+
+        return null;
+    }*/
+
     @Override
     public void addAssessmentDataToDB(Assessment assessment) {
     }
diff --git a/gemeinsamforschen/src/main/webapp/assets/js/AlertAssessmentOutlier.js b/gemeinsamforschen/src/main/webapp/assets/js/AlertAssessmentOutlier.js
index 42c36922..e0b6d5d7 100644
--- a/gemeinsamforschen/src/main/webapp/assets/js/AlertAssessmentOutlier.js
+++ b/gemeinsamforschen/src/main/webapp/assets/js/AlertAssessmentOutlier.js
@@ -12,18 +12,34 @@ $(document).ready(function () {
 $(document).ready(function () {
     $('#ProblemGrp1').on('click',function () {
         var alarm = prompt("hier gibt es Unstimmigeiten","Vorgeschlagene Note:")
-        if (alarm === "1") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "2") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "3") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "4") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "5") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "6") {
-            document.getElementById("demo").innerHTML = alarm;
+        if (alarm === "1"||alarm=="2"||alarm=="3"||alarm=="4"||alarm=="5"||alarm=="6") {
+
+        var dataP= JSON.stringify({"adressat":true,"student": {
+                "projectId": "projekt2",
+                "studentId": "fgnxnw"
+            }, "deadline":new Date(),
+            "bewertender": {
+                "projectId": "projekt2",
+                "studentId": "christians"
+            },
+            "projektId":"projekt2",
+            "bewertung":alarm
+        });
+            $.ajax({
+                url: "../rest/assessments2/calculate2",
+                type: 'POST',
+                headers: {
+                    "Content-Type": "application/json",
+                    "Cache-Control": "no-cache"
+                },
+                data: dataP,
+                success: function (response) {
+                    document.getElementById('ProblemGrp1').innerHTML=response;
+                },
+                error: function (a,b,c) {
+                    alert('some error' + b);
+                }
+            })
         }
         else{
             window.alert("Bitte eine Zahl zwischen eins und 6 angeben")
@@ -34,18 +50,8 @@ $(document).ready(function () {
 $(document).ready(function () {
     $('#ProblemGrp1S1').on('click',function () {
         var alarm = prompt("hier gibt es Unstimmigeiten","Vorgeschlagene Note:")
-        if (alarm === "1") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "2") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "3") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "4") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "5") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "6") {
-            document.getElementById("demo").innerHTML = alarm;
+        if (alarm === "1"||alarm=="2"||alarm=="3"||alarm=="4"||alarm=="5"||alarm=="6") {
+            document.getElementById("ProblemGrp1S1").innerHTML = alarm;
         }
         else{
             window.alert("Bitte eine Zahl zwischen eins und 6 angeben")
@@ -55,18 +61,8 @@ $(document).ready(function () {
 $(document).ready(function () {
     $('#ProblemGrp1S2').on('click',function () {
         var alarm = prompt("hier gibt es Unstimmigeiten","Vorgeschlagene Note:")
-        if (alarm === "1") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "2") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "3") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "4") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "5") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "6") {
-            document.getElementById("demo").innerHTML = alarm;
+        if (alarm === "1"||alarm=="2"||alarm=="3"||alarm=="4"||alarm=="5"||alarm=="6") {
+            document.getElementById("ProblemGrp1S2").innerHTML = alarm;
         }
         else{
             window.alert("Bitte eine Zahl zwischen eins und 6 angeben")
@@ -76,18 +72,8 @@ $(document).ready(function () {
 $(document).ready(function () {
     $('#ProblemGrp2').on('click',function () {
         var alarm = prompt("hier gibt es Unstimmigeiten","Vorgeschlagene Note:")
-        if (alarm === "1") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "2") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "3") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "4") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "5") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "6") {
-            document.getElementById("demo").innerHTML = alarm;
+        if (alarm === "1"||alarm=="2"||alarm=="3"||alarm=="4"||alarm=="5"||alarm=="6") {
+            document.getElementById("ProblemGrp2").innerHTML = alarm;
         }
         else{
             window.alert("Bitte eine Zahl zwischen eins und 6 angeben")
@@ -97,18 +83,8 @@ $(document).ready(function () {
 $(document).ready(function () {
     $('#ProblemGrp2S3').on('click',function () {
         var alarm = prompt("hier gibt es Unstimmigeiten","Vorgeschlagene Note:")
-        if (alarm === "1") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "2") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "3") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "4") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "5") {
-            document.getElementById("demo").innerHTML = alarm;
-        } else if (alarm === "6") {
-            document.getElementById("demo").innerHTML = alarm;
+        if (alarm === "1"||alarm=="2"||alarm=="3"||alarm=="4"||alarm=="5"||alarm=="6") {
+            document.getElementById("ProblemGrp2S3").innerHTML = alarm;
         }
         else{
             window.alert("Bitte eine Zahl zwischen eins und 6 angeben")
diff --git a/gemeinsamforschen/src/main/webapp/pages/project-docent_CG.jsp b/gemeinsamforschen/src/main/webapp/pages/project-docent_CG.jsp
index 5924b674..377db7d8 100644
--- a/gemeinsamforschen/src/main/webapp/pages/project-docent_CG.jsp
+++ b/gemeinsamforschen/src/main/webapp/pages/project-docent_CG.jsp
@@ -42,7 +42,7 @@
                             <table class="table">
                                 <thead>
                                 <tr>
-                                    <th>Gruppe1 </th>
+                                    <th id="testAjax">Gruppe1 </th>
                                     <th>Beiträge </th>
                                     <th> <button id="ProblemGrp1">!</button> </th>
                                 </tr>
diff --git a/gemeinsamforschen/src/test/java/unipotsdam/gf/modules/assessment/TestAddAssessment.java b/gemeinsamforschen/src/test/java/unipotsdam/gf/modules/assessment/TestAddAssessment.java
index 564d54cc..2e5ff313 100644
--- a/gemeinsamforschen/src/test/java/unipotsdam/gf/modules/assessment/TestAddAssessment.java
+++ b/gemeinsamforschen/src/test/java/unipotsdam/gf/modules/assessment/TestAddAssessment.java
@@ -7,6 +7,8 @@ import unipotsdam.gf.modules.assessment.controller.service.FBAssessement;
 import unipotsdam.gf.modules.assessment.controller.model.Performance;
 import unipotsdam.gf.modules.assessment.controller.model.StudentIdentifier;
 
+import java.util.Date;
+
 public class TestAddAssessment {
 
     @Test
@@ -26,7 +28,14 @@ public class TestAddAssessment {
         StudentIdentifier student = new StudentIdentifier("Spaß", "Haralf");
         Performance performance = new Performance(student, quizAnswers,"so ein toller Typ", workRating);
         Assessment assessment = new Assessment(student, performance);
-        iPeerAssessment.addAssessmentDataToDB(assessment);
+        //iPeerAssessment.addAssessmentDataToDB(assessment);
+    }
+    @Test
+    public void testSetAssessment(){
+        StudentIdentifier ersteller=new StudentIdentifier("projekt","christian");
+        StudentIdentifier empfaenger=new StudentIdentifier("projekt","fgnxn");
+        Assessment testAssessment=new Assessment(true,empfaenger,new Date(),ersteller,"projekt",4);
+        testAssessment.setAssessment(testAssessment);
     }
 
 }
-- 
GitLab