RED-7405 - Migrate redaction-report-service to gradle

This commit is contained in:
Andrei Isvoran 2023-11-03 08:38:06 +01:00
parent 92a0a35af5
commit 6aaa7e5247
24 changed files with 354 additions and 499 deletions

8
.gitignore vendored
View File

@ -26,3 +26,11 @@
**/.DS_Store
**/classpath-data.json
**/dependencies-and-licenses-overview.txt
gradle.properties
gradlew
gradlew.bat
gradle/
**/.gradle
**/build

View File

@ -3,4 +3,21 @@ variables:
include:
- project: 'gitlab/gitlab'
ref: 'main'
file: 'ci-templates/maven_java.yml'
file: 'ci-templates/gradle_java.yml'
deploy:
stage: deploy
tags:
- dind
script:
- echo "Building with gradle version ${BUILDVERSION}"
- gradle -Pversion=${BUILDVERSION} publish
- gradle bootBuildImage --cleanCache --publishImage -PbuildbootDockerHostNetwork=true -Pversion=${BUILDVERSION}
- echo "BUILDVERSION=$BUILDVERSION" >> version.env
artifacts:
reports:
dotenv: version.env
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_BRANCH =~ /^release/
- if: $CI_COMMIT_TAG

View File

@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}
repositories {
gradlePluginPortal()
}

View File

@ -0,0 +1,57 @@
plugins {
`java-library`
`maven-publish`
pmd
checkstyle
jacoco
}
repositories {
mavenLocal()
mavenCentral()
maven {
url = uri("https://nexus.knecon.com/repository/gindev/");
credentials {
username = providers.gradleProperty("mavenUser").getOrNull();
password = providers.gradleProperty("mavenPassword").getOrNull();
}
}
}
group = "com.iqser.red.service"
version = "4.0-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17
tasks.pmdMain {
pmd.ruleSetFiles = files("${rootDir}/config/pmd/pmd.xml")
}
tasks.pmdTest {
pmd.ruleSetFiles = files("${rootDir}/config/pmd/test_pmd.xml")
}
tasks.named<Test>("test") {
useJUnitPlatform()
reports {
junitXml.outputLocation.set(layout.buildDirectory.dir("reports/junit"))
}
}
tasks.test {
finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
}
tasks.jacocoTestReport {
dependsOn(tasks.test) // tests are required to run before generating the report
reports {
xml.required.set(true)
csv.required.set(false)
html.outputLocation.set(layout.buildDirectory.dir("jacocoHtml"))
}
}
java {
withJavadocJar()
}

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property
name="severity"
value="error"/>
<module name="TreeWalker">
<module name="SuppressWarningsHolder"/>
<module name="MissingDeprecated"/>
<module name="MissingOverride"/>
<module name="AnnotationLocation"/>
<module name="JavadocStyle"/>
<module name="NonEmptyAtclauseDescription"/>
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="RedundantModifier"/>
<module name="EmptyBlock"/>
<module name="DefaultComesLast"/>
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="ExplicitInitialization"/>
<module name="IllegalInstantiation"/>
<module name="ModifiedControlVariable"/>
<module name="MultipleVariableDeclarations"/>
<module name="PackageDeclaration"/>
<module name="ParameterAssignment"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="StringLiteralEquality"/>
<module name="OneStatementPerLine"/>
<module name="FinalClass"/>
<module name="ArrayTypeStyle"/>
<module name="UpperEll"/>
<module name="OuterTypeFilename"/>
</module>
<module name="FileTabCharacter"/>
<module name="SuppressWarningsFilter"/>
</module>

21
config/pmd/pmd.xml Normal file
View File

