Skip to content

Commit

Permalink
Only add missing attributes and set use=false when new attributes are…
Browse files Browse the repository at this point in the history
… discovered
  • Loading branch information
sjudeng committed Feb 11, 2018
1 parent c243211 commit 214ff09
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.logging.Logger;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -143,11 +144,12 @@ public ContentFeatureSource getFeatureSource(Name name, Transaction tx)
}

public List<ElasticAttribute> getElasticAttributes(Name layerName) throws IOException {
final String localPart = layerName.getLocalPart();
final String docType;
if (docTypes.containsKey(layerName)) {
docType = docTypes.get(layerName);
} else {
docType = layerName.getLocalPart();
docType = localPart;
}

final Map<String,Object> mapping = getClient().getMapping(indexName, docType);
Expand Down Expand Up @@ -188,6 +190,21 @@ public List<ElasticAttribute> getElasticAttributes(Name layerName) throws IOExce
}
}

final ElasticLayerConfiguration layerConfig = layerConfigurations.get(localPart);
if (layerConfig != null && !layerConfig.getAttributes().isEmpty()) {
final Map<String, ElasticAttribute> names = layerConfig.getAttributes().stream()
.collect(Collectors.toMap(ElasticAttribute::getName, Function.identity()));

for (final ElasticAttribute attribute : elasticAttributes) {
if (!names.containsKey(attribute.getName())) {
attribute.setUse(false);
layerConfig.getAttributes().add(attribute);
}
}

return layerConfig.getAttributes();
}

return elasticAttributes;
}

Expand Down

0 comments on commit 214ff09

Please sign in to comment.