Procházet zdrojové kódy

uploaded state

master
DemiSel před 2 roky
rodič
revize
50f1503627

+ 11
- 0
backend/.idea/artifacts/backend_src_main_jar.xml Zobrazit soubor

@@ -0,0 +1,11 @@
1
+<component name="ArtifactManager">
2
+  <artifact type="jar" name="backend.src.main:jar">
3
+    <output-path>$PROJECT_DIR$/out/artifacts/backend_src_main_jar</output-path>
4
+    <root id="archive" name="backend.src.main.jar">
5
+      <element id="directory" name="META-INF">
6
+        <element id="file-copy" path="$PROJECT_DIR$/META-INF/MANIFEST.MF" />
7
+      </element>
8
+      <element id="module-output" name="backend.src.main" />
9
+    </root>
10
+  </artifact>
11
+</component>

+ 3
- 0
backend/META-INF/MANIFEST.MF Zobrazit soubor

@@ -0,0 +1,3 @@
1
+Manifest-Version: 1.0
2
+Main-Class: Application
3
+

+ 19
- 0
backend/build.gradle Zobrazit soubor

@@ -13,11 +13,30 @@ dependencies {
13 13
     compile 'com.github.cliftonlabs:json-simple:3.1.1'
14 14
 }
15 15
 
16
+
16 17
 dependencies {
17 18
     testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
18 19
     testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
19 20
 }
20 21
 
22
+//create a single Jar with all dependencies
23
+task fatJar(type: Jar) {
24
+    manifest {
25
+        attributes 'Implementation-Title': 'Gradle Jar Package',
26
+                'Implementation-Version': version,
27
+                'Main-Class': 'Application'
28
+    }
29
+    baseName = project.name
30
+    from {
31
+        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
32
+
33
+    }
34
+    from('src/main/java'){
35
+        include 'resources/*'
36
+    }
37
+    with jar
38
+}
39
+
21 40
 test {
22 41
     useJUnitPlatform()
23 42
 }

+ 8
- 1
backend/src/main/java/Application.java Zobrazit soubor

@@ -10,15 +10,22 @@ import java.util.Arrays;
10 10
 