@ -0,0 +1,21 @@
<?xml version="1.0"?>
<ruleset name="Custom ruleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
Knecon ruleset checks the code for bad stuff
</description>
<rule ref="category/java/errorprone.xml">
<exclude name="DataflowAnomalyAnalysis"/>
<exclude name="MissingSerialVersionUID"/>
<exclude name="NullAssignment"/>
<exclude name="AvoidLiteralsInIfCondition"/>
<exclude name="AvoidDuplicateLiterals"/>
<exclude name="AvoidFieldNameMatchingMethodName"/>
<exclude name="AssignmentInOperand"/>
</rule>
</ruleset>

24
config/pmd/test_pmd.xml Normal file
View File

@ -0,0 +1,24 @@
<?xml version="1.0"?>
<ruleset name="Custom ruleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
Knecon test ruleset checks the code for bad stuff
</description>
<rule ref="category/java/errorprone.xml">
<exclude name="DataflowAnomalyAnalysis"/>
<exclude name="MissingSerialVersionUID"/>
<exclude name="NullAssignment"/>
<exclude name="AvoidLiteralsInIfCondition"/>
<exclude name="AvoidDuplicateLiterals"/>
<exclude name="AvoidFieldNameMatchingMethodName"/>
<exclude name="AvoidFieldNameMatchingTypeName"/>
<exclude name="AssignmentInOperand"/>
<exclude name="TestClassWithoutTestCases"/>
</rule>
</ruleset>

18
pom.xml
View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.iqser.red.service</groupId>
<artifactId>redaction-report-service</artifactId>
<version>4.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>redaction-report-service-v1</module>
<module>redaction-report-service-image-v1</module>
</modules>
</project>

View File

