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();
}
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);
}
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);
}
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);
}
}
}
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);
}
}
Aggregations