use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.
the class EntityV2JerseyResourceIT method testUTF8.
@Test
public void testUTF8() throws Exception {
String classType = randomString();
String attrName = random();
String attrValue = random();
AtlasEntityDef classTypeDef = AtlasTypeUtil.createClassTypeDef(classType, ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef(attrName, "string"));
AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
atlasTypesDef.getEntityDefs().add(classTypeDef);
createType(atlasTypesDef);
AtlasEntity instance = new AtlasEntity(classType);
instance.setAttribute(attrName, attrValue);
AtlasEntityHeader entity = createEntity(instance);
assertNotNull(entity);
assertNotNull(entity.getGuid());
AtlasEntity entityByGuid = getEntityByGuid(entity.getGuid());
assertEquals(entityByGuid.getAttribute(attrName), attrValue);
}
use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.
the class EntityV2JerseyResourceIT method testDeleteEntities.
@Test
public void testDeleteEntities() throws Exception {
// Create 2 database entities
AtlasEntity db1 = new AtlasEntity(DATABASE_TYPE_V2);
String dbName1 = randomString();
db1.setAttribute("name", dbName1);
db1.setAttribute(NAME, dbName1);
db1.setAttribute("clusterName", randomString());
db1.setAttribute("description", randomString());
AtlasEntityHeader entity1Header = createEntity(db1);
AtlasEntity db2 = new AtlasEntity(DATABASE_TYPE_V2);
String dbName2 = randomString();
db2.setAttribute("name", dbName2);
db2.setAttribute(NAME, dbName2);
db2.setAttribute("clusterName", randomString());
db2.setAttribute("description", randomString());
AtlasEntityHeader entity2Header = createEntity(db2);
// Delete the database entities
EntityMutationResponse deleteResponse = atlasClientV2.deleteEntitiesByGuids(ImmutableList.of(entity1Header.getGuid(), entity2Header.getGuid()));
// Verify that deleteEntities() response has database entity guids
assertNotNull(deleteResponse);
assertNotNull(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE));
assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 2);
// Verify entities were deleted from the repository.
}
use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.
the class IDBasedEntityResolver method resolveEntityReferences.
public EntityGraphDiscoveryContext resolveEntityReferences(EntityGraphDiscoveryContext context) throws AtlasBaseException {
if (context == null) {
throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, "IDBasedEntityResolver.resolveEntityReferences(): context is null");
}
EntityStream entityStream = context.getEntityStream();
for (String guid : context.getReferencedGuids()) {
boolean isAssignedGuid = AtlasTypeUtil.isAssignedGuid(guid);
AtlasVertex vertex = isAssignedGuid ? AtlasGraphUtilsV1.findByGuid(guid) : null;
if (vertex == null && !(entityStream instanceof EntityImportStream)) {
// if not found in the store, look if the entity is present in the stream
AtlasEntity entity = entityStream.getByGuid(guid);
if (entity != null) {
// look for the entity in the store using unique-attributes
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());
if (entityType == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), entity.getTypeName());
}
vertex = AtlasGraphUtilsV1.findByUniqueAttributes(entityType, entity.getAttributes());
} else if (!isAssignedGuid) {
// for local-guids, entity must be in the stream
throw new AtlasBaseException(AtlasErrorCode.REFERENCED_ENTITY_NOT_FOUND, guid);
}
}
if (vertex != null) {
context.addResolvedGuid(guid, vertex);
} else {
if (isAssignedGuid && !(entityStream instanceof EntityImportStream)) {
throw new AtlasBaseException(AtlasErrorCode.REFERENCED_ENTITY_NOT_FOUND, guid);
} else {
context.addLocalGuidReference(guid);
}
}
}
return context;
}
use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.
the class EntityGraphRetriever method toAtlasEntitiesWithExtInfo.
public AtlasEntitiesWithExtInfo toAtlasEntitiesWithExtInfo(List<String> guids) throws AtlasBaseException {
AtlasEntitiesWithExtInfo ret = new AtlasEntitiesWithExtInfo();
for (String guid : guids) {
AtlasVertex vertex = getEntityVertex(guid);
AtlasEntity entity = mapVertexToAtlasEntity(vertex, ret);
ret.addEntity(entity);
}
ret.compact();
return ret;
}
use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.
the class EntityGraphMapper method mapAttributesAndClassifications.
public EntityMutationResponse mapAttributesAndClassifications(EntityMutationContext context, final boolean isPartialUpdate, final boolean replaceClassifications) throws AtlasBaseException {
EntityMutationResponse resp = new EntityMutationResponse();
Collection<AtlasEntity> createdEntities = context.getCreatedEntities();
Collection<AtlasEntity> updatedEntities = context.getUpdatedEntities();
if (CollectionUtils.isNotEmpty(createdEntities)) {
for (AtlasEntity createdEntity : createdEntities) {
String guid = createdEntity.getGuid();
AtlasVertex vertex = context.getVertex(guid);
AtlasEntityType entityType = context.getType(guid);
mapAttributes(createdEntity, vertex, CREATE, context);
resp.addEntity(CREATE, constructHeader(createdEntity, entityType, vertex));
addClassifications(context, guid, createdEntity.getClassifications());
}
}
if (CollectionUtils.isNotEmpty(updatedEntities)) {
for (AtlasEntity updatedEntity : updatedEntities) {
String guid = updatedEntity.getGuid();
AtlasVertex vertex = context.getVertex(guid);
AtlasEntityType entityType = context.getType(guid);
mapAttributes(updatedEntity, vertex, UPDATE, context);
if (isPartialUpdate) {
resp.addEntity(PARTIAL_UPDATE, constructHeader(updatedEntity, entityType, vertex));
} else {
resp.addEntity(UPDATE, constructHeader(updatedEntity, entityType, vertex));
}
if (replaceClassifications) {
deleteClassifications(guid);
addClassifications(context, guid, updatedEntity.getClassifications());
}
}
}
RequestContextV1 req = RequestContextV1.get();
for (AtlasObjectId id : req.getDeletedEntityIds()) {
resp.addEntity(DELETE, constructHeader(id));
}
for (AtlasObjectId id : req.getUpdatedEntityIds()) {
if (isPartialUpdate) {
resp.addEntity(PARTIAL_UPDATE, constructHeader(id));
} else {
resp.addEntity(UPDATE, constructHeader(id));
}
}
return resp;
}
Aggregations