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