Xmlを保存できるようにした

This commit is contained in:
r-ca 2024-01-21 16:26:56 +09:00
parent d7f22c8e36
commit 722a3d8c7b
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9
3 changed files with 34 additions and 2 deletions

View File

@ -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<Void> updateXmlMeta(DocumentDetail documentDetail) {
return CompletableFuture.supplyAsync(() -> {
// TODO-rca: リビジョンIDを検証する, 挿入する
FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory());
ArrayList<XmlMetaPageModel> 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;
});
}
}

View File

@ -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

View File

@ -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();
}