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.release>21</maven.compiler.release>
|
||||
<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>
|
||||
|
||||
<dependencies>
|
||||
|
|
|
@ -6,13 +6,19 @@ import org.springframework.boot.context.properties.bind.ConstructorBinding;
|
|||
@ConfigurationProperties(prefix = "file.storage")
|
||||
public class FileStorageProperties {
|
||||
private final String temp;
|
||||
private final String transientPath;
|
||||
|
||||
@ConstructorBinding
|
||||
public FileStorageProperties(String temp) {
|
||||
public FileStorageProperties(String temp, String transientPath) {
|
||||
this.temp = temp;
|
||||
this.transientPath = transientPath;
|
||||
}
|
||||
|
||||
public String getTemp() {
|
||||
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.models.misc.FileEnvelope;
|
||||
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.storage.FileStorageService;
|
||||
import eu.eudat.file.transformer.utils.types.ParagraphStyle;
|
||||
import eu.eudat.file.transformer.utils.word.WordBuilder;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
|
@ -47,18 +49,25 @@ import java.util.*;
|
|||
@Component
|
||||
public class WordFileTransformer implements FileTransformerClient {
|
||||
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 FileStorageProperties fileStorageProperties;
|
||||
private final PdfProperties pdfProperties;
|
||||
private final ApplicationContext applicationContext;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final FileStorageService fileStorageService;
|
||||
|
||||
@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.fileStorageProperties = fileStorageProperties;
|
||||
this.pdfProperties = pdfProperties;
|
||||
this.applicationContext = applicationContext;
|
||||
this.fileStorageService = fileStorageService;
|
||||
this.objectMapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
|
@ -75,14 +84,8 @@ public class WordFileTransformer implements FileTransformerClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DmpFileTransformerModel importDmp(FileEnvelope file) {
|
||||
//Nothing to do here
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileEnvelope exportDescription(DescriptionFileTransformerModel descriptionFileTransformerModel) throws InvalidApplicationException, IOException {
|
||||
FileFormats fileFormat = FileFormats.of(properties.getFormat());
|
||||
public FileEnvelope exportDescription(DescriptionFileTransformerModel descriptionFileTransformerModel, String format) throws InvalidApplicationException, IOException {
|
||||
FileFormats fileFormat = FileFormats.of(format);
|
||||
return switch (fileFormat) {
|
||||
case DOCX -> getDescriptionWordDocument(descriptionFileTransformerModel);
|
||||
case PDF -> {
|
||||
|
@ -91,17 +94,25 @@ public class WordFileTransformer implements FileTransformerClient {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTransformerConfiguration getConfiguration() {
|
||||
return null; //TODO
|
||||
// return this.zenodoProperties.getDepositConfiguration();
|
||||
FileTransformerConfiguration configuration = new FileTransformerConfiguration();
|
||||
configuration.setFileTransformerId("docx/pdf");
|
||||
configuration.setExportVariants(FILE_FORMATS);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private FileEnvelope getPdfDocument(FileEnvelopeInternal wordFile) throws IOException {
|
||||
|
@ -109,7 +120,7 @@ public class WordFileTransformer implements FileTransformerClient {
|
|||
FileEnvelope result = new FileEnvelope();
|
||||
result.setFilename(wordFile.getFilename().replaceAll(".docx", ".pdf"));
|
||||
try (FileInputStream fis = new FileInputStream(pdfFile)) {
|
||||
result.setFile(fis.readAllBytes());
|
||||
result.setFile(fileStorageService.storeFile(fis.readAllBytes()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -119,14 +130,14 @@ public class WordFileTransformer implements FileTransformerClient {
|
|||
FileEnvelope result = new FileEnvelope();
|
||||
result.setFilename(wordFile.getFilename());
|
||||
try (FileInputStream fis = new FileInputStream(wordFile.getFile())) {
|
||||
result.setFile(fis.readAllBytes());
|
||||
result.setFile(fileStorageService.storeFile(fis.readAllBytes()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private FileEnvelopeInternal getWordDocument(DmpFileTransformerModel dmpEntity, Boolean versioned) throws IOException {
|
||||
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);
|
||||
|
||||
|
@ -505,7 +516,7 @@ public class WordFileTransformer implements FileTransformerClient {
|
|||
FileEnvelope fileEnvelope = new FileEnvelope();
|
||||
fileEnvelope.setFilename(wordFile.getFilename());
|
||||
try (FileInputStream fis = new FileInputStream(wordFile.getFile())) {
|
||||
fileEnvelope.setFile(fis.readAllBytes());
|
||||
fileEnvelope.setFile(fileStorageService.storeFile(fis.readAllBytes()));
|
||||
}
|
||||
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 (!createListing) {
|
||||
try {
|
||||
if(((BaseFieldDataFileTransformerModel) field.getData()).getFieldType().equals(FieldType.UPLOAD)){
|
||||
boolean isImage = false;
|
||||
for(UploadOptionFileTransformerModel type: ((UploadDataFileTransformerModel)field.getData()).getTypes()){
|
||||
String fileFormat = type.getValue();
|
||||
if(IMAGE_TYPE_MAP.containsKey(fileFormat)){
|
||||
isImage = true;
|
||||
break;
|
||||
if (field.getData() != null) {
|
||||
if (field.getData().getFieldType().equals(FieldType.UPLOAD)) {
|
||||
boolean isImage = false;
|
||||
for (UploadOptionFileTransformerModel type : ((UploadDataFileTransformerModel) field.getData()).getTypes()) {
|
||||
String fileFormat = type.getValue();
|
||||
if (IMAGE_TYPE_MAP.containsKey(fileFormat)) {
|
||||
isImage = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isImage){
|
||||
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);
|
||||
if (paragraph != null) {
|
||||
if (isImage) {
|
||||
if (field.getData().getValue() != null && !field.getData().getValue().isEmpty()) {
|
||||
XWPFParagraph paragraph = addParagraphContent(mapper.convertValue(field.getData().getValue(), Map.class), mainDocumentPart, ParagraphStyle.IMAGE, numId, 0);
|
||||
if (paragraph != null) {
|
||||
// CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||
// 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;
|
||||
}
|
||||
else {
|
||||
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, ((BaseFieldDataFileTransformerModel) 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;
|
||||
}
|
||||
if (hasMultiplicityItems) {
|
||||
hasMultiplicityItems = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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) {
|
||||
|
@ -868,7 +860,7 @@ public class WordBuilder {
|
|||
if (field.getData().getValue() == null) {
|
||||
return null;
|
||||
}
|
||||
switch (((BaseFieldDataFileTransformerModel) field.getData()).getFieldType()) {
|
||||
switch (field.getData().getFieldType()) {
|
||||
case RESEARCHERS:
|
||||
// case "projects": //TODO: Description Templatedefinition
|
||||
case ORGANIZATIONS:
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
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.dmp.DmpFileTransformerModel;
|
||||
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.web.bind.annotation.*;
|
||||
|
||||
|
@ -14,39 +14,35 @@ import java.util.List;
|
|||
@RequestMapping("/api/file")
|
||||
public class FileTransformerController {
|
||||
|
||||
private final FileTransformerExecutor fileTransformerExecutor;
|
||||
private final FileTransformerClient fileTransformerExecutor;
|
||||
|
||||
@Autowired
|
||||
public FileTransformerController(FileTransformerExecutor fileTransformerExecutor) {
|
||||
public FileTransformerController(FileTransformerClient 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);
|
||||
public FileEnvelope exportDmp(@RequestBody DmpFileTransformerModel dmpDepositModel) throws Exception {
|
||||
return fileTransformerExecutor.exportDmp(dmpDepositModel);
|
||||
}
|
||||
|
||||
@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);
|
||||
return fileTransformerExecutor.exportDescription(descriptionFileTransformerModel, format);
|
||||
}
|
||||
|
||||
@PostMapping("/import/dmp")
|
||||
public DmpFileTransformerModel importFileToDmp(@RequestBody FileEnvelope fileEnvelope) {
|
||||
return fileTransformerExecutor.importFileToDmp(fileEnvelope);
|
||||
return fileTransformerExecutor.importDmp(fileEnvelope);
|
||||
}
|
||||
|
||||
@PostMapping("/import/description")
|
||||
public DescriptionFileTransformerModel importFileToDescription(@RequestBody FileEnvelope fileEnvelope) {
|
||||
return fileTransformerExecutor.importFileToDescription(fileEnvelope);
|
||||
return fileTransformerExecutor.importDescription(fileEnvelope);
|
||||
}
|
||||
|
||||
@GetMapping("/formats")
|
||||
public List<FileVariant> getSupportedFormats() {
|
||||
return fileTransformerExecutor.getSupportedFileFormats();
|
||||
public FileTransformerConfiguration getSupportedFormats() {
|
||||
return fileTransformerExecutor.getConfiguration();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,4 +4,5 @@ file:
|
|||
pid-template: classpath:pidLinks.json
|
||||
word-description-template: classpath:documents/h2020_dataset.docx
|
||||
storage:
|
||||
temp: ${TEMP_PATH}
|
||||
temp: ${TEMP_PATH}
|
||||
transient-path: ${TRANSIENT_PATH}
|
Loading…
Reference in New Issue