From 722a3d8c7bb7d4d2412a3cf94b611d007427c28d Mon Sep 17 00:00:00 2001 From: r-ca Date: Sun, 21 Jan 2024 16:26:56 +0900 Subject: [PATCH] =?UTF-8?q?Xml=E3=82=92=E4=BF=9D=E5=AD=98=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/data/impl/DocumentImpl.java | 24 +++++++++++++++++++ .../source/file/impl/FileManagerImpl.java | 4 ++++ .../utils/impl/DeviceInfoUtilsImpl.java | 8 +++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java index 6c971144..331b9422 100644 --- a/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java @@ -18,6 +18,7 @@ import one.nem.lacerta.model.document.DocumentMeta; import one.nem.lacerta.model.document.DocumentDetail; // Lacerta/source +import one.nem.lacerta.model.document.internal.XmlMetaModel; import one.nem.lacerta.model.document.internal.XmlMetaPageModel; import one.nem.lacerta.model.document.page.Page; import one.nem.lacerta.source.database.LacertaDatabase; @@ -87,6 +88,9 @@ public class DocumentImpl implements Document { LacertaVcs vcs = vcsFactory.create(meta.getId()); vcs.createDocument(meta.getId()); + // XmlMeta + updateXmlMeta(detail).join(); + return detail; }); } @@ -187,4 +191,24 @@ public class DocumentImpl implements Document { return pages; }); } + + private CompletableFuture updateXmlMeta(DocumentDetail documentDetail) { + return CompletableFuture.supplyAsync(() -> { + // TODO-rca: リビジョンIDを検証する, 挿入する + FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory()); + ArrayList xmlMetaPageModels = new ArrayList<>(); + for (Page page : documentDetail.getPages()) { + xmlMetaPageModels.add(new XmlMetaPageModel(page.getFileName())); + } + try { + fileManager.createDirectoryIfNotExist(documentDetail.getMeta().getId()).resolve(documentDetail.getMeta().getId()) + .createFileIfNotExist("meta.xml").resolve("meta.xml").saveXml(xmlMetaParser.serialize(new XmlMetaModel("revisionId_PLACEHOLDER", xmlMetaPageModels))); + } catch (IOException e) { + logger.error(TAG, "DocumentMeta serialize error"); + logger.trace(TAG, e.getMessage()); + logger.e_code("e3b4d0c9-5b7e-4b7e-9e9a-5b8b8b8b8b8b"); + } + return null; + }); + } } diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 25d5062b..b8f5226c 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -37,7 +37,11 @@ public class FileManagerImpl implements FileManager { @AssistedInject public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) { this.logger = logger; + if (rootDir == null) { + throw new IllegalArgumentException("rootDir must not be null"); + } this.rootDir = rootDir; + this.path = rootDir; } // for generate new instance diff --git a/utils/src/main/java/one/nem/lacerta/utils/impl/DeviceInfoUtilsImpl.java b/utils/src/main/java/one/nem/lacerta/utils/impl/DeviceInfoUtilsImpl.java index 1cb5c759..72a88379 100644 --- a/utils/src/main/java/one/nem/lacerta/utils/impl/DeviceInfoUtilsImpl.java +++ b/utils/src/main/java/one/nem/lacerta/utils/impl/DeviceInfoUtilsImpl.java @@ -20,7 +20,9 @@ public class DeviceInfoUtilsImpl implements DeviceInfoUtils { @Override public Path getExternalStorageDirectory() { - // TODO-rca: 結果がnullだった場合の処理を追加する? + if (applicationContext.getExternalFilesDir(null) == null) { + throw new RuntimeException("applicationContext.getExternalFilesDir(null) is null"); + } return Objects.requireNonNull(applicationContext.getExternalFilesDir(null)).toPath(); } @@ -31,7 +33,9 @@ public class DeviceInfoUtilsImpl implements DeviceInfoUtils { @Override public Path getExternalStorageDirectory(String type) { - // TODO-rca: 結果がnullだった場合の処理を追加する? + if(applicationContext.getExternalFilesDir(type) == null) { + throw new RuntimeException("applicationContext.getExternalFilesDir(" + type + ") is null"); + } return Objects.requireNonNull(applicationContext.getExternalFilesDir(type)).toPath(); }