use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.
the class RestUtilsTest method makeTypeStore.
private AtlasTypeDefGraphStoreV1 makeTypeStore(AtlasTypeRegistry reg) {
AtlasTypeDefGraphStoreV1 result = mock(AtlasTypeDefGraphStoreV1.class);
for (AtlasEntityType type : reg.getAllEntityTypes()) {
String typeName = type.getTypeName();
AtlasVertex typeVertex = mock(AtlasVertex.class);
when(result.isTypeVertex(eq(typeVertex), any(TypeCategory.class))).thenReturn(true);
when(typeVertex.getProperty(eq(Constants.TYPE_CATEGORY_PROPERTY_KEY), eq(TypeCategory.class))).thenReturn(TypeCategory.CLASS);
String attributeListPropertyKey = AtlasGraphUtilsV1.getTypeDefPropertyKey(typeName);
when(typeVertex.getProperty(eq(attributeListPropertyKey), eq(List.class))).thenReturn(new ArrayList<>(type.getAllAttributes().keySet()));
for (AtlasAttribute attribute : type.getAllAttributes().values()) {
String attributeDefPropertyKey = AtlasGraphUtilsV1.getTypeDefPropertyKey(typeName, attribute.getName());
String attributeJson = AtlasStructDefStoreV1.toJsonFromAttribute(attribute);
when(typeVertex.getProperty(eq(attributeDefPropertyKey), eq(String.class))).thenReturn(attributeJson);
}
when(result.findTypeVertexByName(eq(typeName))).thenReturn(typeVertex);
}
return result;
}
use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.
the class AtlasTypeDefGraphStore method searchTypesDef.
@Override
public AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException {
final AtlasTypesDef typesDef = new AtlasTypesDef();
Predicate searchPredicates = FilterUtil.getPredicateFromSearchFilter(searchFilter);
for (AtlasEnumType enumType : typeRegistry.getAllEnumTypes()) {
if (searchPredicates.evaluate(enumType)) {
typesDef.getEnumDefs().add(enumType.getEnumDef());
}
}
for (AtlasStructType structType : typeRegistry.getAllStructTypes()) {
if (searchPredicates.evaluate(structType)) {
typesDef.getStructDefs().add(structType.getStructDef());
}
}
for (AtlasClassificationType classificationType : typeRegistry.getAllClassificationTypes()) {
if (searchPredicates.evaluate(classificationType)) {
typesDef.getClassificationDefs().add(classificationType.getClassificationDef());
}
}
for (AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) {
if (searchPredicates.evaluate(entityType)) {
typesDef.getEntityDefs().add(entityType.getEntityDef());
}
}
return typesDef;
}
use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.
the class AtlasEntityGraphDiscoveryV1 method walkEntityGraph.
void walkEntityGraph(AtlasEntity entity) throws AtlasBaseException {
if (entity == null) {
return;
}
AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName());
recordObjectReference(entity.getGuid());
visitStruct(type, entity);
}
use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.
the class AtlasEntityGraphDiscoveryV1 method validateAndNormalize.
@Override
public void validateAndNormalize(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.validateValue(entity, entity.getTypeName(), messages);
if (!messages.isEmpty()) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, messages);
}
type.getNormalizedValue(entity);
}
use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.
the class EntityREST method partialUpdateEntityByUniqueAttrs.
/*******
* Entity Partial Update - Allows a subset of attributes to be updated on
* an entity which is identified by its type and unique attribute eg: Referenceable.qualifiedName.
* Null updates are not possible
*******/
@PUT
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
@Path("/uniqueAttribute/type/{typeName}")
public EntityMutationResponse partialUpdateEntityByUniqueAttrs(@PathParam("typeName") String typeName, @Context HttpServletRequest servletRequest, AtlasEntityWithExtInfo entityInfo) throws Exception {
AtlasPerfTracer perf = null;
try {
Map<String, Object> uniqueAttributes = getAttributes(servletRequest);
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.partialUpdateEntityByUniqueAttrs(" + typeName + "," + uniqueAttributes + ")");
}
AtlasEntityType entityType = ensureEntityType(typeName);
validateUniqueAttribute(entityType, uniqueAttributes);
return entitiesStore.updateByUniqueAttributes(entityType, uniqueAttributes, entityInfo);
} finally {
AtlasPerfTracer.log(perf);
}
}
Aggregations