Search in sources :

Example 1 with AssociationNNDefinition

use of io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition 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 2 with AssociationNNDefinition

use of io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition 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)

Example 3 with AssociationNNDefinition

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

the class StoreAccountStorePlugin method postStart.

@Override
protected void postStart() {
    userGroupDtDefinition = Home.getApp().getDefinitionSpace().resolve(groupIdentityEntity, DtDefinition.class);
    mapperHelper = new AccountMapperHelper(userGroupDtDefinition, GroupProperty.class, groupToGroupAccountMappingStr).withMandatoryDestField(GroupProperty.id).withMandatoryDestField(GroupProperty.displayName).parseAttributeMapping();
    for (final AssociationDefinition association : Home.getApp().getDefinitionSpace().getAll(AssociationDefinition.class)) {
        if ((userGroupDtDefinition.equals(association.getAssociationNodeA().getDtDefinition()) && getUserDtDefinition().equals(association.getAssociationNodeB().getDtDefinition()))) {
            associationUserGroup = association;
            associationUserRoleName = association.getAssociationNodeB().getRole();
            associationGroupRoleName = association.getAssociationNodeA().getRole();
            break;
        } else if (userGroupDtDefinition.equals(association.getAssociationNodeB().getDtDefinition()) && getUserDtDefinition().equals(association.getAssociationNodeA().getDtDefinition())) {
            associationUserGroup = association;
            associationUserRoleName = association.getAssociationNodeA().getRole();
            associationGroupRoleName = association.getAssociationNodeB().getRole();
            break;
        }
    }
    Assertion.checkNotNull(associationUserGroup, "Association between User ({0}) and Group ({1}) not found", getUserDtDefinition().getClassSimpleName(), userGroupDtDefinition.getClassSimpleName());
    Assertion.checkState(associationUserGroup instanceof AssociationSimpleDefinition || associationUserGroup instanceof AssociationNNDefinition, "Association ({0}) between User and Group must be an AssociationSimpleDefinition or an AssociationNNDefinition", associationUserGroup.getName());
}
Also used : AssociationDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationDefinition) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) AccountMapperHelper(io.vertigo.account.impl.account.AccountMapperHelper) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition)

Example 4 with AssociationNNDefinition

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

the class Studio method start.

/**
 * Start method of the server
 */
public void start() {
    Spark.exception(Exception.class, (e, request, response) -> {
        response.status(500);
        LOGGER.error("studio : error on render ", e);
        response.body(e.getMessage());
    });
    Spark.get("/studio", (request, response) -> {
        final MdaResult mdaResult = null;
        return display(response, mdaResult);
    });
    Spark.get("/grammar", (request, response) -> {
        final MdaResult mdaResult = null;
        return grammar(response, mdaResult);
    });
    Spark.get("/studio/definitions/:definitionName", (request, response) -> {
        final String defintionName = request.params(":definitionName");
        final Map<String, Object> model = new MapBuilder<String, Object>().put("definition", getDefinition(defintionName)).build();
        return render(response, "template/definition.ftl", model);
    });
    Spark.get("/generate", (request, response) -> {
        final MdaResult mdaResult = generate();
        return display(response, mdaResult);
    });
    Spark.get("/clean", (request, response) -> {
        final MdaResult mdaResult = clean();
        return display(response, mdaResult);
    });
    Spark.get("/graph", (request, response) -> {
        final ListBuilder<Vertex> verticlesBuilder = new ListBuilder<>();
        final ListBuilder<Definition> edgesBuilders = new ListBuilder<>();
        edgesBuilders.addAll(app.getDefinitionSpace().getAll(DtDefinition.class));
        for (final AssociationNNDefinition associationDefinition1 : app.getDefinitionSpace().getAll(AssociationNNDefinition.class)) {
            verticlesBuilder.add(new Vertex(associationDefinition1.getAssociationNodeA().getDtDefinition(), associationDefinition1.getAssociationNodeB().getDtDefinition()));
        }
        for (final AssociationSimpleDefinition associationDefinition2 : app.getDefinitionSpace().getAll(AssociationSimpleDefinition.class)) {
            verticlesBuilder.add(new Vertex(associationDefinition2.getAssociationNodeA().getDtDefinition(), associationDefinition2.getAssociationNodeB().getDtDefinition()));
        }
        // for (final Domain domain : app.getDefinitionSpace().getAll(Domain.class)) {
        // //						verticlesBuilder.add(new Vertex(domain.getFormatter(), domain));
        // for (final DefinitionReference<ConstraintDefinition> constraintDefinitionRef : domain.getConstraintDefinitionRefs()) {
        // verticlesBuilder.add(new Vertex(constraintDefinitionRef.get(), domain));
        // }
        // }
        // edgesBuilders.addAll(app.getDefinitionSpace().getAll(ConstraintDefinition.class));
        // edgesBuilders.addAll(app.getDefinitionSpace().getAll(Domain.class));
        final Map<String, Object> model = new MapBuilder<String, Object>().put("edges", edgesBuilders.build()).put("verticles", verticlesBuilder.build()).build();
        return render(response, "template/graph.ftl", model);
    });
}
Also used : AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Definition(io.vertigo.core.definition.Definition) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) MapBuilder(io.vertigo.util.MapBuilder) ListBuilder(io.vertigo.util.ListBuilder) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) MdaResult(io.vertigo.studio.mda.MdaResult)

