Search in sources :

Example 1 with FileInfoURI

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;
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) FileInfoURI(io.vertigo.dynamo.domain.model.FileInfoURI)

Example 2 with FileInfoURI

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);
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) DtObject(io.vertigo.dynamo.domain.model.DtObject) DtObject(io.vertigo.dynamo.domain.model.DtObject) URI(io.vertigo.dynamo.domain.model.URI) FileInfoURI(io.vertigo.dynamo.domain.model.FileInfoURI)

Example 3 with FileInfoURI

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;
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) FileInfoURI(io.vertigo.dynamo.domain.model.FileInfoURI) DtObject(io.vertigo.dynamo.domain.model.DtObject) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 4 with FileInfoURI

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;
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) FileInfoURI(io.vertigo.dynamo.domain.model.FileInfoURI)

Example 5 with FileInfoURI

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);
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) InputStreamBuilder(io.vertigo.dynamo.file.model.InputStreamBuilder) DataStream(io.vertigo.lang.DataStream) Instant(java.time.Instant) URI(io.vertigo.dynamo.domain.model.URI) FileInfoURI(io.vertigo.dynamo.domain.model.FileInfoURI) VFile(io.vertigo.dynamo.file.model.VFile)

Aggregations

FileInfoURI (io.vertigo.dynamo.domain.model.FileInfoURI)8 Entity (io.vertigo.dynamo.domain.model.Entity)6 DtObject (io.vertigo.dynamo.domain.model.DtObject)3 URI (io.vertigo.dynamo.domain.model.URI)3 VFile (io.vertigo.dynamo.file.model.VFile)3 InputStreamBuilder (io.vertigo.dynamo.file.model.InputStreamBuilder)2 DataStream (io.vertigo.lang.DataStream)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Instant (java.time.Instant)2 Date (java.util.Date)2 FileInfo (io.vertigo.dynamo.file.model.FileInfo)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1