Initial Commit
This commit is contained in:
commit
666e6b1ba2
|
@ -0,0 +1,2 @@
|
|||
.idea/
|
||||
target/
|
|
@ -0,0 +1,148 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>file-transformer-document-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>file-transformer-document</artifactId>
|
||||
<version>${revision}</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>OpenDMP File Trasformer For MS-Doc and PDF</name>
|
||||
<description>OpenDMP File Trasformer For MS-Doc and PDF</description>
|
||||
<url>https://code-repo.d4science.org/MaDgiK-CITE/repository-deposit-zenodo</url>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>MIT License</name>
|
||||
<url>https://code-repo.d4science.org/MaDgiK-CITE/repository-deposit-zenodo/src/branch/master/LICENSE.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<name>CITE S.A.</name>
|
||||
<email>maven-central@cite.gr</email>
|
||||
<organization>CITE S.A.</organization>
|
||||
<organizationUrl>https://www.cite.gr</organizationUrl>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>scm:git:git://code-repo.d4science.org</connection>
|
||||
<developerConnection>scm:git:ssh://code-repo.d4science.org</developerConnection>
|
||||
<url>https://code-repo.d4science.org/MaDgiK-CITE/repository-deposit-zenodo</url>
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
<revision>1.0.0-SNAPSHOT</revision>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>file-transformer-base</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
<version>5.2.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>5.2.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.xmlgraphics</groupId>
|
||||
<artifactId>fop</artifactId>
|
||||
<version>2.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jsoup</groupId>
|
||||
<artifactId>jsoup</artifactId>
|
||||
<version>1.16.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20160810</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>eu.eudat.EuDatApplication</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>module-info.class</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.json</pattern>
|
||||
<shadedPattern>zenodorepository.shaded.org.json</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,9 @@
|
|||
package eu.eudat.file.transformer.configuration;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({FilePathProperties.class})
|
||||
public class FilePathConfiguration {
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package eu.eudat.file.transformer.configuration;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.bind.ConstructorBinding;
|
||||
|
||||
@ConfigurationProperties(prefix = "file.template")
|
||||
public class FilePathProperties {
|
||||
private final String wordTemplate;
|
||||
private final String pidTemplate;
|
||||
private final String wordDescriptionTemplate;
|
||||
|
||||
@ConstructorBinding
|
||||
public FilePathProperties(String wordTemplate, String pidTemplate, String wordDescriptionTemplate) {
|
||||
this.wordTemplate = wordTemplate;
|
||||
this.pidTemplate = pidTemplate;
|
||||
this.wordDescriptionTemplate = wordDescriptionTemplate;
|
||||
}
|
||||
|
||||
public String getWordTemplate() {
|
||||
return wordTemplate;
|
||||
}
|
||||
|
||||
public String getPidTemplate() {
|
||||
return pidTemplate;
|
||||
}
|
||||
|
||||
public String getWordDescriptionTemplate() {
|
||||
return wordDescriptionTemplate;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package eu.eudat.file.transformer.configuration;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({FileStorageProperties.class})
|
||||
public class FileStorageConfiguration {
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package eu.eudat.file.transformer.configuration;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.bind.ConstructorBinding;
|
||||
|
||||
@ConfigurationProperties(prefix = "file.storage")
|
||||
public class FileStorageProperties {
|
||||
private final String temp;
|
||||
|
||||
@ConstructorBinding
|
||||
public FileStorageProperties(String temp) {
|
||||
this.temp = temp;
|
||||
}
|
||||
|
||||
public String getTemp() {
|
||||
return temp;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package eu.eudat.file.transformer.configuration;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({PdfProperties.class})
|
||||
public class PdfConfiguration {
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package eu.eudat.file.transformer.configuration;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.bind.ConstructorBinding;
|
||||
|
||||
@ConfigurationProperties(prefix = "pdf.converter")
|
||||
public class PdfProperties {
|
||||
private final String url;
|
||||
|
||||
@ConstructorBinding
|
||||
public PdfProperties(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,623 @@
|
|||
package eu.eudat.file.transformer.executor;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.file.transformer.configuration.FilePathProperties;
|
||||
import eu.eudat.file.transformer.configuration.FileStorageProperties;
|
||||
import eu.eudat.file.transformer.configuration.PdfProperties;
|
||||
import eu.eudat.file.transformer.entities.user.composite.PagedDatasetProfile;
|
||||
import eu.eudat.file.transformer.enums.*;
|
||||
import eu.eudat.file.transformer.enums.ReferenceType;
|
||||
import eu.eudat.file.transformer.model.*;
|
||||
import eu.eudat.file.transformer.model.dmpblueprintdefinition.ExtraField;
|
||||
import eu.eudat.file.transformer.model.dmpblueprintdefinition.Field;
|
||||
import eu.eudat.file.transformer.model.dmpblueprintdefinition.Section;
|
||||
import eu.eudat.file.transformer.model.dmpblueprintdefinition.SystemField;
|
||||
import eu.eudat.file.transformer.model.enums.FileFormats;
|
||||
import eu.eudat.file.transformer.model.file.FileEnvelope;
|
||||
import eu.eudat.file.transformer.model.file.FileEnvelopeInternal;
|
||||
import eu.eudat.file.transformer.services.visibility.VisibilityRuleService;
|
||||
import eu.eudat.file.transformer.services.visibility.VisibilityRuleServiceImpl;
|
||||
import eu.eudat.file.transformer.utils.descriptionTemplate.DescriptionTemplateService;
|
||||
import eu.eudat.file.transformer.utils.pdf.PDFUtils;
|
||||
import eu.eudat.file.transformer.utils.types.ParagraphStyle;
|
||||
import eu.eudat.file.transformer.utils.word.WordBuilder;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
import javax.management.InvalidApplicationException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
@Component
|
||||
public class WordFileTransformer implements FileTransformerExecutor {
|
||||
private final static Logger logger = LoggerFactory.getLogger(WordFileTransformer.class);
|
||||
|
||||
private final FilePathProperties fileTemplateProperties;
|
||||
private final FileStorageProperties fileStorageProperties;
|
||||
private final PdfProperties pdfProperties;
|
||||
private final ApplicationContext applicationContext;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Autowired
|
||||
public WordFileTransformer(FilePathProperties fileTemplateProperties, FileStorageProperties fileStorageProperties, PdfProperties pdfProperties, ApplicationContext applicationContext) {
|
||||
this.fileTemplateProperties = fileTemplateProperties;
|
||||
this.fileStorageProperties = fileStorageProperties;
|
||||
this.pdfProperties = pdfProperties;
|
||||
this.applicationContext = applicationContext;
|
||||
this.objectMapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileEnvelope exportDmp(DmpFileTransformerModel dmp, ExtraPropertiesModel properties) throws IOException {
|
||||
FileFormats fileFormat = FileFormats.of(properties.getFormat());
|
||||
return switch (fileFormat) {
|
||||
case DOCX -> getWordDocument(dmp);
|
||||
case PDF -> {
|
||||
FileEnvelopeInternal wordFile = getWordDocument(dmp, true);
|
||||
yield getPdfDocument(wordFile);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileEnvelope exportDescription(DescriptionFileTransformerModel descriptionFileTransformerModel, ExtraPropertiesModel properties) throws InvalidApplicationException, IOException {
|
||||
FileFormats fileFormat = FileFormats.of(properties.getFormat());
|
||||
return switch (fileFormat) {
|
||||
case DOCX -> getDescriptionWordDocument(descriptionFileTransformerModel);
|
||||
case PDF -> {
|
||||
FileEnvelopeInternal wordFile = getDescriptionWordDocumentInternal(descriptionFileTransformerModel);
|
||||
yield getPdfDocument(wordFile);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DmpFileTransformerModel importFileToDmp(FileEnvelope envelope) {
|
||||
//Nothing to do here
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DescriptionFileTransformerModel importFileToDescription(FileEnvelope envelope) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSupportedFileFormats() {
|
||||
return Arrays.stream(FileFormats.values()).map(FileFormats::getValue).toList();
|
||||
}
|
||||
|
||||
private FileEnvelope getPdfDocument(FileEnvelopeInternal wordFile) throws IOException {
|
||||
File pdfFile = PDFUtils.convertToPDF(wordFile, fileStorageProperties.getTemp(), pdfProperties.getUrl());
|
||||
FileEnvelope result = new FileEnvelope();
|
||||
result.setFilename(wordFile.getFilename().replaceAll(".docx", ".pdf"));
|
||||
try (FileInputStream fis = new FileInputStream(pdfFile)) {
|
||||
result.setFile(fis.readAllBytes());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private FileEnvelope getWordDocument(DmpFileTransformerModel dmp) throws IOException {
|
||||
FileEnvelopeInternal wordFile = getWordDocument(dmp, true);
|
||||
FileEnvelope result = new FileEnvelope();
|
||||
result.setFilename(wordFile.getFilename());
|
||||
try (FileInputStream fis = new FileInputStream(wordFile.getFile())) {
|
||||
result.setFile(fis.readAllBytes());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private FileEnvelopeInternal getWordDocument(DmpFileTransformerModel dmpEntity, Boolean versioned) throws IOException {
|
||||
WordBuilder wordBuilder = new WordBuilder(fileTemplateProperties, fileStorageProperties);
|
||||
VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl();
|
||||
XWPFDocument document = new XWPFDocument(new FileInputStream(ResourceUtils.getFile(fileTemplateProperties.getWordTemplate())));
|
||||
|
||||
wordBuilder.fillFirstPage(dmpEntity, null, document, false);
|
||||
|
||||
List<Reference> funders = dmpEntity.getDmpReferences().stream().filter(dmpReference -> dmpReference.getReference().getType().equals(ReferenceType.Funder) && dmpReference.getReference().getIsActive().equals(IsActive.Active)).map(DmpReference::getReference).toList();
|
||||
List<Reference> grants = dmpEntity.getDmpReferences().stream().filter(referenceFileModel -> referenceFileModel.getReference().getType().equals(ReferenceType.Grants) && referenceFileModel.getReference().getIsActive().equals(IsActive.Active)).map(DmpReference::getReference).toList();
|
||||
List<Reference> researchers = dmpEntity.getDmpReferences().stream().filter(referenceFileModel -> referenceFileModel.getReference().getType().equals(ReferenceType.Researcher)).map(DmpReference::getReference).toList();
|
||||
List<Reference> organizations = dmpEntity.getDmpReferences().stream().filter(referenceFileModel -> referenceFileModel.getReference().getType().equals(ReferenceType.Organizations)).map(DmpReference::getReference).toList();
|
||||
List<Reference> projects = dmpEntity.getDmpReferences().stream().filter(referenceFileModel -> referenceFileModel.getReference().getType().equals(ReferenceType.Project) && referenceFileModel.getReference().getIsActive().equals(IsActive.Active)).map(DmpReference::getReference).toList();
|
||||
|
||||
// int powered_pos = document.getParagraphs().size() - 3;
|
||||
int powered_pos = wordBuilder.findPosOfPoweredBy(document);
|
||||
XWPFParagraph powered_par = null;
|
||||
XWPFParagraph argos_img_par = null;
|
||||
if(powered_pos != -1) {
|
||||
powered_par = document.getParagraphArray(powered_pos);
|
||||
argos_img_par = document.getParagraphArray(powered_pos + 1);
|
||||
}
|
||||
|
||||
|
||||
// // DMP info on top of the document.
|
||||
// wordBuilder.addParagraphContent("Data Management Plan Information", document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
||||
// // DMP title custom style.
|
||||
// wordBuilder.addParagraphContent(dmpEntity.getLabel(), document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
||||
// wordBuilder.addParagraphContent(dmpEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO);
|
||||
//
|
||||
// wordBuilder.addParagraphContent("Funder", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||
// if (dmpEntity.getGrant().getFunder() != null)
|
||||
// wordBuilder.addParagraphContent(dmpEntity.getGrant().getFunder().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
//
|
||||
// wordBuilder.addParagraphContent("Grant", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||
// wordBuilder.addParagraphContent(dmpEntity.getGrant().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
//
|
||||
// wordBuilder.addParagraphContent("Organisations", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||
// if (dmpEntity.getOrganisations().size() > 0) {
|
||||
// wordBuilder.addParagraphContent(dmpEntity.getOrganisations().stream().map(Organisation::getLabel).collect(Collectors.joining(", "))
|
||||
// , document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
// }
|
||||
//
|
||||
// wordBuilder.addParagraphContent("Researchers", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||
// if (dmpEntity.getResearchers().size() > 0) {
|
||||
// wordBuilder.addParagraphContent(dmpEntity.getResearchers().stream().map(Researcher::getLabel).collect(Collectors.joining(", "))
|
||||
// , document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
// }
|
||||
//
|
||||
// /*wordBuilder.addParagraphContent("DMP Profile", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
||||
// if (dmpEntity.getProfile() != null){
|
||||
// wordBuilder.addParagraphContent(dmpEntity.getProfile().getLabel(), document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
// }*/
|
||||
//
|
||||
// // Page break at the end of the DMP title.
|
||||
// XWPFParagraph parBreakDMP = document.createParagraph();
|
||||
// parBreakDMP.setPageBreak(true);
|
||||
//
|
||||
// wordBuilder.addParagraphContent("Datasets", document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
||||
// // Space below Datasets.
|
||||
// XWPFParagraph parBreakDatasets = document.createParagraph();
|
||||
|
||||
DmpBlueprint dmpBlueprint = dmpEntity.getBlueprint();
|
||||
for(Section section: dmpBlueprint.getDefinition().getSections()){
|
||||
wordBuilder.addParagraphContent("Section " + section.getOrdinal(), document, ParagraphStyle.HEADER1, BigInteger.ZERO, 0);
|
||||
XWPFParagraph sectionInfoParagraph = document.createParagraph();
|
||||
sectionInfoParagraph.setSpacingBetween(1.0);
|
||||
XWPFRun runSectionTitle = sectionInfoParagraph.createRun();
|
||||
runSectionTitle.setText("Title: ");
|
||||
runSectionTitle.setColor("000000");
|
||||
XWPFRun runSectionTitleText = sectionInfoParagraph.createRun();
|
||||
runSectionTitleText.setText(section.getLabel());
|
||||
runSectionTitleText.setColor("116a78");
|
||||
XWPFParagraph sectionDescriptionParagraph = document.createParagraph();
|
||||
XWPFRun runSectionDescription = sectionDescriptionParagraph.createRun();
|
||||
runSectionDescription.setText("Description: ");
|
||||
runSectionDescription.setColor("000000");
|
||||
XWPFRun runSectionDescriptionText = sectionDescriptionParagraph.createRun();
|
||||
runSectionDescriptionText.setText(section.getDescription());
|
||||
runSectionDescriptionText.setColor("116a78");
|
||||
|
||||
wordBuilder.addParagraphContent("Section Fields", document, ParagraphStyle.HEADER2, BigInteger.ZERO, 0);
|
||||
section.getFields().sort(Comparator.comparingInt(Field::getOrdinal));
|
||||
for(Field field: section.getFields()){
|
||||
if(field.getCategory() == DmpBlueprintFieldCategory.System){
|
||||
SystemField systemField = (SystemField) field;
|
||||
XWPFParagraph systemFieldParagraph = document.createParagraph();
|
||||
systemFieldParagraph.setSpacingBetween(1.0);
|
||||
XWPFRun runSyStemFieldTitle = systemFieldParagraph.createRun();
|
||||
runSyStemFieldTitle.setText("Title: ");
|
||||
runSyStemFieldTitle.setColor("000000");
|
||||
XWPFRun runSystemFieldTitleText = systemFieldParagraph.createRun();
|
||||
runSystemFieldTitleText.setText(systemField.getLabel());
|
||||
runSystemFieldTitleText.setColor("116a78");
|
||||
if(systemField.getDescription() != null && !systemField.getDescription().isEmpty()){
|
||||
XWPFParagraph systemFieldDescription = document.createParagraph();
|
||||
systemFieldDescription.setSpacingBetween(1.0);
|
||||
XWPFRun runSyStemFieldDescription = systemFieldDescription.createRun();
|
||||
runSyStemFieldDescription.setText("Description: ");
|
||||
runSyStemFieldDescription.setColor("000000");
|
||||
XWPFRun runSystemFieldDescriptionText = systemFieldDescription.createRun();
|
||||
runSystemFieldDescriptionText.setText(systemField.getDescription());
|
||||
runSystemFieldDescriptionText.setColor("116a78");
|
||||
}
|
||||
XWPFParagraph systemFieldInput = document.createParagraph();
|
||||
systemFieldInput.setSpacingBetween(1.0);
|
||||
XWPFRun runInput = systemFieldInput.createRun();
|
||||
runInput.setText("Input: ");
|
||||
runInput.setColor("000000");
|
||||
Map<String, Object> dmpProperties = objectMapper.readValue(dmpEntity.getProperties(), HashMap.class);
|
||||
switch (systemField.getSystemFieldType()) {
|
||||
case Text:
|
||||
XWPFRun runTitle = systemFieldInput.createRun();
|
||||
runTitle.setText(dmpEntity.getLabel());
|
||||
runTitle.setColor("116a78");
|
||||
break;
|
||||
case HtmlText:
|
||||
XWPFRun runDescription = systemFieldInput.createRun();
|
||||
runDescription.setText(dmpEntity.getDescription());
|
||||
runDescription.setColor("116a78");
|
||||
break;
|
||||
case Researchers:
|
||||
for(Reference researcher: researchers){
|
||||
XWPFRun runResearcher = systemFieldInput.createRun();
|
||||
runResearcher.setText("• " + researcher.getLabel());
|
||||
runResearcher.setColor("116a78");
|
||||
}
|
||||
break;
|
||||
case Organizations:
|
||||
for(Reference organisation: organizations){
|
||||
XWPFRun runOrganisation = systemFieldInput.createRun();
|
||||
runOrganisation.setText("• " + organisation.getLabel());
|
||||
runOrganisation.setColor("116a78");
|
||||
}
|
||||
break;
|
||||
/* case Language:
|
||||
XWPFRun runLanguage = systemFieldInput.createRun();
|
||||
runLanguage.setText(dmpProperties.get("language").toString());
|
||||
runLanguage.setColor("116a78");
|
||||
break;*/
|
||||
case Contact:
|
||||
XWPFRun runContact = systemFieldInput.createRun();
|
||||
runContact.setText(dmpEntity.getCreator().getName());
|
||||
runContact.setColor("116a78");
|
||||
break;
|
||||
case Funder:
|
||||
if (!funders.isEmpty()) {
|
||||
XWPFRun runFunder = systemFieldInput.createRun();
|
||||
runFunder.setText(funders.get(0).getLabel());
|
||||
runFunder.setColor("116a78");
|
||||
}
|
||||
break;
|
||||
case Grant:
|
||||
if (!grants.isEmpty()) {
|
||||
XWPFRun runGrant = systemFieldInput.createRun();
|
||||
runGrant.setText(grants.get(0).getLabel());
|
||||
runGrant.setColor("116a78");
|
||||
}
|
||||
break;
|
||||
case Project:
|
||||
if (!projects.isEmpty()) {
|
||||
XWPFRun runProject = systemFieldInput.createRun();
|
||||
runProject.setText(projects.get(0).getLabel());
|
||||
runProject.setColor("116a78");
|
||||
}
|
||||
break;
|
||||
case License:
|
||||
if (dmpProperties.containsKey("license")) {
|
||||
XWPFRun runLicense = systemFieldInput.createRun();
|
||||
runLicense.setText(dmpProperties.get("license").toString());
|
||||
runLicense.setColor("116a78");
|
||||
}
|
||||
break;
|
||||
case AccessRights:
|
||||
if (dmpProperties.containsKey("visible")) {
|
||||
XWPFRun runAccessRights = systemFieldInput.createRun();
|
||||
runAccessRights.setText(dmpProperties.get("visible").toString());
|
||||
runAccessRights.setColor("116a78");
|
||||
}
|
||||
break;
|
||||
}
|
||||
document.createParagraph();
|
||||
}
|
||||
else if(field.getCategory() == DmpBlueprintFieldCategory.Extra){
|
||||
ExtraField extraField = (ExtraField) field;
|
||||
XWPFParagraph extraFieldParagraph = document.createParagraph();
|
||||
extraFieldParagraph.setSpacingBetween(1.0);
|
||||
XWPFRun runExtraFieldLabel = extraFieldParagraph.createRun();
|
||||
runExtraFieldLabel.setText(extraField.getLabel());
|
||||
runExtraFieldLabel.setColor("116a78");
|
||||
if(extraField.getDescription() != null && !extraField.getDescription().isEmpty()){
|
||||
XWPFRun runExtraFieldDescription = extraFieldParagraph.createRun();
|
||||
runExtraFieldDescription.setText(extraField.getDescription());
|
||||
runExtraFieldDescription.setColor("116a78");
|
||||
}
|
||||
XWPFRun runExtraFieldInput = extraFieldParagraph.createRun();
|
||||
Map dmpProperties = objectMapper.readValue(dmpEntity.getProperties(), HashMap.class);
|
||||
if (dmpProperties.containsKey(field.getId()) && dmpProperties.get(field.getId()) != null) {
|
||||
runExtraFieldInput.setText((String) dmpProperties.get(field.getId()));
|
||||
}
|
||||
runExtraFieldInput.setColor("116a78");
|
||||
}
|
||||
}
|
||||
|
||||
final Boolean isFinalized = dmpEntity.getStatus() == DmpStatus.Finalized;
|
||||
final Boolean isPublic = dmpEntity.getPublicAfter() != null && dmpEntity.getPublicAfter().isAfter(Instant.now());
|
||||
List<DescriptionFileTransformerModel> descriptions = dmpEntity.getDescriptions().stream()
|
||||
.filter(item -> item.getStatus() != DescriptionStatus.Canceled)
|
||||
.filter(item -> item.getIsActive() != IsActive.Inactive)
|
||||
.filter(item -> !isPublic && !isFinalized || item.getStatus() == DescriptionStatus.Finalized)
|
||||
.filter(item -> item.getDmpDescriptionTemplate().getSectionId().equals(section.getId())) //TODO
|
||||
.sorted(Comparator.comparing(DescriptionFileTransformerModel::getCreatedAt)).toList();
|
||||
List<eu.eudat.file.transformer.model.DescriptionTemplate> descriptionTemplates = descriptions.stream().map(DescriptionFileTransformerModel::getDescriptionTemplate).toList();
|
||||
|
||||
if(!descriptionTemplates.isEmpty()){
|
||||
wordBuilder.addParagraphContent("Section descriptions", document, ParagraphStyle.HEADER2, BigInteger.ZERO, 0);
|
||||
wordBuilder.addParagraphContent("Description Templates", document, ParagraphStyle.HEADER4, BigInteger.ZERO, 0);
|
||||
for(DescriptionTemplate descriptionTemplateEntity : descriptionTemplates){
|
||||
XWPFParagraph templateParagraph = document.createParagraph();
|
||||
XWPFRun runTemplateLabel = templateParagraph.createRun();
|
||||
runTemplateLabel.setText("• " + descriptionTemplateEntity.getLabel());
|
||||
runTemplateLabel.setColor("116a78");
|
||||
}
|
||||
|
||||
|
||||
descriptions
|
||||
.forEach(datasetEntity -> {
|
||||
eu.eudat.file.transformer.model.DescriptionTemplate descriptionTemplateFileModel = datasetEntity.getDescriptionTemplate();
|
||||
|
||||
// Dataset Description custom style.
|
||||
XWPFParagraph datasetDescriptionParagraph = document.createParagraph();
|
||||
datasetDescriptionParagraph.setStyle("Heading4");
|
||||
datasetDescriptionParagraph.setSpacingBetween(1.5);
|
||||
XWPFRun datasetDescriptionRun = datasetDescriptionParagraph.createRun();
|
||||
datasetDescriptionRun.setText("Dataset Description");
|
||||
//datasetDescriptionRun.setColor("2E75B6");
|
||||
//datasetDescriptionRun.setBold(true);
|
||||
datasetDescriptionRun.setFontSize(15);
|
||||
|
||||
|
||||
// Custom style for the Dataset title.
|
||||
//wordBuilder.addParagraphContent("Title: " + datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
||||
XWPFParagraph datasetLabelParagraph = document.createParagraph();
|
||||
// datasetLabelParagraph.setStyle("Heading2");
|
||||
datasetLabelParagraph.setSpacingBetween(1.0);
|
||||
XWPFRun runDatasetTitle1 = datasetLabelParagraph.createRun();
|
||||
runDatasetTitle1.setText("Title: ");
|
||||
runDatasetTitle1.setColor("000000");
|
||||
//runDatasetTitle1.setBold(true);
|
||||
//runDatasetTitle1.setFontSize(12);
|
||||
XWPFRun runDatasetTitle = datasetLabelParagraph.createRun();
|
||||
runDatasetTitle.setText(datasetEntity.getLabel());
|
||||
runDatasetTitle.setColor("116a78");
|
||||
//runDatasetTitle.setBold(true);
|
||||
//runDatasetTitle.setFontSize(12);
|
||||
|
||||
XWPFParagraph datasetTemplateParagraph = document.createParagraph();
|
||||
// datasetTemplateParagraph.setStyle("Heading3");
|
||||
XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
|
||||
runDatasetTemplate1.setText("Template: ");
|
||||
runDatasetTemplate1.setColor("000000");
|
||||
//runDatasetTemplate1.setBold(true);
|
||||
//runDatasetTemplate1.setFontSize(12);
|
||||
XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
|
||||
runDatasetTemplate.setText(descriptionTemplateFileModel.getLabel());
|
||||
runDatasetTemplate.setColor("116a78");
|
||||
//runDatasetTemplate.setBold(true);
|
||||
//runDatasetTemplate.setFontSize(12);
|
||||
|
||||
// /*XWPFParagraph externalReferencesParagraph = document.createParagraph();
|
||||
// externalReferencesParagraph.setStyle("Heading3");
|
||||
// XWPFRun externalReferencesRun = externalReferencesParagraph.createRun();
|
||||
// externalReferencesRun.setText("External References");
|
||||
// externalReferencesRun.setColor("2E75B6");
|
||||
// externalReferencesRun.setBold(true);
|
||||
// externalReferencesRun.setFontSize(12);
|
||||
//
|
||||
// wordBuilder.addParagraphContent("Data Repositories", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
|
||||
// if (datasetEntity.getDatasetDataRepositories().size() > 0) {
|
||||
// wordBuilder.addParagraphContent(datasetEntity.getDatasetDataRepositories().stream().map(DatasetDataRepository::getDataRepository).map(DataRepository::getLabel).collect(Collectors.joining(", "))
|
||||
// , document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
// }
|
||||
// wordBuilder.addParagraphContent("External Datasets", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
|
||||
// if (datasetEntity.getDatasetExternalDatasets().size() > 0) {
|
||||
// wordBuilder.addParagraphContent(datasetEntity.getDatasetExternalDatasets().stream().map(DatasetExternalDataset::getExternalDataset).map(ExternalDataset::getLabel).collect(Collectors.joining(", "))
|
||||
// , document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
// }
|
||||
// wordBuilder.addParagraphContent("Registries", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
|
||||
// if (datasetEntity.getRegistries().size() > 0) {
|
||||
// wordBuilder.addParagraphContent(datasetEntity.getRegistries().stream().map(Registry::getLabel).collect(Collectors.joining(", "))
|
||||
// , document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
// }
|
||||
// wordBuilder.addParagraphContent("Services", document, ParagraphStyle.HEADER4, BigInteger.ZERO);
|
||||
// if (datasetEntity.getServices().size() > 0) {
|
||||
// wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
|
||||
// , document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
// }
|
||||
// *//*wordBuilder.addParagraphContent("Tags", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||
// if (datasetEntity.().size() > 0) {
|
||||
// wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
|
||||
// , document, ParagraphStyle.HEADER4, BigInteger.ZERO);
|
||||
// }*/
|
||||
//
|
||||
//
|
||||
|
||||
XWPFParagraph datasetDescParagraph = document.createParagraph();
|
||||
XWPFRun runDatasetDescription1 = datasetDescParagraph.createRun();
|
||||
runDatasetDescription1.setText("Description: ");
|
||||
runDatasetDescription1.setColor("000000");
|
||||
XWPFRun runDatasetDescription = datasetDescParagraph.createRun();
|
||||
runDatasetDescription.setText(descriptionTemplateFileModel.getLabel());
|
||||
runDatasetDescription.setColor("116a78");
|
||||
//wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO, 0);
|
||||
|
||||
document.createParagraph();
|
||||
|
||||
|
||||
try {
|
||||
PagedDatasetProfile pagedDatasetProfile = DescriptionTemplateService.getPagedProfile(datasetEntity);
|
||||
|
||||
visibilityRuleService.setProperties(datasetEntity.getProperties());
|
||||
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
||||
//pagedDatasetProfile = this.objectMapper.readValue(this.objectMapper.writeValueAsString(pagedDatasetProfile), eu.eudat.file.transformer.model.descriptiontemplatedefinition.Definition.class);
|
||||
|
||||
wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService);
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
// Page break at the end of the Dataset.
|
||||
XWPFParagraph parBreakDataset = document.createParagraph();
|
||||
parBreakDataset.setPageBreak(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// // Removes the top empty headings.
|
||||
// for (int i = 0; i < 6; i++) {
|
||||
// document.removeBodyElement(0);
|
||||
// }
|
||||
|
||||
|
||||
if(powered_pos != -1) {
|
||||
document.getLastParagraph().setPageBreak(false);
|
||||
document.createParagraph();
|
||||
document.setParagraph(powered_par, document.getParagraphs().size() - 1);
|
||||
|
||||
document.createParagraph();
|
||||
document.setParagraph(argos_img_par, document.getParagraphs().size() - 1);
|
||||
|
||||
document.removeBodyElement(powered_pos + 1);
|
||||
document.removeBodyElement(powered_pos + 1);
|
||||
}
|
||||
|
||||
wordBuilder.fillFooter(dmpEntity, null, document, false);
|
||||
|
||||
String fileName;
|
||||
if (!grants.isEmpty() && grants.get(0).getLabel() != null) {
|
||||
fileName = "DMP_" + grants.get(0).getLabel();
|
||||
}
|
||||
else {
|
||||
fileName = "DMP_" + dmpEntity.getLabel();
|
||||
}
|
||||
if (versioned) {
|
||||
fileName += "_" + dmpEntity.getVersion();
|
||||
}
|
||||
// fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", "");
|
||||
FileEnvelopeInternal exportEnvelope = new FileEnvelopeInternal();
|
||||
exportEnvelope.setFilename(fileName + ".docx");
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
File exportFile = new File(fileStorageProperties.getTemp() + "\\" + uuid + ".docx");
|
||||
FileOutputStream out = new FileOutputStream(exportFile);
|
||||
document.write(out);
|
||||
out.close();
|
||||
exportEnvelope.setFile(exportFile);
|
||||
|
||||
return exportEnvelope;
|
||||
}
|
||||
|
||||
private FileEnvelope getDescriptionWordDocument(DescriptionFileTransformerModel descriptionFileTransformerModel) throws IOException {
|
||||
FileEnvelopeInternal wordFile = getDescriptionWordDocumentInternal(descriptionFileTransformerModel);
|
||||
FileEnvelope fileEnvelope = new FileEnvelope();
|
||||
fileEnvelope.setFilename(wordFile.getFilename());
|
||||
try (FileInputStream fis = new FileInputStream(wordFile.getFile())) {
|
||||
fileEnvelope.setFile(fis.readAllBytes());
|
||||
}
|
||||
return fileEnvelope;
|
||||
}
|
||||
|
||||
private FileEnvelopeInternal getDescriptionWordDocumentInternal(DescriptionFileTransformerModel descriptionFileTransformerModelEntityEntity) throws IOException {
|
||||
WordBuilder wordBuilder = new WordBuilder(fileTemplateProperties, fileStorageProperties);
|
||||
DmpFileTransformerModel dmpEntity = descriptionFileTransformerModelEntityEntity.getDmp();
|
||||
if (dmpEntity == null) {
|
||||
throw new IllegalArgumentException("Dmp is invalid");
|
||||
}
|
||||
XWPFDocument document = new XWPFDocument(new FileInputStream(ResourceUtils.getFile(fileTemplateProperties.getWordDescriptionTemplate())));
|
||||
VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl();
|
||||
|
||||
wordBuilder.fillFirstPage(dmpEntity, descriptionFileTransformerModelEntityEntity, document, true);
|
||||
wordBuilder.fillFooter(dmpEntity, descriptionFileTransformerModelEntityEntity, document, true);
|
||||
|
||||
int powered_pos = wordBuilder.findPosOfPoweredBy(document);
|
||||
XWPFParagraph powered_par = null;
|
||||
XWPFParagraph argos_img_par = null;
|
||||
if(powered_pos != -1) {
|
||||
powered_par = document.getParagraphArray(powered_pos);
|
||||
argos_img_par = document.getParagraphArray(powered_pos + 1);
|
||||
}
|
||||
|
||||
// wordBuilder.addParagraphContent(datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO);
|
||||
|
||||
// Space below Dataset title.
|
||||
// XWPFParagraph parBreakDataset = document.createParagraph();
|
||||
//
|
||||
// XWPFParagraph datasetTemplateParagraph = document.createParagraph();
|
||||
// datasetTemplateParagraph.setStyle("Heading2");
|
||||
// XWPFRun runDatasetTemplate1 = datasetTemplateParagraph.createRun();
|
||||
// runDatasetTemplate1.setText("Template: ");
|
||||
// runDatasetTemplate1.setBold(true);
|
||||
// runDatasetTemplate1.setFontSize(12);
|
||||
// XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
|
||||
// runDatasetTemplate.setText(datasetEntity.getProfile().getLabel());
|
||||
// runDatasetTemplate.setColor("2E75B6");
|
||||
// runDatasetTemplate.setBold(true);
|
||||
// runDatasetTemplate.setFontSize(12);
|
||||
//
|
||||
// wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO);
|
||||
|
||||
/*XWPFParagraph externalReferencesParagraph = document.createParagraph();
|
||||
externalReferencesParagraph.setStyle("Heading2");
|
||||
XWPFRun externalReferencesRun = externalReferencesParagraph.createRun();
|
||||
externalReferencesRun.setText("External References");
|
||||
externalReferencesRun.setColor("2E75B6");
|
||||
externalReferencesRun.setBold(true);
|
||||
externalReferencesRun.setFontSize(12);
|
||||
|
||||
wordBuilder.addParagraphContent("Data Repositories", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||
if (datasetEntity.getDatasetDataRepositories().size() > 0) {
|
||||
wordBuilder.addParagraphContent(datasetEntity.getDatasetDataRepositories().stream().map(DatasetDataRepository::getDataRepository).map(DataRepository::getLabel).collect(Collectors.joining(", "))
|
||||
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
}
|
||||
wordBuilder.addParagraphContent("External Datasets", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||
if (datasetEntity.getDatasetExternalDatasets().size() > 0) {
|
||||
wordBuilder.addParagraphContent(datasetEntity.getDatasetExternalDatasets().stream().map(DatasetExternalDataset::getExternalDataset).map(ExternalDataset::getLabel).collect(Collectors.joining(", "))
|
||||
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
}
|
||||
wordBuilder.addParagraphContent("Registries", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||
if (datasetEntity.getRegistries().size() > 0) {
|
||||
wordBuilder.addParagraphContent(datasetEntity.getRegistries().stream().map(Registry::getLabel).collect(Collectors.joining(", "))
|
||||
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
}
|
||||
wordBuilder.addParagraphContent("Services", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||
if (datasetEntity.getServices().size() > 0) {
|
||||
wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
|
||||
, document, ParagraphStyle.TEXT, BigInteger.ZERO);
|
||||
}*/
|
||||
/*wordBuilder.addParagraphContent("Tags", document, ParagraphStyle.HEADER3, BigInteger.ZERO);
|
||||
if (datasetEntity.().size() > 0) {
|
||||
wordBuilder.addParagraphContent(datasetEntity.getServices().stream().map(DatasetService::getService).map(Service::getLabel).collect(Collectors.joining(", "))
|
||||
, document, ParagraphStyle.HEADER4, BigInteger.ZERO);
|
||||
}*/
|
||||
|
||||
// wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO);
|
||||
PagedDatasetProfile pagedDatasetProfile = DescriptionTemplateService.getPagedProfile(descriptionFileTransformerModelEntityEntity);
|
||||
visibilityRuleService.setProperties(descriptionFileTransformerModelEntityEntity.getProperties());
|
||||
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
||||
wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService);
|
||||
String label = descriptionFileTransformerModelEntityEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", "");
|
||||
// File exportFile = new File(label + ".docx");
|
||||
|
||||
// Removes the top empty headings.
|
||||
// for (int i = 0; i < 6; i++) {
|
||||
// document.removeBodyElement(0);
|
||||
// }
|
||||
|
||||
if(powered_pos != -1) {
|
||||
document.getLastParagraph().setPageBreak(false);
|
||||
document.createParagraph();
|
||||
document.setParagraph(powered_par, document.getParagraphs().size() - 1);
|
||||
|
||||
document.createParagraph();
|
||||
document.setParagraph(argos_img_par, document.getParagraphs().size() - 1);
|
||||
|
||||
document.removeBodyElement(powered_pos + 1);
|
||||
document.removeBodyElement(powered_pos + 1);
|
||||
}
|
||||
|
||||
label = descriptionFileTransformerModelEntityEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", "");
|
||||
FileEnvelopeInternal exportEnvelope = new FileEnvelopeInternal();
|
||||
exportEnvelope.setFilename(label + ".docx");
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
File exportFile = new File(fileStorageProperties.getTemp() + uuid + ".docx");
|
||||
FileOutputStream out = new FileOutputStream(exportFile);
|
||||
document.write(out);
|
||||
out.close();
|
||||
exportEnvelope.setFile(exportFile);
|
||||
|
||||
return exportEnvelope;
|
||||
//FileOutputStream out = new FileOutputStream(exportFile);
|
||||
// document.write(out);
|
||||
// out.close();
|
||||
// return exportFile;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package eu.eudat.file.transformer.model;
|
||||
|
||||
public class PidLink {
|
||||
private String pid;
|
||||
private String link;
|
||||
|
||||
public String getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(String pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
|
||||
public void setLink(String link) {
|
||||
this.link = link;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package eu.eudat.file.transformer.model.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import eu.eudat.file.transformer.entities.descriptiontemplate.fielddata.AutoCompleteDataEntity;
|
||||
import eu.eudat.file.transformer.enums.DatabaseEnum;
|
||||
import eu.eudat.file.transformer.enums.EnumUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public enum FileFormats implements DatabaseEnum<String> {
|
||||
DOCX("docx"),
|
||||
PDF("pdf");
|
||||
|
||||
private final String value;
|
||||
|
||||
FileFormats(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private static final Map<String, FileFormats> map = EnumUtils.getEnumValueMap(FileFormats.class);
|
||||
|
||||
@JsonCreator
|
||||
public static FileFormats of(String i) {
|
||||
return map.get(i);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package eu.eudat.file.transformer.model.file;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 3/6/2018.
|
||||
*/
|
||||
|
||||
public class FileEnvelopeInternal {
|
||||
private String filename;
|
||||
private File file;
|
||||
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
|
||||
public void setFilename(String filename) {
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void setFile(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package eu.eudat.file.transformer.model.visibility;
|
||||
public class Rule {
|
||||
private String sourceField;
|
||||
private String targetField;
|
||||
private String requiredValue;
|
||||
private String type;
|
||||
|
||||
public String getSourceField() {
|
||||
return sourceField;
|
||||
}
|
||||
|
||||
public void setSourceField(String sourceField) {
|
||||
this.sourceField = sourceField;
|
||||
}
|
||||
|
||||
public String getTargetField() {
|
||||
return targetField;
|
||||
}
|
||||
|
||||
public void setTargetField(String targetField) {
|
||||
this.targetField = targetField;
|
||||
}
|
||||
|
||||
public String getRequiredValue() {
|
||||
return requiredValue;
|
||||
}
|
||||
|
||||
public void setRequiredValue(String requiredValue) {
|
||||
this.requiredValue = requiredValue;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package eu.eudat.file.transformer.model.visibility;
|
||||
|
||||
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.Definition;
|
||||
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.Field;
|
||||
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.FieldSet;
|
||||
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.Section;
|
||||
import eu.eudat.file.transformer.model.descriptiontemplatedefinition.fielddata.BaseFieldData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RuleMapper {
|
||||
|
||||
public static List<Rule> mapRulesFromDefinition(Definition definitionFileModel) {
|
||||
return definitionFileModel.getSections().stream().flatMap(section -> mapRulesFromSection(section).stream()).toList();
|
||||
}
|
||||
|
||||
private static List<Rule> mapRulesFromSection(Section section) {
|
||||
List<Rule> rules = new ArrayList<>();
|
||||
if (!section.getSections().isEmpty()) {
|
||||
rules.addAll(section.getSections().stream().flatMap(section1 -> mapRulesFromSection(section1).stream()).toList());
|
||||
}
|
||||
if (!section.getFieldSets().isEmpty()) {
|
||||
rules.addAll(section.getFieldSets().stream().flatMap(fieldSet -> mapRuleFromFieldSet(fieldSet).stream()).toList());
|
||||
}
|
||||
|
||||
return rules;
|
||||
}
|
||||
|
||||
private static List<Rule> mapRuleFromFieldSet(FieldSet fieldSet) {
|
||||
List<Rule> rules = new ArrayList<>();
|
||||
if (!fieldSet.getFields().isEmpty()) {
|
||||
rules.addAll(fieldSet.getFields().stream().flatMap(field -> mapRules(field).stream()).toList());
|
||||
}
|
||||
|
||||
return rules;
|
||||
}
|
||||
|
||||
private static List<Rule> mapRules(Field field) {
|
||||
List<Rule> rules = new ArrayList<>();
|
||||
BaseFieldData data = field.getData();
|
||||
field.getVisibilityRules().forEach(visibilityRule -> {
|
||||
Rule rule = new Rule();
|
||||
rule.setSourceField(field.getId());
|
||||
rule.setType(data.getFieldType().getValue());
|
||||
rule.setRequiredValue(visibilityRule.getValue());
|
||||
rule.setTargetField(visibilityRule.getTarget());
|
||||
rules.add(rule);
|
||||
});
|
||||
|
||||
return rules;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package eu.eudat.file.transformer.services.visibility;
|
||||
import eu.eudat.file.transformer.entities.user.components.commons.Rule;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 3/5/2018.
|
||||
*/
|
||||
public class VisibilityContext {
|
||||
private List<VisibilityRule> visibilityRules = new LinkedList<>();
|
||||
|
||||
public List<VisibilityRule> getVisibilityRules() {
|
||||
return visibilityRules;
|
||||
}
|
||||
|
||||
public VisibilityRule get(String id) {
|
||||
Optional<VisibilityRule> rule = visibilityRules.stream().filter(item -> item.getVisibilityRuleTargetId().equals(id)).findFirst();
|
||||
if (rule.isPresent()) return rule.get();
|
||||
return null;
|
||||
}
|
||||
|
||||
public void buildVisibilityContext(List<Rule> sources) {
|
||||
sources.forEach(this::addToVisibilityRulesContext);
|
||||
}
|
||||
|
||||
private void addToVisibilityRulesContext(Rule item) {
|
||||
VisibilityRuleSource source = new VisibilityRuleSource();
|
||||
source.setVisibilityRuleSourceId(item.getSourceField());
|
||||
source.setVisibilityRuleSourceValue(item.getRequiredValue());
|
||||
|
||||
Optional<VisibilityRule> visibilityRuleOptional = visibilityRules.stream().filter(rule -> rule.getVisibilityRuleTargetId().equals(item.getTargetField())).findFirst();
|
||||
if (visibilityRuleOptional.isPresent()) visibilityRuleOptional.get().getVisibilityRuleSources().add(source);
|
||||
else {
|
||||
List<VisibilityRuleSource> sources = new LinkedList<>();
|
||||
sources.add(source);
|
||||
VisibilityRule visibilityRule = new VisibilityRule();
|
||||
visibilityRule.setVisibilityRuleTargetId(item.getTargetField());
|
||||
visibilityRule.setVisibilityRuleSources(sources);
|
||||
this.visibilityRules.add(visibilityRule);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package eu.eudat.file.transformer.services.visibility;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 3/5/2018.
|
||||
*/
|
||||
public class VisibilityRule {
|
||||
private String visibilityRuleTargetId;
|
||||
private List<VisibilityRuleSource> visibilityRuleSources;
|
||||
|
||||
public String getVisibilityRuleTargetId() {
|
||||
return visibilityRuleTargetId;
|
||||
}
|
||||
|
||||
public void setVisibilityRuleTargetId(String visibilityRuleTargetId) {
|
||||
this.visibilityRuleTargetId = visibilityRuleTargetId;
|
||||
}
|
||||
|
||||
public List<VisibilityRuleSource> getVisibilityRuleSources() {
|
||||
return visibilityRuleSources;
|
||||
}
|
||||
|
||||
public void setVisibilityRuleSources(List<VisibilityRuleSource> visibilityRuleSources) {
|
||||
this.visibilityRuleSources = visibilityRuleSources;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package eu.eudat.file.transformer.services.visibility;
|
||||
|
||||
import eu.eudat.file.transformer.entities.user.components.commons.Rule;
|
||||
import eu.eudat.file.transformer.model.descriptionproperties.PropertyDefinition;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 3/5/2018.
|
||||
*/
|
||||
public interface VisibilityRuleService {
|
||||
boolean isElementVisible(String id);
|
||||
|
||||
void buildVisibilityContext(List<Rule> sources);
|
||||
|
||||
void setProperties(PropertyDefinition properties);
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package eu.eudat.file.transformer.services.visibility;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.file.transformer.entities.user.components.commons.Rule;
|
||||
import eu.eudat.file.transformer.model.descriptionproperties.Field;
|
||||
import eu.eudat.file.transformer.model.descriptionproperties.PropertyDefinition;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 3/5/2018.
|
||||
*/
|
||||
public class VisibilityRuleServiceImpl implements VisibilityRuleService {
|
||||
private final Map<String, Boolean> elementVisibility = new HashMap<>();
|
||||
private PropertyDefinition properties;
|
||||
private ObjectMapper mapper;
|
||||
|
||||
public VisibilityRuleServiceImpl() {
|
||||
this.mapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
public boolean isElementVisible(String id) {
|
||||
return !this.elementVisibility.containsKey(id) || this.elementVisibility.get(id);
|
||||
}
|
||||
|
||||
public void setProperties(PropertyDefinition properties) {
|
||||
this.properties = properties;
|
||||
/*this.properties.entrySet().stream()
|
||||
.filter(stringObjectEntry -> stringObjectEntry.getValue() instanceof String && ((String) stringObjectEntry.getValue()).startsWith("[")
|
||||
&& ((String) stringObjectEntry.getValue()).endsWith("]"))
|
||||
.forEach(stringObjectEntry -> stringObjectEntry.setValue(parseArray((String) stringObjectEntry.getValue())));*/
|
||||
}
|
||||
|
||||
private List<String> parseArray(String original) {
|
||||
String parsed = original.replace("[", "").replace("\"", "").replace("]", "");
|
||||
return Arrays.asList(parsed.split(","));
|
||||
}
|
||||
|
||||
public void buildVisibilityContext(List<Rule> sources) {
|
||||
VisibilityContext visibilityContext = new VisibilityContext();
|
||||
visibilityContext.buildVisibilityContext(sources);
|
||||
visibilityContext.getVisibilityRules().forEach(this::evaluateVisibility);
|
||||
}
|
||||
|
||||
private void evaluateVisibility(VisibilityRule rule) {
|
||||
List<VisibilityRuleSource> sources = rule.getVisibilityRuleSources();
|
||||
for(VisibilityRuleSource source: sources){
|
||||
Field fieldFileModel = properties.getFields().stream().filter(fieldFileModel1 -> fieldFileModel1.getKey().equals(source.getVisibilityRuleSourceId())).findFirst().orElse(null);
|
||||
if (fieldFileModel != null
|
||||
&& isContained(fieldFileModel, source.getVisibilityRuleSourceValue())) {
|
||||
this.elementVisibility.put(rule.getVisibilityRuleTargetId(), true);
|
||||
} else {
|
||||
this.elementVisibility.put(rule.getVisibilityRuleTargetId(),
|
||||
this.elementVisibility.getOrDefault(rule.getVisibilityRuleTargetId(), false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Boolean isContained(Field values, String source) {
|
||||
try {
|
||||
Object value = mapper.readValue(values.getValue(), Object.class);
|
||||
if (value instanceof Collection) {
|
||||
return ((Collection<?>) value).contains(source);
|
||||
} else {
|
||||
if (value != null) {
|
||||
return value.toString().equals(source);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package eu.eudat.file.transformer.services.visibility;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 3/5/2018.
|
||||
*/
|
||||
public class VisibilityRuleSource {
|
||||
private String visibilityRuleSourceId;
|
||||
private String visibilityRuleSourceValue;
|
||||
|
||||
public String getVisibilityRuleSourceId() {
|
||||
return visibilityRuleSourceId;
|
||||
}
|
||||
|
||||
public void setVisibilityRuleSourceId(String visibilityRuleSourceId) {
|
||||
this.visibilityRuleSourceId = visibilityRuleSourceId;
|
||||
}
|
||||
|
||||
public String getVisibilityRuleSourceValue() {
|
||||
return visibilityRuleSourceValue;
|
||||
}
|
||||
|
||||
public void setVisibilityRuleSourceValue(String visibilityRuleSourceValue) {
|
||||
this.visibilityRuleSourceValue = visibilityRuleSourceValue;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package eu.eudat.file.transformer.utils.descriptionTemplate;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import eu.eudat.file.transformer.entities.descriptiontemplate.DefinitionEntity;
|
||||
import eu.eudat.file.transformer.entities.user.composite.DatasetProfile;
|
||||
import eu.eudat.file.transformer.entities.user.composite.PagedDatasetProfile;
|
||||
import eu.eudat.file.transformer.entities.xml.XmlBuilder;
|
||||
import eu.eudat.file.transformer.model.DescriptionFileTransformerModel;
|
||||
import eu.eudat.file.transformer.model.DescriptionTemplate;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DescriptionTemplateService {
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final XmlMapper xmlMapper = new XmlMapper();
|
||||
|
||||
public static PagedDatasetProfile getPagedProfile(DescriptionFileTransformerModel dataset) throws JsonProcessingException {
|
||||
DatasetProfile datasetprofile = generateDatasetProfileModel(dataset.getDescriptionTemplate());
|
||||
datasetprofile.setStatus(dataset.getStatus().getValue());
|
||||
if (dataset.getProperties() != null) {
|
||||
//Map<String, Object> properties = objectMapper.convertValue(dataset.getProperties().getFields(), HashMap.class);
|
||||
datasetprofile.fromJsonObject(dataset.getProperties().getFields());
|
||||
}
|
||||
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
|
||||
pagedDatasetProfile.buildPagedDatasetProfile(datasetprofile);
|
||||
return pagedDatasetProfile;
|
||||
}
|
||||
|
||||
public static DatasetProfile generateDatasetProfileModel(DescriptionTemplate profile) {
|
||||
DefinitionEntity viewstyle = new DefinitionEntity().fromDefinition(profile.getDefinition());
|
||||
|
||||
DatasetProfile datasetprofile = new DatasetProfile();
|
||||
datasetprofile.buildProfile(viewstyle);
|
||||
|
||||
return datasetprofile;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package eu.eudat.file.transformer.utils.interfaces;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 3/1/2018.
|
||||
*/
|
||||
public interface Applier<A, V> {
|
||||
void apply(A applier, V value);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package eu.eudat.file.transformer.utils.interfaces;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/27/2018.
|
||||
*/
|
||||
public interface ApplierWithValue<A, V, R> {
|
||||
R apply(A applier, V value);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package eu.eudat.file.transformer.utils.interfaces;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/5/2018.
|
||||
*/
|
||||
public interface Cloneable<T> {
|
||||
T clone();
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package eu.eudat.file.transformer.utils.interfaces;
|
||||
|
||||
|
||||
import eu.eudat.file.transformer.entities.common.DatabaseModelDefinition;
|
||||
|
||||
public interface ModelSerializer<T, U extends DatabaseModelDefinition> {
|
||||
void fromDatabaseDefinition(T viewStyle, U model);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package eu.eudat.file.transformer.utils.json;
|
||||
|
||||
public class JavaToJson {
|
||||
|
||||
public static String objectStringToJson(String object) {
|
||||
String result = object.replaceAll("=", "\":\"")
|
||||
.replaceAll("\\{", "{\"")
|
||||
.replaceAll(", ", "\", \"")
|
||||
.replaceAll("}", "\"}" )
|
||||
.replaceAll("}\", \"\\{", "}, {");
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
package eu.eudat.file.transformer.utils.json;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class JsonSearcher {
|
||||
|
||||
public static List<JsonNode> findNodes(JsonNode root, String key, String value) {
|
||||
return findNodes(root, key, value, false);
|
||||
}
|
||||
|
||||
public static List<JsonNode> findNodes(JsonNode root, String key, String value, boolean parent) {
|
||||
List<JsonNode> nodes = new ArrayList<>();
|
||||
for (Iterator<JsonNode> it = root.elements(); it.hasNext(); ) {
|
||||
JsonNode node = it.next();
|
||||
int found = 0;
|
||||
for (Iterator<String> iter = node.fieldNames(); iter.hasNext(); ) {
|
||||
String fieldName = iter.next();
|
||||
if (fieldName.equals(key)) {
|
||||
if (node.get(fieldName).asText().equals(value) || node.get(fieldName).asText().startsWith(value)) {
|
||||
if (parent) {
|
||||
nodes.add(root);
|
||||
} else {
|
||||
nodes.add(node);
|
||||
}
|
||||
found++;
|
||||
}
|
||||
else if(node.get(fieldName).isArray()){
|
||||
for(JsonNode item: node.get(fieldName)){
|
||||
if(item.asText().equals(value) || item.asText().startsWith(value)){
|
||||
if (parent) {
|
||||
nodes.add(root);
|
||||
} else {
|
||||
nodes.add(node);
|
||||
}
|
||||
found++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (found == 0) {
|
||||
nodes.addAll(findNodes(node, key, value, parent));
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
public static List<String> getParentValues(JsonNode root, String childValue, String key) {
|
||||
List<String> values = new LinkedList<>();
|
||||
|
||||
for (Iterator<JsonNode> it = root.elements(); it.hasNext(); ) {
|
||||
JsonNode node = it.next();
|
||||
int found = 0;
|
||||
for (Iterator<String> iter = node.fieldNames(); iter.hasNext(); ) {
|
||||
String fieldName = iter.next();
|
||||
if (fieldName.equals(key)) {
|
||||
if (node.get(fieldName).asText().equals(childValue) || node.get(fieldName).asText().startsWith(childValue)) {
|
||||
values.add(childValue);
|
||||
found++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (found == 0) {
|
||||
values.addAll(getParentValues(node, childValue, key));
|
||||
if (!values.isEmpty() && node.has(key)) {
|
||||
values.add(node.get(key).asText());
|
||||
values.remove(childValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package eu.eudat.file.transformer.utils.json;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class MultiDateDeserializer extends StdDeserializer<Date> {
|
||||
|
||||
private static final List<String> DATE_FORMATS = Arrays.asList("yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm:ss.S");
|
||||
|
||||
|
||||
public MultiDateDeserializer() {
|
||||
super(Date.class);
|
||||
}
|
||||
|
||||
protected MultiDateDeserializer(Class<?> vc) {
|
||||
super(vc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
String text = p.getText();
|
||||
|
||||
for (String dateFormat: DATE_FORMATS) {
|
||||
try {
|
||||
return new SimpleDateFormat(dateFormat).parse(text);
|
||||
} catch (ParseException ignored) {
|
||||
}
|
||||
}
|
||||
throw new JsonParseException(p, "No supported Date format");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package eu.eudat.file.transformer.utils.pdf;
|
||||
|
||||
import eu.eudat.file.transformer.model.file.FileEnvelopeInternal;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PDFUtils {
|
||||
|
||||
public static File convertToPDF(FileEnvelopeInternal file, String tempPath, String pdfUrl) throws IOException {
|
||||
WebClient webClient = WebClient.builder().baseUrl(pdfUrl).build();
|
||||
|
||||
|
||||
byte[] queueResult = webClient.post().uri("forms/libreoffice/convert")
|
||||
.headers(httpHeaders -> httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA))
|
||||
.body(BodyInserters.fromMultipartData("file", new FileSystemResource(file.getFile())))
|
||||
.retrieve().bodyToMono(byte[].class).block();
|
||||
|
||||
File resultPdf = new File(tempPath + "/" + UUID.randomUUID() + ".pdf");
|
||||
if (queueResult != null) {
|
||||
try (FileOutputStream output = new FileOutputStream(resultPdf)) {
|
||||
output.write(queueResult);
|
||||
}
|
||||
}
|
||||
Files.deleteIfExists(file.getFile().toPath());
|
||||
|
||||
return resultPdf;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package eu.eudat.file.transformer.utils.pid;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.file.transformer.model.PidLink;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class PidLoader {
|
||||
private static final Logger logger = LoggerFactory.getLogger(PidLoader.class);
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
public static List<PidLink> loadPidLinks(String pidPath) {
|
||||
try {
|
||||
return objectMapper.readValue(ResourceUtils.getFile(pidPath), PidLinksWrapper.class).getPidLinks();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected class PidLinksWrapper {
|
||||
private List<PidLink> pidLinks;
|
||||
|
||||
public List<PidLink> getPidLinks() {
|
||||
return pidLinks;
|
||||
}
|
||||
|
||||
public void setPidLinks(List<PidLink> pidLinks) {
|
||||
this.pidLinks = pidLinks;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package eu.eudat.file.transformer.utils.types;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/26/2018.
|
||||
*/
|
||||
public enum ParagraphStyle {
|
||||
TEXT(0), HEADER1(1), HEADER2(2), HEADER3(3), HEADER4(4), TITLE(5), FOOTER(6), COMMENT(7), HEADER5(8), HEADER6(9), HTML(10), IMAGE(11);
|
||||
|
||||
private Integer value;
|
||||
|
||||
private ParagraphStyle(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static ParagraphStyle fromInteger(Integer value) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
return TEXT;
|
||||
case 1:
|
||||
return HEADER1;
|
||||
case 2:
|
||||
return HEADER2;
|
||||
case 3:
|
||||
return HEADER3;
|
||||
case 4:
|
||||
return HEADER4;
|
||||
case 5:
|
||||
return TITLE;
|
||||
case 6:
|
||||
return FOOTER;
|
||||
case 7:
|
||||
return COMMENT;
|
||||
case 8:
|
||||
return HEADER5;
|
||||
case 9:
|
||||
return HEADER6;
|
||||
case 10:
|
||||
return HTML;
|
||||
case 11:
|
||||
return IMAGE;
|
||||
default:
|
||||
throw new RuntimeException("Unsupported ParagraphStyle Code");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package eu.eudat.file.transformer.utils.types;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/27/2018.
|
||||
*/
|
||||
public enum TextStyle {
|
||||
ITALIC(0), BOLD(1), CAPS(2);
|
||||
|
||||
private Integer value;
|
||||
|
||||
private TextStyle(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static TextStyle fromInteger(Integer value) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
return ITALIC;
|
||||
case 1:
|
||||
return BOLD;
|
||||
case 2:
|
||||
return CAPS;
|
||||
default:
|
||||
throw new RuntimeException("Unsupported TextStyle Code");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,289 @@
|
|||
package eu.eudat.file.transformer.utils.word;
|
||||
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
import org.apache.xmlbeans.XmlCursor;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Node;
|
||||
import org.jsoup.nodes.TextNode;
|
||||
import org.jsoup.select.NodeTraversor;
|
||||
import org.jsoup.select.NodeVisitor;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
|
||||
public class HtmlToWorldBuilder implements NodeVisitor {
|
||||
|
||||
private final Map<String, Boolean> properties = new LinkedHashMap<>();
|
||||
private XWPFParagraph paragraph;
|
||||
private XWPFRun run;
|
||||
private Boolean dumpRun;
|
||||
private final float indentation;
|
||||
private Boolean isIdentationUsed;
|
||||
private XWPFNumbering numbering;
|
||||
private Queue<BigInteger> abstractNumId;
|
||||
private BigInteger numberingLevel;
|
||||
private XmlCursor cursor;
|
||||
|
||||
public static HtmlToWorldBuilder convertInTable(XWPFTableCell document, Document htmlDocument, float indentation) {
|
||||
XWPFParagraph paragraph = document.addParagraph();
|
||||
paragraph.setIndentFromLeft(Math.round(400 * indentation));
|
||||
HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(paragraph, indentation, null);
|
||||
NodeTraversor.traverse(htmlToWorldBuilder, htmlDocument);
|
||||
return htmlToWorldBuilder;
|
||||
}
|
||||
|
||||
public static HtmlToWorldBuilder convert(XWPFDocument document, Document htmlDocument, float indentation) {
|
||||
XWPFParagraph paragraph = document.createParagraph();
|
||||
paragraph.setIndentFromLeft(Math.round(400 * indentation));
|
||||
HtmlToWorldBuilder htmlToWorldBuilder = new HtmlToWorldBuilder(paragraph, indentation, null);
|
||||
NodeTraversor.traverse(htmlToWorldBuilder, htmlDocument);
|
||||
return htmlToWorldBuilder;
|
||||
}
|
||||
|
||||
public HtmlToWorldBuilder(XWPFParagraph paragraph, float indentation, XmlCursor cursor) {
|
||||
this.paragraph = paragraph;
|
||||
this.run = this.paragraph.createRun();
|
||||
this.dumpRun = false;
|
||||
this.indentation = indentation;
|
||||
this.isIdentationUsed = false;
|
||||
this.run.setFontSize(11);
|
||||
this.abstractNumId = new ArrayDeque<>();
|
||||
this.numberingLevel = BigInteger.valueOf(-1);
|
||||
this.setDefaultIndentation();
|
||||
this.cursor = cursor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void head(Node node, int i) {
|
||||
String name = node.nodeName();
|
||||
if (name.equals("#text")) {
|
||||
String text = ((TextNode)node).text();
|
||||
this.run.setText(text);
|
||||
this.dumpRun = true;
|
||||
} else {
|
||||
properties.put(name, true);
|
||||
}
|
||||
if (dumpRun) {
|
||||
this.run = this.paragraph.createRun();
|
||||
this.run.setFontSize(11);
|
||||
this.dumpRun = false;
|
||||
}
|
||||
parseProperties(node);
|
||||
properties.clear();
|
||||
}
|
||||
|
||||
private void parseProperties(Node node) {
|
||||
properties.entrySet().forEach(stringBooleanEntry -> {
|
||||
switch (stringBooleanEntry.getKey()) {
|
||||
case "i" :
|
||||
case "em":
|
||||
this.run.setItalic(stringBooleanEntry.getValue());
|
||||
break;
|
||||
case "b":
|
||||
case "strong":
|
||||
this.run.setBold(stringBooleanEntry.getValue());
|
||||
break;
|
||||
case "u":
|
||||
case "ins":
|
||||
this.run.setUnderline(stringBooleanEntry.getValue() ? UnderlinePatterns.SINGLE : UnderlinePatterns.NONE);
|
||||
break;
|
||||
case "small":
|
||||
this.run.setFontSize(stringBooleanEntry.getValue() ? 8 : 11);
|
||||
break;
|
||||
case "del":
|
||||
case "strike":
|
||||
case "strikethrough":
|
||||
case "s":
|
||||
this.run.setStrikeThrough(stringBooleanEntry.getValue());
|
||||
break;
|
||||
case "mark":
|
||||
this.run.setTextHighlightColor(stringBooleanEntry.getValue() ? STHighlightColor.YELLOW.toString() : STHighlightColor.NONE.toString());
|
||||
break;
|
||||
case "sub":
|
||||
this.run.setSubscript(stringBooleanEntry.getValue() ? VerticalAlign.SUBSCRIPT : VerticalAlign.BASELINE);
|
||||
break;
|
||||
case "sup":
|
||||
this.run.setSubscript(stringBooleanEntry.getValue() ? VerticalAlign.SUPERSCRIPT : VerticalAlign.BASELINE);
|
||||
break;
|
||||
case "div":
|
||||
case "p":
|
||||
if(this.cursor != null) {
|
||||
this.paragraph = this.paragraph.getDocument().insertNewParagraph(this.cursor);
|
||||
this.cursor = this.paragraph.getCTP().newCursor();
|
||||
this.cursor.toNextSibling();
|
||||
} else {
|
||||
this.paragraph = this.paragraph.getDocument().createParagraph();
|
||||
}
|
||||
this.run = this.paragraph.createRun();
|
||||
this.isIdentationUsed = false;
|
||||
this.setDefaultIndentation();
|
||||
if (stringBooleanEntry.getValue()) {
|
||||
if (node.hasAttr("align")) {
|
||||
String alignment = node.attr("align");
|
||||
this.paragraph.setAlignment(ParagraphAlignment.valueOf(alignment.toUpperCase(Locale.ROOT)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "blockquote":
|
||||
if(this.cursor != null) {
|
||||
this.paragraph = this.paragraph.getDocument().insertNewParagraph(this.cursor);
|
||||
this.cursor = this.paragraph.getCTP().newCursor();
|
||||
} else {
|
||||
this.paragraph = this.paragraph.getDocument().createParagraph();
|
||||
}
|
||||
this.run = this.paragraph.createRun();
|
||||
if (stringBooleanEntry.getValue()) {
|
||||
this.paragraph.setIndentationLeft(400);
|
||||
} else {
|
||||
this.isIdentationUsed = false;
|
||||
this.setDefaultIndentation();
|
||||
}
|
||||
break;
|
||||
case "ul":
|
||||
if (stringBooleanEntry.getValue()) {
|
||||
createNumbering(STNumberFormat.BULLET);
|
||||
} else {
|
||||
if(this.cursor != null) {
|
||||
this.paragraph = this.paragraph.getDocument().insertNewParagraph(this.cursor);
|
||||
this.cursor = this.paragraph.getCTP().newCursor();
|
||||
} else {
|
||||
this.paragraph = this.paragraph.getDocument().createParagraph();
|
||||
}
|
||||
this.run = this.paragraph.createRun();
|
||||
this.isIdentationUsed = false;
|
||||
this.setDefaultIndentation();
|
||||
this.numberingLevel = this.numberingLevel.subtract(BigInteger.ONE);
|
||||
((ArrayDeque)this.abstractNumId).removeLast();
|
||||
}
|
||||
break;
|
||||
case "ol":
|
||||
if (stringBooleanEntry.getValue()) {
|
||||
createNumbering(STNumberFormat.DECIMAL);
|
||||
} else {
|
||||
if(this.cursor != null) {
|
||||
this.paragraph = this.paragraph.getDocument().insertNewParagraph(this.cursor);
|
||||
this.cursor = this.paragraph.getCTP().newCursor();
|
||||
} else {
|
||||
this.paragraph = this.paragraph.getDocument().createParagraph();
|
||||
}
|
||||
this.run = this.paragraph.createRun();
|
||||
this.isIdentationUsed = false;
|
||||
this.setDefaultIndentation();
|
||||
this.numberingLevel = this.numberingLevel.subtract(BigInteger.ONE);
|
||||
((ArrayDeque)this.abstractNumId).removeLast();
|
||||
}
|
||||
break;
|
||||
case "li":
|
||||
if (stringBooleanEntry.getValue()) {
|
||||
if(this.cursor != null) {
|
||||
this.paragraph = this.paragraph.getDocument().insertNewParagraph(this.cursor);
|
||||
this.cursor = this.paragraph.getCTP().newCursor();
|
||||
} else {
|
||||
this.paragraph = this.paragraph.getDocument().createParagraph();
|
||||
}
|
||||
// this.paragraph.setIndentationLeft(Math.round(indentation * 720) * (numberingLevel.intValue() + 1));
|
||||
this.paragraph.setIndentFromLeft(Math.round(numberingLevel.intValue() * 400 + this.indentation*400));
|
||||
this.run = this.paragraph.createRun();
|
||||
this.paragraph.setNumID(((ArrayDeque<BigInteger>)abstractNumId).getLast());
|
||||
}
|
||||
break;
|
||||
case "font":
|
||||
if (stringBooleanEntry.getValue()) {
|
||||
if (node.hasAttr("color")) {
|
||||
this.run.setColor(node.attr("color").substring(1));
|
||||
}
|
||||
} else {
|
||||
this.run.setColor("000000");
|
||||
}
|
||||
break;
|
||||
case "a":
|
||||
if (stringBooleanEntry.getValue()) {
|
||||
if (node.hasAttr("href")) {
|
||||
this.run = createHyperLinkRun(node.attr("href"));
|
||||
this.run.setColor("0000FF");
|
||||
this.run.setUnderline(UnderlinePatterns.SINGLE);
|
||||
}
|
||||
} else {
|
||||
this.run = paragraph.createRun();
|
||||
}
|
||||
break;
|
||||
case "br":
|
||||
if (stringBooleanEntry.getValue()) {
|
||||
this.run.addBreak();
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tail(Node node, int i) {
|
||||
String name = node.nodeName();
|
||||
properties.put(name, false);
|
||||
parseProperties(node);
|
||||
properties.clear();
|
||||
}
|
||||
|
||||
//GK: This function creates one numbering.xml for the word document and adds a specific format.
|
||||
//It imitates the numbering.xml that is usually generated by word editors like LibreOffice
|
||||
private void createNumbering(STNumberFormat.Enum format) {
|
||||
CTAbstractNum ctAbstractNum = CTAbstractNum.Factory.newInstance();
|
||||
if (this.numbering == null) this.numbering = this.paragraph.getDocument().createNumbering();
|
||||
BigInteger tempNumId = BigInteger.ONE;
|
||||
boolean found = false;
|
||||
while (!found) {
|
||||
Object o = numbering.getAbstractNum(tempNumId);
|
||||
found = (o == null);
|
||||
if (!found) tempNumId = tempNumId.add(BigInteger.ONE);
|
||||
}
|
||||
ctAbstractNum.setAbstractNumId(tempNumId);
|
||||
CTLvl ctLvl = ctAbstractNum.addNewLvl();
|
||||
this.numberingLevel = numberingLevel.add(BigInteger.ONE);
|
||||
ctLvl.setIlvl(numberingLevel);
|
||||
ctLvl.addNewNumFmt().setVal(format);
|
||||
ctLvl.addNewStart().setVal(BigInteger.ONE);
|
||||
if (format == STNumberFormat.BULLET) {
|
||||
ctLvl.addNewLvlJc().setVal(STJc.LEFT);
|
||||
ctLvl.addNewLvlText().setVal("\u2022");
|
||||
ctLvl.addNewRPr(); //Set the Symbol font
|
||||
CTFonts f = ctLvl.getRPr().addNewRFonts();
|
||||
f.setAscii("Symbol");
|
||||
f.setHAnsi("Symbol");
|
||||
f.setCs("Symbol");
|
||||
f.setHint(STHint.DEFAULT);
|
||||
} else {
|
||||
ctLvl.addNewLvlText().setVal("%1.");
|
||||
}
|
||||
XWPFAbstractNum xwpfAbstractNum = new XWPFAbstractNum(ctAbstractNum);
|
||||
|
||||
this.abstractNumId.add(this.numbering.addAbstractNum(xwpfAbstractNum));
|
||||
this.numbering.addNum(((ArrayDeque<BigInteger>)abstractNumId).getLast());
|
||||
}
|
||||
|
||||
private XWPFHyperlinkRun createHyperLinkRun(String uri) {
|
||||
String rId = this.paragraph.getDocument().getPackagePart().addExternalRelationship(uri, XWPFRelation.HYPERLINK.getRelation()).getId();
|
||||
|
||||
CTHyperlink cthyperLink=paragraph.getCTP().addNewHyperlink();
|
||||
cthyperLink.setId(rId);
|
||||
cthyperLink.addNewR();
|
||||
|
||||
return new XWPFHyperlinkRun(
|
||||
cthyperLink,
|
||||
cthyperLink.getRArray(0),
|
||||
paragraph
|
||||
);
|
||||
}
|
||||
|
||||
private void setDefaultIndentation() {
|
||||
if (!isIdentationUsed) {
|
||||
// this.paragraph.setIndentationLeft(Math.round(indentation * 720.0F));
|
||||
this.paragraph.setIndentFromLeft(Math.round(indentation * 400));
|
||||
this.isIdentationUsed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public XWPFParagraph getParagraph() {
|
||||
return paragraph;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,63 @@
|
|||
package eu.eudat.file.transformer.utils.word;
|
||||
|
||||
import org.apache.poi.ooxml.POIXMLDocumentPart;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.UUID;
|
||||
|
||||
public class XWPFHtmlDocument extends POIXMLDocumentPart {
|
||||
|
||||
private String html;
|
||||
private String id;
|
||||
|
||||
public XWPFHtmlDocument(PackagePart pkg, String id) {
|
||||
super(pkg);
|
||||
this.html = "<!DOCTYPE html><html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"><style></style><title>HTML import</title></head><body><p></p></body>";
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getHtml() {
|
||||
return html;
|
||||
}
|
||||
|
||||
public void setHtml(String html) {
|
||||
this.html = this.html.replace("<p></p>", html);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void commit() throws IOException {
|
||||
PackagePart packagePart = getPackagePart();
|
||||
OutputStream outputStream = packagePart.getOutputStream();
|
||||
Writer writer = new OutputStreamWriter(outputStream, "UTF-8");
|
||||
writer.write(html);
|
||||
writer.close();
|
||||
outputStream.close();
|
||||
}
|
||||
|
||||
public static XWPFHtmlDocument addHtmlDocument(XWPFDocument document) throws InvalidFormatException {
|
||||
OPCPackage oPCPackage = document.getPackage();
|
||||
String id = UUID.randomUUID().toString();
|
||||
PackagePartName partName = PackagingURIHelper.createPartName("/word/" + id + ".html");
|
||||
PackagePart part = oPCPackage.createPart(partName, "text/html");
|
||||
XWPFHtmlDocument xWPFHtmlDocument = new XWPFHtmlDocument(part, id);
|
||||
document.addRelation(xWPFHtmlDocument.getId(), new XWPFHtmlRelation(), xWPFHtmlDocument);
|
||||
return xWPFHtmlDocument;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package eu.eudat.file.transformer.utils.word;
|
||||
|
||||
import org.apache.poi.ooxml.POIXMLRelation;
|
||||
|
||||
public class XWPFHtmlRelation extends POIXMLRelation {
|
||||
public XWPFHtmlRelation() {
|
||||
super("text/html",
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk",
|
||||
"/word/htmlDoc#.html");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>file-transformer-document-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
<revision>1.0.0-SNAPSHOT</revision>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>core</module>
|
||||
<module>web</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,59 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>file-transformer-document-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>file-transformer-document-web</artifactId>
|
||||
<version>${revision}</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
<revision>1.0.0-SNAPSHOT</revision>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>file-transformer-document</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
<artifactId>oidc-authn</artifactId>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gr.cite</groupId>
|
||||
<artifactId>cache</artifactId>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,16 @@
|
|||
package eu.eudat.file.transformer;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication(scanBasePackages = {
|
||||
"eu.eudat.file.transformer.*",
|
||||
"gr.cite.tools",
|
||||
"gr.cite.commons"
|
||||
})
|
||||
public class FileTransformerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(FileTransformerApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package eu.eudat.file.transformer.config;
|
||||
|
||||
import gr.cite.commons.web.oidc.configuration.WebSecurityProperties;
|
||||
import gr.cite.commons.web.oidc.configuration.filter.ApiKeyFilter;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.authentication.AuthenticationManagerResolver;
|
||||
import org.springframework.security.config.Customizer;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class SecurityConfiguration {
|
||||
|
||||
private final ApiKeyFilter apiKeyFilter;
|
||||
private final WebSecurityProperties webSecurityProperties;
|
||||
private final AuthenticationManagerResolver<HttpServletRequest> authenticationManagerResolver;
|
||||
|
||||
@Autowired
|
||||
public SecurityConfiguration(ApiKeyFilter apiKeyFilter, WebSecurityProperties webSecurityProperties, AuthenticationManagerResolver<HttpServletRequest> authenticationManagerResolver) {
|
||||
this.apiKeyFilter = apiKeyFilter;
|
||||
this.webSecurityProperties = webSecurityProperties;
|
||||
this.authenticationManagerResolver = authenticationManagerResolver;
|
||||
}
|
||||
|
||||
@Bean
|
||||
protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
if (webSecurityProperties.isEnabled()) {
|
||||
http.csrf(AbstractHttpConfigurer::disable)
|
||||
.cors(Customizer.withDefaults())
|
||||
.addFilterBefore(apiKeyFilter, AbstractPreAuthenticatedProcessingFilter.class)
|
||||
.authorizeHttpRequests(authorizationManagerRequestMatcherRegistry -> authorizationManagerRequestMatcherRegistry
|
||||
.requestMatchers(buildAntPatterns(webSecurityProperties.getAuthorizedEndpoints())).authenticated()
|
||||
.requestMatchers(buildAntPatterns(webSecurityProperties.getAllowedEndpoints())).anonymous())
|
||||
.sessionManagement(httpSecuritySessionManagementConfigurer -> httpSecuritySessionManagementConfigurer.sessionCreationPolicy(SessionCreationPolicy.NEVER))
|
||||
.oauth2ResourceServer(oauth2 -> oauth2.authenticationManagerResolver(authenticationManagerResolver));
|
||||
return http.build();
|
||||
} else {
|
||||
return http.csrf(AbstractHttpConfigurer::disable)
|
||||
.cors(Customizer.withDefaults())
|
||||
.authorizeHttpRequests(authorizationManagerRequestMatcherRegistry ->
|
||||
authorizationManagerRequestMatcherRegistry.anyRequest().anonymous())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
private String[] buildAntPatterns(Set<String> endpoints) {
|
||||
if (endpoints == null) {
|
||||
return new String[0];
|
||||
}
|
||||
return endpoints.stream()
|
||||
.filter(endpoint -> endpoint != null && !endpoint.isBlank())
|
||||
.map(endpoint -> "/" + stripUnnecessaryCharacters(endpoint) + "/**")
|
||||
.toArray(String[]::new);
|
||||
}
|
||||
|
||||
private String stripUnnecessaryCharacters(String endpoint) {
|
||||
endpoint = endpoint.strip();
|
||||
if (endpoint.startsWith("/")) {
|
||||
endpoint = endpoint.substring(1);
|
||||
}
|
||||
if (endpoint.endsWith("/")) {
|
||||
endpoint = endpoint.substring(0, endpoint.length() - 1);
|
||||
}
|
||||
return endpoint;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package eu.eudat.file.transformer.controller;
|
||||
|
||||
import eu.eudat.file.transformer.executor.FileTransformerExecutor;
|
||||
import eu.eudat.file.transformer.model.DescriptionFileTransformerModel;
|
||||
import eu.eudat.file.transformer.model.DmpFileTransformerModel;
|
||||
import eu.eudat.file.transformer.model.ExtraPropertiesModel;
|
||||
import eu.eudat.file.transformer.model.enums.FileFormats;
|
||||
import eu.eudat.file.transformer.model.file.FileEnvelope;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/file")
|
||||
public class FileTransformerController {
|
||||
|
||||
private final FileTransformerExecutor fileTransformerExecutor;
|
||||
|
||||
@Autowired
|
||||
public FileTransformerController(FileTransformerExecutor fileTransformerExecutor) {
|
||||
this.fileTransformerExecutor = fileTransformerExecutor;
|
||||
}
|
||||
|
||||
@PostMapping("/export/dmp")
|
||||
public FileEnvelope exportDmp(@RequestBody DmpFileTransformerModel dmpDepositModel, @RequestParam(value = "format",required = false)String format) throws Exception {
|
||||
ExtraPropertiesModel properties = new ExtraPropertiesModel();
|
||||
properties.setFormat(format != null ? format : "docx");
|
||||
return fileTransformerExecutor.exportDmp(dmpDepositModel, properties);
|
||||
}
|
||||
|
||||
@PostMapping("/export/description")
|
||||
public FileEnvelope exportDescription(@RequestBody DescriptionFileTransformerModel descriptionFileTransformerModel, @RequestParam(value = "format",required = false)String format, @RequestParam(value = "descriptionId",required = false) String descriptionId) throws Exception {
|
||||
ExtraPropertiesModel properties = new ExtraPropertiesModel();
|
||||
properties.setFormat(format != null ? format : "docx");
|
||||
return fileTransformerExecutor.exportDescription(descriptionFileTransformerModel, properties);
|
||||
}
|
||||
|
||||
@PostMapping("/import/dmp")
|
||||
public DmpFileTransformerModel importFileToDmp(@RequestBody FileEnvelope fileEnvelope) {
|
||||
return fileTransformerExecutor.importFileToDmp(fileEnvelope);
|
||||
}
|
||||
|
||||
@PostMapping("/import/description")
|
||||
public DescriptionFileTransformerModel importFileToDescription(@RequestBody FileEnvelope fileEnvelope) {
|
||||
return fileTransformerExecutor.importFileToDescription(fileEnvelope);
|
||||
}
|
||||
|
||||
@GetMapping("/formats")
|
||||
public List<String> getSupportedFormats() {
|
||||
return fileTransformerExecutor.getSupportedFileFormats();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
spring:
|
||||
jackson:
|
||||
default-property-inclusion: non_null
|
||||
config:
|
||||
import: optional:classpath:config/app.env[.properties], optional:file:../config/app.env[.properties],
|
||||
optional:classpath:config/server.yml[.yml], optional:classpath:config/server-${spring.profiles.active}.yml[.yml], optional:file:../config/server-${spring.profiles.active}.yml[.yml],
|
||||
optional:classpath:config/storage.yml[.yml], optional:classpath:config/storage-${spring.profiles.active}.yml[.yml], optional:file:../config/storage-${spring.profiles.active}.yml[.yml],
|
||||
optional:classpath:config/security.yml[.yml], optional:classpath:config/security-${spring.profiles.active}.yml[.yml], optional:file:../config/security-${spring.profiles.active}.yml[.yml],
|
||||
optional:classpath:config/cache.yml[.yml], optional:classpath:config/cache-${spring.profiles.active}.yml[.yml], optional:file:../config/cache-${spring.profiles.active}.yml[.yml],
|
||||
optional:classpath:config/pdf.yml[.yml], optional:classpath:config/pdf-${spring.profiles.active}.yml[.yml], optional:file:../config/pdf-${spring.profiles.active}.yml[.yml]
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
cache:
|
||||
manager:
|
||||
fallbackToNoOpCache: true
|
||||
caffeineCaches:
|
||||
- names: [ "apikey" ]
|
||||
allowNullValues: true
|
||||
initialCapacity: 100
|
||||
maximumSize: 500
|
||||
enableRecordStats: false
|
||||
expireAfterWriteMinutes: 10
|
||||
expireAfterAccessMinutes: 10
|
||||
refreshAfterWriteMinutes: 10
|
||||
mapCaches:
|
||||
apiKey:
|
||||
name: apikey
|
||||
keyPattern: resolve_$keyhash$:v0
|
|
@ -0,0 +1,3 @@
|
|||
pdf:
|
||||
converter:
|
||||
url: ${PDF_CONVERTER_URL:}
|
|
@ -0,0 +1,20 @@
|
|||
web:
|
||||
security:
|
||||
enabled: true
|
||||
authorized-endpoints: [ api ]
|
||||
allowed-endpoints: [ health ]
|
||||
idp:
|
||||
api-key:
|
||||
enabled: true
|
||||
authorization-header: Authorization
|
||||
client-id: ${IDP_APIKEY_CLIENT_ID:}
|
||||
client-secret: ${IDP_APIKEY_CLIENT_SECRET:}
|
||||
scope: ${IDP_APIKEY_SCOPE:}
|
||||
resource:
|
||||
token-type: JWT #| opaque
|
||||
opaque:
|
||||
client-id: ${IDP_OPAQUE_CLIENT_ID:}
|
||||
client-secret: ${IDP_OPAQUE_CLIENT_SECRET:}
|
||||
jwt:
|
||||
claims: [ role, x-role ]
|
||||
issuer-uri: ${IDP_ISSUER_URI:}
|
|
@ -0,0 +1,12 @@
|
|||
server:
|
||||
port: 8084
|
||||
tomcat:
|
||||
threads:
|
||||
max: 20
|
||||
max-connections: 10000
|
||||
|
||||
spring:
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 10MB
|
||||
max-request-size: 10MB
|
|
@ -0,0 +1,7 @@
|
|||
file:
|
||||
template:
|
||||
word-template: classpath:documents/h2020.docx
|
||||
pid-template: classpath:pidLinks.json
|
||||
word-description-template: classpath:documents/h2020_dataset.docx
|
||||
storage:
|
||||
temp: ${TEMP_PATH}
|
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,100 @@
|
|||
{
|
||||
"pidLinks": [
|
||||
{
|
||||
"pid": "doi",
|
||||
"link": "https://doi.org/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "uniprot",
|
||||
"link": "https://uniprot.org/uniprotkb/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "handle",
|
||||
"link": "https://hdl.handle.net/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "arxiv",
|
||||
"link": "https://arxiv.org/abs/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "ascl",
|
||||
"link": "https://ascl.net/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "orcid",
|
||||
"link": "https://orcid.org/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "pmid",
|
||||
"link": "https://pubmed.ncbi.nlm.nih.gov/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "ads",
|
||||
"link": "https://ui.adsabs.harvard.edu/#abs/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "pmcid",
|
||||
"link": "https://ncbi.nlm.nih.gov/pmc/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "gnd",
|
||||
"link": "https://d-nb.info/gnd/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "urn",
|
||||
"link": "https://nbn-resolving.org/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "sra",
|
||||
"link": "https://ebi.ac.uk/ena/data/view/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "bioproject",
|
||||
"link": "https://ebi.ac.uk/ena/data/view/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "biosample",
|
||||
"link": "https://ebi.ac.uk/ena/data/view/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "ensembl",
|
||||
"link": "https://ensembl.org/id/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "refseq",
|
||||
"link": "https://ncbi.nlm.nih.gov/entrez/viewer.fcgi?val={pid}"
|
||||
},
|
||||
{
|
||||
"pid": "genome",
|
||||
"link": "https://ncbi.nlm.nih.gov/assembly/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "geo",
|
||||
"link": "https://ncbi.nlm.nih.gov/geo/query/acc.cgi?acc={pid}"
|
||||
},
|
||||
{
|
||||
"pid": "arrayexpress_array",
|
||||
"link": "https://ebi.ac.uk/arrayexpress/arrays/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "arrayexpress_experiment",
|
||||
"link": "https://ebi.ac.uk/arrayexpress/experiments/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "hal",
|
||||
"link": "https://hal.archives-ouvertes.fr/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "swh",
|
||||
"link": "https://archive.softwareheritage.org/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "ror",
|
||||
"link": "https://ror.org/{pid}"
|
||||
},
|
||||
{
|
||||
"pid": "viaf",
|
||||
"link": "https://viaf.org/viaf/{pid}"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue