Update base version
This commit is contained in:
parent
bf2520c6b4
commit
865c1d7e3f
|
@ -18,7 +18,7 @@
|
||||||
<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>0.0.2</transformer-base.version>
|
<transformer-base.version>0.0.3</transformer-base.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
|
@ -6,13 +6,19 @@ import org.springframework.boot.context.properties.bind.ConstructorBinding;
|
||||||
@ConfigurationProperties(prefix = "file.storage")
|
@ConfigurationProperties(prefix = "file.storage")
|
||||||
public class FileStorageProperties {
|
public class FileStorageProperties {
|
||||||
private final String temp;
|
private final String temp;
|
||||||
|
private final String transientPath;
|
||||||
|
|
||||||
@ConstructorBinding
|
@ConstructorBinding
|
||||||
public FileStorageProperties(String temp) {
|
public FileStorageProperties(String temp, String transientPath) {
|
||||||
this.temp = temp;
|
this.temp = temp;
|
||||||
|
this.transientPath = transientPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTemp() {
|
public String getTemp() {
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTransientPath() {
|
||||||
|
return transientPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,10 @@ import eu.eudat.file.transformer.models.dmpblueprint.definition.SystemFieldFileT
|
||||||
import eu.eudat.file.transformer.model.enums.FileFormats;
|
import eu.eudat.file.transformer.model.enums.FileFormats;
|
||||||
import eu.eudat.file.transformer.models.misc.FileEnvelope;
|
import eu.eudat.file.transformer.models.misc.FileEnvelope;
|
||||||
import eu.eudat.file.transformer.model.file.FileEnvelopeInternal;
|
import eu.eudat.file.transformer.model.file.FileEnvelopeInternal;
|
||||||
import eu.eudat.file.transformer.models.reference.ReferenceFileTransformerModel;\
|
import eu.eudat.file.transformer.models.misc.FileFormat;
|
||||||
|
import eu.eudat.file.transformer.models.reference.ReferenceFileTransformerModel;
|
||||||
import eu.eudat.file.transformer.utils.pdf.PDFUtils;
|
import eu.eudat.file.transformer.utils.pdf.PDFUtils;
|
||||||
|
import eu.eudat.file.transformer.utils.storage.FileStorageService;
|
||||||
import eu.eudat.file.transformer.utils.types.ParagraphStyle;
|
import eu.eudat.file.transformer.utils.types.ParagraphStyle;
|
||||||
import eu.eudat.file.transformer.utils.word.WordBuilder;
|
import eu.eudat.file.transformer.utils.word.WordBuilder;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||||
|
@ -47,18 +49,25 @@ import java.util.*;
|
||||||
@Component
|
@Component
|
||||||
public class WordFileTransformer implements FileTransformerClient {
|
public class WordFileTransformer implements FileTransformerClient {
|
||||||
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(), true, "fa-file-pdf-o"),
|
||||||
|
new FileFormat(FileFormats.DOCX.getValue(), true, "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;
|
||||||
private final ApplicationContext applicationContext;
|
private final ApplicationContext applicationContext;
|
||||||
private final ObjectMapper objectMapper;
|
private final ObjectMapper objectMapper;
|
||||||
|
private final FileStorageService fileStorageService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public WordFileTransformer(FilePathProperties fileTemplateProperties, FileStorageProperties fileStorageProperties, PdfProperties pdfProperties, ApplicationContext applicationContext) {
|
public WordFileTransformer(FilePathProperties fileTemplateProperties, FileStorageProperties fileStorageProperties, PdfProperties pdfProperties, ApplicationContext applicationContext, FileStorageService fileStorageService) {
|
||||||
this.fileTemplateProperties = fileTemplateProperties;
|
this.fileTemplateProperties = fileTemplateProperties;
|
||||||
this.fileStorageProperties = fileStorageProperties;
|
this.fileStorageProperties = fileStorageProperties;
|
||||||
this.pdfProperties = pdfProperties;
|
this.pdfProperties = pdfProperties;
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
|
this.fileStorageService = fileStorageService;
|
||||||
this.objectMapper = new ObjectMapper();
|
this.objectMapper = new ObjectMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,14 +84,8 @@ public class WordFileTransformer implements FileTransformerClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DmpFileTransformerModel importDmp(FileEnvelope file) {
|
public FileEnvelope exportDescription(DescriptionFileTransformerModel descriptionFileTransformerModel, String format) throws InvalidApplicationException, IOException {
|
||||||
//Nothing to do here
|
FileFormats fileFormat = FileFormats.of(format);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FileEnvelope exportDescription(DescriptionFileTransformerModel descriptionFileTransformerModel) throws InvalidApplicationException, IOException {
|
|
||||||
FileFormats fileFormat = FileFormats.of(properties.getFormat());
|
|
||||||
return switch (fileFormat) {
|
return switch (fileFormat) {
|
||||||
case DOCX -> getDescriptionWordDocument(descriptionFileTransformerModel);
|
case DOCX -> getDescriptionWordDocument(descriptionFileTransformerModel);
|
||||||
case PDF -> {
|
case PDF -> {
|
||||||
|
@ -91,17 +94,25 @@ public class WordFileTransformer implements FileTransformerClient {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DescriptionFileTransformerModel importDescription(FileEnvelope file) {
|
public DmpFileTransformerModel importDmp(FileEnvelope envelope) {
|
||||||
|
//Nothing to do here
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DescriptionFileTransformerModel importDescription(FileEnvelope envelope) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileTransformerConfiguration getConfiguration() {
|
public FileTransformerConfiguration getConfiguration() {
|
||||||
return null; //TODO
|
FileTransformerConfiguration configuration = new FileTransformerConfiguration();
|
||||||
// return this.zenodoProperties.getDepositConfiguration();
|
configuration.setFileTransformerId("docx/pdf");
|
||||||
|
configuration.setExportVariants(FILE_FORMATS);
|
||||||
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileEnvelope getPdfDocument(FileEnvelopeInternal wordFile) throws IOException {
|
private FileEnvelope getPdfDocument(FileEnvelopeInternal wordFile) throws IOException {
|
||||||
|
@ -109,7 +120,7 @@ public class WordFileTransformer implements FileTransformerClient {
|
||||||
FileEnvelope result = new FileEnvelope();
|
FileEnvelope result = new FileEnvelope();
|
||||||
result.setFilename(wordFile.getFilename().replaceAll(".docx", ".pdf"));
|
result.setFilename(wordFile.getFilename().replaceAll(".docx", ".pdf"));
|
||||||
try (FileInputStream fis = new FileInputStream(pdfFile)) {
|
try (FileInputStream fis = new FileInputStream(pdfFile)) {
|
||||||
result.setFile(fis.readAllBytes());
|
result.setFile(fileStorageService.storeFile(fis.readAllBytes()));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -119,14 +130,14 @@ public class WordFileTransformer implements FileTransformerClient {
|
||||||
FileEnvelope result = new FileEnvelope();
|
FileEnvelope result = new FileEnvelope();
|
||||||
result.setFilename(wordFile.getFilename());
|
result.setFilename(wordFile.getFilename());
|
||||||
try (FileInputStream fis = new FileInputStream(wordFile.getFile())) {
|
try (FileInputStream fis = new FileInputStream(wordFile.getFile())) {
|
||||||
result.setFile(fis.readAllBytes());
|
result.setFile(fileStorageService.storeFile(fis.readAllBytes()));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileEnvelopeInternal getWordDocument(DmpFileTransformerModel dmpEntity, Boolean versioned) throws IOException {
|
private FileEnvelopeInternal getWordDocument(DmpFileTransformerModel dmpEntity, Boolean versioned) throws IOException {
|
||||||
WordBuilder wordBuilder = new WordBuilder(fileTemplateProperties, fileStorageProperties);
|
WordBuilder wordBuilder = new WordBuilder(fileTemplateProperties, fileStorageProperties);
|
||||||
\ XWPFDocument document = new XWPFDocument(new FileInputStream(ResourceUtils.getFile(fileTemplateProperties.getWordTemplate())));
|
XWPFDocument document = new XWPFDocument(new FileInputStream(ResourceUtils.getFile(fileTemplateProperties.getWordTemplate())));
|
||||||
|
|
||||||
wordBuilder.fillFirstPage(dmpEntity, null, document, false);
|
wordBuilder.fillFirstPage(dmpEntity, null, document, false);
|
||||||
|
|
||||||
|
@ -505,7 +516,7 @@ public class WordFileTransformer implements FileTransformerClient {
|
||||||
FileEnvelope fileEnvelope = new FileEnvelope();
|
FileEnvelope fileEnvelope = new FileEnvelope();
|
||||||
fileEnvelope.setFilename(wordFile.getFilename());
|
fileEnvelope.setFilename(wordFile.getFilename());
|
||||||
try (FileInputStream fis = new FileInputStream(wordFile.getFile())) {
|
try (FileInputStream fis = new FileInputStream(wordFile.getFile())) {
|
||||||
fileEnvelope.setFile(fis.readAllBytes());
|
fileEnvelope.setFile(fileStorageService.storeFile(fis.readAllBytes()));
|
||||||
}
|
}
|
||||||
return fileEnvelope;
|
return fileEnvelope;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package eu.eudat.file.transformer.utils.storage;
|
||||||
|
|
||||||
|
import eu.eudat.file.transformer.configuration.FileStorageProperties;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class FileStorageService {
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(FileStorageService.class);
|
||||||
|
|
||||||
|
private final FileStorageProperties properties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public FileStorageService(FileStorageProperties properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String storeFile(byte[] data) {
|
||||||
|
try {
|
||||||
|
String fileName = UUID.randomUUID().toString();
|
||||||
|
Path storagePath = Paths.get(properties.getTransientPath() + "/" + fileName);
|
||||||
|
Files.write(storagePath, data, StandardOpenOption.CREATE_NEW);
|
||||||
|
return fileName;
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] readFile(String fileRef) {
|
||||||
|
try (FileInputStream inputStream = new FileInputStream(properties.getTransientPath() + "/" + fileRef)) {
|
||||||
|
return inputStream.readAllBytes();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return new byte[1];
|
||||||
|
}
|
||||||
|
}
|
|
@ -610,157 +610,149 @@ public class WordBuilder {
|
||||||
if (field.getIncludeInExport()) {
|
if (field.getIncludeInExport()) {
|
||||||
if (!createListing) {
|
if (!createListing) {
|
||||||
try {
|
try {
|
||||||
if(((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.UPLOAD)){
|
if (field.getData() != null) {
|
||||||
boolean isImage = false;
|
if (field.getData().getFieldType().equals(FieldType.UPLOAD)) {
|
||||||
for(UploadOptionFileTransformerModel type: ((UploadDataFileTransformerModel)field.getData()).getTypes()){
|
boolean isImage = false;
|
||||||
String fileFormat = type.getValue();
|
for (UploadOptionFileTransformerModel type : ((UploadDataFileTransformerModel) field.getData()).getTypes()) {
|
||||||
if(IMAGE_TYPE_MAP.containsKey(fileFormat)){
|
String fileFormat = type.getValue();
|
||||||
isImage = true;
|
if (IMAGE_TYPE_MAP.containsKey(fileFormat)) {
|
||||||
break;
|
isImage = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (isImage) {
|
||||||
if(isImage){
|
if (field.getData().getValue() != null && !field.getData().getValue().isEmpty()) {
|
||||||
if (field.getData().getValue() != null && !field.getData().getValue().toString().isEmpty()) {
|
XWPFParagraph paragraph = addParagraphContent(mapper.convertValue(field.getData().getValue(), Map.class), mainDocumentPart, ParagraphStyle.IMAGE, numId, 0);
|
||||||
XWPFParagraph paragraph = addParagraphContent(mapper.convertValue(field.getData().getValue(), Map.class), mainDocumentPart, ParagraphStyle.IMAGE, numId, 0);
|
if (paragraph != null) {
|
||||||
if (paragraph != null) {
|
|
||||||
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||||
// number.setVal(BigInteger.valueOf(indent));
|
// number.setVal(BigInteger.valueOf(indent));
|
||||||
hasValue = true;
|
|
||||||
}
|
|
||||||
if(hasMultiplicityItems){
|
|
||||||
hasMultiplicityItems = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (field.getData().getValue() != null && !field.getData().getValue().toString().isEmpty()) {
|
|
||||||
this.indent = indent;
|
|
||||||
String format = this.formatter(field);
|
|
||||||
if (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.TAGS)) {
|
|
||||||
format = getCommaSeparatedFormatsFromJson(format, "name");
|
|
||||||
} else if (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.AUTO_COMPLETE)) {
|
|
||||||
format = getCommaSeparatedFormatsFromJson(format, "label");
|
|
||||||
}
|
|
||||||
switch (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType()) {
|
|
||||||
case ORGANIZATIONS:
|
|
||||||
case EXTERNAL_DATASETS:
|
|
||||||
case PUBLICATIONS:
|
|
||||||
if(format != null && !format.isEmpty()){
|
|
||||||
Object hasMultiAutoComplete = mapper.convertValue(field.getData(), Map.class).get("multiAutoComplete");
|
|
||||||
boolean isMultiAutoComplete = hasMultiAutoComplete != null && (boolean)hasMultiAutoComplete;
|
|
||||||
if(!isMultiAutoComplete){
|
|
||||||
Map<String, String> value = mapper.readValue((String)field.getData().getValue(), Map.class);
|
|
||||||
if(hasMultiplicityItems){
|
|
||||||
createHypeLink(mainDocumentPart, format, value.get("pidTypeField"), value.get("pid"), true, false);
|
|
||||||
hasMultiplicityItems = false;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
createHypeLink(mainDocumentPart, format, value.get("pidTypeField"), value.get("pid"), false, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
|
||||||
List<Map<String, Object>> values = new ArrayList<>();
|
|
||||||
try {
|
|
||||||
values = Arrays.asList(mapper.readValue(field.getData().getValue().toString(), HashMap[].class));
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
Map <String, Object> map = new HashMap<>();
|
|
||||||
map.put("label", field.getData().getValue());
|
|
||||||
values.add(map);
|
|
||||||
}
|
|
||||||
if (values.size() > 1) {
|
|
||||||
for (Map<String, Object> value : values) {
|
|
||||||
if(hasMultiplicityItems){
|
|
||||||
createHypeLink(mainDocumentPart, (String) value.get("name"), (String) value.get("pidTypeField"), (String) value.get("pid"), true, true);
|
|
||||||
hasMultiplicityItems = false;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
createHypeLink(mainDocumentPart, (String) value.get("name"), (String) value.get("pidTypeField"), (String) value.get("pid"), false, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(values.size() == 1){
|
|
||||||
if(hasMultiplicityItems){
|
|
||||||
createHypeLink(mainDocumentPart, format, (String) values.get(0).get("pidTypeField"), (String) values.get(0).get("pid"), true, false);
|
|
||||||
hasMultiplicityItems = false;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
createHypeLink(mainDocumentPart, format, (String) values.get(0).get("pidTypeField"), (String) values.get(0).get("pid"), false, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hasValue = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
boolean isResearcher = ((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.RESEARCHERS);
|
|
||||||
if(format != null && !format.isEmpty()){
|
|
||||||
Object hasMultiAutoComplete = mapper.convertValue(field.getData(), Map.class).get("multiAutoComplete");
|
|
||||||
boolean isMultiAutoComplete = hasMultiAutoComplete != null && (boolean)hasMultiAutoComplete;
|
|
||||||
boolean arrayStringFormat = format.charAt(0) == '[';
|
|
||||||
if(arrayStringFormat || isMultiAutoComplete){
|
|
||||||
List<String> values = (arrayStringFormat) ? Arrays.asList(format.substring(1, format.length() - 1).split(",[ ]*")) : Arrays.asList(format.split(",[ ]*"));
|
|
||||||
if(values.size() > 1) {
|
|
||||||
boolean orcidResearcher;
|
|
||||||
for (String val : values) {
|
|
||||||
orcidResearcher = false;
|
|
||||||
String orcId = null;
|
|
||||||
if(isResearcher && val.contains("orcid:")){
|
|
||||||
orcId = val.substring(val.indexOf(':') + 1, val.indexOf(')'));
|
|
||||||
val = val.substring(0, val.indexOf(':') + 1) + " ";
|
|
||||||
orcidResearcher = true;
|
|
||||||
}
|
|
||||||
format = "• " + val;
|
|
||||||
if(hasMultiplicityItems){
|
|
||||||
mainDocumentPart.getLastParagraph().createRun().setText(format);
|
|
||||||
if(orcidResearcher){
|
|
||||||
XWPFHyperlinkRun run = mainDocumentPart.getLastParagraph().createHyperlinkRun("https://orcid.org/" + orcId);
|
|
||||||
run.setText(orcId);
|
|
||||||
run.setUnderline(UnderlinePatterns.SINGLE);
|
|
||||||
run.setColor("0000FF");
|
|
||||||
mainDocumentPart.getLastParagraph().createRun().setText(")");
|
|
||||||
}
|
|
||||||
hasMultiplicityItems = false;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, ((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent);
|
|
||||||
if(orcidResearcher){
|
|
||||||
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
|
|
||||||
run.setText(orcId);
|
|
||||||
run.setUnderline(UnderlinePatterns.SINGLE);
|
|
||||||
run.setColor("0000FF");
|
|
||||||
paragraph.createRun().setText(")");
|
|
||||||
}
|
|
||||||
if (paragraph != null) {
|
|
||||||
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
|
||||||
// number.setVal(BigInteger.valueOf(indent));
|
|
||||||
hasValue = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
format = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(values.size() == 1){
|
|
||||||
format = values.get(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (format != null) {
|
|
||||||
if (hasMultiplicityItems) {
|
|
||||||
mainDocumentPart.getLastParagraph().createRun().setText(format);
|
|
||||||
hasMultiplicityItems = false;
|
|
||||||
hasValue = true;
|
hasValue = true;
|
||||||
}
|
}
|
||||||
else {
|
if (hasMultiplicityItems) {
|
||||||
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, ((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent);
|
hasMultiplicityItems = false;
|
||||||
if (paragraph != null) {
|
|
||||||
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
|
||||||
// number.setVal(BigInteger.valueOf(indent));
|
|
||||||
hasValue = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else if (field.getData().getValue() != null && !field.getData().getValue().isEmpty()) {
|
||||||
|
this.indent = indent;
|
||||||
|
String format = this.formatter(field);
|
||||||
|
if (field.getData().getFieldType().equals(FieldType.TAGS)) {
|
||||||
|
format = getCommaSeparatedFormatsFromJson(format, "name");
|
||||||
|
} else if (field.getData().getFieldType().equals(FieldType.AUTO_COMPLETE)) {
|
||||||
|
format = getCommaSeparatedFormatsFromJson(format, "label");
|
||||||
|
}
|
||||||
|
switch (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType()) {
|
||||||
|
case ORGANIZATIONS:
|
||||||
|
case EXTERNAL_DATASETS:
|
||||||
|
case PUBLICATIONS:
|
||||||
|
if (format != null && !format.isEmpty()) {
|
||||||
|
Object hasMultiAutoComplete = mapper.convertValue(field.getData(), Map.class).get("multiAutoComplete");
|
||||||
|
boolean isMultiAutoComplete = hasMultiAutoComplete != null && (boolean) hasMultiAutoComplete;
|
||||||
|
if (!isMultiAutoComplete) {
|
||||||
|
Map<String, String> value = mapper.readValue(field.getData().getValue(), Map.class);
|
||||||
|
if (hasMultiplicityItems) {
|
||||||
|
createHypeLink(mainDocumentPart, format, value.get("pidTypeField"), value.get("pid"), true, false);
|
||||||
|
hasMultiplicityItems = false;
|
||||||
|
} else {
|
||||||
|
createHypeLink(mainDocumentPart, format, value.get("pidTypeField"), value.get("pid"), false, false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||||
|
List<Map<String, Object>> values = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
values = Arrays.asList(mapper.readValue(field.getData().getValue(), HashMap[].class));
|
||||||
|
} catch (Exception e) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("label", field.getData().getValue());
|
||||||
|
values.add(map);
|
||||||
|
}
|
||||||
|
if (values.size() > 1) {
|
||||||
|
for (Map<String, Object> value : values) {
|
||||||
|
if (hasMultiplicityItems) {
|
||||||
|
createHypeLink(mainDocumentPart, (String) value.get("name"), (String) value.get("pidTypeField"), (String) value.get("pid"), true, true);
|
||||||
|
hasMultiplicityItems = false;
|
||||||
|
} else {
|
||||||
|
createHypeLink(mainDocumentPart, (String) value.get("name"), (String) value.get("pidTypeField"), (String) value.get("pid"), false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (values.size() == 1) {
|
||||||
|
if (hasMultiplicityItems) {
|
||||||
|
createHypeLink(mainDocumentPart, format, (String) values.get(0).get("pidTypeField"), (String) values.get(0).get("pid"), true, false);
|
||||||
|
hasMultiplicityItems = false;
|
||||||
|
} else {
|
||||||
|
createHypeLink(mainDocumentPart, format, (String) values.get(0).get("pidTypeField"), (String) values.get(0).get("pid"), false, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hasValue = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
boolean isResearcher = field.getData().getFieldType().equals(FieldType.RESEARCHERS);
|
||||||
|
if (format != null && !format.isEmpty()) {
|
||||||
|
Object hasMultiAutoComplete = mapper.convertValue(field.getData(), Map.class).get("multiAutoComplete");
|
||||||
|
boolean isMultiAutoComplete = hasMultiAutoComplete != null && (boolean) hasMultiAutoComplete;
|
||||||
|
boolean arrayStringFormat = format.charAt(0) == '[';
|
||||||
|
if (arrayStringFormat || isMultiAutoComplete) {
|
||||||
|
List<String> values = (arrayStringFormat) ? Arrays.asList(format.substring(1, format.length() - 1).split(",[ ]*")) : Arrays.asList(format.split(",[ ]*"));
|
||||||
|
if (values.size() > 1) {
|
||||||
|
boolean orcidResearcher;
|
||||||
|
for (String val : values) {
|
||||||
|
orcidResearcher = false;
|
||||||
|
String orcId = null;
|
||||||
|
if (isResearcher && val.contains("orcid:")) {
|
||||||
|
orcId = val.substring(val.indexOf(':') + 1, val.indexOf(')'));
|
||||||
|
val = val.substring(0, val.indexOf(':') + 1) + " ";
|
||||||
|
orcidResearcher = true;
|
||||||
|
}
|
||||||
|
format = "• " + val;
|
||||||
|
if (hasMultiplicityItems) {
|
||||||
|
mainDocumentPart.getLastParagraph().createRun().setText(format);
|
||||||
|
if (orcidResearcher) {
|
||||||
|
XWPFHyperlinkRun run = mainDocumentPart.getLastParagraph().createHyperlinkRun("https://orcid.org/" + orcId);
|
||||||
|
run.setText(orcId);
|
||||||
|
run.setUnderline(UnderlinePatterns.SINGLE);
|
||||||
|
run.setColor("0000FF");
|
||||||
|
mainDocumentPart.getLastParagraph().createRun().setText(")");
|
||||||
|
}
|
||||||
|
hasMultiplicityItems = false;
|
||||||
|
} else {
|
||||||
|
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, ((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent);
|
||||||
|
if (orcidResearcher) {
|
||||||
|
XWPFHyperlinkRun run = paragraph.createHyperlinkRun("https://orcid.org/" + orcId);
|
||||||
|
run.setText(orcId);
|
||||||
|
run.setUnderline(UnderlinePatterns.SINGLE);
|
||||||
|
run.setColor("0000FF");
|
||||||
|
paragraph.createRun().setText(")");
|
||||||
|
}
|
||||||
|
if (paragraph != null) {
|
||||||
|
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||||
|
// number.setVal(BigInteger.valueOf(indent));
|
||||||
|
hasValue = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
format = null;
|
||||||
|
}
|
||||||
|
} else if (values.size() == 1) {
|
||||||
|
format = values.get(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (format != null) {
|
||||||
|
if (hasMultiplicityItems) {
|
||||||
|
mainDocumentPart.getLastParagraph().createRun().setText(format);
|
||||||
|
hasMultiplicityItems = false;
|
||||||
|
hasValue = true;
|
||||||
|
} else {
|
||||||
|
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getData().getFieldType().equals(FieldType.RICH_TEXT_AREA) ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId, indent);
|
||||||
|
if (paragraph != null) {
|
||||||
|
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||||
|
// number.setVal(BigInteger.valueOf(indent));
|
||||||
|
hasValue = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -868,7 +860,7 @@ public class WordBuilder {
|
||||||
if (field.getData().getValue() == null) {
|
if (field.getData().getValue() == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
switch (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType()) {
|
switch (field.getData().getFieldType()) {
|
||||||
case RESEARCHERS:
|
case RESEARCHERS:
|
||||||
// case "projects": //TODO: Description Templatedefinition
|
// case "projects": //TODO: Description Templatedefinition
|
||||||
case ORGANIZATIONS:
|
case ORGANIZATIONS:
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package eu.eudat.file.transformer.controller;
|
package eu.eudat.file.transformer.controller;
|
||||||
|
|
||||||
import eu.eudat.file.transformer.executor.FileTransformerExecutor;
|
import eu.eudat.file.transformer.interfaces.FileTransformerClient;
|
||||||
|
import eu.eudat.file.transformer.interfaces.FileTransformerConfiguration;
|
||||||
import eu.eudat.file.transformer.models.description.DescriptionFileTransformerModel;
|
import eu.eudat.file.transformer.models.description.DescriptionFileTransformerModel;
|
||||||
import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel;
|
import eu.eudat.file.transformer.models.dmp.DmpFileTransformerModel;
|
||||||
import eu.eudat.file.transformer.models.misc.FileEnvelope;
|
import eu.eudat.file.transformer.models.misc.FileEnvelope;
|
||||||
import eu.eudat.file.transformer.model.file.FileVariant;
|
|
||||||
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.*;
|
||||||
|
|
||||||
|
@ -14,39 +14,35 @@ import java.util.List;
|
||||||
@RequestMapping("/api/file")
|
@RequestMapping("/api/file")
|
||||||
public class FileTransformerController {
|
public class FileTransformerController {
|
||||||
|
|
||||||
private final FileTransformerExecutor fileTransformerExecutor;
|
private final FileTransformerClient fileTransformerExecutor;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public FileTransformerController(FileTransformerExecutor fileTransformerExecutor) {
|
public FileTransformerController(FileTransformerClient fileTransformerExecutor) {
|
||||||
this.fileTransformerExecutor = fileTransformerExecutor;
|
this.fileTransformerExecutor = fileTransformerExecutor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/export/dmp")
|
@PostMapping("/export/dmp")
|
||||||
public FileEnvelope exportDmp(@RequestBody DmpFileTransformerModel dmpDepositModel, @RequestParam(value = "format",required = false)String format) throws Exception {
|
public FileEnvelope exportDmp(@RequestBody DmpFileTransformerModel dmpDepositModel) throws Exception {
|
||||||
ExtraPropertiesModel properties = new ExtraPropertiesModel();
|
return fileTransformerExecutor.exportDmp(dmpDepositModel);
|
||||||
properties.setFormat(format != null ? format : "docx");
|
|
||||||
return fileTransformerExecutor.exportDmp(dmpDepositModel, properties);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/export/description")
|
@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 {
|
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();
|
return fileTransformerExecutor.exportDescription(descriptionFileTransformerModel, format);
|
||||||
properties.setFormat(format != null ? format : "docx");
|
|
||||||
return fileTransformerExecutor.exportDescription(descriptionFileTransformerModel, properties);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/import/dmp")
|
@PostMapping("/import/dmp")
|
||||||
public DmpFileTransformerModel importFileToDmp(@RequestBody FileEnvelope fileEnvelope) {
|
public DmpFileTransformerModel importFileToDmp(@RequestBody FileEnvelope fileEnvelope) {
|
||||||
return fileTransformerExecutor.importFileToDmp(fileEnvelope);
|
return fileTransformerExecutor.importDmp(fileEnvelope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/import/description")
|
@PostMapping("/import/description")
|
||||||
public DescriptionFileTransformerModel importFileToDescription(@RequestBody FileEnvelope fileEnvelope) {
|
public DescriptionFileTransformerModel importFileToDescription(@RequestBody FileEnvelope fileEnvelope) {
|
||||||
return fileTransformerExecutor.importFileToDescription(fileEnvelope);
|
return fileTransformerExecutor.importDescription(fileEnvelope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/formats")
|
@GetMapping("/formats")
|
||||||
public List<FileVariant> getSupportedFormats() {
|
public FileTransformerConfiguration getSupportedFormats() {
|
||||||
return fileTransformerExecutor.getSupportedFileFormats();
|
return fileTransformerExecutor.getConfiguration();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,4 +4,5 @@ file:
|
||||||
pid-template: classpath:pidLinks.json
|
pid-template: classpath:pidLinks.json
|
||||||
word-description-template: classpath:documents/h2020_dataset.docx
|
word-description-template: classpath:documents/h2020_dataset.docx
|
||||||
storage:
|
storage:
|
||||||
temp: ${TEMP_PATH}
|
temp: ${TEMP_PATH}
|
||||||
|
transient-path: ${TRANSIENT_PATH}
|
Loading…
Reference in New Issue