use of org.apache.atlas.typesystem.types.AttributeDefinition in project incubator-atlas by apache.
the class AtlasStructDefStoreV1 method toAttributeDefintion.
public static AttributeDefinition toAttributeDefintion(AtlasAttribute attribute) {
AttributeDefinition ret = null;
String jsonString = toJsonFromAttribute(attribute);
try {
ret = AttributeInfo.fromJson(jsonString);
} catch (JSONException excp) {
LOG.error("failed in converting to AttributeDefinition: " + jsonString, excp);
}
return ret;
}
use of org.apache.atlas.typesystem.types.AttributeDefinition in project incubator-atlas by apache.
the class StoreBackedTypeCacheMetadataServiceTest method testInvalidUpdateType.
@Test
public void testInvalidUpdateType() throws Exception {
// Cache should be empty
Assert.assertFalse(storeBackedTypeCache.isCachedInMemory(TestUtils.TABLE_TYPE));
HierarchicalTypeDefinition<ClassType> classTypeDef = TypesUtil.createClassTypeDef(TestUtils.TABLE_TYPE, ImmutableSet.<String>of(), new AttributeDefinition("attr1", DataTypes.STRING_TYPE.getName(), Multiplicity.OPTIONAL, false, null));
String json = TypesSerialization.toJson(classTypeDef, false);
// Try to update the type with disallowed changes. Should fail with TypeUpdateException.
try {
metadataService.updateType(json);
Assert.fail(TypeUpdateException.class.getSimpleName() + " was expected but none thrown");
} catch (TypeUpdateException e) {
// good
}
// hive_table type should now be cached.
Assert.assertTrue(storeBackedTypeCache.isCachedInMemory(TestUtils.TABLE_TYPE));
}
use of org.apache.atlas.typesystem.types.AttributeDefinition in project incubator-atlas by apache.
the class DefaultMetadataServiceTest method testSpecialCharacters.
@Test
public //See GraphHelper.encodePropertyKey()
void testSpecialCharacters() throws Exception {
//Verify that type can be created with reserved characters in typename, attribute name
String strAttrName = randomStrWithReservedChars();
String arrayAttrName = randomStrWithReservedChars();
String mapAttrName = randomStrWithReservedChars();
HierarchicalTypeDefinition<ClassType> typeDefinition = createClassTypeDef("test_type_" + RandomStringUtils.randomAlphanumeric(10), ImmutableSet.<String>of(), createOptionalAttrDef(strAttrName, DataTypes.STRING_TYPE), new AttributeDefinition(arrayAttrName, DataTypes.arrayTypeName(DataTypes.STRING_TYPE.getName()), Multiplicity.OPTIONAL, false, null), new AttributeDefinition(mapAttrName, DataTypes.mapTypeName(DataTypes.STRING_TYPE.getName(), DataTypes.STRING_TYPE.getName()), Multiplicity.OPTIONAL, false, null));
metadataService.createType(TypesSerialization.toJson(typeDefinition, false));
//verify that entity can be created with reserved characters in string value, array value and map key and value
Referenceable entity = new Referenceable(typeDefinition.typeName);
entity.set(strAttrName, randomStrWithReservedChars());
entity.set(arrayAttrName, new ArrayList<String>() {
{
add(randomStrWithReservedChars());
}
});
entity.set(mapAttrName, new HashMap<String, String>() {
{
put(randomStrWithReservedChars(), randomStrWithReservedChars());
}
});
String id = createInstance(metadataService, entity);
//Verify that get entity definition returns actual values with reserved characters
Referenceable instance = InstanceSerialization.fromJsonReferenceable(metadataService.getEntityDefinitionJson(id), true);
assertReferenceableEquals(instance, entity);
//Verify that search with reserved characters works - for string attribute
String query = String.format("`%s` where `%s` = '%s'", typeDefinition.typeName, strAttrName, entity.get(strAttrName));
String responseJson = discoveryService.searchByDSL(query, new QueryParams(1, 0));
JSONObject response = new JSONObject(responseJson);
assertEquals(response.getJSONArray("rows").length(), 1);
}
use of org.apache.atlas.typesystem.types.AttributeDefinition in project incubator-atlas by apache.
the class ReverseReferenceUpdateTestBase method setUp.
@BeforeClass
public void setUp() throws Exception {
typeSystem = TypeSystem.getInstance();
typeSystem.reset();
HierarchicalTypeDefinition<ClassType> aDef = TypesUtil.createClassTypeDef("A", ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), // 1-1
new AttributeDefinition("b", "B", Multiplicity.OPTIONAL, false, "a"), // 1-*
new AttributeDefinition("oneB", "B", Multiplicity.OPTIONAL, false, "manyA"), // *-*
new AttributeDefinition("manyB", DataTypes.arrayTypeName("B"), Multiplicity.OPTIONAL, false, "manyToManyA"), new AttributeDefinition("map", DataTypes.mapTypeName(DataTypes.STRING_TYPE.getName(), "B"), Multiplicity.OPTIONAL, false, "backToMap"));
HierarchicalTypeDefinition<ClassType> bDef = TypesUtil.createClassTypeDef("B", ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), new AttributeDefinition("a", "A", Multiplicity.OPTIONAL, false, "b"), new AttributeDefinition("manyA", DataTypes.arrayTypeName("A"), Multiplicity.OPTIONAL, false, "oneB"), new AttributeDefinition("manyToManyA", DataTypes.arrayTypeName("A"), Multiplicity.OPTIONAL, false, "manyB"), new AttributeDefinition("backToMap", "A", Multiplicity.OPTIONAL, false, "map"));
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(aDef, bDef));
typeSystem.defineTypes(typesDef);
typeA = typeSystem.getDataType(ClassType.class, "A");
typeB = typeSystem.getDataType(ClassType.class, "B");
repositoryService = TestUtils.addTransactionWrapper(repositoryService);
}
use of org.apache.atlas.typesystem.types.AttributeDefinition in project incubator-atlas by apache.
the class TypesJerseyResourceIT method testListTypesByFilter.
@Test
public void testListTypesByFilter() throws Exception {
AttributeDefinition attr = TypesUtil.createOptionalAttrDef("attr", DataTypes.STRING_TYPE);
String a = createType(TypesSerialization.toJson(TypesUtil.createClassTypeDef("A" + randomString(), ImmutableSet.<String>of(), attr), false)).get(0);
String a1 = createType(TypesSerialization.toJson(TypesUtil.createClassTypeDef("A1" + randomString(), ImmutableSet.of(a), attr), false)).get(0);
String b = createType(TypesSerialization.toJson(TypesUtil.createClassTypeDef("B" + randomString(), ImmutableSet.<String>of(), attr), false)).get(0);
String c = createType(TypesSerialization.toJson(TypesUtil.createClassTypeDef("C" + randomString(), ImmutableSet.of(a, b), attr), false)).get(0);
List<String> results = atlasClientV1.listTypes(DataTypes.TypeCategory.CLASS, a, b);
assertEquals(results, Arrays.asList(a1), "Results: " + results);
}
Aggregations