@ -1,97 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.knecon.fforesight</groupId>
<artifactId>platform-docker-dependency</artifactId>
<version>0.1.0</version>
<relativePath/>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>redaction-report-service-image-v1</artifactId>
<groupId>com.iqser.red.service</groupId>
<version>4.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<service.server>redaction-report-service-server-v1</service.server>
<platform.jar>${service.server}.jar</platform.jar>
<docker.skip.push>false</docker.skip.push>
<docker.image.name>${docker.image.prefix}/${service.server}</docker.image.name>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>download-platform-jar</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${service.server}</artifactId>
<version>${project.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<destFileName>${platform.jar}</destFileName>
</dependency>
</artifactItems>
<outputDirectory>${docker.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<images>
<image>
<name>${docker.image.name}</name>
<build>
<dockerFileDir>${docker.build.directory}</dockerFileDir>
<args>
<PLATFORM_JAR>${platform.jar}</PLATFORM_JAR>
</args>
<tags>
<tag>${docker.image.version}</tag>
<tag>latest</tag>
</tags>
</build>
</image>
</images>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -1,9 +0,0 @@
FROM red/base-image:2.0.2
ARG PLATFORM_JAR
ENV PLATFORM_JAR ${PLATFORM_JAR}
ENV USES_ELASTICSEARCH false
COPY ["${PLATFORM_JAR}", "/"]

View File

@ -1,102 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.iqser.red</groupId>
<artifactId>platform-dependency</artifactId>
<version>2.2.0</version>
<relativePath/>
</parent>
<groupId>com.iqser.red.service</groupId>
<artifactId>redaction-report-service-v1</artifactId>
<version>4.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>redaction-report-service-api-v1</module>
<module>redaction-report-service-server-v1</module>
</modules>
<properties>
<persistence-service.version>2.229.0</persistence-service.version>
<apache-poi.version>5.2.3</apache-poi.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.iqser.red</groupId>
<artifactId>platform-commons-dependency</artifactId>
<version>2.7.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.9.1.2184</version>
</plugin>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>8.1.2</version>
<configuration>
<format>ALL</format>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report-aggregate</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,31 @@
plugins {
id("com.iqser.red.service.java-conventions")
id("io.freefair.lombok") version "8.4"
}
description = "redaction-report-service-api-v1"
val persistenceServiceVersion = "2.236.0"
dependencies {
implementation("io.github.openfeign:feign-core:12.2")
implementation("org.springframework:spring-web:6.0.6")
implementation("com.iqser.red.service:persistence-service-internal-api-v1:${persistenceServiceVersion}")
}
publishing {
publications {
create<MavenPublication>(name) {
from(components["java"])
}
}
repositories {
maven {
url = uri("https://nexus.knecon.com/repository/red-platform-releases/")
credentials {
username = providers.gradleProperty("mavenUser").getOrNull();
password = providers.gradleProperty("mavenPassword").getOrNull();
}
}
}
}

View File

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.iqser.red.service</groupId>
<artifactId>redaction-report-service-v1</artifactId>
<version>4.0-SNAPSHOT</version>
</parent>
<artifactId>redaction-report-service-api-v1</artifactId>
<dependencies>
<dependency>
<!-- This dependency contains annotations that are used in specifying REST endpoints. -->
<!-- It is optional since not all users of this API might use Feign. -->
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
<optional>true</optional>
</dependency>
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>com.iqser.red.service</groupId>
<artifactId>persistence-service-internal-api-v1</artifactId>
<version>${persistence-service.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessors>
<annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
</annotationProcessors>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,73 @@
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage
plugins {
application
id("com.iqser.red.service.java-conventions")
id("org.springframework.boot") version "3.0.4"
id("io.spring.dependency-management") version "1.1.0"
id("org.sonarqube") version "4.2.1.3168"
id("io.freefair.lombok") version "8.1.0"
}
description = "redaction-service-server-v1"
val tenantCommonVersion = "0.10.0"
val springCommonsVersion = "2.1.0"
val storageCommonsVersion = "2.27.0"
val poiVersion = "5.2.3"
val metricCommonsVersion = "2.1.0"
val persistenceServiceVersion = "2.236.0"
configurations {
all {
exclude(group = "org.springframework.boot", module = "spring-boot-starter-logging")
}
}
description = "redaction-report-service-server-v1"
dependencies {
implementation(project(":redaction-report-service-api-v1"))
implementation("com.knecon.fforesight:tenant-commons:${tenantCommonVersion}")
implementation("com.iqser.red:platform-commons-dependency:2.7.0")
implementation("com.iqser.red.commons:storage-commons:${storageCommonsVersion}")
implementation("com.iqser.red.commons:spring-commons:${springCommonsVersion}")
implementation("com.iqser.red.commons:metric-commons:${metricCommonsVersion}")
implementation("com.iqser.red.service:persistence-service-internal-api-v1:${persistenceServiceVersion}")
implementation("org.apache.poi:poi:${poiVersion}")
implementation("org.apache.poi:poi-ooxml:${poiVersion}")
implementation("org.apache.poi:poi-scratchpad:${poiVersion}")
implementation("org.springframework.boot:spring-boot-starter-amqp:3.0.4")
implementation("org.springframework.boot:spring-boot-starter-test:3.0.4") {
exclude("org.springframework.boot:spring-boot-starter-tomcat:3.0.4")
}
implementation("org.springframework.cloud:spring-cloud-starter-openfeign:4.0.1")
implementation("org.apache.commons:commons-lang3:3.12.0")
testImplementation("com.iqser.red.commons:test-commons:2.1.0")
testImplementation("org.springframework.amqp:spring-rabbit-test:3.0.6")
}
tasks.named<BootBuildImage>("bootBuildImage") {
imageName.set("nexus.knecon.com:5001/red/${project.name}:${project.version}")
if (project.hasProperty("buildbootDockerHostNetwork")) {
network.set("host")
}
docker {
if (project.hasProperty("buildbootDockerHostNetwork")) {
bindHostToBuilder.set(true)
}
verboseLogging.set(true)
publishRegistry {
username.set(providers.gradleProperty("mavenUser").getOrNull())
password.set(providers.gradleProperty("mavenPassword").getOrNull())
email.set(providers.gradleProperty("mavenEmail").getOrNull())
url.set("https://nexus.knecon.com:5001/")
}
}
}

View File

@ -1,153 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.iqser.red.service</groupId>
<artifactId>redaction-report-service-v1</artifactId>
<version>4.0-SNAPSHOT</version>
</parent>
<artifactId>redaction-report-service-server-v1</artifactId>
<properties>
<tennat-commons.version>0.10.0</tennat-commons.version>
</properties>
<dependencies>
<dependency>
<groupId>com.knecon.fforesight</groupId>
<artifactId>tenant-commons</artifactId>
<version>${tennat-commons.version}</version>
</dependency>
<dependency>
<groupId>com.iqser.red.service</groupId>
<artifactId>redaction-report-service-api-v1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${apache-poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${apache-poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>${apache-poi.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>com.iqser.red.commons</groupId>
<artifactId>storage-commons</artifactId>
</dependency>
<dependency>
<groupId>com.iqser.red.commons</groupId>
<artifactId>spring-commons</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>com.iqser.red.commons</groupId>
<artifactId>metric-commons</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.iqser.red.service</groupId>
<artifactId>persistence-service-internal-api-v1</artifactId>
<version>${persistence-service.version}</version>
</dependency>
<dependency>
<groupId>com.iqser.red.commons</groupId>
<artifactId>test-commons</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessors>
<annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
</annotationProcessors>
</configuration>
</plugin>
<plugin>
<!-- generate git.properties for exposure in /info -->
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<gitDescribe>
<tags>true</tags>
</gitDescribe>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- repackages the generated jar into a runnable fat-jar and makes it
executable -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<executable>true</executable>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@ -189,7 +190,7 @@ public class EntityLogConverterService {
StringBuilder stringBuilder = new StringBuilder();
Matcher match = Pattern.compile("([a-z])([a-z]*)", Pattern.CASE_INSENSITIVE).matcher(str);
while (match.find()) {
match.appendReplacement(stringBuilder, match.group(1).toUpperCase() + match.group(2));
match.appendReplacement(stringBuilder, match.group(1).toUpperCase(Locale.getDefault()) + match.group(2));
}
return match.appendTail(stringBuilder).toString();

View File

@ -139,9 +139,9 @@ public class PlaceholderService {
private Set<String> findExcelPlaceholders(byte[] template, Set<String> allPlaceholders) {
try (ByteArrayInputStream is = new ByteArrayInputStream(template)) {
Set<String> resultPlaceholders = new HashSet<>();
XSSFWorkbook workbook = new XSSFWorkbook(is);
Set<String> resultPlaceholders = new HashSet<>();
try (ByteArrayInputStream is = new ByteArrayInputStream(template);
XSSFWorkbook workbook = new XSSFWorkbook(is)) {
loop:
for (Sheet sheet : workbook) {
@ -162,7 +162,6 @@ public class PlaceholderService {
}
return resultPlaceholders;
} catch (IOException e) {
throw new RuntimeException("An error occurred while parsing excel sheet", e);
}
@ -174,8 +173,8 @@ public class PlaceholderService {
Set<String> resultPlaceholders = new HashSet<>();
try (ByteArrayInputStream is = new ByteArrayInputStream(template)) {
XWPFDocument doc = new XWPFDocument(is);
try (ByteArrayInputStream is = new ByteArrayInputStream(template);
XWPFDocument doc = new XWPFDocument(is)) {
for (XWPFParagraph p : doc.getParagraphs()) {
contains(allPlaceholders, resultPlaceholders, p.getText());

View File

@ -90,7 +90,7 @@ public class RSSPoc2Service {
private final Map<Pair, String> guidelineMapping = new HashMap<>();
private final FileAttributesConfigClient fileAttributesClient;
private final List<SimpleDateFormat> formats = new ArrayList<>();
private final DateFormat resultDateFormat = new SimpleDateFormat("dd/MM/yyyy");
private final DateFormat resultDateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
@PostConstruct

View File

@ -36,7 +36,7 @@ import lombok.SneakyThrows;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
@SuppressWarnings("ALL")
@SuppressWarnings("PMD")
@Slf4j
@Service
@RequiredArgsConstructor

View File

@ -3,6 +3,7 @@ package com.iqser.red.service.redaction.report.v1.server.service;
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.FORMAT_DATE_ISO;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.List;
@ -38,68 +39,72 @@ public class StatusReportGenerationService {
List<FileAttributeConfig> fileAttributeConfigs = fileAttributesClient.getFileAttributeConfigs(dossier.getDossierTemplateId());
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet(dossier.getDossierName());
try (XSSFWorkbook workbook = new XSSFWorkbook()){
XSSFSheet sheet = workbook.createSheet(dossier.getDossierName());
XSSFFont font = workbook.createFont();
font.setBold(true);
XSSFCellStyle style = workbook.createCellStyle();
style.setFont(font);
addHeader(sheet, style);
XSSFFont font = workbook.createFont();
font.setBold(true);
XSSFCellStyle style = workbook.createCellStyle();
style.setFont(font);
addHeader(sheet, style);
XSSFRow headerRow = sheet.getRow(0);
int headerCounter = 5;
Map<String, Integer> attributesAssignment = new HashMap<>();
for (FileAttributeConfig fileAttributeConfig : fileAttributeConfigs) {
sheet.autoSizeColumn(headerCounter);
attributesAssignment.put(fileAttributeConfig.getId(), headerCounter);
XSSFCell cell = headerRow.createCell(headerCounter++);
cell.setCellValue(fileAttributeConfig.getLabel());
cell.setCellStyle(style);
}
XSSFRow headerRow = sheet.getRow(0);
int headerCounter = 5;
Map<String, Integer> attributesAssignment = new HashMap<>();
for (FileAttributeConfig fileAttributeConfig : fileAttributeConfigs) {
sheet.autoSizeColumn(headerCounter);
attributesAssignment.put(fileAttributeConfig.getId(), headerCounter);
XSSFCell cell = headerRow.createCell(headerCounter++);
cell.setCellValue(fileAttributeConfig.getLabel());
cell.setCellStyle(style);
}
for (int i = 0; i < fileStatuses.size(); i++) {
for (int i = 0; i < fileStatuses.size(); i++) {
var fileStatus = fileStatuses.get(i);
var fileStatus = fileStatuses.get(i);
String name = fileStatus.getFilename();
OffsetDateTime uploadDate = fileStatus.getLastUploaded();
String assignedTo = fileStatus.getAssignee();
var status = fileStatus.getWorkflowStatus();
int pages = fileStatus.getNumberOfPages();
var fileAttributes = fileStatus.getFileAttributes();
String name = fileStatus.getFilename();
OffsetDateTime uploadDate = fileStatus.getLastUploaded();
String assignedTo = fileStatus.getAssignee();
var status = fileStatus.getWorkflowStatus();
int pages = fileStatus.getNumberOfPages();
var fileAttributes = fileStatus.getFileAttributes();
XSSFRow row = sheet.createRow(i + 1);
XSSFRow row = sheet.createRow(i + 1);
XSSFCell cellName = row.createCell(0);
cellName.setCellValue(name);
XSSFCell cellUploadDate = row.createCell(1);
cellUploadDate.setCellValue(uploadDate.format(FORMAT_DATE_ISO));
XSSFCell cellAssignedTo = row.createCell(2);
cellAssignedTo.setCellValue(assignedTo);
XSSFCell cellStatus = row.createCell(3);
cellStatus.setCellValue(status.name());
XSSFCell cellPages = row.createCell(4);
cellPages.setCellValue(pages);
XSSFCell cellName = row.createCell(0);
cellName.setCellValue(name);
XSSFCell cellUploadDate = row.createCell(1);
cellUploadDate.setCellValue(uploadDate.format(FORMAT_DATE_ISO));
XSSFCell cellAssignedTo = row.createCell(2);
cellAssignedTo.setCellValue(assignedTo);
XSSFCell cellStatus = row.createCell(3);
cellStatus.setCellValue(status.name());
XSSFCell cellPages = row.createCell(4);
cellPages.setCellValue(pages);
sheet.autoSizeColumn(0);
sheet.autoSizeColumn(1);
sheet.autoSizeColumn(2);
sheet.autoSizeColumn(3);
sheet.autoSizeColumn(4);
sheet.autoSizeColumn(0);
sheet.autoSizeColumn(1);
sheet.autoSizeColumn(2);
sheet.autoSizeColumn(3);
sheet.autoSizeColumn(4);
for (Map.Entry<String, String> nextElement : fileAttributes.entrySet()) {
if (attributesAssignment.get(nextElement.getKey()) != null) {
XSSFCell cell = row.createCell(attributesAssignment.get(nextElement.getKey()));
cell.setCellValue(nextElement.getValue());
sheet.autoSizeColumn(attributesAssignment.get(nextElement.getKey()));
}
for (Map.Entry<String, String> nextElement : fileAttributes.entrySet()) {
if (attributesAssignment.get(nextElement.getKey()) != null) {
XSSFCell cell = row.createCell(attributesAssignment.get(nextElement.getKey()));
cell.setCellValue(nextElement.getValue());
sheet.autoSizeColumn(attributesAssignment.get(nextElement.getKey()));
}
}
byte[] bytes = toByteArray(workbook);
return bytes;
} catch (IOException e) {
throw new RuntimeException();
}
return toByteArray(workbook);
}

View File

@ -242,7 +242,7 @@ public class WordReportGenerationService {
replacePlaceholderInParagraphAndSplit(doc.getParagraphs(), placeHolderValueMap, doc);
for (XWPFTable tbl : doc.getTables()) {
if (tableToSkip == tbl) {
if (tableToSkip.equals(tbl)) {
// already processed for entityLog Entries
continue;
}

View File

@ -2,13 +2,11 @@ package com.iqser.red.service.redaction.report.v1.server.storage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@ -50,24 +48,21 @@ public class ReportStorageService {
public byte[] getReportTemplate(String storageId) {
try {
InputStream inputStream = getObject(TenantContext.getTenantId(), storageId);
byte[] storedObjectBytes = IOUtils.toByteArray(inputStream);
inputStream.close();
return storedObjectBytes;
try (InputStream inputStream = getObject(TenantContext.getTenantId(), storageId)){
return IOUtils.toByteArray(inputStream);
} catch (IOException e) {
throw new RuntimeException("Could not get report template.");
}
}
@SneakyThrows
public byte[] getStoredObjectBytes(String dossierId, String fileId, FileType fileType) {
InputStream inputStream = getObject(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, fileType));
byte[] storedObjectBytes = IOUtils.toByteArray(inputStream);
inputStream.close();
return storedObjectBytes;
try (InputStream inputStream = getObject(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, fileType))) {
return IOUtils.toByteArray(inputStream);
} catch (IOException e) {
throw new RuntimeException(String.format("Could not get stored object for dossierId: %s, fileId: %s, fileType: %s.", dossierId, fileId, fileType));
}
}

View File

@ -78,6 +78,7 @@ import lombok.SneakyThrows;
@EnableAutoConfiguration(exclude = {/*StorageAutoConfiguration.class,*/RabbitAutoConfiguration.class})
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = StorageAutoConfiguration.class)})
@SuppressWarnings("PMD")
public class RedactionReportIntegrationTest {
@MockBean

5
settings.gradle.kts Normal file
View File

@ -0,0 +1,5 @@
rootProject.name = "redaction-report-service"
include(":redaction-report-service-server-v1")
include(":redaction-report-service-api-v1")
project(":redaction-report-service-server-v1").projectDir = file("redaction-report-service-v1/redaction-report-service-server-v1")
project(":redaction-report-service-api-v1").projectDir = file("redaction-report-service-v1/redaction-report-service-api-v1")