Search in sources :

Example 86 with ITypedReferenceableInstance

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

the class TypedInstanceToGraphMapper method addOrUpdateAttributesAndTraits.

private List<String> addOrUpdateAttributesAndTraits(Operation operation, List<ITypedReferenceableInstance> instances) throws AtlasException {
    List<String> guids = new ArrayList<>();
    for (ITypedReferenceableInstance instance : instances) {
        try {
            //new vertex, set all the properties
            String guid = addOrUpdateAttributesAndTraits(operation, instance);
            guids.add(guid);
        } catch (AtlasSchemaViolationException e) {
            throw new EntityExistsException(instance, e);
        }
    }
    return guids;
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList) AtlasSchemaViolationException(org.apache.atlas.repository.graphdb.AtlasSchemaViolationException) EntityExistsException(org.apache.atlas.typesystem.exception.EntityExistsException)

Example 87 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance 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 88 with ITypedReferenceableInstance

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

the class GraphBackedDiscoveryServiceTest method setUp.

@Override
@BeforeClass
public void setUp() throws Exception {
    super.setUp();
    repositoryService = TestUtils.addTransactionWrapper(repositoryService);
    final TypeSystem typeSystem = TypeSystem.getInstance();
    Collection<String> oldTypeNames = new HashSet<>();
    oldTypeNames.addAll(typeSystem.getTypeNames());
    TestUtils.defineDeptEmployeeTypes(typeSystem);
    addIndexesForNewTypes(oldTypeNames, typeSystem);
    ITypedReferenceableInstance hrDept = TestUtils.createDeptEg1(typeSystem);
    repositoryService.createEntities(hrDept);
    ITypedReferenceableInstance jane = repositoryService.getEntityDefinition("Manager", "name", "Jane");
    Id janeGuid = jane.getId();
    ClassType personType = typeSystem.getDataType(ClassType.class, "Person");
    ITypedReferenceableInstance instance = personType.createInstance(janeGuid);
    instance.set("orgLevel", "L1");
    repositoryService.updatePartial(instance);
}
Also used : TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id) ClassType(org.apache.atlas.typesystem.types.ClassType) BeforeClass(org.testng.annotations.BeforeClass)

Example 89 with ITypedReferenceableInstance

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

the class SoftDeleteHandlerV1Test method assertTableForTestDeleteReference.

@Override
protected void assertTableForTestDeleteReference(final String tableId) throws Exception {
    ITypedReferenceableInstance table = metadataService.getEntityDefinition(tableId);
    assertNotNull(table.get(NAME));
    assertNotNull(table.get("description"));
    assertNotNull(table.get("type"));
    assertNotNull(table.get("tableType"));
    assertNotNull(table.get("created"));
    Id dbId = (Id) table.get("database");
    assertNotNull(dbId);
    ITypedReferenceableInstance db = metadataService.getEntityDefinition(dbId.getId()._getId());
    assertNotNull(db);
    assertEquals(db.getId().getState(), Id.EntityState.ACTIVE);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Id(org.apache.atlas.typesystem.persistence.Id)

Example 90 with ITypedReferenceableInstance

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

the class FullTextMapper method mapRecursive.

public String mapRecursive(AtlasVertex instanceVertex, boolean followReferences) throws AtlasException {
    String guid = GraphHelper.getGuid(instanceVertex);
    ITypedReferenceableInstance typedReference;
    RequestContext context = RequestContext.get();
    typedReference = context.getInstanceV1(guid);
    if (typedReference != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Cache hit: guid = {}, entityId = {}", guid, typedReference.getId()._getId());
        }
    } else {
        typedReference = graphToTypedInstanceMapper.mapGraphToTypedInstance(guid, instanceVertex);
        context.cache(typedReference);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Cache miss: guid = {}, entityId = {}", guid, typedReference.getId().getId());
        }
    }
    String fullText = forInstance(typedReference, followReferences);
    StringBuilder fullTextBuilder = new StringBuilder(typedReference.getTypeName()).append(FULL_TEXT_DELIMITER).append(fullText);
    List<String> traits = typedReference.getTraits();
    for (String traitName : traits) {
        String traitText = forInstance((ITypedInstance) typedReference.getTrait(traitName), false);
        fullTextBuilder.append(FULL_TEXT_DELIMITER).append(traitName).append(FULL_TEXT_DELIMITER).append(traitText);
    }
    return fullTextBuilder.toString();
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) RequestContext(org.apache.atlas.RequestContext)

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