RED-5232: Reformatted whole project with new style

This commit is contained in:
Philipp Schramm 2022-10-10 15:03:26 +02:00
parent 2a933fb2d7
commit e60a312cb6
49 changed files with 770 additions and 360 deletions

View File

@ -1,4 +1,5 @@
# Changelog # Changelog
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## [Unreleased] ## [Unreleased]

View File

@ -1,4 +1,4 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <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/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -40,6 +40,7 @@ public class PlanSpec {
private static final String SERVICE_KEY = SERVICE_NAME.toUpperCase().replaceAll("-", ""); private static final String SERVICE_KEY = SERVICE_NAME.toUpperCase().replaceAll("-", "");
/** /**
* Run main to publish plan on Bamboo * Run main to publish plan on Bamboo
*/ */
@ -58,9 +59,15 @@ public class PlanSpec {
bambooServer.publish(secPlanPermission); bambooServer.publish(secPlanPermission);
} }
private PlanPermissions createPlanPermission(PlanIdentifier planIdentifier) { private PlanPermissions createPlanPermission(PlanIdentifier planIdentifier) {
Permissions permission = new Permissions()
.userPermissions("atlbamboo", PermissionType.EDIT, PermissionType.VIEW, PermissionType.ADMIN, PermissionType.CLONE, PermissionType.BUILD) Permissions permission = new Permissions().userPermissions("atlbamboo",
PermissionType.EDIT,
PermissionType.VIEW,
PermissionType.ADMIN,
PermissionType.CLONE,
PermissionType.BUILD)
.groupPermissions("development", PermissionType.EDIT, PermissionType.VIEW, PermissionType.CLONE, PermissionType.BUILD) .groupPermissions("development", PermissionType.EDIT, PermissionType.VIEW, PermissionType.CLONE, PermissionType.BUILD)
.groupPermissions("devplant", PermissionType.EDIT, PermissionType.VIEW, PermissionType.CLONE, PermissionType.BUILD) .groupPermissions("devplant", PermissionType.EDIT, PermissionType.VIEW, PermissionType.CLONE, PermissionType.BUILD)
.loggedInUserPermissions(PermissionType.VIEW) .loggedInUserPermissions(PermissionType.VIEW)
@ -68,104 +75,52 @@ public class PlanSpec {
return new PlanPermissions(planIdentifier.getProjectKey(), planIdentifier.getPlanKey()).permissions(permission); return new PlanPermissions(planIdentifier.getProjectKey(), planIdentifier.getPlanKey()).permissions(permission);
} }
private Project project() { private Project project() {
return new Project()
.name("RED") return new Project().name("RED").key(new BambooKey("RED"));
.key(new BambooKey("RED"));
} }
public Plan createPlan() { public Plan createPlan() {
return new Plan(
project(), return new Plan(project(), SERVICE_NAME, new BambooKey(SERVICE_KEY)).description("Plan created from (enter repository url of your plan)")
SERVICE_NAME, new BambooKey(SERVICE_KEY))
.description("Plan created from (enter repository url of your plan)")
.variables(new Variable("maven_add_param", "")) .variables(new Variable("maven_add_param", ""))
.stages(new Stage("Default Stage") .stages(new Stage("Default Stage").jobs(new Job("Default Job", new BambooKey("JOB1")).tasks(new ScriptTask().description("Clean")
.jobs(new Job("Default Job", .inlineBody("#!/bin/bash\n" + "set -e\n" + "rm -rf ./*"),
new BambooKey("JOB1")) new VcsCheckoutTask().description("Checkout Default Repository").cleanCheckout(true).checkoutItems(new CheckoutItem().defaultRepository()),
.tasks( new ScriptTask().description("Build").location(Location.FILE).fileFromPath("bamboo-specs/src/main/resources/scripts/build-java.sh").argument(SERVICE_NAME),
new ScriptTask() createJUnitParserTask().description("Resultparser")
.description("Clean") .resultDirectories("**/test-reports/*.xml, **/target/surefire-reports/*.xml, **/target/failsafe-reports/*.xml")
.inlineBody("#!/bin/bash\n" + .enabled(true),
"set -e\n" + new InjectVariablesTask().description("Inject git Tag").path("git.tag").namespace("g").scope(InjectVariablesScope.LOCAL),
"rm -rf ./*"), new VcsTagTask().description("${bamboo.g.gitTag}").tagName("${bamboo.g.gitTag}").defaultRepository())
new VcsCheckoutTask() .dockerConfiguration(new DockerConfiguration().image("nexus.iqser.com:5001/infra/maven:3.8.4-openjdk-17-slim")
.description("Checkout Default Repository") .volume("/etc/maven/settings.xml", "/usr/share/maven/conf/settings.xml")
.cleanCheckout(true) .volume("/var/run/docker.sock", "/var/run/docker.sock"))))
.checkoutItems(new CheckoutItem().defaultRepository()),
new ScriptTask()
.description("Build")
.location(Location.FILE)
.fileFromPath("bamboo-specs/src/main/resources/scripts/build-java.sh")
.argument(SERVICE_NAME),
createJUnitParserTask()
.description("Resultparser")
.resultDirectories("**/test-reports/*.xml, **/target/surefire-reports/*.xml, **/target/failsafe-reports/*.xml")
.enabled(true),
new InjectVariablesTask()
.description("Inject git Tag")
.path("git.tag")
.namespace("g")
.scope(InjectVariablesScope.LOCAL),
new VcsTagTask()
.description("${bamboo.g.gitTag}")
.tagName("${bamboo.g.gitTag}")
.defaultRepository())
.dockerConfiguration(
new DockerConfiguration()
.image("nexus.iqser.com:5001/infra/maven:3.8.4-openjdk-17-slim")
.volume("/etc/maven/settings.xml", "/usr/share/maven/conf/settings.xml")
.volume("/var/run/docker.sock", "/var/run/docker.sock")
)
)
)
.linkedRepositories("RED / " + SERVICE_NAME) .linkedRepositories("RED / " + SERVICE_NAME)
.triggers(new BitbucketServerTrigger()) .triggers(new BitbucketServerTrigger())
.planBranchManagement(new PlanBranchManagement() .planBranchManagement(new PlanBranchManagement().createForVcsBranch()
.createForVcsBranch() .delete(new BranchCleanup().whenInactiveInRepositoryAfterDays(14))
.delete(new BranchCleanup()
.whenInactiveInRepositoryAfterDays(14))
.notificationForCommitters()); .notificationForCommitters());
} }
public Plan createSecBuild() { public Plan createSecBuild() {
return new Plan(
project(), return new Plan(project(), SERVICE_NAME + "-Sec", new BambooKey(SERVICE_KEY + "SEC")).description("Security Analysis Plan")
SERVICE_NAME + "-Sec", new BambooKey(SERVICE_KEY + "SEC")) .stages(new Stage("Default Stage").jobs(new Job("Default Job", new BambooKey("JOB1")).tasks(new ScriptTask().description("Clean")
.description("Security Analysis Plan") .inlineBody("#!/bin/bash\n" + "set -e\n" + "rm -rf ./*"),
.stages(new Stage("Default Stage") new VcsCheckoutTask().description("Checkout Default Repository").cleanCheckout(true).checkoutItems(new CheckoutItem().defaultRepository()),
.jobs(new Job("Default Job", new ScriptTask().description("Sonar").location(Location.FILE).fileFromPath("bamboo-specs/src/main/resources/scripts/sonar-java.sh").argument(SERVICE_NAME))
new BambooKey("JOB1")) .dockerConfiguration(new DockerConfiguration().image("nexus.iqser.com:5001/infra/maven:3.8.4-openjdk-17-slim")
.tasks( .volume("/etc/maven/settings.xml", "/usr/share/maven/conf/settings.xml")
new ScriptTask() .dockerRunArguments("--net=host")
.description("Clean") .volume("/var/run/docker.sock", "/var/run/docker.sock"))))
.inlineBody("#!/bin/bash\n" +
"set -e\n" +
"rm -rf ./*"),
new VcsCheckoutTask()
.description("Checkout Default Repository")
.cleanCheckout(true)
.checkoutItems(new CheckoutItem().defaultRepository()),
new ScriptTask()
.description("Sonar")
.location(Location.FILE)
.fileFromPath("bamboo-specs/src/main/resources/scripts/sonar-java.sh")
.argument(SERVICE_NAME))
.dockerConfiguration(
new DockerConfiguration()
.image("nexus.iqser.com:5001/infra/maven:3.8.4-openjdk-17-slim")
.volume("/etc/maven/settings.xml", "/usr/share/maven/conf/settings.xml")
.dockerRunArguments("--net=host")
.volume("/var/run/docker.sock", "/var/run/docker.sock")
)
)
)
.linkedRepositories("RED / " + SERVICE_NAME) .linkedRepositories("RED / " + SERVICE_NAME)
.triggers( .triggers(new ScheduledTrigger().scheduleOnceDaily(LocalTime.of(23, 00)))
new ScheduledTrigger() .planBranchManagement(new PlanBranchManagement().createForVcsBranchMatching("release.*").notificationForCommitters());
.scheduleOnceDaily(LocalTime.of(23, 00)))
.planBranchManagement(new PlanBranchManagement()
.createForVcsBranchMatching("release.*")
.notificationForCommitters());
} }
} }

View File

@ -1,6 +1,5 @@
package buildjob; package buildjob;
import org.junit.Test; import org.junit.Test;
import com.atlassian.bamboo.specs.api.builders.plan.Plan; import com.atlassian.bamboo.specs.api.builders.plan.Plan;

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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"> 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> <modelVersion>4.0.0</modelVersion>

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<groupId>com.iqser.red</groupId> <groupId>com.iqser.red</groupId>
<artifactId>platform-docker-dependency</artifactId> <artifactId>platform-docker-dependency</artifactId>
<version>1.2.0</version> <version>1.2.0</version>
<relativePath /> <relativePath/>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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"> 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> <modelVersion>4.0.0</modelVersion>
@ -8,7 +8,7 @@
<groupId>com.iqser.red</groupId> <groupId>com.iqser.red</groupId>
<artifactId>platform-dependency</artifactId> <artifactId>platform-dependency</artifactId>
<version>1.10.0</version> <version>1.10.0</version>
<relativePath /> <relativePath/>
</parent> </parent>
<groupId>com.iqser.red.service</groupId> <groupId>com.iqser.red.service</groupId>
@ -48,7 +48,7 @@
<groupId>org.sonarsource.scanner.maven</groupId> <groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId> <artifactId>sonar-maven-plugin</artifactId>
<version>3.9.0.2155</version> <version>3.9.0.2155</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.owasp</groupId> <groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId> <artifactId>dependency-check-maven</artifactId>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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"> 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> <modelVersion>4.0.0</modelVersion>

View File

@ -1,15 +1,15 @@
package com.iqser.red.service.redaction.report.v1.api.model; package com.iqser.red.service.redaction.report.v1.api.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data @Data
@Builder @Builder
@AllArgsConstructor @AllArgsConstructor

View File

@ -1,6 +1,7 @@
package com.iqser.red.service.redaction.report.v1.api.model; package com.iqser.red.service.redaction.report.v1.api.model;
import com.dslplatform.json.CompiledJson; import com.dslplatform.json.CompiledJson;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;

View File