11 11
 public class Application {
12 12
 
13
+
14
+
13 15
     public static void main(String [] args)
14 16
     {
17
+        int port = 8080;
18
+        //Optionally expect a port number as argument
19
+        if(args.length > 0)
20
+            port = Integer.parseInt(args[0]);
15 21
 
16 22
         Questionnaire vQuestionnaire = getQuestionnaire();
23
+
17 24
         //------------------------------------
18 25
         // Start server
19 26
         //------------------------------------
20 27
         try {
21
-            HttpServer vServer = HttpServer.create(new InetSocketAddress(8080), 0);
28
+            HttpServer vServer = HttpServer.create(new InetSocketAddress(port), 0);
22 29
             vServer.createContext("/", new ResponseHandler());
23 30
             vServer.setExecutor(null);
24 31
             vServer.start();

+ 0
- 1
backend/src/main/java/api/JsonKeys.java Zobrazit soubor

@@ -10,7 +10,6 @@ public enum JsonKeys implements JsonKey {
10 10
     KEY_DESCRIPTION("description"),
11 11
     KEY_NAME("name"),
12 12
     KEY_ID("id"),
13
-    KEY_TRAIT("trait"),
14 13
     KEY_TRAITS("traits"),
15 14
     KEY_WEIGHT("weight"),
16 15
     KEY_RESULTS("results");

+ 1
- 0
backend/src/main/java/model/questionnaire/Question.java Zobrazit soubor

@@ -28,6 +28,7 @@ public class Question implements Jsonable {
28 28
         sQuestions.put(fId, this);
29 29
     }
30 30
 
31
+    public UUID getId(){return fId;}
31 32
 
32 33
     public static Question getForUUID(UUID iId) {
33 34
         return sQuestions.get(iId);

+ 3
- 0
backend/src/main/resources/META-INF/MANIFEST.MF Zobrazit soubor

@@ -0,0 +1,3 @@
1
+Manifest-Version: 1.0
2
+Main-Class: Application
3
+

+ 11
- 4
backend/src/test/java/api/ResponseHandlerTest.java Zobrazit soubor

@@ -10,6 +10,14 @@ import static org.junit.jupiter.api.Assertions.*;
10 10
 
11 11
 class ResponseHandlerTest {
12 12
 
13
+    public String getSessionId(ResponseHandler iResponseHandler){
14
+        //Get a valid session id
15
+        SessionController vSessionController = new SessionController();
16
+        JsonObject vSessionObject = iResponseHandler.getResponse("GET",new String[]{},"", vSessionController);
17
+        assertTrue(vSessionObject.containsKey("id"));
18
+        return (String) vSessionObject.get("id");
19
+    }
20
+
13 21
     @Test
14 22
     public void TestGetResponse(){
15 23
         ResponseHandler vResponseHandler = new ResponseHandler();
@@ -29,9 +37,7 @@ class ResponseHandlerTest {
29 37
 
30 38
         //Get a valid session id
31 39
         SessionController vSessionController = new SessionController();
32
-        JsonObject vSessionObject = vResponseHandler.getResponse("GET",new String[]{},"", vSessionController);
33
-        assertTrue(vSessionObject.containsKey("id"));
34
-        String vSessionId = (String) vSessionObject.get("id");
40
+        String vSessionId = getSessionId(vResponseHandler);
35 41
 
36 42
         //Verify error management in various cases
37 43
         String[] vPathSession = new String[]{vSessionId};
@@ -50,6 +56,7 @@ class ResponseHandlerTest {
50 56
             assertNotEquals(null, vResponseObject.get("error"));
51 57
         }
52 58
 
53
-
54 59
     }
60
+
61
+
55 62
 }

+ 105
- 1
backend/src/test/java/controller/SessionControllerTest.java Zobrazit soubor

@@ -1,4 +1,108 @@
1
+package controller;
2
+
3
+import api.ResponseHandler;
4
+import com.github.cliftonlabs.json_simple.JsonArray;
5
+import com.github.cliftonlabs.json_simple.JsonObject;
6
+import model.personnality.Trait;
7
+import model.questionnaire.Answer;
8
+import model.questionnaire.Question;
9
+import model.questionnaire.Questionnaire;
10
+import org.junit.jupiter.api.Test;
11
+
12
+import java.util.Arrays;
13
+import java.util.List;
14
+import java.util.UUID;
15
+
1 16
 import static org.junit.jupiter.api.Assertions.*;
17
+
2 18
 class SessionControllerTest {
3
-  
19
+
20
+    public String getSessionId(ResponseHandler iResponseHandler){
21
+        //Get a valid session id
22
+        SessionController vSessionController = new SessionController();
23
+        JsonObject vSessionObject = iResponseHandler.getResponse("GET",new String[]{},"", vSessionController);
24
+        assertTrue(vSessionObject.containsKey("id"));
25
+        return (String) vSessionObject.get("id");
26
+    }
27
+
28
+    public float getTraitWeight(JsonObject iJsonObject)
29
+    {
30
+        return (float) ((JsonObject)((JsonArray)((JsonObject) iJsonObject.get("results")).get("traits")).get(0)).get("weight");
31
+    }
32
+
33
+    @Test
34
+    public void TestSessionController(){
35
+        ResponseHandler vHandler = new ResponseHandler();
36
+        SessionController vController = new SessionController();
37
+        String vSessionId = getSessionId(vHandler);
38
+
39
+        Trait vTrait1 = new Trait("1","desc1");
40
+        Trait vTrait2 = new Trait("2","desc2");
41
+
42
+        Answer vAnswer0 = new Answer("1",vTrait1,0);
43
+        Answer vAnswerMax = new Answer("2",vTrait1,Float.MAX_VALUE);
44
+        Answer vAnswerMin = new Answer("3",vTrait1,Float.MIN_VALUE);
45
+
46
+        Question vQuestion1 = new Question("1", Arrays.asList(
47
+                vAnswer0,
48
+                vAnswerMax,
49
+                vAnswerMin
50
+        ));
51
+        Question vQuestion2 = new Question("2", Arrays.asList(
52
+                vAnswer0,
53
+                vAnswerMax,
54
+                vAnswerMin
55
+        ));
56
+
57
+        Questionnaire vQuestionnaire = new Questionnaire("1",Arrays.asList(
58
+                vQuestion1,vQuestion2
59
+        ));
60
+        //Verify update session question answer
61
+        JsonObject vObject = new JsonObject().putChain("question",vQuestion1.getId().toString()).putChain("answer",vAnswerMax.getId().toString());
62
+        try {
63
+            vController.updateEntry(vSessionId,vObject);
64
+        } catch (Exception e) {
65
+            assertNotEquals(false,true);
66
+            e.printStackTrace();
67
+        }
68
+        assertEquals(Float.MAX_VALUE,getTraitWeight(vController.getEntriesForId(vSessionId,null)));
69
+        try {
70
+            vController.updateEntry(vSessionId,vObject);
71
+        } catch (Exception e) {
72
+            assertNotEquals(false,true);
73
+            e.printStackTrace();
74
+        }
75
+        assertEquals(Float.MAX_VALUE,getTraitWeight(vController.getEntriesForId(vSessionId,null)));
76
+
77
+        vObject.putChain("answer", vAnswerMin.getId().toString());
78
+
79
+        try {
80
+            vController.updateEntry(vSessionId,vObject);
81
+        } catch (Exception e) {
82
+            assertNotEquals(false,true);
83
+            e.printStackTrace();
84
+        }
85
+        assertEquals(Float.MIN_VALUE,getTraitWeight(vController.getEntriesForId(vSessionId,null)));
86
+
87
+        try {
88
+            vController.updateEntry(vSessionId,vObject);
89
+        } catch (Exception e) {
90
+            assertNotEquals(false,true);
91
+            e.printStackTrace();
92
+        }
93
+        assertEquals(Float.MIN_VALUE,getTraitWeight(vController.getEntriesForId(vSessionId,null)));
94
+
95
+        vObject.putChain("answer",1);
96
+        assertThrows(Exception.class, () -> vController.updateEntry(vSessionId,vObject));
97
+        assertEquals(Float.MIN_VALUE,getTraitWeight(vController.getEntriesForId(vSessionId,null)));
98
+
99
+        vObject.putChain("answer","12");
100
+        assertThrows(Exception.class, () -> vController.updateEntry(vSessionId,vObject));
101
+        assertEquals(Float.MIN_VALUE,getTraitWeight(vController.getEntriesForId(vSessionId,null)));
102
+
103
+        vObject.putChain("answer", UUID.randomUUID().toString());
104
+        assertThrows(Exception.class, () -> vController.updateEntry(vSessionId,vObject));
105
+        assertEquals(Float.MIN_VALUE,getTraitWeight(vController.getEntriesForId(vSessionId,null)));
106
+
107
+    }
4 108
 }

+ 19
- 7
frontend/package-lock.json Zobrazit soubor

@@ -7995,17 +7995,19 @@
7995 7995
       "integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg=="
7996 7996
     },
7997 7997
     "mini-css-extract-plugin": {
7998
-      "version": "2.5.0",
7999
-      "resolved": "https://registry.npmjs.org/mini-css-extract-plugin/-/mini-css-extract-plugin-2.5.0.tgz",
8000
-      "integrity": "sha512-hWAswjzsausaaIjk4GiUtoiNnsMc8tLAA2TZ0vbMDZcxKYS/b3UBGNElBjgQ4QYztYR+nsKp5h2Lo1NL3zz2bg==",
7998
+      "version": "2.4.5",
7999
+      "resolved": "https://registry.npmjs.org/mini-css-extract-plugin/-/mini-css-extract-plugin-2.4.5.tgz",
8000
+      "integrity": "sha512-oEIhRucyn1JbT/1tU2BhnwO6ft1jjH1iCX9Gc59WFMg0n5773rQU0oyQ0zzeYFFuBfONaRbQJyGoPtuNseMxjA==",
8001
+      "dev": true,
8001 8002
       "requires": {
8002 8003
         "schema-utils": "^4.0.0"
8003 8004
       },
8004 8005
       "dependencies": {
8005 8006
         "ajv": {
8006
-          "version": "8.8.2",
8007
-          "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.8.2.tgz",
8008
-          "integrity": "sha512-x9VuX+R/jcFj1DHo/fCp99esgGDWiHENrKxaCENuCxpoMCmAt/COCGVDwA7kleEpEzJjDnvh3yGoOuLu0Dtllw==",
8007
+          "version": "8.9.0",
8008
+          "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.9.0.tgz",
8009
+          "integrity": "sha512-qOKJyNj/h+OWx7s5DePL6Zu1KeM9jPZhwBqs+7DzP6bGOvqzVCSf0xueYmVuaC/oQ/VtS2zLMLHdQFbkka+XDQ==",
8010
+          "dev": true,
8009 8011
           "requires": {
8010 8012
             "fast-deep-equal": "^3.1.1",
8011 8013
             "json-schema-traverse": "^1.0.0",
@@ -8017,6 +8019,7 @@
8017 8019
           "version": "5.1.0",
8018 8020
           "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-5.1.0.tgz",
8019 8021
           "integrity": "sha512-YCS/JNFAUyr5vAuhk1DWm1CBxRHW9LbJ2ozWeemrIqpbsqKjHVxYPyi5GC0rjZIT5JxJ3virVTS8wk4i/Z+krw==",
8022
+          "dev": true,
8020 8023
           "requires": {
8021 8024
             "fast-deep-equal": "^3.1.3"
8022 8025
           }
@@ -8024,12 +8027,14 @@
8024 8027
         "json-schema-traverse": {
8025 8028
           "version": "1.0.0",
8026 8029
           "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
8027
-          "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="
8030
+          "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
8031
+          "dev": true
8028 8032
         },
8029 8033
         "schema-utils": {
8030 8034
           "version": "4.0.0",
8031 8035
           "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-4.0.0.tgz",
8032 8036
           "integrity": "sha512-1edyXKgh6XnJsJSQ8mKWXnN/BVaIbFMLpouRUrXgVq7WYne5kw3MW7UPhO44uRXQSIpTSXoJbmrR2X0w9kUTyg==",
8037
+          "dev": true,
8033 8038
           "requires": {
8034 8039
             "@types/json-schema": "^7.0.9",
8035 8040
             "ajv": "^8.8.0",
@@ -9568,6 +9573,13 @@
9568 9573
         "webpack-dev-server": "^4.6.0",
9569 9574
         "webpack-manifest-plugin": "^4.0.2",
9570 9575
         "workbox-webpack-plugin": "^6.4.1"
9576
+      },
9577
+      "dependencies": {
9578
+        "mini-css-extract-plugin": {
9579
+          "version": "2.4.5",
9580
+          "resolved": "https://registry.npmjs.org/mini-css-extract-plugin/-/mini-css-extract-plugin-2.4.5.tgz",
9581
+          "integrity": "sha512-oEIhRucyn1JbT/1tU2BhnwO6ft1jjH1iCX9Gc59WFMg0n5773rQU0oyQ0zzeYFFuBfONaRbQJyGoPtuNseMxjA=="
9582
+        }
9571 9583
       }
9572 9584
     },
9573 9585
     "readable-stream": {

+ 1
- 0
frontend/package.json Zobrazit soubor

@@ -2,6 +2,7 @@
2 2
   "name": "frontend",
3 3
   "version": "0.1.0",
4 4
   "private": true,
5
+  "homepage": "https://demisel.space/teamway",
5 6
   "dependencies": {
6 7
     "@nivo/core": "^0.79.0",
7 8
     "@nivo/radar": "^0.79.1",

+ 0
- 1
frontend/src/component/question.js Zobrazit soubor

@@ -1,6 +1,5 @@
1 1
 import React from 'react';
2 2
 import url from '../server';
3
-import Questionnaire from './questionnaire';
4 3
 
5 4
 function Question(props){
6 5
     let current_question = props.questions[props.index];

+ 3
- 4
frontend/src/component/questionnaire_result.js Zobrazit soubor

@@ -1,5 +1,4 @@
1 1
 import React from 'react';
2
-import { createPortal } from 'react-dom';
3 2
 import url from '../server';
4 3
 import {ResponsiveRadar} from "@nivo/radar"
5 4
 
@@ -44,12 +43,12 @@ function QuestionnaireResult(props){
44 43
         })
45 44
 
46 45
         // two traits : display them on a scale
47
-        if(radar_data.length == 2)
46
+        if(radar_data.length === 2)
48 47
         {
49 48
              
50 49
             scale_start = dominant.name;
51 50
             
52
-            scale_end = radar_data[0].trait == scale_start ? radar_data[1].trait : radar_data[0].trait;
51
+            scale_end = radar_data[0].trait === scale_start ? radar_data[1].trait : radar_data[0].trait;
53 52
         }
54 53
     }
55 54
 
@@ -70,7 +69,7 @@ function QuestionnaireResult(props){
70 69
         />
71 70
         </div>
72 71
         }
73
-        { radar_data.length == 2 &&
72
+        { radar_data.length === 2 &&
74 73
         <div className="gradient bordered" 
75 74
         style={{
76 75
             "--data-weight": dominant_weight+"%",

+ 1
- 1
frontend/src/server.js Zobrazit soubor

@@ -1,7 +1,7 @@
1 1
 let url = "";
2 2
 switch(process.env.NODE_ENV) {
3 3
   case 'production':
4
-    url = 'https://demisel.space/garage/';
4
+    url = 'https://demisel.space/teamway/garage/';
5 5
     break;
6 6
   case 'development':
7 7
   default:

Načítá se…
Zrušit
Uložit