Make the supported formats to return some additional information

This commit is contained in:
George Kalampokis 2023-12-19 18:03:58 +02:00
parent 666e6b1ba2
commit 236f3bbb8e
7 changed files with 48 additions and 66 deletions

View File

@ -6,49 +6,26 @@
<groupId>gr.cite.opendmp</groupId>
<artifactId>file-transformer-document-parent</artifactId>
<version>${revision}</version>
<relativePath>..</relativePath>
<relativePath>../pom.xml</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>
<transformer-base.version>1.0-SNAPSHOT</transformer-base.version>
</properties>
<dependencies>
<dependency>
<groupId>gr.cite.opendmp</groupId>
<artifactId>file-transformer-base</artifactId>
<version>1.0-SNAPSHOT</version>
<version>${transformer-base.version}</version>
</dependency>
<dependency>
@ -79,12 +56,6 @@
<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>

View File

@ -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.file.FileEnvelope;
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.VisibilityRuleServiceImpl;
import eu.eudat.file.transformer.utils.descriptionTemplate.DescriptionTemplateService;
@ -43,6 +44,10 @@ import java.util.*;
public class WordFileTransformer implements FileTransformerExecutor {
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 FileStorageProperties fileStorageProperties;
private final PdfProperties pdfProperties;
@ -95,8 +100,8 @@ public class WordFileTransformer implements FileTransformerExecutor {
}
@Override
public List<String> getSupportedFileFormats() {
return Arrays.stream(FileFormats.values()).map(FileFormats::getValue).toList();
public List<FileFormat> getSupportedFileFormats() {
return FILE_FORMATS;
}
private FileEnvelope getPdfDocument(FileEnvelopeInternal wordFile) throws IOException {
@ -126,11 +131,18 @@ public class WordFileTransformer implements FileTransformerExecutor {
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();
List<Reference> grants = new ArrayList<>();
List<Reference> researchers = new ArrayList<>();
List<Reference> organizations = new ArrayList<>();
List<Reference> funders = new ArrayList<>();
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 = wordBuilder.findPosOfPoweredBy(document);

View File

@ -1,29 +1,18 @@
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();

View File

@ -18,15 +18,12 @@ import eu.eudat.file.transformer.enums.ReferenceType;
import eu.eudat.file.transformer.model.*;
import eu.eudat.file.transformer.services.visibility.VisibilityRuleService;
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.types.ParagraphStyle;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.usermodel.*;
import org.apache.xmlbeans.XmlCursor;
import org.json.JSONArray;
import org.json.JSONException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.NodeTraversor;
@ -781,16 +778,16 @@ public class WordBuilder {
return null;
}
try {
JSONArray array = new JSONArray(JavaToJson.objectStringToJson(format));
List<Map<String, Object>> array = mapper.readValue(format, ArrayList.class);
StringBuilder multipleFormats = new StringBuilder();
for (int i = 0; i < array.length(); i++) {
multipleFormats.append(array.getJSONObject(i).getString(attribute)).append(", ");
for (int i = 0; i < array.size(); i++) {
multipleFormats.append(array.get(i).get(attribute)).append(", ");
}
if (multipleFormats.length() > 0) {
multipleFormats.setLength(multipleFormats.length() - 2);
}
return multipleFormats.toString();
} catch (JSONException e) {
} catch (JsonProcessingException e) {
return format;
}
}
@ -1019,11 +1016,16 @@ public class WordBuilder {
int parPos = 0;
int descrParPos = -1;
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> researchers = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(reference -> reference.getType().equals(ReferenceType.Researcher)).toList();
List<Reference> organizations = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Organizations)).toList();
List<Reference> funders = dmpEntity.getDmpReferences().stream().map(DmpReference::getReference).filter(referenceFileModel -> referenceFileModel.getType().equals(ReferenceType.Funder) && referenceFileModel.getIsActive().equals(IsActive.Active)).toList();
List<Reference> grants = new ArrayList<>();
List<Reference> researchers = new ArrayList<>();
List<Reference> organizations = new ArrayList<>();
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()){
List<XWPFRun> runs = p.getRuns();
if(runs != null){

View File

@ -21,6 +21,14 @@
<revision>1.0.0-SNAPSHOT</revision>
</properties>
<dependencies>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
<modules>
<module>core</module>
<module>web</module>

View File

@ -6,7 +6,7 @@
<groupId>gr.cite.opendmp</groupId>
<artifactId>file-transformer-document-parent</artifactId>
<version>${revision}</version>
<relativePath>..</relativePath>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>file-transformer-document-web</artifactId>

View File

@ -4,12 +4,12 @@ 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 eu.eudat.file.transformer.model.file.FileFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.List;
@RestController
@RequestMapping("/api/file")
@ -47,7 +47,7 @@ public class FileTransformerController {
}
@GetMapping("/formats")
public List<String> getSupportedFormats() {
public List<FileFormat> getSupportedFormats() {
return fileTransformerExecutor.getSupportedFileFormats();
}
}