Search in sources :

Example 6 with KeyConcept

use of io.vertigo.dynamo.domain.model.KeyConcept in project vertigo by KleeGroup.

the class AuthorizationManagerImpl method getSearchSecurity.

/**
 * {@inheritDoc}
 */
@Override
public <K extends KeyConcept> String getSearchSecurity(final Class<K> keyConceptClass, final OperationName<K> operationName) {
    Assertion.checkNotNull(keyConceptClass);
    Assertion.checkNotNull(operationName);
    // ---
    final Optional<UserAuthorizations> userPermissionsOpt = getUserPermissionsOpt();
    if (!userPermissionsOpt.isPresent()) {
        // Attention : pas de *:*
        return "";
    }
    final UserAuthorizations userPermissions = userPermissionsOpt.get();
    final SearchSecurityRuleTranslator securityRuleTranslator = new SearchSecurityRuleTranslator();
    securityRuleTranslator.withCriteria(userPermissions.getSecurityKeys());
    final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(keyConceptClass);
    final List<Authorization> permissions = userPermissions.getEntityAuthorizations(dtDefinition).stream().filter(permission -> permission.getOperation().get().equals(operationName.name())).collect(Collectors.toList());
    for (final Authorization permission : permissions) {
        for (final RuleMultiExpression ruleExpression : permission.getRules()) {
            securityRuleTranslator.withRule(ruleExpression);
        }
    }
    return securityRuleTranslator.toSearchQuery();
}
Also used : Authorization(io.vertigo.account.authorization.metamodel.Authorization) 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) SearchSecurityRuleTranslator(io.vertigo.account.impl.authorization.dsl.translator.SearchSecurityRuleTranslator) RuleMultiExpression(io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) UserAuthorizations(io.vertigo.account.authorization.UserAuthorizations)

Example 7 with KeyConcept

use of io.vertigo.dynamo.domain.model.KeyConcept in project vertigo by KleeGroup.

the class AbstractESSearchServicesPlugin method loadList.

/**
 * {@inheritDoc}
 */
@Override
public final <R extends DtObject> FacetedQueryResult<R, SearchQuery> loadList(final SearchIndexDefinition indexDefinition, final SearchQuery searchQuery, final DtListState listState) {
    Assertion.checkNotNull(searchQuery);
    // -----
    final ESStatement<KeyConcept, R> statement = createElasticStatement(indexDefinition);
    final DtListState usedListState = listState != null ? listState : defaultListState;
    return statement.loadList(indexDefinition, searchQuery, usedListState, defaultMaxRows);
}
Also used : KeyConcept(io.vertigo.dynamo.domain.model.KeyConcept) DtListState(io.vertigo.dynamo.domain.model.DtListState)

Example 8 with KeyConcept

use of io.vertigo.dynamo.domain.model.KeyConcept in project vertigo by KleeGroup.

the class ReindexTask method run.

/**
 * {@inheritDoc}
 */
@Override
public void run() {
    long dirtyElementsCount = 0;
    do {
        final long startTime = System.currentTimeMillis();
        final List<URI<? extends KeyConcept>> reindexUris = new ArrayList<>();
        try {
            synchronized (dirtyElements) {
                if (!dirtyElements.isEmpty()) {
                    reindexUris.addAll(dirtyElements.subList(0, Math.min(dirtyElements.size(), DIRTY_ELEMENTS_CHUNK_SIZE)));
                    dirtyElements.removeAll(reindexUris);
                }
            }
            dirtyElementsCount = reindexUris.size();
            if (!reindexUris.isEmpty()) {
                loadAndIndexAndRetry(new SearchChunk(reindexUris), 0);
            }
        } catch (final Exception e) {
            LOGGER.error("Update index error, skip " + dirtyElementsCount + " elements (" + reindexUris + ")", e);
        } finally {
            LOGGER.log(dirtyElementsCount > 0 ? Level.INFO : Level.DEBUG, "Update index, " + dirtyElementsCount + " " + searchIndexDefinition.getName() + " finished in " + (System.currentTimeMillis() - startTime) + "ms");
        }
    } while (dirtyElementsCount > 0);
}
Also used : SearchChunk(io.vertigo.dynamo.search.metamodel.SearchChunk) KeyConcept(io.vertigo.dynamo.domain.model.KeyConcept) ArrayList(java.util.ArrayList) URI(io.vertigo.dynamo.domain.model.URI)

