Skip to content

Commit

Permalink
Merge pull request #2 from MEITREX/java-version-issue
Browse files Browse the repository at this point in the history
Java version issue
  • Loading branch information
myluki2000 authored Jun 29, 2024
2 parents d56b6f6 + 49ec817 commit fb3727c
Show file tree
Hide file tree
Showing 66 changed files with 568 additions and 421 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: Building Docker Image

on:
workflow_run:
workflows:
- Testing CI pipeline
types:
- completed
workflow_dispatch:
# enable when deployment is ready
# workflow_run:
# workflows:
# - Testing CI pipeline
# types:
# - completed

jobs:
docker-build:
Expand Down
21 changes: 14 additions & 7 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,32 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v3
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3
uses: gradle/wrapper-validation-action@v2
- name: Run chmod to make gradlew executable
run: chmod +x gradlew

- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Execute tests
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629
uses: gradle/gradle-build-action@v3
with:
arguments: cleanTest test jacocoTestReport sonar





2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:experimental
FROM gradle:7.6.2-jdk17 AS build
FROM gradle:8-jdk21 AS build
WORKDIR /workspace/app

# Copy only gradle files to container so we can install them
Expand Down
62 changes: 45 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.6'
id 'io.spring.dependency-management' version '1.1.0'
id "io.github.kobylynskyi.graphql.codegen" version "5.7.2"
id "org.sonarqube" version "4.0.0.2929"
id 'org.springframework.boot' version '3.+'
id 'io.spring.dependency-management' version '1.+'
id "io.github.kobylynskyi.graphql.codegen" version "5.+"
id "org.sonarqube" version "5.+"
id "jacoco"

}

group = 'de.unistuttgart.iste.gits'
group = 'de.unistuttgart.iste.meitrex'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
sourceCompatibility = '21'

def jacocoEnabled = System.properties.getProperty("jacocoEnabled") ?: "true"

Expand All @@ -26,15 +26,35 @@ sonarqube {
property("sonar.organization", "meitrex")
property("sonar.host.url", "https://sonarcloud.io")
}
}

// workaround to fetch schema files from external repositories
// as gradle only supports java dependencies
def fetchFilesFromRepo(String repository, List<String> files) {
def baseurl = "https://raw.githubusercontent.com/MEITREX/"
def fileUrl = "${baseurl}${repository}/main/src/main/resources/graphql/"
def outputDir = "src/main/resources/graphql"

files.each { file ->
tasks.register("fetchExternalSchema-${file.capitalize()}", Exec) {
commandLine 'curl', "${fileUrl}${file}", '-o', "${outputDir}/${repository}/${file}"
}
}
}

fetchFilesFromRepo("common", ["directives.graphqls", "scalars.graphqls", "sortFilterPagination.graphqls"])

// run this task to fetch the latest schema files from the external github repositories
tasks.register("fetchAllExternalSchemas", Task) {
dependsOn tasks.matching { it.name.startsWith("fetchExternalSchema-") }
}

// Automatically generate DTOs from GraphQL schema:
graphqlCodegen {
// all config options:
// https://github.com/kobylynskyi/graphql-java-codegen/blob/main/docs/codegen-options.md
outputDir = new File("$buildDir/generated")
packageName = "de.unistuttgart.iste.gits.generated.dto"
packageName = "de.unistuttgart.iste.meitrex.generated.dto"
generatedAnnotation = "jakarta.annotation.Generated"
modelValidationAnnotation = "jakarta.validation.constraints.NotNull"
generateApis = false // set to false as the generator does not support spring boot graphQL
Expand All @@ -48,6 +68,7 @@ graphqlCodegen {
]
generateEqualsAndHashCode = true
generateToString = true
fieldsWithResolvers = ["@OnDemand"]
}

// Automatically generate GraphQL code on project build:
Expand All @@ -56,6 +77,16 @@ compileJava.dependsOn 'graphqlCodegen'
// Add generated sources to your project source sets:
sourceSets.main.java.srcDir "$buildDir/generated"

// Automatically generate API documentation on project build:
// Remark: Only works on Windows
tasks.register('generateApiDocs', Exec) {
commandLine 'cmd', '/c', 'generate_api_doc.bat'
}

