use of io.vertigo.dynamo.domain.metamodel.DtDefinition 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.metamodel.DtDefinition in project vertigo by KleeGroup.
the class SqlDataStorePlugin method createUpdateQuery.
/**
* Creates the update request.
*
* @param dtDefinition the dtDefinition
* @return the sql request
*/
private static String createUpdateQuery(final DtDefinition dtDefinition) {
final String tableName = getTableName(dtDefinition);
final DtField idField = getIdField(dtDefinition);
return new StringBuilder().append("update ").append(tableName).append(" set ").append(dtDefinition.getFields().stream().filter(dtField -> dtField.isPersistent() && !dtField.getType().isId()).map(dtField -> dtField.getName() + " =#DTO." + dtField.getName() + '#').collect(Collectors.joining(", "))).append(" where ").append(idField.getName()).append(" = #DTO.").append(idField.getName()).append('#').toString();
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class SqlDataStorePlugin method findAll.
/**
* {@inheritDoc}
*/
@Override
public <E extends Entity> DtList<E> findAll(final DtDefinition dtDefinition, final DtListURIForNNAssociation dtcUri) {
Assertion.checkNotNull(dtDefinition);
Assertion.checkNotNull(dtcUri);
// -----
final String tableName = getTableName(dtDefinition);
final String taskName = TASK.TK_SELECT + "_N_N_LIST_" + tableName + "_BY_URI";
// PK de la DtList recherchée
final String idFieldName = getIdField(dtDefinition).getName();
// FK dans la table nn correspondant à la collection recherchée. (clé de jointure ).
final AssociationNNDefinition associationNNDefinition = dtcUri.getAssociationDefinition();
final String joinTableName = associationNNDefinition.getTableName();
final DtDefinition joinDtDefinition = AssociationUtil.getAssociationNode(associationNNDefinition, dtcUri.getRoleName()).getDtDefinition();
final DtField joinDtField = getIdField(joinDtDefinition);
// La condition s'applique sur l'autre noeud de la relation (par rapport à la collection attendue)
final AssociationNode associationNode = AssociationUtil.getAssociationNodeTarget(associationNNDefinition, dtcUri.getRoleName());
final DtField fkField = getIdField(associationNode.getDtDefinition());
final String fkFieldName = fkField.getName();
final String request = new StringBuilder(" select t.* from ").append(tableName).append(" t").append(" join ").append(joinTableName).append(" j on j.").append(joinDtField.getName()).append(" = t.").append(idFieldName).append(" where j.").append(fkFieldName).append(" = #").append(fkFieldName).append('#').toString();
final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineSelect.class).withDataSpace(dataSpace).withRequest(request).addInRequired(fkFieldName, fkField.getDomain()).withOutRequired("dtc", Home.getApp().getDefinitionSpace().resolve(DOMAIN_PREFIX + SEPARATOR + dtDefinition.getName() + "_DTC", Domain.class)).build();
final URI uri = dtcUri.getSource();
final Task task = Task.builder(taskDefinition).addValue(fkFieldName, uri.getId()).build();
return taskManager.execute(task).getResult();
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class AbstractDbFileStorePlugin method setIdValue.
/**
* @param dto DtObject
* @param value Pk value
*/
protected static void setIdValue(final DtObject dto, final Object value) {
final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(dto);
final DtField idField = dtDefinition.getIdField().get();
idField.getDataAccessor().setValue(dto, value);
}
use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.
the class MemoryAccountCachePlugin method putAccount.
/**
* {@inheritDoc}
*/
@Override
public synchronized void putAccount(final Account account) {
Assertion.checkNotNull(account);
// -----
final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(account);
final URI<Account> uri = new URI<>(dtDefinition, account.getId());
// ----
final Object old = accountByURI.put(uri, account);
if (old == null) {
groupByAccountURI.put(uri, new HashSet<URI<AccountGroup>>());
accountURIByAuthToken.put(account.getAuthToken(), uri);
}
}
Aggregations