support shared storage

This commit is contained in:
Efstratios Giannopoulos 2024-05-09 14:22:31 +03:00
parent a96f62abf8
commit 4527634953
1 changed files with 19 additions and 14 deletions

View File

@ -12,6 +12,7 @@ import org.opencdmp.commonmodels.models.dmp.DmpModel;
import org.opencdmp.commonmodels.models.dmpreference.DmpReferenceModel; import org.opencdmp.commonmodels.models.dmpreference.DmpReferenceModel;
import org.opencdmp.commonmodels.models.reference.ReferenceFieldModel; import org.opencdmp.commonmodels.models.reference.ReferenceFieldModel;
import org.opencdmp.commonmodels.models.reference.ReferenceModel; import org.opencdmp.commonmodels.models.reference.ReferenceModel;
import org.opencdmp.filetransformer.docx.service.storage.FileStorageService;
import org.opencdmp.filetransformer.docx.service.storage.FileStorageServiceProperties; import org.opencdmp.filetransformer.docx.service.storage.FileStorageServiceProperties;
import org.opencdmp.filetransformer.docx.service.wordfiletransformer.WordFileTransformerServiceProperties; import org.opencdmp.filetransformer.docx.service.wordfiletransformer.WordFileTransformerServiceProperties;
import org.opencdmp.filetransformer.docx.model.PidLink; import org.opencdmp.filetransformer.docx.model.PidLink;
@ -27,6 +28,7 @@ import org.apache.xmlbeans.XmlObject;
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;
import org.opencdmp.filetransformerbase.interfaces.FileTransformerConfiguration;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -62,17 +64,17 @@ public class WordBuilderImpl implements WordBuilder {
private Integer indent; private Integer indent;
private Integer imageCount; private Integer imageCount;
private final CTAbstractNum cTAbstractNum; private final CTAbstractNum cTAbstractNum;
private final FileStorageServiceProperties fileStorageServiceProperties; private final FileStorageService fileStorageService;
private final WordFileTransformerServiceProperties wordFileTransformerServiceProperties; private final WordFileTransformerServiceProperties wordFileTransformerServiceProperties;
private final PidService pidService; private final PidService pidService;
private final Map<ParagraphStyle, ApplierWithValue<XWPFDocument, Object, XWPFParagraph>> options = new HashMap<>(); private final Map<ParagraphStyle, ApplierWithValue<XWPFDocument, Object, XWPFParagraph>> options = new HashMap<>();
private final Map<ParagraphStyle, ApplierWithValue<XWPFTableCell, Object, XWPFParagraph>> optionsInTable = new HashMap<>(); private final Map<ParagraphStyle, ApplierWithValue<XWPFTableCell, Object, XWPFParagraph>> optionsInTable = new HashMap<>();
public WordBuilderImpl(FileStorageServiceProperties fileStorageServiceProperties, WordFileTransformerServiceProperties wordFileTransformerServiceProperties, PidService pidService) { public WordBuilderImpl(FileStorageService fileStorageService, WordFileTransformerServiceProperties wordFileTransformerServiceProperties, PidService pidService) {
this.fileStorageServiceProperties = fileStorageServiceProperties; this.fileStorageService = fileStorageService;
this.wordFileTransformerServiceProperties = wordFileTransformerServiceProperties; this.wordFileTransformerServiceProperties = wordFileTransformerServiceProperties;
this.pidService = pidService; this.pidService = pidService;
this.cTAbstractNum = CTAbstractNum.Factory.newInstance(); this.cTAbstractNum = CTAbstractNum.Factory.newInstance();
this.cTAbstractNum.setAbstractNumId(BigInteger.valueOf(1)); this.cTAbstractNum.setAbstractNumId(BigInteger.valueOf(1));
this.indent = 0; this.indent = 0;
this.imageCount = 0; this.imageCount = 0;
@ -208,15 +210,14 @@ public class WordBuilderImpl implements WordBuilder {
String fileType = itemTyped.getMimeType(); String fileType = itemTyped.getMimeType();
int format; int format;
format = IMAGE_TYPE_MAP.getOrDefault(fileType, 0); format = IMAGE_TYPE_MAP.getOrDefault(fileType, 0);
byte[] file;
InputStream image; if (this.wordFileTransformerServiceProperties.isUseSharedStorage() && itemTyped.getFileRef() != null && !itemTyped.getFileRef().isBlank()) {
ImageInputStream iis; file = this.fileStorageService.readFile(itemTyped.getFileRef());
if (itemTyped.getFile() == null) {
throw new RuntimeException("Not implemented");
} else { } else {
image = new ByteArrayInputStream(itemTyped.getFile()); file = itemTyped.getFile();
iis = ImageIO.createImageInputStream(new ByteArrayInputStream(itemTyped.getFile()));
} }
InputStream image = new ByteArrayInputStream(file);
ImageInputStream iis = ImageIO.createImageInputStream(new ByteArrayInputStream(file));
Iterator<ImageReader> readers = ImageIO.getImageReaders(iis); Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
if (readers.hasNext()) { if (readers.hasNext()) {
ImageReader reader = readers.next(); ImageReader reader = readers.next();
@ -268,8 +269,12 @@ public class WordBuilderImpl implements WordBuilder {
} }
private int toIntFormBigInteger(Object object){ private int toIntFormBigInteger(Object object){
if (object instanceof BigInteger) return ((BigInteger)object).intValue(); try {
return (int) object; if (object instanceof BigInteger) return ((BigInteger) object).intValue();
return (int) object;
} catch (Exception e){
return 0;
}
} }
@Override @Override