DocumentProcessor更新 WIP

This commit is contained in:
r-ca 2024-01-14 16:45:48 +09:00
parent aa7f285773
commit eba02abfd4
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9

View File

@ -14,12 +14,16 @@ import one.nem.lacerta.processor.DocumentProcessor;
import one.nem.lacerta.model.document.DocumentDetail;
import one.nem.lacerta.model.document.internal.XmlMetaModel;
import one.nem.lacerta.model.document.page.Page;
import one.nem.lacerta.source.file.FileManager;
import one.nem.lacerta.source.file.factory.FileManagerFactory;
import one.nem.lacerta.utils.LacertaLogger;
import one.nem.lacerta.utils.XmlMetaParser;
import one.nem.lacerta.utils.repository.DeviceInfoUtils;
public class DocumentProcessorImpl implements DocumentProcessor{
@ -37,8 +41,10 @@ public class DocumentProcessorImpl implements DocumentProcessor{
private final FileManagerFactory fileManagerFactory;
private final LacertaLogger logger;
private final XmlMetaParser xmlMetaParser;
private final DeviceInfoUtils deviceInfoUtils;
@AssistedInject
public DocumentProcessorImpl(FileManagerFactory fileManagerFactory, LacertaLogger logger, XmlMetaParser xmlMetaParser, @Assisted DocumentDetail documentDetail) {
public DocumentProcessorImpl(FileManagerFactory fileManagerFactory, LacertaLogger logger, XmlMetaParser xmlMetaParser, DeviceInfoUtils deviceInfoUtils, @Assisted DocumentDetail documentDetail) {
this.fileManagerFactory = fileManagerFactory;
this.logger = logger;
this.xmlMetaParser = xmlMetaParser;
@ -46,51 +52,20 @@ public class DocumentProcessorImpl implements DocumentProcessor{
throw new IllegalArgumentException("documentDetail must not be null");
}
this.documentDetail = documentDetail;
this.deviceInfoUtils = deviceInfoUtils;
}
@Override
public void init() throws Exception{
logger.debug("init", "called");
// Init Variables
this.documentRootPath = this.documentDetail.getPath().getFullPath();
this.documentRootPath = deviceInfoUtils.getExternalStorageDirectory().resolve(this.documentDetail.getMeta().getId());
logger.debug("init", "documentRootPath: " + this.documentRootPath);
this.fileManager = fileManagerFactory.create(this.documentRootPath).enableAutoCreateParent(); //Initialize FileManager
FileManager initFileManager = this.fileManager.getNewInstance();
logger.debug("init", "fileManager created");
// xmlファイルの読み込み
if (initFileManager.isExist("meta.xml")) {
logger.debug("init", "meta.xml found");
try {
this.xmlMetaModel = xmlMetaParser.deserialize(this.fileManager.loadXml("meta.xml"));
logger.debug("init", "meta.xml parsed");
} catch (Exception e) {
logger.debug("init", "meta.xml parse failed");
logger.trace("init", e.getMessage());
}
} else {
logger.debug("init", "meta.xml not found");
xmlMetaModel = new XmlMetaModel();
xmlMetaModel.setTitle(this.documentDetail.getMeta().getTitle());
xmlMetaModel.setAuthor(this.documentDetail.getAuthor());
xmlMetaModel.setDescription(""); // FIXME-rca:
xmlMetaModel.setDefaultBranch(this.documentDetail.getDefaultBranch());
xmlMetaModel.setPages(new ArrayList<>());
try {
initFileManager.createFileIfNotExist("meta.xml").saveXml(xmlMetaParser.serialize(xmlMetaModel), "meta.xml");
logger.debug("init", "meta.xml saved");
} catch (Exception e) {
logger.error("init", "meta.xml save failed");
logger.trace("init", e.getMessage());
}
}
logger.info("init", "finished");
}
@Override
@ -98,11 +73,12 @@ public class DocumentProcessorImpl implements DocumentProcessor{
logger.debug("addNewPageToLast", "called");
String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする
this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename);
Page page = new Page();
page.setFileName(filename);
page.setBitmap(bitmap);
this.documentDetail.getPages().add(page);
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
xmlMetaPageModel.setFilename(filename);
xmlMetaModel.getPages().add(xmlMetaPageModel);
this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename);
logger.info("addNewPageToLast", "finished");
logger.info("addNewPageToLast", "filename: " + filename);
@ -124,9 +100,10 @@ public class DocumentProcessorImpl implements DocumentProcessor{
this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename);
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
xmlMetaPageModel.setFilename(filename);
xmlMetaModel.getPages().add(index, xmlMetaPageModel);
Page page = new Page();
page.setFileName(filename);
page.setBitmap(bitmap);
this.documentDetail.getPages().add(index + 1, page);
}
@Override
@ -136,9 +113,11 @@ public class DocumentProcessorImpl implements DocumentProcessor{
this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename);
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
xmlMetaPageModel.setFilename(filename);
xmlMetaModel.getPages().add(index - 1, xmlMetaPageModel);
Page page = new Page();
page.setFileName(filename);
page.setBitmap(bitmap);
this.documentDetail.getPages().add(index, page);
}
@Override