Make the supported formats to return some additional information
This commit is contained in:
parent
666e6b1ba2
commit
236f3bbb8e
35
core/pom.xml
35
core/pom.xml
|
@ -6,49 +6,26 @@
|
||||||
<groupId>gr.cite.opendmp</groupId>
|
<groupId>gr.cite.opendmp</groupId>
|
||||||
<artifactId>file-transformer-document-parent</artifactId>
|
<artifactId>file-transformer-document-parent</artifactId>
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>file-transformer-document</artifactId>
|
<artifactId>file-transformer-document</artifactId>
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
<packaging>jar</packaging>
|
<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>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
<maven.compiler.release>21</maven.compiler.release>
|
<maven.compiler.release>21</maven.compiler.release>
|
||||||
<revision>1.0.0-SNAPSHOT</revision>
|
<revision>1.0.0-SNAPSHOT</revision>
|
||||||
|
<transformer-base.version>1.0-SNAPSHOT</transformer-base.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>gr.cite.opendmp</groupId>
|
<groupId>gr.cite.opendmp</groupId>
|
||||||
<artifactId>file-transformer-base</artifactId>
|
<artifactId>file-transformer-base</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>${transformer-base.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -79,12 +56,6 @@
|
||||||
<artifactId>jsoup</artifactId>
|
<artifactId>jsoup</artifactId>
|
||||||
<version>1.16.1</version>
|
<version>1.16.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.json</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
<version>20160810</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||||
<artifactId>jackson-dataformat-xml</artifactId>
|
<artifactId>jackson-dataformat-xml</artifactId>
|
||||||
|
|
|
@ -15,6 +15,7 @@ import eu.eudat.file.transformer.model.dmpblueprintdefinition.SystemField;
|
||||||
import eu.eudat.file.transformer.model.enums.FileFormats;
|
import eu.eudat.file.transformer.model.enums.FileFormats;
|
||||||
import eu.eudat.file.transformer.model.file.FileEnvelope;
|
import eu.eudat.file.transformer.model.file.FileEnvelope;
|
||||||
import eu.eudat.file.transformer.model.file.FileEnvelopeInternal;
|
import eu.eudat.file.transformer.model.file.FileEnvelopeInternal;
|
||||||
|
import eu.eudat.file.transformer.model.file.FileFormat;
|
||||||
import eu.eudat.file.transformer.services.visibility.VisibilityRuleService;
|
import eu.eudat.file.transformer.services.visibility.VisibilityRuleService;
|
||||||
import eu.eudat.file.transformer.services.visibility.VisibilityRuleServiceImpl;
|
import eu.eudat.file.transformer.services.visibility.VisibilityRuleServiceImpl;
|
||||||
import eu.eudat.file.transformer.utils.descriptionTemplate.DescriptionTemplateService;
|
import eu.eudat.file.transformer.utils.descriptionTemplate.DescriptionTemplateService;
|
||||||
|
@ -43,6 +44,10 @@ import java.util.*;
|
||||||
public class WordFileTransformer implements FileTransformerExecutor {
|
public class WordFileTransformer implements FileTransformerExecutor {
|
||||||
private final static Logger logger = LoggerFactory.getLogger(WordFileTransformer.class);
|
private final static Logger logger = LoggerFactory.getLogger(WordFileTransformer.class);
|
||||||
|
|
||||||
|
private final static List<FileFormat> FILE_FORMATS = List.of(
|
||||||
|
new FileFormat(FileFormats.PDF.getValue(), "PDF", "fa-file-pdf-o"),
|
||||||
|
new FileFormat(FileFormats.DOCX.getValue(), "Document", "fa-file-word-o"));
|
||||||
|
|
||||||
private final FilePathProperties fileTemplateProperties;
|
private final FilePathProperties fileTemplateProperties;
|
||||||
private final FileStorageProperties fileStorageProperties;
|
private final FileStorageProperties fileStorageProperties;
|
||||||
private final PdfProperties pdfProperties;
|
private final PdfProperties pdfProperties;
|
||||||
|
@ -95,8 +100,8 @@ public class WordFileTransformer implements FileTransformerExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getSupportedFileFormats() {
|
public List<FileFormat> getSupportedFileFormats() {
|
||||||
return Arrays.stream(FileFormats.values()).map(FileFormats::getValue).toList();
|
return FILE_FORMATS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileEnvelope getPdfDocument(FileEnvelopeInternal wordFile) throws IOException {
|
private FileEnvelope getPdfDocument(FileEnvelopeInternal wordFile) throws IOException {
|
||||||
|
@ -126,11 +131,18 @@ public class WordFileTransformer implements FileTransformerExecutor {
|
||||||
|
|
||||||
wordBuilder.fillFirstPage(dmpEntity, null, document, false);
|
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 = new ArrayList<>();
|
||||||
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 = new ArrayList<>();
|
||||||
List<Reference> researchers = dmpEntity.getDmpReferences().stream().filter(referenceFileModel -> referenceFileModel.getReference().getType().equals(ReferenceType.Researcher)).map(DmpReference::getReference).toList();
|
List<Reference> organizations = new ArrayList<>();
|
||||||
List<Reference> organizations = dmpEntity.getDmpReferences().stream().filter(referenceFileModel -> referenceFileModel.getReference().getType().equals(ReferenceType.Organizations)).map(DmpReference::getReference).toList();
|
List<Reference> funders = new ArrayList<>();
|
||||||
List<Reference> projects = dmpEntity.getDmpReferences().stream().filter(referenceFileModel -> referenceFileModel.getReference().getType().equals(ReferenceType.Project) && referenceFileModel.getReference().getIsActive().equals(IsActive.Active)).map(DmpReference::getReference).toList();
|
List<Reference> projects = new ArrayList<>();
|
||||||
|
if (dmpEntity.getDmpReferences() != null) {
|
||||||
|
grants = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Grants) && referenceFileModel.getIsActive().equals(IsActive.Active)).toList();
|
||||||
|
researchers = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(reference -> reference.getType().equals(ReferenceType.Researcher)).toList();
|
||||||
|
organizations = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Organizations)).toList();
|
||||||
|
funders = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Funder) && referenceFileModel.getIsActive().equals(IsActive.Active)).toList();
|
||||||
|
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 = document.getParagraphs().size() - 3;
|
||||||
int powered_pos = wordBuilder.findPosOfPoweredBy(document);
|
int powered_pos = wordBuilder.findPosOfPoweredBy(document);
|
||||||
|
|
|
@ -1,29 +1,18 @@
|
||||||
package eu.eudat.file.transformer.utils.descriptionTemplate;
|
package eu.eudat.file.transformer.utils.descriptionTemplate;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
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.descriptiontemplate.DefinitionEntity;
|
||||||
import eu.eudat.file.transformer.entities.user.composite.DatasetProfile;
|
import eu.eudat.file.transformer.entities.user.composite.DatasetProfile;
|
||||||
import eu.eudat.file.transformer.entities.user.composite.PagedDatasetProfile;
|
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.DescriptionFileTransformerModel;
|
||||||
import eu.eudat.file.transformer.model.DescriptionTemplate;
|
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 {
|
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 {
|
public static PagedDatasetProfile getPagedProfile(DescriptionFileTransformerModel dataset) throws JsonProcessingException {
|
||||||
DatasetProfile datasetprofile = generateDatasetProfileModel(dataset.getDescriptionTemplate());
|
DatasetProfile datasetprofile = generateDatasetProfileModel(dataset.getDescriptionTemplate());
|
||||||
datasetprofile.setStatus(dataset.getStatus().getValue());
|
datasetprofile.setStatus(dataset.getStatus().getValue());
|
||||||
if (dataset.getProperties() != null) {
|
if (dataset.getProperties() != null) {
|
||||||
//Map<String, Object> properties = objectMapper.convertValue(dataset.getProperties().getFields(), HashMap.class);
|
|
||||||
datasetprofile.fromJsonObject(dataset.getProperties().getFields());
|
datasetprofile.fromJsonObject(dataset.getProperties().getFields());
|
||||||
}
|
}
|
||||||
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
|
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
|
||||||
|
|
|
@ -18,15 +18,12 @@ import eu.eudat.file.transformer.enums.ReferenceType;
|
||||||
import eu.eudat.file.transformer.model.*;
|
import eu.eudat.file.transformer.model.*;
|
||||||
import eu.eudat.file.transformer.services.visibility.VisibilityRuleService;
|
import eu.eudat.file.transformer.services.visibility.VisibilityRuleService;
|
||||||
import eu.eudat.file.transformer.utils.interfaces.ApplierWithValue;
|
import eu.eudat.file.transformer.utils.interfaces.ApplierWithValue;
|
||||||
import eu.eudat.file.transformer.utils.json.JavaToJson;
|
|
||||||
import eu.eudat.file.transformer.utils.pid.PidLoader;
|
import eu.eudat.file.transformer.utils.pid.PidLoader;
|
||||||
import eu.eudat.file.transformer.utils.types.ParagraphStyle;
|
import eu.eudat.file.transformer.utils.types.ParagraphStyle;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.util.Units;
|
import org.apache.poi.util.Units;
|
||||||
import org.apache.poi.xwpf.usermodel.*;
|
import org.apache.poi.xwpf.usermodel.*;
|
||||||
import org.apache.xmlbeans.XmlCursor;
|
import org.apache.xmlbeans.XmlCursor;
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.select.NodeTraversor;
|
import org.jsoup.select.NodeTraversor;
|
||||||
|
@ -781,16 +778,16 @@ public class WordBuilder {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
JSONArray array = new JSONArray(JavaToJson.objectStringToJson(format));
|
List<Map<String, Object>> array = mapper.readValue(format, ArrayList.class);
|
||||||
StringBuilder multipleFormats = new StringBuilder();
|
StringBuilder multipleFormats = new StringBuilder();
|
||||||
for (int i = 0; i < array.length(); i++) {
|
for (int i = 0; i < array.size(); i++) {
|
||||||
multipleFormats.append(array.getJSONObject(i).getString(attribute)).append(", ");
|
multipleFormats.append(array.get(i).get(attribute)).append(", ");
|
||||||
}
|
}
|
||||||
if (multipleFormats.length() > 0) {
|
if (multipleFormats.length() > 0) {
|
||||||
multipleFormats.setLength(multipleFormats.length() - 2);
|
multipleFormats.setLength(multipleFormats.length() - 2);
|
||||||
}
|
}
|
||||||
return multipleFormats.toString();
|
return multipleFormats.toString();
|
||||||
} catch (JSONException e) {
|
} catch (JsonProcessingException e) {
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1019,11 +1016,16 @@ public class WordBuilder {
|
||||||
int parPos = 0;
|
int parPos = 0;
|
||||||
int descrParPos = -1;
|
int descrParPos = -1;
|
||||||
XWPFParagraph descrPar = null;
|
XWPFParagraph descrPar = null;
|
||||||
List<Reference> grants = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Grants) && referenceFileModel.getIsActive().equals(IsActive.Active)).toList();
|
List<Reference> grants = new ArrayList<>();
|
||||||
List<Reference> researchers = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(reference -> reference.getType().equals(ReferenceType.Researcher)).toList();
|
List<Reference> researchers = new ArrayList<>();
|
||||||
List<Reference> organizations = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Organizations)).toList();
|
List<Reference> organizations = new ArrayList<>();
|
||||||
List<Reference> funders = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Funder) && referenceFileModel.getIsActive().equals(IsActive.Active)).toList();
|
List<Reference> funders = new ArrayList<>();
|
||||||
|
if (dmpEntity.getDmpReferences() != null) {
|
||||||
|
grants = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Grants) && referenceFileModel.getIsActive().equals(IsActive.Active)).toList();
|
||||||
|
researchers = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(reference -> reference.getType().equals(ReferenceType.Researcher)).toList();
|
||||||
|
organizations = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Organizations)).toList();
|
||||||
|
funders = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Funder) && referenceFileModel.getIsActive().equals(IsActive.Active)).toList();
|
||||||
|
}
|
||||||
for(XWPFParagraph p: document.getParagraphs()){
|
for(XWPFParagraph p: document.getParagraphs()){
|
||||||
List<XWPFRun> runs = p.getRuns();
|
List<XWPFRun> runs = p.getRuns();
|
||||||
if(runs != null){
|
if(runs != null){
|
||||||
|
|
8
pom.xml
8
pom.xml
|
@ -21,6 +21,14 @@
|
||||||
<revision>1.0.0-SNAPSHOT</revision>
|
<revision>1.0.0-SNAPSHOT</revision>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>core</module>
|
<module>core</module>
|
||||||
<module>web</module>
|
<module>web</module>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<groupId>gr.cite.opendmp</groupId>
|
<groupId>gr.cite.opendmp</groupId>
|
||||||
<artifactId>file-transformer-document-parent</artifactId>
|
<artifactId>file-transformer-document-parent</artifactId>
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>file-transformer-document-web</artifactId>
|
<artifactId>file-transformer-document-web</artifactId>
|
||||||
|
|
|
@ -4,12 +4,12 @@ import eu.eudat.file.transformer.executor.FileTransformerExecutor;
|
||||||
import eu.eudat.file.transformer.model.DescriptionFileTransformerModel;
|
import eu.eudat.file.transformer.model.DescriptionFileTransformerModel;
|
||||||
import eu.eudat.file.transformer.model.DmpFileTransformerModel;
|
import eu.eudat.file.transformer.model.DmpFileTransformerModel;
|
||||||
import eu.eudat.file.transformer.model.ExtraPropertiesModel;
|
import eu.eudat.file.transformer.model.ExtraPropertiesModel;
|
||||||
import eu.eudat.file.transformer.model.enums.FileFormats;
|
|
||||||
import eu.eudat.file.transformer.model.file.FileEnvelope;
|
import eu.eudat.file.transformer.model.file.FileEnvelope;
|
||||||
|
import eu.eudat.file.transformer.model.file.FileFormat;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/file")
|
@RequestMapping("/api/file")
|
||||||
|
@ -47,7 +47,7 @@ public class FileTransformerController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/formats")
|
@GetMapping("/formats")
|
||||||
public List<String> getSupportedFormats() {
|
public List<FileFormat> getSupportedFormats() {
|
||||||
return fileTransformerExecutor.getSupportedFileFormats();
|
return fileTransformerExecutor.getSupportedFileFormats();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue