diff --git a/.github/workflows/run-terraform.yml b/.github/workflows/run-terraform.yml index d5123db5..7cb72172 100644 --- a/.github/workflows/run-terraform.yml +++ b/.github/workflows/run-terraform.yml @@ -54,6 +54,9 @@ jobs: --selector=app.kubernetes.io/component=controller \ --timeout=90s + - name: "Run Backend-service" + uses: ./.github/actions/backend-service + - name: "Terraform init" working-directory: mxd run: |- diff --git a/mxd/backend-service.tf b/mxd/backend-service.tf new file mode 100644 index 00000000..c8835693 --- /dev/null +++ b/mxd/backend-service.tf @@ -0,0 +1,84 @@ +# +# Copyright (c) 2023 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available 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. +# +# SPDX-License-Identifier: Apache-2.0 +# + + +resource "kubernetes_deployment" "backend-service" { + metadata { + name = "backend-service" + labels = { + App = "backend-service" + } + } + + spec { + replicas = 1 + selector { + match_labels = { + App = "backend-service" + } + } + template { + metadata { + labels = { + App = "backend-service" + } + } + spec { + container { + name = "backend-service" + image = "tractusx/mxd-backend-service:0.0.1,latest" + image_pull_policy = "Always" + + port { + container_port = 8080 + name = "backend-port" + } + env { + name = "BACKEND-SERVICE-DATABASE_URL" + value = "jdbc:postgresql://${local.pg-ip}:${var.postgres-port}/backendservicedb" + } + + env { + name = "BACKEND-SERVICE-DATABASE_USER" + value = "postgres" + } + env { + name = "BACKEND-SERVICE-DATABASE_PASSWORD" + value = "postgres" + } + } + } + } + } +} + +resource "kubernetes_service" "backend-service" { + metadata { + name = "backend-service" + } + spec { + selector = { + app = "backend-service" + } + port { + port = 8080 + name = "backend-port" + } + } +} diff --git a/mxd/backend-service/Dockerfile b/mxd/backend-service/Dockerfile new file mode 100644 index 00000000..e5320e60 --- /dev/null +++ b/mxd/backend-service/Dockerfile @@ -0,0 +1,42 @@ +# application.properties + +#******************************************************************************* +# * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +# * Copyright (c) 2023 Contributors to the Eclipse Foundation +# * +# * See the NOTICE file(s) distributed with this work for additional +# * information regarding copyright ownership. +# * +# * This program and the accompanying materials are made available under the +# * terms of the Apache License, Version 2.0 which is available 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. +# * +# * SPDX-License-Identifier: Apache-2.0 +# * Contributors:Ravinder Kumar +# * Backend-API and implementation +# * +# ******************************************************************************/ + + + + +# Use the official OpenJDK 17 image as the base image +FROM openjdk:17 + +# Set the working directory +WORKDIR /app + +# Copy your JAR file from the local build context to the image +COPY build/libs/backend-service.jar /app/backend-service.jar + +# Expose the port your application is running on +EXPOSE 8080 + +# Start your Java application +CMD java -jar backend-service.jar diff --git a/mxd/backend-service/build.gradle b/mxd/backend-service/build.gradle new file mode 100644 index 00000000..7003d210 --- /dev/null +++ b/mxd/backend-service/build.gradle @@ -0,0 +1,82 @@ +plugins { + id 'java' + id 'com.bmuschko.docker-remote-api' version '9.3.4' +} +import com.bmuschko.gradle.docker.tasks.image.Dockerfile +import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage +group 'com.eclipse.mxd' +version '0.0.1' + +repositories { + mavenCentral() +} + +ext { + junitVersion = '5.9.2' + jerseyVersion = '3.0.3' + jettyVersion = '11.0.7' + hibernateVersion = '6.0.2.Final' +} + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +jar { + duplicatesStrategy = 'INCLUDE' + manifest { + attributes( + 'Main-Class': 'com.eclipse.mxd.Main' + ) + } + from { + configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } + } +} + +dependencies { + implementation "jakarta.enterprise:jakarta.enterprise.cdi-api:3.0.0" + implementation "jakarta.ws.rs:jakarta.ws.rs-api:3.0.0" + implementation "jakarta.servlet:jakarta.servlet-api:5.0.0" + implementation "org.hibernate:hibernate-core:${hibernateVersion}" + + implementation "org.glassfish.jersey.core:jersey-server:${jerseyVersion}" + implementation "org.eclipse.jetty:jetty-servlet:${jettyVersion}" + implementation "org.glassfish.jersey.media:jersey-media-json-jackson:${jerseyVersion}" +// https://mvnrepository.com/artifact/org.postgresql/postgresql + implementation group: 'org.postgresql', name: 'postgresql', version: '42.7.0' + + implementation 'org.hibernate.validator:hibernate-validator:7.0.2.Final' // Use the latest version available + implementation "org.glassfish.jersey.containers:jersey-container-servlet:${jerseyVersion}" + implementation "org.glassfish.jersey.inject:jersey-hk2:${jerseyVersion}" + implementation "org.glassfish.jersey.core:jersey-common:${jerseyVersion}" + implementation "org.glassfish.jersey.containers:jersey-container-servlet-core:${jerseyVersion}" + implementation 'org.slf4j:slf4j-api:2.0.9' + implementation("org.glassfish.jersey.inject:jersey-hk2:3.0.3") { + exclude group: 'org.glassfish.hk2.external', module: 'javax.inject' + } + + implementation 'org.glassfish.jersey.containers:jersey-container-servlet:2.25' + implementation 'org.glassfish.jersey.core:jersey-server:2.25' + implementation 'org.glassfish.jersey.core:jersey-client:2.25' + implementation 'org.glassfish.jersey.media:jersey-media-json-jackson:2.25' + implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.1' // Use the latest version available + implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.1' // Use the latest version available + + + + // Additional Jetty dependencies if needed + implementation "org.eclipse.jetty:jetty-webapp:${jettyVersion}" + implementation "org.eclipse.jetty:jetty-util:${jettyVersion}" + implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1' + testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}" +} + +test { + useJUnitPlatform() +} + +tasks.register('dockerize', DockerBuildImage) { + images.add('mxd-backend-service-'+version+':latest') +} diff --git a/mxd/backend-service/gradle/wrapper/gradle-wrapper.jar b/mxd/backend-service/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..249e5832 Binary files /dev/null and b/mxd/backend-service/gradle/wrapper/gradle-wrapper.jar differ diff --git a/mxd/backend-service/gradle/wrapper/gradle-wrapper.properties b/mxd/backend-service/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..db9a6b82 --- /dev/null +++ b/mxd/backend-service/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/mxd/backend-service/gradlew b/mxd/backend-service/gradlew new file mode 100644 index 00000000..1b6c7873 --- /dev/null +++ b/mxd/backend-service/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original 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 POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${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 "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# 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 ;; #( + MSYS* | 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" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/mxd/backend-service/gradlew.bat b/mxd/backend-service/gradlew.bat new file mode 100644 index 00000000..107acd32 --- /dev/null +++ b/mxd/backend-service/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/mxd/backend-service/postman/mxd-backend-services.postman_collection-v2.json b/mxd/backend-service/postman/mxd-backend-services.postman_collection-v2.json new file mode 100644 index 00000000..767b2375 --- /dev/null +++ b/mxd/backend-service/postman/mxd-backend-services.postman_collection-v2.json @@ -0,0 +1,210 @@ +{ + "info": { + "_postman_id": "64d8cc24-47b2-4fc3-a94a-6faf5c3408d6", + "name": "Backend-services", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "31550443" + }, + "item": [ + { + "name": "Get All Contents", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{backend-service-url}}/api/v1/content/", + "host": [ + "{{backend-service-url}}" + ], + "path": [ + "api", + "v1", + "content", + "" + ] + } + }, + "response": [] + }, + { + "name": "Post Contents", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "[\r\n {\r\n \"userId\": 1,\r\n \"id\": 1,\r\n \"title\": \"Testing Testing\",\r\n \"completed\": false\r\n }\r\n \r\n]", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{backend-service-url}}/api/v1/content/", + "host": [ + "{{backend-service-url}}" + ], + "path": [ + "api", + "v1", + "content", + "" + ] + } + }, + "response": [] + }, + { + "name": "Get Contents By ID", + "protocolProfileBehavior": { + "disableBodyPruning": true + }, + "request": { + "method": "GET", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"id\": 1,\r\n \"name\": \"java\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{backend-service-url}}/api/v1/content/1", + "host": [ + "{{backend-service-url}}" + ], + "path": [ + "api", + "v1", + "content", + "1" + ] + } + }, + "response": [] + }, + { + "name": "Post Transfer", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{backend-service-url}}/api/v1/transfer/", + "host": [ + "{{backend-service-url}}" + ], + "path": [ + "api", + "v1", + "transfer", + "" + ] + } + }, + "response": [] + }, + { + "name": "Get Transfer Content By ID", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{backend-service-url}}/api/v1/transfer/52ba4b2f-ae3a-46ae-96f2-6781aa819386/contents/", + "host": [ + "{{backend-service-url}}" + ], + "path": [ + "api", + "v1", + "transfer", + "52ba4b2f-ae3a-46ae-96f2-6781aa819386", + "contents", + "" + ] + } + }, + "response": [] + }, + { + "name": "Get Transfer By ID", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{backend-service-url}}/api/v1/transfer/52ba4b2f-ae3a-46ae-96f2-6781aa819386/", + "host": [ + "{{backend-service-url}}" + ], + "path": [ + "api", + "v1", + "transfer", + "52ba4b2f-ae3a-46ae-96f2-6781aa819386", + "" + ] + } + }, + "response": [] + }, + { + "name": "Get Random Content", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{backend-service-url}}/api/v1/content/random", + "host": [ + "{{backend-service-url}}" + ], + "path": [ + "api", + "v1", + "content", + "random" + ] + } + }, + "response": [] + } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ], + "variable": [ + { + "key": "backend-service-url", + "value": "http://localhost:8080", + "type": "string" + } + ] +} \ No newline at end of file diff --git a/mxd/backend-service/settings.gradle b/mxd/backend-service/settings.gradle new file mode 100644 index 00000000..7f3b3b69 --- /dev/null +++ b/mxd/backend-service/settings.gradle @@ -0,0 +1 @@ +rootProject.name = "backend-service" \ No newline at end of file diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/AppInitializer.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/AppInitializer.java new file mode 100644 index 00000000..8fa95323 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/AppInitializer.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.Initialized; +import jakarta.enterprise.event.Observes; + +@ApplicationScoped +public class AppInitializer { + public void onApplicationStart(@Observes @Initialized(ApplicationScoped.class) Object init) { + + } +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/BackendApplication.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/BackendApplication.java new file mode 100644 index 00000000..f960db8b --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/BackendApplication.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd; + +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; + +@ApplicationPath("/api") +public class BackendApplication extends Application { + + + +} \ No newline at end of file diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/Main.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/Main.java new file mode 100644 index 00000000..b8457f6a --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/Main.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd; + +import com.eclipse.mxd.service.ContentService; +import com.eclipse.mxd.service.Impl.ContentServiceImpl; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.glassfish.jersey.servlet.ServletContainer; + +import java.util.logging.Logger; + +public class Main { + private final static ContentService contentService = new ContentServiceImpl(); + private static final Logger logger = Logger.getLogger(Main.class.getName()); + + public static void main(String[] args) { + contentService.getAll(); + startJettyServer(); + } + + private static void startJettyServer() { + int port = 8080; + Server server = new Server(port); + ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); + context.setContextPath("/"); + server.setHandler(context); + ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/api/*"); + jerseyServlet.setInitOrder(0); + jerseyServlet.setInitParameter("jersey.config.server.provider.packages", "com.eclipse.mxd"); + try { + server.start(); + server.join(); + } catch (Exception e) { + logger.info("exception " + e.getMessage()); + } finally { + server.destroy(); + } + } +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/controller/ContentController.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/controller/ContentController.java new file mode 100644 index 00000000..c077d19b --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/controller/ContentController.java @@ -0,0 +1,68 @@ + +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.controller; + +import com.eclipse.mxd.service.ContentRandomService; +import com.eclipse.mxd.service.ContentService; +import com.eclipse.mxd.service.Impl.ContentRandomServiceImpl; +import com.eclipse.mxd.service.Impl.ContentServiceImpl; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.ws.rs.*; +import jakarta.ws.rs.core.*; + + +@Path("/v1/content") +@ApplicationScoped +public class ContentController { + private final ContentService contentService = new ContentServiceImpl(); + + private final ContentRandomService contentRandomService = new ContentRandomServiceImpl(); + + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response getAll() { + return this.contentService.getAll(); + } + + @GET + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public Response getById(@PathParam("id") Long id) { + return contentService.getById(id); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + public Response postContent(String requestBody, @Context UriInfo uriInfo) { + return this.contentService.postContent(requestBody, uriInfo); + } + + @GET + @Path("/random") + @Produces(MediaType.APPLICATION_JSON) + public Response getRandomContent() { + return this.contentRandomService.getRandomContent(); + } +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/controller/TransferController.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/controller/TransferController.java new file mode 100644 index 00000000..980bb481 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/controller/TransferController.java @@ -0,0 +1,60 @@ + +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + + +package com.eclipse.mxd.controller; + +import com.eclipse.mxd.service.Impl.TransferServiceImpl; +import com.eclipse.mxd.service.TransferService; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.ws.rs.*; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; + +@Path("/v1/transfer") +@ApplicationScoped +public class TransferController { + + TransferService transfersAPIService = new TransferServiceImpl(); + + @POST + @Path("/") + public Response acceptTransfer(String transferRequest) { + return this.transfersAPIService.acceptTransfer(transferRequest); + } + + @GET + @Path("/{id}") + @Produces(MediaType.APPLICATION_JSON) + public Response getTransfer(@PathParam("id") String id) { + return this.transfersAPIService.getTransfer(id); + } + + @GET + @Path("/{id}/contents") + public Response getTransferContents(@PathParam("id") String id) { + return this.transfersAPIService.getTransferContents(id); + } + +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/entity/Content.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/entity/Content.java new file mode 100644 index 00000000..247b860f --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/entity/Content.java @@ -0,0 +1,95 @@ + +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + + + +package com.eclipse.mxd.entity; + +import jakarta.persistence.*; +import java.util.Date; + +@Entity +public class Content { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Content_SEQ") + @SequenceGenerator(name = "Content_SEQ", sequenceName = "Content_SEQ", allocationSize = 1) + private Long id; + + @Column(columnDefinition = "TEXT") + private String asset; + @Column + private Date createdDate; + @Column + private Date updatedDate; + + public Content() { + + } + + public Content(Long id, String asset, Date createdDate, Date updatedDate) { + this.id = id; + this.asset = asset; + this.createdDate = createdDate; + this.updatedDate = updatedDate; + } + + public void setId(Long id) { + this.id = id; + } + + public void setAsset(String asset) { + this.asset = asset; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public void setUpdatedDate(Date updatedDate) { + this.updatedDate = updatedDate; + } + + public Long getId() { + return id; + } + + public String getAsset() { + return asset; + } + + public Date getCreatedDate() { + return createdDate; + } + + public Date getUpdatedDate() { + return updatedDate; + } + + @Override + public String toString() { + return "ContentEntity{" + "id=" + id + ", asset='" + asset + '\'' + ", createdDate=" + createdDate + + ", updatedDate=" + updatedDate + '}'; + } +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/entity/Transfer.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/entity/Transfer.java new file mode 100644 index 00000000..be93ec2d --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/entity/Transfer.java @@ -0,0 +1,125 @@ + +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + + +package com.eclipse.mxd.entity; + +import jakarta.persistence.*; +import java.util.Date; + +@Entity +public class Transfer { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Transfer_SEQ") + @SequenceGenerator(name = "Transfer_SEQ", sequenceName = "Transfer_SEQ", allocationSize = 1) + private Long id; + + @Column(columnDefinition = "TEXT") + private String asset; + @Column(columnDefinition = "TEXT") + private String contents; + + private String transferid; + + @Temporal(TemporalType.TIMESTAMP) + @Column + private Date createdDate; + @Temporal(TemporalType.TIMESTAMP) + @Column + private Date updatedDate; + + public Transfer() { + + } + + public Transfer(Long id, String asset, String contents, String transferid, Date createdDate, Date updatedDate) { + this.id = id; + this.asset = asset; + this.contents = contents; + this.transferid = transferid; + this.createdDate = createdDate; + this.updatedDate = updatedDate; + } + + public Long getId() { + return id; + } + + public String getAsset() { + return asset; + } + + public String getContents() { + return contents; + } + + public String getTransferid() { + return transferid; + } + + public Date getCreatedDate() { + return createdDate; + } + + public Date getUpdatedDate() { + return updatedDate; + } + + public void setId(Long id) { + this.id = id; + } + + public void setAsset(String asset) { + this.asset = asset; + } + + public void setContents(String contents) { + this.contents = contents; + } + + public void setTransferid(String transferid) { + this.transferid = transferid; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public void setUpdatedDate(Date updatedDate) { + this.updatedDate = updatedDate; + } + + @Override + public String toString() { + return "Transfer{" + + "id=" + id + + ", asset='" + asset + '\'' + + ", contents='" + contents + '\'' + + ", transferid='" + transferid + '\'' + + ", createdDate=" + createdDate + + ", updatedDate=" + updatedDate + + '}'; + } +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/model/ContentModelResponse.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/ContentModelResponse.java new file mode 100644 index 00000000..b88d7570 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/ContentModelResponse.java @@ -0,0 +1,91 @@ + +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + + +package com.eclipse.mxd.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; + +import java.util.Date; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ContentModelResponse { + + @JsonProperty("id") + private Long id; + + @JsonProperty("asset") + private JsonNode asset; + + @JsonProperty("createdDate") + private Date createdDate; + + @JsonProperty("updatedDate") + private Date updatedDate; + + public ContentModelResponse(Long id, JsonNode asset, Date createdDate, Date updatedDate) { + this.id = id; + this.asset = asset; + this.createdDate = createdDate; + this.updatedDate = updatedDate; + } + + public ContentModelResponse() { + } + + + public JsonNode getAsset() { + return asset; + } + + public void setAsset(JsonNode asset) { + this.asset = asset; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public Date getUpdatedDate() { + return updatedDate; + } + + public void setUpdatedDate(Date updatedDate) { + this.updatedDate = updatedDate; + } +} \ No newline at end of file diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/model/ContentRandomResponse.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/ContentRandomResponse.java new file mode 100644 index 00000000..8c2a6757 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/ContentRandomResponse.java @@ -0,0 +1,77 @@ + +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + + + +package com.eclipse.mxd.model; + +public class ContentRandomResponse { + + private Integer id; + private String title; + private String text; + + + public ContentRandomResponse() { + } + + public ContentRandomResponse(Integer id, String title, String text) { + this.id = id; + this.title = title; + this.text = text; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + @Override + public String toString() { + return "ContentRandomResponse{" + + "id=" + id + + ", title='" + title + '\'' + + ", text='" + text + '\'' + + '}'; + } +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/model/ContentsModel.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/ContentsModel.java new file mode 100644 index 00000000..4e443ec4 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/ContentsModel.java @@ -0,0 +1,99 @@ + +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + + +package com.eclipse.mxd.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.util.Date; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ContentsModel { + + @JsonProperty("id") + private Long id; + + @JsonProperty("asset") + private String asset; + + @JsonProperty("createdDate") + private Date createdDate; + + @JsonProperty("updatedDate") + private Date updatedDate; + + public ContentsModel(Long id, String asset, Date createdDate, Date updatedDate) { + this.id = id; + this.asset = asset; + this.createdDate = createdDate; + this.updatedDate = updatedDate; + } + + public ContentsModel() { + + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getAsset() { + return asset; + } + + public void setAsset(String asset) { + this.asset = asset; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(java.sql.Timestamp createdDate) { + this.createdDate = createdDate; + } + + public Date getUpdatedDate() { + return updatedDate; + } + + public void setUpdatedDate(java.sql.Timestamp updatedDate) { + this.updatedDate = updatedDate; + } + + @Override + public String toString() { + return "Asset{" + "id=" + id + ", asset='" + asset + '\'' + ", createdDate=" + createdDate + ", updatedDate=" + + updatedDate + '}'; + } +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/model/PropertiesModel.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/PropertiesModel.java new file mode 100644 index 00000000..a3ec5011 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/PropertiesModel.java @@ -0,0 +1,29 @@ + +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.model; + +public class PropertiesModel { + +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/model/TransferContentResponse.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/TransferContentResponse.java new file mode 100644 index 00000000..d0aa9fc3 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/TransferContentResponse.java @@ -0,0 +1,60 @@ + +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class TransferContentResponse { + + @JsonProperty("content") + private JsonNode asset; + + public JsonNode getAsset() { + return asset; + } + + public void setAsset(JsonNode asset) { + this.asset = asset; + } + + public TransferContentResponse(JsonNode asset) { + this.asset = asset; + } + + public TransferContentResponse() { + } + + @Override + public String toString() { + return "TransferResponse{" + + "asset=" + asset + + '}'; + } +} + + diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/model/TransferRequest.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/TransferRequest.java new file mode 100644 index 00000000..702d08ff --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/TransferRequest.java @@ -0,0 +1,92 @@ + +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.model; + +public class TransferRequest { + + private String id; + private String endpoint; + private String authKey; + private String authCode; + private PropertiesModel properties; + + public TransferRequest(String id, String endpoint, String authKey, String authCode, PropertiesModel properties) { + this.id = id; + this.endpoint = endpoint; + this.authKey = authKey; + this.authCode = authCode; + this.properties = properties; + } + + public TransferRequest() { + } + + public String getId() { + return id; + } + + public String getEndpoint() { + return endpoint; + } + + public String getAuthKey() { + return authKey; + } + + public String getAuthCode() { + return authCode; + } + + public PropertiesModel getProperties() { + return properties; + } + + public void setId(String id) { + this.id = id; + } + + public void setEndpoint(String endpoint) { + this.endpoint = endpoint; + } + + public void setAuthKey(String authKey) { + this.authKey = authKey; + } + + public void setAuthCode(String authCode) { + this.authCode = authCode; + } + + public void setProperties(PropertiesModel properties) { + this.properties = properties; + } + + @Override + public String toString() { + return "ReceivedModel{" + "id='" + id + '\'' + ", endpoint='" + endpoint + '\'' + ", authKey='" + authKey + '\'' + + ", authCode='" + authCode + '\'' + ", properties=" + properties + '}'; + } + +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/model/TransferResponse.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/TransferResponse.java new file mode 100644 index 00000000..31dd88ae --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/TransferResponse.java @@ -0,0 +1,60 @@ + +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class TransferResponse { + + @JsonProperty("asset") + private JsonNode asset; + + public TransferResponse(JsonNode asset) { + this.asset = asset; + } + + public TransferResponse() { + } + + public JsonNode getAsset() { + return asset; + } + + public void setAsset(JsonNode asset) { + this.asset = asset; + } + + @Override + public String toString() { + return "TransferResponse{" + + "asset=" + asset + + '}'; + } +} + + diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/model/TransfersModel.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/TransfersModel.java new file mode 100644 index 00000000..0236e1c7 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/model/TransfersModel.java @@ -0,0 +1,115 @@ + +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.model; + +import java.util.Date; + +public class TransfersModel { + + private Long id; + private String asset; + private String contents; + private String transferid; + private Date createdDate; + private Date updatedDate; + + public TransfersModel() { + + } + + public TransfersModel(Long id, String asset, String contents, String transferid, Date createdDate, + Date updatedDate) { + super(); + this.id = id; + this.asset = asset; + this.contents = contents; + this.transferid = transferid; + this.createdDate = createdDate; + this.updatedDate = updatedDate; + } + + public TransfersModel(Long id, String asset, String contents, Date createdDate, Date updatedDate) { + this.id = id; + this.asset = asset; + this.contents = contents; + this.createdDate = createdDate; + this.updatedDate = updatedDate; + } + + + public Long getId() { + return id; + } + + public void setId(int Long) { + this.id = id; + } + + public String getAsset() { + return asset; + } + + public void setAsset(String asset) { + this.asset = asset; + } + + public String getContents() { + return contents; + } + + public void setContents(String contents) { + this.contents = contents; + } + + public String getTransferid() { + return transferid; + } + + public void setTransferid(String transferid) { + this.transferid = transferid; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public Date getUpdatedDate() { + return updatedDate; + } + + public void setUpdatedDate(Date updatedDate) { + this.updatedDate = updatedDate; + } + + @Override + public String toString() { + return "TransfersModel [id=" + id + ", asset=" + asset + ", contents=" + contents + ", transferid=" + transferid + + ", createdDate=" + createdDate + ", updatedDate=" + updatedDate + "]"; + } +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/ContentRamdomRepository.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/ContentRamdomRepository.java new file mode 100644 index 00000000..d21a6e9b --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/ContentRamdomRepository.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.repository; + +import jakarta.ws.rs.core.Response; + +public interface ContentRamdomRepository { + + public Response getRandomContent(); + +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/ContentServiceRepository.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/ContentServiceRepository.java new file mode 100644 index 00000000..b945edc4 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/ContentServiceRepository.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.repository; + +import com.eclipse.mxd.model.ContentsModel; + +import java.util.List; + +public interface ContentServiceRepository { + + Long createAsset(String assetName); + + ContentsModel getAssetById(Long id); + + void updateAsset(Long id, String newAssetName); + + void deleteAsset(Long id); + + List getAllAssets(); +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/Impl/ContentRandomRepositoryImpl.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/Impl/ContentRandomRepositoryImpl.java new file mode 100644 index 00000000..e64303d1 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/Impl/ContentRandomRepositoryImpl.java @@ -0,0 +1,62 @@ + +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.repository.Impl; + +import com.eclipse.mxd.model.ContentRandomResponse; +import com.eclipse.mxd.repository.ContentRamdomRepository; +import com.eclipse.mxd.util.RandomWordUtil; +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.ws.rs.core.Response; + +import java.util.Random; +import java.util.logging.Logger; + +@ApplicationScoped +public class ContentRandomRepositoryImpl implements ContentRamdomRepository { + private static final Logger logger = Logger.getLogger(ContentRandomRepositoryImpl.class.getName()); + + @Override + public Response getRandomContent() { + try { + Random random = new Random(); + int random_number = random.nextInt(100) + 1; + String title = RandomWordUtil.generateRandomWord(); + String text = RandomWordUtil.generateRandomWord(); + ContentRandomResponse contentRandomResponse = new ContentRandomResponse(); + contentRandomResponse.setId(random_number); + contentRandomResponse.setText(text); + contentRandomResponse.setTitle(title); + ObjectMapper objectMapper = new ObjectMapper(); + return Response.ok(objectMapper.writeValueAsString(contentRandomResponse)).build(); + + }catch (Exception e){ + logger.info("error "+e.getMessage()); + } + + return Response.ok("Random Json Not Generated !").build(); + } + +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/Impl/ContentRepositoryImpl.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/Impl/ContentRepositoryImpl.java new file mode 100644 index 00000000..fe4e421e --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/Impl/ContentRepositoryImpl.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ +package com.eclipse.mxd.repository.Impl; + +import com.eclipse.mxd.util.HibernateUtil; +import com.eclipse.mxd.entity.Content; +import com.eclipse.mxd.model.ContentsModel; +import com.eclipse.mxd.repository.ContentServiceRepository; +import com.eclipse.mxd.util.DateTimeUtil; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.persistence.Query; +import org.hibernate.Session; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +@ApplicationScoped +public class ContentRepositoryImpl implements ContentServiceRepository { + + private static final Logger logger = Logger.getLogger(ContentRepositoryImpl.class.getName()); + + @Override + public Long createAsset(String assetName) { + try { + Content content = saveContent(assetName); + if (content.getId() != null) { + logger.info(content.toString()); + return content.getId(); + } else { + return -1L; + } + } catch (Exception e) { + logger.info(e.getMessage()); + return -1L; + } finally { + + } + } + + public Content saveContent(String assetName) { + Content content = new Content(); + try { + Session session = HibernateUtil.getSessionFactory().openSession(); + if (session != null) { + content.setAsset(assetName); + content.setCreatedDate(DateTimeUtil.getCurrentDateTimeInAsiaKolkata()); + content.setUpdatedDate(DateTimeUtil.getCurrentDateTimeInAsiaKolkata()); + session.getTransaction().begin(); + session.persist(content); + session.getTransaction().commit(); + session.close(); + } + + } catch (Exception e) { + logger.info(e.getMessage()); + } + return content; + } + + @Override + public ContentsModel getAssetById(Long id) { + ContentsModel response = new ContentsModel(); + try { + Session session = HibernateUtil.getSessionFactory().openSession(); + + if (session != null) { + Content content = session.find(Content.class, id); + response = new ContentsModel(content.getId(), content.getAsset(), content.getCreatedDate(), content.getUpdatedDate()); + session.close(); + } + } catch (Exception e) { + logger.info(e.getMessage()); + } + return response; + } + + @Override + public void updateAsset(Long id, String newAssetName) { + try { + Session session = HibernateUtil.getSessionFactory().openSession(); + if (session != null) { + Content content = session.find(Content.class, id); + session.getTransaction().begin(); + session.persist(content); + session.getTransaction().commit(); + session.close(); + } + } catch (Exception e) { + logger.info(e.getMessage()); + } + } + + @Override + public void deleteAsset(Long id) { + try { + Session session = HibernateUtil.getSessionFactory().openSession(); + if (session != null) { + Content content = session.find(Content.class, id); + session.getTransaction().begin(); + session.remove(content); + session.getTransaction().begin(); + session.close(); + } + + } catch (Exception e) { + logger.info(e.getMessage()); + } + } + + @Override + public List getAllAssets() { + List response = new ArrayList(); + try { + Session session = HibernateUtil.getSessionFactory().openSession(); + if (session != null) { + Query query = session.createQuery("select e from Content e", Content.class); + List contentList = query.getResultList(); + contentList.forEach(data -> { + ContentsModel contentsModel = new ContentsModel(data.getId(), data.getAsset(), data.getCreatedDate(), data.getCreatedDate()); + response.add(contentsModel); + }); + session.close(); + } + } catch (Exception e) { + logger.info(e.getMessage()); + } + return response.isEmpty() ? null : response; + } + + +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/Impl/TransferRepositoryImpl.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/Impl/TransferRepositoryImpl.java new file mode 100644 index 00000000..b7ae3167 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/Impl/TransferRepositoryImpl.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.repository.Impl; + +import com.eclipse.mxd.util.HibernateUtil; +import com.eclipse.mxd.entity.Content; +import com.eclipse.mxd.entity.Transfer; +import com.eclipse.mxd.model.TransfersModel; +import com.eclipse.mxd.repository.TransferRepository; +import com.eclipse.mxd.util.DateTimeUtil; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.persistence.Query; +import org.hibernate.Session; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +@ApplicationScoped +public class TransferRepositoryImpl implements TransferRepository { + + private static final Logger logger = Logger.getLogger(TransferRepositoryImpl.class.getName()); + + @Override + public Long createTransferWithID(String asset, String contents, String id) { + try { + Session session = HibernateUtil.getSessionFactory().openSession(); + if (session != null) { + Transfer transfer = new Transfer(); + transfer.setTransferid(id); + transfer.setAsset(asset); + transfer.setCreatedDate(DateTimeUtil.getCurrentDateTimeInAsiaKolkata()); + transfer.setUpdatedDate(DateTimeUtil.getCurrentDateTimeInAsiaKolkata()); + transfer.setContents(contents); + session.getTransaction().begin(); + session.persist(transfer); + session.getTransaction().commit(); + session.close(); + if(transfer.getId() != null){ + return transfer.getId(); + }else { + return -1L; + } + } + + + }catch (Exception e){ + logger.info(e.getMessage()); + }finally { + + } + + return null; + } + + @Override + public TransfersModel getTransferById(String id) { + Transfer transfer = new Transfer(); + TransfersModel transfersData = new TransfersModel(); + try { + Session session = HibernateUtil.getSessionFactory().openSession(); + if (session != null) { + transfer = session.createQuery("SELECT t FROM Transfer t WHERE t.transferid = :transferid", Transfer.class) + .setParameter("transferid", id) + .getSingleResult(); + session.close(); + } + transfersData = new TransfersModel(transfer.getId(),transfer.getAsset(),transfer.getContents(),transfer.getCreatedDate(), transfer.getUpdatedDate()); + }catch (Exception e){ + logger.info(e.getMessage()); + } + return transfersData; + } + + @Override + public void updateTransfer(Long id, String newAsset) { + try { + Session session = HibernateUtil.getSessionFactory().openSession(); + if (session != null) { + Transfer transfer = session.find(Transfer.class, id); + transfer.setAsset(newAsset); + session.close(); + } + + }catch (Exception e){ + logger.info(e.getMessage()); + }finally { + + } + } + + @Override + public void deleteTransfer(Long id) { + try { + Session session = HibernateUtil.getSessionFactory().openSession(); + if (session != null) { + Transfer transfer = session.find(Transfer.class, id); + session.getTransaction().begin(); + session.remove(transfer); + session.getTransaction().commit(); + session.close(); + } + + }catch (Exception e){ + logger.info(e.getMessage()); + }finally { + + } + } + + @Override + public List getAllTransfers() { + List response = new ArrayList(); + try { + Session session = HibernateUtil.getSessionFactory().openSession(); + if (session != null) { + Query query = session.createQuery("select e from Content e", Content.class); + List transferList = query.getResultList(); + transferList.forEach(data->{ + TransfersModel transfersModel = new TransfersModel(data.getId(),data.getAsset(), data.getContents(),data.getCreatedDate(), data.getCreatedDate()); + response.add(transfersModel); + }); + session.close(); + } + + }catch (Exception e){ + logger.info(e.getMessage()); + }finally { + + } + return response.isEmpty() ? null : response; + } + + +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/TransferRepository.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/TransferRepository.java new file mode 100644 index 00000000..a9877e29 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/repository/TransferRepository.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.repository; + +import com.eclipse.mxd.model.TransfersModel; + +import java.util.List; + +public interface TransferRepository { + + Long createTransferWithID(String asset, String contents, String id); + + TransfersModel getTransferById(String id); + + void updateTransfer(Long id, String newAsset); + + void deleteTransfer(Long id); + + List getAllTransfers(); + +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/service/ContentRandomService.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/service/ContentRandomService.java new file mode 100644 index 00000000..b65bfaf7 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/service/ContentRandomService.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.service; + +import jakarta.ws.rs.core.Response; + +public interface ContentRandomService { + public Response getRandomContent(); +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/service/ContentService.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/service/ContentService.java new file mode 100644 index 00000000..c67bf550 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/service/ContentService.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.service; + + +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.UriInfo; + +public interface ContentService { + Response getAll(); + + Response getById(Long id); + + Response postContent(String requestBody, UriInfo uriInfo); +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/service/HttpServiceConnection.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/service/HttpServiceConnection.java new file mode 100644 index 00000000..60953c66 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/service/HttpServiceConnection.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.service; + + +import com.eclipse.mxd.model.TransferRequest; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.logging.Logger; + +public class HttpServiceConnection { + private static final Logger logger = Logger.getLogger(HttpServiceConnection.class.getName()); + + public static String getUrlAssets(TransferRequest receivedModel) { + String res = null; + try { + URL url = new URL(receivedModel.getEndpoint()); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty(receivedModel.getAuthKey(), receivedModel.getAuthCode()); + connection.setRequestProperty("User-Agent", "Java HttpURLConnection Bot"); + connection.setRequestProperty("Content-Type", "application/json"); + int responseCode = connection.getResponseCode(); + logger.info("Response Code: " + responseCode); + BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String inputLine; + StringBuilder response = new StringBuilder(); + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + logger.info("Response Body: " + response.toString()); + connection.disconnect(); + return response.toString(); + } catch (Exception e) { + logger.info(e.getMessage()); + } + return res; + } +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/service/Impl/ContentRandomServiceImpl.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/service/Impl/ContentRandomServiceImpl.java new file mode 100644 index 00000000..ec864f8f --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/service/Impl/ContentRandomServiceImpl.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.service.Impl; + +import com.eclipse.mxd.repository.ContentRamdomRepository; +import com.eclipse.mxd.repository.Impl.ContentRandomRepositoryImpl; +import com.eclipse.mxd.service.ContentRandomService; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.ws.rs.core.Response; + +import java.util.logging.Logger; + +@ApplicationScoped +public class ContentRandomServiceImpl implements ContentRandomService { + + private static final Logger logger = Logger.getLogger(ContentRandomServiceImpl.class.getName()); + + private final ContentRamdomRepository contentRamdomRepository = new ContentRandomRepositoryImpl(); + + @Override + public Response getRandomContent() { + try { + return contentRamdomRepository.getRandomContent(); + }catch (Exception e){ + logger.info(e.getMessage()); + return Response.ok(e.getMessage()).build(); + } + } +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/service/Impl/ContentServiceImpl.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/service/Impl/ContentServiceImpl.java new file mode 100644 index 00000000..2b730f16 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/service/Impl/ContentServiceImpl.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.service.Impl; + +import com.eclipse.mxd.model.ContentModelResponse; +import com.eclipse.mxd.model.ContentsModel; +import com.eclipse.mxd.repository.ContentServiceRepository; +import com.eclipse.mxd.repository.Impl.ContentRepositoryImpl; +import com.eclipse.mxd.service.ContentService; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.UriInfo; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + + +@ApplicationScoped +public class ContentServiceImpl implements ContentService { + + private static final Logger logger = Logger.getLogger(ContentServiceImpl.class.getName()); + + private final ContentServiceRepository contentServiceRepository = new ContentRepositoryImpl(); + + @Override + public Response getAll() { + try { + List contentResponse = this.contentServiceRepository.getAllAssets(); + if (contentResponse != null && !contentResponse.isEmpty()) { + List contentsModels = new ArrayList(); + for (ContentsModel contentsModel : contentResponse) { + JsonNode jsonNode = new ObjectMapper().readTree(contentsModel.getAsset()); + ContentModelResponse contentsModel1 = new ContentModelResponse(); + contentsModel1.setId(contentsModel.getId()); + contentsModel1.setAsset(jsonNode); + contentsModel1.setCreatedDate(contentsModel.getCreatedDate()); + contentsModel1.setUpdatedDate(contentsModel.getUpdatedDate()); + contentsModels.add(contentsModel1); + } + return Response.ok(new ObjectMapper().writeValueAsString(contentsModels)).build(); + + } else { + return Response.status(Response.Status.NOT_FOUND).entity("Asset Not Found").build(); + } + } catch (Exception e) { + logger.info(e.getMessage()); + return Response.serverError().entity("Internal server error").build(); + } + } + + @Override + public Response getById(Long id) { + try { + ContentsModel content = this.contentServiceRepository.getAssetById(id); + if (content != null && content.getId()!=null) { + JsonNode jsonNode = new ObjectMapper().readTree(content.getAsset()); + ContentModelResponse contentModelRes = new ContentModelResponse(); + contentModelRes.setId(content.getId()); + contentModelRes.setCreatedDate(content.getCreatedDate()); + contentModelRes.setUpdatedDate(content.getUpdatedDate()); + contentModelRes.setAsset(jsonNode); + return Response.ok(new ObjectMapper().writeValueAsString(contentModelRes)).build(); + } else { + return Response.status(Response.Status.NOT_FOUND).entity("Asset Not Found With ID").build(); + } + } catch (Exception e) { + logger.info(e.getMessage()); + return Response.serverError().entity("Internal server error").build(); + } + } + + @Override + public Response postContent(String requestBody, UriInfo uriInfo) { + try { + Long id = contentServiceRepository.createAsset(requestBody); + if (id != null) { + logger.info(uriInfo.getAbsolutePath() + ""); + return Response.ok(uriInfo.getAbsolutePath() + "" + id).build(); + } else { + return Response.status(Response.Status.NOT_FOUND).entity("Asset Not Created").build(); + } + } catch (Exception e) { + logger.info(e.getMessage()); + return Response.serverError().entity("Internal server error").build(); + } + } +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/service/Impl/TransferServiceImpl.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/service/Impl/TransferServiceImpl.java new file mode 100644 index 00000000..a768066a --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/service/Impl/TransferServiceImpl.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.service.Impl; + +import com.eclipse.mxd.model.TransferContentResponse; +import com.eclipse.mxd.model.TransferRequest; +import com.eclipse.mxd.model.TransferResponse; +import com.eclipse.mxd.model.TransfersModel; +import com.eclipse.mxd.repository.Impl.TransferRepositoryImpl; +import com.eclipse.mxd.repository.TransferRepository; +import com.eclipse.mxd.service.HttpServiceConnection; +import com.eclipse.mxd.service.TransferService; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.ws.rs.core.Response; + +import java.util.logging.Logger; + + +@ApplicationScoped +public class TransferServiceImpl implements TransferService { + + private static final Logger logger = Logger.getLogger(TransferServiceImpl.class.getName()); + + private final TransferRepository transferRepository = new TransferRepositoryImpl(); + + @Override + public Response acceptTransfer(String transferRequest) { + ObjectMapper objectMapper = new ObjectMapper(); + try { + TransferRequest transferRequestData = objectMapper.readValue(transferRequest, TransferRequest.class); + String assetsUrl = HttpServiceConnection.getUrlAssets(transferRequestData); + Gson gson = new Gson(); + String transferRequestJson = gson.toJson(transferRequest); + Long id = this.transferRepository.createTransferWithID(transferRequestJson, assetsUrl, + transferRequestData.getId()); + return Response.ok(id).build(); + + } catch (Exception e) { + logger.info(e.getMessage()); + return Response.status(Response.Status.BAD_REQUEST).entity("Not Created").build(); + } + } + + @Override + public Response getTransfer(String id) { + try { + TransfersModel transfersModel = this.transferRepository.getTransferById(id); + if (transfersModel != null && transfersModel.getId()!=null) { + JsonNode jsonNode = new ObjectMapper().readTree(transfersModel.getAsset()); + TransferResponse transferResponse = new TransferResponse(); + transferResponse.setAsset(jsonNode); + return Response.ok(new ObjectMapper().writeValueAsString(transferResponse)).build(); + } else { + return Response.status(Response.Status.NOT_FOUND).entity("Transfer Not Found").build(); + } + } catch (Exception e) { + logger.info(e.getMessage()); + return Response.serverError().entity("Internal server error").build(); + } + } + + @Override + public Response getTransferContents(String id) { + try { + TransfersModel transfersModel = this.transferRepository.getTransferById(id); + if (transfersModel != null && transfersModel.getContents()!=null) { + JsonNode jsonNode = new ObjectMapper().readTree(transfersModel.getContents()); + TransferContentResponse transferContentResponse = new TransferContentResponse(); + transferContentResponse.setAsset(jsonNode); + return Response.ok(new ObjectMapper().writeValueAsString(transferContentResponse)).build(); + } else { + return Response.status(Response.Status.NOT_FOUND).entity("Transfer Contents Not Found").build(); + } + } catch (Exception e) { + logger.info(e.getMessage()); + return Response.serverError().entity("Internal server error").build(); + } + } +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/service/TransferService.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/service/TransferService.java new file mode 100644 index 00000000..035baefa --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/service/TransferService.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.service; + +import jakarta.ws.rs.core.Response; + +public interface TransferService { + Response acceptTransfer(String transferRequest); + + Response getTransfer(String id); + + Response getTransferContents(String id); +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/util/DateTimeUtil.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/util/DateTimeUtil.java new file mode 100644 index 00000000..1726d0c2 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/util/DateTimeUtil.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.util; + +import java.util.Date; + +public class DateTimeUtil { + + public static Date getCurrentDateTimeInAsiaKolkata() { + long currentTimeMillis = System.currentTimeMillis(); + // Create a new Date object using the current time + return new Date(currentTimeMillis); + } + +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/util/HibernateUtil.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/util/HibernateUtil.java new file mode 100644 index 00000000..f100384d --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/util/HibernateUtil.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.util; + + +import java.io.InputStream; +import java.util.Properties; +import java.util.logging.Logger; + +import com.eclipse.mxd.entity.Content; +import com.eclipse.mxd.entity.Transfer; +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; +import org.hibernate.service.ServiceRegistry; + +public class HibernateUtil { + private static SessionFactory sessionFactory; + private static final Logger logger = Logger.getLogger(HibernateUtil.class.getName()); + + public static SessionFactory getSessionFactory() { + if (sessionFactory == null) { + try { + Configuration configuration = new Configuration(); + Properties settings = new Properties(); + Properties appProperties = new Properties(); + try (InputStream input = HibernateUtil.class.getClassLoader().getResourceAsStream("application.properties")) { + appProperties.load(input); + } catch (Exception e) { + logger.info(" error " + e.getMessage()); + } + // Read database configuration from environment variables + String databaseUrl = System.getenv("BACKEND-SERVICE-DATABASE_URL"); + String databaseUser = System.getenv("BACKEND-SERVICE-DATABASE_USER"); + String databasePassword = System.getenv("BACKEND-SERVICE-DATABASE_PASSWORD"); + // If environment variables are not set, fall back to application properties + logger.info(" env databaseUrl : " + databaseUrl); + logger.info(" env databaseUser : " + databaseUser); + logger.info(" env databasePassword : " + databasePassword); + logger.info(" props databaseUrl : " + appProperties.getProperty("database.url")); + logger.info(" props databaseUser : " + appProperties.getProperty("database.user")); + logger.info(" props databasePassword : " + appProperties.getProperty("database.password")); + if ((databaseUrl != null && !databaseUrl.isEmpty()) && (databaseUser != null && !databaseUser.isEmpty()) && (databasePassword != null && !databasePassword.isEmpty())) { + settings.put(Environment.URL, databaseUrl); + settings.put(Environment.USER, databaseUser); + settings.put(Environment.PASS, databasePassword); + logger.info(" connecting using evn variables"); + } else { + settings.put(Environment.URL, appProperties.getProperty("database.url")); + settings.put(Environment.USER, appProperties.getProperty("database.user")); + settings.put(Environment.PASS, appProperties.getProperty("database.password")); + logger.info(" connecting using application.properties variables"); + } + settings.put(Environment.DRIVER, "org.postgresql.Driver"); + settings.put(Environment.DIALECT, "org.hibernate.dialect.PostgreSQLDialect"); + settings.put(Environment.SHOW_SQL, "true"); + settings.put(Environment.FORMAT_SQL, "true"); + settings.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread"); + settings.put(Environment.HBM2DDL_AUTO, "create-drop"); + configuration.setProperties(settings); + configuration.addAnnotatedClass(Transfer.class); + configuration.addAnnotatedClass(Content.class); + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() + .applySettings(configuration.getProperties()).build(); + logger.info("Hibernate Java Config serviceRegistry created"); + sessionFactory = configuration.buildSessionFactory(serviceRegistry); + return sessionFactory; + } catch (Exception e) { + logger.info(" error " + e.getMessage()); + } + } + return sessionFactory; + } +} diff --git a/mxd/backend-service/src/main/java/com/eclipse/mxd/util/RandomWordUtil.java b/mxd/backend-service/src/main/java/com/eclipse/mxd/util/RandomWordUtil.java new file mode 100644 index 00000000..209b2c41 --- /dev/null +++ b/mxd/backend-service/src/main/java/com/eclipse/mxd/util/RandomWordUtil.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available 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. + * + * SPDX-License-Identifier: Apache-2.0 + * Contributors:Ravinder Kumar + * Backend-API and implementation + * + ******************************************************************************/ + +package com.eclipse.mxd.util; + +import java.security.SecureRandom; + +public class RandomWordUtil { + + public static String generateRandomWord() { + String characters = "abcdefghijklmnopqrstuvwxyz"; + SecureRandom random = new SecureRandom(); + StringBuilder sb = new StringBuilder(); + + int length = random.nextInt(8) + 1; + for (int i = 0; i < length; i++) { + int index = random.nextInt(characters.length()); + sb.append(characters.charAt(index)); + } + return sb.toString(); + } + +} diff --git a/mxd/backend-service/src/main/resources/META-INF/beans.xml b/mxd/backend-service/src/main/resources/META-INF/beans.xml new file mode 100644 index 00000000..11d388ed --- /dev/null +++ b/mxd/backend-service/src/main/resources/META-INF/beans.xml @@ -0,0 +1,32 @@ + + + + + + + \ No newline at end of file diff --git a/mxd/backend-service/src/main/resources/application.properties b/mxd/backend-service/src/main/resources/application.properties new file mode 100644 index 00000000..55d5018b --- /dev/null +++ b/mxd/backend-service/src/main/resources/application.properties @@ -0,0 +1,30 @@ +# application.properties + +#******************************************************************************* +# * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +# * Copyright (c) 2023 Contributors to the Eclipse Foundation +# * +# * See the NOTICE file(s) distributed with this work for additional +# * information regarding copyright ownership. +# * +# * This program and the accompanying materials are made available under the +# * terms of the Apache License, Version 2.0 which is available 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. +# * +# * SPDX-License-Identifier: Apache-2.0 +# * Contributors:Ravinder Kumar +# * Backend-API and implementation +# * +# ******************************************************************************/ + + +database.driver=org.postgresql.Driver +database.url=jdbc:postgresql://localhost:5432/backendservicedb +database.user=postgres +database.password=postgres \ No newline at end of file diff --git a/mxd/postgres.tf b/mxd/postgres.tf index 36bd1b56..7ed39601 100644 --- a/mxd/postgres.tf +++ b/mxd/postgres.tf @@ -115,7 +115,9 @@ resource "kubernetes_config_map" "postgres-config" { CREATE DATABASE ${module.alice-connector.database-name}; CREATE DATABASE ${module.bob-connector.database-name}; CREATE DATABASE trudy; - + + CREATE DATABASE backendservicedb; + \c backendservicedb; EOT } }