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