Search in sources :

Example 11 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.

the class GoogleJsonEngine method uiListDeltaFromJson.

/**
 * {@inheritDoc}
 */
@Override
public <D extends DtObject> UiListDelta<D> uiListDeltaFromJson(final String json, final Type paramType) {
    // we known that DtListDelta has one parameterized type
    final Class<DtObject> dtoClass = (Class<DtObject>) ((ParameterizedType) paramType).getActualTypeArguments()[0];
    final Type typeOfDest = createParameterizedType(UiListDelta.class, dtoClass);
    return gson.fromJson(json, typeOfDest);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ParameterizedType(java.lang.reflect.ParameterizedType) FieldType(io.vertigo.dynamo.domain.metamodel.DtField.FieldType) DtObject(io.vertigo.dynamo.domain.model.DtObject)

Example 12 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.

the class ESDocumentCodec method index2XContentBuilder.

/**
 * Transformation d'un index en un document ElasticSearch.
 * @param <S> Type du sujet représenté par ce document
 * @param <I> Type d'object indexé
 * @param index Objet logique de recherche
 * @return Document SOLR
 * @throws IOException Json exception
 */
<S extends KeyConcept, I extends DtObject> XContentBuilder index2XContentBuilder(final SearchIndex<S, I> index) throws IOException {
    Assertion.checkNotNull(index);
    // -----
    final DtDefinition dtDefinition = index.getDefinition().getIndexDtDefinition();
    // on ne copie pas les champs not stored dans le domain
    final List<DtField> notStoredFields = getNotStoredFields(dtDefinition);
    // on ne copie pas les champs (copyTo)
    notStoredFields.addAll(index.getDefinition().getIndexCopyToFields());
    final I dtResult;
    if (notStoredFields.isEmpty()) {
        dtResult = index.getIndexDtObject();
    } else {
        dtResult = cloneDto(dtDefinition, index.getIndexDtObject(), notStoredFields);
    }
    /* 2: Result stocké */
    final String result = encode(dtResult);
    /* 1 : URI */
    try (final XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()) {
        xContentBuilder.startObject().field(FULL_RESULT, result).field("urn", index.getURI().urn());
        /* 3 : Les champs du dto index */
        final DtObject dtIndex = index.getIndexDtObject();
        final DtDefinition indexDtDefinition = DtObjectUtil.findDtDefinition(dtIndex);
        final Set<DtField> copyToFields = index.getDefinition().getIndexCopyToFields();
        for (final DtField dtField : indexDtDefinition.getFields()) {
            if (!copyToFields.contains(dtField)) {
                // On index pas les copyFields
                final Object value = dtField.getDataAccessor().getValue(dtIndex);
                if (value != null) {
                    // les valeurs null ne sont pas indexées => conséquence : on ne peut pas les rechercher
                    final String indexFieldName = dtField.getName();
                    if (value instanceof String) {
                        final String encodedValue = escapeInvalidUTF8Char((String) value);
                        xContentBuilder.field(indexFieldName, encodedValue);
                    } else {
                        xContentBuilder.field(indexFieldName, value);
                    }
                }
            }
        }
        return xContentBuilder.endObject();
    }
}
Also used : DtObject(io.vertigo.dynamo.domain.model.DtObject) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI) DtObject(io.vertigo.dynamo.domain.model.DtObject) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 13 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.

the class TwoTablesDbFileStorePlugin method update.

/**
 * {@inheritDoc}
 */
@Override
public void update(final FileInfo fileInfo) {
    checkReadonly();
    checkDefinitionStoreBinding(fileInfo.getDefinition());
    Assertion.checkArgument(fileInfo.getURI() != null, "Only file with id can be updated");
    // -----
    final Entity fileMetadataDto = createMetaDataEntity(fileInfo);
    final Entity fileDataDto = createFileEntity(fileInfo);
    // -----
    setValue(fileMetadataDto, DtoFields.FMD_ID, fileInfo.getURI().getKey());
    // Chargement du FDT_ID
    final URI<Entity> dtoMetaDataUri = new URI<>(storeMetaDataDtDefinition, fileInfo.getURI().getKey());
    final DtObject fileMetadataDtoOld = getStoreManager().getDataStore().readOne(dtoMetaDataUri);
    final Object fdtId = getValue(fileMetadataDtoOld, DtoFields.FDT_ID, Object.class);
    setValue(fileMetadataDto, DtoFields.FDT_ID, fdtId);
    setValue(fileDataDto, DtoFields.FDT_ID, fdtId);
    getStoreManager().getDataStore().update(fileDataDto);
    getStoreManager().getDataStore().update(fileMetadataDto);
}
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 14 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.

