Commit 7303a412 by Madhan Neethiraj

ATLAS-1568: moved helper methods from org.apache.atlas.model package classes into an utility class

parent 8cd6a644
......@@ -22,6 +22,7 @@ import java.util.List;
import org.apache.atlas.AtlasClient.EntityResult;
import org.apache.atlas.model.instance.GuidMapping;
import org.apache.atlas.type.AtlasType;
/**
* Result from creating or updating entities.
......@@ -77,7 +78,7 @@ public class CreateUpdateEntitiesResult {
*/
public static CreateUpdateEntitiesResult fromJson(String json) throws AtlasServiceException {
GuidMapping guidMapping = GuidMapping.fromString(json);
GuidMapping guidMapping = AtlasType.fromJson(json, GuidMapping.class);
EntityResult entityResult = EntityResult.fromString(json);
CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
result.setEntityResult(entityResult);
......
......@@ -40,7 +40,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE;
......@@ -175,33 +174,6 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
public void setClassifications(List<AtlasClassification> classifications) { this.classifications = classifications; }
@JsonIgnore
public boolean isUnassigned() {
return isUnAssigned(guid);
}
@JsonIgnore
public boolean isAssigned() {
return isAssigned(guid);
}
@JsonIgnore
public static boolean isAssigned(String guid) {
if (guid != null) {
try {
UUID.fromString(guid);
return true;
} catch (IllegalArgumentException e) {
// ignore
}
}
return false;
}
@JsonIgnore
public static boolean isUnAssigned(String guid) {
return guid != null && guid.length() > 0 && guid.charAt(0) == '-';
}
private void init() {
setGuid(nextInternalId());
......@@ -217,11 +189,6 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
return "-" + Long.toString(s_nextId.getAndIncrement());
}
@JsonIgnore
public AtlasObjectId getAtlasObjectId() {
return new AtlasObjectId(getGuid(), getTypeName());
}
@Override
public StringBuilder toString(StringBuilder sb) {
if (sb == null) {
......
......@@ -34,7 +34,6 @@ import org.codehaus.jackson.annotate.JsonAutoDetect;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;
......@@ -191,10 +190,4 @@ public class AtlasEntityHeader extends AtlasStruct implements Serializable {
super(list, startIndex, pageSize, totalCount, sortType, sortBy);
}
}
@JsonIgnore
public AtlasObjectId getAtlasObjectId() {
return new AtlasObjectId(getGuid(), getTypeName());
}
}
......@@ -31,13 +31,10 @@ import javax.xml.bind.annotation.XmlSeeAlso;
import org.apache.atlas.model.PList;
import org.apache.atlas.model.SearchFilter.SortType;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY;
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;
......@@ -139,32 +136,6 @@ public class AtlasObjectId implements Serializable {
this.uniqueAttributes = uniqueAttributes;
}
@JsonIgnore
public boolean isValidGuid() {
return isAssignedGuid() || isUnAssignedGuid();
}
@JsonIgnore
public boolean isAssignedGuid() {
return AtlasEntity.isAssigned(guid);
}
@JsonIgnore
public boolean isUnAssignedGuid() {
return AtlasEntity.isUnAssigned(guid);
}
@JsonIgnore
public boolean isValid() {
if (isAssignedGuid() || isUnAssignedGuid()) {
return true;
} else if (StringUtils.isNotEmpty(typeName) && MapUtils.isNotEmpty(uniqueAttributes)) {
return true;
}
return false;
}
public StringBuilder toString(StringBuilder sb) {
if (sb == null) {
sb = new StringBuilder();
......@@ -193,7 +164,8 @@ public class AtlasObjectId implements Serializable {
AtlasObjectId that = (AtlasObjectId) o;
if (isValidGuid() && Objects.equals(guid, that.guid)) {
// if guid is null, equality should be based on typeName/uniqueAttributes
if (guid != null && Objects.equals(guid, that.guid)) {
return true;
}
......@@ -203,7 +175,7 @@ public class AtlasObjectId implements Serializable {
@Override
public int hashCode() {
return isValidGuid() ? Objects.hash(guid) : Objects.hash(typeName, uniqueAttributes);
return guid != null ? Objects.hash(guid) : Objects.hash(typeName, uniqueAttributes);
}
@Override
......
......@@ -26,13 +26,11 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
/**
* This stores a mapping of guid assignments that were made during the processing
......@@ -45,15 +43,13 @@ import com.google.gson.GsonBuilder;
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class GuidMapping {
private static final long serialVersionUID = 1L;
@JsonIgnore
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
private Map<String,String> guidAssignments;
public GuidMapping() {
}
public GuidMapping(Map<String,String> guidAssignments) {
......@@ -68,17 +64,23 @@ public class GuidMapping {
public void setGuidAssignments(Map<String,String> guidAssignments) {
this.guidAssignments = guidAssignments;
}
/**
* Converts the GuidMapping to json
*/
@Override
public String toString() {
return gson.toJson(this);
}
@JsonIgnore
public static GuidMapping fromString(String json) {
return gson.fromJson(json, GuidMapping.class);
public StringBuilder toString(StringBuilder sb) {
if (sb == null) {
sb = new StringBuilder();
}
sb.append("GuidMapping{");
sb.append("guidAssignments={");
AtlasBaseTypeDef.dumpObjects(guidAssignments, sb);
sb.append('}');
sb.append('}');
return sb;
}
@Override
public String toString() {
return toString(new StringBuilder()).toString();
}
}
\ No newline at end of file
......@@ -362,7 +362,7 @@ public class AtlasEntityType extends AtlasStructType {
}
boolean isAssignableFrom(AtlasObjectId objId) {
boolean ret = objId.isValid() && (StringUtils.equals(objId.getTypeName(), getTypeName()) || isSuperTypeOf(objId.getTypeName()));
boolean ret = AtlasTypeUtil.isValid(objId) && (StringUtils.equals(objId.getTypeName(), getTypeName()) || isSuperTypeOf(objId.getTypeName()));
return ret;
}
......
......@@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
......@@ -35,8 +36,10 @@ import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
import org.apache.atlas.model.typedef.AtlasTypeDefHeader;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;
......@@ -46,6 +49,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -309,7 +313,7 @@ public class AtlasTypeUtil {
if (CollectionUtils.isNotEmpty(entities)) {
for (AtlasEntity entity : entities) {
if (entity != null) {
ret.add(entity.getAtlasObjectId());
ret.add(AtlasTypeUtil.getAtlasObjectId(entity));
}
}
}
......@@ -324,4 +328,54 @@ public class AtlasTypeUtil {
return map;
}
public static AtlasObjectId getAtlasObjectId(AtlasEntity entity) {
return new AtlasObjectId(entity.getGuid(), entity.getTypeName());
}
public static AtlasObjectId getAtlasObjectId(AtlasEntityHeader header) {
return new AtlasObjectId(header.getGuid(), header.getTypeName());
}
public static boolean isValidGuid(AtlasObjectId objId) {
return isValidGuid(objId.getGuid());
}
public static boolean isAssignedGuid(AtlasObjectId objId) {
return isAssignedGuid(objId.getGuid());
}
public static boolean isUnAssignedGuid(AtlasObjectId objId) {
return isUnAssignedGuid(objId.getGuid());
}
public static boolean isValidGuid(String guid) {
return isAssignedGuid(guid) || isUnAssignedGuid(guid);
}
public static boolean isAssignedGuid(String guid) {
if (guid != null) {
try {
UUID.fromString(guid);
return true;
} catch (IllegalArgumentException e) {
// ignore
}
}
return false;
}
public static boolean isUnAssignedGuid(String guid) {
return guid != null && guid.length() > 0 && guid.charAt(0) == '-';
}
public static boolean isValid(AtlasObjectId objId) {
if (isAssignedGuid(objId) || isUnAssignedGuid(objId)) {
return true;
} else if (StringUtils.isNotEmpty(objId.getTypeName()) && MapUtils.isNotEmpty(objId.getUniqueAttributes())) {
return true;
}
return false;
}
}
\ No newline at end of file
......@@ -311,7 +311,7 @@ public final class TestUtilsV2 {
/******* Department - HR *******/
AtlasEntity hrDept = new AtlasEntity(DEPARTMENT_TYPE, "name", "hr");
AtlasObjectId hrDeptId = hrDept.getAtlasObjectId();
AtlasObjectId hrDeptId = AtlasTypeUtil.getAtlasObjectId(hrDept);
/******* Address Entities *******/
AtlasStruct janeAddr = new AtlasStruct(ADDRESS_TYPE);
......@@ -332,14 +332,14 @@ public final class TestUtilsV2 {
/******* Manager - Jane (John and Max subordinates) *******/
AtlasEntity jane = new AtlasEntity(MANAGER_TYPE);
AtlasObjectId janeId = jane.getAtlasObjectId();
AtlasObjectId janeId = AtlasTypeUtil.getAtlasObjectId(jane);
jane.setAttribute("name", "Jane");
jane.setAttribute("department", hrDeptId);
jane.setAttribute("address", janeAddr);
/******* Manager - Julius (no subordinates) *******/
AtlasEntity julius = new AtlasEntity(MANAGER_TYPE);
AtlasObjectId juliusId = julius.getAtlasObjectId();
AtlasObjectId juliusId = AtlasTypeUtil.getAtlasObjectId(julius);
julius.setAttribute("name", "Julius");
julius.setAttribute("department", hrDeptId);
julius.setAttribute("address", juliusAddr);
......@@ -347,7 +347,7 @@ public final class TestUtilsV2 {
/******* Employee - Max (Manager: Jane, Mentor: Julius) *******/
AtlasEntity max = new AtlasEntity(EMPLOYEE_TYPE);
AtlasObjectId maxId = max.getAtlasObjectId();
AtlasObjectId maxId = AtlasTypeUtil.getAtlasObjectId(max);
max.setAttribute("name", "Max");
max.setAttribute("department", hrDeptId);
max.setAttribute("address", maxAddr);
......@@ -366,7 +366,7 @@ public final class TestUtilsV2 {
/******* Employee - John (Manager: Jane, Mentor: Max) *******/
AtlasEntity john = new AtlasEntity(EMPLOYEE_TYPE);
AtlasObjectId johnId = john.getAtlasObjectId();
AtlasObjectId johnId = AtlasTypeUtil.getAtlasObjectId(john);
john.setAttribute("name", "John");
john.setAttribute("department", hrDeptId);
john.setAttribute("address", johnAddr);
......@@ -442,8 +442,8 @@ public final class TestUtilsV2 {
julius.setAttribute("address", juliusAddr);
julius.setAttribute("subordinates", ImmutableList.of());
AtlasObjectId janeId = jane.getAtlasObjectId();
AtlasObjectId johnId = john.getAtlasObjectId();
AtlasObjectId janeId = AtlasTypeUtil.getAtlasObjectId(jane);
AtlasObjectId johnId = AtlasTypeUtil.getAtlasObjectId(john);
//TODO - Change to MANAGER_TYPE for JULIUS
AtlasObjectId maxId = new AtlasObjectId(max.getGuid(), EMPLOYEE_TYPE);
......@@ -797,7 +797,7 @@ public final class TestUtilsV2 {
entity.setAttribute("description", "random table");
entity.setAttribute("type", "type");
entity.setAttribute("tableType", "MANAGED");
entity.setAttribute("database", dbEntity.getAtlasObjectId());
entity.setAttribute("database", AtlasTypeUtil.getAtlasObjectId(dbEntity));
entity.setAttribute("created", new Date());
Map<String, Object> partAttributes = new HashMap<String, Object>() {{
......@@ -820,7 +820,7 @@ public final class TestUtilsV2 {
tblEntity.setAttribute("description", "random table");
tblEntity.setAttribute("type", "type");
tblEntity.setAttribute("tableType", "MANAGED");
tblEntity.setAttribute("database", dbEntity.getAtlasObjectId());
tblEntity.setAttribute("database", AtlasTypeUtil.getAtlasObjectId(dbEntity));
tblEntity.setAttribute("created", new Date());
final AtlasStruct partitionStruct = new AtlasStruct("partition_struct_type", "name", "part0");
......@@ -845,7 +845,7 @@ public final class TestUtilsV2 {
AtlasEntity entity = new AtlasEntity(COLUMN_TYPE);
entity.setAttribute(NAME, colName);
entity.setAttribute("type", "VARCHAR(32)");
entity.setAttribute("table", tableEntity.getAtlasObjectId());
entity.setAttribute("table", AtlasTypeUtil.getAtlasObjectId(tableEntity));
return entity;
}
......
......@@ -9,14 +9,15 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES:
ATLAS-1568 moved helper methods from org.apache.atlas.model package classes into an utility class (mneethiraj)
ATLAS-1566 replace GSON ser-de with ObjectMapper ser-de (svimal2016 via mneethiraj)
ATLAS-1551 auto update of reverse references in V1 API (dkantor)
ATLAS-1565 Create EntityREST endpoints for delete operations (sarathkumarsubramanian via svimal2106)
ATLAS-1547 Added tests for hard delete (mneethiraj)
ATLAS-1547 Added tests for hard delete (sumasai)
ATLAS-1546 (ATLAS-1546.3.patch)Hive hook should choose appropriate JAAS config if host uses kerberos ticket-cache (nixonrodrigues via kevalbhat)
ATLAS-1503 Export/import support to copy data between Atlas instances (ashutoshm via mneethiraj)
ATLAS-1554 v2 EntityREST implementation for entity partial update (sarathkumarsubramanian via mneethiraj)
ATLAS-1547 Fix DeleteHandlerV1 for new model changes and add tests (mneethiraj)
ATLAS-1547 Fix DeleteHandlerV1 for new model changes and add tests (sumasai)
ATLAS-1556 Edit entity button not working from search table of tag detail page. (kevalbhatt)
ATLAS-1559 Regression - If a new tag is created then the earlier tags doesn't render properly (kevalbhatt)
ATLAS-1508 Make AtlasADAuthenticationProvider like Ranger ADLdap Methods (gss2002 via mneethiraj)
......
......@@ -72,7 +72,7 @@ public class AtlasEntityGraphDiscoveryV1 implements EntityGraphDiscovery {
public void validateAndNormalize(AtlasEntity entity) throws AtlasBaseException {
List<String> messages = new ArrayList<>();
if (!AtlasEntity.isAssigned(entity.getGuid()) && !AtlasEntity.isUnAssigned(entity.getGuid())) {
if (! AtlasTypeUtil.isValidGuid(entity.getGuid())) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid());
}
......@@ -95,7 +95,7 @@ public class AtlasEntityGraphDiscoveryV1 implements EntityGraphDiscovery {
public void validateAndNormalizeForUpdate(AtlasEntity entity) throws AtlasBaseException {
List<String> messages = new ArrayList<>();
if (!AtlasEntity.isAssigned(entity.getGuid()) && !AtlasEntity.isUnAssigned(entity.getGuid())) {
if (! AtlasTypeUtil.isValidGuid(entity.getGuid())) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid());
}
......@@ -176,7 +176,7 @@ public class AtlasEntityGraphDiscoveryV1 implements EntityGraphDiscovery {
if (val instanceof AtlasObjectId) {
AtlasObjectId objId = (AtlasObjectId)val;
if (!objId.isValid()) {
if (!AtlasTypeUtil.isValid(objId)) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, objId.toString());
}
......@@ -184,7 +184,7 @@ public class AtlasEntityGraphDiscoveryV1 implements EntityGraphDiscovery {
} else if (val instanceof Map) {
AtlasObjectId objId = new AtlasObjectId((Map)val);
if (!objId.isValid()) {
if (!AtlasTypeUtil.isValid(objId)) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, objId.toString());
}
......@@ -323,7 +323,7 @@ public class AtlasEntityGraphDiscoveryV1 implements EntityGraphDiscovery {
}
private void recordObjectReference(AtlasObjectId objId) {
if (objId.isValidGuid()) {
if (AtlasTypeUtil.isValidGuid(objId)) {
discoveryContext.addReferencedGuid(objId.getGuid());
} else {
discoveryContext.addReferencedByUniqAttribs(objId);
......
......@@ -38,6 +38,7 @@ import org.apache.atlas.repository.store.graph.EntityGraphDiscovery;
import org.apache.atlas.repository.store.graph.EntityGraphDiscoveryContext;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -378,7 +379,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());
//Create vertices which do not exist in the repository
if ((entityStream instanceof EntityImportStream) && AtlasEntity.isAssigned(entity.getGuid())) {
if ((entityStream instanceof EntityImportStream) && AtlasTypeUtil.isAssignedGuid(entity.getGuid())) {
vertex = entityGraphMapper.createVertexWithGuid(entity, entity.getGuid());
} else {
vertex = entityGraphMapper.createVertex(entity);
......
......@@ -538,7 +538,7 @@ public class EntityGraphMapper {
} else if (val instanceof Map) {
AtlasObjectId ret = new AtlasObjectId((Map)val);
if (ret.isValid()) {
if (AtlasTypeUtil.isValid(ret)) {
return ret;
}
}
......
......@@ -127,10 +127,10 @@ public final class EntityGraphRetriever {
private AtlasVertex getEntityVertex(AtlasObjectId objId) throws AtlasBaseException {
try {
if (! objId.isValid()) {
if (! AtlasTypeUtil.isValid(objId)) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, objId.toString());
}
if (objId.isAssignedGuid()) {
if (AtlasTypeUtil.isAssignedGuid(objId)) {
return graphHelper.getVertexForGUID(objId.getGuid());
} else {
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(objId.getTypeName());
......@@ -419,7 +419,7 @@ public final class EntityGraphRetriever {
AtlasEntity entity = mapVertexToAtlasEntity(referenceVertex, entityExtInfo);
if (entity != null) {
ret = entity.getAtlasObjectId();
ret = AtlasTypeUtil.getAtlasObjectId(entity);
}
} else {
ret = new AtlasObjectId(GraphHelper.getGuid(referenceVertex), GraphHelper.getTypeName(referenceVertex));
......
......@@ -26,6 +26,7 @@ import org.apache.atlas.repository.store.graph.EntityGraphDiscoveryContext;
import org.apache.atlas.repository.store.graph.EntityResolver;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -47,7 +48,7 @@ public class IDBasedEntityResolver implements EntityResolver {
EntityStream entityStream = context.getEntityStream();
for (String guid : context.getReferencedGuids()) {
boolean isAssignedGuid = AtlasEntity.isAssigned(guid);
boolean isAssignedGuid = AtlasTypeUtil.isAssignedGuid(guid);
AtlasVertex vertex = isAssignedGuid ? AtlasGraphUtilsV1.findByGuid(guid) : null;
if (vertex == null) { // if not found in the store, look if the entity is present in the stream
......
......@@ -240,7 +240,6 @@ public class GraphBackedMetadataRepositoryTest {
CreateUpdateEntitiesResult result = repositoryService.createEntities(deptInstance);
System.out.println(result.getGuidMapping().toString());
validateGuidMapping(toValidate, result);
}
......@@ -362,7 +361,6 @@ public class GraphBackedMetadataRepositoryTest {
CreateUpdateEntitiesResult result = repositoryService.createEntities(deptInstance);
System.out.println(result.getGuidMapping().toString());
assertEquals(result.getCreatedEntities().size(), toVerify.size());
validateGuidMapping(toVerify, result);
......
......@@ -198,7 +198,7 @@ public abstract class AtlasDeleteHandlerV1Test {
final AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity);
final AtlasEntity columnEntity = TestUtilsV2.createColumnEntity(tableEntity);
tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(columnEntity.getAtlasObjectId()));
tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(columnEntity)));
AtlasEntity.AtlasEntityWithExtInfo input = new AtlasEntity.AtlasEntityWithExtInfo(tableEntity);
input.addReferredEntity(columnEntity);
......@@ -220,7 +220,7 @@ public abstract class AtlasDeleteHandlerV1Test {
assertColumnForTestDeleteReference(entityStore.getById(tableCreated.getGuid()));
//Deleting table should update process
AtlasEntity process = TestUtilsV2.createProcessEntity(null, Arrays.asList(tableCreated.getAtlasObjectId()));
AtlasEntity process = TestUtilsV2.createProcessEntity(null, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(tableCreated)));
init();
final EntityMutationResponse processCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(process), false);
......@@ -249,7 +249,9 @@ public abstract class AtlasDeleteHandlerV1Test {
final AtlasEntity columnEntity3 = TestUtilsV2.createColumnEntity(tableEntity);
entitiesInfo.addReferredEntity(columnEntity3);
tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(columnEntity1.getAtlasObjectId(), columnEntity2.getAtlasObjectId(), columnEntity3.getAtlasObjectId()));
tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(columnEntity1),
AtlasTypeUtil.getAtlasObjectId(columnEntity2),
AtlasTypeUtil.getAtlasObjectId(columnEntity3)));
init();
......@@ -287,7 +289,7 @@ public abstract class AtlasDeleteHandlerV1Test {
AtlasEntity.AtlasEntitiesWithExtInfo entitiesInfo1 = new AtlasEntity.AtlasEntitiesWithExtInfo(tableEntity1);
final AtlasEntity columnEntity3New = TestUtilsV2.createColumnEntity(tableEntity1, (String) column3Created.getAttribute(NAME));
tableEntity1.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(columnEntity3New.getAtlasObjectId()));
tableEntity1.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(columnEntity3New)));
entitiesInfo1.addReferredEntity(columnEntity3New);
init();
......@@ -357,9 +359,9 @@ public abstract class AtlasDeleteHandlerV1Test {
Assert.assertNotNull(modificationTimestampPreUpdate);
AtlasEntity maxEmployee = getEmployeeByName(hrDept, "Max");
maxEmployee.setAttribute("mentor", johnEmployeeCreated.getAtlasObjectId());
maxEmployee.setAttribute("department", deptCreated.getAtlasObjectId());
maxEmployee.setAttribute("manager", janeEmployeeCreated.getAtlasObjectId());
maxEmployee.setAttribute("mentor", AtlasTypeUtil.getAtlasObjectId(johnEmployeeCreated));
maxEmployee.setAttribute("department", AtlasTypeUtil.getAtlasObjectId(deptCreated));
maxEmployee.setAttribute("manager", AtlasTypeUtil.getAtlasObjectId(janeEmployeeCreated));
init();
EntityMutationResponse entityResult = entityStore.createOrUpdate(new AtlasEntityStream(maxEmployee), false);
......@@ -379,7 +381,7 @@ public abstract class AtlasDeleteHandlerV1Test {
Assert.assertTrue(creationTimestamp < modificationTimestampPostUpdate);
// Update max's mentor reference to jane.
maxEmployee.setAttribute("mentor", janeEmployeeCreated.getAtlasObjectId());
maxEmployee.setAttribute("mentor", AtlasTypeUtil.getAtlasObjectId(janeEmployeeCreated));
init();
entityResult = entityStore.createOrUpdate(new AtlasEntityStream(maxEmployee), false);
assertEquals(entityResult.getUpdatedEntities().size(), 1);
......@@ -400,7 +402,7 @@ public abstract class AtlasDeleteHandlerV1Test {
Id juliusGuid = julius.getId();
init();
maxEmployee.setAttribute("manager", juliusEmployeeCreated.getAtlasObjectId());
maxEmployee.setAttribute("manager", AtlasTypeUtil.getAtlasObjectId(juliusEmployeeCreated));
entityResult = entityStore.createOrUpdate(new AtlasEntityStream(maxEmployee), false);
//TODO ATLAS-499 should have updated julius' subordinates
assertEquals(entityResult.getUpdatedEntities().size(), 2);
......@@ -625,7 +627,7 @@ public abstract class AtlasDeleteHandlerV1Test {
AtlasStruct nestedStructInstance = new AtlasStruct("NestedStruct");
Struct traitInstance = new Struct("TestTrait");
structContainerEntity.setAttribute("struct", structInstance);
structInstance.setAttribute("target", ImmutableList.of(structTargetEntity.getAtlasObjectId()));
structInstance.setAttribute("target", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(structTargetEntity)));
structInstance.setAttribute("nestedStructs", ImmutableList.of(nestedStructInstance));
AtlasEntity.AtlasEntitiesWithExtInfo structCreationObj = new AtlasEntity.AtlasEntitiesWithExtInfo();
......@@ -728,7 +730,9 @@ public abstract class AtlasDeleteHandlerV1Test {
final AtlasEntity columnEntity3 = TestUtilsV2.createColumnEntity(tableEntity);
entitiesInfo.addReferredEntity(columnEntity3);
tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(columnEntity1.getAtlasObjectId(), columnEntity2.getAtlasObjectId(), columnEntity3.getAtlasObjectId()));
tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(columnEntity1),
AtlasTypeUtil.getAtlasObjectId(columnEntity2),
AtlasTypeUtil.getAtlasObjectId(columnEntity3)));
init();
......
......@@ -191,8 +191,8 @@ public class AtlasEntityStoreV1Test {
AtlasEntity col2 = TestUtilsV2.createColumnEntity(tableEntity);
col2.setAttribute(TestUtilsV2.NAME, "col2");
columns.add(col1.getAtlasObjectId());
columns.add(col2.getAtlasObjectId());
columns.add(AtlasTypeUtil.getAtlasObjectId(col1));
columns.add(AtlasTypeUtil.getAtlasObjectId(col2));
tableEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns);
......@@ -213,8 +213,8 @@ public class AtlasEntityStoreV1Test {
AtlasEntity col4 = TestUtilsV2.createColumnEntity(tableEntity);
col4.setAttribute(TestUtilsV2.NAME, "col4");
columns.add(col3.getAtlasObjectId());
columns.add(col4.getAtlasObjectId());
columns.add(AtlasTypeUtil.getAtlasObjectId(col3));
columns.add(AtlasTypeUtil.getAtlasObjectId(col4));
tableEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns);
entitiesInfo.addReferredEntity(col3);
......@@ -228,8 +228,8 @@ public class AtlasEntityStoreV1Test {
//Swap elements
columns.clear();
columns.add(col4.getAtlasObjectId());
columns.add(col3.getAtlasObjectId());
columns.add(AtlasTypeUtil.getAtlasObjectId(col4));
columns.add(AtlasTypeUtil.getAtlasObjectId(col3));
tableEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns);
init();
......@@ -321,7 +321,7 @@ public class AtlasEntityStoreV1Test {
AtlasEntity col0 = new AtlasEntity(TestUtilsV2.COLUMN_TYPE, TestUtilsV2.NAME, "test1");
col0.setAttribute("type", "string");
col0.setAttribute("table", tableEntity.getAtlasObjectId());
col0.setAttribute("table", AtlasTypeUtil.getAtlasObjectId(tableEntity));
AtlasEntityWithExtInfo col0WithExtendedInfo = new AtlasEntityWithExtInfo(col0);
col0WithExtendedInfo.addReferredEntity(tableEntity);
......@@ -332,7 +332,7 @@ public class AtlasEntityStoreV1Test {
AtlasEntity col1 = new AtlasEntity(TestUtils.COLUMN_TYPE, TestUtilsV2.NAME, "test2");
col1.setAttribute("type", "string");
col1.setAttribute("table", tableEntity.getAtlasObjectId());
col1.setAttribute("table", AtlasTypeUtil.getAtlasObjectId(tableEntity));
AtlasEntityWithExtInfo col1WithExtendedInfo = new AtlasEntityWithExtInfo(col1);
col1WithExtendedInfo.addReferredEntity(tableEntity);
......@@ -342,8 +342,8 @@ public class AtlasEntityStoreV1Test {
entityStore.createOrUpdate(new AtlasEntityStream(col1WithExtendedInfo), false);
Map<String, AtlasObjectId> columnsMap = new HashMap<String, AtlasObjectId>();
columnsMap.put("col0", col0.getAtlasObjectId());
columnsMap.put("col1", col1.getAtlasObjectId());
columnsMap.put("col0", AtlasTypeUtil.getAtlasObjectId(col0));
columnsMap.put("col1", AtlasTypeUtil.getAtlasObjectId(col1));
tableEntity.setAttribute(TestUtils.COLUMNS_MAP, columnsMap);
......@@ -356,8 +356,8 @@ public class AtlasEntityStoreV1Test {
//Swap elements
columnsMap.clear();
columnsMap.put("col0", col1.getAtlasObjectId());
columnsMap.put("col1", col0.getAtlasObjectId());
columnsMap.put("col0", AtlasTypeUtil.getAtlasObjectId(col1));
columnsMap.put("col1", AtlasTypeUtil.getAtlasObjectId(col0));
tableEntity.setAttribute(TestUtils.COLUMNS_MAP, columnsMap);
init();
......@@ -367,7 +367,7 @@ public class AtlasEntityStoreV1Test {
//Drop the first key and change the class type as well to col0
columnsMap.clear();
columnsMap.put("col0", col0.getAtlasObjectId());
columnsMap.put("col0", AtlasTypeUtil.getAtlasObjectId(col0));
init();
response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
AtlasEntityHeader tableDefinition7 = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
......@@ -695,7 +695,7 @@ public class AtlasEntityStoreV1Test {
tblEntity.setAttribute("name", RandomStringUtils.randomAlphanumeric(10));
tblEntity.setAttribute("type", "type");
tblEntity.setAttribute("tableType", "MANAGED");
tblEntity.setAttribute("database", updatedDbEntity.getAtlasObjectId());
tblEntity.setAttribute("database", AtlasTypeUtil.getAtlasObjectId(updatedDbEntity));
// create new column entity
AtlasEntity col1 = TestUtilsV2.createColumnEntity(tblEntity);
......@@ -704,8 +704,8 @@ public class AtlasEntityStoreV1Test {
col2.setAttribute(TestUtilsV2.NAME, "col2");
List<AtlasObjectId> columns = new ArrayList<>();
columns.add(col1.getAtlasObjectId());
columns.add(col2.getAtlasObjectId());
columns.add(AtlasTypeUtil.getAtlasObjectId(col1));
columns.add(AtlasTypeUtil.getAtlasObjectId(col2));
tblEntity.setAttribute(TestUtilsV2.COLUMNS_ATTR_NAME, columns);
......@@ -731,8 +731,8 @@ public class AtlasEntityStoreV1Test {
col4.setAttribute("description", "description col4");
columns.clear();
columns.add(col3.getAtlasObjectId());
columns.add(col4.getAtlasObjectId());
columns.add(AtlasTypeUtil.getAtlasObjectId(col3));
columns.add(AtlasTypeUtil.getAtlasObjectId(col4));
tblEntity = new AtlasEntity(TABLE_TYPE);
tblEntity.setGuid(createdTblEntity.getGuid());
......@@ -774,7 +774,9 @@ public class AtlasEntityStoreV1Test {
columnEntity3.setAttribute("description", "desc for col3");
entitiesInfo.addReferredEntity(columnEntity3);
tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(columnEntity1.getAtlasObjectId(), columnEntity2.getAtlasObjectId(), columnEntity3.getAtlasObjectId()));
tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(columnEntity1),
AtlasTypeUtil.getAtlasObjectId(columnEntity2),
AtlasTypeUtil.getAtlasObjectId(columnEntity3)));
init();
......@@ -801,7 +803,9 @@ public class AtlasEntityStoreV1Test {
final AtlasEntity tableEntity1 = new AtlasEntity(TABLE_TYPE);
tableEntity1.setGuid(createdTblHeader.getGuid());
tableEntity1.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(col1.getAtlasObjectId(), col2.getAtlasObjectId(), col3.getAtlasObjectId()));
tableEntity1.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(col1),
AtlasTypeUtil.getAtlasObjectId(col2),
AtlasTypeUtil.getAtlasObjectId(col3)));
AtlasEntitiesWithExtInfo tableInfo = new AtlasEntitiesWithExtInfo(tableEntity1);
tableInfo.addReferredEntity(col1.getGuid(), col1);
tableInfo.addReferredEntity(col2.getGuid(), col2);
......@@ -862,7 +866,7 @@ public class AtlasEntityStoreV1Test {
case OBJECT_ID_TYPE:
Assert.assertTrue(actual instanceof AtlasObjectId);
String guid = ((AtlasObjectId) actual).getGuid();
Assert.assertTrue(AtlasEntity.isAssigned(guid), "expected assigned guid. found " + guid);
Assert.assertTrue(AtlasTypeUtil.isAssignedGuid(guid), "expected assigned guid. found " + guid);
break;
case PRIMITIVE:
......
......@@ -420,8 +420,8 @@ public class QuickStartV2 {
entity.setAttribute("createTime", System.currentTimeMillis());
entity.setAttribute("lastAccessTime", System.currentTimeMillis());
entity.setAttribute("retention", System.currentTimeMillis());
entity.setAttribute("db", db.getAtlasObjectId());
entity.setAttribute("sd", sd.getAtlasObjectId());
entity.setAttribute("db", AtlasTypeUtil.getAtlasObjectId(db));
entity.setAttribute("sd", AtlasTypeUtil.getAtlasObjectId(sd));
entity.setAttribute("columns", AtlasTypeUtil.toObjectIds(columns));
return createInstance(entity, traitNames);
......
......@@ -28,6 +28,7 @@ import org.apache.atlas.EntityAuditEvent;
import org.apache.atlas.AtlasClient.EntityResult;
import org.apache.atlas.model.instance.GuidMapping;
import org.apache.atlas.services.MetadataService;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.exception.EntityExistsException;
......@@ -201,7 +202,7 @@ public class EntityResource {
}
}
if(mapping != null) {
response.put(AtlasClient.GUID_ASSIGNMENTS, new JSONObject(mapping.toString()).get(AtlasClient.GUID_ASSIGNMENTS));
response.put(AtlasClient.GUID_ASSIGNMENTS, new JSONObject(AtlasType.toJson(mapping)).get(AtlasClient.GUID_ASSIGNMENTS));
}
return response;
}
......
......@@ -23,7 +23,6 @@ import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.store.graph.v1.EntityGraphRetriever;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.AtlasException;
import org.apache.atlas.AtlasServiceException;
......@@ -32,6 +31,7 @@ import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.impexp.*;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -133,7 +133,7 @@ public class ExportService {
private void processEntity(AtlasEntity entity, ExportContext context) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> processEntity({})", entity.getAtlasObjectId());
LOG.debug("==> processEntity({})", AtlasTypeUtil.getAtlasObjectId(entity));
}
if (!context.guidsProcessed.contains(entity.getGuid())) {
......@@ -148,7 +148,7 @@ public class ExportService {
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== processEntity({})", entity.getAtlasObjectId());
LOG.debug("<== processEntity({})", AtlasTypeUtil.getAtlasObjectId(entity));
}
}
......@@ -156,7 +156,7 @@ public class ExportService {
try {
if (LOG.isDebugEnabled()) {
LOG.debug("==> getConnectedEntityGuids({}): guidsToProcess {}", entity.getAtlasObjectId(), context.guidsToProcess.size());
LOG.debug("==> getConnectedEntityGuids({}): guidsToProcess {}", AtlasTypeUtil.getAtlasObjectId(entity), context.guidsToProcess.size());
}
List<String> result = executeGremlinScriptFor(entity.getGuid());
......
......@@ -18,8 +18,6 @@
package org.apache.atlas.web.rest;
import com.google.inject.Inject;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
......
......@@ -18,6 +18,7 @@
package org.apache.atlas.web.adapters;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.RequestContextV1;
import org.apache.atlas.RepositoryMetadataModule;
import org.apache.atlas.RequestContext;
import org.apache.atlas.TestUtilsV2;
......@@ -37,6 +38,7 @@ import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.web.rest.EntityREST;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -101,6 +103,7 @@ public class TestEntitiesREST {
@AfterMethod
public void cleanup() throws Exception {
RequestContext.clear();
RequestContextV1.clear();
}
@AfterClass
......@@ -263,7 +266,7 @@ public class TestEntitiesREST {
List<AtlasObjectId> ret = new ArrayList<>();
for (AtlasEntity entity : entities) {
ret.add(entity.getAtlasObjectId());
ret.add(AtlasTypeUtil.getAtlasObjectId(entity));
}
return ret;
......
......@@ -19,6 +19,7 @@ package org.apache.atlas.web.adapters;
import org.apache.atlas.RepositoryMetadataModule;
import org.apache.atlas.RequestContext;
import org.apache.atlas.RequestContextV1;
import org.apache.atlas.TestUtilsV2;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasEntity;
......@@ -30,6 +31,7 @@ import org.apache.atlas.model.instance.EntityMutations;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.web.rest.EntityREST;
import org.mockito.Mockito;
import org.testng.Assert;
......@@ -73,6 +75,7 @@ public class TestEntityREST {
@AfterMethod
public void cleanup() throws Exception {
RequestContext.clear();
RequestContextV1.clear();
}
private void createTestEntity() throws Exception {
......@@ -158,7 +161,7 @@ public class TestEntityREST {
EntityMutationResponse response = entityREST.createOrUpdate(new AtlasEntitiesWithExtInfo(dbEntity));
String dbGuid = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0).getGuid();
Assert.assertTrue(AtlasEntity.isAssigned(dbGuid));
Assert.assertTrue(AtlasTypeUtil.isAssignedGuid(dbGuid));
final String prevDBName = (String) dbEntity.getAttribute(TestUtilsV2.NAME);
final String updatedDBName = prevDBName + ":updated";
......@@ -189,7 +192,7 @@ public class TestEntityREST {
EntityMutationResponse response = entityREST.createOrUpdate(new AtlasEntitiesWithExtInfo(dbEntity));
String dbGuid = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0).getGuid();
Assert.assertTrue(AtlasEntity.isAssigned(dbGuid));
Assert.assertTrue(AtlasTypeUtil.isAssignedGuid(dbGuid));
final String prevDBName = (String) dbEntity.getAttribute(TestUtilsV2.NAME);
final String updatedDBName = prevDBName + ":updated";
......
......@@ -40,6 +40,7 @@ import org.apache.atlas.notification.NotificationConsumer;
import org.apache.atlas.notification.NotificationInterface;
import org.apache.atlas.notification.NotificationModule;
import org.apache.atlas.notification.entity.EntityNotification;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.Struct;
......@@ -158,7 +159,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.CREATE_ENTITY, json);
GuidMapping guidMapping = GuidMapping.fromString(response.toString());
GuidMapping guidMapping = AtlasType.fromJson(response.toString(), GuidMapping.class);
Map<String,String> guidsCreated = guidMapping.getGuidAssignments();
assertEquals(guidsCreated.size(), nTables * colsPerTable + nTables + 1);
......
......@@ -126,7 +126,7 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
AtlasEntity tableInstance = new AtlasEntity(HIVE_TABLE_TYPE_V2, "name", tableName);
tableInstance.setAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
tableInstance.setAttribute("db", databaseInstance.getAtlasObjectId());
tableInstance.setAttribute("db", AtlasTypeUtil.getAtlasObjectId(databaseInstance));
tableInstance.setAttribute("description", tableName + " table");
entities.addEntity(tableInstance);
......@@ -137,7 +137,7 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
columnInstance.setAttribute("dataType", "String");
columnInstance.setAttribute("comment", "column " + j + " for table " + i);
columns.add(columnInstance.getAtlasObjectId());
columns.add(AtlasTypeUtil.getAtlasObjectId(columnInstance));
entities.addReferredEntity(columnInstance);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment