Search in sources :

Example 16 with AttributeDefinition

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;
}
Also used : AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) JSONException(org.codehaus.jettison.json.JSONException)

Example 17 with AttributeDefinition

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));
}
Also used : AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) TypeUpdateException(org.apache.atlas.typesystem.types.TypeUpdateException) ClassType(org.apache.atlas.typesystem.types.ClassType) Test(org.testng.annotations.Test)

Example 18 with AttributeDefinition

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);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) JSONObject(org.codehaus.jettison.json.JSONObject) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) QueryParams(org.apache.atlas.query.QueryParams) ClassType(org.apache.atlas.typesystem.types.ClassType) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 19 with AttributeDefinition

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);
}
Also used : TypesDef(org.apache.atlas.typesystem.TypesDef) TraitType(org.apache.atlas.typesystem.types.TraitType) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType) BeforeClass(org.testng.annotations.BeforeClass)

Example 20 with AttributeDefinition

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);
}
Also used : AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) Test(org.testng.annotations.Test)

Aggregations

AttributeDefinition (org.apache.atlas.typesystem.types.AttributeDefinition)27 ClassType (org.apache.atlas.typesystem.types.ClassType)17 Test (org.testng.annotations.Test)13 TraitType (org.apache.atlas.typesystem.types.TraitType)10 ArrayList (java.util.ArrayList)7 TypesDef (org.apache.atlas.typesystem.TypesDef)7 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)5 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)4 HierarchicalTypeDefinition (org.apache.atlas.typesystem.types.HierarchicalTypeDefinition)4 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)3 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)3 Referenceable (org.apache.atlas.typesystem.Referenceable)3 StructTypeDefinition (org.apache.atlas.typesystem.types.StructTypeDefinition)3 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)3 BeforeTest (org.testng.annotations.BeforeTest)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)2 QueryParams (org.apache.atlas.query.QueryParams)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 Callable (java.util.concurrent.Callable)1