tasks.named('assemble') {
finalizedBy('generateApiDocs')
}

configurations {
compileOnly {
extendsFrom annotationProcessor
Expand All @@ -67,35 +98,32 @@ repositories {
}

dependencies {
implementation 'de.unistuttgart.iste.gits:gits-common:0.6.4'
implementation 'com.google.code.findbugs:jsr305:3.0.2' // removes a gradle warning about an unknown annotation
implementation 'de.unistuttgart.iste.meitrex:meitrex-common:1.0.6'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-graphql'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.modelmapper:modelmapper:3.+'
implementation 'com.graphql-java:graphql-java-extended-scalars:20.0'
implementation 'com.graphql-java:graphql-java-extended-validation:20.0'
implementation 'com.graphql-java:graphql-java-extended-scalars:22.0'
implementation 'com.graphql-java:graphql-java-extended-validation:22.0'
implementation 'io.dapr:dapr-sdk:1.9.0' // Dapr's core SDK with all features, except Actors.
implementation 'io.dapr:dapr-sdk-springboot:1.9.0' // Dapr's SDK integration with SpringBoot
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'de.unistuttgart.iste.gits:gits-common-test:0.3.2'
testImplementation 'de.unistuttgart.iste.meitrex:meitrex-common-test:1.0.6'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework:spring-webflux'
testImplementation 'org.springframework.graphql:spring-graphql-test'
testImplementation "org.mockito:mockito-core:3.+"
testImplementation "org.mockito:mockito-core:5.+"
testImplementation 'org.hamcrest:hamcrest:2.+'
testImplementation "org.testcontainers:postgresql:1.18.3"
testImplementation "org.testcontainers:junit-jupiter:1.18.3"
testImplementation "org.testcontainers:postgresql:1.+"
testImplementation "org.testcontainers:junit-jupiter:1.+"
}

tasks.named('test') {
useJUnitPlatform()
}

tasks.withType(Test).configureEach { testLogging.showStandardStreams = true }
2 changes: 1 addition & 1 deletion components/pubsub.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: gits
name: meitrex
spec:
type: pubsub.redis
version: v1
Expand Down
19 changes: 15 additions & 4 deletions generate_api_doc.bat
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
@echo off
echo Generating API documentation...
echo This requires the service to be running
echo This requires npm to be installed!

REM clear old docs
del api.md
REM Delete the combined file
del combined.graphql

set port=9001
set title=Quiz Service API

REM install graphql-markdown if not installed
if not exist node_modules\graphql-markdown (
start cmd /C npm install graphql-markdown
echo Installing graphql-markdown, run this script again after installation
npm install graphql-markdown
)

npx graphql-markdown "http://localhost:%port%/graphql" --title "%title%" > api.md
REM Concatenate all graphql files into one
for /r src\main\resources\graphql %%i in (*.graphqls) do type "%%i" >> combined.graphql

REM Run npx in a separate cmd instance
cmd /c npx graphql-markdown combined.graphql --title "%title%" > api.md

echo API documentation generated.

REM Delete the combined file
del combined.graphql
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
7 changes: 3 additions & 4 deletions jacoco.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
jacoco {
toolVersion = "0.8.8"
toolVersion = "0.8.11"
}

test {
finalizedBy jacocoTestReport
}


jacocoTestReport {
reports {
xml.enabled true
html.enabled true
xml.required.set(true)
html.required.set(true)
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
}
}
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ rootProject.name = 'quiz_service'

sourceControl {
gitRepository(uri('https://github.com/MEITREX/common')) {
producesModule('de.unistuttgart.iste.gits:gits-common')
producesModule('de.unistuttgart.iste.meitrex:meitrex-common')
}
gitRepository(uri('https://github.com/MEITREX/common_test')) {
producesModule('de.unistuttgart.iste.gits:gits-common-test')
producesModule('de.unistuttgart.iste.meitrex:meitrex-common-test')
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.unistuttgart.iste.gits.quiz_service;
package de.unistuttgart.iste.meitrex.quiz_service;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package de.unistuttgart.iste.gits.quiz_service.config;
package de.unistuttgart.iste.meitrex.quiz_service.config;

import de.unistuttgart.iste.gits.common.dapr.MockTopicPublisher;
import de.unistuttgart.iste.gits.common.dapr.TopicPublisher;
import de.unistuttgart.iste.meitrex.common.dapr.MockTopicPublisher;
import de.unistuttgart.iste.meitrex.common.dapr.TopicPublisher;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
* This is a dev-config for the TopicPublisher. It is intended to be used for development only.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.unistuttgart.iste.gits.quiz_service.config;
package de.unistuttgart.iste.meitrex.quiz_service.config;

import graphql.scalars.ExtendedScalars;
import graphql.validation.rules.OnValidationErrorStrategy;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.unistuttgart.iste.gits.quiz_service.config;
package de.unistuttgart.iste.meitrex.quiz_service.config;

import org.modelmapper.ModelMapper;
import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package de.unistuttgart.iste.gits.quiz_service.config;
package de.unistuttgart.iste.meitrex.quiz_service.config;

import de.unistuttgart.iste.gits.common.user_handling.RequestHeaderUserProcessor;
import de.unistuttgart.iste.meitrex.common.user_handling.RequestHeaderUserProcessor;
import lombok.SneakyThrows;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Configuration;
import org.springframework.graphql.server.*;
import org.springframework.graphql.server.WebGraphQlInterceptor;
import org.springframework.graphql.server.WebGraphQlRequest;
import org.springframework.graphql.server.WebGraphQlResponse;
import reactor.core.publisher.Mono;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.unistuttgart.iste.gits.quiz_service.config;
package de.unistuttgart.iste.meitrex.quiz_service.config;

import de.unistuttgart.iste.gits.common.dapr.TopicPublisher;
import de.unistuttgart.iste.meitrex.common.dapr.TopicPublisher;
import io.dapr.client.DaprClientBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package de.unistuttgart.iste.gits.quiz_service.controller;

import de.unistuttgart.iste.gits.common.exception.NoAccessToCourseException;
import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser;
import de.unistuttgart.iste.gits.common.user_handling.LoggedInUser.UserRoleInCourse;
import de.unistuttgart.iste.gits.generated.dto.*;
import de.unistuttgart.iste.gits.quiz_service.persistence.entity.QuizEntity;
import de.unistuttgart.iste.gits.quiz_service.service.QuizService;
package de.unistuttgart.iste.meitrex.quiz_service.controller;

import de.unistuttgart.iste.meitrex.common.exception.NoAccessToCourseException;
import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser;
import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser.UserRoleInCourse;
import de.unistuttgart.iste.meitrex.generated.dto.*;
import de.unistuttgart.iste.meitrex.quiz_service.persistence.entity.QuizEntity;
import de.unistuttgart.iste.meitrex.quiz_service.service.QuizService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.graphql.data.method.annotation.*;
Expand All @@ -14,7 +14,7 @@
import java.util.List;
import java.util.UUID;

import static de.unistuttgart.iste.gits.common.user_handling.UserCourseAccessValidator.validateUserHasAccessToCourse;
import static de.unistuttgart.iste.meitrex.common.user_handling.UserCourseAccessValidator.validateUserHasAccessToCourse;

@Slf4j
@Controller
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package de.unistuttgart.iste.gits.quiz_service.controller;
package de.unistuttgart.iste.meitrex.quiz_service.controller;

import de.unistuttgart.iste.gits.common.event.ContentChangeEvent;
import de.unistuttgart.iste.gits.quiz_service.service.QuizService;
import de.unistuttgart.iste.meitrex.common.event.ContentChangeEvent;
import de.unistuttgart.iste.meitrex.quiz_service.service.QuizService;
import io.dapr.Topic;
import io.dapr.client.domain.CloudEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.unistuttgart.iste.gits.quiz_service.exception;
package de.unistuttgart.iste.meitrex.quiz_service.exception;

import de.unistuttgart.iste.gits.common.exception.ExceptionToGraphQlErrorConverter;
import de.unistuttgart.iste.meitrex.common.exception.ExceptionToGraphQlErrorConverter;
import graphql.GraphQLError;
import graphql.schema.DataFetchingEnvironment;
import lombok.extern.slf4j.Slf4j;
Expand Down
Loading

0 comments on commit fb3727c

Please sign in to comment.