use of io.vertigo.account.account.AccountGroup in project vertigo by KleeGroup.
the class TextAccountStorePlugin method parseGroups.
private void parseGroups(final String line) {
final Matcher matcher = groupFilePattern.matcher(line);
final boolean matches = matcher.matches();
Assertion.checkState(matches, "GroupFile ({2}) can't be parse by this regexp :\nline:{0}\nregexp:{1}", line, matches, groupFilePath);
final String groupId = matcher.group(GroupProperty.id.name());
final String displayName = matcher.group(GroupProperty.displayName.name());
final String accountIds = matcher.group(GroupProperty.accountIds.name());
final AccountGroup accountGroup = new AccountGroup(groupId, displayName);
groups.put(groupId, accountGroup);
final List<Account> groupAccounts = new ArrayList<>();
for (final String accountId : accountIds.split(";")) {
groupsPerAccount.computeIfAbsent(accountId, k -> new ArrayList<>()).add(accountGroup);
final Account account = accounts.get(accountId).getAccount();
Assertion.checkNotNull(account, "Group {0} reference an undeclared account {1}", groupId, accountId);
groupAccounts.add(account);
}
accountsPerGroup.put(groupId, groupAccounts);
}
use of io.vertigo.account.account.AccountGroup in project vertigo by KleeGroup.
the class MemoryAccountCachePlugin method putGroup.
/**
* {@inheritDoc}
*/
@Override
public synchronized void putGroup(final AccountGroup group) {
Assertion.checkNotNull(group);
// -----
final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(group);
final URI<AccountGroup> uri = new URI<>(dtDefinition, group.getId());
// ----
Assertion.checkArgument(!groupByURI.containsKey(uri), "this group is already registered, you can't create it");
// -----
accountByGroupURI.put(uri, new HashSet<URI<Account>>());
groupByURI.put(uri, group);
}
use of io.vertigo.account.account.AccountGroup in project vertigo by KleeGroup.
the class RedisAccountCachePlugin method attach.
/**
* {@inheritDoc}
*/
@Override
public void attach(final URI<Account> accountURI, final Set<URI<AccountGroup>> groupURIs) {
Assertion.checkNotNull(accountURI);
Assertion.checkNotNull(groupURIs);
// -----
try (final Jedis jedis = redisConnector.getResource()) {
try (final Transaction tx = jedis.multi()) {
for (final URI<AccountGroup> groupURI : groupURIs) {
tx.sadd(SACCOUNTS_BY_GROUP_START_KEY + groupURI.getId(), accountURI.getId().toString());
tx.sadd(SGROUPS_BY_ACCOUNT_START_KEY + accountURI.getId(), groupURI.getId().toString());
}
tx.exec();
} catch (final IOException ex) {
throw WrappedException.wrap(ex);
}
}
}
use of io.vertigo.account.account.AccountGroup in project vertigo by KleeGroup.
the class TestIdentities method initData.
public void initData() {
final Account testAccount0 = Account.builder("0").withAuthToken("john.doe").withDisplayName("John doe").withEmail("john.doe@yopmail.com").build();
final Account testAccount1 = Account.builder("1").withAuthToken("palmer.luckey").withDisplayName("Palmer Luckey").withEmail("palmer.luckey@yopmail.com").build();
final Account testAccount2 = Account.builder("2").withAuthToken("bill.clinton").withDisplayName("Bill Clinton").withEmail("bill.clinton@yopmail.com").build();
final Account testAccount3 = Account.builder("3").withAuthToken("admin").withDisplayName("Phil Mormon").withEmail("phil.mormon@yopmail.com").build();
saveAccounts(Arrays.asList(testAccount0, testAccount1, testAccount2, testAccount3));
final URI<Account> accountURI0 = createAccountURI(testAccount0.getId());
final URI<Account> accountURI1 = createAccountURI(testAccount1.getId());
final URI<Account> accountURI2 = createAccountURI(testAccount2.getId());
final AccountGroup testAccountGroup1 = new AccountGroup("100", "TIME's cover");
final URI<AccountGroup> group1Uri = DtObjectUtil.createURI(AccountGroup.class, testAccountGroup1.getId());
saveGroup(testAccountGroup1);
attach(accountURI1, group1Uri);
attach(accountURI2, group1Uri);
final AccountGroup groupAll = new AccountGroup("ALL", "Everyone");
final URI<AccountGroup> groupAllUri = DtObjectUtil.createURI(AccountGroup.class, groupAll.getId());
saveGroup(groupAll);
attach(accountURI0, groupAllUri);
attach(accountURI1, groupAllUri);
attach(accountURI2, groupAllUri);
// ---create 10 noisy data
final List<Account> accounts = createAccounts();
saveAccounts(accounts);
for (final Account account : accounts) {
final URI<Account> accountUri = createAccountURI(account.getId());
attach(accountUri, groupAllUri);
}
}
use of io.vertigo.account.account.AccountGroup in project vertigo by KleeGroup.
the class RedisAccountCachePlugin method getGroupURIs.
/**
* {@inheritDoc}
*/
@Override
public Set<URI<AccountGroup>> getGroupURIs(final URI<Account> accountURI) {
Assertion.checkNotNull(accountURI);
// -----
final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(AccountGroup.class);
final Set<URI<AccountGroup>> set = new HashSet<>();
try (final Jedis jedis = redisConnector.getResource()) {
final Set<String> ids = jedis.smembers(SGROUPS_BY_ACCOUNT_START_KEY + accountURI.getId());
for (final String id : ids) {
set.add(new URI<AccountGroup>(dtDefinition, id));
}
return set;
}
}
Aggregations