Commit 75415862 by apoorvnaik Committed by Madhan Neethiraj

ATLAS-2534: Atlas Glossary - REST API

Change-Id: I47210446be9e38c274bae0ee4a688187ba6e4fd0 Signed-off-by: 's avatarMadhan Neethiraj <madhan@apache.org>
parent 6812a7d5
......@@ -30,6 +30,8 @@ import java.util.List;
*/
public interface AtlasGraphQuery<V, E> {
enum SortOrder { ASC, DESC }
/**
* Adds a predicate that the returned vertices must have the specified
* property and that one of the values of the property must be the
......@@ -106,6 +108,15 @@ public interface AtlasGraphQuery<V, E> {
*/
AtlasGraphQuery<V, E> has(String propertyKey, QueryOperator op, Object values);
/**
* Adds a sorting predicate
* @param propertyKey property key to sort on
* @param order ASC or DESC
* @return
*/
AtlasGraphQuery<V, E> orderBy(String propertyKey, SortOrder order);
/**
* Adds a predicate that the vertices returned must satisfy the
* conditions in at least one of the child queries provided.
......
......@@ -18,6 +18,7 @@
package org.apache.atlas.repository.graphdb.tinkerpop.query;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery.QueryOperator;
import org.apache.atlas.repository.graphdb.AtlasVertex;
......@@ -93,4 +94,11 @@ public interface NativeTinkerpopGraphQuery<V, E> {
* @param value
*/
void has(String propertyName, QueryOperator op, Object value);
/**
* Add sort predicate for give property
* @param propertyName
* @param sortOrder
*/
void orderBy(String propertyName, AtlasGraphQuery.SortOrder sortOrder);
}
......@@ -26,11 +26,13 @@ import org.apache.atlas.repository.graphdb.tinkerpop.query.expr.AndCondition;
import org.apache.atlas.repository.graphdb.tinkerpop.query.expr.HasPredicate;
import org.apache.atlas.repository.graphdb.tinkerpop.query.expr.InPredicate;
import org.apache.atlas.repository.graphdb.tinkerpop.query.expr.OrCondition;
import org.apache.atlas.repository.graphdb.tinkerpop.query.expr.OrderByPredicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
......@@ -129,7 +131,8 @@ public abstract class TinkerpopGraphQuery<V, E> implements AtlasGraphQuery<V, E>
}
// Compute the overall result by combining the results of all the AndConditions (nested within OR) together.
Set<AtlasVertex<V, E>> result = new HashSet<>();
Set<AtlasVertex<V, E>> result = new LinkedHashSet<>();
for(AndCondition andExpr : queryCondition.getAndTerms()) {
NativeTinkerpopGraphQuery<V, E> andQuery = andExpr.create(getQueryFactory());
for(AtlasVertex<V, E> vertex : andQuery.vertices()) {
......@@ -269,6 +272,12 @@ public abstract class TinkerpopGraphQuery<V, E> implements AtlasGraphQuery<V, E>
return this;
}
@Override
public AtlasGraphQuery<V, E> orderBy(final String propertyKey, final SortOrder order) {
queryCondition.andWith(new OrderByPredicate(propertyKey, order));
return this;
}
private OrCondition getOrCondition() {
return queryCondition;
}
......
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.repository.graphdb.tinkerpop.query.expr;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery;
import org.apache.atlas.repository.graphdb.tinkerpop.query.NativeTinkerpopGraphQuery;
public class OrderByPredicate implements QueryPredicate {
private final String propertyKey;
private final AtlasGraphQuery.SortOrder sortOrder;
public OrderByPredicate(final String propertyKey, final AtlasGraphQuery.SortOrder sortOrder) {
this.propertyKey = propertyKey;
this.sortOrder = sortOrder;
}
@Override
public void addTo(final NativeTinkerpopGraphQuery query) {
query.orderBy(propertyKey, sortOrder);
}
@Override
public String toString() {
return "OrderBy [ propertyKey = " + propertyKey + ", order = " + sortOrder + " ]";
}
}
......@@ -18,22 +18,11 @@
package org.apache.atlas.repository.graphdb.janus;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasException;
import org.apache.atlas.type.AtlasType;
import org.apache.commons.configuration.Configuration;
import org.janusgraph.core.Cardinality;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.PropertyKey;
import org.janusgraph.core.SchemaViolationException;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphIndexQuery;
import org.janusgraph.core.schema.JanusGraphIndex;
import org.janusgraph.core.schema.JanusGraphManagement;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.groovy.GroovyExpression;
import org.apache.atlas.repository.graphdb.AtlasEdge;
......@@ -46,6 +35,8 @@ import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.graphdb.GremlinVersion;
import org.apache.atlas.repository.graphdb.janus.query.AtlasJanusGraphQuery;
import org.apache.atlas.repository.graphdb.utils.IteratorToIterableAdapter;
import org.apache.atlas.type.AtlasType;
import org.apache.commons.configuration.Configuration;
import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
......@@ -58,6 +49,14 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.io.IoCore;
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter;
import org.janusgraph.core.Cardinality;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.JanusGraphIndexQuery;
import org.janusgraph.core.PropertyKey;
import org.janusgraph.core.SchemaViolationException;
import org.janusgraph.core.schema.JanusGraphIndex;
import org.janusgraph.core.schema.JanusGraphManagement;
import org.janusgraph.diskstorage.BackendException;
import javax.script.Bindings;
......@@ -72,6 +71,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import static org.apache.atlas.repository.Constants.INDEX_SEARCH_VERTEX_PREFIX_DEFAULT;
import static org.apache.atlas.repository.Constants.INDEX_SEARCH_VERTEX_PREFIX_PROPERTY;
......@@ -406,13 +407,7 @@ public class AtlasJanusGraph implements AtlasGraph<AtlasJanusVertex, AtlasJanusE
public Iterable<AtlasVertex<AtlasJanusVertex, AtlasJanusEdge>> wrapVertices(Iterable<? extends Vertex> it) {
return Iterables.transform(it, new Function<Vertex, AtlasVertex<AtlasJanusVertex, AtlasJanusEdge>>() {
@Override
public AtlasVertex<AtlasJanusVertex, AtlasJanusEdge> apply(Vertex input) {
return GraphDbObjectFactory.createVertex(AtlasJanusGraph.this, input);
}
});
return StreamSupport.stream(it.spliterator(), false).map(input -> GraphDbObjectFactory.createVertex(AtlasJanusGraph.this, input)).collect(Collectors.toList());
}
......@@ -423,13 +418,7 @@ public class AtlasJanusGraph implements AtlasGraph<AtlasJanusVertex, AtlasJanusE
public Iterable<AtlasEdge<AtlasJanusVertex, AtlasJanusEdge>> wrapEdges(Iterable<? extends Edge> it) {
return Iterables.transform(it, new Function<Edge, AtlasEdge<AtlasJanusVertex, AtlasJanusEdge>>() {
@Override
public AtlasEdge<AtlasJanusVertex, AtlasJanusEdge> apply(Edge input) {
return GraphDbObjectFactory.createEdge(AtlasJanusGraph.this, input);
}
});
return StreamSupport.stream(it.spliterator(), false).map(input -> GraphDbObjectFactory.createEdge(AtlasJanusGraph.this, input)).collect(Collectors.toList());
}
......
......@@ -17,6 +17,8 @@
*/
package org.apache.atlas.repository.graphdb.janus.query;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery;
import org.apache.tinkerpop.gremlin.process.traversal.Order;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.janusgraph.core.JanusGraphEdge;
import org.janusgraph.core.JanusGraphQuery;
......@@ -126,6 +128,12 @@ public class NativeJanusGraphQuery implements NativeTinkerpopGraphQuery<AtlasJan
query.has(propertyName, pred, value);
}
@Override
public void orderBy(final String propertyName, final AtlasGraphQuery.SortOrder sortOrder) {
Order order = sortOrder == AtlasGraphQuery.SortOrder.ASC ? Order.incr : Order.decr;
query.orderBy(propertyName, order);
}
private Text getGremlinPredicate(MatchingOperator op) {
switch (op) {
case CONTAINS:
......
......@@ -17,7 +17,7 @@
*/
package org.apache.atlas.repository.graphdb.titan0.query;
import com.google.common.collect.Lists;
import com.thinkaurelius.titan.core.Order;
import com.thinkaurelius.titan.core.TitanGraphQuery;
import com.thinkaurelius.titan.core.attribute.Contain;
import com.thinkaurelius.titan.core.attribute.Text;
......@@ -26,6 +26,7 @@ import com.tinkerpop.blueprints.Compare;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery.ComparisionOperator;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery.MatchingOperator;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery.QueryOperator;
......@@ -36,7 +37,10 @@ import org.apache.atlas.repository.graphdb.titan0.Titan0Graph;
import org.apache.atlas.repository.graphdb.titan0.Titan0GraphDatabase;
import org.apache.atlas.repository.graphdb.titan0.Titan0Vertex;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
/**
* Titan 0.5.4 implementation of NativeTitanGraphQuery.
......@@ -129,6 +133,11 @@ public class NativeTitan0GraphQuery implements NativeTinkerpopGraphQuery<Titan0V
query.has(propertyName, pred, value);
}
@Override
public void orderBy(final String propertyName, final AtlasGraphQuery.SortOrder sortOrder) {
query.orderBy(propertyName, sortOrder == AtlasGraphQuery.SortOrder.ASC ? Order.ASC : Order.DESC);
}
private Text getGremlinPredicate(MatchingOperator op) {
switch (op) {
case CONTAINS:
......
......@@ -128,6 +128,9 @@ public enum AtlasErrorCode {
NO_CLASSIFICATIONS_FOUND_FOR_ENTITY(400, "ATLAS-400-00-06E", "No classifications associated with entity: {0}"),
INVALID_CLASSIFICATION_PARAMS(400, "ATLAS-400-00-06F", "Invalid classification parameters passed for {0} operation for entity: {1}"),
PROPAGATED_CLASSIFICATION_NOT_ASSOCIATED_WITH_ENTITY(400, "ATLAS-400-00-070", "Propagated classification {0} is not associated with entity"),
// Glossary Related errors
INVALID_PARTIAL_UPDATE_ATTR_VAL(400, "ATLAS-400-00-071", "Invalid attrVal for partial update of {0}, expected = {1} found {2}"),
MISSING_MANDATORY_ANCHOR(400, "ATLAS-400-00-072", "Mandatory anchor attribute is missing"),
UNAUTHORIZED_ACCESS(403, "ATLAS-403-00-001", "{0} is not authorized to perform {1}"),
......@@ -148,6 +151,7 @@ public enum AtlasErrorCode {
RELATIONSHIP_ALREADY_DELETED(404, "ATLAS-404-00-00F", "Attempting to delete a relationship which is already deleted : {0}"),
INVALID_ENTITY_GUID_FOR_CLASSIFICATION_UPDATE(404, "ATLAS-404-00-010", "Updating entityGuid of classification is not allowed."),
INSTANCE_GUID_NOT_DATASET(404, "ATLAS-404-00-011", "Given instance guid {0} is not a dataset"),
INSTANCE_GUID_DELETED(404, "ATLAS-404-00-012", "Given instance guid {0} has been deleted"),
// All data conflict errors go here
TYPE_ALREADY_EXISTS(409, "ATLAS-409-00-001", "Given type {0} already exists"),
......@@ -177,7 +181,7 @@ public enum AtlasErrorCode {
HIVE_HOOK_METASTORE_BRIDGE(500, "ATLAS-500-00-011", "HiveHookMetaStoreBridge: {0}"),
DATA_ACCESS_SAVE_FAILED(500, "ATLAS-500-00-012", "Save failed: {0}"),
DATA_ACCESS_LOAD_FAILED(500, "ATLAS-500-00-013", "Load failed: {0}"),
ENTITY_NOTIFICATION_FAILED(500, "ATLAS-500-00-014", "Notification failed for operation: {} : {}");
ENTITY_NOTIFICATION_FAILED(500, "ATLAS-500-00-014", "Notification failed for operation: {0} : {1}");
private String errorCode;
private String errorMessage;
......
......@@ -17,32 +17,18 @@
*/
package org.apache.atlas.model;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.atlas.model.annotation.AtlasJSON;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.Objects;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY;
@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE)
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
@AtlasJSON
public abstract class AtlasBaseModelObject implements Serializable {
private static final long serialVersionUID = 1L;
private String guid;
protected AtlasBaseModelObject() {
}
protected AtlasBaseModelObject() {}
public String getGuid() {
return this.guid;
......@@ -52,7 +38,6 @@ public abstract class AtlasBaseModelObject implements Serializable {
this.guid = guid;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
......@@ -63,5 +48,19 @@ public abstract class AtlasBaseModelObject implements Serializable {
return sb.toString();
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof AtlasBaseModelObject)) return false;
final AtlasBaseModelObject that = (AtlasBaseModelObject) o;
return Objects.equals(guid, that.guid);
}
@Override
public int hashCode() {
return Objects.hash(guid);
}
protected abstract StringBuilder toString(StringBuilder sb);
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.model.annotation;
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY;
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotationsInside
@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown=true)
public @interface AtlasJSON {}
\ No newline at end of file
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.model.glossary;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.atlas.model.annotation.AtlasJSON;
import org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader;
import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader;
import org.apache.commons.collections.CollectionUtils;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
@AtlasJSON
public class AtlasGlossary extends AtlasGlossaryBaseObject {
private String language;
private String usage;
private Set<AtlasRelatedTermHeader> terms;
private Set<AtlasRelatedCategoryHeader> categories;
public AtlasGlossary() {
}
public AtlasGlossary(final AtlasGlossary other) {
super.setQualifiedName(other.getQualifiedName());
super.setGuid(other.getGuid());
super.setDisplayName(other.displayName);
super.setShortDescription(other.shortDescription);
super.setLongDescription(other.longDescription);
this.language = other.language;
this.usage = other.usage;
this.terms = other.terms;
this.categories = other.categories;
}
public String getLanguage() {
return language;
}
public void setLanguage(final String language) {
this.language = language;
}
public String getUsage() {
return usage;
}
public void setUsage(final String usage) {
this.usage = usage;
}
public Set<AtlasRelatedCategoryHeader> getCategories() {
return categories;
}
public void setCategories(final Set<AtlasRelatedCategoryHeader> categories) {
this.categories = categories;
}
public Set<AtlasRelatedTermHeader> getTerms() {
return terms;
}
public void setTerms(final Set<AtlasRelatedTermHeader> terms) {
this.terms = terms;
}
@JsonIgnore
@Override
public void setAttribute(String attrName, String attrVal) {
Objects.requireNonNull(attrName, "AtlasGlossary attribute name");
switch (attrName) {
case "displayName":
setDisplayName(attrVal);
break;
case "shortDescription":
setShortDescription(attrVal);
break;
case "longDescription":
setLongDescription(attrVal);
break;
case "language":
setLanguage(attrVal);
break;
case "usage":
setUsage(attrVal);
break;
default:
throw new IllegalArgumentException("Invalid attribute '" + attrName + "' for object AtlasGlossary");
}
}
@JsonIgnore
public void addTerm(AtlasRelatedTermHeader relatedTermId) {
Set<AtlasRelatedTermHeader> terms = this.terms;
if (terms == null) {
terms = new HashSet<>();
}
terms.add(relatedTermId);
setTerms(terms);
}
@JsonIgnore
public void addCategory(AtlasRelatedCategoryHeader relatedCategoryId) {
Set<AtlasRelatedCategoryHeader> categories = this.categories;
if (categories == null) {
categories = new HashSet<>();
}
categories.add(relatedCategoryId);
setCategories(categories);
}
@JsonIgnore
public void removeTerm(AtlasRelatedTermHeader relatedTermId) {
if (CollectionUtils.isNotEmpty(terms)) {
terms.remove(relatedTermId);
}
}
@JsonIgnore
public void removeCategory(AtlasRelatedCategoryHeader relatedCategoryId) {
if (CollectionUtils.isNotEmpty(categories)) {
categories.remove(relatedCategoryId);
}
}
@Override
protected StringBuilder toString(final StringBuilder sb) {
return sb == null ? new StringBuilder(toString()) : sb.append(toString());
}
@AtlasJSON
public static class AtlasGlossaryExtInfo extends AtlasGlossary {
private Map<String, AtlasGlossaryTerm> termInfo;
private Map<String, AtlasGlossaryCategory> categoryInfo;
public AtlasGlossaryExtInfo() {
}
public AtlasGlossaryExtInfo(AtlasGlossary glossary) {
super(glossary);
}
public Map<String, AtlasGlossaryTerm> getTermInfo() {
return termInfo;
}
public void addTermInfo(final AtlasGlossaryTerm term) {
if (termInfo == null) {
termInfo = new HashMap<>();
}
termInfo.put(term.getGuid(), term);
}
public void setTermInfo(final Map<String, AtlasGlossaryTerm> termInfo) {
this.termInfo = termInfo;
}
public Map<String, AtlasGlossaryCategory> getCategoryInfo() {
return categoryInfo;
}
public void addCategoryInfo(final AtlasGlossaryCategory category) {
if (categoryInfo == null) {
categoryInfo = new HashMap<>();
}
categoryInfo.put(category.getGuid(), category);
}
public void setCategoryInfo(final Map<String, AtlasGlossaryCategory> categoryInfo) {
this.categoryInfo = categoryInfo;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof AtlasGlossaryExtInfo)) return false;
if (!super.equals(o)) return false;
final AtlasGlossaryExtInfo that = (AtlasGlossaryExtInfo) o;
return Objects.equals(termInfo, that.termInfo) &&
Objects.equals(categoryInfo, that.categoryInfo);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), termInfo, categoryInfo);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AtlasGlossaryExtInfo{");
sb.append(super.toString());
sb.append(", termInfo=").append(termInfo);
sb.append(", categoryInfo=").append(categoryInfo);
sb.append('}');
return sb.toString();
}
}
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.model.glossary;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.atlas.model.AtlasBaseModelObject;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.commons.collections.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public abstract class AtlasGlossaryBaseObject extends AtlasBaseModelObject {
// Core attributes
protected String displayName;
protected String shortDescription;
protected String longDescription;
// Classifications
protected List<AtlasClassification> classifications;
private String qualifiedName;
public String getQualifiedName() {
return qualifiedName;
}
public void setQualifiedName(final String qualifiedName) {
this.qualifiedName = qualifiedName;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(final String displayName) {
this.displayName = displayName;
}
public String getShortDescription() {
return shortDescription;
}
public void setShortDescription(final String shortDescription) {
this.shortDescription = shortDescription;
}
public String getLongDescription() {
return longDescription;
}
public void setLongDescription(final String longDescription) {
this.longDescription = longDescription;
}
abstract public void setAttribute(String attrName, String attrVal);
public List<AtlasClassification> getClassifications() {
return classifications;
}
public void setClassifications(final List<AtlasClassification> classifications) {
this.classifications = classifications;
}
@JsonIgnore
public void addClassification(AtlasClassification classification) {
List<AtlasClassification> classifications = this.classifications;
if (classifications == null) {
classifications = new ArrayList<>();
}
classifications.add(classification);
setClassifications(classifications);
}
@JsonIgnore
public void removeClassification(AtlasClassification classification) {
if (CollectionUtils.isNotEmpty(classifications)) {
classifications.remove(classification);
}
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof AtlasGlossaryBaseObject)) return false;
if (!super.equals(o)) return false;
final AtlasGlossaryBaseObject that = (AtlasGlossaryBaseObject) o;
return Objects.equals(displayName, that.displayName) &&
Objects.equals(shortDescription, that.shortDescription) &&
Objects.equals(longDescription, that.longDescription) &&
Objects.equals(classifications, that.classifications) &&
Objects.equals(qualifiedName, that.qualifiedName);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), displayName, shortDescription, longDescription, classifications, qualifiedName);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AtlasGlossaryBaseObject{");
sb.append("displayName='").append(displayName).append('\'');
sb.append(", shortDescription='").append(shortDescription).append('\'');
sb.append(", longDescription='").append(longDescription).append('\'');
sb.append(", classifications=").append(classifications);
sb.append(", qualifiedName='").append(qualifiedName).append('\'');
sb.append('}');
return sb.toString();
}
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.model.glossary;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.atlas.model.annotation.AtlasJSON;
import org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader;
import org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader;
import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader;
import org.apache.commons.collections.CollectionUtils;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
@AtlasJSON
public class AtlasGlossaryCategory extends AtlasGlossaryBaseObject {
// Inherited attributes from relations
private AtlasGlossaryHeader anchor;
// Category hierarchy links
private AtlasRelatedCategoryHeader parentCategory;
private Set<AtlasRelatedCategoryHeader> childrenCategories;
// Terms associated with this category
private Set<AtlasRelatedTermHeader> terms;
public AtlasGlossaryCategory() {
}
public AtlasGlossaryHeader getAnchor() {
return anchor;
}
public void setAnchor(final AtlasGlossaryHeader anchor) {
this.anchor = anchor;
}
public AtlasRelatedCategoryHeader getParentCategory() {
return parentCategory;
}
public void setParentCategory(final AtlasRelatedCategoryHeader parentCategory) {
this.parentCategory = parentCategory;
}
public Set<AtlasRelatedCategoryHeader> getChildrenCategories() {
return childrenCategories;
}
public void setChildrenCategories(final Set<AtlasRelatedCategoryHeader> childrenCategories) {
this.childrenCategories = childrenCategories;
}
public Set<AtlasRelatedTermHeader> getTerms() {
return terms;
}
public void setTerms(final Set<AtlasRelatedTermHeader> terms) {
this.terms = terms;
}
@JsonIgnore
public void addChild(AtlasRelatedCategoryHeader child) {
Set<AtlasRelatedCategoryHeader> children = this.childrenCategories ;
if (children == null) {
children = new HashSet<>();
}
children.add(child);
setChildrenCategories(children);
}
@JsonIgnore
public void removeChild(AtlasRelatedCategoryHeader child) {
if (CollectionUtils.isNotEmpty(childrenCategories)) {
childrenCategories.remove(child);
}
}
@JsonIgnore
public void addTerm(AtlasRelatedTermHeader term) {
Set<AtlasRelatedTermHeader> terms = this.terms;
if (terms == null) {
terms = new HashSet<>();
}
terms.add(term);
setTerms(terms);
}
@JsonIgnore
public void removeTerm(AtlasRelatedTermHeader term) {
if (CollectionUtils.isNotEmpty(terms)) {
terms.remove(term);
}
}
@JsonIgnore
@Override
public void setAttribute(String attrName, String attrVal) {
Objects.requireNonNull(attrName, "AtlasGlossary attribute name");
switch(attrName) {
case "displayName":
setDisplayName(attrVal);
break;
case "shortDescription":
setShortDescription(attrVal);
break;
case "longDescription":
setLongDescription(attrVal);
break;
default:
throw new IllegalArgumentException("Invalid attribute '" + attrName + "' for object AtlasGlossaryCategory");
}
}
@Override
public String toString() {
final StringBuffer sb = new StringBuffer("AtlasGlossaryCategory{");
sb.append("displayName='").append(getDisplayName()).append('\'');
sb.append(", shortDescription='").append(getShortDescription()).append('\'');
sb.append(", longDescription='").append(getLongDescription()).append('\'');
sb.append(", anchor=").append(anchor);
sb.append(", parentCategory=").append(parentCategory);
sb.append(", childrenCategories=").append(childrenCategories);
sb.append(", terms=").append(terms);
sb.append(", classifications=").append(getClassifications());
sb.append('}');
return sb.toString();
}
@Override
protected StringBuilder toString(final StringBuilder sb) {
return sb == null ? new StringBuilder(toString()) : sb.append(toString());
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof AtlasGlossaryCategory)) return false;
if (!super.equals(o)) return false;
final AtlasGlossaryCategory category = (AtlasGlossaryCategory) o;
return Objects.equals(getDisplayName(), category.getDisplayName()) &&
Objects.equals(getShortDescription(), category.getShortDescription()) &&
Objects.equals(getLongDescription(), category.getLongDescription()) &&
Objects.equals(anchor, category.anchor) &&
Objects.equals(parentCategory, category.parentCategory) &&
Objects.equals(childrenCategories, category.childrenCategories) &&
Objects.equals(terms, category.terms) &&
Objects.equals(getClassifications(), category.getClassifications());
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), getDisplayName(), getShortDescription(), getLongDescription(),
anchor, parentCategory, childrenCategories,
terms, getClassifications());
}
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.model.glossary.enums;
public enum AtlasTermAssignmentStatus {
DISCOVERED(0),
PROPOSED(1),
IMPORTED(2),
VALIDATED(3),
DEPRECATED(4),
OBSOLETE(5),
OTHER(6),
;
private int value;
AtlasTermAssignmentStatus(final int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.model.glossary.enums;
public enum AtlasTermRelationshipStatus {
DRAFT(0),
ACTIVE(1),
DEPRECATED(2),
OBSOLETE(3),
OTHER(99)
;
private int value;
AtlasTermRelationshipStatus(final int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.model.glossary.relations;
import org.apache.atlas.model.annotation.AtlasJSON;
import java.util.Objects;
@AtlasJSON
public class AtlasGlossaryHeader {
private String glossaryGuid;
private String relationGuid;
private String displayText;
public String getDisplayText() {
return displayText;
}
public void setDisplayText(final String displayText) {
this.displayText = displayText;
}
public String getGlossaryGuid() {
return glossaryGuid;
}
public void setGlossaryGuid(final String glossaryGuid) {
this.glossaryGuid = glossaryGuid;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof AtlasGlossaryHeader)) return false;
final AtlasGlossaryHeader that = (AtlasGlossaryHeader) o;
return Objects.equals(glossaryGuid, that.glossaryGuid) &&
Objects.equals(relationGuid, that.relationGuid) &&
Objects.equals(displayText, that.displayText);
}
@Override
public int hashCode() {
return Objects.hash(glossaryGuid, displayText);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AtlasGlossaryId{");
sb.append("glossaryGuid='").append(glossaryGuid).append('\'');
sb.append(", relationGuid='").append(relationGuid).append('\'');
sb.append(", displayText='").append(displayText).append('\'');
sb.append('}');
return sb.toString();
}
public String getRelationGuid() {
return relationGuid;
}
public void setRelationGuid(final String relationGuid) {
this.relationGuid = relationGuid;
}
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.model.glossary.relations;
import org.apache.atlas.model.annotation.AtlasJSON;
import java.util.Objects;
@AtlasJSON
public class AtlasRelatedCategoryHeader {
private String categoryGuid;
private String relationGuid;
private String displayText;
private String description;
public AtlasRelatedCategoryHeader() {
}
public String getCategoryGuid() {
return categoryGuid;
}
public void setCategoryGuid(final String categoryGuid) {
this.categoryGuid = categoryGuid;
}
public String getDescription() {
return description;
}
public void setDescription(final String description) {
this.description = description;
}
public String getDisplayText() {
return displayText;
}
public void setDisplayText(final String displayText) {
this.displayText = displayText;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof AtlasRelatedCategoryHeader)) return false;
final AtlasRelatedCategoryHeader that = (AtlasRelatedCategoryHeader) o;
return Objects.equals(categoryGuid, that.categoryGuid) &&
Objects.equals(displayText, that.displayText) &&
Objects.equals(description, that.description);
}
@Override
public int hashCode() {
return Objects.hash(categoryGuid, displayText, description);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AtlasRelatedCategoryId{");
sb.append("categoryGuid='").append(categoryGuid).append('\'');
sb.append(", relationGuid='").append(relationGuid).append('\'');
sb.append(", displayText='").append(displayText).append('\'');
sb.append(", description='").append(description).append('\'');
sb.append('}');
return sb.toString();
}
public String getRelationGuid() {
return relationGuid;
}
public void setRelationGuid(final String relationGuid) {
this.relationGuid = relationGuid;
}
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.model.glossary.relations;
import org.apache.atlas.model.annotation.AtlasJSON;
import org.apache.atlas.model.glossary.enums.AtlasTermRelationshipStatus;
import java.util.Objects;
@AtlasJSON
public class AtlasRelatedTermHeader {
private String termGuid;
private String relationGuid;
private String displayText;
private String description;
private String expression;
private String steward;
private String source;
private AtlasTermRelationshipStatus status;
public AtlasRelatedTermHeader() {
}
public String getTermGuid() {
return termGuid;
}
public void setTermGuid(final String termGuid) {
this.termGuid = termGuid;
}
public String getDescription() {
return description;
}
public void setDescription(final String description) {
this.description = description;
}
public String getExpression() {
return expression;
}
public void setExpression(final String expression) {
this.expression = expression;
}
public String getSteward() {
return steward;
}
public void setSteward(final String steward) {
this.steward = steward;
}
public String getSource() {
return source;
}
public void setSource(final String source) {
this.source = source;
}
public AtlasTermRelationshipStatus getStatus() {
return status;
}
public void setStatus(final AtlasTermRelationshipStatus status) {
this.status = status;
}
@Override
public int hashCode() {
return Objects.hash(termGuid, displayText, description, expression, steward, source, status);
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof AtlasRelatedTermHeader)) return false;
final AtlasRelatedTermHeader that = (AtlasRelatedTermHeader) o;
return Objects.equals(termGuid, that.termGuid) &&
Objects.equals(relationGuid, that.relationGuid) &&
Objects.equals(description, that.description) &&
Objects.equals(displayText, that.displayText) &&
Objects.equals(expression, that.expression) &&
Objects.equals(steward, that.steward) &&
Objects.equals(source, that.source) &&
status == that.status;
}
@Override
public String toString() {
final StringBuffer sb = new StringBuffer("AtlasRelatedTermId{");
sb.append("termGuid='").append(termGuid).append('\'');
sb.append(", relationGuid='").append(relationGuid).append('\'');
sb.append(", description='").append(description).append('\'');
sb.append(", displayText='").append(displayText).append('\'');
sb.append(", expression='").append(expression).append('\'');
sb.append(", steward='").append(steward).append('\'');
sb.append(", source='").append(source).append('\'');
sb.append(", status=").append(status);
sb.append('}');
return sb.toString();
}
public String getDisplayText() {
return displayText;
}
public void setDisplayText(final String displayText) {
this.displayText = displayText;
}
public String getRelationGuid() {
return relationGuid;
}
public void setRelationGuid(final String relationGuid) {
this.relationGuid = relationGuid;
}
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.model.glossary.relations;
import org.apache.atlas.model.annotation.AtlasJSON;
import org.apache.atlas.model.glossary.enums.AtlasTermAssignmentStatus;
import java.util.Objects;
@AtlasJSON
public class AtlasTermAssignmentHeader {
private String termGuid;
private String relationGuid;
private String description;
private String displayText;
private String expression;
private String createdBy;
private String steward;
private String source;
private int confidence;
private AtlasTermAssignmentStatus status;
public AtlasTermAssignmentHeader() {
}
public String getTermGuid() {
return termGuid;
}
public void setTermGuid(final String termGuid) {
this.termGuid = termGuid;
}
public String getDescription() {
return description;
}
public void setDescription(final String description) {
this.description = description;
}
public String getExpression() {
return expression;
}
public void setExpression(final String expression) {
this.expression = expression;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(final String createdBy) {
this.createdBy = createdBy;
}
public String getSteward() {
return steward;
}
public void setSteward(final String steward) {
this.steward = steward;
}
public String getSource() {
return source;
}
public void setSource(final String source) {
this.source = source;
}
public int getConfidence() {
return confidence;
}
public void setConfidence(final int confidence) {
this.confidence = confidence;
}
public AtlasTermAssignmentStatus getStatus() {
return status;
}
public void setStatus(final AtlasTermAssignmentStatus status) {
this.status = status;
}
public String getDisplayText() {
return displayText;
}
public void setDisplayText(final String displayText) {
this.displayText = displayText;
}
@Override
public int hashCode() {
return Objects.hash(termGuid, description, displayText, expression, createdBy, steward, source, confidence, status);
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof AtlasTermAssignmentHeader)) return false;
final AtlasTermAssignmentHeader that = (AtlasTermAssignmentHeader) o;
return confidence == that.confidence &&
Objects.equals(termGuid, that.termGuid) &&
Objects.equals(relationGuid, that.relationGuid) &&
Objects.equals(description, that.description) &&
Objects.equals(displayText, that.displayText) &&
Objects.equals(expression, that.expression) &&
Objects.equals(createdBy, that.createdBy) &&
Objects.equals(steward, that.steward) &&
Objects.equals(source, that.source) &&
status == that.status;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AtlasTermAssignmentId{");
sb.append("termGuid='").append(termGuid).append('\'');
sb.append(", relationGuid='").append(relationGuid).append('\'');
sb.append(", description='").append(description).append('\'');
sb.append(", displayText='").append(displayText).append('\'');
sb.append(", expression='").append(expression).append('\'');
sb.append(", createdBy='").append(createdBy).append('\'');
sb.append(", steward='").append(steward).append('\'');
sb.append(", source='").append(source).append('\'');
sb.append(", confidence=").append(confidence);
sb.append(", status=").append(status);
sb.append('}');
return sb.toString();
}
public String getRelationGuid() {
return relationGuid;
}
public void setRelationGuid(final String relationGuid) {
this.relationGuid = relationGuid;
}
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.model.glossary.relations;
import org.apache.atlas.model.annotation.AtlasJSON;
import org.apache.atlas.model.glossary.enums.AtlasTermRelationshipStatus;
import java.util.Objects;
@AtlasJSON
public class AtlasTermCategorizationHeader {
private String categoryGuid;
private String relationGuid;
private String description;
private String displayText;
private AtlasTermRelationshipStatus status;
public AtlasTermCategorizationHeader() {
}
public String getCategoryGuid() {
return categoryGuid;
}
public void setCategoryGuid(final String categoryGuid) {
this.categoryGuid = categoryGuid;
}
public String getDescription() {
return description;
}
public void setDescription(final String description) {
this.description = description;
}
public AtlasTermRelationshipStatus getStatus() {
return status;
}
public void setStatus(final AtlasTermRelationshipStatus status) {
this.status = status;
}
public String getDisplayText() {
return displayText;
}
public void setDisplayText(final String displayText) {
this.displayText = displayText;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof AtlasTermCategorizationHeader)) return false;
final AtlasTermCategorizationHeader that = (AtlasTermCategorizationHeader) o;
return Objects.equals(categoryGuid, that.categoryGuid) &&
Objects.equals(relationGuid, that.relationGuid) &&
Objects.equals(description, that.description) &&
Objects.equals(displayText, that.displayText) &&
status == that.status;
}
@Override
public int hashCode() {
return Objects.hash(categoryGuid, relationGuid, description, displayText, status);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AtlasTermCategorizationId{");
sb.append("categoryGuid='").append(categoryGuid).append('\'');
sb.append(", relationGuid='").append(relationGuid).append('\'');
sb.append(", description='").append(description).append('\'');
sb.append(", displayText='").append(displayText).append('\'');
sb.append(", status=").append(status);
sb.append('}');
return sb.toString();
}
public String getRelationGuid() {
return relationGuid;
}
public void setRelationGuid(final String relationGuid) {
this.relationGuid = relationGuid;
}
}
......@@ -22,9 +22,9 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.atlas.model.PList;
import org.apache.atlas.model.SearchFilter.SortType;
import org.apache.atlas.model.glossary.relations.AtlasTermAssignmentHeader;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.commons.collections.CollectionUtils;
......@@ -80,9 +80,10 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
private Date updateTime = null;
private Long version = 0L;
private Map<String, Object> relationshipAttributes;
private List<AtlasClassification> classifications;
private List<AtlasClassification> propagationDisabledClassifications;
private Map<String, Object> relationshipAttributes;
private List<AtlasClassification> classifications;
private List<AtlasClassification> propagationDisabledClassifications;
private List<AtlasTermAssignmentHeader> meanings;
@JsonIgnore
private static AtomicLong s_nextId = new AtomicLong(System.nanoTime());
......@@ -280,6 +281,24 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
this.classifications = c;
}
public List<AtlasTermAssignmentHeader> getMeanings() {
return meanings;
}
public void setMeanings(final List<AtlasTermAssignmentHeader> meanings) {
this.meanings = meanings;
}
public void addMeaning(AtlasTermAssignmentHeader meaning) {
List<AtlasTermAssignmentHeader> meanings = this.meanings;
if (meanings == null) {
meanings = new ArrayList<>();
}
meanings.add(meaning);
setMeanings(meanings);
}
private void init() {
setGuid(nextInternalId());
setStatus(null);
......@@ -289,6 +308,7 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
setUpdateTime(null);
setClassifications(null);
setPropagationDisabledClassifications(null);
setMeanings(null);
}
private static String nextInternalId() {
......@@ -319,6 +339,9 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
sb.append(", propagationDisabledClassifications=[");
AtlasBaseTypeDef.dumpObjects(propagationDisabledClassifications, sb);
sb.append(']');
sb.append(", meanings=[");
AtlasBaseTypeDef.dumpObjects(meanings, sb);
sb.append(']');
sb.append('}');
return sb;
......
......@@ -6,9 +6,9 @@
* to you 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
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.
......@@ -21,24 +21,23 @@ package org.apache.atlas.model.instance;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.atlas.model.PList;
import org.apache.atlas.model.SearchFilter.SortType;
import org.apache.atlas.model.glossary.relations.AtlasTermAssignmentHeader;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.commons.collections.CollectionUtils;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import org.apache.atlas.model.PList;
import org.apache.atlas.model.SearchFilter.SortType;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.commons.collections.CollectionUtils;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY;
......@@ -46,19 +45,21 @@ import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_
/**
* An instance of an entity - like hive_table, hive_database.
*/
@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE)
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AtlasEntityHeader extends AtlasStruct implements Serializable {
private static final long serialVersionUID = 1L;
private String guid = null;
private AtlasEntity.Status status = AtlasEntity.Status.ACTIVE;
private String displayText = null;
private List<String> classificationNames = null;
private List<AtlasClassification> classifications = null;
private String guid = null;
private AtlasEntity.Status status = AtlasEntity.Status.ACTIVE;
private String displayText = null;
private List<String> classificationNames = null;
private List<AtlasClassification> classifications = null;
private List<String> meaningNames = null;
private List<AtlasTermAssignmentHeader> meanings = null;
public AtlasEntityHeader() {
this(null, null);
......@@ -80,7 +81,7 @@ public class AtlasEntityHeader extends AtlasStruct implements Serializable {
}
public AtlasEntityHeader(String typeName, String guid, Map<String, Object> attributes) {
public AtlasEntityHeader(String typeName, String guid, Map<String, Object> attributes) {
super(typeName, attributes);
setGuid(guid);
setClassificationNames(null);
......@@ -100,7 +101,7 @@ public class AtlasEntityHeader extends AtlasStruct implements Serializable {
}
}
public AtlasEntityHeader(AtlasEntity entity){
public AtlasEntityHeader(AtlasEntity entity) {
super(entity.getTypeName(), entity.getAttributes());
setGuid(entity.getGuid());
setClassifications(entity.getClassifications());
......@@ -138,7 +139,7 @@ public class AtlasEntityHeader extends AtlasStruct implements Serializable {
this.displayText = displayText;
}
public List<String> getClassificationNames(){
public List<String> getClassificationNames() {
return classificationNames;
}
......@@ -146,9 +147,13 @@ public class AtlasEntityHeader extends AtlasStruct implements Serializable {
this.classificationNames = classificationNames;
}
public List<AtlasClassification> getClassifications() { return classifications; }
public List<AtlasClassification> getClassifications() {
return classifications;
}
public void setClassifications(List<AtlasClassification> classifications) { this.classifications = classifications; }
public void setClassifications(List<AtlasClassification> classifications) {
this.classifications = classifications;
}
@Override
public StringBuilder toString(StringBuilder sb) {
......@@ -179,15 +184,17 @@ public class AtlasEntityHeader extends AtlasStruct implements Serializable {
if (!super.equals(o)) return false;
AtlasEntityHeader that = (AtlasEntityHeader) o;
return Objects.equals(guid, that.guid) &&
status == that.status &&
Objects.equals(displayText, that.displayText) &&
Objects.equals(classificationNames, that.classificationNames) &&
Objects.equals(classifications, that.classifications);
status == that.status &&
Objects.equals(displayText, that.displayText) &&
Objects.equals(classificationNames, that.classificationNames) &&
Objects.equals(meaningNames, that.classificationNames) &&
Objects.equals(classifications, that.classifications) &&
Objects.equals(meanings, that.meanings);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), guid, status, displayText, classificationNames, classifications);
return Objects.hash(super.hashCode(), guid, status, displayText, classificationNames, classifications, meaningNames, meanings);
}
@Override
......@@ -195,12 +202,28 @@ public class AtlasEntityHeader extends AtlasStruct implements Serializable {
return toString(new StringBuilder()).toString();
}
public List<String> getMeaningNames() {
return meaningNames;
}
public void setMeaningNames(final List<String> meaningNames) {
this.meaningNames = meaningNames;
}
public List<AtlasTermAssignmentHeader> getMeanings() {
return meanings;
}
public void setMeanings(final List<AtlasTermAssignmentHeader> meanings) {
this.meanings = meanings;
}
/**
* REST serialization friendly list.
*/
@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE)
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlSeeAlso(AtlasEntity.class)
......@@ -216,7 +239,7 @@ public class AtlasEntityHeader extends AtlasStruct implements Serializable {
}
public AtlasEntityHeaders(List list, long startIndex, int pageSize, long totalCount,
SortType sortType, String sortBy) {
SortType sortType, String sortBy) {
super(list, startIndex, pageSize, totalCount, sortType, sortBy);
}
}
......
......@@ -22,17 +22,14 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags;
import org.apache.atlas.type.AtlasBuiltInTypes;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;
......
......@@ -20,9 +20,7 @@ package org.apache.atlas.type;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.AtlasRelationship;
import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory;
......
......@@ -27,14 +27,24 @@ import org.apache.commons.lang3.StringUtils;
public abstract class AbstractDataTransferObject<T extends AtlasBaseModelObject> implements DataTransferObject<T> {
private static final String DEFAULT_PREFIX = "Atlas";
private final AtlasTypeRegistry typeRegistry;
private final Class<T> objectType;
private final String entityTypeName;
private final String alternateEntityTypeName;
protected AbstractDataTransferObject(AtlasTypeRegistry typeRegistry, Class<T> tClass) {
protected AbstractDataTransferObject(AtlasTypeRegistry typeRegistry, Class<T> tClass, boolean isInternal) {
this.typeRegistry = typeRegistry;
this.objectType = tClass;
this.entityTypeName = Constants.INTERNAL_PROPERTY_KEY_PREFIX + objectType.getSimpleName();
if (isInternal) {
this.entityTypeName = Constants.INTERNAL_PROPERTY_KEY_PREFIX + objectType.getSimpleName();
this.alternateEntityTypeName = null;
} else {
this.entityTypeName = objectType.getSimpleName();
this.alternateEntityTypeName = entityTypeName.startsWith(DEFAULT_PREFIX) ? entityTypeName.substring(DEFAULT_PREFIX.length()) : null;
}
}
@Override
......@@ -44,7 +54,11 @@ public abstract class AbstractDataTransferObject<T extends AtlasBaseModelObject>
@Override
public AtlasEntityType getEntityType() {
return typeRegistry.getEntityTypeByName(entityTypeName);
AtlasEntityType ret = typeRegistry.getEntityTypeByName(entityTypeName);
if (ret == null) {
ret = typeRegistry.getEntityTypeByName(alternateEntityTypeName);
}
return ret;
}
......
......@@ -17,29 +17,30 @@
*/
package org.apache.atlas.repository.ogm;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@Component
public class DTORegistry {
private final Map<Type, DataTransferObject> typeDTOMap = new HashMap<>();
private static final Logger LOG = LoggerFactory.getLogger(DTORegistry.class);
private final Map<Class, DataTransferObject> typeDTOMap = new HashMap<>();
@Inject
public DTORegistry(AtlasTypeRegistry typeRegistry) {
AtlasSavedSearchDTO savedSearchDTO = new AtlasSavedSearchDTO(typeRegistry);
AtlasUserProfileDTO userProfileDTO = new AtlasUserProfileDTO(typeRegistry, savedSearchDTO);
registerDTO(savedSearchDTO);
registerDTO(userProfileDTO);
public DTORegistry(Set<DataTransferObject> availableDTOs) {
for (DataTransferObject availableDTO : availableDTOs) {
LOG.info("Registering DTO: {}", availableDTO.getClass().getSimpleName());
registerDTO(availableDTO);
}
}
public <T extends DataTransferObject> DataTransferObject get(Type t) {
public <T extends DataTransferObject> DataTransferObject get(Class t) {
return typeDTOMap.get(t);
}
......
......@@ -20,18 +20,29 @@ package org.apache.atlas.repository.ogm;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.AtlasBaseModelObject;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.repository.store.graph.v1.AtlasEntityStream;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Component
public class DataAccess {
private static final Logger LOG = LoggerFactory.getLogger(DataAccess.class);
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("repository.DataAccess");
private final AtlasEntityStore entityStore;
private final DTORegistry dtoRegistry;
......@@ -42,49 +53,186 @@ public class DataAccess {
}
public <T extends AtlasBaseModelObject> T save(T obj) throws AtlasBaseException {
DataTransferObject<T> dto = (DataTransferObject<T>)dtoRegistry.get(obj.getClass());
Objects.requireNonNull(obj, "Can't save a null object");
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataAccess.save()");
}
DataTransferObject<T> dto = (DataTransferObject<T>) dtoRegistry.get(obj.getClass());
AtlasEntityWithExtInfo entityWithExtInfo = dto.toEntityWithExtInfo(obj);
EntityMutationResponse entityMutationResponse = entityStore.createOrUpdate(new AtlasEntityStream(entityWithExtInfo), false);
if (noEntityMutation(entityMutationResponse)) {
throw new AtlasBaseException(AtlasErrorCode.DATA_ACCESS_SAVE_FAILED, obj.toString());
}
AtlasEntityWithExtInfo entityWithExtInfo = dto.toEntityWithExtInfo(obj);
EntityMutationResponse entityMutationResponse = entityStore.createOrUpdate(new AtlasEntityStream(entityWithExtInfo), false);
// Since mutation context has guid information, attempt to set the same.
if (entityMutationResponse.getFirstEntityCreated() != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Object created");
}
obj.setGuid(entityMutationResponse.getFirstEntityCreated().getGuid());
} else if (entityMutationResponse.getFirstEntityUpdated() != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Object updated");
}
obj.setGuid(entityMutationResponse.getFirstEntityUpdated().getGuid());
}
if (hasError(entityMutationResponse)) {
throw new AtlasBaseException(AtlasErrorCode.DATA_ACCESS_SAVE_FAILED, obj.toString());
return this.load(obj);
} finally {
AtlasPerfTracer.log(perf);
}
return this.load(obj);
}
public <T extends AtlasBaseModelObject> Iterable<T> save(Iterable<T> obj) throws AtlasBaseException {
Objects.requireNonNull(obj, "Can't save a null object");
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataAccess.multiSave()");
}
List<T> ret = new ArrayList<>();
for (T o : obj) {
ret.add(save(o));
}
return ret;
} finally {
AtlasPerfTracer.log(perf);
}
}
public <T extends AtlasBaseModelObject> Iterable<T> load(final Iterable<T> objects) throws AtlasBaseException {
Objects.requireNonNull(objects, "Objects to load");
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataAccess.multiLoad()");
}
List<AtlasBaseModelObject> ret = new ArrayList<>();
for (T object : objects) {
ret.add(load(object));
}
return (Iterable<T>) ret;
} finally {
AtlasPerfTracer.log(perf);
}
}
public <T extends AtlasBaseModelObject> T load(T obj) throws AtlasBaseException {
DataTransferObject<T> dto = (DataTransferObject<T>)dtoRegistry.get(obj.getClass());
return load(obj, false);
}
public <T extends AtlasBaseModelObject> T load(T obj, boolean loadDeleted) throws AtlasBaseException {
Objects.requireNonNull(obj, "Can't load a null object");
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataAccess.load()");
}
DataTransferObject<T> dto = (DataTransferObject<T>) dtoRegistry.get(obj.getClass());
AtlasEntityWithExtInfo entityWithExtInfo;
AtlasEntityWithExtInfo entityWithExtInfo;
if (StringUtils.isNotEmpty(obj.getGuid())) {
if (LOG.isDebugEnabled()) {
LOG.debug("Load using GUID");
}
entityWithExtInfo = entityStore.getById(obj.getGuid());
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Load using unique attributes");
}
entityWithExtInfo = entityStore.getByUniqueAttributes(dto.getEntityType(), dto.getUniqueAttributes(obj));
}
if (StringUtils.isNotEmpty(obj.getGuid())) {
entityWithExtInfo = entityStore.getById(obj.getGuid());
} else {
entityWithExtInfo = entityStore.getByUniqueAttributes(dto.getEntityType(), dto.getUniqueAttributes(obj));
if (!loadDeleted && entityWithExtInfo.getEntity().getStatus() == AtlasEntity.Status.DELETED) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_DELETED, obj.getGuid());
}
return dto.from(entityWithExtInfo);
} finally {
AtlasPerfTracer.log(perf);
}
return dto.from(entityWithExtInfo);
}
public void delete(String guid) throws AtlasBaseException {
Objects.requireNonNull(guid, "guid");
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataAccess.delete()");
}
entityStore.deleteById(guid);
} finally {
AtlasPerfTracer.log(perf);
}
}
public void delete(List<String> guids) throws AtlasBaseException {
Objects.requireNonNull(guids, "guids");
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataAccess.multiDelete()");
}
entityStore.deleteByIds(guids);
public void deleteUsingGuid(String guid) throws AtlasBaseException {
entityStore.deleteById(guid);
} finally {
AtlasPerfTracer.log(perf);
}
}
public <T extends AtlasBaseModelObject> void delete(T obj) throws AtlasBaseException {
T object = load(obj);
Objects.requireNonNull(obj, "Can't delete a null object");
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataAccess.delete()");
}
T object = load(obj);
if (object != null) {
delete(object.getGuid());
}
if (object != null) {
deleteUsingGuid(object.getGuid());
} finally {
AtlasPerfTracer.log(perf);
}
}
private boolean hasError(EntityMutationResponse er) {
return (er == null ||
!((er.getCreatedEntities() != null && er.getCreatedEntities().size() > 0)
|| (er.getUpdatedEntities() != null && er.getUpdatedEntities().size() > 0)
)
);
// Helper functions
private boolean noEntityMutation(EntityMutationResponse er) {
return er == null || (CollectionUtils.isEmpty(er.getCreatedEntities()) && CollectionUtils.isEmpty(er.getUpdatedEntities()));
}
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.repository.ogm.glossary;
import org.apache.atlas.model.AtlasBaseModelObject;
import org.apache.atlas.model.glossary.enums.AtlasTermRelationshipStatus;
import org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader;
import org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader;
import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader;
import org.apache.atlas.model.glossary.relations.AtlasTermCategorizationHeader;
import org.apache.atlas.model.instance.AtlasRelatedObjectId;
import org.apache.atlas.model.instance.AtlasRelationship;
import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.repository.ogm.AbstractDataTransferObject;
import org.apache.atlas.type.AtlasTypeRegistry;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
public abstract class AbstractGlossaryDTO<T extends AtlasBaseModelObject> extends AbstractDataTransferObject<T> {
protected AbstractGlossaryDTO(final AtlasTypeRegistry typeRegistry, final Class<T> tClass, final boolean isInternal) {
super(typeRegistry, tClass, isInternal);
}
protected AtlasRelatedTermHeader constructRelatedTermId(AtlasRelatedObjectId relatedObjectId) {
AtlasRelatedTermHeader ret = new AtlasRelatedTermHeader();
ret.setTermGuid(relatedObjectId.getGuid());
ret.setRelationGuid(relatedObjectId.getRelationshipGuid());
AtlasStruct relationshipAttributes = relatedObjectId.getRelationshipAttributes();
if (relationshipAttributes != null) {
ret.setDescription((String) relationshipAttributes.getAttribute("description"));
ret.setExpression((String) relationshipAttributes.getAttribute("expression"));
ret.setSource((String) relationshipAttributes.getAttribute("source"));
ret.setSteward((String) relationshipAttributes.getAttribute("steward"));
Object status = relationshipAttributes.getAttribute("status");
if (status instanceof String) {
ret.setStatus(AtlasTermRelationshipStatus.valueOf((String) status));
} else if (status instanceof AtlasTermRelationshipStatus) {
ret.setStatus((AtlasTermRelationshipStatus) status);
}
}
return ret;
}
protected AtlasRelatedObjectId termIdToRelatedObjectId(AtlasRelatedTermHeader relatedTermId) {
AtlasRelatedObjectId ret = new AtlasRelatedObjectId();
ret.setGuid(relatedTermId.getTermGuid());
ret.setRelationshipGuid(relatedTermId.getRelationGuid());
AtlasStruct relationshipAttributes = new AtlasStruct();
relationshipAttributes.setAttribute("description", relatedTermId.getDescription());
relationshipAttributes.setAttribute("expression", relatedTermId.getExpression());
relationshipAttributes.setAttribute("source", relatedTermId.getSource());
relationshipAttributes.setAttribute("steward", relatedTermId.getSteward());
relationshipAttributes.setAttribute("status", relatedTermId.getStatus().name());
ret.setRelationshipAttributes(relationshipAttributes);
return ret;
}
protected AtlasRelatedCategoryHeader constructRelatedCategoryId(AtlasRelatedObjectId relatedObjectId) {
AtlasRelatedCategoryHeader ret = new AtlasRelatedCategoryHeader();
ret.setCategoryGuid(relatedObjectId.getGuid());
ret.setRelationGuid(relatedObjectId.getRelationshipGuid());
AtlasStruct relationshipAttributes = relatedObjectId.getRelationshipAttributes();
if (relationshipAttributes != null) {
ret.setDescription((String) relationshipAttributes.getAttribute("description"));
}
return ret;
}
protected AtlasRelatedObjectId relatedCategoryIdToRelatedObjectId(AtlasRelatedCategoryHeader relatedCategoryId) {
AtlasRelatedObjectId ret = new AtlasRelatedObjectId();
ret.setGuid(relatedCategoryId.getCategoryGuid());
ret.setRelationshipGuid(relatedCategoryId.getRelationGuid());
AtlasStruct relationshipAttributes = new AtlasStruct();
relationshipAttributes.setAttribute("description", relatedCategoryId.getDescription());
ret.setRelationshipAttributes(relationshipAttributes);
return ret;
}
protected AtlasGlossaryHeader constructGlossaryId(AtlasRelatedObjectId relatedObjectId) {
AtlasGlossaryHeader ret = new AtlasGlossaryHeader();
ret.setGlossaryGuid(relatedObjectId.getGuid());
ret.setRelationGuid(relatedObjectId.getRelationshipGuid());
return ret;
}
protected AtlasRelatedObjectId glossaryIdToRelatedObjectId(AtlasGlossaryHeader glossaryId) {
AtlasRelatedObjectId ret = new AtlasRelatedObjectId();
ret.setGuid(glossaryId.getGlossaryGuid());
ret.setRelationshipGuid(glossaryId.getRelationGuid());
return ret;
}
protected AtlasTermCategorizationHeader constructTermCategorizationId(final AtlasRelatedObjectId category) {
AtlasTermCategorizationHeader ret = new AtlasTermCategorizationHeader();
ret.setCategoryGuid(category.getGuid());
ret.setRelationGuid(category.getRelationshipGuid());
AtlasStruct relationshipAttributes = category.getRelationshipAttributes();
if (relationshipAttributes != null) {
ret.setDescription((String) relationshipAttributes.getAttribute("description"));
Object status = relationshipAttributes.getAttribute("status");
if (status instanceof AtlasTermRelationshipStatus) {
ret.setStatus((AtlasTermRelationshipStatus) status);
} else if (status instanceof String) {
ret.setStatus(AtlasTermRelationshipStatus.valueOf((String) status));
}
}
return ret;
}
protected Set<AtlasRelatedTermHeader> toRelatedTermIdsSet(Object relatedObjectIds) {
Set<AtlasRelatedTermHeader> ret = null;
if (relatedObjectIds instanceof Collection) {
ret = new HashSet<>();
for (Object t : (Collection) relatedObjectIds) {
if (t instanceof AtlasRelatedObjectId) {
if (((AtlasRelatedObjectId) t).getRelationshipStatus() == AtlasRelationship.Status.ACTIVE) {
ret.add(constructRelatedTermId((AtlasRelatedObjectId) t));
}
}
}
}
return ret;
}
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.repository.ogm.glossary;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.glossary.AtlasGlossaryCategory;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasRelatedObjectId;
import org.apache.atlas.model.instance.AtlasRelationship;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@Component
public class AtlasGlossaryCategoryDTO extends AbstractGlossaryDTO<AtlasGlossaryCategory> {
private static final Logger LOG = LoggerFactory.getLogger(AtlasGlossaryCategoryDTO.class);
@Inject
protected AtlasGlossaryCategoryDTO(final AtlasTypeRegistry typeRegistry) {
super(typeRegistry, AtlasGlossaryCategory.class, true);
}
@Override
public AtlasGlossaryCategory from(final AtlasEntity entity) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasGlossaryCategoryDTO.from()", entity);
}
Objects.requireNonNull(entity, "entity");
AtlasGlossaryCategory ret = new AtlasGlossaryCategory();
ret.setGuid(entity.getGuid());
ret.setQualifiedName((String) entity.getAttribute("qualifiedName"));
ret.setDisplayName((String) entity.getAttribute("displayName"));
ret.setShortDescription((String) entity.getAttribute("shortDescription"));
ret.setLongDescription((String) entity.getAttribute("longDescription"));
Object anchor = entity.getRelationshipAttribute("anchor");
if (anchor instanceof AtlasRelatedObjectId) {
LOG.debug("Processing anchor");
if (((AtlasRelatedObjectId) anchor).getRelationshipStatus() == AtlasRelationship.Status.ACTIVE) {
ret.setAnchor(constructGlossaryId((AtlasRelatedObjectId) anchor));
}
}
Object parentCategory = entity.getRelationshipAttribute("parentCategory");
if (parentCategory instanceof AtlasRelatedObjectId) {
LOG.debug("Processing parentCategory");
if (((AtlasRelatedObjectId) parentCategory).getRelationshipStatus() == AtlasRelationship.Status.ACTIVE) {
ret.setParentCategory(constructRelatedCategoryId((AtlasRelatedObjectId) parentCategory));
}
}
Object childrenCategories = entity.getRelationshipAttribute("childrenCategories");
if (childrenCategories instanceof Collection) {
LOG.debug("Processing childrenCategories");
for (Object child : (Collection) childrenCategories) {
if (child instanceof AtlasRelatedObjectId) {
if (((AtlasRelatedObjectId) child).getRelationshipStatus() == AtlasRelationship.Status.ACTIVE) {
ret.addChild(constructRelatedCategoryId((AtlasRelatedObjectId) child));
}
}
}
}
Object terms = entity.getRelationshipAttribute("terms");
if (terms instanceof Collection) {
LOG.debug("Processing terms");
for (Object term : (Collection) terms) {
if (term instanceof AtlasRelatedObjectId) {
if (((AtlasRelatedObjectId) term).getRelationshipStatus() == AtlasRelationship.Status.ACTIVE) {
ret.addTerm(constructRelatedTermId((AtlasRelatedObjectId) term));
}
}
}
}
return ret;
}
@Override
public AtlasGlossaryCategory from(final AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasGlossaryCategoryDTO.from()", entityWithExtInfo);
}
Objects.requireNonNull(entityWithExtInfo, "entity");
AtlasGlossaryCategory ret = from(entityWithExtInfo.getEntity());
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasGlossaryCategoryDTO.from() : {}", ret);
}
return ret;
}
@Override
public AtlasEntity toEntity(final AtlasGlossaryCategory obj) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasGlossaryCategoryDTO.toEntity()", obj);
}
Objects.requireNonNull(obj, "atlasGlossaryCategory");
Objects.requireNonNull(obj.getQualifiedName(), "atlasGlossaryCategory qualifiedName must be specified");
Objects.requireNonNull(obj.getAnchor(), "atlasGlossaryCategory anchor must be specified");
AtlasEntity ret = getDefaultAtlasEntity(obj);
ret.setAttribute("qualifiedName", obj.getQualifiedName());
ret.setAttribute("displayName", obj.getDisplayName());
ret.setAttribute("shortDescription", obj.getShortDescription());
ret.setAttribute("longDescription", obj.getLongDescription());
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasGlossaryCategoryDTO.toEntity() : {}", ret);
}
return ret;
}
@Override
public AtlasEntity.AtlasEntityWithExtInfo toEntityWithExtInfo(final AtlasGlossaryCategory obj) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasGlossaryCategoryDTO.toEntityWithExtInfo()", obj);
}
Objects.requireNonNull(obj, "atlasGlossaryCategory");
AtlasEntity.AtlasEntityWithExtInfo ret = new AtlasEntity.AtlasEntityWithExtInfo(toEntity(obj));
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasGlossaryCategoryDTO.toEntityWithExtInfo() : {}", ret);
}
return ret;
}
@Override
public Map<String, Object> getUniqueAttributes(final AtlasGlossaryCategory obj) {
Map<String, Object> ret = new HashMap<>();
ret.put("qualifiedName", obj.getQualifiedName());
return ret;
}
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.repository.ogm.glossary;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.glossary.AtlasGlossary;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasRelatedObjectId;
import org.apache.atlas.model.instance.AtlasRelationship;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@Component
public class AtlasGlossaryDTO extends AbstractGlossaryDTO<AtlasGlossary> {
private static final Logger LOG = LoggerFactory.getLogger(AtlasGlossaryDTO.class);
@Inject
public AtlasGlossaryDTO(AtlasTypeRegistry typeRegistry) {
super(typeRegistry, AtlasGlossary.class, true);
}
@Override
public AtlasGlossary from(final AtlasEntity entity) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasGlossaryDTO.from()", entity);
}
Objects.requireNonNull(entity, "entity");
AtlasGlossary ret = new AtlasGlossary();
ret.setGuid(entity.getGuid());
ret.setQualifiedName((String) entity.getAttribute("qualifiedName"));
ret.setDisplayName((String) entity.getAttribute("displayName"));
ret.setShortDescription((String) entity.getAttribute("shortDescription"));
ret.setLongDescription((String) entity.getAttribute("longDescription"));
ret.setLanguage((String) entity.getAttribute("language"));
ret.setUsage((String) entity.getAttribute("usage"));
Object categoriesAttr = entity.getRelationshipAttribute("categories");
Object termsAttr = entity.getRelationshipAttribute("terms");
// Populate categories
if (Objects.nonNull(categoriesAttr)) {
LOG.debug("Processing categories");
if (categoriesAttr instanceof Collection) {
for (Object o : (Collection) categoriesAttr) {
if (o instanceof AtlasRelatedObjectId) {
if (((AtlasRelatedObjectId) o).getRelationshipStatus() == AtlasRelationship.Status.ACTIVE) {
ret.addCategory(constructRelatedCategoryId((AtlasRelatedObjectId) o));
}
}
}
}
}
// Populate terms
if (Objects.nonNull(termsAttr)) {
LOG.debug("Processing terms");
if (termsAttr instanceof Collection) {
for (Object o : (Collection) termsAttr) {
if (o instanceof AtlasRelatedObjectId) {
if (((AtlasRelatedObjectId) o).getRelationshipStatus() == AtlasRelationship.Status.ACTIVE) {
ret.addTerm(constructRelatedTermId((AtlasRelatedObjectId) o));
}
}
}
}
}
return ret;
}
@Override
public AtlasGlossary from(final AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasGlossaryDTO.from()",entityWithExtInfo);
}
Objects.requireNonNull(entityWithExtInfo, "entity");
AtlasGlossary ret = from(entityWithExtInfo.getEntity());
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasGlossaryDTO.from() : {}", ret);
}
return ret;
}
@Override
public AtlasEntity toEntity(final AtlasGlossary obj) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasGlossaryDTO.toEntity()", obj);
}
Objects.requireNonNull(obj, "atlasGlossary");
Objects.requireNonNull(obj.getQualifiedName(), "atlasGlossary qualifiedName must be specified");
AtlasEntity ret = getDefaultAtlasEntity(obj);
ret.setAttribute("qualifiedName", obj.getQualifiedName());
ret.setAttribute("displayName", obj.getDisplayName());
ret.setAttribute("shortDescription", obj.getShortDescription());
ret.setAttribute("longDescription", obj.getLongDescription());
ret.setAttribute("language", obj.getLanguage());
ret.setAttribute("usage", obj.getUsage());
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasGlossaryDTO.toEntity() : {}", ret);
}
return ret;
}
@Override
public AtlasEntity.AtlasEntityWithExtInfo toEntityWithExtInfo(final AtlasGlossary obj) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasGlossaryDTO.toEntityWithExtInfo()", obj);
}
Objects.requireNonNull(obj, "atlasGlossary");
AtlasEntity entity = toEntity(obj);
AtlasEntity.AtlasEntityWithExtInfo ret = new AtlasEntity.AtlasEntityWithExtInfo(entity);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasGlossaryDTO.toEntityWithExtInfo() : {}", ret);
}
return ret;
}
@Override
public Map<String, Object> getUniqueAttributes(final AtlasGlossary obj) {
Map<String, Object> ret = new HashMap<>();
ret.put("qualifiedName", obj.getQualifiedName());
return ret;
}
}
......@@ -15,21 +15,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.repository.ogm;
package org.apache.atlas.repository.ogm.profiles;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.discovery.SearchParameters;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import org.apache.atlas.model.profile.AtlasUserSavedSearch;
import org.apache.atlas.repository.ogm.AbstractDataTransferObject;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.util.HashMap;
import java.util.Map;
@Component
public class AtlasSavedSearchDTO extends AbstractDataTransferObject<AtlasUserSavedSearch> {
private static final String PROPERTY_NAME = "name";
private static final String PROPERTY_OWNER_NAME = "ownerName";
......@@ -38,8 +42,9 @@ public class AtlasSavedSearchDTO extends AbstractDataTransferObject<AtlasUserSav
private static final String PROPERTY_SEARCH_TYPE = "searchType";
private static final String PROPERTY_UI_PARAMETERS = "uiParameters";
@Inject
public AtlasSavedSearchDTO(AtlasTypeRegistry typeRegistry) {
super(typeRegistry, AtlasUserSavedSearch.class);
super(typeRegistry, AtlasUserSavedSearch.class, true);
}
@Override
......
......@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.repository.ogm;
package org.apache.atlas.repository.ogm.profiles;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasEntity;
......@@ -23,10 +23,14 @@ import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.profile.AtlasUserProfile;
import org.apache.atlas.model.profile.AtlasUserSavedSearch;
import org.apache.atlas.repository.ogm.AbstractDataTransferObject;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.util.*;
@Component
public class AtlasUserProfileDTO extends AbstractDataTransferObject<AtlasUserProfile> {
private final String PROPERTY_USER_NAME = "name";
private final String PROPERTY_FULL_NAME = "fullName";
......@@ -34,8 +38,9 @@ public class AtlasUserProfileDTO extends AbstractDataTransferObject<AtlasUserPro
private final AtlasSavedSearchDTO savedSearchDTO;
@Inject
public AtlasUserProfileDTO(AtlasTypeRegistry typeRegistry, AtlasSavedSearchDTO savedSearchDTO) {
super(typeRegistry, AtlasUserProfile.class);
super(typeRegistry, AtlasUserProfile.class, true);
this.savedSearchDTO = savedSearchDTO;
}
......
......@@ -60,16 +60,16 @@ public class AtlasEntityChangeNotifier {
private final Set<EntityChangeListener> entityChangeListeners;
private final Set<EntityChangeListenerV2> entityChangeListenersV2;
private final AtlasInstanceConverter instanceConverter;
private final FullTextMapperV2 fullTextMapperV2;
@Inject
private FullTextMapperV2 fullTextMapperV2;
@Inject
public AtlasEntityChangeNotifier(Set<EntityChangeListener> entityChangeListeners, Set<EntityChangeListenerV2> entityChangeListenersV2,
AtlasInstanceConverter instanceConverter) {
AtlasInstanceConverter instanceConverter, final FullTextMapperV2 fullTextMapperV2) {
this.entityChangeListeners = entityChangeListeners;
this.entityChangeListenersV2 = entityChangeListenersV2;
this.instanceConverter = instanceConverter;
this.fullTextMapperV2 = fullTextMapperV2;
}
public void onEntitiesMutated(EntityMutationResponse entityMutationResponse, boolean isImport) throws AtlasBaseException {
......
......@@ -20,6 +20,7 @@ package org.apache.atlas.repository.store.graph.v1;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.SortOrder;
import org.apache.atlas.discovery.SearchProcessor;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
......@@ -54,6 +55,7 @@ import java.util.Set;
import static org.apache.atlas.repository.Constants.INDEX_SEARCH_VERTEX_PREFIX_DEFAULT;
import static org.apache.atlas.repository.Constants.INDEX_SEARCH_VERTEX_PREFIX_PROPERTY;
import static org.apache.atlas.repository.graphdb.AtlasGraphQuery.SortOrder.*;
/**
* Utility methods for Graph.
......@@ -338,20 +340,30 @@ public class AtlasGraphUtilsV1 {
return vertex;
}
public static List<String> findEntityGUIDsByType(String typename) {
public static List<String> findEntityGUIDsByType(String typename, SortOrder sortOrder) {
AtlasGraphQuery query = AtlasGraphProvider.getGraphInstance().query()
.has(Constants.ENTITY_TYPE_PROPERTY_KEY, typename);
if (sortOrder != null) {
AtlasGraphQuery.SortOrder qrySortOrder = sortOrder == SortOrder.ASCENDING ? ASC : DESC;
query.orderBy(Constants.QUALIFIED_NAME, qrySortOrder);
}
Iterator<AtlasVertex> results = query.vertices().iterator();
ArrayList<String> ret = new ArrayList<>();
if (!results.hasNext()) {
return Collections.emptyList();
}
ArrayList<String> entityList = new ArrayList<>();
while (results.hasNext()) {
entityList.add(getIdFromVertex(results.next()));
ret.add(getIdFromVertex(results.next()));
}
return entityList;
return ret;
}
public static List<String> findEntityGUIDsByType(String typename) {
return findEntityGUIDsByType(typename, null);
}
public static boolean relationshipTypeHasInstanceEdges(String typeName) throws AtlasBaseException {
......
......@@ -21,6 +21,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TimeBoundary;
import org.apache.atlas.model.glossary.relations.AtlasTermAssignmentHeader;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasClassification.PropagationState;
import org.apache.atlas.model.instance.AtlasEntity;
......@@ -68,6 +69,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static org.apache.atlas.model.instance.AtlasClassification.PropagationState.ACTIVE;
import static org.apache.atlas.model.instance.AtlasClassification.PropagationState.DELETED;
......@@ -220,6 +222,11 @@ public final class EntityGraphRetriever {
ret.setClassifications(classifications);
ret.setClassificationNames(classificationNames);
}
if (CollectionUtils.isNotEmpty(entity.getMeanings())) {
ret.setMeanings(entity.getMeanings());
ret.setMeaningNames(entity.getMeanings().stream().map(AtlasTermAssignmentHeader::getDisplayText).collect(Collectors.toList()));
}
}
return ret;
......@@ -359,6 +366,8 @@ public final class EntityGraphRetriever {
ret.setStatus(GraphHelper.getStatus(entityVertex));
ret.setClassificationNames(getAllTraitNames(entityVertex));
// TODO: Add the term mapping here
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
if (entityType != null) {
......
......@@ -144,11 +144,11 @@ public class UserProfileService {
public void deleteUserProfile(String userName) throws AtlasBaseException {
AtlasUserProfile profile = getUserProfile(userName);
dataAccess.deleteUsingGuid(profile.getGuid());
dataAccess.delete(profile.getGuid());
}
public void deleteSavedSearch(String guid) throws AtlasBaseException {
dataAccess.deleteUsingGuid(guid);
dataAccess.delete(guid);
}
public void deleteSearchBySearchName(String userName, String searchName) throws AtlasBaseException {
......
......@@ -28,6 +28,7 @@ import org.apache.atlas.discovery.AtlasDiscoveryService;
import org.apache.atlas.discovery.AtlasLineageService;
import org.apache.atlas.discovery.EntityDiscoveryService;
import org.apache.atlas.discovery.EntityLineageService;
import org.apache.atlas.glossary.GlossaryService;
import org.apache.atlas.graph.GraphSandboxUtil;
import org.apache.atlas.listener.EntityChangeListener;
import org.apache.atlas.listener.EntityChangeListenerV2;
......@@ -38,13 +39,21 @@ import org.apache.atlas.repository.audit.EntityAuditRepository;
import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.impexp.ExportService;
import org.apache.atlas.repository.ogm.profiles.AtlasSavedSearchDTO;
import org.apache.atlas.repository.ogm.profiles.AtlasUserProfileDTO;
import org.apache.atlas.repository.ogm.DTORegistry;
import org.apache.atlas.repository.ogm.DataAccess;
import org.apache.atlas.repository.ogm.DataTransferObject;
import org.apache.atlas.repository.ogm.glossary.AtlasGlossaryCategoryDTO;
import org.apache.atlas.repository.ogm.glossary.AtlasGlossaryDTO;
import org.apache.atlas.repository.ogm.glossary.AtlasGlossaryTermDTO;
import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.repository.store.graph.AtlasRelationshipStore;
import org.apache.atlas.repository.store.graph.BulkImporter;
import org.apache.atlas.repository.store.graph.v1.AtlasEntityChangeNotifier;
import org.apache.atlas.repository.store.graph.v1.AtlasEntityStoreV1;
import org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1;
import org.apache.atlas.repository.store.graph.v1.AtlasRelationshipStoreV1;
import org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1;
import org.apache.atlas.repository.store.graph.v1.BulkImporterImpl;
import org.apache.atlas.repository.store.graph.v1.DeleteHandlerV1;
import org.apache.atlas.repository.store.graph.v1.EntityGraphMapper;
......@@ -151,6 +160,20 @@ public class TestModules {
Multibinder.newSetBinder(binder(), EntityChangeListenerV2.class);
entityChangeListenerV2Binder.addBinding().to(EntityAuditListenerV2.class);
// OGM related mappings
Multibinder<DataTransferObject> availableDTOs = Multibinder.newSetBinder(binder(), DataTransferObject.class);
availableDTOs.addBinding().to(AtlasUserProfileDTO.class);
availableDTOs.addBinding().to(AtlasSavedSearchDTO.class);
availableDTOs.addBinding().to(AtlasGlossaryDTO.class);
availableDTOs.addBinding().to(AtlasGlossaryTermDTO.class);
availableDTOs.addBinding().to(AtlasGlossaryCategoryDTO.class);
bind(DTORegistry.class).asEagerSingleton();
bind(DataAccess.class).asEagerSingleton();
// Glossary related bindings
bind(GlossaryService.class).asEagerSingleton();
final GraphTransactionInterceptor graphTransactionInterceptor = new GraphTransactionInterceptor(new AtlasGraphProvider().get());
requestInjection(graphTransactionInterceptor);
bindInterceptor(Matchers.any(), Matchers.annotatedWith(GraphTransaction.class), graphTransactionInterceptor);
......
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.apache.atlas.glossary;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static org.testng.Assert.assertEquals;
public class PaginationHelperTest {
@DataProvider
public Object[][] paginationProvider() {
return new Object[][] {
// maxSize, offset, limit, expected
{10, 0 , 5, 5},
{10, 0 , -1, 10},
{10, -1 , -1, 10},
{10, -1 , 5, 5},
{10, -1 , 11, 10},
{10, 5 , 11, 5},
{10, 2 , 11, 8},
{10, 8 , 11, 2},
{10, 5 , 1, 1},
{10, 9 , 1, 1},
{10, 10 , 5, 0},
{10, 11 , 5, 0},
{10, 20 , -1, 0},
{5, 6 , -1, 0},
{0, -1 , -1, 0},
{0, 5 , 10, 0},
{0, 0 , 10, 0},
{1, -1 , -1, 1},
{1, 5 , 10, 0},
{1, 0 , 10, 1},
};
}
@Test(dataProvider = "paginationProvider")
public void testPaginationHelper(int maxSize, int offset, int limit, int expectedSize) {
List<Integer> intList = IntStream.range(0, maxSize).boxed().collect(Collectors.toCollection(() -> new ArrayList<>(maxSize)));
GlossaryService.PaginationHelper helper = new GlossaryService.PaginationHelper<>(intList, offset, limit);
assertEquals(helper.getPaginatedList().size(), expectedSize);
}
}
......@@ -29,6 +29,7 @@ import org.apache.atlas.repository.store.bootstrap.AtlasTypeDefStoreInitializer;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.utils.AtlasJson;
import org.apache.atlas.utils.TestResourceFileUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
......@@ -38,10 +39,12 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import static org.testng.Assert.assertEquals;
......@@ -56,6 +59,36 @@ public class ZipFileResourceTestUtils {
return TestResourceFileUtils.getFileInputStream(fileName);
}
public static List<String> getAllModels(String dirName) throws IOException {
List<String> ret = null;
File topModelsDir = new File(System.getProperty("user.dir") + "/../addons/models");
File[] topModelsDirContents = topModelsDir.exists() ? topModelsDir.listFiles() : null;
assertTrue(topModelsDirContents != null, topModelsDir.getAbsolutePath() + ": unable to find/read directory");
if(topModelsDirContents != null) {
Arrays.sort(topModelsDirContents);
for (File modelDir : topModelsDirContents) {
if (modelDir.exists() && modelDir.isDirectory() && modelDir.getAbsolutePath().contains(dirName)) {
File[] models = modelDir.listFiles();
Arrays.sort(models);
ret = new ArrayList<>();
for (File model : Objects.requireNonNull(models)) {
ret.add(getFileContents(modelDir, model.getName()));
}
}
if (ret != null && ret.size() > 0) {
break;
}
}
} else {
throw new IOException("Unable to retrieve model contents.");
}
return ret;
}
public static String getModelJson(String fileName) throws IOException {
String ret = null;
File topModelsDir = new File(System.getProperty("user.dir") + "/../addons/models");
......@@ -145,12 +178,19 @@ public class ZipFileResourceTestUtils {
return r;
}
public static void loadModelFromJson(String fileName, AtlasTypeDefStore typeDefStore, AtlasTypeRegistry typeRegistry) throws IOException, AtlasBaseException {
AtlasTypesDef typesFromJson = getAtlasTypesDefFromFile(fileName);
createTypesAsNeeded(typesFromJson, typeDefStore, typeRegistry);
}
public static void loadAllModels(String dirName, AtlasTypeDefStore typeDefStore, AtlasTypeRegistry typeRegistry) throws IOException, AtlasBaseException {
List<String> allModels = getAllModels(dirName);
for (String model : allModels) {
AtlasTypesDef typesFromJson = AtlasJson.fromJson(model, AtlasTypesDef.class);
createTypesAsNeeded(typesFromJson, typeDefStore, typeRegistry);
}
}
public static void loadModelFromResourcesJson(String fileName, AtlasTypeDefStore typeDefStore, AtlasTypeRegistry typeRegistry) throws IOException, AtlasBaseException {
AtlasTypesDef typesFromJson = getAtlasTypesDefFromResourceFile(fileName);
createTypesAsNeeded(typesFromJson, typeDefStore, typeRegistry);
......
......@@ -24,6 +24,7 @@ import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.discovery.SearchParameters;
import org.apache.atlas.model.profile.AtlasUserProfile;
import org.apache.atlas.model.profile.AtlasUserSavedSearch;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.util.FilterUtil;
......@@ -39,11 +40,15 @@ import javax.inject.Inject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.apache.atlas.graph.GraphSandboxUtil.useLocalSolr;
import static org.apache.atlas.model.profile.AtlasUserSavedSearch.SavedSearchType.BASIC;
import static org.apache.atlas.repository.impexp.ZipFileResourceTestUtils.loadModelFromJson;
import static org.testng.Assert.*;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
@Guice(modules = TestModules.TestOnlyModule.class)
public class UserProfileServiceTest {
......@@ -80,7 +85,8 @@ public class UserProfileServiceTest {
filteredTypeDefs = typeDefStore.searchTypesDef(searchFilter);
assertNotNull(filteredTypeDefs);
assertEquals(filteredTypeDefs.getEntityDefs().size(), maxTypeDefs - 3);
Optional<AtlasEntityDef> anyInternal = filteredTypeDefs.getEntityDefs().stream().filter(e -> e.getSuperTypes().contains("__internal")).findAny();
assertFalse(anyInternal.isPresent());
}
@Test
......
......@@ -17,9 +17,7 @@
*/
package org.apache.atlas.notification;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.listener.EntityChangeListenerV2;
import org.apache.atlas.model.instance.AtlasClassification;
......@@ -46,26 +44,23 @@ import java.util.Set;
import static org.apache.atlas.notification.NotificationEntityChangeListener.ATLAS_ENTITY_NOTIFICATION_PROPERTY;
import static org.apache.atlas.notification.NotificationInterface.NotificationType.ENTITIES;
import static org.apache.atlas.v1.model.notification.EntityNotificationV2.OperationType.CLASSIFICATION_ADD;
import static org.apache.atlas.v1.model.notification.EntityNotificationV2.OperationType.CLASSIFICATION_DELETE;
import static org.apache.atlas.v1.model.notification.EntityNotificationV2.OperationType.CLASSIFICATION_UPDATE;
import static org.apache.atlas.repository.graph.GraphHelper.isInternalType;
import static org.apache.atlas.v1.model.notification.EntityNotificationV2.OperationType.ENTITY_CREATE;
import static org.apache.atlas.v1.model.notification.EntityNotificationV2.OperationType.ENTITY_DELETE;
import static org.apache.atlas.v1.model.notification.EntityNotificationV2.OperationType.ENTITY_UPDATE;
import static org.apache.atlas.v1.model.notification.EntityNotificationV2.OperationType.*;
@Component
public class EntityNotificationListenerV2 implements EntityChangeListenerV2 {
private final AtlasTypeRegistry typeRegistry;
private final NotificationInterface notificationInterface;
private final Configuration configuration;
private final Map<String, List<String>> notificationAttributesCache = new HashMap<>();
private static Configuration APPLICATION_PROPERTIES = null;
@Inject
public EntityNotificationListenerV2(AtlasTypeRegistry typeRegistry, NotificationInterface notificationInterface) {
public EntityNotificationListenerV2(AtlasTypeRegistry typeRegistry,
NotificationInterface notificationInterface,
Configuration configuration) {
this.typeRegistry = typeRegistry;
this.notificationInterface = notificationInterface;
this.configuration = configuration;
}
@Override
......@@ -186,13 +181,11 @@ public class EntityNotificationListenerV2 implements EntityChangeListenerV2 {
private List<String> getNotificationAttributes(String entityType) {
List<String> ret = null;
initApplicationProperties();
if (notificationAttributesCache.containsKey(entityType)) {
ret = notificationAttributesCache.get(entityType);
} else if (APPLICATION_PROPERTIES != null) {
String[] notificationAttributes = APPLICATION_PROPERTIES.getStringArray(ATLAS_ENTITY_NOTIFICATION_PROPERTY + "." +
entityType + "." + "attributes.include");
} else if (configuration != null) {
String attributesToIncludeKey = ATLAS_ENTITY_NOTIFICATION_PROPERTY + "." + entityType + "." + "attributes.include";
String[] notificationAttributes = configuration.getStringArray(attributesToIncludeKey);
if (notificationAttributes != null) {
ret = Arrays.asList(notificationAttributes);
......@@ -203,14 +196,4 @@ public class EntityNotificationListenerV2 implements EntityChangeListenerV2 {
return ret;
}
private void initApplicationProperties() {
if (APPLICATION_PROPERTIES == null) {
try {
APPLICATION_PROPERTIES = ApplicationProperties.get();
} catch (AtlasException ex) {
// ignore
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment