Search in sources :

Example 1 with AssociationSimpleDefinition

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

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

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

the class DomainDynamicRegistry method createAssociationSimpleDefinition.

private AssociationSimpleDefinition createAssociationSimpleDefinition(final DefinitionSpace definitionSpace, final DslDefinition xassociation) {
    final String multiplicityA = (String) xassociation.getPropertyValue(KspProperty.MULTIPLICITY_A);
    final String multiplicityB = (String) xassociation.getPropertyValue(KspProperty.MULTIPLICITY_B);
    // Vérification que l'on est bien dans le cas d'une association simple de type 1-n
    if (AssociationUtil.isMultiple(multiplicityB) && AssociationUtil.isMultiple(multiplicityA)) {
        // Relation n-n
        throw new IllegalArgumentException("Utiliser la déclaration AssociationNN");
    }
    if (!AssociationUtil.isMultiple(multiplicityB) && !AssociationUtil.isMultiple(multiplicityA)) {
        // Relation 1-1
        throw new IllegalArgumentException("Les associations 1-1 sont interdites");
    }
    final String fkFieldName = (String) xassociation.getPropertyValue(KspProperty.FK_FIELD_NAME);
    final DtDefinition dtDefinitionA = definitionSpace.resolve(xassociation.getDefinitionLinkName("dtDefinitionA"), DtDefinition.class);
    final boolean navigabilityA = (Boolean) xassociation.getPropertyValue(KspProperty.NAVIGABILITY_A);
    final String roleA = (String) xassociation.getPropertyValue(KspProperty.ROLE_A);
    final String labelA = (String) xassociation.getPropertyValue(KspProperty.LABEL_A);
    final DtDefinition dtDefinitionB = definitionSpace.resolve(xassociation.getDefinitionLinkName("dtDefinitionB"), DtDefinition.class);
    final boolean navigabilityB = (Boolean) xassociation.getPropertyValue(KspProperty.NAVIGABILITY_B);
    final String roleB = (String) xassociation.getPropertyValue(KspProperty.ROLE_B);
    final String labelB = (String) xassociation.getPropertyValue(KspProperty.LABEL_B);
    // Relation 1-n ou 1-1
    final String urn = fixAssociationName(ASSOCIATION_SIMPLE_DEFINITION_PREFIX, xassociation.getName());
    final AssociationNode associationNodeA = new AssociationNode(dtDefinitionA, navigabilityA, roleA, labelA, AssociationUtil.isMultiple(multiplicityA), AssociationUtil.isNotNull(multiplicityA));
    final AssociationNode associationNodeB = new AssociationNode(dtDefinitionB, navigabilityB, roleB, labelB, AssociationUtil.isMultiple(multiplicityB), AssociationUtil.isNotNull(multiplicityB));
    final AssociationSimpleDefinition associationSimpleDefinition = new AssociationSimpleDefinition(urn, fkFieldName, associationNodeA, associationNodeB);
    final AssociationNode primaryAssociationNode = associationSimpleDefinition.getPrimaryAssociationNode();
    final AssociationNode foreignAssociationNode = associationSimpleDefinition.getForeignAssociationNode();
    final DtDefinition fkDefinition = primaryAssociationNode.getDtDefinition();
    LOGGER.trace("" + xassociation.getName() + " : ajout d'une FK [" + fkFieldName + "] sur la table '" + foreignAssociationNode.getDtDefinition().getName() + "'");
    final String label = primaryAssociationNode.getLabel();
    dtDefinitionBuilders.get(foreignAssociationNode.getDtDefinition().getName()).addForeignKey(fkFieldName, label, fkDefinition.getIdField().get().getDomain(), primaryAssociationNode.isNotNull(), fkDefinition.getName());
    return associationSimpleDefinition;
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) AssociationNode(io.vertigo.dynamo.domain.metamodel.association.AssociationNode)

Example 4 with AssociationSimpleDefinition

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

the class DtObjectUtil method createDtListURIForSimpleAssociation.

/**
 * Récupération d'une URI de Collection à partir d'un dto
 * @param entity the entity
 * @param associationDefinitionName Nom de l'association
 * @param roleName Nom du role
 * @return URI de la collection référencée.
 */
public static DtListURIForSimpleAssociation createDtListURIForSimpleAssociation(final Entity entity, final String associationDefinitionName, final String roleName) {
    Assertion.checkNotNull(associationDefinitionName);
    Assertion.checkNotNull(roleName);
    Assertion.checkNotNull(entity);
    // -----
    final AssociationSimpleDefinition associationDefinition = Home.getApp().getDefinitionSpace().resolve(associationDefinitionName, AssociationSimpleDefinition.class);
    return new DtListURIForSimpleAssociation(associationDefinition, entity.getURI(), roleName);
}
Also used : AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) DtListURIForSimpleAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForSimpleAssociation)

Example 5 with AssociationSimpleDefinition

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

Aggregations

AssociationSimpleDefinition (io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition)32 Test (org.junit.Test)24 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)7 AssociationNNDefinition (io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition)5 AccountMapperHelper (io.vertigo.account.impl.account.AccountMapperHelper)3 DtField (io.vertigo.dynamo.domain.metamodel.DtField)3 AssociationDefinition (io.vertigo.dynamo.domain.metamodel.association.AssociationDefinition)3 DtListURIForSimpleAssociation (io.vertigo.dynamo.domain.metamodel.association.DtListURIForSimpleAssociation)3 URI (io.vertigo.dynamo.domain.model.URI)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 DtListURIForNNAssociation (io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation)2 DtList (io.vertigo.dynamo.domain.model.DtList)2 DtListURI (io.vertigo.dynamo.domain.model.DtListURI)2 Entity (io.vertigo.dynamo.domain.model.Entity)2