Search in sources :

Example 66 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class GraphBackedMetadataRepositoryDeleteTestBase method testDeleteMixOfNullAndNonNullGuids.

@Test
public void testDeleteMixOfNullAndNonNullGuids() throws Exception {
    ITypedReferenceableInstance entity1 = compositeMapValueType.createInstance();
    ITypedReferenceableInstance entity2 = compositeMapValueType.createInstance();
    List<String> createEntitiesResult = repositoryService.createEntities(entity1, entity2).getCreatedEntities();
    Assert.assertEquals(createEntitiesResult.size(), 2);
    List<String> guids = Arrays.asList(createEntitiesResult.get(0), null, null, createEntitiesResult.get(1));
    EntityResult deleteEntitiesResult = repositoryService.deleteEntities(guids);
    Assert.assertEquals(deleteEntitiesResult.getDeletedEntities().size(), 2);
    Assert.assertTrue(deleteEntitiesResult.getDeletedEntities().containsAll(createEntitiesResult));
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

Example 67 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class DefaultGraphPersistenceStrategy method constructClassInstanceId.

@Override
public ITypedReferenceableInstance constructClassInstanceId(ClassType classType, Object value) {
    try {
        AtlasVertex classVertex = (AtlasVertex) value;
        ITypedReferenceableInstance classInstance = classType.createInstance(GraphHelper.getIdFromVertex(classVertex), new String[0]);
        return classType.convert(classInstance, Multiplicity.OPTIONAL);
    } catch (AtlasException e) {
        LOG.error("error while constructing an instance", e);
    }
    return null;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AtlasException(org.apache.atlas.AtlasException)

Example 68 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class DefaultMetadataService method updateEntities.

/**
     * Updates an entity, instance of the type based on the guid set.
     *
     * @param entityInstanceDefinition json array of entity definitions
     * @return guids - json array of guids
     */
@Override
public CreateUpdateEntitiesResult updateEntities(String entityInstanceDefinition) throws AtlasException {
    entityInstanceDefinition = ParamChecker.notEmpty(entityInstanceDefinition, "Entity instance definition");
    ITypedReferenceableInstance[] typedInstances = deserializeClassInstances(entityInstanceDefinition);
    CreateUpdateEntitiesResult result = repository.updateEntities(typedInstances);
    onEntitiesAddedUpdated(result.getEntityResult());
    return result;
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult)

Example 69 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance 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;
}
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)

Example 70 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class DefaultMetadataService method getTraitDefinition.

@Override
public IStruct getTraitDefinition(String guid, final String traitName) throws AtlasException {
    guid = ParamChecker.notEmpty(guid, "entity id");
    final ITypedReferenceableInstance instance = repository.getEntityDefinition(guid);
    return instance.getTrait(traitName);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance)

Aggregations

ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)142 Test (org.testng.annotations.Test)54 List (java.util.List)34 ArrayList (java.util.ArrayList)29 Id (org.apache.atlas.typesystem.persistence.Id)28 Referenceable (org.apache.atlas.typesystem.Referenceable)22 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)21 ImmutableList (com.google.common.collect.ImmutableList)20 ClassType (org.apache.atlas.typesystem.types.ClassType)19 AtlasException (org.apache.atlas.AtlasException)16 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)16 HashMap (java.util.HashMap)15 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)14 EntityResult (org.apache.atlas.model.legacy.EntityResult)12 IStruct (org.apache.atlas.typesystem.IStruct)10 Map (java.util.Map)9 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)9 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)9 RepositoryException (org.apache.atlas.repository.RepositoryException)9 BeforeTest (org.testng.annotations.BeforeTest)9