use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.
the class EntityREST method getByUniqueAttributes.
/**
* Fetch complete definition of an entity given its type and unique attribute.
* @param typeName
* @return AtlasEntityWithExtInfo
* @throws AtlasBaseException
*/
@GET
@Path("/uniqueAttribute/type/{typeName}")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntityWithExtInfo getByUniqueAttributes(@PathParam("typeName") String typeName, @Context HttpServletRequest servletRequest) throws AtlasBaseException {
AtlasPerfTracer perf = null;
try {
Map<String, Object> attributes = getAttributes(servletRequest);
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getByUniqueAttributes(" + typeName + "," + attributes + ")");
}
AtlasEntityType entityType = ensureEntityType(typeName);
validateUniqueAttribute(entityType, attributes);
return entitiesStore.getByUniqueAttributes(entityType, attributes);
} finally {
AtlasPerfTracer.log(perf);
}
}
use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.
the class EntityREST method deleteByUniqueAttribute.
/**
* Delete an entity identified by its type and unique attributes.
* @param typeName - entity type to be deleted
* @param servletRequest - request containing unique attributes/values
* @return EntityMutationResponse
*/
@DELETE
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
@Path("/uniqueAttribute/type/{typeName}")
public EntityMutationResponse deleteByUniqueAttribute(@PathParam("typeName") String typeName, @Context HttpServletRequest servletRequest) throws AtlasBaseException {
AtlasPerfTracer perf = null;
try {
Map<String, Object> attributes = getAttributes(servletRequest);
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.deleteByUniqueAttribute(" + typeName + "," + attributes + ")");
}
AtlasEntityType entityType = ensureEntityType(typeName);
return entitiesStore.deleteByUniqueAttributes(entityType, attributes);
} finally {
AtlasPerfTracer.log(perf);
}
}
use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.
the class AtlasEntityStoreV1 method preCreateOrUpdate.
private EntityMutationContext preCreateOrUpdate(EntityStream entityStream, EntityGraphMapper entityGraphMapper, boolean isPartialUpdate) throws AtlasBaseException {
EntityGraphDiscovery graphDiscoverer = new AtlasEntityGraphDiscoveryV1(typeRegistry, entityStream);
EntityGraphDiscoveryContext discoveryContext = graphDiscoverer.discoverEntities();
EntityMutationContext context = new EntityMutationContext(discoveryContext);
for (String guid : discoveryContext.getReferencedGuids()) {
AtlasVertex vertex = discoveryContext.getResolvedEntityVertex(guid);
AtlasEntity entity = entityStream.getByGuid(guid);
if (entity != null) {
if (vertex != null) {
// entity would be null if guid is not in the stream but referenced by an entity in the stream
if (!isPartialUpdate) {
graphDiscoverer.validateAndNormalize(entity);
} else {
graphDiscoverer.validateAndNormalizeForUpdate(entity);
}
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());
String guidVertex = AtlasGraphUtilsV1.getIdFromVertex(vertex);
if (!StringUtils.equals(guidVertex, guid)) {
// if entity was found by unique attribute
entity.setGuid(guidVertex);
}
context.addUpdated(guid, entity, entityType, vertex);
} else {
graphDiscoverer.validateAndNormalize(entity);
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());
//Create vertices which do not exist in the repository
if ((entityStream instanceof EntityImportStream) && AtlasTypeUtil.isAssignedGuid(entity.getGuid())) {
vertex = entityGraphMapper.createVertexWithGuid(entity, entity.getGuid());
} else {
vertex = entityGraphMapper.createVertex(entity);
}
discoveryContext.addResolvedGuid(guid, vertex);
String generatedGuid = AtlasGraphUtilsV1.getIdFromVertex(vertex);
entity.setGuid(generatedGuid);
context.addCreated(guid, entity, entityType, vertex);
}
// during import, update the system attributes
if (entityStream instanceof EntityImportStream) {
entityGraphMapper.updateSystemAttributes(vertex, entity);
}
}
}
return context;
}
use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.
the class AtlasEntityGraphDiscoveryV1 method validateAndNormalizeForUpdate.
@Override
public void validateAndNormalizeForUpdate(AtlasEntity entity) throws AtlasBaseException {
List<String> messages = new ArrayList<>();
if (!AtlasTypeUtil.isValidGuid(entity.getGuid())) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid());
}
AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName());
if (type == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), entity.getTypeName());
}
type.validateValueForUpdate(entity, entity.getTypeName(), messages);
if (!messages.isEmpty()) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, messages);
}
type.getNormalizedValueForUpdate(entity);
}
use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.
the class RestUtilsTest method convertV2toV1.
private List<HierarchicalTypeDefinition<ClassType>> convertV2toV1(List<AtlasEntityDef> toConvert) throws AtlasBaseException {
AtlasTypeRegistry reg = createRegistry(toConvert);
List<HierarchicalTypeDefinition<ClassType>> result = new ArrayList<>(toConvert.size());
for (int i = 0; i < toConvert.size(); i++) {
AtlasEntityDef entityDef = toConvert.get(i);
AtlasEntityType entity = reg.getEntityTypeByName(entityDef.getName());
HierarchicalTypeDefinition<ClassType> converted = TypeConverterUtil.toTypesDef(entity, reg).classTypesAsJavaList().get(0);
result.add(converted);
}
return result;
}
Aggregations