use of io.vertigo.dynamo.domain.model.FileInfoURI in project vertigo by KleeGroup.
the class TwoTablesDbFileStorePlugin method create.
/**
* {@inheritDoc}
*/
@Override
public FileInfo create(final FileInfo fileInfo) {
checkReadonly();
checkDefinitionStoreBinding(fileInfo.getDefinition());
Assertion.checkArgument(fileInfo.getURI() == null, "Only file without any id can be created");
// -----
final Entity fileMetadataDto = createMetaDataEntity(fileInfo);
final Entity fileEntity = createFileEntity(fileInfo);
// -----
getStoreManager().getDataStore().create(fileEntity);
setValue(fileMetadataDto, DtoFields.FDT_ID, DtObjectUtil.getId(fileEntity));
getStoreManager().getDataStore().create(fileMetadataDto);
final FileInfoURI fileInfoUri = createURI(fileInfo.getDefinition(), DtObjectUtil.getId(fileMetadataDto));
fileInfo.setURIStored(fileInfoUri);
return fileInfo;
}
use of io.vertigo.dynamo.domain.model.FileInfoURI in project vertigo by KleeGroup.
the class TwoTablesDbFileStorePlugin method delete.
/**
* {@inheritDoc}
*/
@Override
public void delete(final FileInfoURI fileInfoUri) {
checkReadonly();
checkDefinitionStoreBinding(fileInfoUri.getDefinition());
// -----
final URI<Entity> dtoMetaDataUri = new URI<>(storeMetaDataDtDefinition, fileInfoUri.getKey());
final DtObject fileMetadataDtoOld = getStoreManager().getDataStore().readOne(dtoMetaDataUri);
final Object fdtId = getValue(fileMetadataDtoOld, DtoFields.FDT_ID, Object.class);
final URI<Entity> dtoDataUri = new URI<>(storeFileDtDefinition, fdtId);
getStoreManager().getDataStore().delete(dtoMetaDataUri);
getStoreManager().getDataStore().delete(dtoDataUri);
}
use of io.vertigo.dynamo.domain.model.FileInfoURI in project vertigo by KleeGroup.
the class FsFileStorePlugin method create.
/**
* {@inheritDoc}
*/
@Override
public FileInfo create(final FileInfo fileInfo) {
Assertion.checkArgument(!readOnly, STORE_READ_ONLY);
Assertion.checkNotNull(fileInfo.getURI() == null, "Only file without any id can be created.");
// -----
final Entity fileInfoDto = createFileInfoEntity(fileInfo);
// -----
getStoreManager().getDataStore().create(fileInfoDto);
// cas de la création
final Object fileInfoDtoId = DtObjectUtil.getId(fileInfoDto);
Assertion.checkNotNull(fileInfoDtoId, "ID du fichier doit être renseignée.");
final FileInfoURI uri = createURI(fileInfo.getDefinition(), fileInfoDtoId);
fileInfo.setURIStored(uri);
// on met a jour la base
final SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd/", Locale.FRANCE);
final String pathToSave = format.format(new Date()) + fileInfoDtoId;
setValue(fileInfoDto, DtoFields.FILE_PATH, pathToSave);
// -----
getStoreManager().getDataStore().update(fileInfoDto);
// -----
saveFile(fileInfo, pathToSave);
return fileInfo;
}
use of io.vertigo.dynamo.domain.model.FileInfoURI in project vertigo by KleeGroup.
the class DbFileStorePlugin method create.
/**
* {@inheritDoc}
*/
@Override
public FileInfo create(final FileInfo fileInfo) {
checkReadonly();
Assertion.checkNotNull(fileInfo.getURI() == null, "Only file without any id can be created.");
checkDefinitionStoreBinding(fileInfo.getDefinition());
// -----
final Entity fileInfoDto = createFileInfoDto(fileInfo);
// -----
getStoreManager().getDataStore().create(fileInfoDto);
// -----
final Object fileInfoDtoId = DtObjectUtil.getId(fileInfoDto);
Assertion.checkNotNull(fileInfoDtoId, "ID du fichier doit être renseignée.");
final FileInfoURI uri = new FileInfoURI(fileInfo.getDefinition(), fileInfoDtoId);
fileInfo.setURIStored(uri);
return fileInfo;
}
use of io.vertigo.dynamo.domain.model.FileInfoURI in project vertigo by KleeGroup.
the class DbFileStorePlugin method read.
/**
* {@inheritDoc}
*/
@Override
public FileInfo read(final FileInfoURI uri) {
Assertion.checkNotNull(uri);
checkDefinitionStoreBinding(uri.getDefinition());
// -----
final URI<Entity> dtoUri = new URI<>(storeDtDefinition, uri.getKey());
final Entity fileInfoDto = getStoreManager().getDataStore().readOne(dtoUri);
final InputStreamBuilder inputStreamBuilder = new DataStreamInputStreamBuilder(getValue(fileInfoDto, DtoFields.FILE_DATA, DataStream.class));
final String fileName = getValue(fileInfoDto, DtoFields.FILE_NAME, String.class);
final String mimeType = getValue(fileInfoDto, DtoFields.MIME_TYPE, String.class);
final Instant lastModified = getValue(fileInfoDto, DtoFields.LAST_MODIFIED, Instant.class);
final Long length = getValue(fileInfoDto, DtoFields.LENGTH, Long.class);
final VFile vFile = fileManager.createFile(fileName, mimeType, lastModified, length, inputStreamBuilder);
return new DatabaseFileInfo(uri.getDefinition(), vFile);
}
Aggregations