Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.n52.youngs.transform.impl.MappingEntryImpl Maven / Gradle / Ivy
Go to download
A mapping platform to load CSW records into Elasticsearch
/*
* Copyright 2015-2019 52°North Initiative for Geospatial Open Source
* Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.n52.youngs.transform.impl;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Maps;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.xml.xpath.XPathExpression;
import org.n52.youngs.transform.MappingEntry;
/**
*
* @author Daniel Nüst
*/
public class MappingEntryImpl implements MappingEntry {
private final XPathExpression xPath;
private final Map indexProperties = Maps.newHashMap();
private Optional identifier = Optional.empty();
private Optional location = Optional.empty();
private Optional> coordinates = Optional.empty();
private Optional coordinatesType = Optional.empty();
private Optional raw = Optional.empty();
private Optional> replacements = Optional.empty();
private Optional> outputProperties = Optional.empty();
private Optional split = Optional.empty();
private final List children;
private final String fieldName;
private XPathExpression condition;
private final Map suggest;
public MappingEntryImpl(String fieldName, XPathExpression xPath, Map indexProperties,
boolean identifier, boolean location, boolean rawXml) {
this(fieldName, xPath, indexProperties, identifier, location, rawXml, null);
}
public MappingEntryImpl(String fieldName, XPathExpression xPath, Map indexProperties,
boolean identifier, boolean location, boolean rawXml, XPathExpression condition) {
this(fieldName, xPath, indexProperties, identifier, location, rawXml, condition, Collections.emptyList());
}
public MappingEntryImpl(String fieldName, XPathExpression xPath, Map indexProperties,
boolean identifier, boolean location, boolean rawXml, XPathExpression condition, List children) {
this(fieldName, xPath, indexProperties, identifier, location, rawXml, condition, children, null);
}
public MappingEntryImpl(String fieldName, XPathExpression xPath, Map indexProperties,
boolean identifier, boolean location, boolean rawXml, XPathExpression condition, List children,
Map suggest) {
this.fieldName = fieldName;
this.xPath = xPath;
this.indexProperties.putAll(indexProperties);
this.identifier = Optional.of(identifier);
this.location = Optional.of(location);
this.raw = Optional.of(rawXml);
this.condition = condition;
this.children = children;
this.suggest = suggest;
}
@Override
public XPathExpression getXPath() {
return xPath;
}
@Override
public String getFieldName() {
return this.fieldName;
}
public MappingEntryImpl addIndexProperty(String key, Object value) {
this.indexProperties.put(key, value);
return this;
}
@Override
public Map getIndexProperties() {
return this.indexProperties;
}
@Override
public Object getIndexPropery(String name) {
return this.indexProperties.get(name);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("xpath", xPath)
.add("identifer", identifier.orElse(null))
.add("location", location.orElse(null))
.add("raw", raw.orElse(null))
.add("analyzed", isAnalyzed())
.add("properties", Arrays.deepToString(indexProperties.entrySet().toArray()))
.omitNullValues()
.toString();
}
@Override
public boolean isIdentifier() {
return identifier.isPresent() && identifier.get();
}
@Override
public boolean isLocation() {
return location.isPresent() && location.get();
}
@Override
public boolean hasCoordinates() {
return coordinates.isPresent();
}
@Override
public List getCoordinatesXPaths() {
return coordinates.get();
}
public MappingEntryImpl setCoordinatesXPaths(List coords) {
this.coordinates = Optional.of(coords);
return this;
}
@Override
public boolean hasCoordinatesType() {
return this.coordinatesType.isPresent();
}
@Override
public String getCoordinatesType() {
return this.coordinatesType.get();
}
public MappingEntryImpl setCoordinatesType(String type) {
this.coordinatesType = Optional.of(type);
return this;
}
@Override
public boolean isRawXml() {
return raw.isPresent() && raw.get();
}
@Override
public boolean isAnalyzed() {
boolean analyzed = true;
if (indexProperties.containsKey(INDEX_MAPPING_ATTRIBUTE)) {
analyzed = !(indexProperties.get(INDEX_MAPPING_ATTRIBUTE).equals(false)
|| indexProperties.get(INDEX_MAPPING_ATTRIBUTE).equals("no"));
}
else if (indexProperties.containsKey(IndexProperties.TYPE)) {
// by default, keywords are not analyzed in ES 6.x
analyzed = !(indexProperties.get(IndexProperties.TYPE).equals("keyword"));
}
return analyzed;
}
@Override
public boolean hasReplacements() {
return replacements.isPresent();
}
@Override
public Map getReplacements() {
return replacements.get();
}
public MappingEntryImpl setReplacements(Map replacements) {
this.replacements = Optional.of(replacements);
return this;
}
@Override
public boolean hasOutputProperties() {
return this.outputProperties.isPresent();
}
@Override
public Map getOutputProperties() {
return this.outputProperties.get();
}
public void setOutputProperties(Map properties) {
this.outputProperties = Optional.of(properties);
}
@Override
public boolean hasSplit() {
return this.split.isPresent();
}
@Override
public String getSplit() {
return split.get();
}
public MappingEntryImpl setSplit(String split) {
this.split = Optional.of(split);
return this;
}
@Override
public XPathExpression getCondition() {
return this.condition;
}
@Override
public boolean hasCondition() {
return this.condition != null;
}
@Override
public List getChildren() {
return children;
}
@Override
public boolean hasSuggest() {
return suggest != null && !suggest.isEmpty();
}
@Override
public Map getSuggest() {
return this.suggest;
}
}