Search in sources :

Example 1 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class AbstractESSearchServicesPlugin method updateTypeMapping.

/**
 * Update template definition of this type.
 * @param indexDefinition Index concerné
 */
private void updateTypeMapping(final SearchIndexDefinition indexDefinition) {
    Assertion.checkNotNull(indexDefinition);
    // -----
    try (final XContentBuilder typeMapping = XContentFactory.jsonBuilder()) {
        typeMapping.startObject().startObject("properties").startObject(ESDocumentCodec.FULL_RESULT).field("type", "binary").endObject();
        /* 3 : Les champs du dto index */
        final Set<DtField> copyFromFields = indexDefinition.getIndexCopyFromFields();
        final DtDefinition indexDtDefinition = indexDefinition.getIndexDtDefinition();
        for (final DtField dtField : indexDtDefinition.getFields()) {
            final IndexType indexType = IndexType.readIndexType(dtField.getDomain());
            typeMapping.startObject(dtField.getName());
            appendIndexTypeMapping(typeMapping, indexType);
            if (copyFromFields.contains(dtField)) {
                appendIndexCopyToMapping(indexDefinition, typeMapping, dtField);
            }
            typeMapping.endObject();
        }
        // end properties
        typeMapping.endObject().endObject();
        final PutMappingResponse putMappingResponse = esClient.admin().indices().preparePutMapping(obtainIndexName(indexDefinition)).setType(indexDefinition.getName().toLowerCase(Locale.ENGLISH)).setSource(typeMapping).get();
        putMappingResponse.isAcknowledged();
    } catch (final IOException e) {
        throw WrappedException.wrap(e, "Serveur ElasticSearch indisponible");
    }
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 2 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class TaskGeneratorPlugin method builDtDefinitiondMap.

private static Map<DtDefinition, List<TaskDefinition>> builDtDefinitiondMap() {
    final Collection<TaskDefinition> taskDefinitions = Home.getApp().getDefinitionSpace().getAll(TaskDefinition.class);
    final Map<DtDefinition, List<TaskDefinition>> taskDefinitionsMap = new LinkedHashMap<>();
    // ---
    // Par défaut, On crée pour chaque DT une liste vide des taches lui étant associées.
    final Collection<DtDefinition> dtDefinitions = Home.getApp().getDefinitionSpace().getAll(DtDefinition.class);
    for (final DtDefinition dtDefinition : dtDefinitions) {
        taskDefinitionsMap.put(dtDefinition, new ArrayList<TaskDefinition>());
    }
    // ---
    for (final TaskDefinition taskDefinition : taskDefinitions) {
        final TaskDefinitionModel templateTaskDefinition = new TaskDefinitionModel(taskDefinition);
        final DtDefinition dtDefinition = getDtDefinition(templateTaskDefinition);
        final boolean dao = dtDefinition != null;
        if (dao) {
            // Dans le cas d'un DTO ou DTC en sortie on considère que la tache est liée au DAO.
            taskDefinitionsMap.get(dtDefinition).add(taskDefinition);
        }
    }
    return taskDefinitionsMap;
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) ArrayList(java.util.ArrayList) List(java.util.List) TaskDefinitionModel(io.vertigo.studio.plugins.mda.task.model.TaskDefinitionModel) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class JpaAnnotationWriter method getSequenceName.

/**
 * Nom de la séquence utilisée lors des inserts
 * @param dtDefinition Définition du DT mappé
 * @return String Nom de la sequence
 */
private static String getSequenceName(final DtField field) {
    final DtDefinition dtDefinition = Home.getApp().getDefinitionSpace().getAll(DtDefinition.class).stream().filter(definition -> definition.getFields().contains(field)).findFirst().orElseThrow(NoSuchElementException::new);
    // oracle n'autorise pas de sequence de plus de 30 char.
    String seqName = SEQUENCE_PREFIX + getTableName(dtDefinition);
    if (seqName.length() > 30) {
        seqName = seqName.substring(0, 30);
    }
    return seqName;
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class SqlGeneratorPlugin method generateSql.

private void generateSql(final FileGeneratorConfig fileGeneratorConfig, final MdaResultBuilder mdaResultBuilder) {
    final Map<String, List<SqlDtDefinitionModel>> mapListDtDef = new HashMap<>();
    for (final DtDefinition dtDefinition : DomainUtil.sortDefinitionCollection(DomainUtil.getDtDefinitions())) {
        if (dtDefinition.isPersistent()) {
            final SqlDtDefinitionModel templateDef = new SqlDtDefinitionModel(dtDefinition);
            final String dataSpace = dtDefinition.getDataSpace();
            final List<SqlDtDefinitionModel> listDtDef = obtainListDtDefinitionPerDataSpace(mapListDtDef, dataSpace);
            listDtDef.add(templateDef);
        }
    }
    // 
    final Collection<AssociationSimpleDefinition> collectionSimpleAll = DomainUtil.getSimpleAssociations();
    final Collection<AssociationNNDefinition> collectionNNAll = DomainUtil.getNNAssociations();
    // 
    for (final Entry<String, List<SqlDtDefinitionModel>> entry : mapListDtDef.entrySet()) {
        final String dataSpace = entry.getKey();
        final Collection<AssociationSimpleDefinition> associationSimpleDefinitions = filterAssociationSimple(collectionSimpleAll, dataSpace);
        final Collection<AssociationNNDefinition> associationNNDefinitions = filterAssociationNN(collectionNNAll, dataSpace);
        generateSqlByDataSpace(fileGeneratorConfig, mdaResultBuilder, associationSimpleDefinitions, associationNNDefinitions, dataSpace, entry.getValue());
    }
}
Also used : HashMap(java.util.HashMap) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) ArrayList(java.util.ArrayList) List(java.util.List) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) SqlDtDefinitionModel(io.vertigo.studio.plugins.mda.domain.sql.model.SqlDtDefinitionModel) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition)

Example 5 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class JpaDataStorePlugin method doFindAll.

private <E extends Entity> DtList<E> doFindAll(final ProcessAnalyticsTracer tracer, final DtDefinition dtDefinition, final DtListURIForNNAssociation dtcUri) {
    final Class<E> resultClass = (Class<E>) ClassUtil.classForName(dtDefinition.getClassCanonicalName());
    // PK de la DtList recherchée
    final String idFieldName = dtDefinition.getIdField().get().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 = joinDtDefinition.getIdField().get();
    // 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 = associationNode.getDtDefinition().getIdField().get();
    final String fkFieldName = fkField.getName();
    final String request = new StringBuilder(" select t.* from ").append(dtDefinition.getLocalName()).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).toString();
    final URI uri = dtcUri.getSource();
    final Query q = getEntityManager().createNativeQuery(request, resultClass);
    q.setParameter(fkFieldName, uri.getId());
    final List<E> results = q.getResultList();
    final DtList<E> dtc = new DtList<>(dtDefinition);
    dtc.addAll(results);
    tracer.setMeasure("nbSelectedRow", dtc.size());
    return dtc;
}
Also used : TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) 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) DtList(io.vertigo.dynamo.domain.model.DtList)

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