Search in sources :

Example 1 with AccountGroup

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);
}
Also used : URL(java.net.URL) URI(io.vertigo.dynamo.domain.model.URI) URISyntaxException(java.net.URISyntaxException) Scanner(java.util.Scanner) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) Matcher(java.util.regex.Matcher) WrappedException(io.vertigo.lang.WrappedException) Map(java.util.Map) Assertion(io.vertigo.lang.Assertion) Named(javax.inject.Named) AccountGroup(io.vertigo.account.account.AccountGroup) Files(java.nio.file.Files) Set(java.util.Set) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) VFile(io.vertigo.dynamo.file.model.VFile) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Consumer(java.util.function.Consumer) List(java.util.List) AccountStorePlugin(io.vertigo.account.impl.account.AccountStorePlugin) FSFile(io.vertigo.dynamo.impl.file.model.FSFile) Activeable(io.vertigo.core.component.Activeable) Account(io.vertigo.account.account.Account) Optional(java.util.Optional) ResourceManager(io.vertigo.core.resource.ResourceManager) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) Account(io.vertigo.account.account.Account) AccountGroup(io.vertigo.account.account.AccountGroup) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList)

Example 2 with AccountGroup

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);
}
Also used : AccountGroup(io.vertigo.account.account.AccountGroup) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI)

Example 3 with AccountGroup

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);
        }
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction) AccountGroup(io.vertigo.account.account.AccountGroup) IOException(java.io.IOException)

Example 4 with AccountGroup

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);
    }
}
Also used : Account(io.vertigo.account.account.Account) AccountGroup(io.vertigo.account.account.AccountGroup)

Example 5 with AccountGroup

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;
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) AccountGroup(io.vertigo.account.account.AccountGroup) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) URI(io.vertigo.dynamo.domain.model.URI) HashSet(java.util.HashSet)

Aggregations

AccountGroup (io.vertigo.account.account.AccountGroup)7 URI (io.vertigo.dynamo.domain.model.URI)5 Account (io.vertigo.account.account.Account)4 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)4 AccountStorePlugin (io.vertigo.account.impl.account.AccountStorePlugin)3 VFile (io.vertigo.dynamo.file.model.VFile)3 Assertion (io.vertigo.lang.Assertion)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Inject (javax.inject.Inject)3 Named (javax.inject.Named)3 AccountMapperHelper (io.vertigo.account.impl.account.AccountMapperHelper)2 AbstractAccountStorePlugin (io.vertigo.account.plugins.account.store.AbstractAccountStorePlugin)2 Home (io.vertigo.app.Home)2 Criteria (io.vertigo.dynamo.criteria.Criteria)2 Criterions (io.vertigo.dynamo.criteria.Criterions)2 DtField (io.vertigo.dynamo.domain.metamodel.DtField)2 AssociationDefinition (io.vertigo.dynamo.domain.metamodel.association.AssociationDefinition)2 AssociationNNDefinition (io.vertigo.dynamo.domain.metamodel.association.AssociationNNDefinition)2