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());
}
}
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());
}
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;
}
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);
}
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);
});
}
Aggregations