Search in sources :

Example 11 with AssociationNNDefinition

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());
}
Also used : AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) Test(org.junit.Test)

Example 12 with AssociationNNDefinition

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());
}
Also used : AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) Test(org.junit.Test)

Example 13 with AssociationNNDefinition

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();
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) TaskEngineSelect(io.vertigo.dynamox.task.TaskEngineSelect) 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)

Example 14 with AssociationNNDefinition

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());
}
Also used : AbstractAccountStorePlugin(io.vertigo.account.plugins.account.store.AbstractAccountStorePlugin) DtListURIForNNAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation) DtField(io.vertigo.dynamo.domain.metamodel.DtField) URI(io.vertigo.dynamo.domain.model.URI) Criteria(io.vertigo.dynamo.criteria.Criteria) Inject(javax.inject.Inject) Home(io.vertigo.app.Home) StoreManager(io.vertigo.dynamo.store.StoreManager) Criterions(io.vertigo.dynamo.criteria.Criterions) DtListURIForSimpleAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForSimpleAssociation) Assertion(io.vertigo.lang.Assertion) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) Named(javax.inject.Named) AccountMapperHelper(io.vertigo.account.impl.account.AccountMapperHelper) AccountGroup(io.vertigo.account.account.AccountGroup) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Set(java.util.Set) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) DtList(io.vertigo.dynamo.domain.model.DtList) Collectors(java.util.stream.Collectors) VFile(io.vertigo.dynamo.file.model.VFile) AccountStorePlugin(io.vertigo.account.impl.account.AccountStorePlugin) Entity(io.vertigo.dynamo.domain.model.Entity) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) Account(io.vertigo.account.account.Account) AssociationDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationDefinition) Optional(java.util.Optional) Collections(java.util.Collections) Entity(io.vertigo.dynamo.domain.model.Entity) AccountGroup(io.vertigo.account.account.AccountGroup) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) DtListURIForNNAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) URI(io.vertigo.dynamo.domain.model.URI) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition)

Example 15 with AssociationNNDefinition

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());
}
Also used : AbstractAccountStorePlugin(io.vertigo.account.plugins.account.store.AbstractAccountStorePlugin) DtListURIForNNAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation) DtField(io.vertigo.dynamo.domain.metamodel.DtField) URI(io.vertigo.dynamo.domain.model.URI) Criteria(io.vertigo.dynamo.criteria.Criteria) Inject(javax.inject.Inject) Home(io.vertigo.app.Home) StoreManager(io.vertigo.dynamo.store.StoreManager) Criterions(io.vertigo.dynamo.criteria.Criterions) DtListURIForSimpleAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForSimpleAssociation) Assertion(io.vertigo.lang.Assertion) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition) Named(javax.inject.Named) AccountMapperHelper(io.vertigo.account.impl.account.AccountMapperHelper) AccountGroup(io.vertigo.account.account.AccountGroup) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Set(java.util.Set) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) DtList(io.vertigo.dynamo.domain.model.DtList) Collectors(java.util.stream.Collectors) VFile(io.vertigo.dynamo.file.model.VFile) AccountStorePlugin(io.vertigo.account.impl.account.AccountStorePlugin) Entity(io.vertigo.dynamo.domain.model.Entity) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) Account(io.vertigo.account.account.Account) AssociationDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationDefinition) Optional(java.util.Optional) Collections(java.util.Collections) DtListURI(io.vertigo.dynamo.domain.model.DtListURI) DtListURIForNNAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForNNAssociation) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) DtListURIForSimpleAssociation(io.vertigo.dynamo.domain.metamodel.association.DtListURIForSimpleAssociation) AssociationNNDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition)

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