/** * 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(); }
ruleMapping.keywordFieldBuilder(FIELD_RULE_LANGUAGE).disableNorms().build(); ruleMapping.createBooleanField(FIELD_RULE_IS_TEMPLATE); ruleMapping.createBooleanField(FIELD_RULE_IS_EXTERNAL); ruleMapping.keywordFieldBuilder(FIELD_RULE_TEMPLATE_KEY).disableNorms().build();
ruleMapping.keywordFieldBuilder(FIELD_RULE_LANGUAGE).disableNorms().build(); ruleMapping.createBooleanField(FIELD_RULE_IS_TEMPLATE); ruleMapping.createBooleanField(FIELD_RULE_IS_EXTERNAL); ruleMapping.keywordFieldBuilder(FIELD_RULE_TEMPLATE_KEY).disableNorms().build();
type.keywordFieldBuilder(FIELD_ISSUE_PROJECT_UUID).disableNorms().addSubFields(SORTABLE_ANALYZER).build(); type.keywordFieldBuilder(FIELD_ISSUE_BRANCH_UUID).disableNorms().build(); type.createBooleanField(FIELD_ISSUE_IS_MAIN_BRANCH); type.keywordFieldBuilder(FIELD_ISSUE_DIRECTORY_PATH).disableNorms().build(); type.keywordFieldBuilder(FIELD_ISSUE_RESOLUTION).disableNorms().build();
/** * 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; }
@Override public void define(IndexDefinitionContext context) { NewIndex index = context.create(INDEX_TYPE_USER.getIndex(), newBuilder(config) .setDefaultNbOfShards(1) .build()); // type "user" NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_USER.getType()); mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_LOGIN).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build(); mapping.keywordFieldBuilder(FIELD_NAME).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build(); mapping.keywordFieldBuilder(FIELD_EMAIL).addSubFields(USER_SEARCH_GRAMS_ANALYZER, SORTABLE_ANALYZER).build(); mapping.createBooleanField(FIELD_ACTIVE); mapping.keywordFieldBuilder(FIELD_SCM_ACCOUNTS).disableNorms().addSubFields(SORTABLE_ANALYZER).build(); mapping.keywordFieldBuilder(FIELD_ORGANIZATION_UUIDS).disableNorms().build(); } }
type.keywordFieldBuilder(FIELD_ISSUE_PROJECT_UUID).disableNorms().addSubFields(SORTABLE_ANALYZER).build(); type.keywordFieldBuilder(FIELD_ISSUE_BRANCH_UUID).disableNorms().build(); type.createBooleanField(FIELD_ISSUE_IS_MAIN_BRANCH); type.keywordFieldBuilder(FIELD_ISSUE_DIRECTORY_PATH).disableNorms().build(); type.keywordFieldBuilder(FIELD_ISSUE_RESOLUTION).disableNorms().build();
@Override public void define(IndexDefinitionContext context) { NewIndex index = context.create(INDEX_TYPE_USER.getIndex(), newBuilder(config) .setDefaultNbOfShards(1) .build()); // type "user" NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_USER.getType()); mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build(); mapping.keywordFieldBuilder(FIELD_LOGIN).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build(); mapping.keywordFieldBuilder(FIELD_NAME).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build(); mapping.keywordFieldBuilder(FIELD_EMAIL).addSubFields(USER_SEARCH_GRAMS_ANALYZER, SORTABLE_ANALYZER).build(); mapping.createBooleanField(FIELD_ACTIVE); mapping.keywordFieldBuilder(FIELD_SCM_ACCOUNTS).disableNorms().addSubFields(SORTABLE_ANALYZER).build(); mapping.keywordFieldBuilder(FIELD_ORGANIZATION_UUIDS).disableNorms().build(); } }