the class TwoTablesDbFileStorePlugin method read.

/**
 * {@inheritDoc}
 */
@Override
public FileInfo read(final FileInfoURI fileInfoUri) {
    checkDefinitionStoreBinding(fileInfoUri.getDefinition());
    // Ramène FileMetada
    final URI<Entity> dtoMetaDataUri = new URI<>(storeMetaDataDtDefinition, fileInfoUri.getKey());
    final DtObject fileMetadataDto = getStoreManager().getDataStore().readOne(dtoMetaDataUri);
    final Object fdtId = getValue(fileMetadataDto, DtoFields.FDT_ID, Object.class);
    // Ramène FileData
    final URI<Entity> dtoDataUri = new URI<>(storeFileDtDefinition, fdtId);
    final DtObject fileDataDto = getStoreManager().getDataStore().readOne(dtoDataUri);
    // Construction du vFile.
    final InputStreamBuilder inputStreamBuilder = new DataStreamInputStreamBuilder(getValue(fileDataDto, DtoFields.FILE_DATA, DataStream.class));
    final String fileName = getValue(fileMetadataDto, DtoFields.FILE_NAME, String.class);
    final String mimeType = getValue(fileMetadataDto, DtoFields.MIME_TYPE, String.class);
    final Instant lastModified = getValue(fileMetadataDto, DtoFields.LAST_MODIFIED, Instant.class);
    final Long length = getValue(fileMetadataDto, DtoFields.LENGTH, Long.class);
    final VFile vFile = fileManager.createFile(fileName, mimeType, lastModified, length, inputStreamBuilder);
    // TODO passer par une factory de FileInfo à partir de la FileInfoDefinition (comme DomainFactory)
    final FileInfo fileInfo = new DatabaseFileInfo(fileInfoUri.getDefinition(), vFile);
    fileInfo.setURIStored(fileInfoUri);
    return fileInfo;
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) DataStream(io.vertigo.lang.DataStream) DtObject(io.vertigo.dynamo.domain.model.DtObject) 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) FileInfo(io.vertigo.dynamo.file.model.FileInfo) InputStreamBuilder(io.vertigo.dynamo.file.model.InputStreamBuilder) DtObject(io.vertigo.dynamo.domain.model.DtObject)

Example 15 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.

the class FsFileStorePlugin method read.

/**
 * {@inheritDoc}
 */
@Override
public FileInfo read(final FileInfoURI uri) {
    // récupération de l'objet en base
    final URI<Entity> dtoUri = createDtObjectURI(uri);
    final DtObject fileInfoDto = getStoreManager().getDataStore().readOne(dtoUri);
    // récupération du fichier
    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 String filePath = getValue(fileInfoDto, DtoFields.FILE_PATH, String.class);
    final InputStreamBuilder inputStreamBuilder = new FileInputStreamBuilder(new File(documentRoot + filePath));
    final VFile vFile = fileManager.createFile(fileName, mimeType, lastModified, length, inputStreamBuilder);
    // retourne le fileinfo avec le fichier et son URI
    final FsFileInfo fsFileInfo = new FsFileInfo(uri.getDefinition(), vFile);
    fsFileInfo.setURIStored(uri);
    return fsFileInfo;
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) InputStreamBuilder(io.vertigo.dynamo.file.model.InputStreamBuilder) DtObject(io.vertigo.dynamo.domain.model.DtObject) Instant(java.time.Instant) VFile(io.vertigo.dynamo.file.model.VFile) File(java.io.File) VFile(io.vertigo.dynamo.file.model.VFile)

Aggregations

DtObject (io.vertigo.dynamo.domain.model.DtObject)32 DtField (io.vertigo.dynamo.domain.metamodel.DtField)14 Entity (io.vertigo.dynamo.domain.model.Entity)9 URI (io.vertigo.dynamo.domain.model.URI)8 Type (java.lang.reflect.Type)8 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)5 DtList (io.vertigo.dynamo.domain.model.DtList)5 ParameterizedType (java.lang.reflect.ParameterizedType)5 VFile (io.vertigo.dynamo.file.model.VFile)4 UiContext (io.vertigo.vega.engines.webservice.json.UiContext)4 UiListDelta (io.vertigo.vega.engines.webservice.json.UiListDelta)4 FileInfoURI (io.vertigo.dynamo.domain.model.FileInfoURI)3 Instant (java.time.Instant)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 JsonObject (com.google.gson.JsonObject)2 CollectionsManager (io.vertigo.dynamo.collections.CollectionsManager)2