use of org.apache.atlas.model.typedef.AtlasEntityDef in project atlas by apache.
the class TypesREST method getEntityDefByGuid.
/**
* Get the Entity definition for the given guid
* @param guid entity guid
* @return Entity definition
* @throws AtlasBaseException
* @HTTP 200 On successful lookup of the the entity definition by it's guid
* @HTTP 404 On Failed lookup for the given guid
*/
@GET
@Path("/entitydef/guid/{guid}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntityDef getEntityDefByGuid(@PathParam("guid") String guid) throws AtlasBaseException {
Servlets.validateQueryParamLength("guid", guid);
AtlasEntityDef ret = typeDefStore.getEntityDefByGuid(guid);
return ret;
}
use of org.apache.atlas.model.typedef.AtlasEntityDef in project atlas by apache.
the class TypesREST method getEntityDefByName.
/**
* Get the entity definition by it's name (unique)
* @param name entity name
* @return Entity definition
* @throws AtlasBaseException
* @HTTP 200 On successful lookup of the the entity definition by it's name
* @HTTP 404 On Failed lookup for the given name
*/
@GET
@Path("/entitydef/name/{name}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntityDef getEntityDefByName(@PathParam("name") String name) throws AtlasBaseException {
Servlets.validateQueryParamLength("name", name);
AtlasEntityDef ret = typeDefStore.getEntityDefByName(name);
return ret;
}
use of org.apache.atlas.model.typedef.AtlasEntityDef in project atlas by apache.
the class EntityV2JerseyResourceIT method testEntityDefinitionAcrossTypeUpdate.
@Test
public void testEntityDefinitionAcrossTypeUpdate() throws Exception {
// create type
AtlasEntityDef entityDef = AtlasTypeUtil.createClassTypeDef(randomString(), Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getEntityDefs().add(entityDef);
AtlasTypesDef created = atlasClientV2.createAtlasTypeDefs(typesDef);
assertNotNull(created);
assertNotNull(created.getEntityDefs());
assertEquals(created.getEntityDefs().size(), 1);
// create entity for the type
AtlasEntity instance = new AtlasEntity(entityDef.getName());
instance.setAttribute("name", randomString());
EntityMutationResponse mutationResponse = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(instance));
assertNotNull(mutationResponse);
assertNotNull(mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
assertEquals(mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).size(), 1);
String guid = mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0).getGuid();
// update type - add attribute
entityDef = AtlasTypeUtil.createClassTypeDef(entityDef.getName(), Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createOptionalAttrDef("description", "string"));
typesDef = new AtlasTypesDef();
typesDef.getEntityDefs().add(entityDef);
AtlasTypesDef updated = atlasClientV2.updateAtlasTypeDefs(typesDef);
assertNotNull(updated);
assertNotNull(updated.getEntityDefs());
assertEquals(updated.getEntityDefs().size(), 1);
// Get definition after type update - new attributes should be null
AtlasEntity entityByGuid = getEntityByGuid(guid);
assertNull(entityByGuid.getAttribute("description"));
assertEquals(entityByGuid.getAttribute("name"), instance.getAttribute("name"));
}
use of org.apache.atlas.model.typedef.AtlasEntityDef in project atlas by apache.
the class TypedefsJerseyResourceIT method testInvalidGets.
@Test
public void testInvalidGets() throws Exception {
try {
AtlasEnumDef byName = clientV2.getEnumDefByName("blah");
fail("Get for invalid name should have reported a failure");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
}
try {
AtlasEnumDef byGuid = clientV2.getEnumDefByGuid("blah");
fail("Get for invalid name should have reported a failure");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
}
try {
AtlasStructDef byName = clientV2.getStructDefByName("blah");
fail("Get for invalid name should have reported a failure");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
}
try {
AtlasStructDef byGuid = clientV2.getStructDefByGuid("blah");
fail("Get for invalid name should have reported a failure");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
}
try {
AtlasClassificationDef byName = clientV2.getClassificationDefByName("blah");
fail("Get for invalid name should have reported a failure");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
}
try {
AtlasClassificationDef byGuid = clientV2.getClassificationDefByGuid("blah");
fail("Get for invalid name should have reported a failure");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
}
try {
AtlasEntityDef byName = clientV2.getEntityDefByName("blah");
fail("Get for invalid name should have reported a failure");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
}
try {
AtlasEntityDef byGuid = clientV2.getEntityDefByGuid("blah");
fail("Get for invalid name should have reported a failure");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
}
}
use of org.apache.atlas.model.typedef.AtlasEntityDef in project atlas by apache.
the class TypedefsJerseyResourceIT method testDuplicateCreate.
@Test
public void testDuplicateCreate() throws Exception {
AtlasEntityDef type = createClassTypeDef(randomString(), Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getEntityDefs().add(type);
AtlasTypesDef created = clientV2.createAtlasTypeDefs(typesDef);
assertNotNull(created);
try {
created = clientV2.createAtlasTypeDefs(typesDef);
fail("Expected 409");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode());
}
}
Aggregations