use of org.apache.atlas.typesystem.persistence.ReferenceableInstance in project incubator-atlas by apache.
the class GraphHelper method getTypedReferenceableInstance.
public static ITypedReferenceableInstance getTypedReferenceableInstance(TypeSystem typeSystem, Referenceable entityInstance) throws AtlasException {
final String entityTypeName = ParamChecker.notEmpty(entityInstance.getTypeName(), "Entity type cannot be null");
ClassType entityType = typeSystem.getDataType(ClassType.class, entityTypeName);
//Both assigned id and values are required for full update
//classtype.convert() will remove values if id is assigned. So, set temp id, convert and
// then replace with original id
Id origId = entityInstance.getId();
entityInstance.replaceWithNewId(new Id(entityInstance.getTypeName()));
ITypedReferenceableInstance typedInstrance = entityType.convert(entityInstance, Multiplicity.REQUIRED);
((ReferenceableInstance) typedInstrance).replaceWithNewId(origId);
return typedInstrance;
}
use of org.apache.atlas.typesystem.persistence.ReferenceableInstance in project incubator-atlas by apache.
the class DefaultMetadataService method updateEntityByUniqueAttribute.
@Override
public CreateUpdateEntitiesResult updateEntityByUniqueAttribute(String typeName, String uniqueAttributeName, String attrValue, Referenceable updatedEntity) throws AtlasException {
typeName = ParamChecker.notEmpty(typeName, "typeName");
uniqueAttributeName = ParamChecker.notEmpty(uniqueAttributeName, "uniqueAttributeName");
attrValue = ParamChecker.notNull(attrValue, "unique attribute value");
updatedEntity = ParamChecker.notNull(updatedEntity, "updatedEntity");
ITypedReferenceableInstance oldInstance = getEntityDefinitionReference(typeName, uniqueAttributeName, attrValue);
final ITypedReferenceableInstance newInstance = validateAndConvertToTypedInstance(updatedEntity, typeName);
((ReferenceableInstance) newInstance).replaceWithNewId(oldInstance.getId());
CreateUpdateEntitiesResult result = repository.updatePartial(newInstance);
onEntitiesAddedUpdated(result.getEntityResult());
return result;
}
use of org.apache.atlas.typesystem.persistence.ReferenceableInstance in project incubator-atlas by apache.
the class ClassType method createInstanceWithTraits.
public ITypedReferenceableInstance createInstanceWithTraits(Id id, AtlasSystemAttributes systemAttributes, Referenceable r, String... traitNames) throws AtlasException {
ImmutableMap.Builder<String, ITypedStruct> b = new ImmutableBiMap.Builder<>();
if (traitNames != null) {
for (String t : traitNames) {
TraitType tType = typeSystem.getDataType(TraitType.class, t);
IStruct iTraitObject = r == null ? null : r.getTrait(t);
ITypedStruct trait = iTraitObject == null ? tType.createInstance() : tType.convert(iTraitObject, Multiplicity.REQUIRED);
b.put(t, trait);
}
}
return new ReferenceableInstance(id == null ? new Id(getName()) : id, getName(), systemAttributes, fieldMapping, new boolean[fieldMapping.fields.size()], new boolean[fieldMapping.fields.size()], fieldMapping.numBools == 0 ? null : new boolean[fieldMapping.numBools], fieldMapping.numBytes == 0 ? null : new byte[fieldMapping.numBytes], fieldMapping.numShorts == 0 ? null : new short[fieldMapping.numShorts], fieldMapping.numInts == 0 ? null : new int[fieldMapping.numInts], fieldMapping.numLongs == 0 ? null : new long[fieldMapping.numLongs], fieldMapping.numFloats == 0 ? null : new float[fieldMapping.numFloats], fieldMapping.numDoubles == 0 ? null : new double[fieldMapping.numDoubles], fieldMapping.numBigDecimals == 0 ? null : new BigDecimal[fieldMapping.numBigDecimals], fieldMapping.numBigInts == 0 ? null : new BigInteger[fieldMapping.numBigInts], fieldMapping.numDates == 0 ? null : new Date[fieldMapping.numDates], fieldMapping.numStrings == 0 ? null : new String[fieldMapping.numStrings], fieldMapping.numArrays == 0 ? null : new ImmutableList[fieldMapping.numArrays], fieldMapping.numMaps == 0 ? null : new ImmutableMap[fieldMapping.numMaps], fieldMapping.numStructs == 0 ? null : new StructInstance[fieldMapping.numStructs], fieldMapping.numReferenceables == 0 ? null : new ReferenceableInstance[fieldMapping.numReferenceables], fieldMapping.numReferenceables == 0 ? null : new Id[fieldMapping.numReferenceables], b.build());
}
use of org.apache.atlas.typesystem.persistence.ReferenceableInstance in project incubator-atlas by apache.
the class MemRepository method getDuringWalk.
/*
* - Id must be valid; Class must be valid.
* - Ask ClassStore to createInstance.
* - Ask ClassStore to load instance.
* - load instance traits
* - add to GraphWalker
*/
ITypedReferenceableInstance getDuringWalk(Id id, ObjectGraphWalker walker) throws RepositoryException {
ClassStore cS = getClassStore(id.getTypeName());
if (cS == null) {
throw new RepositoryException(String.format("Unknown Class %s", id.getTypeName()));
}
cS.validate(this, id);
ReferenceableInstance r = cS.createInstance(this, id);
cS.load(r);
for (String traitName : r.getTraits()) {
HierarchicalTypeStore tt = typeStores.get(traitName);
tt.load(r);
}
walker.addRoot(r);
return r;
}
use of org.apache.atlas.typesystem.persistence.ReferenceableInstance in project incubator-atlas by apache.
the class ClassStore method createInstance.
/*
* - assumes id is already validated
*/
ReferenceableInstance createInstance(MemRepository repo, Id id) throws RepositoryException {
Integer pos = idPosMap.get(id);
String typeName = typeNameList.get(pos);
if (!Objects.equals(typeName, hierarchicalType.getName())) {
return repo.getClassStore(typeName).createInstance(repo, id);
}
ImmutableList<String> traitNames = traitNamesStore.get(pos);
String[] tNs = traitNames.toArray(new String[] {});
try {
return (ReferenceableInstance) classType.createInstance(id, tNs);
} catch (AtlasException me) {
throw new RepositoryException(me);
}
}
Aggregations