use of org.apache.atlas.typesystem.types.StructType in project incubator-atlas by apache.
the class GraphBackedSearchIndexer method addIndexForType.
private void addIndexForType(AtlasGraphManagement management, IDataType dataType) {
switch(dataType.getTypeCategory()) {
case PRIMITIVE:
case ENUM:
case ARRAY:
case MAP:
// and not types like structs, traits or classes
break;
case STRUCT:
StructType structType = (StructType) dataType;
createIndexForFields(management, structType, structType.fieldMapping().fields);
break;
case TRAIT:
TraitType traitType = (TraitType) dataType;
createIndexForFields(management, traitType, traitType.fieldMapping().fields);
break;
case CLASS:
ClassType classType = (ClassType) dataType;
createIndexForFields(management, classType, classType.fieldMapping().fields);
break;
default:
throw new IllegalArgumentException("bad data type" + dataType);
}
}
use of org.apache.atlas.typesystem.types.StructType in project incubator-atlas by apache.
the class GraphToTypedInstanceMapper method getReferredEntity.
public ITypedInstance getReferredEntity(String edgeId, IDataType<?> referredType) throws AtlasException {
final AtlasEdge edge = getGraph().getEdge(edgeId);
if (edge != null) {
final AtlasVertex referredVertex = edge.getInVertex();
if (referredVertex != null) {
switch(referredType.getTypeCategory()) {
case STRUCT:
if (LOG.isDebugEnabled()) {
LOG.debug("Found struct instance vertex {}, mapping to instance {} ", referredVertex, referredType.getName());
}
StructType structType = (StructType) referredType;
ITypedStruct instance = structType.createInstance();
Map<String, AttributeInfo> fields = structType.fieldMapping().fields;
mapVertexToInstance(referredVertex, instance, fields);
return instance;
case CLASS:
//TODO isComposite handling for class loads
return GraphHelper.getIdFromVertex(referredType.getName(), referredVertex);
default:
throw new UnsupportedOperationException("Loading " + referredType.getTypeCategory() + " is not supported");
}
}
}
return null;
}
use of org.apache.atlas.typesystem.types.StructType in project incubator-atlas by apache.
the class DefaultGraphPersistenceStrategy method constructInstance.
@Override
public <U> U constructInstance(IDataType<U> dataType, Object value) {
try {
switch(dataType.getTypeCategory()) {
case PRIMITIVE:
case ENUM:
return dataType.convert(value, Multiplicity.OPTIONAL);
case ARRAY:
DataTypes.ArrayType arrType = (DataTypes.ArrayType) dataType;
IDataType<?> elemType = arrType.getElemType();
ImmutableCollection.Builder result = ImmutableList.builder();
List list = (List) value;
for (Object listElement : list) {
Object collectionEntry = constructCollectionEntry(elemType, listElement);
if (collectionEntry != null) {
result.add(collectionEntry);
}
}
return (U) result.build();
case MAP:
// todo
break;
case STRUCT:
AtlasVertex structVertex = (AtlasVertex) value;
StructType structType = (StructType) dataType;
ITypedStruct structInstance = structType.createInstance();
TypeSystem.IdType idType = TypeSystem.getInstance().getIdType();
if (dataType.getName().equals(idType.getName())) {
structInstance.set(idType.typeNameAttrName(), GraphHelper.getSingleValuedProperty(structVertex, typeAttributeName(), String.class));
structInstance.set(idType.idAttrName(), GraphHelper.getSingleValuedProperty(structVertex, idAttributeName(), String.class));
String stateValue = GraphHelper.getSingleValuedProperty(structVertex, stateAttributeName(), String.class);
if (stateValue != null) {
structInstance.set(idType.stateAttrName(), stateValue);
}
structInstance.set(idType.versionAttrName(), structVertex.getProperty(versionAttributeName(), Integer.class));
} else {
metadataRepository.getGraphToInstanceMapper().mapVertexToInstance(structVertex, structInstance, structType.fieldMapping().fields);
}
return dataType.convert(structInstance, Multiplicity.OPTIONAL);
case TRAIT:
AtlasVertex traitVertex = (AtlasVertex) value;
TraitType traitType = (TraitType) dataType;
ITypedStruct traitInstance = traitType.createInstance();
// todo - this is not right, we should load the Instance associated with this
// trait. for now just loading the trait struct.
// metadataRepository.getGraphToInstanceMapper().mapVertexToTraitInstance(
// traitVertex, dataType.getName(), , traitType, traitInstance);
metadataRepository.getGraphToInstanceMapper().mapVertexToInstance(traitVertex, traitInstance, traitType.fieldMapping().fields);
break;
case CLASS:
AtlasVertex classVertex = (AtlasVertex) value;
String guid = classVertex.getProperty(Constants.GUID_PROPERTY_KEY, String.class);
// Check if the instance we need was previously loaded.
ITypedReferenceableInstance classInstance = RequestContext.get().getInstanceV1(guid);
if (classInstance == null) {
classInstance = metadataRepository.getGraphToInstanceMapper().mapGraphToTypedInstance(guid, classVertex);
}
return dataType.convert(classInstance, Multiplicity.OPTIONAL);
default:
throw new UnsupportedOperationException("Load for type " + dataType + "is not supported");
}
} catch (AtlasException e) {
LOG.error("error while constructing an instance", e);
}
return null;
}
use of org.apache.atlas.typesystem.types.StructType in project incubator-atlas by apache.
the class GraphBackedSearchIndexer method createIndexForAttribute.
private void createIndexForAttribute(AtlasGraphManagement management, String typeName, AttributeInfo field) {
final String propertyName = GraphHelper.encodePropertyKey(typeName + "." + field.name);
switch(field.dataType().getTypeCategory()) {
case PRIMITIVE:
AtlasCardinality cardinality = getCardinality(field.multiplicity);
createIndexes(management, propertyName, getPrimitiveClass(field.dataType()), field.isUnique, cardinality, false, field.isIndexable);
break;
case ENUM:
cardinality = getCardinality(field.multiplicity);
createIndexes(management, propertyName, String.class, field.isUnique, cardinality, false, field.isIndexable);
break;
case ARRAY:
case MAP:
// IGNORE: Can only index single-valued property keys on vertices in Mixed Index
break;
case STRUCT:
StructType structType = (StructType) field.dataType();
createIndexForFields(management, structType, structType.fieldMapping().fields);
break;
case TRAIT:
// do nothing since this is NOT contained in other types
break;
case CLASS:
//createEdgeMixedIndex(propertyName);
break;
default:
throw new IllegalArgumentException("bad data type" + field.dataType().getName());
}
}
use of org.apache.atlas.typesystem.types.StructType in project incubator-atlas by apache.
the class StructInstance method getSignatureHash.
@Override
public String getSignatureHash(MessageDigest digester) throws AtlasException {
StructType structType = TypeSystem.getInstance().getDataType(StructType.class, getTypeName());
structType.updateSignatureHash(digester, this);
byte[] digest = digester.digest();
return MD5Utils.toString(digest);
}
Aggregations