org.graylog2.indexer.indexset.CustomFieldMappings Maven / Gradle / Ivy
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* .
*/
package org.graylog2.indexer.indexset;
import com.google.common.collect.ImmutableMap;
import org.graylog2.indexer.fieldtypes.FieldTypeMapper;
import org.graylog2.indexer.fieldtypes.FieldTypes;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
public class CustomFieldMappings extends HashSet {
public record TypeDescription(String description, FieldTypes.Type type) {}
public static final Map AVAILABLE_TYPES = ImmutableMap.builder()
.put("string", new TypeDescription("String (aggregatable)", FieldTypeMapper.STRING_TYPE))
.put("string_fts", new TypeDescription("String (full-text searchable)", FieldTypeMapper.STRING_FTS_TYPE))
.put("long", new TypeDescription("Number", FieldTypeMapper.LONG_TYPE))
.put("double", new TypeDescription("Number (Floating Point)", FieldTypeMapper.DOUBLE_TYPE))
.put("date", new TypeDescription("Date", FieldTypeMapper.DATE_TYPE))
.put("boolean", new TypeDescription("Boolean", FieldTypeMapper.BOOLEAN_TYPE))
.put("binary", new TypeDescription("Binary Data", FieldTypeMapper.BINARY_TYPE))
.put("geo-point", new TypeDescription("Geo Point", FieldTypeMapper.GEO_POINT_TYPE))
.put("ip", new TypeDescription("IP", FieldTypeMapper.IP_TYPE))
.build();
public static final Map REVERSE_TYPES = AVAILABLE_TYPES.entrySet()
.stream()
.collect(Collectors.toMap(entry -> entry.getValue().type, Map.Entry::getKey));
public CustomFieldMappings() {
super();
}
public CustomFieldMappings(final Collection mappings) {
super(mappings);
}
public CustomFieldMappings mergeWith(final CustomFieldMapping changedMapping) {
final Set modifiedMappings = new HashSet<>(this);
modifiedMappings.removeIf(m -> changedMapping.fieldName().equals(m.fieldName()));
modifiedMappings.add(changedMapping);
return new CustomFieldMappings(modifiedMappings);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy