Search in sources :

Example 6 with Multimap

use of com.google.common.collect.Multimap in project sonarqube by SonarSource.

the class ActiveRuleIndex method getStatsByProfileKeys.

public Map<String, Multimap<String, FacetValue>> getStatsByProfileKeys(List<String> keys) {
    SearchRequestBuilder request = getClient().prepareSearch(INDEX_TYPE_RULE.getIndex()).setQuery(QueryBuilders.boolQuery().must(QueryBuilders.termsQuery(FIELD_ACTIVE_RULE_PROFILE_KEY, keys)).filter(QueryBuilders.boolQuery().mustNot(QueryBuilders.hasParentQuery(INDEX_TYPE_RULE.getType(), QueryBuilders.termQuery(FIELD_RULE_STATUS, RuleStatus.REMOVED.name()))))).addAggregation(AggregationBuilders.terms(FIELD_ACTIVE_RULE_PROFILE_KEY).field(RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_KEY).size(0).subAggregation(AggregationBuilders.terms(FIELD_ACTIVE_RULE_INHERITANCE).field(RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE)).subAggregation(AggregationBuilders.terms(FIELD_ACTIVE_RULE_SEVERITY).field(RuleIndexDefinition.FIELD_ACTIVE_RULE_SEVERITY)).subAggregation(AggregationBuilders.count(COUNT_ACTIVE_RULES))).setSize(0);
    SearchResponse response = request.get();
    Map<String, Multimap<String, FacetValue>> stats = new HashMap<>();
    Aggregation aggregation = response.getAggregations().get(FIELD_ACTIVE_RULE_PROFILE_KEY);
    for (Terms.Bucket value : ((Terms) aggregation).getBuckets()) {
        stats.put(value.getKeyAsString(), processAggregations(value.getAggregations()));
    }
    return stats;
}
Also used : Aggregation(org.elasticsearch.search.aggregations.Aggregation) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Multimap(com.google.common.collect.Multimap) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) HashMap(java.util.HashMap) StringTerms(org.elasticsearch.search.aggregations.bucket.terms.StringTerms) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 7 with Multimap

use of com.google.common.collect.Multimap in project sonarqube by SonarSource.

the class ActiveRuleIndexTest method stats_for_all.

@Test
public void stats_for_all() {
    indexRules(newDoc(RULE_KEY_1), newDoc(RULE_KEY_2));
    ActiveRuleKey activeRuleKey1 = ActiveRuleKey.of(QUALITY_PROFILE_KEY1, RULE_KEY_1);
    ActiveRuleKey activeRuleKey2 = ActiveRuleKey.of(QUALITY_PROFILE_KEY1, RULE_KEY_2);
    indexActiveRules(ActiveRuleDocTesting.newDoc(activeRuleKey1).setSeverity(BLOCKER), ActiveRuleDocTesting.newDoc(activeRuleKey2).setSeverity(MINOR), // Profile 2 is a child a profile 1
    ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_1)).setSeverity(MAJOR).setInheritance(INHERITED.name()), ActiveRuleDocTesting.newDoc(ActiveRuleKey.of(QUALITY_PROFILE_KEY2, RULE_KEY_2)).setSeverity(BLOCKER).setInheritance(OVERRIDES.name()));
    // 0. Test base case
    assertThat(tester.countDocuments(INDEX_TYPE_ACTIVE_RULE)).isEqualTo(4);
    // 1. Assert by term aggregation;
    Map<String, Multimap<String, FacetValue>> stats = index.getStatsByProfileKeys(ImmutableList.of(QUALITY_PROFILE_KEY1, QUALITY_PROFILE_KEY2));
    assertThat(stats).hasSize(2);
}
Also used : Multimap(com.google.common.collect.Multimap) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) Test(org.junit.Test)

Example 8 with Multimap

use of com.google.common.collect.Multimap in project sonarqube by SonarSource.

the class UserUpdaterTest method not_associate_default_group_when_updating_user_if_already_existing.

