Search in sources :

Example 6 with ReferenceableInstance

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);
    }
}
Also used : Id(org.apache.atlas.typesystem.persistence.Id) ReferenceableInstance(org.apache.atlas.typesystem.persistence.ReferenceableInstance) IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance)

Example 7 with ReferenceableInstance

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;
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) Id(org.apache.atlas.typesystem.persistence.Id) ReferenceableInstance(org.apache.atlas.typesystem.persistence.ReferenceableInstance) IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AtlasException(org.apache.atlas.AtlasException)

Example 8 with ReferenceableInstance

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;
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) ReferenceableInstance(org.apache.atlas.typesystem.persistence.ReferenceableInstance) IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id)

Aggregations

ReferenceableInstance (org.apache.atlas.typesystem.persistence.ReferenceableInstance)8 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)7 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)7 Id (org.apache.atlas.typesystem.persistence.Id)5 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)3 AtlasException (org.apache.atlas.AtlasException)2 RepositoryException (org.apache.atlas.repository.RepositoryException)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 IStruct (org.apache.atlas.typesystem.IStruct)1 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)1 StructInstance (org.apache.atlas.typesystem.persistence.StructInstance)1 ClassType (org.apache.atlas.typesystem.types.ClassType)1