use of org.apache.atlas.typesystem.persistence.ReferenceableInstance in project incubator-atlas by apache.
the class TypedInstanceToGraphMapper method addToEntityCache.
private void addToEntityCache(RequestContext context, ITypedReferenceableInstance instance) throws EntityNotFoundException {
Id instanceId = instance.getId();
if (instanceId.isUnassigned()) {
if (instance instanceof ReferenceableInstance) {
//When the id is unassigned, we can only cache the instance of it is
//an instance of ReferenceableInstance, since replaceWithNewId is not
//currently in the ITypedReferenceableInstance interface.
Id id = getId(instance);
((ReferenceableInstance) instance).replaceWithNewId(id);
context.cache(instance);
}
} else {
context.cache(instance);
}
}
use of org.apache.atlas.typesystem.persistence.ReferenceableInstance in project incubator-atlas by apache.
the class DefaultMetadataService method updateEntityAttributeByGuid.
@Override
public CreateUpdateEntitiesResult updateEntityAttributeByGuid(String guid, String attributeName, String value) throws AtlasException {
guid = ParamChecker.notEmpty(guid, "entity id");
attributeName = ParamChecker.notEmpty(attributeName, "attribute name");
value = ParamChecker.notEmpty(value, "attribute value");
ITypedReferenceableInstance existInstance = validateEntityExists(guid);
ClassType type = typeSystem.getDataType(ClassType.class, existInstance.getTypeName());
ITypedReferenceableInstance newInstance = type.createInstance();
AttributeInfo attributeInfo = type.fieldMapping.fields.get(attributeName);
if (attributeInfo == null) {
throw new AtlasException("Invalid property " + attributeName + " for entity " + existInstance.getTypeName());
}
DataTypes.TypeCategory attrTypeCategory = attributeInfo.dataType().getTypeCategory();
switch(attrTypeCategory) {
case PRIMITIVE:
newInstance.set(attributeName, value);
break;
case CLASS:
Id id = new Id(value, 0, attributeInfo.dataType().getName());
newInstance.set(attributeName, id);
break;
default:
throw new AtlasException("Update of " + attrTypeCategory + " is not supported");
}
((ReferenceableInstance) newInstance).replaceWithNewId(new Id(guid, 0, newInstance.getTypeName()));
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 DefaultMetadataService method updateEntityPartialByGuid.
@Override
public CreateUpdateEntitiesResult updateEntityPartialByGuid(String guid, Referenceable newEntity) throws AtlasException {
guid = ParamChecker.notEmpty(guid, "guid cannot be null");
newEntity = ParamChecker.notNull(newEntity, "updatedEntity cannot be null");
ITypedReferenceableInstance existInstance = validateEntityExists(guid);
ITypedReferenceableInstance newInstance = validateAndConvertToTypedInstance(newEntity, existInstance.getTypeName());
((ReferenceableInstance) newInstance).replaceWithNewId(new Id(guid, 0, newInstance.getTypeName()));
CreateUpdateEntitiesResult result = repository.updatePartial(newInstance);
onEntitiesAddedUpdated(result.getEntityResult());
return result;
}
Aggregations