Example 5 with AssociationNNDefinition

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

the class OOMParserAATest method testAssoctationAnBnv.

/**
 * Test d'une relation An - Bnv.
 */
@Test
public void testAssoctationAnBnv() {
    final AssociationNNDefinition association = getAssociationNNDefinition("ANN_CHI_CHI_7");
    /* "0..*" */
    Assert.assertTrue(association.getAssociationNodeA().isMultiple());
    Assert.assertFalse(association.getAssociationNodeA().isNotNull());
    /* "0..*" */
    Assert.assertTrue(association.getAssociationNodeB().isMultiple());
    Assert.assertFalse(association.getAssociationNodeB().isNotNull());
    Assert.assertEquals("R7A", association.getAssociationNodeA().getRole());
    Assert.assertEquals("R7B", association.getAssociationNodeB().getRole());
    Assert.assertFalse(association.getAssociationNodeA().isNavigable());
    Assert.assertTrue(association.getAssociationNodeB().isNavigable());
}
Also used : AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) Test(org.junit.Test)

Aggregations

AssociationNNDefinition (io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition)25 Test (org.junit.Test)16 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)8 AssociationSimpleDefinition (io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition)5 DtField (io.vertigo.dynamo.domain.metamodel.DtField)4 URI (io.vertigo.dynamo.domain.model.URI)4 AccountMapperHelper (io.vertigo.account.impl.account.AccountMapperHelper)3 AssociationDefinition (io.vertigo.dynamo.domain.metamodel.association.AssociationDefinition)3 AssociationNode (io.vertigo.dynamo.domain.metamodel.association.AssociationNode)3 DtListURIForNNAssociation (io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation)3 DtList (io.vertigo.dynamo.domain.model.DtList)3 Account (io.vertigo.account.account.Account)2 AccountGroup (io.vertigo.account.account.AccountGroup)2 AccountStorePlugin (io.vertigo.account.impl.account.AccountStorePlugin)2 AbstractAccountStorePlugin (io.vertigo.account.plugins.account.store.AbstractAccountStorePlugin)2 Home (io.vertigo.app.Home)2 Criteria (io.vertigo.dynamo.criteria.Criteria)2 Criterions (io.vertigo.dynamo.criteria.Criterions)2 DtListURIForSimpleAssociation (io.vertigo.dynamo.domain.metamodel.association.DtListURIForSimpleAssociation)2 DtListURI (io.vertigo.dynamo.domain.model.DtListURI)2