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