Skip to content

Commit

Permalink
Merge pull request #9 from rwth-acis/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
Tobasco99 authored Jun 12, 2024
2 parents afd0b80 + b06b751 commit 38d781f
Show file tree
Hide file tree
Showing 8 changed files with 2,141 additions and 3,048 deletions.
86 changes: 2 additions & 84 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,14 @@ sourceSets {
repositories {
// Use MavenCentral for resolving dependencies.
mavenCentral()

// DBIS Archiva
maven {
url "https://archiva.dbis.rwth-aachen.de:9911/repository/internal/"
}
}

dependencies {
// las2peer bundle dependency
implementation "io.github.rwth-acis.org.las2peer:las2peer-bundle:${project.property('core.version')}"
// Use JUnit test framework.
testImplementation "junit:junit:4.13.2"
// las2peer bundle which is not necessary in the runtime path
// compileOnly will be moved into the lib dir afterwards
implementation "i5:las2peer-bundle:${project.property('core.version')}"

// Add service dependencies here
// example:
Expand Down Expand Up @@ -155,83 +150,6 @@ pause

build.dependsOn "startscripts"

def startup = "$rootDir/etc/startup"
def userAgent1Path = "${startup}/agent-user-${project.property('las2peer_user1.name')}.xml"
def userAgent2Path = "${startup}/agent-user-${project.property('las2peer_user2.name')}.xml"
def userAgent3Path = "${startup}/agent-user-${project.property('las2peer_user3.name')}.xml"
def passphrasesPath = "${startup}/passphrases.txt"

task generateUserAgent1 {
dependsOn "jar"

onlyIf { !(new File(userAgent1Path).exists()) }

doLast {
tasks.create("generateUserAgent1Help", JavaExec) {
println "Writing User Agent xml to ${userAgent1Path}"

main = "i5.las2peer.tools.UserAgentGenerator"
classpath = sourceSets.main.compileClasspath
args "${project.property('las2peer_user1.password')}", "${project.property('las2peer_user1.name')}", "${project.property('las2peer_user1.email')}"
mkdir "${startup}"
standardOutput new FileOutputStream(userAgent1Path)
}.exec()
}
}

task generateUserAgent2 {
dependsOn "jar"

onlyIf { !(new File(userAgent2Path).exists()) }

doLast {
tasks.create("generateUserAgent2Help", JavaExec) {
println "Writing User Agent xml to ${userAgent2Path}"

main = "i5.las2peer.tools.UserAgentGenerator"
classpath = sourceSets.main.compileClasspath
args "${project.property('las2peer_user2.password')}", "${project.property('las2peer_user2.name')}", "${project.property('las2peer_user2.email')}"
mkdir "${startup}"
standardOutput new FileOutputStream(userAgent2Path)
}.exec()
}
}

task generateUserAgent3 {
dependsOn "jar"

onlyIf { !(new File(userAgent3Path).exists()) }

doLast {
tasks.create("generateUserAgent3Help", JavaExec) {
println "Writing User Agent xml to ${userAgent3Path}"

main = "i5.las2peer.tools.UserAgentGenerator"
classpath = sourceSets.main.compileClasspath
args "${project.property('las2peer_user3.password')}", "${project.property('las2peer_user3.name')}", "${project.property('las2peer_user3.email')}"
mkdir "${startup}"
standardOutput new FileOutputStream(userAgent3Path)
}.exec()
}
}

// generate example user agents
task generateAgents {
description "Generate example user agents"
dependsOn "generateUserAgent1"
dependsOn "generateUserAgent2"
dependsOn "generateUserAgent3"

doLast {
new File(passphrasesPath).text = """agent-user-${project.property('las2peer_user1.name')}.xml;${project.property('las2peer_user1.password')}
agent-user-${project.property('las2peer_user2.name')}.xml;${project.property('las2peer_user2.password')}
agent-user-${project.property('las2peer_user3.name')}.xml;${project.property('las2peer_user3.password')}
"""
}
}

build.dependsOn "generateAgents"

clean.doLast {
file("$rootDir/tmp").deleteDir()
file("$rootDir/lib").deleteDir()
Expand Down
4 changes: 2 additions & 2 deletions app/etc/texts.properties
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ changeAnswerExplanationDE = \nUm eine Antwort zu aendern kannst du deine Nachric
changeAnswerExplanationButtonDE = , oder erneut auf einen Button klickst.
firstDE = \tUm eine zweite Umfrage zu starten musst du alle Fragen der ersten Umfrage beantwortet haben.
resultsGetSavedDE = \nDeine Antworten werden kontinuierlich gespeichert.
completedSurveyDE = Du hast die Umfrage bereits vollstaendig beantwortet.
completedSurveyDE = Du hast die Umfrage vollstaendig beantwortet.
changedAnswerDE = Deine Antwort wurde erfolgreich geaendert.
surveyDoneStringDE = Danke fuer deine Teilnahme :slightly_smiling_face:
surveyDoneStringDE = Du hast die Umfrage vollstaendig beantwortet.
firstEditDE = Wenn du Antworten zu dieser Umfrage aendern mochtest, mache dies bitte bevor du die naechste Umfrage startest.
welcomeStringDE = {hello}Schreibe mir eine Nachricht im Chat und ich werde die Umfrage "{title}" mit dir durchfuehren. Es gibt {questionsInSurvey} Fragen die du beantworten kannst. {welcomeText} \n\nHier sind ein paar Hinweise:\n
skipTextDE = Diese Frage wurde von dir uebersprungen, du kannst sie jetzt beantworten oder erneut skippen: \n
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package i5.las2peer.services.SurveyHandler;

import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;

import java.util.ArrayList;

public class AnswerOptionHelper {

public static JSONArray buildAnswerOption(String type, ArrayList<AnswerOption> options) {
JSONArray interactiveElements = new JSONArray();
switch (Question.qType.fromName(type)){
case DICHOTOMOUS:
case LISTRADIO:
case SCALE:
case LISTDROPDOWN:
case ARRAY:
interactiveElements = buildMC(options);
break;
case GENDER:
interactiveElements = buildGender();
break;
case YESNO:
interactiveElements.add(buildButton("Survey Answer Option 1", "Ja"));
interactiveElements.add(buildButton("Survey Answer Option 2", "Nein"));
break;
case FIVESCALE:
interactiveElements.add(buildButton("Survey Answer Option 1", "1"));
interactiveElements.add(buildButton("Survey Answer Option 2", "2"));
interactiveElements.add(buildButton("Survey Answer Option 3", "3"));
interactiveElements.add(buildButton("Survey Answer Option 4", "4"));
interactiveElements.add(buildButton("Survey Answer Option 5", "5"));
break;
}
return interactiveElements;
}

private static JSONArray buildGender() {
JSONArray array = new JSONArray();
array.add(buildButton("Survey Answer Option 1", "Weiblich"));
array.add(buildButton("Survey Answer Option 2", "Maennlich"));
array.add(buildButton("Survey Answer Option 3", "Keine Angabe"));
return array;
}

private static JSONArray buildMC(ArrayList<AnswerOption> options){
JSONArray array = new JSONArray();
for(int i = 1; i < options.size() + 1; i++){
array.add(buildButton("Survey Answer Option " + i, getAnswerOptionByIndex(i, options).getText()));
}
return array;
}

public static AnswerOption getAnswerOptionByIndex(Integer index, ArrayList<AnswerOption> options){
for(AnswerOption ao : options){
if(ao.getIndexi().equals(index)){
return ao;
}
}
return null;
}

private static JSONObject buildButton(String intent, String label){
JSONObject button = new JSONObject();
button.put("intent", intent);
button.put("label", label);
button.put("description", label);
button.put("isFile", false);
return button;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package i5.las2peer.services.SurveyHandler;
/**
* Enum representing different types of messengers.
*/
public enum Messenger {
SLACK("Slack"),
ROCKETCHAT("Rocket.Chat"),
TELEGRAM("Telegram"),

RESTFUL("Restful");

private final String name;

/**
* Returns the name of the messenger.
*
* @return A string representing the name of the messenger.
*/
@Override
public String toString(){
return this.name;
}

/**
* Constructor for the Messenger enum.
*
* @param name The name of the messenger.
*/
Messenger(String name){
this.name= name;
}
}
Loading

0 comments on commit 38d781f

Please sign in to comment.