diff --git a/.classpath b/.classpath deleted file mode 100644 index d6ab6e7..0000000 --- a/.classpath +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/.gitignore b/.gitignore index c5a26fb..dc986ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,11 @@ /output/ -/export/ +/project_management_service/output/ +/project_management_service/export/ /node-storage/ /.las2peer/ /tmp/ /log/ +/project_management_service/log/ /lib/ /etc/ivy/ivy.jar /service/ @@ -18,3 +20,11 @@ /etc/startup/ *.secret archiva_credentials.xml +.project +.classpath + +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build diff --git a/.project b/.project deleted file mode 100644 index 46339d6..0000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - Project Management Service - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 415d6ea..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: java -jdk: - - openjdk8 -install: - - sudo apt-get install -y ant ant-optional -sudo: false -script: 'ant all' -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/Dockerfile b/Dockerfile index 8885c73..dc0aac3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -FROM openjdk:8-jdk-alpine +FROM openjdk:14-jdk-alpine ENV HTTP_PORT=8080 ENV HTTPS_PORT=8443 ENV LAS2PEER_PORT=9011 -RUN apk add --update bash mysql-client apache-ant && rm -f /var/cache/apk/* +RUN apk add --update bash mysql-client && rm -f /var/cache/apk/* RUN addgroup -g 1000 -S las2peer && \ adduser -u 1000 -S las2peer -G las2peer @@ -13,7 +13,7 @@ WORKDIR /src # run the rest as unprivileged user USER las2peer -RUN ant jar +RUN chmod +x gradlew && ./gradlew build --exclude-task test EXPOSE $HTTP_PORT EXPOSE $HTTPS_PORT diff --git a/README.md b/README.md index 81dcbfa..d86b0cf 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This includes creating projects and managing their components, users and roles. ## How to build this service -Building the service is just building a las2peer service. The [las2peer template project](https://github.com/rwth-acis/las2peer-Template-Project) and its wiki contain detailed information, but basically you should be able to clone the repository and execute a build using ant. +Building the service is just building a las2peer service. The [las2peer template project](https://github.com/rwth-acis/las2peer-Template-Project) and its wiki contain detailed information, but basically you should be able to clone the repository and execute a build using gradle. ## How to run using Docker diff --git a/build.xml b/build.xml deleted file mode 100644 index ff34d43..0000000 --- a/build.xml +++ /dev/null @@ -1,326 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Java/JVM version: ${ant.java.version} - Java/JVM detail version: ${java.version} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #!/bin/bash - -# this script is autogenerated by 'ant startscripts' -# it starts a las2peer node providing the service '${service.name}.${service.class}' of this project -# pls execute it from the root folder of your deployment, e. g. ./bin/start_network.sh - -java -cp "lib/*" i5.las2peer.tools.L2pNodeLauncher --port 9011 --service-directory service uploadStartupDirectory startService\(\'${service.name}.${service.class}@${service.version}\'\) startWebConnector interactive - - - :: this script is autogenerated by 'ant startscripts' -:: it starts a las2peer node providing the service '${service.name}.${service.class}' of this project -:: pls execute it from the bin folder of your deployment by double-clicking on it - -%~d0 -cd %~p0 -cd .. -set BASE=%CD% -set CLASSPATH="%BASE%/lib/*;" - -java -cp %CLASSPATH% i5.las2peer.tools.L2pNodeLauncher --port 9011 --service-directory service uploadStartupDirectory startService('${service.name}.${service.class}@${service.version}') startWebConnector interactive - -pause - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - agent-user-${las2peer_user1.name}.xml;${las2peer_user1.password} -agent-user-${las2peer_user2.name}.xml;${las2peer_user2.password} -agent-user-${las2peer_user3.name}.xml;${las2peer_user3.password} - - - - - - - - - - - - - - - - - - - - - diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 989e6d7..4450a0f 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -10,9 +10,9 @@ fi # set some helpful variables export SERVICE_PROPERTY_FILE='etc/i5.las2peer.services.projectManagementService.ProjectManagementService.properties' export WEB_CONNECTOR_PROPERTY_FILE='etc/i5.las2peer.connectors.webConnector.WebConnector.properties' -export SERVICE_VERSION=$(awk -F "=" '/service.version/ {print $2}' etc/ant_configuration/service.properties) -export SERVICE_NAME=$(awk -F "=" '/service.name/ {print $2}' etc/ant_configuration/service.properties) -export SERVICE_CLASS=$(awk -F "=" '/service.class/ {print $2}' etc/ant_configuration/service.properties) +export SERVICE_VERSION=$(awk -F "=" '/service.version/ {print $2}' gradle.properties) +export SERVICE_NAME=$(awk -F "=" '/service.name/ {print $2}' gradle.properties) +export SERVICE_CLASS=$(awk -F "=" '/service.class/ {print $2}' gradle.properties) export SERVICE=${SERVICE_NAME}.${SERVICE_CLASS}@${SERVICE_VERSION} export CREATE_DB_SQL='database/ProjectManagementService_Database.sql' export MYSQL_DATABASE='commedit' diff --git a/etc/ant_configuration/service.properties b/etc/ant_configuration/service.properties deleted file mode 100644 index 927c178..0000000 --- a/etc/ant_configuration/service.properties +++ /dev/null @@ -1,5 +0,0 @@ -service.version=0.1.0 -service.name=i5.las2peer.services.projectManagementService -service.path=i5/las2peer/services/projectManagementService -service.class=ProjectManagementService -core.version=1.0.0 \ No newline at end of file diff --git a/etc/ivy/ivy.xml b/etc/ivy/ivy.xml deleted file mode 100644 index 3fccd27..0000000 --- a/etc/ivy/ivy.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/etc/ivy/ivysettings.xml b/etc/ivy/ivysettings.xml deleted file mode 100644 index 5e9b1a6..0000000 --- a/etc/ivy/ivysettings.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - diff --git a/etc/ant_configuration/user.properties b/gradle.properties similarity index 56% rename from etc/ant_configuration/user.properties rename to gradle.properties index 0608770..8006c84 100644 --- a/etc/ant_configuration/user.properties +++ b/gradle.properties @@ -1,3 +1,9 @@ +core.version=1.1.1 +service.name=i5.las2peer.services.projectManagementService +service.class=ProjectManagementService +service.version=0.1.0 +java.version=14 + las2peer_user1.name=alice las2peer_user1.password=pwalice las2peer_user1.email=alice@example.org @@ -6,4 +12,4 @@ las2peer_user2.password=pwbobby las2peer_user2.email=bobby@example.org las2peer_user3.name=joey las2peer_user3.password=pwjoey -las2peer_user3.email=joey@example.org +las2peer_user3.email=joey@example.org \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e708b1c Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..da9702f --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..4f906e0 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/project_management_service/build.gradle b/project_management_service/build.gradle new file mode 100644 index 0000000..c787a54 --- /dev/null +++ b/project_management_service/build.gradle @@ -0,0 +1,243 @@ +plugins { + // Apply the application plugin to add support for building a CLI application in Java. + id 'application' + id 'eclipse' +} + +repositories { + // Use JCenter for resolving dependencies. + jcenter() + + // DBIS Archiva + maven { + url "https://archiva.dbis.rwth-aachen.de:9911/repository/internal/" + } +} + +dependencies { + // 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 + compileOnly "i5:las2peer-bundle:${project.property('core.version')}" + + implementation "com.googlecode.json-simple:json-simple:1.1" + implementation "org.apache.commons:commons-dbcp2:2.0" + implementation "mysql:mysql-connector-java:5.1.6" +} + +configurations { + // This ensures las2peer is available in the tests, but won't be bundled + testCompile.extendsFrom compileOnly +} + +jar { + manifest { + attributes "Main-Class": "${project.property('service.name')}.${project.property('service.class')}" + attributes "Library-Version": "${project.property('service.version')}" + attributes "Library-SymbolicName": "${project.property('service.name')}" + } + + from { (configurations.runtimeClasspath).collect { it.isDirectory() ? it : zipTree(it) } } { + // Exclude signatures to be able to natively bundle signed jars + exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA' + } +} + +application { + // Define the main class for the application. + mainClass = "${project.property('service.name')}.${project.property('service.class')}" + + group = "${project.property('service.name')}" + archivesBaseName = group + + version = "${project.property('service.version')}" + mainClassName = "i5.las2peer.tools.L2pNodeLauncher" + sourceCompatibility = "${project.property('java.version')}" + targetCompatibility = "${project.property('java.version')}" +} + +// put all .jar files into export/jars folder +tasks.withType(Jar) { + destinationDir = file("$projectDir/export/jars") +} + +javadoc { + destinationDir = file("$projectDir/export/doc") +} + +build.dependsOn "javadoc" + +compileJava { + dependsOn "copyMain" +} + +compileTestJava { + dependsOn "copyTest" +} + +// Copies .xml files into build directory +task copyMain(type: Copy) { + from "src/main/java" + include "**/*.xml" + into "$buildDir/classes/java/main" +} + +// Copies .xml files into build directory +task copyTest(type: Copy) { + from "src/test/java" + include "**/*.xml" + into "$buildDir/classes/java/test" +} + +// These two tasks restore the build and runtime environment used +// in the ant environment +task copyJar(type: Copy) { + from jar // here it automatically reads jar file produced from jar task + into "$rootDir/service" +} + +task copyToLib(type: Copy) { + from configurations.compileClasspath + into "$rootDir/lib" +} + +build.dependsOn copyJar +build.dependsOn copyToLib + +task startscripts { + new File("$rootDir/bin", "start_network.sh").text = """#!/bin/bash +# this script is autogenerated by 'gradle startscripts' +# it starts a las2peer node providing the service '${project.property('service.name')}.${project.property('service.class')}' of this project +# pls execute it from the root folder of your deployment, e. g. ./bin/start_network.sh +java -cp "lib/*" i5.las2peer.tools.L2pNodeLauncher --port 9011 --service-directory service uploadStartupDirectory startService\\(\\'${project.property('service.name')}.${project.property('service.class')}@${project.property('service.version')}\\'\\) startWebConnector interactive +""" + new File("$rootDir/bin", "start_network.bat").text = """:: this script is autogenerated by 'gradle startscripts' +:: it starts a las2peer node providing the service '${project.property('service.name')}.${project.property('service.class')}' of this project +:: pls execute it from the bin folder of your deployment by double-clicking on it +%~d0 +cd %~p0 +cd .. +set BASE=%CD% +set CLASSPATH="%BASE%/lib/*;" +java -cp %CLASSPATH% i5.las2peer.tools.L2pNodeLauncher --port 9011 --service-directory service uploadStartupDirectory startService('${project.property('service.name')}.${project.property('service.class')}@${project.property('service.version')}') startWebConnector interactive +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() + file("$rootDir/servicebundle").deleteDir() + file("$rootDir/service").deleteDir() + file("$rootDir/etc/startup").deleteDir() + file("$projectDir/export").deleteDir() +} + +task cleanAll { + dependsOn "clean" + + doLast { + file("$rootDir/log").deleteDir() + file("$rootDir/node-storage").deleteDir() + } +} + +// configuration for eclipse (this allows to import the project as a gradle project in eclipse without any problems) +eclipse { + classpath { + file { + whenMerged { + // change output directory for test, main, resources and default + def main = entries.find { it.path == "src/main/java" } + main.output = "output/main" + + def test = entries.find { it.path == "src/test/java" } + test.output = "output/test" + + def defaultEntry = entries.find { it.kind == "output" && it.path == "bin/default" } + defaultEntry.path = "output/default" + } + } + } +} \ No newline at end of file diff --git a/src/main/i5/las2peer/services/projectManagementService/ProjectManagementService.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/ProjectManagementService.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/ProjectManagementService.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/ProjectManagementService.java diff --git a/src/main/i5/las2peer/services/projectManagementService/RESTResources.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/RESTResources.java similarity index 99% rename from src/main/i5/las2peer/services/projectManagementService/RESTResources.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/RESTResources.java index 3585f2a..7d542f2 100644 --- a/src/main/i5/las2peer/services/projectManagementService/RESTResources.java +++ b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/RESTResources.java @@ -380,10 +380,6 @@ public Response addUserToProject(@PathParam("id") int projectId, String inputUse boolean added = project.addUser(user, connection, true); // true, because user also should be added to users list of Project object if(added) { // return result: ok - // user object should be returned - // also the assigned role should be included - JSONObject o = user.toJSONObject(); - o.put("roleId", project.getRoleByUser(user).getId()); // remove invitation ProjectInvitation.delete(projectId, user.getId(), connection); @@ -1688,7 +1684,7 @@ public Response getActiveUser() { user = authManager.getUser(); // returns user as json string - return Response.ok(user.toJSONObject().toJSONString()).build(); + return Response.ok(user.toJSONObject(true).toJSONString()).build(); } catch (SQLException e) { logger.printStackTrace(e); // return server error at the end diff --git a/src/main/i5/las2peer/services/projectManagementService/auth/AuthManager.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/auth/AuthManager.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/auth/AuthManager.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/auth/AuthManager.java diff --git a/src/main/i5/las2peer/services/projectManagementService/component/Component.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/component/Component.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/component/Component.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/component/Component.java diff --git a/src/main/i5/las2peer/services/projectManagementService/component/ComponentInitHelper.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/component/ComponentInitHelper.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/component/ComponentInitHelper.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/component/ComponentInitHelper.java diff --git a/src/main/i5/las2peer/services/projectManagementService/component/ComponentType.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/component/ComponentType.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/component/ComponentType.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/component/ComponentType.java diff --git a/src/main/i5/las2peer/services/projectManagementService/component/Dependency.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/component/Dependency.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/component/Dependency.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/component/Dependency.java diff --git a/src/main/i5/las2peer/services/projectManagementService/component/ExternalDependency.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/component/ExternalDependency.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/component/ExternalDependency.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/component/ExternalDependency.java diff --git a/src/main/i5/las2peer/services/projectManagementService/database/DatabaseManager.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/database/DatabaseManager.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/database/DatabaseManager.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/database/DatabaseManager.java diff --git a/src/main/i5/las2peer/services/projectManagementService/exception/GitHubException.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/exception/GitHubException.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/exception/GitHubException.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/exception/GitHubException.java diff --git a/src/main/i5/las2peer/services/projectManagementService/exception/InvitationNotFoundException.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/exception/InvitationNotFoundException.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/exception/InvitationNotFoundException.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/exception/InvitationNotFoundException.java diff --git a/src/main/i5/las2peer/services/projectManagementService/exception/NoDefaultRoleFoundException.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/exception/NoDefaultRoleFoundException.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/exception/NoDefaultRoleFoundException.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/exception/NoDefaultRoleFoundException.java diff --git a/src/main/i5/las2peer/services/projectManagementService/exception/ProjectNotFoundException.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/exception/ProjectNotFoundException.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/exception/ProjectNotFoundException.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/exception/ProjectNotFoundException.java diff --git a/src/main/i5/las2peer/services/projectManagementService/exception/ReqBazException.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/exception/ReqBazException.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/exception/ReqBazException.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/exception/ReqBazException.java diff --git a/src/main/i5/las2peer/services/projectManagementService/exception/RoleNotFoundException.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/exception/RoleNotFoundException.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/exception/RoleNotFoundException.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/exception/RoleNotFoundException.java diff --git a/src/main/i5/las2peer/services/projectManagementService/exception/UserNotFoundException.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/exception/UserNotFoundException.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/exception/UserNotFoundException.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/exception/UserNotFoundException.java diff --git a/src/main/i5/las2peer/services/projectManagementService/github/GitHubHelper.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/github/GitHubHelper.java similarity index 87% rename from src/main/i5/las2peer/services/projectManagementService/github/GitHubHelper.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/github/GitHubHelper.java index dc8e36a..7ebd236 100644 --- a/src/main/i5/las2peer/services/projectManagementService/github/GitHubHelper.java +++ b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/github/GitHubHelper.java @@ -4,16 +4,15 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; import java.net.HttpURLConnection; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.util.ArrayList; -import java.util.Arrays; import java.util.Base64; -import java.util.LinkedHashSet; -import java.util.Set; +import java.net.http.*; +import java.net.http.HttpRequest.BodyPublishers; +import java.net.http.HttpResponse.BodyHandlers; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -35,9 +34,7 @@ public class GitHubHelper { private static final String API_BASE_URL = "https://api.github.com"; // make sure that constructor cannot be accessed from outside - private GitHubHelper() { - allowPatchMethod(); - } + private GitHubHelper() {} public static GitHubHelper getInstance() { if(GitHubHelper.instance == null) { @@ -373,32 +370,26 @@ private GitHubProject createGitHubProject(String projectName) throws GitHubExcep private void makeGitHubProjectPublic(int gitHubProjectId) throws GitHubException { String body = getVisibilityPublicBody(); String authStringEnc = getAuthStringEnc(); - - URL url; + + String url = API_BASE_URL + "/projects/" + gitHubProjectId; + + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create(url)) + .method("PATCH", BodyPublishers.ofString(body)) + .header("Content-Type", "application/json") + .header("Accept", "application/vnd.github.inertia-preview+json") + .header("Authorization", "Basic " + authStringEnc) + .build(); + + HttpResponse response; try { - url = new URL(API_BASE_URL + "/projects/" + gitHubProjectId); - - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("PATCH"); - connection.setDoInput(true); - connection.setDoOutput(true); - connection.setUseCaches(false); - connection.setRequestProperty("Accept", "application/vnd.github.inertia-preview+json"); - connection.setRequestProperty("Content-Type", "application/json"); - connection.setRequestProperty("Content-Length", String.valueOf(body.length())); - connection.setRequestProperty("Authorization", "Basic " + authStringEnc); - - writeRequestBody(connection, body); - - // forward (in case of) error - if (connection.getResponseCode() != 200) { - String message = getErrorMessage(connection); + response = client.send(request, BodyHandlers.ofString()); + if(response.statusCode() != 200) { + String message = response.body(); throw new GitHubException(message); - } - } catch (MalformedURLException e) { - e.printStackTrace(); - throw new GitHubException(e.getMessage()); - } catch (IOException e) { + } + } catch (IOException | InterruptedException e) { e.printStackTrace(); throw new GitHubException(e.getMessage()); } @@ -544,35 +535,4 @@ private void writeRequestBody(HttpURLConnection connection, String body) throws writer.close(); } - /** - * This is a workaround for the following problem: - * In order to make the GitHub project public, it is necessary to - * send a PATCH request. This is normally not working when using - * HttpURLConnection. Since we dont want to use an external library for - * it, we make use of this workaround found on Stackoverflow: - * https://stackoverflow.com/questions/25163131/httpurlconnection-invalid-http-method-patch/46323891#46323891 - * Then also PATCH requests are working. - * @param methods - */ - private static void allowPatchMethod() { - try { - Field methodsField = HttpURLConnection.class.getDeclaredField("methods"); - - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(methodsField, methodsField.getModifiers() & ~Modifier.FINAL); - - methodsField.setAccessible(true); - - String[] oldMethods = (String[]) methodsField.get(null); - Set methodsSet = new LinkedHashSet<>(Arrays.asList(oldMethods)); - methodsSet.add("PATCH"); - String[] newMethods = methodsSet.toArray(new String[0]); - - methodsField.set(null, newMethods); - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new IllegalStateException(e); - } - } - } diff --git a/src/main/i5/las2peer/services/projectManagementService/github/GitHubProject.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/github/GitHubProject.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/github/GitHubProject.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/github/GitHubProject.java diff --git a/src/main/i5/las2peer/services/projectManagementService/project/PredefinedRoles.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/project/PredefinedRoles.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/project/PredefinedRoles.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/project/PredefinedRoles.java diff --git a/src/main/i5/las2peer/services/projectManagementService/project/Project.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/project/Project.java similarity index 99% rename from src/main/i5/las2peer/services/projectManagementService/project/Project.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/project/Project.java index f9da016..715277b 100644 --- a/src/main/i5/las2peer/services/projectManagementService/project/Project.java +++ b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/project/Project.java @@ -524,7 +524,7 @@ public JSONObject toJSONObject() { // the project too) the role needs to be added manually JSONArray jsonUsers = new JSONArray(); for(User user : users) { - JSONObject jsonUser = user.toJSONObject(); + JSONObject jsonUser = user.toJSONObject(false); // find out id of the role which is assigned to the user int roleId = roleAssignment.get(user).getId(); diff --git a/src/main/i5/las2peer/services/projectManagementService/project/ProjectInvitation.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/project/ProjectInvitation.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/project/ProjectInvitation.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/project/ProjectInvitation.java diff --git a/src/main/i5/las2peer/services/projectManagementService/project/Role.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/project/Role.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/project/Role.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/project/Role.java diff --git a/src/main/i5/las2peer/services/projectManagementService/project/User.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/project/User.java similarity index 96% rename from src/main/i5/las2peer/services/projectManagementService/project/User.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/project/User.java index e38acb9..09d948c 100644 --- a/src/main/i5/las2peer/services/projectManagementService/project/User.java +++ b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/project/User.java @@ -204,18 +204,21 @@ public static ArrayList searchUsers(String loginName, Connection connectio /** * Creates a JSON object from the user object. + * @param all Whether all information of the user is required, or e.g. email can be omitted. * @return JSONObject containing the user information. */ @SuppressWarnings("unchecked") - public JSONObject toJSONObject() { + public JSONObject toJSONObject(boolean all) { JSONObject jsonUser = new JSONObject(); // put attributes jsonUser.put("id", this.id); jsonUser.put("loginName", this.loginName); - jsonUser.put("email", this.email); jsonUser.put("gitHubUsername", this.gitHubUsername); - jsonUser.put("gitHubAccessToken", this.gitHubAccessToken); + if(all) { + jsonUser.put("email", this.email); + jsonUser.put("gitHubAccessToken", this.gitHubAccessToken); + } return jsonUser; } diff --git a/src/main/i5/las2peer/services/projectManagementService/reqbaz/ReqBazCategory.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/reqbaz/ReqBazCategory.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/reqbaz/ReqBazCategory.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/reqbaz/ReqBazCategory.java diff --git a/src/main/i5/las2peer/services/projectManagementService/reqbaz/ReqBazHelper.java b/project_management_service/src/main/java/i5/las2peer/services/projectManagementService/reqbaz/ReqBazHelper.java similarity index 100% rename from src/main/i5/las2peer/services/projectManagementService/reqbaz/ReqBazHelper.java rename to project_management_service/src/main/java/i5/las2peer/services/projectManagementService/reqbaz/ReqBazHelper.java diff --git a/src/test/i5/las2peer/services/projectManagementService/DatabaseHelper.java b/project_management_service/src/test/java/i5/las2peer/services/projectManagementService/DatabaseHelper.java similarity index 100% rename from src/test/i5/las2peer/services/projectManagementService/DatabaseHelper.java rename to project_management_service/src/test/java/i5/las2peer/services/projectManagementService/DatabaseHelper.java diff --git a/src/test/i5/las2peer/services/projectManagementService/ServiceTest.java b/project_management_service/src/test/java/i5/las2peer/services/projectManagementService/ServiceTest.java similarity index 100% rename from src/test/i5/las2peer/services/projectManagementService/ServiceTest.java rename to project_management_service/src/test/java/i5/las2peer/services/projectManagementService/ServiceTest.java diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..53220d6 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'CAE-Project-Management-Service' +include('project_management_service')