Commit 01ea65c2 by Sarath Subramanian

ATLAS-3095: Update QuickStartV2 to use relationships

parent 3ba4a3fe
...@@ -152,13 +152,12 @@ public class AtlasRelationshipDef extends AtlasStructDef implements java.io.Seri ...@@ -152,13 +152,12 @@ public class AtlasRelationshipDef extends AtlasStructDef implements java.io.Seri
* *
* The ends are defined as 1 and 2 to avoid implying a direction. So we do not use to and from. * The ends are defined as 1 and 2 to avoid implying a direction. So we do not use to and from.
* *
* @throws AtlasBaseException
*/ */
public AtlasRelationshipDef(String name, String description, String typeVersion, public AtlasRelationshipDef(String name, String description, String typeVersion,
RelationshipCategory relationshipCategory, RelationshipCategory relationshipCategory,
PropagateTags propagatetags, PropagateTags propagatetags,
AtlasRelationshipEndDef endDef1, AtlasRelationshipEndDef endDef1,
AtlasRelationshipEndDef endDef2) throws AtlasBaseException { AtlasRelationshipEndDef endDef2) {
this(name, description, typeVersion, relationshipCategory,propagatetags, endDef1, endDef2, this(name, description, typeVersion, relationshipCategory,propagatetags, endDef1, endDef2,
new ArrayList<AtlasAttributeDef>()); new ArrayList<AtlasAttributeDef>());
} }
......
...@@ -21,6 +21,7 @@ import org.apache.atlas.model.instance.AtlasClassification; ...@@ -21,6 +21,7 @@ import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntityHeader; import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.instance.AtlasObjectId; import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.AtlasRelatedObjectId;
import org.apache.atlas.model.instance.AtlasStruct; import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef; import org.apache.atlas.model.typedef.AtlasClassificationDef;
...@@ -276,6 +277,10 @@ public class AtlasTypeUtil { ...@@ -276,6 +277,10 @@ public class AtlasTypeUtil {
return new AtlasEntityDef(name, description, version, Arrays.asList(attrDefs), superTypes); return new AtlasEntityDef(name, description, version, Arrays.asList(attrDefs), superTypes);
} }
public static AtlasEntityDef createClassTypeDef(String name, String description, String version, Set<String> superTypes, Map<String, String> options, AtlasAttributeDef... attrDefs) {
return new AtlasEntityDef(name, description, version, Arrays.asList(attrDefs), superTypes, options);
}
public static AtlasRelationshipDef createRelationshipTypeDef(String name, public static AtlasRelationshipDef createRelationshipTypeDef(String name,
String description, String description,
String version, String version,
...@@ -288,6 +293,10 @@ public class AtlasTypeUtil { ...@@ -288,6 +293,10 @@ public class AtlasTypeUtil {
endDef1, endDef2, Arrays.asList(attrDefs)); endDef1, endDef2, Arrays.asList(attrDefs));
} }
public static AtlasRelationshipEndDef createRelationshipEndDef(String typeName, String name, Cardinality cardinality, boolean isContainer) {
return new AtlasRelationshipEndDef(typeName, name, cardinality, isContainer);
}
public static AtlasTypesDef getTypesDef(List<AtlasEnumDef> enums, public static AtlasTypesDef getTypesDef(List<AtlasEnumDef> enums,
List<AtlasStructDef> structs, List<AtlasStructDef> structs,
List<AtlasClassificationDef> traits, List<AtlasClassificationDef> traits,
...@@ -295,6 +304,14 @@ public class AtlasTypeUtil { ...@@ -295,6 +304,14 @@ public class AtlasTypeUtil {
return new AtlasTypesDef(enums, structs, traits, classes); return new AtlasTypesDef(enums, structs, traits, classes);
} }
public static AtlasTypesDef getTypesDef(List<AtlasEnumDef> enums,
List<AtlasStructDef> structs,
List<AtlasClassificationDef> traits,
List<AtlasEntityDef> classes,
List<AtlasRelationshipDef> relations) {
return new AtlasTypesDef(enums, structs, traits, classes, relations);
}
public static List<AtlasTypeDefHeader> toTypeDefHeader(AtlasTypesDef typesDef) { public static List<AtlasTypeDefHeader> toTypeDefHeader(AtlasTypesDef typesDef) {
List<AtlasTypeDefHeader> headerList = new LinkedList<>(); List<AtlasTypeDefHeader> headerList = new LinkedList<>();
if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) { if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
...@@ -360,6 +377,20 @@ public class AtlasTypeUtil { ...@@ -360,6 +377,20 @@ public class AtlasTypeUtil {
return ret; return ret;
} }
public static Collection<AtlasRelatedObjectId> toAtlasRelatedObjectIds(Collection<AtlasEntity> entities) {
List<AtlasRelatedObjectId> ret = new ArrayList<>();
if (CollectionUtils.isNotEmpty(entities)) {
for (AtlasEntity entity : entities) {
if (entity != null) {
ret.add(toAtlasRelatedObjectId(entity));
}
}
}
return ret;
}
public static Map toStructAttributes(Map map) { public static Map toStructAttributes(Map map) {
if (map != null && map.containsKey("typeName") && map.containsKey("attributes") && map.get("attributes") instanceof Map) { if (map != null && map.containsKey("typeName") && map.containsKey("attributes") && map.get("attributes") instanceof Map) {
return (Map)map.get("attributes"); return (Map)map.get("attributes");
...@@ -378,6 +409,10 @@ public class AtlasTypeUtil { ...@@ -378,6 +409,10 @@ public class AtlasTypeUtil {
return ret; return ret;
} }
public static AtlasRelatedObjectId toAtlasRelatedObjectId(AtlasEntity entity) {
return new AtlasRelatedObjectId(getAtlasObjectId(entity));
}
public static AtlasObjectId getAtlasObjectId(AtlasEntity entity) { public static AtlasObjectId getAtlasObjectId(AtlasEntity entity) {
return new AtlasObjectId(entity.getGuid(), entity.getTypeName()); return new AtlasObjectId(entity.getGuid(), entity.getTypeName());
} }
......
...@@ -95,7 +95,7 @@ public class AtlasGraphUtilsV2 { ...@@ -95,7 +95,7 @@ public class AtlasGraphUtilsV2 {
public static final String VERTEX_TYPE = "typeSystem"; public static final String VERTEX_TYPE = "typeSystem";
private static boolean USE_INDEX_QUERY_TO_FIND_ENTITY_BY_UNIQUE_ATTRIBUTES = false; private static boolean USE_INDEX_QUERY_TO_FIND_ENTITY_BY_UNIQUE_ATTRIBUTES = false;
private static boolean USE_UNIQUE_INDEX_PROPERTY_TO_FIND_ENTITY = false; private static boolean USE_UNIQUE_INDEX_PROPERTY_TO_FIND_ENTITY = true;
private static String INDEX_SEARCH_PREFIX; private static String INDEX_SEARCH_PREFIX;
static { static {
......
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