Search in sources :

Example 16 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class AuthorizationManagerImpl method getAuthorizedOperations.

/**
 * {@inheritDoc}
 */
@Override
public <K extends KeyConcept> List<String> getAuthorizedOperations(final K keyConcept) {
    Assertion.checkNotNull(keyConcept);
    // ---
    final Optional<UserAuthorizations> userPermissionsOpt = getUserPermissionsOpt();
    if (!userPermissionsOpt.isPresent()) {
        // Si il n'y a pas de session alors pas d'autorisation.
        return Collections.emptyList();
    }
    final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(keyConcept);
    return userPermissionsOpt.get().getEntityAuthorizations(dtDefinition).stream().map(permission -> permission.getOperation().get()).collect(Collectors.toList());
}
Also used : RuleMultiExpression(io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression) CriteriaSecurityRuleTranslator(io.vertigo.account.impl.authorization.dsl.translator.CriteriaSecurityRuleTranslator) VSecurityManager(io.vertigo.persona.security.VSecurityManager) UserAuthorizations(io.vertigo.account.authorization.UserAuthorizations) AuthorizationName(io.vertigo.account.authorization.metamodel.AuthorizationName) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtObjectUtil(io.vertigo.dynamo.domain.util.DtObjectUtil) Criteria(io.vertigo.dynamo.criteria.Criteria) AuthorizationManager(io.vertigo.account.authorization.AuthorizationManager) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) Home(io.vertigo.app.Home) List(java.util.List) DefinitionUtil(io.vertigo.core.definition.DefinitionUtil) Criterions(io.vertigo.dynamo.criteria.Criterions) Assertion(io.vertigo.lang.Assertion) KeyConcept(io.vertigo.dynamo.domain.model.KeyConcept) Optional(java.util.Optional) Authorization(io.vertigo.account.authorization.metamodel.Authorization) OperationName(io.vertigo.account.authorization.metamodel.OperationName) Collections(java.util.Collections) SearchSecurityRuleTranslator(io.vertigo.account.impl.authorization.dsl.translator.SearchSecurityRuleTranslator) UserSession(io.vertigo.persona.security.UserSession) SecuredEntity(io.vertigo.account.authorization.metamodel.SecuredEntity) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) UserAuthorizations(io.vertigo.account.authorization.UserAuthorizations)

Example 17 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class AccountDefinitionProvider method provideDefinitions.

/**
 * {@inheritDoc}
 */
@Override
public List<Definition> provideDefinitions(final DefinitionSpace definitionSpace) {
    final Domain domainAccountId = Domain.builder("DO_X_ACCOUNT_ID", DataType.String).build();
    final Domain domainAccountName = Domain.builder("DO_X_ACCOUNT_NAME", DataType.String).build();
    final Domain domainAccountEmail = Domain.builder("DO_X_ACCOUNT_EMAIL", DataType.String).build();
    final DtDefinition accountDtDefinition = DtDefinition.builder("DT_ACCOUNT").addIdField(ID, "id", domainAccountId).addDataField(DISPLAY_NAME, "displayName", domainAccountName, false, true).addDataField(EMAIL, "email", domainAccountEmail, false, true).withSortField(DISPLAY_NAME).withDisplayField(DISPLAY_NAME).build();
    final DtDefinition accountGroupDtDefinition = DtDefinition.builder("DT_ACCOUNT_GROUP").addIdField(ID, "id", domainAccountId).addDataField(DISPLAY_NAME, "displayName", domainAccountName, false, true).withSortField(DISPLAY_NAME).withDisplayField(DISPLAY_NAME).build();
    return new ListBuilder<Definition>().add(domainAccountId).add(domainAccountName).add(domainAccountEmail).add(accountDtDefinition).add(accountGroupDtDefinition).build();
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) ListBuilder(io.vertigo.util.ListBuilder) Domain(io.vertigo.dynamo.domain.metamodel.Domain)

