mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-23 00:13:16 +00:00
Xmlを保存できるようにした
This commit is contained in:
parent
d7f22c8e36
commit
722a3d8c7b
|
@ -18,6 +18,7 @@ import one.nem.lacerta.model.document.DocumentMeta;
|
||||||
import one.nem.lacerta.model.document.DocumentDetail;
|
import one.nem.lacerta.model.document.DocumentDetail;
|
||||||
|
|
||||||
// Lacerta/source
|
// Lacerta/source
|
||||||
|
import one.nem.lacerta.model.document.internal.XmlMetaModel;
|
||||||
import one.nem.lacerta.model.document.internal.XmlMetaPageModel;
|
import one.nem.lacerta.model.document.internal.XmlMetaPageModel;
|
||||||
import one.nem.lacerta.model.document.page.Page;
|
import one.nem.lacerta.model.document.page.Page;
|
||||||
import one.nem.lacerta.source.database.LacertaDatabase;
|
import one.nem.lacerta.source.database.LacertaDatabase;
|
||||||
|
@ -87,6 +88,9 @@ public class DocumentImpl implements Document {
|
||||||
LacertaVcs vcs = vcsFactory.create(meta.getId());
|
LacertaVcs vcs = vcsFactory.create(meta.getId());
|
||||||
vcs.createDocument(meta.getId());
|
vcs.createDocument(meta.getId());
|
||||||
|
|
||||||
|
// XmlMeta
|
||||||
|
updateXmlMeta(detail).join();
|
||||||
|
|
||||||
return detail;
|
return detail;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -187,4 +191,24 @@ public class DocumentImpl implements Document {
|
||||||
return pages;
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,11 @@ public class FileManagerImpl implements FileManager {
|
||||||
@AssistedInject
|
@AssistedInject
|
||||||
public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) {
|
public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
if (rootDir == null) {
|
||||||
|
throw new IllegalArgumentException("rootDir must not be null");
|
||||||
|
}
|
||||||
this.rootDir = rootDir;
|
this.rootDir = rootDir;
|
||||||
|
this.path = rootDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for generate new instance
|
// for generate new instance
|
||||||
|
|
|
@ -20,7 +20,9 @@ public class DeviceInfoUtilsImpl implements DeviceInfoUtils {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path getExternalStorageDirectory() {
|
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();
|
return Objects.requireNonNull(applicationContext.getExternalFilesDir(null)).toPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +33,9 @@ public class DeviceInfoUtilsImpl implements DeviceInfoUtils {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path getExternalStorageDirectory(String type) {
|
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();
|
return Objects.requireNonNull(applicationContext.getExternalFilesDir(type)).toPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user