Search in sources :

Example 46 with DtDefinition

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();
    }
}
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 47 with DtDefinition

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();
}
Also used : AssociationNode(io.vertigo.dynamo.domain.metamodel.association.AssociationNode) DtListURIForNNAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation) TaskBuilder(io.vertigo.dynamo.task.model.TaskBuilder) CriteriaCtx(io.vertigo.dynamo.criteria.CriteriaCtx) DtField(io.vertigo.dynamo.domain.metamodel.DtField) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) URI(io.vertigo.dynamo.domain.model.URI) DtObjectUtil(io.vertigo.dynamo.domain.util.DtObjectUtil) TaskEngine(io.vertigo.dynamo.task.model.TaskEngine) VSystemException(io.vertigo.lang.VSystemException) Criteria(io.vertigo.dynamo.criteria.Criteria) Task(io.vertigo.dynamo.task.model.Task) SqlDialect(io.vertigo.database.sql.vendor.SqlDialect) Inject(javax.inject.Inject) Home(io.vertigo.app.Home) StoreManager(io.vertigo.dynamo.store.StoreManager) Criterions(io.vertigo.dynamo.criteria.Criterions) DtListURIForSimpleAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForSimpleAssociation) AssociationUtil(io.vertigo.dynamo.domain.util.AssociationUtil) Assertion(io.vertigo.lang.Assertion) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) Named(javax.inject.Named) DataStorePlugin(io.vertigo.dynamo.impl.store.datastore.DataStorePlugin) DataType(io.vertigo.dynamo.domain.metamodel.DataType) TaskDefinitionBuilder(io.vertigo.dynamo.task.metamodel.TaskDefinitionBuilder) Tuples(io.vertigo.lang.Tuples) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Domain(io.vertigo.dynamo.domain.metamodel.Domain) DtList(io.vertigo.dynamo.domain.model.DtList) TaskEngineInsertWithGeneratedKeys(io.vertigo.dynamox.task.sqlserver.TaskEngineInsertWithGeneratedKeys) Collectors(java.util.stream.Collectors) Definition(io.vertigo.core.definition.Definition) Serializable(java.io.Serializable) SqlDataBaseManager(io.vertigo.database.sql.SqlDataBaseManager) List(java.util.List) Entity(io.vertigo.dynamo.domain.model.Entity) DefinitionUtil(io.vertigo.core.definition.DefinitionUtil) TaskManager(io.vertigo.dynamo.task.TaskManager) AbstractTaskEngineSQL(io.vertigo.dynamox.task.AbstractTaskEngineSQL) TaskEngineSelect(io.vertigo.dynamox.task.TaskEngineSelect) Optional(java.util.Optional) TaskEngineProc(io.vertigo.dynamox.task.TaskEngineProc) DtListURIForCriteria(io.vertigo.dynamo.domain.model.DtListURIForCriteria) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 48 with DtDefinition

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();
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) TaskEngineSelect(io.vertigo.dynamox.task.TaskEngineSelect) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField) AssociationNode(io.vertigo.dynamo.domain.metamodel.association.AssociationNode)

Example 49 with DtDefinition

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);
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 50 with DtDefinition

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);
    }
}
Also used : Account(io.vertigo.account.account.Account) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI)

Aggregations

DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)91 DtField (io.vertigo.dynamo.domain.metamodel.DtField)29 Test (org.junit.Test)21 URI (io.vertigo.dynamo.domain.model.URI)18 List (java.util.List)17 ArrayList (java.util.ArrayList)16 Assertion (io.vertigo.lang.Assertion)12 Collectors (java.util.stream.Collectors)11 Home (io.vertigo.app.Home)10 Optional (java.util.Optional)10 Domain (io.vertigo.dynamo.domain.metamodel.Domain)9 Collections (java.util.Collections)8 DefinitionUtil (io.vertigo.core.definition.DefinitionUtil)7 DtObjectUtil (io.vertigo.dynamo.domain.util.DtObjectUtil)7 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)7 Inject (javax.inject.Inject)7 Authorization (io.vertigo.account.authorization.metamodel.Authorization)6 SecuredEntity (io.vertigo.account.authorization.metamodel.SecuredEntity)6 Criterions (io.vertigo.dynamo.criteria.Criterions)6 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)5