This commit is contained in:
Diamantis Tziotzios 2024-06-21 12:49:31 +03:00
commit 099e8707e3
6 changed files with 90 additions and 25 deletions

View File

@ -10,6 +10,8 @@ public class AuditableAction {
public static final EventId FileTransformer_ImportFileToDmp = new EventId(1002, "FileTransformer_ImportFileToDmp");
public static final EventId FileTransformer_ImportFileToDescription = new EventId(1003, "FileTransformer_ImportFileToDescription");
public static final EventId FileTransformer_GetSupportedFormats = new EventId(1004, "FileTransformer_GetSupportedFormats");
public static final EventId FileTransformer_PreprocessingDmp = new EventId(1005, "FileTransformer_PreprocessingDmp");
public static final EventId FileTransformer_PreprocessingDescription = new EventId(1006, "FileTransformer_PreprocessingDescription");
}

View File

@ -18,7 +18,7 @@ import org.opencdmp.filetransformerbase.enums.FileTransformerEntityType;
import org.opencdmp.filetransformerbase.interfaces.FileTransformerClient;
import org.opencdmp.filetransformerbase.interfaces.FileTransformerConfiguration;
import org.opencdmp.filetransformer.docx.model.enums.FileFormats;
import org.opencdmp.filetransformerbase.models.misc.FileFormat;
import org.opencdmp.filetransformerbase.models.misc.*;
import org.opencdmp.filetransformer.docx.service.pdf.PdfService;
import org.opencdmp.filetransformer.docx.model.enums.ParagraphStyle;
import org.opencdmp.filetransformer.docx.service.storage.FileStorageService;
@ -124,12 +124,12 @@ public class WordFileTransformerService implements FileTransformerClient {
@Override
public DmpModel importDmp(FileEnvelopeModel envelope) {
public DmpModel importDmp(DmpImportModel dmpImportModel) {
throw new MyApplicationException("import not supported");
}
@Override
public DescriptionModel importDescription(FileEnvelopeModel envelope) {
public DescriptionModel importDescription(DescriptionImportModel descriptionImportModel) {
throw new MyApplicationException("import not supported");
}
@ -144,6 +144,16 @@ public class WordFileTransformerService implements FileTransformerClient {
return configuration;
}
@Override
public PreprocessingDmpModel preprocessingDmp(FileEnvelopeModel fileEnvelopeModel) {
throw new MyApplicationException("preprocessing not supported");
}
@Override
public PreprocessingDescriptionModel preprocessingDescription(FileEnvelopeModel fileEnvelopeModel) {
throw new MyApplicationException("preprocessing not supported");
}
private List<ReferenceModel> getReferenceModelOfTypeCode(DmpModel dmp, String code, UUID blueprintId){
List<ReferenceModel> response = new ArrayList<>();
if (dmp.getReferences() == null) return response;

View File

@ -8,12 +8,17 @@ import org.jsoup.nodes.TextNode;
import org.jsoup.select.NodeTraversor;
import org.jsoup.select.NodeVisitor;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.math.BigInteger;
import java.net.URI;
import java.net.URL;
import java.util.*;
public class HtmlToWorldBuilder implements NodeVisitor {
private static final Logger log = LoggerFactory.getLogger(HtmlToWorldBuilder.class);
private final Map<String, Boolean> properties = new LinkedHashMap<>();
private XWPFParagraph paragraph;
private XWPFRun run;
@ -204,9 +209,14 @@ public class HtmlToWorldBuilder implements NodeVisitor {
case "a":
if (stringBooleanEntry.getValue()) {
if (node.hasAttr("href")) {
this.run = createHyperLinkRun(node.attr("href"));
XWPFHyperlinkRun xwpfHyperlinkRun = createHyperLinkRun(node.attr("href"));
if (xwpfHyperlinkRun != null) {
this.run = xwpfHyperlinkRun;
this.run.setColor("0000FF");
this.run.setUnderline(UnderlinePatterns.SINGLE);
} else {
this.run.setText(node.attr("href") + " ");
}
}
} else {
this.run = paragraph.createRun();
@ -218,7 +228,6 @@ public class HtmlToWorldBuilder implements NodeVisitor {
}
break;
case "h1":
System.out.println(this.run.getFontSize());
this.run.setFontSize(24);
break;
case "h2":
@ -288,7 +297,22 @@ public class HtmlToWorldBuilder implements NodeVisitor {
}
private XWPFHyperlinkRun createHyperLinkRun(String uri) {
String rId = this.paragraph.getDocument().getPackagePart().addExternalRelationship(uri, XWPFRelation.HYPERLINK.getRelation()).getId();
URI fixedUri = null;
try {
fixedUri = URI.create(uri);
} catch (Exception e){
log.error(e.getMessage(), e);
}
if (fixedUri == null){
try {
fixedUri = URI.create(uri.replace(" ", "%20"));
} catch (Exception e){
log.error(e.getMessage(), e);
}
}
if (fixedUri == null) return null;
String rId = this.paragraph.getDocument().getPackagePart().addExternalRelationship(fixedUri.toASCIIString(), XWPFRelation.HYPERLINK.getRelation()).getId();
CTHyperlink cthyperLink=paragraph.getCTP().addNewHyperlink();
cthyperLink.setId(rId);

View File

@ -285,15 +285,19 @@ public class WordBuilderImpl implements WordBuilder {
}
private void createPages(List<PageModel> datasetProfilePages, PropertyDefinitionModel propertyDefinitionModel, XWPFDocument mainDocumentPart, VisibilityService visibilityService) {
datasetProfilePages.stream().filter(item -> item.getSections() != null).forEach(item -> {
for (PageModel item : datasetProfilePages) {
if (item.getSections() != null) {
try {
XWPFParagraph paragraph = addParagraphContent(item.getOrdinal() + 1 + " " + item.getTitle(), mainDocumentPart, ParagraphStyle.HEADER5, numId, 0);
mainDocumentPart.getPosOfParagraph(paragraph);
if (visibilityService.isVisible(item.getId(), null)) {
createSections(item.getSections(), propertyDefinitionModel, mainDocumentPart, 0, false, item.getOrdinal() + 1, null, visibilityService);
createSections(item.getSections(), propertyDefinitionModel, mainDocumentPart, 1, false, item.getOrdinal() + 1, null, visibilityService);
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
});
}
}
}
private boolean createSections(List<SectionModel> sections, PropertyDefinitionModel propertyDefinitionModel, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, Integer page, String sectionString, VisibilityService visibilityService) {

View File

@ -27,7 +27,7 @@
<dependency>
<groupId>org.opencdmp</groupId>
<artifactId>file-transformer-base</artifactId>
<version>0.0.22</version>
<version>0.0.23</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>

View File

@ -10,6 +10,10 @@ import org.opencdmp.filetransformer.docx.audit.AuditableAction;
import org.opencdmp.filetransformerbase.interfaces.FileTransformerClient;
import org.opencdmp.filetransformerbase.interfaces.FileTransformerConfiguration;
import org.opencdmp.filetransformer.docx.service.wordfiletransformer.WordFileTransformerService;
import org.opencdmp.filetransformerbase.models.misc.DescriptionImportModel;
import org.opencdmp.filetransformerbase.models.misc.DmpImportModel;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingDescriptionModel;
import org.opencdmp.filetransformerbase.models.misc.PreprocessingDmpModel;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -56,29 +60,50 @@ public class FileTransformerController implements org.opencdmp.filetransformerba
return model;
}
public DmpModel importFileToDmp(@RequestBody FileEnvelopeModel fileEnvelope) {
public DmpModel importFileToDmp(@RequestBody DmpImportModel dmpImportModel) {
logger.debug(new MapLogEntry("importFileToDmp " + FileEnvelopeModel.class.getSimpleName()).And("fileEnvelope", fileEnvelope));
logger.debug(new MapLogEntry("importFileToDmp " + FileEnvelopeModel.class.getSimpleName()).And("fileEnvelope", dmpImportModel.getFile()));
DmpModel model = fileTransformerExecutor.importDmp(fileEnvelope);
DmpModel model = fileTransformerExecutor.importDmp(dmpImportModel);
this.auditService.track(AuditableAction.FileTransformer_ImportFileToDmp, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("fileEnvelope", fileEnvelope)
new AbstractMap.SimpleEntry<String, Object>("fileEnvelope", dmpImportModel.getFile())
));
return model;
}
public DescriptionModel importFileToDescription(@RequestBody FileEnvelopeModel fileEnvelope) {
logger.debug(new MapLogEntry("importFileToDescription " + FileEnvelopeModel.class.getSimpleName()).And("fileEnvelope", fileEnvelope));
public DescriptionModel importFileToDescription(@RequestBody DescriptionImportModel descriptionImportModel) {
logger.debug(new MapLogEntry("importFileToDescription " + FileEnvelopeModel.class.getSimpleName()).And("fileEnvelope", descriptionImportModel.getFile()));
DescriptionModel model = fileTransformerExecutor.importDescription(fileEnvelope);
DescriptionModel model = fileTransformerExecutor.importDescription(descriptionImportModel);
this.auditService.track(AuditableAction.FileTransformer_ImportFileToDescription, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("importFileToDescription ", fileEnvelope)
new AbstractMap.SimpleEntry<String, Object>("importFileToDescription ", descriptionImportModel.getFile())
));
return model;
}
public PreprocessingDmpModel preprocessingDmp(FileEnvelopeModel fileEnvelopeModel) {
logger.debug(new MapLogEntry("PreprocessingDmpModel " + FileEnvelopeModel.class.getSimpleName()).And("fileEnvelope", fileEnvelopeModel));
PreprocessingDmpModel model = fileTransformerExecutor.preprocessingDmp(fileEnvelopeModel);
this.auditService.track(AuditableAction.FileTransformer_PreprocessingDmp, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("importFileToDescription ", fileEnvelopeModel)
));
return model;
}
public PreprocessingDescriptionModel preprocessingDescription(FileEnvelopeModel fileEnvelopeModel) {
logger.debug(new MapLogEntry("PreprocessingDescriptionModel " + FileEnvelopeModel.class.getSimpleName()).And("fileEnvelope", fileEnvelopeModel));
PreprocessingDescriptionModel model = fileTransformerExecutor.preprocessingDescription(fileEnvelopeModel);
this.auditService.track(AuditableAction.FileTransformer_PreprocessingDescription, Map.ofEntries(
new AbstractMap.SimpleEntry<String, Object>("importFileToDescription ", fileEnvelopeModel)
));
return model; }
public FileTransformerConfiguration getSupportedFormats() {
logger.debug(new MapLogEntry("getSupportedFormats"));