Search in sources :

Example 6 with Id

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

the class TypedInstanceToGraphMapper method getClassVertex.

private <V, E> AtlasVertex<V, E> getClassVertex(ITypedReferenceableInstance typedReference) throws EntityNotFoundException {
    AtlasVertex<V, E> referenceVertex = null;
    Id id = null;
    if (typedReference != null) {
        id = getExistingId(typedReference);
        referenceVertex = idToVertexMap.get(id);
        if (referenceVertex == null && id.isAssigned()) {
            referenceVertex = graphHelper.getVertexForGUID(id.id);
        }
    }
    return referenceVertex;
}
Also used : Id(org.apache.atlas.typesystem.persistence.Id)

Example 7 with Id

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

the class SoftDeleteHandlerV1Test method assertMaxForTestDisconnectBidirectionalReferences.

@Override
protected void assertMaxForTestDisconnectBidirectionalReferences(final Map<String, String> nameGuidMap) throws Exception {
    // Verify that the Department.employees reference to the deleted employee
    // was disconnected.
    ITypedReferenceableInstance hrDept = metadataService.getEntityDefinition(nameGuidMap.get("hr"));
    List<ITypedReferenceableInstance> employees = (List<ITypedReferenceableInstance>) hrDept.get("employees");
    Assert.assertEquals(employees.size(), 4);
    String maxGuid = nameGuidMap.get("Max");
    for (ITypedReferenceableInstance employee : employees) {
        if (employee.getId()._getId().equals(maxGuid)) {
            assertEquals(employee.getId().getState(), Id.EntityState.DELETED);
        }
    }
    // Verify that the Manager.subordinates still references deleted employee
    ITypedReferenceableInstance jane = metadataService.getEntityDefinition(nameGuidMap.get("Jane"));
    List<ITypedReferenceableInstance> subordinates = (List<ITypedReferenceableInstance>) jane.get("subordinates");
    assertEquals(subordinates.size(), 2);
    for (ITypedReferenceableInstance subordinate : subordinates) {
        if (subordinate.getId()._getId().equals(maxGuid)) {
            assertEquals(subordinate.getId().getState(), Id.EntityState.DELETED);
        }
    }
    // Verify that max's Person.mentor unidirectional reference to john was disconnected.
    ITypedReferenceableInstance john = metadataService.getEntityDefinition(nameGuidMap.get("John"));
    Id mentor = (Id) john.get("mentor");
    assertEquals(mentor._getId(), maxGuid);
    assertEquals(mentor.getState(), Id.EntityState.DELETED);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) List(java.util.List) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Id(org.apache.atlas.typesystem.persistence.Id)

Example 8 with Id

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

the class QuickStartIT method testViewIsAdded.

@Test
public void testViewIsAdded() throws AtlasServiceException, JSONException {
    Referenceable view = atlasClientV1.getEntity(QuickStart.VIEW_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStart.PRODUCT_DIM_VIEW);
    assertEquals(QuickStart.PRODUCT_DIM_VIEW, view.get(AtlasClient.NAME));
    Id productDimId = getTable(QuickStart.PRODUCT_DIM_TABLE).getId();
    Id inputTableId = ((List<Id>) view.get(QuickStart.INPUT_TABLES_ATTRIBUTE)).get(0);
    assertEquals(productDimId, inputTableId);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) List(java.util.List) Id(org.apache.atlas.typesystem.persistence.Id) Test(org.testng.annotations.Test)

Example 9 with Id

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

the class RequestContext method recordEntityDelete.

public void recordEntityDelete(String entityId, String typeName) throws AtlasException {
    ClassType type = typeSystem.getDataType(ClassType.class, typeName);
    ITypedReferenceableInstance entity = type.createInstance(new Id(entityId, 0, typeName));
    if (deletedEntityIds.add(entityId)) {
        deletedEntities.add(entity);
    }
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 10 with Id

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

the class DefaultMetadataServiceTest method testCreateEntityWithUniqueAttributeWithReference.

@Test
public void testCreateEntityWithUniqueAttributeWithReference() throws Exception {
    Referenceable db = createDBEntity();
    String dbId = TestUtils.createInstance(metadataService, db);
    //Assert that there is just 1 audit events and thats for entity create
    assertAuditEvents(dbId, 1);
    assertAuditEvents(dbId, EntityAuditEvent.EntityAuditAction.ENTITY_CREATE);
    Referenceable table = new Referenceable(TestUtils.TABLE_TYPE);
    table.set(NAME, TestUtils.randomString());
    table.set("description", "random table");
    table.set("type", "type");
    table.set("tableType", "MANAGED");
    table.set("database", new Id(dbId, 0, TestUtils.DATABASE_TYPE));
    table.set("databaseComposite", db);
    TestUtils.createInstance(metadataService, table);
    //table create should re-use the db instance created earlier
    String tableDefinitionJson = metadataService.getEntityDefinition(TestUtils.TABLE_TYPE, NAME, (String) table.get(NAME));
    Referenceable tableDefinition = InstanceSerialization.fromJsonReferenceable(tableDefinitionJson, true);
    Referenceable actualDb = (Referenceable) tableDefinition.get("databaseComposite");
    assertEquals(actualDb.getId().id, dbId);
    //Assert that as part table create, db is not created and audit event is not added to db
    assertAuditEvents(dbId, 1);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) Id(org.apache.atlas.typesystem.persistence.Id) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

Id (org.apache.atlas.typesystem.persistence.Id)94 Referenceable (org.apache.atlas.typesystem.Referenceable)50 Test (org.testng.annotations.Test)37 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)28 List (java.util.List)17 ArrayList (java.util.ArrayList)12 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)12 ImmutableList (com.google.common.collect.ImmutableList)10 TraitType (org.apache.atlas.typesystem.types.TraitType)10 JSONObject (org.codehaus.jettison.json.JSONObject)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AtlasServiceException (org.apache.atlas.AtlasServiceException)7 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)7 Struct (org.apache.atlas.typesystem.Struct)7 ClassType (org.apache.atlas.typesystem.types.ClassType)7 AtlasException (org.apache.atlas.AtlasException)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)6 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)5