use of io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition in project vertigo by KleeGroup.
the class EAXmiTestParserAA method testAssoctationAnvBn.
/**
* Test d'une relation Anv - Bn.
*/
@Test
public void testAssoctationAnvBn() {
final AssociationNNDefinition association = getAssociationNNDefinition("ANN_CHI_CHI_10");
/* "0..*" */
Assert.assertTrue(association.getAssociationNodeA().isMultiple());
Assert.assertFalse(association.getAssociationNodeA().isNotNull());
/* "0..*" */
Assert.assertTrue(association.getAssociationNodeB().isMultiple());
Assert.assertFalse(association.getAssociationNodeB().isNotNull());
Assert.assertEquals("R10A", association.getAssociationNodeA().getRole());
Assert.assertEquals("R10B", association.getAssociationNodeB().getRole());
Assert.assertTrue(association.getAssociationNodeA().isNavigable());
Assert.assertFalse(association.getAssociationNodeB().isNavigable());
}
use of io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition in project vertigo by KleeGroup.
the class EAXmiTestParserAA 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());
}
use of io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition in project vertigo by KleeGroup.
the class SqlDataStorePlugin method findAll.
/**
* {@inheritDoc}
*/
@Override
public <E extends Entity> DtList<E> findAll(final DtDefinition dtDefinition, final DtListURIForNNAssociation dtcUri) {
Assertion.checkNotNull(dtDefinition);
Assertion.checkNotNull(dtcUri);
// -----
final String tableName = getTableName(dtDefinition);
final String taskName = TASK.TK_SELECT + "_N_N_LIST_" + tableName + "_BY_URI";
// PK de la DtList recherchée
final String idFieldName = getIdField(dtDefinition).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 = getIdField(joinDtDefinition);
// 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 = getIdField(associationNode.getDtDefinition());
final String fkFieldName = fkField.getName();
final String request = new StringBuilder(" select t.* from ").append(tableName).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).append('#').toString();
final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineSelect.class).withDataSpace(dataSpace).withRequest(request).addInRequired(fkFieldName, fkField.getDomain()).withOutRequired("dtc", Home.getApp().getDefinitionSpace().resolve(DOMAIN_PREFIX + SEPARATOR + dtDefinition.getName() + "_DTC", Domain.class)).build();
final URI uri = dtcUri.getSource();
final Task task = Task.builder(taskDefinition).addValue(fkFieldName, uri.getId()).build();
return taskManager.execute(task).getResult();
}
use of io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition in project vertigo by KleeGroup.
the class StoreAccountStorePlugin method getGroupURIs.
/**
* {@inheritDoc}
*/
@Override
public Set<URI<AccountGroup>> getGroupURIs(final URI<Account> accountURI) {
if (associationUserGroup instanceof AssociationSimpleDefinition) {
// case 1 group per user
final URI<Entity> userURI = new URI(getUserDtDefinition(), accountURI.getId());
final Entity userEntity = storeManager.getDataStore().readOne(userURI);
final Object fkValue = ((AssociationSimpleDefinition) associationUserGroup).getFKField().getDataAccessor().getValue(userEntity);
final URI<AccountGroup> groupURI = new URI(userGroupDtDefinition, fkValue);
return Collections.singleton(groupURI);
}
// case N group per user
// other case checked in postStart by assertions
Assertion.checkArgument(associationUserGroup instanceof AssociationNNDefinition, "Association ({0}) between User and Group must be an AssociationSimpleDefinition or an AssociationNNDefinition", associationUserGroup.getName());
final DtListURI groupDtListURI = new DtListURIForNNAssociation((AssociationNNDefinition) associationUserGroup, accountURI, associationGroupRoleName);
// -----
final DtList<? extends Entity> result = Home.getApp().getComponentSpace().resolve(StoreManager.class).getDataStore().findAll(groupDtListURI);
return result.stream().map(groupEntity -> groupToAccount(groupEntity).getURI()).collect(Collectors.toSet());
}
use of io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition in project vertigo by KleeGroup.
the class StoreAccountStorePlugin method getAccountURIs.
/**
* {@inheritDoc}
*/
@Override
public Set<URI<Account>> getAccountURIs(final URI<AccountGroup> groupURI) {
final DtListURI userDtListURI;
if (associationUserGroup instanceof AssociationSimpleDefinition) {
userDtListURI = new DtListURIForSimpleAssociation((AssociationSimpleDefinition) associationUserGroup, groupURI, associationUserRoleName);
} else {
// autres cas éliminés par assertion dans le postStart
Assertion.checkArgument(associationUserGroup instanceof AssociationNNDefinition, "Association ({0}) between User and Group must be an AssociationSimpleDefinition or an AssociationNNDefinition", associationUserGroup.getName());
userDtListURI = new DtListURIForNNAssociation((AssociationNNDefinition) associationUserGroup, groupURI, associationUserRoleName);
}
// -----
final DtList<? extends Entity> result = Home.getApp().getComponentSpace().resolve(StoreManager.class).getDataStore().findAll(userDtListURI);
return result.stream().map(userEntity -> userToAccount(userEntity).getURI()).collect(Collectors.toSet());
}
Aggregations