@ -1,11 +1,11 @@
package com.iqser.red.service.redaction.report.v1.api.resource; package com.iqser.red.service.redaction.report.v1.api.resource;
import java.util.List;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import java.util.List;
public interface PlaceholderResource { public interface PlaceholderResource {
String PLACEHOLDERS_PATH = "/placeholders"; String PLACEHOLDERS_PATH = "/placeholders";
@ -17,11 +17,12 @@ public interface PlaceholderResource {
String REPORT_TEMPLATE_ID_PATH_VARIABLE = "/report-template-id/{" + REPORT_TEMPLATE_ID + "}"; String REPORT_TEMPLATE_ID_PATH_VARIABLE = "/report-template-id/{" + REPORT_TEMPLATE_ID + "}";
String PLACEHOLDER_PATH_VARIABLE = "/placeholder/{" + PLACEHOLDER + "}"; String PLACEHOLDER_PATH_VARIABLE = "/placeholder/{" + PLACEHOLDER + "}";
@GetMapping(value = PLACEHOLDERS_PATH, produces = MediaType.APPLICATION_JSON_VALUE) @GetMapping(value = PLACEHOLDERS_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
List<String> getPlaceholders(); List<String> getPlaceholders();
@GetMapping(value = PLACEHOLDERS_PATH + DOSSIER_TEMPLATE_ID_PATH_VARIABLE + REPORT_TEMPLATE_ID_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE) @GetMapping(value = PLACEHOLDERS_PATH + DOSSIER_TEMPLATE_ID_PATH_VARIABLE + REPORT_TEMPLATE_ID_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
List<String> getPlaceholdersOfTemplate(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId, List<String> getPlaceholdersOfTemplate(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId, @PathVariable(REPORT_TEMPLATE_ID) String reportTemplateId);
@PathVariable(REPORT_TEMPLATE_ID) String reportTemplateId);
} }

View File

@ -19,7 +19,6 @@ public interface RSSResource {
@GetMapping(value = RSS_PATH + DOSSIER_ID_PATH_VARIABLE, produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE}) @GetMapping(value = RSS_PATH + DOSSIER_ID_PATH_VARIABLE, produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
RSSResponse getRSS(@PathVariable(DOSSIER_ID) String dossierId, RSSResponse getRSS(@PathVariable(DOSSIER_ID) String dossierId, @RequestParam(value = "fileId", required = false) String fileId);
@RequestParam(value = "fileId", required = false) String fileId);
} }

View File

@ -1,13 +1,14 @@
package com.iqser.red.service.redaction.report.v1.api.resource; package com.iqser.red.service.redaction.report.v1.api.resource;
import com.iqser.red.service.persistence.service.v1.api.model.common.JSONPrimitive; import java.util.List;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.ReportTemplate;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import java.util.List; import com.iqser.red.service.persistence.service.v1.api.model.common.JSONPrimitive;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.ReportTemplate;
public interface ReportTemplateResource { public interface ReportTemplateResource {
@ -17,8 +18,8 @@ public interface ReportTemplateResource {
String DOSSIER_TEMPLATE_ID_PATH_VARIABLE = "/dossier-template-id/{" + DOSSIER_TEMPLATE_ID + "}"; String DOSSIER_TEMPLATE_ID_PATH_VARIABLE = "/dossier-template-id/{" + DOSSIER_TEMPLATE_ID + "}";
@PostMapping(value = REPORT_TEMPLATE_PATH + DOSSIER_TEMPLATE_ID_PATH_VARIABLE, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = REPORT_TEMPLATE_PATH + DOSSIER_TEMPLATE_ID_PATH_VARIABLE, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
List<ReportTemplate> getReportTemplatesByPlaceholder(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId, List<ReportTemplate> getReportTemplatesByPlaceholder(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId, @RequestBody JSONPrimitive<String> placeholder);
@RequestBody JSONPrimitive<String> placeholder);
} }

View File

@ -1,10 +1,11 @@
package com.iqser.red.service.redaction.report.v1.api.resource; package com.iqser.red.service.redaction.report.v1.api.resource;
import com.iqser.red.service.redaction.report.v1.api.model.StatusReportResponse;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import com.iqser.red.service.redaction.report.v1.api.model.StatusReportResponse;
public interface StatusReportResource { public interface StatusReportResource {
String STATUS_REPORT = "/statusReport"; String STATUS_REPORT = "/statusReport";

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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"> 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> <modelVersion>4.0.0</modelVersion>

View File

@ -1,10 +1,5 @@
package com.iqser.red.service.redaction.report.v1.server; package com.iqser.red.service.redaction.report.v1.server;
import com.iqser.red.commons.spring.DefaultWebMvcConfiguration;
import com.iqser.red.service.redaction.report.v1.server.client.DossierClient;
import com.iqser.red.service.redaction.report.v1.server.configuration.MessagingConfiguration;
import com.iqser.red.service.redaction.report.v1.server.settings.ReportTemplateSettings;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -15,6 +10,11 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import com.iqser.red.commons.spring.DefaultWebMvcConfiguration;
import com.iqser.red.service.redaction.report.v1.server.client.DossierClient;
import com.iqser.red.service.redaction.report.v1.server.configuration.MessagingConfiguration;
import com.iqser.red.service.redaction.report.v1.server.settings.ReportTemplateSettings;
import io.micrometer.core.aop.TimedAspect; import io.micrometer.core.aop.TimedAspect;
import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.MeterRegistry;
@ -35,8 +35,10 @@ public class Application {
SpringApplication.run(Application.class, args); SpringApplication.run(Application.class, args);
} }
@Bean @Bean
public TimedAspect timedAspect(MeterRegistry registry) { public TimedAspect timedAspect(MeterRegistry registry) {
return new TimedAspect(registry); return new TimedAspect(registry);
} }

View File

@ -1,9 +1,10 @@
package com.iqser.red.service.redaction.report.v1.server.client; package com.iqser.red.service.redaction.report.v1.server.client;
import org.springframework.cloud.openfeign.FeignClient;
import com.iqser.red.service.persistence.service.v1.api.resources.DossierAttributesResource; import com.iqser.red.service.persistence.service.v1.api.resources.DossierAttributesResource;
import org.springframework.cloud.openfeign.FeignClient;
@FeignClient(name = "DossierAttributesResource", url = "${persistence-service.url}") @FeignClient(name = "DossierAttributesResource", url = "${persistence-service.url}")
public interface DossierAttributesClient extends DossierAttributesResource { public interface DossierAttributesClient extends DossierAttributesResource {
} }

View File

@ -1,8 +1,10 @@
package com.iqser.red.service.redaction.report.v1.server.client; package com.iqser.red.service.redaction.report.v1.server.client;
import com.iqser.red.service.persistence.service.v1.api.resources.DossierAttributesConfigResource;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import com.iqser.red.service.persistence.service.v1.api.resources.DossierAttributesConfigResource;
@FeignClient(name = "DossierAttributesConfigResource", url = "${persistence-service.url}") @FeignClient(name = "DossierAttributesConfigResource", url = "${persistence-service.url}")
public interface DossierAttributesConfigClient extends DossierAttributesConfigResource { public interface DossierAttributesConfigClient extends DossierAttributesConfigResource {
} }

View File

@ -1,8 +1,9 @@
package com.iqser.red.service.redaction.report.v1.server.client; package com.iqser.red.service.redaction.report.v1.server.client;
import com.iqser.red.service.persistence.service.v1.api.resources.DossierResource;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import com.iqser.red.service.persistence.service.v1.api.resources.DossierResource;
@FeignClient(name = "DossierResource", url = "${persistence-service.url}") @FeignClient(name = "DossierResource", url = "${persistence-service.url}")
public interface DossierClient extends DossierResource { public interface DossierClient extends DossierResource {

View File

@ -1,8 +1,10 @@
package com.iqser.red.service.redaction.report.v1.server.client; package com.iqser.red.service.redaction.report.v1.server.client;
import com.iqser.red.service.persistence.service.v1.api.resources.FileAttributesConfigResource;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import com.iqser.red.service.persistence.service.v1.api.resources.FileAttributesConfigResource;
@FeignClient(name = "FileAttributesResource", url = "${persistence-service.url}") @FeignClient(name = "FileAttributesResource", url = "${persistence-service.url}")
public interface FileAttributesConfigClient extends FileAttributesConfigResource { public interface FileAttributesConfigClient extends FileAttributesConfigResource {
} }

View File

@ -1,8 +1,9 @@
package com.iqser.red.service.redaction.report.v1.server.client; package com.iqser.red.service.redaction.report.v1.server.client;
import com.iqser.red.service.persistence.service.v1.api.resources.StatusResource;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import com.iqser.red.service.persistence.service.v1.api.resources.StatusResource;
@FeignClient(name = "StatusResource", url = "${persistence-service.url}") @FeignClient(name = "StatusResource", url = "${persistence-service.url}")
public interface FileStatusClient extends StatusResource { public interface FileStatusClient extends StatusResource {

View File

@ -1,8 +1,10 @@
package com.iqser.red.service.redaction.report.v1.server.client; package com.iqser.red.service.redaction.report.v1.server.client;
import com.iqser.red.service.persistence.service.v1.api.resources.RedactionLogResource;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import com.iqser.red.service.persistence.service.v1.api.resources.RedactionLogResource;
@FeignClient(name = "RedactionLogResource", url = "${persistence-service.url}") @FeignClient(name = "RedactionLogResource", url = "${persistence-service.url}")
public interface RedactionLogClient extends RedactionLogResource { public interface RedactionLogClient extends RedactionLogResource {
} }

View File

@ -1,8 +1,9 @@
package com.iqser.red.service.redaction.report.v1.server.client; package com.iqser.red.service.redaction.report.v1.server.client;
import com.iqser.red.service.persistence.service.v1.api.resources.ReportTemplateResource;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import com.iqser.red.service.persistence.service.v1.api.resources.ReportTemplateResource;
@FeignClient(name = "ReportTemplateResource", url = "${persistence-service.url}") @FeignClient(name = "ReportTemplateResource", url = "${persistence-service.url}")
public interface ReportTemplateClient extends ReportTemplateResource { public interface ReportTemplateClient extends ReportTemplateResource {

View File

@ -1,11 +1,12 @@
package com.iqser.red.service.redaction.report.v1.server.configuration; package com.iqser.red.service.redaction.report.v1.server.configuration;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.Queue; import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder; import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import lombok.RequiredArgsConstructor;
@Configuration @Configuration
@RequiredArgsConstructor @RequiredArgsConstructor
public class MessagingConfiguration { public class MessagingConfiguration {
@ -39,10 +40,7 @@ public class MessagingConfiguration {
@Bean @Bean
public Queue reportResultQueue() { public Queue reportResultQueue() {
return QueueBuilder.durable(REPORT_RESULT_QUEUE) return QueueBuilder.durable(REPORT_RESULT_QUEUE).withArgument("x-dead-letter-exchange", "").withArgument("x-dead-letter-routing-key", REPORT_RESULT_DLQ).build();
.withArgument("x-dead-letter-exchange", "")
.withArgument("x-dead-letter-routing-key", REPORT_RESULT_DLQ)
.build();
} }

View File

@ -1,15 +1,17 @@
package com.iqser.red.service.redaction.report.v1.server.controller; package com.iqser.red.service.redaction.report.v1.server.controller;
import com.iqser.red.service.redaction.report.v1.api.resource.PlaceholderResource;
import com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import com.iqser.red.service.redaction.report.v1.api.resource.PlaceholderResource;
import com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequiredArgsConstructor @RequiredArgsConstructor
@ -17,15 +19,16 @@ public class PlaceholderController implements PlaceholderResource {
private final PlaceholderService placeholderService; private final PlaceholderService placeholderService;
@Override @Override
public List<String> getPlaceholders() { public List<String> getPlaceholders() {
return placeholderService.getGeneralPlaceholders(); return placeholderService.getGeneralPlaceholders();
} }
@Override @Override
public List<String> getPlaceholdersOfTemplate(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId, public List<String> getPlaceholdersOfTemplate(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId, @PathVariable(REPORT_TEMPLATE_ID) String reportTemplateId) {
@PathVariable(REPORT_TEMPLATE_ID) String reportTemplateId) {
return new ArrayList<>(placeholderService.getPlaceholdersOfTemplate(dossierTemplateId, reportTemplateId)); return new ArrayList<>(placeholderService.getPlaceholdersOfTemplate(dossierTemplateId, reportTemplateId));
} }

View File

@ -17,8 +17,7 @@ public class RSSController implements RSSResource {
private final RSSService rSSService; private final RSSService rSSService;
public RSSResponse getRSS(@PathVariable(DOSSIER_ID) String dossierId, public RSSResponse getRSS(@PathVariable(DOSSIER_ID) String dossierId, @RequestParam(value = "fileId", required = false) String fileId) {
@RequestParam(value = "fileId", required = false) String fileId) {
return rSSService.getRSS(dossierId, fileId); return rSSService.getRSS(dossierId, fileId);
} }

View File

@ -1,16 +1,18 @@
package com.iqser.red.service.redaction.report.v1.server.controller; package com.iqser.red.service.redaction.report.v1.server.controller;
import java.util.List;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.iqser.red.service.persistence.service.v1.api.model.common.JSONPrimitive; import com.iqser.red.service.persistence.service.v1.api.model.common.JSONPrimitive;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.ReportTemplate; import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.ReportTemplate;
import com.iqser.red.service.redaction.report.v1.api.resource.ReportTemplateResource; import com.iqser.red.service.redaction.report.v1.api.resource.ReportTemplateResource;
import com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService; import com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Slf4j @Slf4j
@RestController @RestController
@ -19,10 +21,11 @@ public class ReportTemplateController implements ReportTemplateResource {
private final PlaceholderService placeholderService; private final PlaceholderService placeholderService;
@Override @Override
public List<ReportTemplate> getReportTemplatesByPlaceholder(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId, public List<ReportTemplate> getReportTemplatesByPlaceholder(@PathVariable(DOSSIER_TEMPLATE_ID) String dossierTemplateId, @RequestBody JSONPrimitive<String> placeholder) {
@RequestBody JSONPrimitive<String> placeholder) {
return placeholderService.getReportTemplatesByPlaceholder(dossierTemplateId, placeholder.getValue()); return placeholderService.getReportTemplatesByPlaceholder(dossierTemplateId, placeholder.getValue());
} }
} }

View File

@ -1,21 +1,22 @@
package com.iqser.red.service.redaction.report.v1.server.controller; package com.iqser.red.service.redaction.report.v1.server.controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.Dossier; import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.Dossier;
import com.iqser.red.service.redaction.report.v1.api.model.StatusReportResponse; import com.iqser.red.service.redaction.report.v1.api.model.StatusReportResponse;
import com.iqser.red.service.redaction.report.v1.api.resource.StatusReportResource; import com.iqser.red.service.redaction.report.v1.api.resource.StatusReportResource;
import com.iqser.red.service.redaction.report.v1.server.client.DossierClient; import com.iqser.red.service.redaction.report.v1.server.client.DossierClient;
import com.iqser.red.service.redaction.report.v1.server.service.StatusReportGenerationService; import com.iqser.red.service.redaction.report.v1.server.service.StatusReportGenerationService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@Slf4j @Slf4j
@RestController @RestController
@RequiredArgsConstructor @RequiredArgsConstructor
public class StatusReportController implements StatusReportResource { public class StatusReportController implements StatusReportResource {
private final StatusReportGenerationService statusReportGenerationService; private final StatusReportGenerationService statusReportGenerationService;
private final DossierClient dossierClient; private final DossierClient dossierClient;
@ -23,7 +24,7 @@ public class StatusReportController implements StatusReportResource {
@Override @Override
public StatusReportResponse generateStatusReport(@PathVariable(DOSSIER_ID) String dossierId) { public StatusReportResponse generateStatusReport(@PathVariable(DOSSIER_ID) String dossierId) {
Dossier dossier = dossierClient.getDossierById(dossierId, true,false); Dossier dossier = dossierClient.getDossierById(dossierId, true, false);
byte[] report = statusReportGenerationService.generateReport(dossier); byte[] report = statusReportGenerationService.generateReport(dossier);
return new StatusReportResponse(report, dossier.getDossierName() + ".xlsx"); return new StatusReportResponse(report, dossier.getDossierName() + ".xlsx");
} }

View File

@ -8,6 +8,8 @@ import lombok.Data;
@Builder @Builder
@AllArgsConstructor @AllArgsConstructor
public class ColoredText { public class ColoredText {
private String text; private String text;
private String color; private String color;
} }

View File

@ -10,4 +10,5 @@ public class ExcelCell {
private Cell cell; private Cell cell;
private int columnWidth; private int columnWidth;
private int rowHeights; private int rowHeights;
} }

View File

@ -29,5 +29,4 @@ public class ExcelModel {
private boolean placeholderInFirstRow; private boolean placeholderInFirstRow;
private boolean firstRowWritten; private boolean firstRowWritten;
} }

View File

@ -6,6 +6,8 @@ import lombok.Data;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
public class ImagePlaceholder { public class ImagePlaceholder {
private String placeholder; private String placeholder;
private byte[] image; private byte[] image;
} }

View File

@ -1,8 +1,9 @@
package com.iqser.red.service.redaction.report.v1.server.model; package com.iqser.red.service.redaction.report.v1.server.model;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
@Data @Data
@AllArgsConstructor @AllArgsConstructor

View File

@ -1,11 +1,11 @@
package com.iqser.red.service.redaction.report.v1.server.model; package com.iqser.red.service.redaction.report.v1.server.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
public class MultiFileWorkbook { public class MultiFileWorkbook {

View File

@ -13,4 +13,5 @@ public class PlaceHolderFunctions {
private Map<Integer, Function<PlaceholderInput, String>> functionPerPlaceHolder; private Map<Integer, Function<PlaceholderInput, String>> functionPerPlaceHolder;
private Set<String> foundPlaceHolder; private Set<String> foundPlaceHolder;
} }

View File

@ -74,10 +74,15 @@ import lombok.extern.slf4j.Slf4j;
@RequiredArgsConstructor @RequiredArgsConstructor
public class ExcelReportGenerationService { public class ExcelReportGenerationService {
@Timed("redactmanager_generateExcelReport") @Timed("redactmanager_generateExcelReport")
public void generateExcelReport(List<ReportRedactionEntry> reportEntries, PlaceholderModel placeholderModel, String reportTemplateName, SXSSFWorkbook workbook, public void generateExcelReport(List<ReportRedactionEntry> reportEntries,
String dossierName, FileModel fileModel, ExcelModel excelModel, boolean isLastFile) { PlaceholderModel placeholderModel,
String reportTemplateName,
SXSSFWorkbook workbook,
String dossierName,
FileModel fileModel,
ExcelModel excelModel,
boolean isLastFile) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
@ -91,25 +96,43 @@ public class ExcelReportGenerationService {
sheet.setColumnWidth(columnWidthEntry.getKey(), columnWidthEntry.getValue()); sheet.setColumnWidth(columnWidthEntry.getKey(), columnWidthEntry.getValue());
} }
addRows(workbook, sheet, excelModel.getCellsToCopyBeforeRedactionPlaceholderRow(), excelModel.isHasRssPlaceHolders() ? excelModel.getWrittenRows() addRows(workbook,
.size() : 0, placeholderModel, dossierName, fileModel.getFilename(), excelModel); sheet,
excelModel.getCellsToCopyBeforeRedactionPlaceholderRow(),
excelModel.isHasRssPlaceHolders() ? excelModel.getWrittenRows().size() : 0,
placeholderModel,
dossierName,
fileModel.getFilename(),
excelModel);
if(!excelModel.isHasRssPlaceHolders()) { if (!excelModel.isHasRssPlaceHolders()) {
excelModel.setRowsBeforeRedactionEntryRowsAdded(true); excelModel.setRowsBeforeRedactionEntryRowsAdded(true);
} }
} }
if(!excelModel.isHasRssPlaceHolders()) { if (!excelModel.isHasRssPlaceHolders()) {
addRedactionEntryRows(sheet, reportEntries, fileModel.getFilename(), excelModel, placeholderModel); addRedactionEntryRows(sheet, reportEntries, fileModel.getFilename(), excelModel, placeholderModel);
} }
if (isLastFile) { if (isLastFile) {
addRows(workbook, sheet, excelModel.getCellsToCopyAfterRedactionPlaceholderRow(), excelModel.getWrittenRows() addRows(workbook,
.size(), placeholderModel, dossierName, fileModel.getFilename(), excelModel); sheet,
excelModel.getCellsToCopyAfterRedactionPlaceholderRow(),
excelModel.getWrittenRows().size(),
placeholderModel,
dossierName,
fileModel.getFilename(),
excelModel);
} }
} }
log.info("Report Generation took: {} for file with id {}, pageCount: {}, redactionLogEntryCount: {}, reportName: {}, className: {}", System.currentTimeMillis() - start, fileModel.getId(), fileModel.getNumberOfPages(), reportEntries.size(), reportTemplateName, getClass().getSimpleName()); log.info("Report Generation took: {} for file with id {}, pageCount: {}, redactionLogEntryCount: {}, reportName: {}, className: {}",
System.currentTimeMillis() - start,
fileModel.getId(),
fileModel.getNumberOfPages(),
reportEntries.size(),
reportTemplateName,
getClass().getSimpleName());
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@ -119,15 +142,21 @@ public class ExcelReportGenerationService {
@SneakyThrows @SneakyThrows
@Timed("redactmanager_excel-addRows") @Timed("redactmanager_excel-addRows")
private void addRows(SXSSFWorkbook workbook, Sheet sheet, Map<CellIdentifier, Cell> copiedCells, int numberOfRowsToShift, PlaceholderModel placeholderModel, String dossierName, private void addRows(SXSSFWorkbook workbook,
String filename, ExcelModel excelModel) { Sheet sheet,
Map<CellIdentifier, Cell> copiedCells,
int numberOfRowsToShift,
PlaceholderModel placeholderModel,
String dossierName,
String filename,
ExcelModel excelModel) {
Set<Integer> createdCopyRows = new HashSet<>(); Set<Integer> createdCopyRows = new HashSet<>();
int skipRows = excelModel.isHasRssPlaceHolders() && excelModel.isFirstRowWritten() && !excelModel.isPlaceholderInFirstRow() ? 1 : 0; int skipRows = excelModel.isHasRssPlaceHolders() && excelModel.isFirstRowWritten() && !excelModel.isPlaceholderInFirstRow() ? 1 : 0;
for (Map.Entry<CellIdentifier, Cell> cellsToCopyEntry : copiedCells.entrySet()) { for (Map.Entry<CellIdentifier, Cell> cellsToCopyEntry : copiedCells.entrySet()) {
if(excelModel.isHasRssPlaceHolders() && cellsToCopyEntry.getKey().getRowIndex() == 0 && excelModel.isFirstRowWritten() && !excelModel.isPlaceholderInFirstRow()){ if (excelModel.isHasRssPlaceHolders() && cellsToCopyEntry.getKey().getRowIndex() == 0 && excelModel.isFirstRowWritten() && !excelModel.isPlaceholderInFirstRow()) {
continue; continue;
} }
@ -190,11 +219,11 @@ public class ExcelReportGenerationService {
columnWidths.put(i, columnWidth); columnWidths.put(i, columnWidth);
String cellStringValue = cell.getStringCellValue(); String cellStringValue = cell.getStringCellValue();
if(j == 0 && cellStringValue.contains("{{")){ if (j == 0 && cellStringValue.contains("{{")) {
placeholderInFirstRow = true; placeholderInFirstRow = true;
} }
if(cellStringValue.contains(RSS_PLACEHOLDER_BASE)){ if (cellStringValue.contains(RSS_PLACEHOLDER_BASE)) {
hasRssPlaceHolders = true; hasRssPlaceHolders = true;
} }
@ -221,7 +250,16 @@ public class ExcelReportGenerationService {
} }
log.debug("Calculate Placeholder Cells took: {}", System.currentTimeMillis() - start); log.debug("Calculate Placeholder Cells took: {}", System.currentTimeMillis() - start);
return new ExcelModel(placeholderCellPos, placeholderRow, columnWidths, cellsToCopyBeforePlaceholderRow, cellsToCopyAfterPlaceholderRow, new ArrayList<>(), false, hasRssPlaceHolders, placeholderInFirstRow, false); return new ExcelModel(placeholderCellPos,
placeholderRow,
columnWidths,
cellsToCopyBeforePlaceholderRow,
cellsToCopyAfterPlaceholderRow,
new ArrayList<>(),
false,
hasRssPlaceHolders,
placeholderInFirstRow,
false);
} }
@ -251,7 +289,12 @@ public class ExcelReportGenerationService {
private boolean containsRedactionPlaceholder(String text) { private boolean containsRedactionPlaceholder(String text) {
return text.startsWith(DOSSIER_ATTRIBUTE_PLACEHOLDER_BASE) || text.startsWith(FILE_ATTRIBUTE_PLACEHOLDER_BASE) || text.contains(FILE_NAME_PLACEHOLDER) || text.contains(PAGE_PLACEHOLDER) || text.contains(PARAGRAPH_PLACEHOLDER) || text.contains(JUSTIFICATION_PLACEHOLDER) || text.contains(EXCERPT_PLACEHOLDER) || text.contains(JUSTIFICATION_PARAGRAPH_PLACEHOLDER) || text.contains(JUSTIFICATION_REASON_PLACEHOLDER) || text.contains(REDACTION_VALUE_PLACEHOLDER) || text.contains(JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER) || text.contains(JUSTIFICATION_TEXT_PLACEHOLDER) || text.contains(SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER) || text.contains(SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER) || text.contains(REDACTION_ENTITY_DISPLAY_NAME_PLACEHOLDER); return text.startsWith(DOSSIER_ATTRIBUTE_PLACEHOLDER_BASE) || text.startsWith(FILE_ATTRIBUTE_PLACEHOLDER_BASE) || text.contains(FILE_NAME_PLACEHOLDER) || text.contains(
PAGE_PLACEHOLDER) || text.contains(PARAGRAPH_PLACEHOLDER) || text.contains(JUSTIFICATION_PLACEHOLDER) || text.contains(EXCERPT_PLACEHOLDER) || text.contains(
JUSTIFICATION_PARAGRAPH_PLACEHOLDER) || text.contains(JUSTIFICATION_REASON_PLACEHOLDER) || text.contains(REDACTION_VALUE_PLACEHOLDER) || text.contains(
JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER) || text.contains(JUSTIFICATION_TEXT_PLACEHOLDER) || text.contains(
SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER) || text.contains(SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER) || text.contains(
REDACTION_ENTITY_DISPLAY_NAME_PLACEHOLDER);
} }
@ -318,8 +361,9 @@ public class ExcelReportGenerationService {
if (cell.getStringCellValue().contains(imagePlaceholder.getPlaceholder())) { if (cell.getStringCellValue().contains(imagePlaceholder.getPlaceholder())) {
try (ByteArrayInputStream is = new ByteArrayInputStream(imagePlaceholder.getImage())) { try (ByteArrayInputStream is = new ByteArrayInputStream(imagePlaceholder.getImage())) {
double factor = calculateScale(is, PixelUtil.widthUnits2Pixel((short) sheet.getColumnWidth(cell.getColumnIndex())), PixelUtil.heightUnits2Pixel(cell.getRow() double factor = calculateScale(is,
.getHeight())); PixelUtil.widthUnits2Pixel((short) sheet.getColumnWidth(cell.getColumnIndex())),
PixelUtil.heightUnits2Pixel(cell.getRow().getHeight()));
is.reset(); is.reset();
int pictureIdx = workbook.addPicture(is.readAllBytes(), SXSSFWorkbook.PICTURE_TYPE_JPEG); int pictureIdx = workbook.addPicture(is.readAllBytes(), SXSSFWorkbook.PICTURE_TYPE_JPEG);

View File

@ -62,8 +62,8 @@ public class GeneratePlaceholderService {
if (dossierAttribute.getValue() != null) { if (dossierAttribute.getValue() != null) {
if (dossierAttribute.getValue().startsWith("data:")) { if (dossierAttribute.getValue().startsWith("data:")) {
imagePlaceholders.add(new ImagePlaceholder(attributeConfig.getPlaceholder(), Base64.getDecoder() imagePlaceholders.add(new ImagePlaceholder(attributeConfig.getPlaceholder(),
.decode(dossierAttribute.getValue().split(",")[1]))); Base64.getDecoder().decode(dossierAttribute.getValue().split(",")[1])));
} else { } else {
imagePlaceholders.add(new ImagePlaceholder(attributeConfig.getPlaceholder(), Base64.getDecoder().decode(dossierAttribute.getValue()))); imagePlaceholders.add(new ImagePlaceholder(attributeConfig.getPlaceholder(), Base64.getDecoder().decode(dossierAttribute.getValue())));
} }
@ -115,10 +115,17 @@ public class GeneratePlaceholderService {
} }
public Set<String> getDefaultPlaceholders() { public Set<String> getDefaultPlaceholders() {
return new HashSet<>(Set.of(FILE_NAME_PLACEHOLDER, FORMAT_DATE_ISO_PLACEHOLDER, FORMAT_DATE_GER_PLACEHOLDER, FORMAT_DATE_ENG_PLACEHOLDER, FORMAT_TIME_ISO_PLACEHOLDER, DOSSIER_NAME_PLACEHOLDER, IUCLID_FUNCTION_PLACEHOLDER, SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER, SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER)); return new HashSet<>(Set.of(FILE_NAME_PLACEHOLDER,
FORMAT_DATE_ISO_PLACEHOLDER,
FORMAT_DATE_GER_PLACEHOLDER,
FORMAT_DATE_ENG_PLACEHOLDER,
FORMAT_TIME_ISO_PLACEHOLDER,
DOSSIER_NAME_PLACEHOLDER,
IUCLID_FUNCTION_PLACEHOLDER,
SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER,
SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER));
} }

View File

@ -77,7 +77,23 @@ public class PlaceholderService {
public List<String> getGeneralPlaceholders() { public List<String> getGeneralPlaceholders() {
return List.of(FILE_NAME_PLACEHOLDER, PAGE_PLACEHOLDER, PARAGRAPH_PLACEHOLDER, JUSTIFICATION_PLACEHOLDER, EXCERPT_PLACEHOLDER, FORMAT_DATE_ISO_PLACEHOLDER, FORMAT_DATE_GER_PLACEHOLDER, FORMAT_DATE_ENG_PLACEHOLDER, FORMAT_TIME_ISO_PLACEHOLDER, DOSSIER_NAME_PLACEHOLDER, IUCLID_FUNCTION_PLACEHOLDER, REDACTION_VALUE_PLACEHOLDER, JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER, JUSTIFICATION_TEXT_PLACEHOLDER, SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER, SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER, REDACTION_ENTITY_DISPLAY_NAME_PLACEHOLDER); return List.of(FILE_NAME_PLACEHOLDER,
PAGE_PLACEHOLDER,
PARAGRAPH_PLACEHOLDER,
JUSTIFICATION_PLACEHOLDER,
EXCERPT_PLACEHOLDER,
FORMAT_DATE_ISO_PLACEHOLDER,
FORMAT_DATE_GER_PLACEHOLDER,
FORMAT_DATE_ENG_PLACEHOLDER,
FORMAT_TIME_ISO_PLACEHOLDER,
DOSSIER_NAME_PLACEHOLDER,
IUCLID_FUNCTION_PLACEHOLDER,
REDACTION_VALUE_PLACEHOLDER,
JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER,
JUSTIFICATION_TEXT_PLACEHOLDER,
SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER,
SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER,
REDACTION_ENTITY_DISPLAY_NAME_PLACEHOLDER);
} }

View File

@ -14,14 +14,10 @@ import java.util.stream.Collectors;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileModel; import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileModel;
import com.iqser.red.service.redaction.report.v1.api.model.rss.RSSFileResponse; import com.iqser.red.service.redaction.report.v1.api.model.rss.RSSFileResponse;
import com.iqser.red.service.redaction.report.v1.api.model.rss.RSSResponse; import com.iqser.red.service.redaction.report.v1.api.model.rss.RSSResponse;
import com.iqser.red.service.redaction.report.v1.api.resource.RSSResource;
import com.iqser.red.service.redaction.report.v1.server.client.FileStatusClient; import com.iqser.red.service.redaction.report.v1.server.client.FileStatusClient;
import com.iqser.red.service.redaction.report.v1.server.client.RedactionLogClient; import com.iqser.red.service.redaction.report.v1.server.client.RedactionLogClient;
import com.iqser.red.service.redaction.v1.model.ChangeType; import com.iqser.red.service.redaction.v1.model.ChangeType;
@ -43,12 +39,74 @@ public class RSSService {
@PostConstruct @PostConstruct
public void init() { public void init() {
guidelineMapping.put("Acute Dermal Toxicity", Set.of("OECD 402", "OECD Test Guideline 402", "OECD Guidelines for the Testing of Chemicals No. 402", "OECD Guidelines for Testing of Chemicals, Procedure 402", "OPPTS 870.1200", "OPPTS Guideline Number 870.1200", "EPA 870.1200")); guidelineMapping.put("Acute Dermal Toxicity",
guidelineMapping.put("Acute inhalation toxicity", Set.of("OECD 403", "OECD Test Guideline 403", "OECD Guidelines for the Testing of Chemicals No. 403", "OECD Guidelines for Testing of Chemicals, Procedure 403", "OECD 436", "OECD Test Guideline 436", "OECD Guidelines for the Testing of Chemicals No. 436", "OECD Guidelines for Testing of Chemicals, Procedure 436", "OPPTS 870.1300", "OPPTS Guideline Number 870.1300", "EPA 870.1300")); Set.of("OECD 402",
guidelineMapping.put("Acute oral toxicity", Set.of("OECD 425", "OECD Test Guideline 425", "OECD Guidelines for the Testing of Chemicals No. 425", "OECD Guidelines for Testing of Chemicals, Procedure 425", "OECD 423", "OECD Test Guideline 423", "OECD Guidelines for the Testing of Chemicals No. 423", "OECD Guidelines for Testing of Chemicals, Procedure 423", "OPPTS 870.1100", "OPPTS Guideline Number 870.1100", "EPA 870.1100")); "OECD Test Guideline 402",
guidelineMapping.put("Eye irritation", Set.of("OECD 437", "OECD Test Guideline 437", "OECD Guidelines for the Testing of Chemicals No. 437", "OECD Guidelines for Testing of Chemicals, Procedure 437", "OECD 405", "OECD Test Guideline 405", "OECD Guidelines for the Testing of Chemicals No. 405", "OECD Guidelines for Testing of Chemicals, Procedure 405", "OPPTS 870.2400", "OPPTS Guideline Number 870.2400", "EPA 870.2400")); "OECD Guidelines for the Testing of Chemicals No. 402",
guidelineMapping.put("Skin irritation", Set.of("OECD 404", "OECD Test Guideline 404", "OECD Guidelines for the Testing of Chemicals No. 404", "OECD Guidelines for Testing of Chemicals, Procedure 404", "OECD 439", "OECD Test Guideline 439", "OECD Guidelines for the Testing of Chemicals No. 439", "OECD Guidelines for Testing of Chemicals, Procedure 439", "OPPTS 870.2500", "OPPTS Guideline Number 870.2500", "EPA 870.2500")); "OECD Guidelines for Testing of Chemicals, Procedure 402",
guidelineMapping.put("Skin sentitization", Set.of("OECD 406", "OECD Test Guideline 406", "OECD Guidelines for the Testing of Chemicals No. 406", "OECD Guidelines for Testing of Chemicals, Procedure 406", "OECD 429", "OECD Test Guideline 429", "OECD Guidelines for the Testing of Chemicals No. 429", "OECD Guidelines for Testing of Chemicals, Procedure 429", "OPPTS 870.2600", "OPPTS Guideline Number 870.2600", "EPA 870.2600")); "OPPTS 870.1200",
"OPPTS Guideline Number 870.1200",
"EPA 870.1200"));
guidelineMapping.put("Acute inhalation toxicity",
Set.of("OECD 403",
"OECD Test Guideline 403",
"OECD Guidelines for the Testing of Chemicals No. 403",
"OECD Guidelines for Testing of Chemicals, Procedure 403",
"OECD 436",
"OECD Test Guideline 436",
"OECD Guidelines for the Testing of Chemicals No. 436",
"OECD Guidelines for Testing of Chemicals, Procedure 436",
"OPPTS 870.1300",
"OPPTS Guideline Number 870.1300",
"EPA 870.1300"));
guidelineMapping.put("Acute oral toxicity",
Set.of("OECD 425",
"OECD Test Guideline 425",
"OECD Guidelines for the Testing of Chemicals No. 425",
"OECD Guidelines for Testing of Chemicals, Procedure 425",
"OECD 423",
"OECD Test Guideline 423",
"OECD Guidelines for the Testing of Chemicals No. 423",
"OECD Guidelines for Testing of Chemicals, Procedure 423",
"OPPTS 870.1100",
"OPPTS Guideline Number 870.1100",
"EPA 870.1100"));
guidelineMapping.put("Eye irritation",
Set.of("OECD 437",
"OECD Test Guideline 437",
"OECD Guidelines for the Testing of Chemicals No. 437",
"OECD Guidelines for Testing of Chemicals, Procedure 437",
"OECD 405",
"OECD Test Guideline 405",
"OECD Guidelines for the Testing of Chemicals No. 405",
"OECD Guidelines for Testing of Chemicals, Procedure 405",
"OPPTS 870.2400",
"OPPTS Guideline Number 870.2400",
"EPA 870.2400"));
guidelineMapping.put("Skin irritation",
Set.of("OECD 404",
"OECD Test Guideline 404",
"OECD Guidelines for the Testing of Chemicals No. 404",
"OECD Guidelines for Testing of Chemicals, Procedure 404",
"OECD 439",
"OECD Test Guideline 439",
"OECD Guidelines for the Testing of Chemicals No. 439",
"OECD Guidelines for Testing of Chemicals, Procedure 439",
"OPPTS 870.2500",
"OPPTS Guideline Number 870.2500",
"EPA 870.2500"));
guidelineMapping.put("Skin sentitization",
Set.of("OECD 406",
"OECD Test Guideline 406",
"OECD Guidelines for the Testing of Chemicals No. 406",
"OECD Guidelines for Testing of Chemicals, Procedure 406",
"OECD 429",
"OECD Test Guideline 429",
"OECD Guidelines for the Testing of Chemicals No. 429",
"OECD Guidelines for Testing of Chemicals, Procedure 429",
"OPPTS 870.2600",
"OPPTS Guideline Number 870.2600",
"EPA 870.2600"));
} }

View File

@ -1,14 +1,23 @@
package com.iqser.red.service.redaction.report.v1.server.service; package com.iqser.red.service.redaction.report.v1.server.service;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus; import java.util.ArrayList;
import com.iqser.red.service.redaction.report.v1.server.model.ReportRedactionEntry; import java.util.HashSet;
import com.iqser.red.service.redaction.v1.model.*; import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus;
import java.util.regex.Matcher; import com.iqser.red.service.redaction.report.v1.server.model.ReportRedactionEntry;
import java.util.regex.Pattern; import com.iqser.red.service.redaction.v1.model.ManualRedactionType;
import com.iqser.red.service.redaction.v1.model.Rectangle;
import com.iqser.red.service.redaction.v1.model.RedactionLog;
import com.iqser.red.service.redaction.v1.model.RedactionLogEntry;
import com.iqser.red.service.redaction.v1.model.RedactionLogLegalBasis;
@Service @Service
public class RedactionLogConverterService { public class RedactionLogConverterService {
@ -52,16 +61,24 @@ public class RedactionLogConverterService {
if (pages.isEmpty() || !pages.contains(position.getPage())) { if (pages.isEmpty() || !pages.contains(position.getPage())) {
pages.add(position.getPage()); pages.add(position.getPage());
reportEntries.add(new ReportRedactionEntry(position.getPage(), position.getTopLeft().getX(), position.getTopLeft() reportEntries.add(new ReportRedactionEntry(position.getPage(),
.getY(), getSection(entry, position), checkTextForNull(entry.getLegalBasis()) + " " + legalBasisMappings.stream() position.getTopLeft().getX(),
.filter(lbm -> lbm.getReason().equalsIgnoreCase(entry.getLegalBasis())) position.getTopLeft().getY(),
.findAny() getSection(entry, position),
.map(RedactionLogLegalBasis::getDescription) checkTextForNull(entry.getLegalBasis()) + " " + legalBasisMappings.stream()
.orElse(""), entry.getLegalBasis(), legalBasisMappings.stream() .filter(lbm -> lbm.getReason().equalsIgnoreCase(entry.getLegalBasis()))
.filter(lbm -> lbm.getReason().equalsIgnoreCase(entry.getLegalBasis())) .findAny()
.findAny() .map(RedactionLogLegalBasis::getDescription)
.map(RedactionLogLegalBasis::getDescription) .orElse(""),
.orElse(""), checkTextForNull(entry.getTextBefore()) + entry.getValue() + checkTextForNull(entry.getTextAfter()), entry.getValue(), mapOfEntityDisplayName.get(entry.getType()))); entry.getLegalBasis(),
legalBasisMappings.stream()
.filter(lbm -> lbm.getReason().equalsIgnoreCase(entry.getLegalBasis()))
.findAny()
.map(RedactionLogLegalBasis::getDescription)
.orElse(""),
checkTextForNull(entry.getTextBefore()) + entry.getValue() + checkTextForNull(entry.getTextAfter()),
entry.getValue(),
mapOfEntityDisplayName.get(entry.getType())));
} }
} }
} }

View File

@ -1,5 +1,19 @@
package com.iqser.red.service.redaction.report.v1.server.service; package com.iqser.red.service.redaction.report.v1.server.service;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.stereotype.Service;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.ReportTemplate; import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.ReportTemplate;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.Dossier; import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.Dossier;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileModel; import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileModel;
@ -7,7 +21,11 @@ import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.ty
import com.iqser.red.service.redaction.report.v1.api.model.ReportRequestMessage; import com.iqser.red.service.redaction.report.v1.api.model.ReportRequestMessage;
import com.iqser.red.service.redaction.report.v1.api.model.ReportType; import com.iqser.red.service.redaction.report.v1.api.model.ReportType;
import com.iqser.red.service.redaction.report.v1.api.model.StoredFileInformation; import com.iqser.red.service.redaction.report.v1.api.model.StoredFileInformation;
import com.iqser.red.service.redaction.report.v1.server.client.*; import com.iqser.red.service.redaction.report.v1.server.client.DictionaryClient;
import com.iqser.red.service.redaction.report.v1.server.client.DossierClient;
import com.iqser.red.service.redaction.report.v1.server.client.FileStatusClient;
import com.iqser.red.service.redaction.report.v1.server.client.RedactionLogClient;
import com.iqser.red.service.redaction.report.v1.server.client.ReportTemplateClient;
import com.iqser.red.service.redaction.report.v1.server.model.MultiFileDocument; import com.iqser.red.service.redaction.report.v1.server.model.MultiFileDocument;
import com.iqser.red.service.redaction.report.v1.server.model.MultiFileWorkbook; import com.iqser.red.service.redaction.report.v1.server.model.MultiFileWorkbook;
import com.iqser.red.service.redaction.report.v1.server.model.PlaceholderModel; import com.iqser.red.service.redaction.report.v1.server.model.PlaceholderModel;
@ -16,19 +34,11 @@ import com.iqser.red.service.redaction.report.v1.server.settings.ReportTemplateS
import com.iqser.red.service.redaction.report.v1.server.storage.ReportStorageService; import com.iqser.red.service.redaction.report.v1.server.storage.ReportStorageService;
import com.iqser.red.service.redaction.v1.model.RedactionLog; import com.iqser.red.service.redaction.v1.model.RedactionLog;
import com.iqser.red.storage.commons.exception.StorageObjectDoesNotExist; import com.iqser.red.storage.commons.exception.StorageObjectDoesNotExist;
import io.micrometer.core.annotation.Timed; import io.micrometer.core.annotation.Timed;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.stereotype.Service;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.*;
@SuppressWarnings("ALL") @SuppressWarnings("ALL")
@Slf4j @Slf4j
@ -49,6 +59,7 @@ public class ReportGenerationService {
private final ReportTemplateSettings reportTemplateSettings; private final ReportTemplateSettings reportTemplateSettings;
private final RSSService rSSService; private final RSSService rSSService;
@SneakyThrows @SneakyThrows
@Timed("redactmanager_generateReports") @Timed("redactmanager_generateReports")
public String generateReports(ReportRequestMessage reportMessage) { public String generateReports(ReportRequestMessage reportMessage) {
@ -72,7 +83,10 @@ public class ReportGenerationService {
for (Sheet sheet : readWorkbook) { for (Sheet sheet : readWorkbook) {
writeWorkbook.createSheet(sheet.getSheetName()); writeWorkbook.createSheet(sheet.getSheetName());
} }
MultiFileWorkbook multiFileWorkbook = new MultiFileWorkbook(readWorkbook, writeWorkbook, templateId, reportTemplate.getFileName(), MultiFileWorkbook multiFileWorkbook = new MultiFileWorkbook(readWorkbook,
writeWorkbook,
templateId,
reportTemplate.getFileName(),
excelTemplateReportGenerationService.calculateExcelModel(readWorkbook.getSheetAt(0))); excelTemplateReportGenerationService.calculateExcelModel(readWorkbook.getSheetAt(0)));
multiFileWorkbookReportTemplates.add(multiFileWorkbook); multiFileWorkbookReportTemplates.add(multiFileWorkbook);
} catch (IOException e) { } catch (IOException e) {
@ -103,21 +117,26 @@ public class ReportGenerationService {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
var fileStatus = fileStatusClient.getFileStatus(reportMessage.getDossierId(), reportMessage.getFileIds() var fileStatus = fileStatusClient.getFileStatus(reportMessage.getDossierId(), reportMessage.getFileIds().get(j));
.get(j));
generatePlaceholderService.resolveFileAttributeValues(fileStatus, placeholderModel); generatePlaceholderService.resolveFileAttributeValues(fileStatus, placeholderModel);
List<ReportRedactionEntry> reportEntries = getReportEntries(reportMessage.getDossierId(), reportMessage.getFileIds() List<ReportRedactionEntry> reportEntries = getReportEntries(reportMessage.getDossierId(), reportMessage.getFileIds().get(j), fileStatus.isExcluded());
.get(j), fileStatus.isExcluded());
var isLastFile = j == reportMessage.getFileIds().size() - 1; var isLastFile = j == reportMessage.getFileIds().size() - 1;
for (MultiFileWorkbook multiFileWorkbook : multiFileWorkbookReportTemplates) { for (MultiFileWorkbook multiFileWorkbook : multiFileWorkbookReportTemplates) {
if(multiFileWorkbook.getExcelModel().isHasRssPlaceHolders()){ if (multiFileWorkbook.getExcelModel().isHasRssPlaceHolders()) {
generatePlaceholderService.resolveRssValues(fileStatus, placeholderModel); generatePlaceholderService.resolveRssValues(fileStatus, placeholderModel);
} }
excelTemplateReportGenerationService.generateExcelReport(reportEntries, placeholderModel, multiFileWorkbook.getTemplateName(), multiFileWorkbook.getWriteWorkbook(), dossier.getDossierName(), fileStatus, multiFileWorkbook.getExcelModel(), isLastFile); excelTemplateReportGenerationService.generateExcelReport(reportEntries,
placeholderModel,
multiFileWorkbook.getTemplateName(),
multiFileWorkbook.getWriteWorkbook(),
dossier.getDossierName(),
fileStatus,
multiFileWorkbook.getExcelModel(),
isLastFile);
} }
for (MultiFileDocument multiFileDocument : multiFileDocumentReportTemplates) { for (MultiFileDocument multiFileDocument : multiFileDocumentReportTemplates) {
@ -127,7 +146,11 @@ public class ReportGenerationService {
wordReportGenerationService.removePlaceholdersRow(wordReportGenerationService.getRedactionTable(multiFileDocument.getDocument())); wordReportGenerationService.removePlaceholdersRow(wordReportGenerationService.getRedactionTable(multiFileDocument.getDocument()));
byte[] wordDoc = wordReportGenerationService.toByteArray(multiFileDocument.getDocument()); byte[] wordDoc = wordReportGenerationService.toByteArray(multiFileDocument.getDocument());
String storageId = reportStorageService.storeObject(reportMessage.getDownloadId(), wordDoc); String storageId = reportStorageService.storeObject(reportMessage.getDownloadId(), wordDoc);
storedFileInformation.add(new StoredFileInformation(null, storageId, ReportType.WORD_TEMPLATE_MULTI_FILE, multiFileDocument.getTemplateId(), multiFileDocument.getDocumentPartNr())); storedFileInformation.add(new StoredFileInformation(null,
storageId,
ReportType.WORD_TEMPLATE_MULTI_FILE,
multiFileDocument.getTemplateId(),
multiFileDocument.getDocumentPartNr()));
multiFileDocument.setDocumentPartNr(multiFileDocument.getDocumentPartNr() + 1); multiFileDocument.setDocumentPartNr(multiFileDocument.getDocumentPartNr() + 1);
try (ByteArrayInputStream is = new ByteArrayInputStream(multiFileDocument.getTemplateAsBytes())) { try (ByteArrayInputStream is = new ByteArrayInputStream(multiFileDocument.getTemplateAsBytes())) {
@ -136,18 +159,29 @@ public class ReportGenerationService {
multiFileDocument.setNumberOfChars(0); multiFileDocument.setNumberOfChars(0);
} }
} }
numberOfChars = wordReportGenerationService.generateWordReport(reportEntries, placeholderModel, multiFileDocument.getTemplateName(), multiFileDocument.getDocument(), fileStatus, dossier, isLastFile ? isLastFile : multiFileDocument.getNumberOfChars() + numberOfChars >= reportTemplateSettings.getMultiFileChunkSize()); numberOfChars = wordReportGenerationService.generateWordReport(reportEntries,
placeholderModel,
multiFileDocument.getTemplateName(),
multiFileDocument.getDocument(),
fileStatus,
dossier,
isLastFile ? isLastFile : multiFileDocument.getNumberOfChars() + numberOfChars >= reportTemplateSettings.getMultiFileChunkSize());
multiFileDocument.setNumberOfChars(multiFileDocument.getNumberOfChars() + numberOfChars); multiFileDocument.setNumberOfChars(multiFileDocument.getNumberOfChars() + numberOfChars);
} }
for (ReportTemplate reportTemplate : singleFilesTemplates) { for (ReportTemplate reportTemplate : singleFilesTemplates) {
storedFileInformation.add(createReportFromTemplate(dossier, fileStatus, placeholderModel, reportTemplate.getFileName(), reportMessage.getDownloadId(), reportEntries, reportTemplate)); storedFileInformation.add(createReportFromTemplate(dossier,
fileStatus,
placeholderModel,
reportTemplate.getFileName(),
reportMessage.getDownloadId(),
reportEntries,
reportTemplate));
} }
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
log.info("Successfully processed {}/{} fileIds for downloadId {}, took {}", i, reportMessage.getFileIds() log.info("Successfully processed {}/{} fileIds for downloadId {}, took {}", i, reportMessage.getFileIds().size(), reportMessage.getDownloadId(), end - start);
.size(), reportMessage.getDownloadId(), end - start);
i++; i++;
} }
@ -160,16 +194,23 @@ public class ReportGenerationService {
for (MultiFileDocument multiFileDocument : multiFileDocumentReportTemplates) { for (MultiFileDocument multiFileDocument : multiFileDocumentReportTemplates) {
byte[] template = wordReportGenerationService.toByteArray(multiFileDocument.getDocument()); byte[] template = wordReportGenerationService.toByteArray(multiFileDocument.getDocument());
String storageId = reportStorageService.storeObject(reportMessage.getDownloadId(), template); String storageId = reportStorageService.storeObject(reportMessage.getDownloadId(), template);
storedFileInformation.add(new StoredFileInformation(null, storageId, ReportType.WORD_TEMPLATE_MULTI_FILE, multiFileDocument.getTemplateId(), multiFileDocument.getDocumentPartNr())); storedFileInformation.add(new StoredFileInformation(null,
storageId,
ReportType.WORD_TEMPLATE_MULTI_FILE,
multiFileDocument.getTemplateId(),
multiFileDocument.getDocumentPartNr()));
} }
return reportStorageService.storeReportInformation(reportMessage.getDownloadId(), storedFileInformation); return reportStorageService.storeReportInformation(reportMessage.getDownloadId(), storedFileInformation);
} }
private StoredFileInformation createReportFromTemplate(Dossier dossier, FileModel fileStatus, private StoredFileInformation createReportFromTemplate(Dossier dossier,
PlaceholderModel placeholderModel, String templateName, FileModel fileStatus,
String downloadId, List<ReportRedactionEntry> reportEntries, PlaceholderModel placeholderModel,
String templateName,
String downloadId,
List<ReportRedactionEntry> reportEntries,
ReportTemplate reportTemplate) { ReportTemplate reportTemplate) {
if (reportTemplate.getFileName().endsWith(".xlsx")) { if (reportTemplate.getFileName().endsWith(".xlsx")) {
@ -181,11 +222,18 @@ public class ReportGenerationService {
writeWorkbook.createSheet(sheet.getSheetName()); writeWorkbook.createSheet(sheet.getSheetName());
} }
var excelModel = excelTemplateReportGenerationService.calculateExcelModel(readWorkbook.getSheetAt(0)); var excelModel = excelTemplateReportGenerationService.calculateExcelModel(readWorkbook.getSheetAt(0));
if(excelModel.isHasRssPlaceHolders()){ if (excelModel.isHasRssPlaceHolders()) {
generatePlaceholderService.resolveRssValues(fileStatus, placeholderModel); generatePlaceholderService.resolveRssValues(fileStatus, placeholderModel);
} }
excelTemplateReportGenerationService.generateExcelReport(reportEntries, placeholderModel, templateName, writeWorkbook, dossier.getDossierName(), fileStatus, excelModel, true); excelTemplateReportGenerationService.generateExcelReport(reportEntries,
placeholderModel,
templateName,
writeWorkbook,
dossier.getDossierName(),
fileStatus,
excelModel,
true);
byte[] template = excelTemplateReportGenerationService.toByteArray(writeWorkbook); byte[] template = excelTemplateReportGenerationService.toByteArray(writeWorkbook);
String storageId = reportStorageService.storeObject(downloadId, template); String storageId = reportStorageService.storeObject(downloadId, template);
return new StoredFileInformation(fileStatus.getId(), storageId, ReportType.EXCEL_TEMPLATE_SINGLE_FILE, reportTemplate.getTemplateId(), 0); return new StoredFileInformation(fileStatus.getId(), storageId, ReportType.EXCEL_TEMPLATE_SINGLE_FILE, reportTemplate.getTemplateId(), 0);
@ -232,8 +280,7 @@ public class ReportGenerationService {
List<Type> typeList = new ArrayList<>(); List<Type> typeList = new ArrayList<>();
typeList.addAll(dictionaryClient.getAllTypesForDossier(dossierId, false)); typeList.addAll(dictionaryClient.getAllTypesForDossier(dossierId, false));
typeList.addAll(dictionaryClient.getAllTypesForDossierTemplate(dossierClient.getDossierById(dossierId, true, false) typeList.addAll(dictionaryClient.getAllTypesForDossierTemplate(dossierClient.getDossierById(dossierId, true, false).getDossierTemplateId(), false));
.getDossierTemplateId(), false));
Map<String, String> mapOfEntityDisplayName = new HashMap<>(); Map<String, String> mapOfEntityDisplayName = new HashMap<>();

View File

@ -37,7 +37,7 @@ public class ReportMessageReceiver {
ReportRequestMessage reportMessage = objectMapper.readValue(message.getBody(), ReportRequestMessage.class); ReportRequestMessage reportMessage = objectMapper.readValue(message.getBody(), ReportRequestMessage.class);
// This prevents from endless retries oom errors. // This prevents from endless retries oom errors.
if(message.getMessageProperties().isRedelivered()){ if (message.getMessageProperties().isRedelivered()) {
throw new AmqpRejectAndDontRequeueException(String.format("Error during last processing of request with downloadId: %s, do not retry.", reportMessage.getDownloadId())); throw new AmqpRejectAndDontRequeueException(String.format("Error during last processing of request with downloadId: %s, do not retry.", reportMessage.getDownloadId()));
} }
@ -55,10 +55,12 @@ public class ReportMessageReceiver {
private void addToReportResultQueue(String userId, String downloadId, String reportFileInformationStorageId, int priority) { private void addToReportResultQueue(String userId, String downloadId, String reportFileInformationStorageId, int priority) {
try { try {
rabbitTemplate.convertAndSend(REPORT_RESULT_QUEUE, objectMapper.writeValueAsString(new ReportResultMessage(userId, downloadId, reportFileInformationStorageId)), message -> { rabbitTemplate.convertAndSend(REPORT_RESULT_QUEUE,
message.getMessageProperties().setPriority(priority); objectMapper.writeValueAsString(new ReportResultMessage(userId, downloadId, reportFileInformationStorageId)),
return message; message -> {
}); message.getMessageProperties().setPriority(priority);
return message;
});
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@ -82,8 +82,13 @@ public class WordReportGenerationService {
@Timed("redactmanager_generateWordReport") @Timed("redactmanager_generateWordReport")
public int generateWordReport(List<ReportRedactionEntry> reportEntries, PlaceholderModel placeholderModel, String reportTemplateName, XWPFDocument doc, FileModel fileModel, public int generateWordReport(List<ReportRedactionEntry> reportEntries,
Dossier dossier, boolean isLastFile) { PlaceholderModel placeholderModel,
String reportTemplateName,
XWPFDocument doc,
FileModel fileModel,
Dossier dossier,
boolean isLastFile) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
@ -107,8 +112,13 @@ public class WordReportGenerationService {
removePlaceholdersRow(table); removePlaceholdersRow(table);
} }
log.info("Report Generation took: {} for file with id {}, pageCount: {}, redactionLogEntryCount: {}, reportName: {}, className: {}", System.currentTimeMillis() - start, log.info("Report Generation took: {} for file with id {}, pageCount: {}, redactionLogEntryCount: {}, reportName: {}, className: {}",
fileModel.getId(), fileModel.getNumberOfPages(), reportEntries.size(), reportTemplateName, getClass().getSimpleName()); System.currentTimeMillis() - start,
fileModel.getId(),
fileModel.getNumberOfPages(),
reportEntries.size(),
reportTemplateName,
getClass().getSimpleName());
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage() + " in file: " + fileModel.getFilename()); log.error(e.getMessage() + " in file: " + fileModel.getFilename());
@ -149,7 +159,10 @@ public class WordReportGenerationService {
} }
private String getPlaceholderValue(String placeholder, String dossierName, String filename, PlaceholderModel placeholderModel, private String getPlaceholderValue(String placeholder,
String dossierName,
String filename,
PlaceholderModel placeholderModel,
List<ReportRedactionEntry> reportRedactionEntries) { List<ReportRedactionEntry> reportRedactionEntries) {
if (placeholder.equals(FORMAT_DATE_ISO_PLACEHOLDER)) { if (placeholder.equals(FORMAT_DATE_ISO_PLACEHOLDER)) {
@ -210,7 +223,11 @@ public class WordReportGenerationService {
@Timed("redactmanager_word-replaceTextPlaceholders") @Timed("redactmanager_word-replaceTextPlaceholders")
public int replaceTextPlaceholders(XWPFDocument doc, PlaceholderModel placeholderModel, String dossierName, String fileName, XWPFTable tableToSkip, public int replaceTextPlaceholders(XWPFDocument doc,
PlaceholderModel placeholderModel,
String dossierName,
String fileName,
XWPFTable tableToSkip,
List<ReportRedactionEntry> reportRedactionEntries) { List<ReportRedactionEntry> reportRedactionEntries) {
int sumOfChars = 0; int sumOfChars = 0;
@ -296,10 +313,10 @@ public class WordReportGenerationService {
for (XWPFTable tbl : doc.getTables()) { for (XWPFTable tbl : doc.getTables()) {
String tblText = tbl.getText(); String tblText = tbl.getText();
if (tblText.contains(PAGE_PLACEHOLDER) || tblText.contains(PARAGRAPH_PLACEHOLDER) || tblText.contains(JUSTIFICATION_PLACEHOLDER) || tblText.contains( if (tblText.contains(PAGE_PLACEHOLDER) || tblText.contains(PARAGRAPH_PLACEHOLDER) || tblText.contains(JUSTIFICATION_PLACEHOLDER) || tblText.contains(EXCERPT_PLACEHOLDER) || tblText.contains(
EXCERPT_PLACEHOLDER) || tblText.contains(JUSTIFICATION_PARAGRAPH_PLACEHOLDER) || tblText.contains(JUSTIFICATION_REASON_PLACEHOLDER) || tblText.contains( JUSTIFICATION_PARAGRAPH_PLACEHOLDER) || tblText.contains(JUSTIFICATION_REASON_PLACEHOLDER) || tblText.contains(JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER) || tblText.contains(
JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER) || tblText.contains(JUSTIFICATION_TEXT_PLACEHOLDER) || tblText.contains( JUSTIFICATION_TEXT_PLACEHOLDER) || tblText.contains(SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER) || tblText.contains(
SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER) || tblText.contains(SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER)) { SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER)) {
return tbl; return tbl;
} }
} }
@ -341,7 +358,10 @@ public class WordReportGenerationService {
@Timed("redactmanager_word-addRedactionEntryRows") @Timed("redactmanager_word-addRedactionEntryRows")
private int addRedactionEntryRows(XWPFTable table, List<ReportRedactionEntry> reportEntries, String filename, PlaceholderModel placeholderModel, private int addRedactionEntryRows(XWPFTable table,
List<ReportRedactionEntry> reportEntries,
String filename,
PlaceholderModel placeholderModel,
PlaceHolderFunctions placeHolderFunctions) { PlaceHolderFunctions placeHolderFunctions) {
int sumOfChars = 0; int sumOfChars = 0;
@ -527,7 +547,8 @@ public class WordReportGenerationService {
protected int approxNumberOfChars(Optional<ReportRedactionEntry> firstReportEntry, String filename) { protected int approxNumberOfChars(Optional<ReportRedactionEntry> firstReportEntry, String filename) {
if(firstReportEntry.isPresent()) {
if (firstReportEntry.isPresent()) {
int sumOfChars = 0; int sumOfChars = 0;
sumOfChars += filename.length(); sumOfChars += filename.length();

View File

@ -1,23 +1,26 @@
package com.iqser.red.service.redaction.report.v1.server.storage; package com.iqser.red.service.redaction.report.v1.server.storage;
import com.iqser.red.service.redaction.report.v1.api.model.StoredFileInformation;
import com.iqser.red.storage.commons.service.StorageService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Service;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Service;
import com.iqser.red.service.redaction.report.v1.api.model.StoredFileInformation;
import com.iqser.red.storage.commons.service.StorageService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class ReportStorageService { public class ReportStorageService {
private final StorageService storageService; private final StorageService storageService;
public String storeObject(String downloadId, byte[] data) { public String storeObject(String downloadId, byte[] data) {
String storageId = StorageIdUtils.getStorageId(downloadId, UUID.randomUUID().toString()); String storageId = StorageIdUtils.getStorageId(downloadId, UUID.randomUUID().toString());
@ -36,6 +39,7 @@ public class ReportStorageService {
public byte[] getReportTemplate(String storageId) { public byte[] getReportTemplate(String storageId) {
try { try {
return IOUtils.toByteArray(storageService.getObject(storageId).getInputStream()); return IOUtils.toByteArray(storageService.getObject(storageId).getInputStream());
} catch (IOException e) { } catch (IOException e) {

View File

@ -1,11 +1,11 @@
package com.iqser.red.service.redaction.report.v1.server.utils; package com.iqser.red.service.redaction.report.v1.server.utils;
import lombok.experimental.UtilityClass;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import lombok.experimental.UtilityClass;
@UtilityClass @UtilityClass
public class ResourceLoader { public class ResourceLoader {
@ -21,4 +21,5 @@ public class ResourceLoader {
throw new IllegalArgumentException("could not load classpath resource: " + classpathPath, e); throw new IllegalArgumentException("could not load classpath resource: " + classpathPath, e);
} }
} }
} }

View File

@ -1,5 +1,22 @@
package com.iqser.red.service.redaction.report.v1.server; package com.iqser.red.service.redaction.report.v1.server;
import static org.mockito.Mockito.when;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.test.context.junit4.SpringRunner;
import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.DossierAttributeConfig; import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.DossierAttributeConfig;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.ReportTemplate; import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.ReportTemplate;
@ -11,22 +28,6 @@ import com.iqser.red.service.redaction.report.v1.server.client.ReportTemplateCli
import com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService; import com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService;
import com.iqser.red.service.redaction.report.v1.server.storage.ReportStorageService; import com.iqser.red.service.redaction.report.v1.server.storage.ReportStorageService;
import com.iqser.red.storage.commons.service.StorageService; import com.iqser.red.storage.commons.service.StorageService;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import static org.mockito.Mockito.when;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = RANDOM_PORT) @SpringBootTest(webEnvironment = RANDOM_PORT)
@ -53,6 +54,7 @@ public class PlaceholderTest {
@MockBean @MockBean
private FileAttributesConfigClient fileAttributesClient; private FileAttributesConfigClient fileAttributesClient;
@Test @Test
public void testGeneralPlaceholders() { public void testGeneralPlaceholders() {
@ -64,6 +66,7 @@ public class PlaceholderTest {
Assert.assertEquals(placeholders.size(), 17); Assert.assertEquals(placeholders.size(), 17);
} }
@Test @Test
public void testGetReportTemplates() throws IOException { public void testGetReportTemplates() throws IOException {
@ -78,20 +81,62 @@ public class PlaceholderTest {
ClassPathResource templateResource2 = new ClassPathResource("templates/" + storageId2); ClassPathResource templateResource2 = new ClassPathResource("templates/" + storageId2);
when(reportStorageService.getReportTemplate(storageId2)).thenReturn(IOUtils.toByteArray(templateResource2.getInputStream())); when(reportStorageService.getReportTemplate(storageId2)).thenReturn(IOUtils.toByteArray(templateResource2.getInputStream()));
when(reportTemplateClient.getAvailableReportTemplates(dossierTemplateId)).thenReturn(List.of( when(reportTemplateClient.getAvailableReportTemplates(dossierTemplateId)).thenReturn(List.of(ReportTemplate.builder().storageId(storageId).build(),
ReportTemplate.builder().storageId(storageId).build(),
ReportTemplate.builder().storageId(storageId2).build())); ReportTemplate.builder().storageId(storageId2).build()));
DossierAttributeConfig dossierAttributeConfig = new DossierAttributeConfig("id", "Active Substance", true, "{{dossier.attribute.ActiveSubstance}}", DossierAttributeType.TEXT, dossierTemplateId); DossierAttributeConfig dossierAttributeConfig = new DossierAttributeConfig("id",
DossierAttributeConfig dossierAttributeConfig2 = new DossierAttributeConfig("id2", "Rapporteur Member State", false, "{{dossier.attribute.RapporteurMemberState}}", DossierAttributeType.TEXT, dossierTemplateId); "Active Substance",
DossierAttributeConfig dossierAttributeConfig3 = new DossierAttributeConfig("id3", "Dossier Name", true, "{{dossier.attribute.Name}}", DossierAttributeType.TEXT, dossierTemplateId); true,
DossierAttributeConfig dossierAttributeConfig4 = new DossierAttributeConfig("id4", "Company", false, "{{dossier.attribute.Company}}", DossierAttributeType.TEXT, dossierTemplateId); "{{dossier.attribute.ActiveSubstance}}",
DossierAttributeConfig dossierAttributeConfig5 = new DossierAttributeConfig("id5", "Date", true, "{{dossier.attribute.Date}}", DossierAttributeType.DATE, dossierTemplateId); DossierAttributeType.TEXT,
DossierAttributeConfig dossierAttributeConfig6 = new DossierAttributeConfig("id6", "Signature", false, "{{dossier.attribute.Signature}}", DossierAttributeType.IMAGE, dossierTemplateId); dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig7 = new DossierAttributeConfig("id7", "Does not exist", true, "{{does.not.exist}}", DossierAttributeType.DATE, dossierTemplateId); DossierAttributeConfig dossierAttributeConfig2 = new DossierAttributeConfig("id2",
"Rapporteur Member State",
false,
"{{dossier.attribute.RapporteurMemberState}}",
DossierAttributeType.TEXT,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig3 = new DossierAttributeConfig("id3",
"Dossier Name",
true,
"{{dossier.attribute.Name}}",
DossierAttributeType.TEXT,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig4 = new DossierAttributeConfig("id4",
"Company",
false,
"{{dossier.attribute.Company}}",
DossierAttributeType.TEXT,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig5 = new DossierAttributeConfig("id5",
"Date",
true,
"{{dossier.attribute.Date}}",
DossierAttributeType.DATE,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig6 = new DossierAttributeConfig("id6",
"Signature",
false,
"{{dossier.attribute.Signature}}",
DossierAttributeType.IMAGE,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig7 = new DossierAttributeConfig("id7",
"Does not exist",
true,
"{{does.not.exist}}",
DossierAttributeType.DATE,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig8 = new DossierAttributeConfig("id8", "test1", true, "{{test1}}", DossierAttributeType.DATE, dossierTemplateId); DossierAttributeConfig dossierAttributeConfig8 = new DossierAttributeConfig("id8", "test1", true, "{{test1}}", DossierAttributeType.DATE, dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig9 = new DossierAttributeConfig("id9", "test1", true, "{{TEST1}}", DossierAttributeType.DATE, dossierTemplateId); DossierAttributeConfig dossierAttributeConfig9 = new DossierAttributeConfig("id9", "test1", true, "{{TEST1}}", DossierAttributeType.DATE, dossierTemplateId);
when(dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId)).thenReturn(List.of(dossierAttributeConfig, dossierAttributeConfig2, dossierAttributeConfig3, dossierAttributeConfig4, dossierAttributeConfig5, dossierAttributeConfig6, dossierAttributeConfig7, dossierAttributeConfig8, dossierAttributeConfig9)); when(dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId)).thenReturn(List.of(dossierAttributeConfig,
dossierAttributeConfig2,
dossierAttributeConfig3,
dossierAttributeConfig4,
dossierAttributeConfig5,
dossierAttributeConfig6,
dossierAttributeConfig7,
dossierAttributeConfig8,
dossierAttributeConfig9));
FileAttributeConfig fileAttributeConfig1 = FileAttributeConfig.builder().id("config1").label("Label1").placeholder("{{file.test.1}}").build(); FileAttributeConfig fileAttributeConfig1 = FileAttributeConfig.builder().id("config1").label("Label1").placeholder("{{file.test.1}}").build();
FileAttributeConfig fileAttributeConfig2 = FileAttributeConfig.builder().id("config2").label("Label2").placeholder("{{file.test.not.exist}}").build(); FileAttributeConfig fileAttributeConfig2 = FileAttributeConfig.builder().id("config2").label("Label2").placeholder("{{file.test.not.exist}}").build();
@ -109,6 +154,7 @@ public class PlaceholderTest {
Assert.assertEquals(storageId, reportTemplates.get(0).getStorageId()); Assert.assertEquals(storageId, reportTemplates.get(0).getStorageId());
} }
@Test @Test
public void testWord() throws IOException { public void testWord() throws IOException {
@ -122,23 +168,65 @@ public class PlaceholderTest {
when(reportTemplateClient.getReportTemplate(dossierTemplateId, reportTemplateId)).thenReturn(ReportTemplate.builder().storageId(storageId).build()); when(reportTemplateClient.getReportTemplate(dossierTemplateId, reportTemplateId)).thenReturn(ReportTemplate.builder().storageId(storageId).build());
DossierAttributeConfig dossierAttributeConfig = new DossierAttributeConfig("id", "Active Substance", true, "{{dossier.attribute.ActiveSubstance}}", DossierAttributeType.TEXT, dossierTemplateId); DossierAttributeConfig dossierAttributeConfig = new DossierAttributeConfig("id",
DossierAttributeConfig dossierAttributeConfig2 = new DossierAttributeConfig("id2", "Rapporteur Member State", false, "{{dossier.attribute.RapporteurMemberState}}", DossierAttributeType.TEXT, dossierTemplateId); "Active Substance",
DossierAttributeConfig dossierAttributeConfig3 = new DossierAttributeConfig("id3", "Dossier Name", true, "{{dossier.attribute.Name}}", DossierAttributeType.TEXT, dossierTemplateId); true,
DossierAttributeConfig dossierAttributeConfig4 = new DossierAttributeConfig("id4", "Company", false, "{{dossier.attribute.Company}}", DossierAttributeType.TEXT, dossierTemplateId); "{{dossier.attribute.ActiveSubstance}}",
DossierAttributeConfig dossierAttributeConfig5 = new DossierAttributeConfig("id5", "Date", true, "{{dossier.attribute.Date}}", DossierAttributeType.DATE, dossierTemplateId); DossierAttributeType.TEXT,
DossierAttributeConfig dossierAttributeConfig6 = new DossierAttributeConfig("id6", "Signature", false, "{{dossier.attribute.Signature}}", DossierAttributeType.IMAGE, dossierTemplateId); dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig7 = new DossierAttributeConfig("id7", "Does not exist", true, "{{does.not.exist}}", DossierAttributeType.DATE, dossierTemplateId); DossierAttributeConfig dossierAttributeConfig2 = new DossierAttributeConfig("id2",
"Rapporteur Member State",
false,
"{{dossier.attribute.RapporteurMemberState}}",
DossierAttributeType.TEXT,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig3 = new DossierAttributeConfig("id3",
"Dossier Name",
true,
"{{dossier.attribute.Name}}",
DossierAttributeType.TEXT,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig4 = new DossierAttributeConfig("id4",
"Company",
false,
"{{dossier.attribute.Company}}",
DossierAttributeType.TEXT,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig5 = new DossierAttributeConfig("id5",
"Date",
true,
"{{dossier.attribute.Date}}",
DossierAttributeType.DATE,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig6 = new DossierAttributeConfig("id6",
"Signature",
false,
"{{dossier.attribute.Signature}}",
DossierAttributeType.IMAGE,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig7 = new DossierAttributeConfig("id7",
"Does not exist",
true,
"{{does.not.exist}}",
DossierAttributeType.DATE,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig8 = new DossierAttributeConfig("id8", "test1", true, "{{test1}}", DossierAttributeType.DATE, dossierTemplateId); DossierAttributeConfig dossierAttributeConfig8 = new DossierAttributeConfig("id8", "test1", true, "{{test1}}", DossierAttributeType.DATE, dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig9 = new DossierAttributeConfig("id9", "test1", true, "{{TEST1}}", DossierAttributeType.DATE, dossierTemplateId); DossierAttributeConfig dossierAttributeConfig9 = new DossierAttributeConfig("id9", "test1", true, "{{TEST1}}", DossierAttributeType.DATE, dossierTemplateId);
when(dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId)).thenReturn(List.of(dossierAttributeConfig, dossierAttributeConfig2, dossierAttributeConfig3, dossierAttributeConfig4, dossierAttributeConfig5, dossierAttributeConfig6, dossierAttributeConfig7, dossierAttributeConfig8, dossierAttributeConfig9)); when(dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId)).thenReturn(List.of(dossierAttributeConfig,
dossierAttributeConfig2,
dossierAttributeConfig3,
dossierAttributeConfig4,
dossierAttributeConfig5,
dossierAttributeConfig6,
dossierAttributeConfig7,
dossierAttributeConfig8,
dossierAttributeConfig9));
FileAttributeConfig fileAttributeConfig1 = FileAttributeConfig.builder().id("config1").label("Label1").placeholder("{{file.test.1}}").build(); FileAttributeConfig fileAttributeConfig1 = FileAttributeConfig.builder().id("config1").label("Label1").placeholder("{{file.test.1}}").build();
FileAttributeConfig fileAttributeConfig2 = FileAttributeConfig.builder().id("config2").label("Label2").placeholder("{{file.test.not.exist}}").build(); FileAttributeConfig fileAttributeConfig2 = FileAttributeConfig.builder().id("config2").label("Label2").placeholder("{{file.test.not.exist}}").build();
when(fileAttributesClient.getFileAttributeConfigs(dossierTemplateId)).thenReturn(List.of(fileAttributeConfig1, fileAttributeConfig2)); when(fileAttributesClient.getFileAttributeConfigs(dossierTemplateId)).thenReturn(List.of(fileAttributeConfig1, fileAttributeConfig2));
// Act // Act
Set<String> placeholders = placeholderService.getPlaceholdersOfTemplate(dossierTemplateId, reportTemplateId); Set<String> placeholders = placeholderService.getPlaceholdersOfTemplate(dossierTemplateId, reportTemplateId);
@ -155,6 +243,7 @@ public class PlaceholderTest {
Assert.assertFalse(placeholders.contains("{{file.test.not.exist}}")); Assert.assertFalse(placeholders.contains("{{file.test.not.exist}}"));
} }
@Test @Test
public void testExcel() throws IOException { public void testExcel() throws IOException {
@ -168,16 +257,59 @@ public class PlaceholderTest {
when(reportTemplateClient.getReportTemplate(dossierTemplateId, reportTemplateId)).thenReturn(ReportTemplate.builder().storageId(storageId).build()); when(reportTemplateClient.getReportTemplate(dossierTemplateId, reportTemplateId)).thenReturn(ReportTemplate.builder().storageId(storageId).build());
DossierAttributeConfig dossierAttributeConfig = new DossierAttributeConfig("id", "Active Substance", true, "{{dossier.attribute.ActiveSubstance}}", DossierAttributeType.TEXT, dossierTemplateId); DossierAttributeConfig dossierAttributeConfig = new DossierAttributeConfig("id",
DossierAttributeConfig dossierAttributeConfig2 = new DossierAttributeConfig("id2", "Rapporteur Member State", false, "{{dossier.attribute.RapporteurMemberState}}", DossierAttributeType.TEXT, dossierTemplateId); "Active Substance",
DossierAttributeConfig dossierAttributeConfig3 = new DossierAttributeConfig("id3", "Dossier Name", true, "{{dossier.attribute.Name}}", DossierAttributeType.TEXT, dossierTemplateId); true,
DossierAttributeConfig dossierAttributeConfig4 = new DossierAttributeConfig("id4", "Company", false, "{{dossier.attribute.Company}}", DossierAttributeType.TEXT, dossierTemplateId); "{{dossier.attribute.ActiveSubstance}}",
DossierAttributeConfig dossierAttributeConfig5 = new DossierAttributeConfig("id5", "Date", true, "{{dossier.attribute.Date}}", DossierAttributeType.DATE, dossierTemplateId); DossierAttributeType.TEXT,
DossierAttributeConfig dossierAttributeConfig6 = new DossierAttributeConfig("id6", "Signature", false, "{{dossier.attribute.Signature}}", DossierAttributeType.IMAGE, dossierTemplateId); dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig7 = new DossierAttributeConfig("id7", "Does not exist", true, "{{does.not.exist}}", DossierAttributeType.DATE, dossierTemplateId); DossierAttributeConfig dossierAttributeConfig2 = new DossierAttributeConfig("id2",
"Rapporteur Member State",
false,
"{{dossier.attribute.RapporteurMemberState}}",
DossierAttributeType.TEXT,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig3 = new DossierAttributeConfig("id3",
"Dossier Name",
true,
"{{dossier.attribute.Name}}",
DossierAttributeType.TEXT,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig4 = new DossierAttributeConfig("id4",
"Company",
false,
"{{dossier.attribute.Company}}",
DossierAttributeType.TEXT,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig5 = new DossierAttributeConfig("id5",
"Date",
true,
"{{dossier.attribute.Date}}",
DossierAttributeType.DATE,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig6 = new DossierAttributeConfig("id6",
"Signature",
false,
"{{dossier.attribute.Signature}}",
DossierAttributeType.IMAGE,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig7 = new DossierAttributeConfig("id7",
"Does not exist",
true,
"{{does.not.exist}}",
DossierAttributeType.DATE,
dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig8 = new DossierAttributeConfig("id8", "test1", true, "{{test1}}", DossierAttributeType.DATE, dossierTemplateId); DossierAttributeConfig dossierAttributeConfig8 = new DossierAttributeConfig("id8", "test1", true, "{{test1}}", DossierAttributeType.DATE, dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig9 = new DossierAttributeConfig("id9", "test1", true, "{{TEST1}}", DossierAttributeType.DATE, dossierTemplateId); DossierAttributeConfig dossierAttributeConfig9 = new DossierAttributeConfig("id9", "test1", true, "{{TEST1}}", DossierAttributeType.DATE, dossierTemplateId);
when(dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId)).thenReturn(List.of(dossierAttributeConfig, dossierAttributeConfig2, dossierAttributeConfig3, dossierAttributeConfig4, dossierAttributeConfig5, dossierAttributeConfig6, dossierAttributeConfig7, dossierAttributeConfig8, dossierAttributeConfig9)); when(dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId)).thenReturn(List.of(dossierAttributeConfig,
dossierAttributeConfig2,
dossierAttributeConfig3,
dossierAttributeConfig4,
dossierAttributeConfig5,
dossierAttributeConfig6,
dossierAttributeConfig7,
dossierAttributeConfig8,
dossierAttributeConfig9));
FileAttributeConfig fileAttributeConfig1 = FileAttributeConfig.builder().id("config1").label("Label1").placeholder("{{file.test.1}}").build(); FileAttributeConfig fileAttributeConfig1 = FileAttributeConfig.builder().id("config1").label("Label1").placeholder("{{file.test.1}}").build();
FileAttributeConfig fileAttributeConfig2 = FileAttributeConfig.builder().id("config2").label("Label2").placeholder("{{file.test.not.exist}}").build(); FileAttributeConfig fileAttributeConfig2 = FileAttributeConfig.builder().id("config2").label("Label2").placeholder("{{file.test.not.exist}}").build();

View File

@ -122,7 +122,18 @@ public class RedactionReportIntegrationTest {
Dossier dossier = Dossier.builder().dossierName("dossierName").build(); Dossier dossier = Dossier.builder().dossierName("dossierName").build();
FileModel fileModel = FileModel.builder().filename("filename").build(); FileModel fileModel = FileModel.builder().filename("filename").build();
var placeholders = buildPlaceHolderModel(Map.of("{{dossier.attribute.ActiveSubstance}}", "Aktive Substanz \n Test Return", "{{dossier.attribute.RapporteurMemberState}}", "Reporter Status", "{{dossier.attribute.Name}}", "Dossier Name", "{{dossier.attribute.Company}}", "Firma", "{{dossier.attribute.Date}}", "2021-11-09T23:00:00.000Z"), Map.of("{{file.attribute.placeholder}}", "Test"), List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream())))); var placeholders = buildPlaceHolderModel(Map.of("{{dossier.attribute.ActiveSubstance}}",
"Aktive Substanz \n Test Return",
"{{dossier.attribute.RapporteurMemberState}}",
"Reporter Status",
"{{dossier.attribute.Name}}",
"Dossier Name",
"{{dossier.attribute.Company}}",
"Firma",
"{{dossier.attribute.Date}}",
"2021-11-09T23:00:00.000Z"),
Map.of("{{file.attribute.placeholder}}", "Test"),
List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream()))));
XWPFDocument doc = new XWPFDocument(wordTemplateResource.getInputStream()); XWPFDocument doc = new XWPFDocument(wordTemplateResource.getInputStream());
wordReportGenerationService.generateWordReport(reportEntries, placeholders, "test", doc, fileModel, dossier, true); wordReportGenerationService.generateWordReport(reportEntries, placeholders, "test", doc, fileModel, dossier, true);
@ -148,7 +159,18 @@ public class RedactionReportIntegrationTest {
Dossier dossier = Dossier.builder().dossierName("dossierName").build(); Dossier dossier = Dossier.builder().dossierName("dossierName").build();
FileModel fileModel = FileModel.builder().filename("filename").build(); FileModel fileModel = FileModel.builder().filename("filename").build();
var placeholders = buildPlaceHolderModel(Map.of("{{dossier.attribute.ActiveSubstance}}", "Aktive Substanz \n Test Return", "{{dossier.attribute.RapporteurMemberState}}", "Reporter Status", "{{dossier.attribute.Name}}", "Dossier Name", "{{dossier.attribute.Company}}", "Firma", "{{dossier.attribute.Date}}", "2021-11-09T23:00:00.000Z"), Map.of("{{file.attribute.placeholder}}", "Test"), List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream())))); var placeholders = buildPlaceHolderModel(Map.of("{{dossier.attribute.ActiveSubstance}}",
"Aktive Substanz \n Test Return",
"{{dossier.attribute.RapporteurMemberState}}",
"Reporter Status",
"{{dossier.attribute.Name}}",
"Dossier Name",
"{{dossier.attribute.Company}}",
"Firma",
"{{dossier.attribute.Date}}",
"2021-11-09T23:00:00.000Z"),
Map.of("{{file.attribute.placeholder}}", "Test"),
List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream()))));
XWPFDocument doc = new XWPFDocument(wordTemplateResource.getInputStream()); XWPFDocument doc = new XWPFDocument(wordTemplateResource.getInputStream());
wordReportGenerationService.generateWordReport(reportEntries, placeholders, "test", doc, fileModel, dossier, true); wordReportGenerationService.generateWordReport(reportEntries, placeholders, "test", doc, fileModel, dossier, true);
@ -257,7 +279,18 @@ public class RedactionReportIntegrationTest {
Dossier dossier = Dossier.builder().dossierName("dossierName").build(); Dossier dossier = Dossier.builder().dossierName("dossierName").build();
FileModel fileModel = FileModel.builder().filename("filename").build(); FileModel fileModel = FileModel.builder().filename("filename").build();
var placeholders = buildPlaceHolderModel(Map.of("{{dossier.attribute.ActiveSubstance}}", "Aktive Substanz \n Test Return", "{{dossier.attribute.RapporteurMemberState}}", "Reporter Status", "{{dossier.attribute.Name}}", "Dossier Name", "{{dossier.attribute.Company}}", "Firma", "{{dossier.attribute.Date}}", "2021-11-09T23:00:00.000Z"), Map.of("{{file.attribute.placeholder}}", "Test"), List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream())))); var placeholders = buildPlaceHolderModel(Map.of("{{dossier.attribute.ActiveSubstance}}",
"Aktive Substanz \n Test Return",
"{{dossier.attribute.RapporteurMemberState}}",
"Reporter Status",
"{{dossier.attribute.Name}}",
"Dossier Name",
"{{dossier.attribute.Company}}",
"Firma",
"{{dossier.attribute.Date}}",
"2021-11-09T23:00:00.000Z"),
Map.of("{{file.attribute.placeholder}}", "Test"),
List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream()))));
XWPFDocument doc = new XWPFDocument(wordTemplateResource.getInputStream()); XWPFDocument doc = new XWPFDocument(wordTemplateResource.getInputStream());
wordReportGenerationService.generateWordReport(reportEntries, placeholders, "test", doc, fileModel, dossier, true); wordReportGenerationService.generateWordReport(reportEntries, placeholders, "test", doc, fileModel, dossier, true);
@ -278,7 +311,7 @@ public class RedactionReportIntegrationTest {
Map<String, String> mapOfEntityDisplayName = createEntityDisplayNames(redactionLog); Map<String, String> mapOfEntityDisplayName = createEntityDisplayNames(redactionLog);
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, mapOfEntityDisplayName); List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, mapOfEntityDisplayName);
FileModel fileModel = FileModel.builder().filename("filename").fileAttributes(Map.of("TestAttribute","Lorem Ipsum")).build(); FileModel fileModel = FileModel.builder().filename("filename").fileAttributes(Map.of("TestAttribute", "Lorem Ipsum")).build();
ClassPathResource templateResource = new ClassPathResource("templates/Excel Report.xlsx"); ClassPathResource templateResource = new ClassPathResource("templates/Excel Report.xlsx");
@ -323,7 +356,14 @@ public class RedactionReportIntegrationTest {
RedactionLog redactionLogSecondFile = objectMapper.readValue(new ClassPathResource("files/excelReportRedactionLog.json").getInputStream(), RedactionLog.class); RedactionLog redactionLogSecondFile = objectMapper.readValue(new ClassPathResource("files/excelReportRedactionLog.json").getInputStream(), RedactionLog.class);
List<ReportRedactionEntry> reportEntriesSecondFile = redactionLogConverterService.convertAndSort(redactionLogSecondFile, legalBasisMapping, mapOfEntityDisplayName); List<ReportRedactionEntry> reportEntriesSecondFile = redactionLogConverterService.convertAndSort(redactionLogSecondFile, legalBasisMapping, mapOfEntityDisplayName);
FileModel fileModelSecondFile = FileModel.builder().filename("secondFile").build(); FileModel fileModelSecondFile = FileModel.builder().filename("secondFile").build();
excelTemplateReportGenerationService.generateExcelReport(reportEntriesSecondFile, placeholders, "test", writeWorkbook, "dossierName", fileModelSecondFile, excelModel, true); excelTemplateReportGenerationService.generateExcelReport(reportEntriesSecondFile,
placeholders,
"test",
writeWorkbook,
"dossierName",
fileModelSecondFile,
excelModel,
true);
byte[] excelTemplateReport3 = excelTemplateReportGenerationService.toByteArray(writeWorkbook); byte[] excelTemplateReport3 = excelTemplateReportGenerationService.toByteArray(writeWorkbook);
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/Excel Report_multifile.xlsx")) { try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/Excel Report_multifile.xlsx")) {
@ -347,7 +387,9 @@ public class RedactionReportIntegrationTest {
ClassPathResource templateResource = new ClassPathResource("templates/Excel Report_PlaceholderTest.xlsx"); ClassPathResource templateResource = new ClassPathResource("templates/Excel Report_PlaceholderTest.xlsx");
var placeholders = buildPlaceHolderModel(Map.of("{{dossier_attribute.test1}}", "replaced_dossier_test1"), Map.of("{{file_attribute.test1}}", "replaced_file_test1", "{{file_attribute.test2}}", "replaced_file_test2"), List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream())))); var placeholders = buildPlaceHolderModel(Map.of("{{dossier_attribute.test1}}", "replaced_dossier_test1"),
Map.of("{{file_attribute.test1}}", "replaced_file_test1", "{{file_attribute.test2}}", "replaced_file_test2"),
List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream()))));
XSSFWorkbook readWorkbook = new XSSFWorkbook(templateResource.getInputStream()); XSSFWorkbook readWorkbook = new XSSFWorkbook(templateResource.getInputStream());
var excelModel = excelTemplateReportGenerationService.calculateExcelModel(readWorkbook.getSheetAt(0)); var excelModel = excelTemplateReportGenerationService.calculateExcelModel(readWorkbook.getSheetAt(0));
@ -362,8 +404,6 @@ public class RedactionReportIntegrationTest {
} }
private Map<String, String> createEntityDisplayNames(RedactionLog redactionLog) { private Map<String, String> createEntityDisplayNames(RedactionLog redactionLog) {
Type t1 = new Type(); Type t1 = new Type();
@ -391,7 +431,15 @@ public class RedactionReportIntegrationTest {
private PlaceholderModel buildPlaceHolderModel(Map<String, String> dossierAttributes, Map<String, String> fileAttributes, List<ImagePlaceholder> imagePlaceholders) { private PlaceholderModel buildPlaceHolderModel(Map<String, String> dossierAttributes, Map<String, String> fileAttributes, List<ImagePlaceholder> imagePlaceholders) {
var defaultPlaceHolder = new HashSet<>(Set.of(FILE_NAME_PLACEHOLDER, FORMAT_DATE_ISO_PLACEHOLDER, FORMAT_DATE_GER_PLACEHOLDER, FORMAT_DATE_ENG_PLACEHOLDER, FORMAT_TIME_ISO_PLACEHOLDER, DOSSIER_NAME_PLACEHOLDER, IUCLID_FUNCTION_PLACEHOLDER, SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER, SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER)); var defaultPlaceHolder = new HashSet<>(Set.of(FILE_NAME_PLACEHOLDER,
FORMAT_DATE_ISO_PLACEHOLDER,
FORMAT_DATE_GER_PLACEHOLDER,
FORMAT_DATE_ENG_PLACEHOLDER,
FORMAT_TIME_ISO_PLACEHOLDER,
DOSSIER_NAME_PLACEHOLDER,
IUCLID_FUNCTION_PLACEHOLDER,
SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER,
SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER));
defaultPlaceHolder.addAll(dossierAttributes.keySet()); defaultPlaceHolder.addAll(dossierAttributes.keySet());
defaultPlaceHolder.addAll(fileAttributes.keySet()); defaultPlaceHolder.addAll(fileAttributes.keySet());
return new PlaceholderModel(defaultPlaceHolder, imagePlaceholders, dossierAttributes, null, fileAttributes, new HashMap<>()); return new PlaceholderModel(defaultPlaceHolder, imagePlaceholders, dossierAttributes, null, fileAttributes, new HashMap<>());

View File

@ -1,5 +1,33 @@
package com.iqser.red.service.redaction.report.v1.server; package com.iqser.red.service.redaction.report.v1.server;
import static com.iqser.red.service.redaction.report.v1.server.utils.OsUtils.getTemporaryDirectory;
import static org.mockito.Mockito.when;
import java.io.FileOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.ClassPathResource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.Base64Utils;
import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -13,7 +41,14 @@ import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.do
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileModel; import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileModel;
import com.iqser.red.service.redaction.report.v1.api.model.ReportRequestMessage; import com.iqser.red.service.redaction.report.v1.api.model.ReportRequestMessage;
import com.iqser.red.service.redaction.report.v1.api.model.StoredFileInformation; import com.iqser.red.service.redaction.report.v1.api.model.StoredFileInformation;
import com.iqser.red.service.redaction.report.v1.server.client.*; import com.iqser.red.service.redaction.report.v1.server.client.DictionaryClient;
import com.iqser.red.service.redaction.report.v1.server.client.DossierAttributesClient;
import com.iqser.red.service.redaction.report.v1.server.client.DossierAttributesConfigClient;
import com.iqser.red.service.redaction.report.v1.server.client.DossierClient;
import com.iqser.red.service.redaction.report.v1.server.client.FileAttributesConfigClient;
import com.iqser.red.service.redaction.report.v1.server.client.FileStatusClient;
import com.iqser.red.service.redaction.report.v1.server.client.RedactionLogClient;
import com.iqser.red.service.redaction.report.v1.server.client.ReportTemplateClient;
import com.iqser.red.service.redaction.report.v1.server.configuration.MessagingConfiguration; import com.iqser.red.service.redaction.report.v1.server.configuration.MessagingConfiguration;
import com.iqser.red.service.redaction.report.v1.server.service.ReportGenerationService; import com.iqser.red.service.redaction.report.v1.server.service.ReportGenerationService;
import com.iqser.red.service.redaction.report.v1.server.utils.FileSystemBackedStorageService; import com.iqser.red.service.redaction.report.v1.server.utils.FileSystemBackedStorageService;
@ -24,30 +59,6 @@ import com.iqser.red.storage.commons.service.StorageService;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.*;
import org.springframework.core.io.ClassPathResource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.Base64Utils;
import java.io.FileOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import static com.iqser.red.service.redaction.report.v1.server.utils.OsUtils.getTemporaryDirectory;
import static org.mockito.Mockito.when;
@Slf4j @Slf4j
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@Import(RedactionReportV2IntegrationTest.TestConfiguration.class) @Import(RedactionReportV2IntegrationTest.TestConfiguration.class)
@ -197,7 +208,7 @@ public class RedactionReportV2IntegrationTest {
@SneakyThrows @SneakyThrows
public void testBasicExcelReportFlow() { public void testBasicExcelReportFlow() {
var reportRequestMessage = prepareFlow(1,"templates/Excel Report.xlsx"); var reportRequestMessage = prepareFlow(1, "templates/Excel Report.xlsx");
processRequest(reportRequestMessage, ".xlsx"); processRequest(reportRequestMessage, ".xlsx");
} }
@ -206,7 +217,7 @@ public class RedactionReportV2IntegrationTest {
@SneakyThrows @SneakyThrows
public void testMultifileWordReportFlow() { public void testMultifileWordReportFlow() {
var reportRequestMessage = prepareFlow(2,"templates/Justification Appendix A1.docx"); var reportRequestMessage = prepareFlow(2, "templates/Justification Appendix A1.docx");
processRequest(reportRequestMessage, ".docx"); processRequest(reportRequestMessage, ".docx");
} }
@ -215,7 +226,7 @@ public class RedactionReportV2IntegrationTest {
@SneakyThrows @SneakyThrows
public void test2FilesConcurrently() { public void test2FilesConcurrently() {
var reportRequestMessage = prepareFlow(1,"templates/report.xlsx", "templates/report-advanced.xlsx"); var reportRequestMessage = prepareFlow(1, "templates/report.xlsx", "templates/report-advanced.xlsx");
processRequest(reportRequestMessage, ".xlsx"); processRequest(reportRequestMessage, ".xlsx");
} }

View File

@ -1,13 +1,5 @@
package com.iqser.red.service.redaction.report.v1.server.utils; package com.iqser.red.service.redaction.report.v1.server.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.commons.jackson.ObjectMapperFactory;
import com.iqser.red.storage.commons.exception.StorageObjectDoesNotExist;
import com.iqser.red.storage.commons.service.StorageService;
import lombok.SneakyThrows;
import org.apache.commons.io.IOUtils;
import org.springframework.core.io.InputStreamResource;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -18,13 +10,26 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.io.IOUtils;
import org.springframework.core.io.InputStreamResource;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.commons.jackson.ObjectMapperFactory;
import com.iqser.red.storage.commons.exception.StorageObjectDoesNotExist;
import com.iqser.red.storage.commons.service.StorageService;
import lombok.SneakyThrows;
public class FileSystemBackedStorageService implements StorageService { public class FileSystemBackedStorageService implements StorageService {
private final Map<String, File> dataMap = new HashMap<>(); private final Map<String, File> dataMap = new HashMap<>();
public FileSystemBackedStorageService() { public FileSystemBackedStorageService() {
} }
@SneakyThrows @SneakyThrows
@Override @Override
public InputStreamResource getObject(String objectId) { public InputStreamResource getObject(String objectId) {
@ -37,48 +42,62 @@ public class FileSystemBackedStorageService implements StorageService {
} }
@Override @Override
public void deleteObject(String objectId) { public void deleteObject(String objectId) {
dataMap.remove(objectId); dataMap.remove(objectId);
} }
@Override @Override
public boolean objectExists(String objectId) { public boolean objectExists(String objectId) {
return dataMap.containsKey(objectId); return dataMap.containsKey(objectId);
} }
@Override @Override
public void init() { public void init() {
} }
@Override @Override
@SneakyThrows @SneakyThrows
public <T> void storeJSONObject(String objectId, T any) { public <T> void storeJSONObject(String objectId, T any) {
File tempFile = File.createTempFile("test", ".tmp"); File tempFile = File.createTempFile("test", ".tmp");
getMapper().writeValue(new FileOutputStream(tempFile), any); getMapper().writeValue(new FileOutputStream(tempFile), any);
dataMap.put(objectId, tempFile); dataMap.put(objectId, tempFile);
} }
private ObjectMapper getMapper() { private ObjectMapper getMapper() {
return ObjectMapperFactory.create(); return ObjectMapperFactory.create();
} }
@Override @Override
@SneakyThrows @SneakyThrows
public <T> T readJSONObject(String objectId, Class<T> clazz) { public <T> T readJSONObject(String objectId, Class<T> clazz) {
if (dataMap.get(objectId) == null || !dataMap.get(objectId).exists()) { if (dataMap.get(objectId) == null || !dataMap.get(objectId).exists()) {
throw new StorageObjectDoesNotExist("Stored object not found"); throw new StorageObjectDoesNotExist("Stored object not found");
} }
return getMapper().readValue(new FileInputStream(dataMap.get(objectId)), clazz); return getMapper().readValue(new FileInputStream(dataMap.get(objectId)), clazz);
} }
public List<String> listPaths() { public List<String> listPaths() {
return new ArrayList<>(dataMap.keySet()); return new ArrayList<>(dataMap.keySet());
} }
public List<String> listFilePaths() { public List<String> listFilePaths() {
return dataMap.values().stream().map(File::getAbsolutePath).collect(Collectors.toList()); return dataMap.values().stream().map(File::getAbsolutePath).collect(Collectors.toList());
} }
@ -86,6 +105,7 @@ public class FileSystemBackedStorageService implements StorageService {
@Override @Override
@SneakyThrows @SneakyThrows
public void storeObject(String objectId, InputStream stream) { public void storeObject(String objectId, InputStream stream) {
File tempFile = File.createTempFile("test", ".tmp"); File tempFile = File.createTempFile("test", ".tmp");
try (var fileOutputStream = new FileOutputStream(tempFile)) { try (var fileOutputStream = new FileOutputStream(tempFile)) {
@ -97,9 +117,11 @@ public class FileSystemBackedStorageService implements StorageService {
public void clearStorage() { public void clearStorage() {
this.dataMap.forEach((k, v) -> { this.dataMap.forEach((k, v) -> {
v.delete(); v.delete();
}); });
this.dataMap.clear(); this.dataMap.clear();
} }
} }