Example 18 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class DAO method getListByDtFieldName.

/**
 * @param dtFieldName de l'object à récupérer NOT NULL
 * @param value de l'object à récupérer NOT NULL
 * @param maxRows Nombre maximum de ligne
 * @return DtList<D> récupéré NOT NUL
 */
public final DtList<E> getListByDtFieldName(final DtFieldName dtFieldName, final Serializable value, final int maxRows) {
    final Criteria<E> criteria = Criterions.isEqualTo(dtFieldName, value);
    // Verification de la valeur est du type du champ
    final DtDefinition dtDefinition = getDtDefinition();
    dtDefinition.getField(dtFieldName.name()).getDomain().checkValue(value);
    return dataStore.findAll(new DtListURIForCriteria<>(dtDefinition, criteria, maxRows));
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition)

Example 19 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class DomainDynamicRegistry method createFragmentDtDefinition.

private static DtDefinition createFragmentDtDefinition(final DefinitionSpace definitionSpace, final DslDefinition xdtDefinition) {
    final DtDefinition from = definitionSpace.resolve(xdtDefinition.getDefinitionLinkName("from"), DtDefinition.class);
    final String sortFieldName = (String) xdtDefinition.getPropertyValue(KspProperty.SORT_FIELD);
    final String displayFieldName = (String) xdtDefinition.getPropertyValue(KspProperty.DISPLAY_FIELD);
    // 0. clones characteristics
    final DtDefinitionBuilder dtDefinitionBuilder = DtDefinition.builder(xdtDefinition.getName()).withFragment(from).withPackageName(xdtDefinition.getPackageName()).withDataSpace(from.getDataSpace()).withPackageName(from.getPackageName()).withSortField(sortFieldName).withDisplayField(displayFieldName);
    // 1. adds aliases
    for (final DslDefinition alias : xdtDefinition.getChildDefinitions("alias")) {
        final DtField aliasDtField = from.getField(alias.getName());
        // --- REQUIRED
        final Boolean overiddenRequired = (Boolean) alias.getPropertyValue(KspProperty.NOT_NULL);
        final boolean required = overiddenRequired != null ? overiddenRequired : aliasDtField.isRequired();
        // --- LABEL
        final String overiddenLabel = (String) alias.getPropertyValue(KspProperty.LABEL);
        final String label = overiddenLabel != null ? overiddenLabel : aliasDtField.getLabel().getDisplay();
        dtDefinitionBuilder.addDataField(aliasDtField.getName(), label, aliasDtField.getDomain(), required, aliasDtField.isPersistent());
    }
    // 2. adds data and computed fields
    // Déclaration des champs du DT
    final List<DslDefinition> fields = xdtDefinition.getChildDefinitions(DomainGrammar.FIELD);
    populateDataDtField(definitionSpace, dtDefinitionBuilder, fields);
    // Déclaration des champs calculés
    final List<DslDefinition> computedFields = xdtDefinition.getChildDefinitions(DomainGrammar.COMPUTED);
    populateComputedDtField(definitionSpace, dtDefinitionBuilder, computedFields);
    final DtDefinition dtDefinition = dtDefinitionBuilder.build();
    // 0. adds ID field -->>> Should be first, but needs an already build DtDefinition
    if (from.getIdField().isPresent()) {
        final DtField idField = from.getIdField().get();
        dtDefinitionBuilder.addForeignKey(idField.getName(), idField.getLabel().getDisplay(), idField.getDomain(), true, from.getName());
    }
    return dtDefinition;
}
Also used : DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) DtDefinitionBuilder(io.vertigo.dynamo.domain.metamodel.DtDefinitionBuilder) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 20 with DtDefinition

use of io.vertigo.dynamo.domain.metamodel.DtDefinition in project vertigo by KleeGroup.

the class DomainDynamicRegistry method createDtDefinition.

/**
 * @param xdtDefinition Définition de DT
 */