Example 9 with KeyConcept

use of io.vertigo.dynamo.domain.model.KeyConcept in project vertigo by KleeGroup.

the class SearchManagerImpl method markAsDirty.

/**
 * {@inheritDoc}
 */
@Override
public void markAsDirty(final List<URI<? extends KeyConcept>> keyConceptUris) {
    Assertion.checkNotNull(keyConceptUris);
    Assertion.checkArgument(!keyConceptUris.isEmpty(), "dirty keyConceptUris cant be empty");
    // -----
    final DtDefinition keyConceptDefinition = keyConceptUris.get(0).getDefinition();
    final List<SearchIndexDefinition> searchIndexDefinitions = findIndexDefinitionByKeyConcept(keyConceptDefinition);
    Assertion.checkNotNull(!searchIndexDefinitions.isEmpty(), "No SearchIndexDefinition was defined for this keyConcept : {0}", keyConceptDefinition.getName());
    // -----
    for (final SearchIndexDefinition searchIndexDefinition : searchIndexDefinitions) {
        final List<URI<? extends KeyConcept>> dirtyElements = dirtyElementsPerIndexName.get(searchIndexDefinition.getName());
        synchronized (dirtyElements) {
            // TODO : doublons ?
            dirtyElements.addAll(keyConceptUris);
        }
    }
}
Also used : KeyConcept(io.vertigo.dynamo.domain.model.KeyConcept) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI)

Example 10 with KeyConcept

use of io.vertigo.dynamo.domain.model.KeyConcept in project vertigo by KleeGroup.

the class SearchManagerImpl method onEvent.

/**
 * Receive Store event.
 * @param storeEvent Store event
 */
@EventBusSubscribed
public void onEvent(final StoreEvent storeEvent) {
    final URI uri = storeEvent.getUri();
    // On ne traite l'event que si il porte sur un KeyConcept
    if (uri.getDefinition().getStereotype() == DtStereotype.KeyConcept && hasIndexDefinitionByKeyConcept(uri.getDefinition())) {
        final List<URI<? extends KeyConcept>> list = Collections.singletonList(uri);
        markAsDirty(list);
    }
}
Also used : KeyConcept(io.vertigo.dynamo.domain.model.KeyConcept) URI(io.vertigo.dynamo.domain.model.URI) EventBusSubscribed(io.vertigo.commons.eventbus.EventBusSubscribed)

Aggregations

KeyConcept (io.vertigo.dynamo.domain.model.KeyConcept)10 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)5 AuthorizationManager (io.vertigo.account.authorization.AuthorizationManager)4 UserAuthorizations (io.vertigo.account.authorization.UserAuthorizations)4 Authorization (io.vertigo.account.authorization.metamodel.Authorization)4 AuthorizationName (io.vertigo.account.authorization.metamodel.AuthorizationName)4 OperationName (io.vertigo.account.authorization.metamodel.OperationName)4 SecuredEntity (io.vertigo.account.authorization.metamodel.SecuredEntity)4 RuleMultiExpression (io.vertigo.account.authorization.metamodel.rulemodel.RuleMultiExpression)4 CriteriaSecurityRuleTranslator (io.vertigo.account.impl.authorization.dsl.translator.CriteriaSecurityRuleTranslator)4 SearchSecurityRuleTranslator (io.vertigo.account.impl.authorization.dsl.translator.SearchSecurityRuleTranslator)4 Home (io.vertigo.app.Home)4 DefinitionUtil (io.vertigo.core.definition.DefinitionUtil)4 Criteria (io.vertigo.dynamo.criteria.Criteria)4 Criterions (io.vertigo.dynamo.criteria.Criterions)4 URI (io.vertigo.dynamo.domain.model.URI)4 DtObjectUtil (io.vertigo.dynamo.domain.util.DtObjectUtil)4 Assertion (io.vertigo.lang.Assertion)4 UserSession (io.vertigo.persona.security.UserSession)4 VSecurityManager (io.vertigo.persona.security.VSecurityManager)4