Skip to content

Commit

Permalink
Eliminating code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
luk-kaminski committed Jul 17, 2024
1 parent 1007a47 commit a9421f1
Showing 1 changed file with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import javax.annotation.Nullable;
import java.time.ZonedDateTime;
import java.util.Optional;
import java.util.Set;

import static com.google.common.base.Strings.isNullOrEmpty;
import static org.graylog2.indexer.EventIndexTemplateProvider.EVENT_TEMPLATE_TYPE;
Expand All @@ -61,6 +62,12 @@ public abstract class IndexSetConfig implements Comparable<IndexSetConfig>, Simp
public static final String FIELD_INDEX_TEMPLATE_NAME = "index_template_name";
public static final String FIELD_CUSTOM_FIELD_MAPPINGS = "custom_field_mappings";

private static final Set<String> TEMPLATE_TYPES_FOR_INDEX_SETS_WITH_IMMUTABLE_FIELD_TYPES = Set.of(
EVENT_TEMPLATE_TYPE,
IndexTemplateProvider.FAILURE_TEMPLATE_TYPE,
IndexTemplateProvider.ILLUMINATE_INDEX_TEMPLATE_TYPE
);

@JsonCreator
public static IndexSetConfig create(@Id @ObjectId @JsonProperty("_id") @Nullable String id,
@JsonProperty(FIELD_TITLE) @NotBlank String title,
Expand Down Expand Up @@ -255,26 +262,12 @@ public boolean isRegularIndex() {

@JsonIgnore
public boolean canHaveCustomFieldMappings() {
final String indexTemplateType = this.indexTemplateType().orElse(null);
if (EVENT_TEMPLATE_TYPE.equals(indexTemplateType) ||
IndexTemplateProvider.FAILURE_TEMPLATE_TYPE.equals(indexTemplateType) ||
IndexTemplateProvider.ILLUMINATE_INDEX_TEMPLATE_TYPE.equals(indexTemplateType)

) {
return false;
}
return true;
return !this.indexTemplateType().map(TEMPLATE_TYPES_FOR_INDEX_SETS_WITH_IMMUTABLE_FIELD_TYPES::contains).orElse(false);
}

@JsonIgnore
public boolean canHaveProfile() {
final String indexTemplateType = this.indexTemplateType().orElse(null);
if (EVENT_TEMPLATE_TYPE.equals(indexTemplateType) ||
IndexTemplateProvider.FAILURE_TEMPLATE_TYPE.equals(indexTemplateType) ||
IndexTemplateProvider.ILLUMINATE_INDEX_TEMPLATE_TYPE.equals(indexTemplateType)) {
return false;
}
return true;
return !this.indexTemplateType().map(TEMPLATE_TYPES_FOR_INDEX_SETS_WITH_IMMUTABLE_FIELD_TYPES::contains).orElse(false);
}

@Override
Expand Down

0 comments on commit a9421f1

Please sign in to comment.