/** * Creates a type that requires to verify that user has the read permission * when searching for documents. * * Both types {@code typeName} and "authorization" are created. Documents * must be created with _parent and _routing having the parent uuid as values. * * @see NewIndex.NewIndexType#requireProjectAuthorization() */ private static NewIndex.NewIndexType enableProjectAuthorization(NewIndex.NewIndexType type) { type.setAttribute("_parent", ImmutableMap.of("type", TYPE_AUTHORIZATION)); type.setAttribute("_routing", ImmutableMap.of("required", true)); NewIndex.NewIndexType authType = type.getIndex().createType(TYPE_AUTHORIZATION); authType.setAttribute("_routing", ImmutableMap.of("required", true)); authType.createLongField(FIELD_GROUP_IDS); authType.createLongField(FIELD_USER_IDS); authType.createBooleanField(FIELD_ALLOW_ANYONE); authType.setEnableSource(false); return type; }
@Test public void define_fields() { NewIndex index = new NewIndex("issues", defaultSettingsConfiguration); NewIndex.NewIndexType mapping = index.createType("issue"); mapping.setAttribute("dynamic", "true"); mapping.setProperty("foo_field", ImmutableMap.of("type", "keyword")); mapping.createBooleanField("boolean_field"); mapping.createByteField("byte_field"); mapping.createDateTimeField("dt_field"); mapping.createDoubleField("double_field"); mapping.createIntegerField("int_field"); mapping.createLongField("long_field"); mapping.createShortField("short_field"); mapping.createUuidPathField("uuid_path_field"); mapping = index.getTypes().get("issue"); assertThat(mapping).isNotNull(); assertThat(mapping.getAttributes().get("dynamic")).isEqualTo("true"); assertThat(mapping.getProperty("foo_field")).isInstanceOf(Map.class); assertThat((Map) mapping.getProperty("foo_field")).containsEntry("type", "keyword"); assertThat((Map) mapping.getProperty("byte_field")).isNotEmpty(); assertThat((Map) mapping.getProperty("double_field")).isNotEmpty(); assertThat((Map) mapping.getProperty("dt_field")).isNotEmpty(); assertThat((Map) mapping.getProperty("int_field")).containsEntry("type", "integer"); assertThat((Map) mapping.getProperty("long_field")).isNotEmpty(); assertThat((Map) mapping.getProperty("short_field")).isNotEmpty(); assertThat((Map) mapping.getProperty("uuid_path_field")).isNotEmpty(); assertThat((Map) mapping.getProperty("unknown")).isNull(); }
@Override public void define(IndexDefinitionContext context) { NewIndex index = context.create( INDEX_TYPE_TEST.getIndex(), newBuilder(config) .setRefreshInterval(MANUAL_REFRESH_INTERVAL) .setDefaultNbOfShards(5) .build()); NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_TEST.getType()); mapping.setAttribute("_routing", ImmutableMap.of("required", true)); mapping.keywordFieldBuilder(FIELD_PROJECT_UUID).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_FILE_UUID).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_TEST_UUID).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_NAME).disableNorms().disableSearch().disableSortingAndAggregating().build(); mapping.keywordFieldBuilder(FIELD_STATUS).disableNorms().disableSearch().build(); mapping.createLongField(FIELD_DURATION_IN_MS); mapping.keywordFieldBuilder(FIELD_MESSAGE).disableNorms().disableSearch().disableSortingAndAggregating().build(); mapping.keywordFieldBuilder(FIELD_STACKTRACE).disableNorms().disableSearch().disableSortingAndAggregating().build(); mapping.setProperty(FIELD_COVERED_FILES, ImmutableMap.of("type", "nested", "properties", ImmutableMap.of( FIELD_COVERED_FILE_UUID, ImmutableMap.of("type", FIELD_TYPE_KEYWORD, "index", INDEX_SEARCHABLE), FIELD_COVERED_FILE_LINES, ImmutableMap.of("type", "integer")))); mapping.createDateTimeField(FIELD_UPDATED_AT); } }
activeRuleMapping.setAttribute("_parent", ImmutableMap.of("type", INDEX_TYPE_RULE.getType())); ruleExtensionType.setAttribute("_parent", ImmutableMap.of("type", INDEX_TYPE_RULE.getType()));
@Override public void define(IndexDefinitionContext context) { NewIndex index = context.create( INDEX_TYPE_TEST.getIndex(), newBuilder(config) .setRefreshInterval(MANUAL_REFRESH_INTERVAL) .setDefaultNbOfShards(5) .build()); NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_TEST.getType()); mapping.setAttribute("_routing", ImmutableMap.of("required", true)); mapping.keywordFieldBuilder(FIELD_PROJECT_UUID).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_FILE_UUID).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_TEST_UUID).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_NAME).disableNorms().disableSearch().disableSortingAndAggregating().build(); mapping.keywordFieldBuilder(FIELD_STATUS).disableNorms().disableSearch().build(); mapping.createLongField(FIELD_DURATION_IN_MS); mapping.keywordFieldBuilder(FIELD_MESSAGE).disableNorms().disableSearch().disableSortingAndAggregating().build(); mapping.keywordFieldBuilder(FIELD_STACKTRACE).disableNorms().disableSearch().disableSortingAndAggregating().build(); mapping.setProperty(FIELD_COVERED_FILES, ImmutableMap.of("type", "nested", "properties", ImmutableMap.of( FIELD_COVERED_FILE_UUID, ImmutableMap.of("type", FIELD_TYPE_KEYWORD, "index", INDEX_SEARCHABLE), FIELD_COVERED_FILE_LINES, ImmutableMap.of("type", "integer")))); mapping.createDateTimeField(FIELD_UPDATED_AT); } }
/** * Creates a type that requires to verify that user has the read permission * when searching for documents. * It relies on a parent type named "authorization" that is automatically * populated by {@link org.sonar.server.permission.index.PermissionIndexer}. * * Both types {@code typeName} and "authorization" are created. Documents * must be created with _parent and _routing having the parent uuid as values. * * @see NewIndex.NewIndexType#requireProjectAuthorization() */ public static NewIndex.NewIndexType enableProjectAuthorization(NewIndex.NewIndexType type) { type.setAttribute("_parent", ImmutableMap.of("type", TYPE_AUTHORIZATION)); type.setAttribute("_routing", ImmutableMap.of("required", true)); NewIndex.NewIndexType authType = type.getIndex().createType(TYPE_AUTHORIZATION); authType.setAttribute("_routing", ImmutableMap.of("required", true)); authType.createLongField(FIELD_GROUP_IDS); authType.createLongField(FIELD_USER_IDS); authType.createBooleanField(FIELD_ALLOW_ANYONE); authType.setEnableSource(false); return type; }
activeRuleMapping.setAttribute("_parent", ImmutableMap.of("type", INDEX_TYPE_RULE.getType())); ruleExtensionType.setAttribute("_parent", ImmutableMap.of("type", INDEX_TYPE_RULE.getType()));
private NewIndex createIndex() { NewIndex newIndex = new NewIndex("fakes", newBuilder(new MapSettings().asConfig()).build()); NewIndex.NewIndexType mapping = newIndex.createType("fake"); mapping.setAttribute("list_attr", Arrays.asList("foo", "bar")); mapping.keywordFieldBuilder("key").build(); mapping.createDateTimeField("updatedAt"); return newIndex; }