Repository: incubator-atlas Updated Branches: refs/heads/master 22650d6eb -> d8db43100
ATLAS-1435: include common attributes in v2 entity API response Signed-off-by: Madhan Neethiraj <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/d8db4310 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/d8db4310 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/d8db4310 Branch: refs/heads/master Commit: d8db43100cc182ecb59a75236b810ca45c19e725 Parents: 22650d6 Author: Vimal Sharma <[email protected]> Authored: Mon Jan 9 10:42:31 2017 -0800 Committer: Madhan Neethiraj <[email protected]> Committed: Mon Jan 9 10:42:31 2017 -0800 ---------------------------------------------------------------------- .../adapters/AtlasEntityFormatConverter.java | 21 ++++++++++++++++++++ .../web/resources/EntityV2JerseyResourceIT.java | 11 ++++++++++ 2 files changed, 32 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/d8db4310/webapp/src/main/java/org/apache/atlas/web/adapters/AtlasEntityFormatConverter.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/adapters/AtlasEntityFormatConverter.java b/webapp/src/main/java/org/apache/atlas/web/adapters/AtlasEntityFormatConverter.java index b8537c4..c4be236 100644 --- a/webapp/src/main/java/org/apache/atlas/web/adapters/AtlasEntityFormatConverter.java +++ b/webapp/src/main/java/org/apache/atlas/web/adapters/AtlasEntityFormatConverter.java @@ -23,6 +23,7 @@ import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.TypeCategory; import org.apache.atlas.model.instance.AtlasClassification; import org.apache.atlas.model.instance.AtlasEntity; +import org.apache.atlas.model.instance.AtlasEntity.Status; import org.apache.atlas.model.instance.AtlasEntityWithAssociations; import org.apache.atlas.model.instance.AtlasObjectId; import org.apache.atlas.type.AtlasEntityType; @@ -31,7 +32,9 @@ import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.typesystem.IReferenceableInstance; import org.apache.atlas.typesystem.IStruct; import org.apache.atlas.typesystem.Referenceable; +import org.apache.atlas.typesystem.persistence.AtlasSystemAttributes; import org.apache.atlas.typesystem.persistence.Id; +import org.apache.atlas.typesystem.persistence.Id.EntityState; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -61,6 +64,8 @@ public class AtlasEntityFormatConverter extends AtlasStructFormatConverter { ret = new AtlasEntityWithAssociations(id.getTypeName()); ret.setGuid(id.getId()._getId()); + EntityState state = id.getState(); + ret.setStatus(convertState(state)); } else if (v1Obj instanceof IReferenceableInstance) { IReferenceableInstance entity = (IReferenceableInstance) v1Obj; Map<String, Object> v1Attribs = null; @@ -73,6 +78,13 @@ public class AtlasEntityFormatConverter extends AtlasStructFormatConverter { ret = new AtlasEntityWithAssociations(entity.getTypeName(), super.fromV1ToV2(entityType, v1Attribs)); ret.setGuid(entity.getId()._getId()); + ret.setStatus(convertState(entity.getId().getState())); + AtlasSystemAttributes systemAttributes = entity.getSystemAttributes(); + ret.setCreatedBy(systemAttributes.createdBy); + ret.setCreateTime(systemAttributes.createdTime); + ret.setUpdatedBy(systemAttributes.modifiedBy); + ret.setUpdateTime(systemAttributes.modifiedTime); + ret.setVersion(new Long(entity.getId().version)); if (CollectionUtils.isNotEmpty(entity.getTraits())) { List<AtlasClassification> classifications = new ArrayList<>(); @@ -96,6 +108,15 @@ public class AtlasEntityFormatConverter extends AtlasStructFormatConverter { return ret; } + private AtlasEntity.Status convertState(EntityState state){ + Status status = Status.STATUS_ACTIVE; + if(state != null && state.equals(EntityState.DELETED)){ + status = Status.STATUS_DELETED; + } + LOG.debug("Setting state to {}", state); + return status; + } + @Override public Object fromV2ToV1(Object v2Obj, AtlasType type) throws AtlasBaseException { Object ret = null; http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/d8db4310/webapp/src/test/java/org/apache/atlas/web/resources/EntityV2JerseyResourceIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/EntityV2JerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/EntityV2JerseyResourceIT.java index c407130..8b4bd96 100755 --- a/webapp/src/test/java/org/apache/atlas/web/resources/EntityV2JerseyResourceIT.java +++ b/webapp/src/test/java/org/apache/atlas/web/resources/EntityV2JerseyResourceIT.java @@ -335,6 +335,17 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT { assertEquals(classifications.getList().size(), 8); } + @Test(dependsOnMethods = "testSubmitEntity") + public void testCommonAttributes() throws Exception{ + AtlasEntity entity = entitiesClientV2.getEntityByGuid(tableEntity.getGuid()); + Assert.assertNotNull(entity.getStatus()); + Assert.assertNotNull(entity.getVersion()); + Assert.assertNotNull(entity.getCreatedBy()); + Assert.assertNotNull(entity.getCreateTime()); + Assert.assertNotNull(entity.getUpdatedBy()); + Assert.assertNotNull(entity.getUpdateTime()); + } + private void addProperty(String guid, String property, String value) throws AtlasServiceException { AtlasEntity entityByGuid = entitiesClientV2.getEntityByGuid(guid);