private DtDefinition createDtDefinition(final DefinitionSpace definitionSpace, final DslDefinition xdtDefinition) {
    // Déclaration de la définition
    final String sortFieldName = (String) xdtDefinition.getPropertyValue(KspProperty.SORT_FIELD);
    final String displayFieldName = (String) xdtDefinition.getPropertyValue(KspProperty.DISPLAY_FIELD);
    // -----
    final String tmpStereotype = (String) xdtDefinition.getPropertyValue(KspProperty.STEREOTYPE);
    // Si Stereotype est non renseigné on suppose que la définition est DtStereotype.Data.
    final DtStereotype stereotype = tmpStereotype != null ? DtStereotype.valueOf(tmpStereotype) : null;
    // -----
    final String dataSpace = (String) xdtDefinition.getPropertyValue(KspProperty.DATA_SPACE);
    // -----
    final String fragmentOf = (String) xdtDefinition.getPropertyValue(KspProperty.FRAGMENT_OF);
    // -----
    // -----
    final String dtDefinitionName = xdtDefinition.getName();
    final DtDefinitionBuilder dtDefinitionBuilder = DtDefinition.builder(dtDefinitionName).withPackageName(xdtDefinition.getPackageName()).withDataSpace(dataSpace).withSortField(sortFieldName).withDisplayField(displayFieldName);
    if (stereotype != null) {
        dtDefinitionBuilder.withStereoType(stereotype);
    }
    if (!StringUtil.isEmpty(fragmentOf)) {
        dtDefinitionBuilder.withFragment(definitionSpace.resolve(fragmentOf, DtDefinition.class));
    }
    // On enregistre les Builder pour pouvoir les mettre à jour sur les associations.
    Assertion.checkArgument(!dtDefinitionBuilders.containsKey(dtDefinitionName), "Definition '{0}' already registered", dtDefinitionName);
    dtDefinitionBuilders.put(dtDefinitionName, dtDefinitionBuilder);
    // Déclaration de la clé primaire
    final List<DslDefinition> keys = xdtDefinition.getChildDefinitions(DomainGrammar.ID);
    populateIdDtField(definitionSpace, dtDefinitionBuilder, keys);
    // Déclaration des champs du DT
    final List<DslDefinition> fields = xdtDefinition.getChildDefinitions(DomainGrammar.FIELD);
    populateDataDtField(definitionSpace, dtDefinitionBuilder, fields);
    // Déclaration des champs calculés
    final List<DslDefinition> computedFields = xdtDefinition.getChildDefinitions(DomainGrammar.COMPUTED);
    populateComputedDtField(definitionSpace, dtDefinitionBuilder, computedFields);
    return dtDefinitionBuilder.build();
}
Also used : DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) DtDefinitionBuilder(io.vertigo.dynamo.domain.metamodel.DtDefinitionBuilder) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtStereotype(io.vertigo.dynamo.domain.metamodel.DtStereotype)

Aggregations

DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)91 DtField (io.vertigo.dynamo.domain.metamodel.DtField)29 Test (org.junit.Test)21 URI (io.vertigo.dynamo.domain.model.URI)18 List (java.util.List)17 ArrayList (java.util.ArrayList)16 Assertion (io.vertigo.lang.Assertion)12 Collectors (java.util.stream.Collectors)11 Home (io.vertigo.app.Home)10 Optional (java.util.Optional)10 Domain (io.vertigo.dynamo.domain.metamodel.Domain)9 Collections (java.util.Collections)8 DefinitionUtil (io.vertigo.core.definition.DefinitionUtil)7 DtObjectUtil (io.vertigo.dynamo.domain.util.DtObjectUtil)7 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)7 Inject (javax.inject.Inject)7 Authorization (io.vertigo.account.authorization.metamodel.Authorization)6 SecuredEntity (io.vertigo.account.authorization.metamodel.SecuredEntity)6 Criterions (io.vertigo.dynamo.criteria.Criterions)6 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)5