use of io.vertigo.dynamo.domain.model.DtListURI 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());
}
use of io.vertigo.dynamo.domain.model.DtListURI 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());
}
use of io.vertigo.dynamo.domain.model.DtListURI in project vertigo by KleeGroup.
the class LuceneIndexPlugin method indexList.
private <D extends DtObject> RamLuceneIndex<D> indexList(final DtList<D> fullDtc, final boolean storeValue) throws IOException {
// TODO : gestion du cache a revoir... et le lien avec le CacheStore.
// L'index devrait être interrogé par le Broker ? on pourrait alors mettre en cache dans le DataCache.
final DtListURI dtcUri = fullDtc.getURI();
// no cache if no URI
final boolean useCache = dtcUri != null;
RamLuceneIndex<D> index;
if (useCache) {
final String indexName = "INDEX_" + dtcUri.urn();
final String cacheContext = getIndexCacheContext(fullDtc.getDefinition());
// TODO non threadSafe.
Map<String, RamLuceneIndex> luceneIndexMap = Map.class.cast(cacheManager.get(CACHE_LUCENE_INDEX, cacheContext));
if (luceneIndexMap == null) {
luceneIndexMap = new HashMap<>();
}
if (!luceneIndexMap.containsKey(indexName)) {
index = createIndex(fullDtc, storeValue);
luceneIndexMap.put(indexName, index);
cacheManager.put(CACHE_LUCENE_INDEX, cacheContext, luceneIndexMap);
return index;
}
return luceneIndexMap.get(indexName);
}
return createIndex(fullDtc, storeValue);
}
use of io.vertigo.dynamo.domain.model.DtListURI in project vertigo by KleeGroup.
the class CacheDataStore method loadNullable.
private synchronized <E extends Entity> E loadNullable(final DtDefinition dtDefinition, final URI<E> uri) {
final E entity;
if (cacheDataStoreConfig.isReloadedByList(dtDefinition)) {
// On ne charge pas les cache de façon atomique.
final DtListURI dtcURIAll = new DtListURIForCriteria<>(dtDefinition, null, null);
// on charge la liste complete (et on remplit les caches)
loadList(dtcURIAll);
entity = cacheDataStoreConfig.getDataCache().getDtObject(uri);
} else {
// On charge le cache de façon atomique à partir du dataStore
entity = getPhysicalStore(dtDefinition).readNullable(dtDefinition, uri);
if (entity != null) {
cacheDataStoreConfig.getDataCache().putDtObject(entity);
}
}
return entity;
}
Aggregations