Search in sources :

Example 1 with AtlasSystemAttributes

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

the class GraphBackedMetadataRepositoryTest method testGetEntityDefinitionForDepartment.

@Test(dependsOnMethods = "testSubmitEntity")
public void testGetEntityDefinitionForDepartment() throws Exception {
    ITypedReferenceableInstance entity = repositoryService.getEntityDefinition(guid);
    Assert.assertNotNull(entity);
    // entity state should be active by default
    Assert.assertEquals(entity.getId().getState(), Id.EntityState.ACTIVE);
    // System attributes created time and modified time should not be null
    AtlasSystemAttributes systemAttributes = entity.getSystemAttributes();
    Assert.assertNotNull(systemAttributes.createdTime);
    Assert.assertNotNull(systemAttributes.modifiedTime);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AtlasSystemAttributes(org.apache.atlas.typesystem.persistence.AtlasSystemAttributes) Test(org.testng.annotations.Test)

Example 2 with AtlasSystemAttributes

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

the class GraphToTypedInstanceMapper method mapGraphToTypedInstance.

public ITypedReferenceableInstance mapGraphToTypedInstance(String guid, AtlasVertex instanceVertex) throws AtlasException {
    if (LOG.isDebugEnabled()) {
        // place to add a check to see if there are any places that were missed.
        if (RequestContext.get().getInstanceV1(guid) != null) {
            LOG.warn("Looking up previously cached guid at: ", new Exception());
        }
        LOG.debug("Mapping graph root vertex {} to typed instance for guid {}", instanceVertex, guid);
    }
    String typeName = GraphHelper.getSingleValuedProperty(instanceVertex, Constants.ENTITY_TYPE_PROPERTY_KEY, String.class);
    List<String> traits = GraphHelper.getTraitNames(instanceVertex);
    String state = GraphHelper.getStateAsString(instanceVertex);
    String createdBy = GraphHelper.getCreatedByAsString(instanceVertex);
    String modifiedBy = GraphHelper.getModifiedByAsString(instanceVertex);
    Date createdTime = new Date(GraphHelper.getCreatedTime(instanceVertex));
    Date modifiedTime = new Date(GraphHelper.getModifiedTime(instanceVertex));
    AtlasSystemAttributes systemAttributes = new AtlasSystemAttributes(createdBy, modifiedBy, createdTime, modifiedTime);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Found createdBy : {} modifiedBy : {} createdTime: {} modifedTime: {}", createdBy, modifiedBy, createdTime, modifiedTime);
    }
    Id id = new Id(guid, Integer.parseInt(String.valueOf(GraphHelper.getProperty(instanceVertex, Constants.VERSION_PROPERTY_KEY))), typeName, state);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Created id {} for instance type {}", id, typeName);
    }
    ClassType classType = typeSystem.getDataType(ClassType.class, typeName);
    ITypedReferenceableInstance typedInstance = classType.createInstance(id, systemAttributes, traits.toArray(new String[traits.size()]));
    mapVertexToInstance(instanceVertex, typedInstance, classType.fieldMapping().fields);
    mapVertexToInstanceTraits(instanceVertex, typedInstance, traits);
    RequestContext.get().cache(typedInstance);
    return typedInstance;
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AtlasSystemAttributes(org.apache.atlas.typesystem.persistence.AtlasSystemAttributes) Id(org.apache.atlas.typesystem.persistence.Id) ClassType(org.apache.atlas.typesystem.types.ClassType) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasException(org.apache.atlas.AtlasException) Date(java.util.Date)

Aggregations

ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)2 AtlasSystemAttributes (org.apache.atlas.typesystem.persistence.AtlasSystemAttributes)2 Date (java.util.Date)1 AtlasException (org.apache.atlas.AtlasException)1 RepositoryException (org.apache.atlas.repository.RepositoryException)1 Id (org.apache.atlas.typesystem.persistence.Id)1 ClassType (org.apache.atlas.typesystem.types.ClassType)1 Test (org.testng.annotations.Test)1