Commit e0c6b98e by Vimal Sharma Committed by Madhan Neethiraj

ATLAS-1460: v2 search API updated to return name/description/owner and…

ATLAS-1460: v2 search API updated to return name/description/owner and classification names in result Signed-off-by: 's avatarMadhan Neethiraj <madhan@apache.org>
parent 53f88222
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
*/ */
package org.apache.atlas.model.discovery; package org.apache.atlas.model.discovery;
import org.apache.atlas.model.instance.AtlasEntityHeader; import org.apache.atlas.model.instance.AtlasEntityHeaderWithAssociations;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.annotate.JsonAutoDetect; import org.codehaus.jackson.annotate.JsonAutoDetect;
...@@ -42,11 +42,11 @@ import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONL ...@@ -42,11 +42,11 @@ import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONL
@XmlRootElement @XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY) @XmlAccessorType(XmlAccessType.PROPERTY)
public class AtlasSearchResult implements Serializable { public class AtlasSearchResult implements Serializable {
private String queryText; private String queryText;
private AtlasQueryType queryType; private AtlasQueryType queryType;
private List<AtlasEntityHeader> entities; private List<AtlasEntityHeaderWithAssociations> entities;
private AttributeSearchResult attributes; private AttributeSearchResult attributes;
private List<AtlasFullTextResult> fullTextResult; private List<AtlasFullTextResult> fullTextResult;
public AtlasSearchResult() {} public AtlasSearchResult() {}
...@@ -66,9 +66,9 @@ public class AtlasSearchResult implements Serializable { ...@@ -66,9 +66,9 @@ public class AtlasSearchResult implements Serializable {
public void setQueryType(AtlasQueryType queryType) { this.queryType = queryType; } public void setQueryType(AtlasQueryType queryType) { this.queryType = queryType; }
public List<AtlasEntityHeader> getEntities() { return entities; } public List<AtlasEntityHeaderWithAssociations> getEntities() { return entities; }
public void setEntities(List<AtlasEntityHeader> entities) { this.entities = entities; } public void setEntities(List<AtlasEntityHeaderWithAssociations> entities) { this.entities = entities; }
public AttributeSearchResult getAttributes() { return attributes; } public AttributeSearchResult getAttributes() { return attributes; }
...@@ -104,7 +104,7 @@ public class AtlasSearchResult implements Serializable { ...@@ -104,7 +104,7 @@ public class AtlasSearchResult implements Serializable {
'}'; '}';
} }
public void addEntity(AtlasEntityHeader newEntity) { public void addEntity(AtlasEntityHeaderWithAssociations newEntity) {
if (entities == null) { if (entities == null) {
entities = new ArrayList<>(); entities = new ArrayList<>();
} }
...@@ -117,13 +117,13 @@ public class AtlasSearchResult implements Serializable { ...@@ -117,13 +117,13 @@ public class AtlasSearchResult implements Serializable {
} }
} }
public void removeEntity(AtlasEntityHeader entity) { public void removeEntity(AtlasEntityHeaderWithAssociations entity) {
List<AtlasEntityHeader> entities = this.entities; List<AtlasEntityHeaderWithAssociations> entities = this.entities;
if (CollectionUtils.isNotEmpty(entities)) { if (CollectionUtils.isNotEmpty(entities)) {
Iterator<AtlasEntityHeader> iter = entities.iterator(); Iterator<AtlasEntityHeaderWithAssociations> iter = entities.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
AtlasEntityHeader currEntity = iter.next(); AtlasEntityHeaderWithAssociations currEntity = iter.next();
if (StringUtils.equals(currEntity.getGuid(), entity.getGuid())) { if (StringUtils.equals(currEntity.getGuid(), entity.getGuid())) {
iter.remove(); iter.remove();
} }
...@@ -184,19 +184,19 @@ public class AtlasSearchResult implements Serializable { ...@@ -184,19 +184,19 @@ public class AtlasSearchResult implements Serializable {
@XmlRootElement @XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY) @XmlAccessorType(XmlAccessType.PROPERTY)
public static class AtlasFullTextResult { public static class AtlasFullTextResult {
AtlasEntityHeader entity; AtlasEntityHeaderWithAssociations entity;
Double score; Double score;
public AtlasFullTextResult() {} public AtlasFullTextResult() {}
public AtlasFullTextResult(AtlasEntityHeader entity, Double score) { public AtlasFullTextResult(AtlasEntityHeaderWithAssociations entity, Double score) {
this.entity = entity; this.entity = entity;
this.score = score; this.score = score;
} }
public AtlasEntityHeader getEntity() { return entity; } public AtlasEntityHeaderWithAssociations getEntity() { return entity; }
public void setEntity(AtlasEntityHeader entity) { this.entity = entity; } public void setEntity(AtlasEntityHeaderWithAssociations entity) { this.entity = entity; }
public Double getScore() { return score; } public Double getScore() { return score; }
......
/**
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.model.instance;
import org.apache.atlas.model.PList;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;
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.List;
import java.util.Map;
import java.util.Objects;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY;
/**
* An instance of an entity and its associations - like hive_table, hive_database.
*/
@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE)
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AtlasEntityHeaderWithAssociations extends AtlasEntityHeader implements Serializable{
private static final long serialVersionUID = 1L;
private List<String> classificationNames;
public AtlasEntityHeaderWithAssociations(){
this(null, null);
}
public AtlasEntityHeaderWithAssociations(AtlasEntityDef entityDef) {
this(entityDef != null ? entityDef.getName() : null, null);
}
public AtlasEntityHeaderWithAssociations(String typeName, Map<String, Object> attributes) {
super(typeName, attributes);
setClassificationNames(null);
}
public AtlasEntityHeaderWithAssociations(AtlasEntityHeaderWithAssociations other) {
super(other);
if (other != null) {
setClassificationNames(other.getClassificationNames());
}
}
public List<String> getClassificationNames(){
return classificationNames;
}
public void setClassificationNames(List<String> classificationNames) {
this.classificationNames = classificationNames;
}
@Override
public StringBuilder toString(StringBuilder sb) {
if (sb == null) {
sb = new StringBuilder();
}
sb.append("AtlasEntityHeaderwithAssociations{");
sb.append(", classificationNames=[");
dumpObjects(classificationNames, sb);
sb.append("],");
super.toString(sb);
sb.append('}');
return sb;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
AtlasEntityHeaderWithAssociations that = (AtlasEntityHeaderWithAssociations) o;
return Objects.equals(classificationNames, that.classificationNames);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), classificationNames);
}
@Override
public String toString() {
return toString(new StringBuilder()).toString();
}
/**
* REST serialization friendly list.
*/
@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)
public static class AtlasEntityHeadersWithAssociations extends PList<AtlasEntityHeaderWithAssociations> {
private static final long serialVersionUID = 1L;
public AtlasEntityHeadersWithAssociations() {
super();
}
public AtlasEntityHeadersWithAssociations(List<AtlasEntityHeaderWithAssociations> list) {
super(list);
}
public AtlasEntityHeadersWithAssociations(List list, long startIndex, int pageSize, long totalCount,
SearchFilter.SortType sortType, String sortBy) {
super(list, startIndex, pageSize, totalCount, sortType, sortBy);
}
}
}
...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai) ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES: ALL CHANGES:
ATLAS-1460 v2 search API updated to return name/description/owner and classification names in result (vimalsharma via mneethiraj)
ATLAS-1434 fixed unit test to use correct type names; updated error message per review comments (ashutoshm via mneethiraj) ATLAS-1434 fixed unit test to use correct type names; updated error message per review comments (ashutoshm via mneethiraj)
ATLAS-1391 Add exclusion mechanism for Atlas audit mechanism (guptaneeru via svimal2106) ATLAS-1391 Add exclusion mechanism for Atlas audit mechanism (guptaneeru via svimal2106)
ATLAS-1280 Atlas changes to support Hive hook for Hive2 (mneethiraj via svimal2106) ATLAS-1280 Atlas changes to support Hive hook for Hive2 (mneethiraj via svimal2106)
......
...@@ -26,7 +26,7 @@ import org.apache.atlas.model.discovery.AtlasSearchResult; ...@@ -26,7 +26,7 @@ import org.apache.atlas.model.discovery.AtlasSearchResult;
import org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult; import org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult;
import org.apache.atlas.model.discovery.AtlasSearchResult.AtlasQueryType; import org.apache.atlas.model.discovery.AtlasSearchResult.AtlasQueryType;
import org.apache.atlas.model.instance.AtlasEntity.Status; import org.apache.atlas.model.instance.AtlasEntity.Status;
import org.apache.atlas.model.instance.AtlasEntityHeader; import org.apache.atlas.model.instance.AtlasEntityHeaderWithAssociations;
import org.apache.atlas.typesystem.TypesDef; import org.apache.atlas.typesystem.TypesDef;
import org.apache.atlas.typesystem.types.ClassType; import org.apache.atlas.typesystem.types.ClassType;
import org.apache.atlas.typesystem.types.DataTypes; import org.apache.atlas.typesystem.types.DataTypes;
...@@ -68,11 +68,11 @@ public class EntityDiscoveryJerseyResourceIT extends BaseResourceIT { ...@@ -68,11 +68,11 @@ public class EntityDiscoveryJerseyResourceIT extends BaseResourceIT {
assertEquals(searchResult.getQueryText(), dslQuery); assertEquals(searchResult.getQueryText(), dslQuery);
assertEquals(searchResult.getQueryType(), AtlasQueryType.DSL); assertEquals(searchResult.getQueryType(), AtlasQueryType.DSL);
List<AtlasEntityHeader> entities = searchResult.getEntities(); List<AtlasEntityHeaderWithAssociations> entities = searchResult.getEntities();
assertNotNull(entities); assertNotNull(entities);
assertEquals(entities.size(), 1); assertEquals(entities.size(), 1);
AtlasEntityHeader dbEntity = entities.get(0); AtlasEntityHeaderWithAssociations dbEntity = entities.get(0);
assertEquals(dbEntity.getTypeName(), DATABASE_TYPE); assertEquals(dbEntity.getTypeName(), DATABASE_TYPE);
assertEquals(dbEntity.getDisplayText(), dbName); assertEquals(dbEntity.getDisplayText(), dbName);
assertEquals(dbEntity.getStatus(), Status.STATUS_ACTIVE); assertEquals(dbEntity.getStatus(), Status.STATUS_ACTIVE);
...@@ -130,11 +130,11 @@ public class EntityDiscoveryJerseyResourceIT extends BaseResourceIT { ...@@ -130,11 +130,11 @@ public class EntityDiscoveryJerseyResourceIT extends BaseResourceIT {
assertEquals(searchResult.getQueryText(), query); assertEquals(searchResult.getQueryText(), query);
assertEquals(searchResult.getQueryType(), AtlasQueryType.DSL); assertEquals(searchResult.getQueryType(), AtlasQueryType.DSL);
List<AtlasEntityHeader> entities = searchResult.getEntities(); List<AtlasEntityHeaderWithAssociations> entities = searchResult.getEntities();
assertNotNull(entities); assertNotNull(entities);
assertEquals(entities.size(), 1); assertEquals(entities.size(), 1);
AtlasEntityHeader dbEntity = entities.get(0); AtlasEntityHeaderWithAssociations dbEntity = entities.get(0);
assertEquals(dbEntity.getTypeName(), DATABASE_TYPE); assertEquals(dbEntity.getTypeName(), DATABASE_TYPE);
assertEquals(dbEntity.getDisplayText(), dbName); assertEquals(dbEntity.getDisplayText(), dbName);
assertEquals(dbEntity.getStatus(), Status.STATUS_ACTIVE); assertEquals(dbEntity.getStatus(), Status.STATUS_ACTIVE);
......
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