Skip to content

Commit

Permalink
Merge pull request geotools#63 from ngageoint/layer-refresh
Browse files Browse the repository at this point in the history
Always re-read layer attributes
  • Loading branch information
sjudeng committed Feb 11, 2018
2 parents ffca3f7 + 949f70f commit c243211
Showing 1 changed file with 40 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,57 +143,51 @@ public ContentFeatureSource getFeatureSource(Name name, Transaction tx)
}

public List<ElasticAttribute> getElasticAttributes(Name layerName) throws IOException {
final String localPart = layerName.getLocalPart();
final ElasticLayerConfiguration layerConfig = layerConfigurations.get(localPart);
final List<ElasticAttribute> elasticAttributes;
if (layerConfig == null || layerConfig.getAttributes().isEmpty()) {
final String docType;
if (docTypes.containsKey(layerName)) {
docType = docTypes.get(layerName);
} else {
docType = localPart;
}
final String docType;
if (docTypes.containsKey(layerName)) {
docType = docTypes.get(layerName);
} else {
docType = layerName.getLocalPart();
}

final Map<String,Object> mapping = getClient().getMapping(indexName, docType);
elasticAttributes = new ArrayList<ElasticAttribute>();
if (mapping != null) {
add(elasticAttributes, "_id", "string", mapping, false);
add(elasticAttributes, "_index", "string", mapping, false);
add(elasticAttributes, "_type", "string", mapping, false);
add(elasticAttributes, "_score", "float", mapping, false);
add(elasticAttributes, "_relative_score", "float", mapping, false);
add(elasticAttributes, "_aggregation", "binary", mapping, false);

walk(elasticAttributes, mapping, "", false, false);

// add default geometry and short name and count duplicate short names
final Map<String,Integer> counts = new HashMap<>();
boolean foundGeometry = false;
for (final ElasticAttribute attribute : elasticAttributes) {
if (!foundGeometry && Geometry.class.isAssignableFrom(attribute.getType())) {
attribute.setDefaultGeometry(true);
foundGeometry = true;
}
final String[] parts = attribute.getName().split("\\.");
attribute.setShortName(parts[parts.length-1]);
final int count;
if (counts.containsKey(attribute.getShortName())) {
count = counts.get(attribute.getShortName())+1;
} else {
count = 1;
}
counts.put(attribute.getShortName(), count);
final Map<String,Object> mapping = getClient().getMapping(indexName, docType);
final List<ElasticAttribute> elasticAttributes = new ArrayList<ElasticAttribute>();
if (mapping != null) {
add(elasticAttributes, "_id", "string", mapping, false);
add(elasticAttributes, "_index", "string", mapping, false);
add(elasticAttributes, "_type", "string", mapping, false);
add(elasticAttributes, "_score", "float", mapping, false);
add(elasticAttributes, "_relative_score", "float", mapping, false);
add(elasticAttributes, "_aggregation", "binary", mapping, false);

walk(elasticAttributes, mapping, "", false, false);

// add default geometry and short name and count duplicate short names
final Map<String,Integer> counts = new HashMap<>();
boolean foundGeometry = false;
for (final ElasticAttribute attribute : elasticAttributes) {
if (!foundGeometry && Geometry.class.isAssignableFrom(attribute.getType())) {
attribute.setDefaultGeometry(true);
foundGeometry = true;
}
// use full name if short name has duplicates
for (final ElasticAttribute attribute : elasticAttributes) {
if (counts.get(attribute.getShortName()) > 1) {
attribute.setShortName(attribute.getName());
}
final String[] parts = attribute.getName().split("\\.");
attribute.setShortName(parts[parts.length-1]);
final int count;
if (counts.containsKey(attribute.getShortName())) {
count = counts.get(attribute.getShortName())+1;
} else {
count = 1;
}
counts.put(attribute.getShortName(), count);
}
// use full name if short name has duplicates
for (final ElasticAttribute attribute : elasticAttributes) {
if (counts.get(attribute.getShortName()) > 1) {
attribute.setShortName(attribute.getName());
}
}
} else {
elasticAttributes = layerConfig.getAttributes();
}

return elasticAttributes;
}

Expand Down

0 comments on commit c243211

Please sign in to comment.