Search in sources :

Example 1 with DefinitionReference

use of io.vertigo.core.definition.DefinitionReference in project vertigo by KleeGroup.

the class UserAuthorizations method addAuthorization.

/**
 * Add a authorization to this User.
 * Authorization must be previously declared.
 *
 * @param authorization Authorization to add
 * @return this UserAuthorizations
 */
public UserAuthorizations addAuthorization(final Authorization authorization) {
    Assertion.checkNotNull(authorization);
    // -----
    authorizationRefs.put(authorization.getName(), new DefinitionReference<>(authorization));
    if (authorization.getEntityDefinition().isPresent()) {
        authorizationMapRefs.computeIfAbsent(new DefinitionReference<>(authorization.getEntityDefinition().get()), key -> new HashSet<>()).add(new DefinitionReference<>(authorization));
        for (final Authorization grantedAuthorization : authorization.getGrants()) {
            if (!hasAuthorization(grantedAuthorization::getName)) {
                // On test pour ne pas créer de boucle
                addAuthorization(grantedAuthorization);
            }
        }
    }
    return this;
}
Also used : AuthorizationName(io.vertigo.account.authorization.metamodel.AuthorizationName) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Set(java.util.Set) HashMap(java.util.HashMap) DefinitionReference(io.vertigo.core.definition.DefinitionReference) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) Role(io.vertigo.account.authorization.metamodel.Role) HashSet(java.util.HashSet) List(java.util.List) Map(java.util.Map) Assertion(io.vertigo.lang.Assertion) Authorization(io.vertigo.account.authorization.metamodel.Authorization) Collections(java.util.Collections) Authorization(io.vertigo.account.authorization.metamodel.Authorization) DefinitionReference(io.vertigo.core.definition.DefinitionReference) HashSet(java.util.HashSet)

Example 2 with DefinitionReference

use of io.vertigo.core.definition.DefinitionReference in project vertigo by KleeGroup.

the class DefinitionSpaceTest method testRegister.

@Test
public void testRegister() throws IOException, ClassNotFoundException {
    final DefinitionSpace definitionSpace = getApp().getDefinitionSpace();
    assertEquals(1L, definitionSpace.getAllTypes().size(), "definitionSpace must contain one element ");
    assertEquals(1L, definitionSpace.getAll(SampleDefinition.class).size(), "definitionSpace[SampleDefinition.class] must contain one element ");
    final SampleDefinition sampleDefinition = definitionSpace.resolve("SAMPLE_THE_DEFINITION", SampleDefinition.class);
    assertNotNull(sampleDefinition);
    assertEquals("THE_DEFINITION", DefinitionUtil.getLocalName(sampleDefinition.getName(), SampleDefinition.class), "localName must be THE_DEFINITION");
    assertEquals(sampleDefinition.getName(), DefinitionUtil.getPrefix(SampleDefinition.class) + "_" + DefinitionUtil.getLocalName(sampleDefinition.getName(), SampleDefinition.class), "localName must be THE_DEFINITION");
    final DefinitionReference<SampleDefinition> sampleDefinitionRef = new DefinitionReference<>(sampleDefinition);
    byte[] serialized;
    try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        final ObjectOutputStream oos = new ObjectOutputStream(bos)) {
        oos.writeObject(sampleDefinitionRef);
        oos.flush();
        serialized = bos.toByteArray();
    }
    // ---
    DefinitionReference definitionReference;
    try (final ByteArrayInputStream bis = new ByteArrayInputStream(serialized);
        final ObjectInputStream ios = new ObjectInputStream(bis)) {
        definitionReference = DefinitionReference.class.cast(ios.readObject());
    }
    assertNotSame(sampleDefinitionRef, definitionReference, "DefinitionReferences must be not strictly equals");
    assertSame(sampleDefinition, definitionReference.get(), "Definitions must be strictly equals");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DefinitionSpace(io.vertigo.core.definition.DefinitionSpace) DefinitionReference(io.vertigo.core.definition.DefinitionReference) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.jupiter.api.Test)

Aggregations

DefinitionReference (io.vertigo.core.definition.DefinitionReference)2 Authorization (io.vertigo.account.authorization.metamodel.Authorization)1 AuthorizationName (io.vertigo.account.authorization.metamodel.AuthorizationName)1 Role (io.vertigo.account.authorization.metamodel.Role)1 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)1 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)1 Assertion (io.vertigo.lang.Assertion)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1