@Test
public void not_associate_default_group_when_updating_user_if_already_existing() {
    UserDto user = db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@email.com"));
    GroupDto defaultGroup = createDefaultGroup();
    db.users().insertMember(defaultGroup, user);
    // User is already associate to the default group
    Multimap<String, String> groups = dbClient.groupMembershipDao().selectGroupsByLogins(session, asList(DEFAULT_LOGIN));
    assertThat(groups.get(DEFAULT_LOGIN).stream().anyMatch(g -> g.equals(DEFAULT_GROUP))).as("Current user groups : %s", groups.get(DEFAULT_GROUP)).isTrue();
    underTest.update(session, UpdateUser.create(DEFAULT_LOGIN).setName("Marius2").setEmail("marius2@mail.com").setPassword("password2").setScmAccounts(newArrayList("ma2")));
    session.commit();
    // Nothing as changed
    groups = dbClient.groupMembershipDao().selectGroupsByLogins(session, asList(DEFAULT_LOGIN));
    assertThat(groups.get(DEFAULT_LOGIN).stream().anyMatch(g -> g.equals(DEFAULT_GROUP))).isTrue();
}
Also used : UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServerException(org.sonar.server.exceptions.ServerException) Multimap(com.google.common.collect.Multimap) TestDefaultOrganizationProvider(org.sonar.server.organization.TestDefaultOrganizationProvider) DbSession(org.sonar.db.DbSession) BadRequestException(org.sonar.server.exceptions.BadRequestException) Collections.singletonList(java.util.Collections.singletonList) Strings(com.google.common.base.Strings) ArgumentCaptor(org.mockito.ArgumentCaptor) OrganizationCreation(org.sonar.server.organization.OrganizationCreation) UserTesting.newDisabledUser(org.sonar.db.user.UserTesting.newDisabledUser) ImmutableList(com.google.common.collect.ImmutableList) Arrays.asList(java.util.Arrays.asList) GroupTesting(org.sonar.db.user.GroupTesting) Assert.fail(org.junit.Assert.fail) NewUserHandler(org.sonar.api.platform.NewUserHandler) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) SearchHit(org.elasticsearch.search.SearchHit) GroupDto(org.sonar.db.user.GroupDto) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) UserIndexDefinition(org.sonar.server.user.index.UserIndexDefinition) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) UserTesting.newLocalUser(org.sonar.db.user.UserTesting.newLocalUser) Mockito.verify(org.mockito.Mockito.verify) UserIndexer(org.sonar.server.user.index.UserIndexer) DbClient(org.sonar.db.DbClient) List(java.util.List) Rule(org.junit.Rule) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) SQ_AUTHORITY(org.sonar.server.user.ExternalIdentity.SQ_AUTHORITY) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) UserTesting(org.sonar.db.user.UserTesting) MapEntry.entry(org.assertj.core.data.MapEntry.entry) CORE_DEFAULT_GROUP(org.sonar.api.CoreProperties.CORE_DEFAULT_GROUP) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 9 with Multimap

use of com.google.common.collect.Multimap in project atlas by alibaba.

the class NativeSoUtils method getAbiSoFiles.

/**
     * 校验指定abi下的so文件的目录
     *
     * @param supportAbis
     * @param removeSoFiles
     * @param dirs
     * @return
     */
public static Map<String, Multimap<String, File>> getAbiSoFiles(Set<String> supportAbis, Set<String> removeSoFiles, List<File> dirs) {
    Map<String, Multimap<String, File>> result = new HashMap<String, Multimap<String, File>>();
    IOFileFilter filter = new NativeSoFilter(supportAbis, removeSoFiles);
    for (File dir : dirs) {
        Collection<File> files = FileUtils.listFiles(dir, filter, TrueFileFilter.TRUE);
        for (File file : files) {
            File parentFolder = file.getParentFile();
            String parentName = parentFolder.getName();
            String shortName = getSoShortName(file);
            Multimap<String, File> maps = result.get(parentName);
            if (null == maps) {
                maps = HashMultimap.create(10, 3);
            }
            maps.put(shortName, file);
            result.put(parentName, maps);
        }
    }
    return result;
}
Also used : HashMultimap(com.google.common.collect.HashMultimap) Multimap(com.google.common.collect.Multimap) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) File(java.io.File)

Example 10 with Multimap

use of com.google.common.collect.Multimap in project Minechem by iopleke.

the class AugmentSharp method getAttributeModifiers.

@Override
public Multimap<String, AttributeModifier> getAttributeModifiers(ItemStack stack, int level) {
    Multimap multimap = super.getAttributeModifiers(stack, level);
    multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(AugmentedItem.itemUUID, "Weapon modifier", (double) level, 0));
    return multimap;
}
Also used : Multimap(com.google.common.collect.Multimap) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier)

Aggregations

Multimap (com.google.common.collect.Multimap)47 HashMultimap (com.google.common.collect.HashMultimap)16 Test (org.junit.Test)15 List (java.util.List)13 InetAddress (java.net.InetAddress)11 Map (java.util.Map)9 IOException (java.io.IOException)8 ImmutableList (com.google.common.collect.ImmutableList)7 Collection (java.util.Collection)7 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)6 ArrayList (java.util.ArrayList)6 Set (java.util.Set)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 LinkedListMultimap (com.google.common.collect.LinkedListMultimap)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Collectors (java.util.stream.Collectors)5 Token (org.apache.cassandra.dht.Token)4 HashMap (java.util.HashMap)3