Search in sources :

Example 61 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class EntityJerseyResourceIT method testSubmitEntityWithBadDateFormat.

@Test
public void testSubmitEntityWithBadDateFormat() throws Exception {
    try {
        String dbName = "db" + randomString();
        String tableName = "table" + randomString();
        Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
        Id dbId = createInstance(hiveDBInstance);
        Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
        hiveTableInstance.set("lastAccessTime", "2014-07-11");
        Id tableId = createInstance(hiveTableInstance);
        Assert.fail("Was expecting an  exception here ");
    } catch (AtlasServiceException e) {
        Assert.assertTrue(e.getMessage().contains("\"error\":\"Cannot convert value '2014-07-11' to datatype date\""));
    }
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) AtlasServiceException(org.apache.atlas.AtlasServiceException) Id(org.apache.atlas.typesystem.persistence.Id) Test(org.testng.annotations.Test)

Example 62 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class EntityJerseyResourceIT method testGetTraitNames.

@Test
public void testGetTraitNames() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(hiveTableInstance);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    List<String> traits = atlasClientV1.listTraits(guid);
    assertNotNull(traits);
    Assert.assertEquals(traits.size(), 7);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) Id(org.apache.atlas.typesystem.persistence.Id) Test(org.testng.annotations.Test)

Example 63 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class EntityJerseyResourceIT method testPartialUpdate.

@Test
public void testPartialUpdate() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id tableId = createInstance(hiveTableInstance);
    final String guid = tableId._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    String colName = "col1" + randomString();
    final List<Referenceable> columns = new ArrayList<>();
    Map<String, Object> values = new HashMap<>();
    values.put(NAME, colName);
    values.put("comment", "col1 comment");
    values.put(QUALIFIED_NAME, "default.table.col1@" + colName);
    values.put("comment", "col1 comment");
    values.put("type", "string");
    values.put("owner", "user1");
    values.put("position", 0);
    values.put("description", "col1");
    //table is a required reference, can't be null
    values.put("table", tableId);
    Referenceable ref = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values);
    columns.add(ref);
    Referenceable tableUpdated = new Referenceable(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, new HashMap<String, Object>() {

        {
            put("columns", columns);
        }
    });
    LOG.debug("Updating entity= {}", tableUpdated);
    EntityResult entityResult = atlasClientV1.updateEntity(guid, tableUpdated);
    assertEquals(entityResult.getUpdateEntities().size(), 1);
    assertEquals(entityResult.getUpdateEntities().get(0), guid);
    Referenceable entity = atlasClientV1.getEntity(guid);
    List<Referenceable> refs = (List<Referenceable>) entity.get("columns");
    Assert.assertTrue(refs.get(0).equalsContents(columns.get(0)));
    //Update by unique attribute
    values.put("type", "int");
    ref = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values);
    columns.set(0, ref);
    tableUpdated = new Referenceable(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, new HashMap<String, Object>() {

        {
            put("columns", columns);
        }
    });
    LOG.debug("Updating entity= {}", tableUpdated);
    entityResult = atlasClientV1.updateEntity(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, (String) hiveTableInstance.get(QUALIFIED_NAME), tableUpdated);
    assertEquals(entityResult.getUpdateEntities().size(), 2);
    assertEquals(entityResult.getUpdateEntities().get(1), guid);
    entity = atlasClientV1.getEntity(guid);
    refs = (List<Referenceable>) entity.get("columns");
    Assert.assertTrue(refs.get(0).getValuesMap().equals(values));
    Assert.assertEquals(refs.get(0).get("type"), "int");
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONObject(org.codehaus.jettison.json.JSONObject) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Id(org.apache.atlas.typesystem.persistence.Id) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

Example 64 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class VertexLookupContext method addInstance.

/**
     * Adds an instance to be loaded.
     *
     */
public void addInstance(IReferenceableInstance instance) throws AtlasException {
    ClassType classType = typeSystem.getDataType(ClassType.class, instance.getTypeName());
    ITypedReferenceableInstance newInstance = classType.convert(instance, Multiplicity.REQUIRED);
    findReferencedInstancesToPreLoad(newInstance);
    Id id = instance.getId();
    if (mapper.lookupVertex(id) == null) {
        if (id.isAssigned()) {
            guidsToLookup.add(id);
        } else {
            addToClassMap(classType, instance);
        }
    }
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 65 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class ReplaceIdWithInstance method convertToInstances.

ImmutableCollection<?> convertToInstances(ImmutableCollection<?> val, Multiplicity m, DataTypes.ArrayType arrType) throws AtlasException {
    if (val == null || arrType.getElemType().getTypeCategory() != DataTypes.TypeCategory.CLASS) {
        return val;
    }
    ImmutableCollection.Builder b = m.isUnique ? ImmutableSet.builder() : ImmutableList.builder();
    for (Object elem : val) {
        if (elem instanceof Id) {
            Id id = (Id) elem;
            elem = getInstance(id);
        }
        b.add(elem);
    }
    return b.build();
}
Also used : ImmutableCollection(com.google.common.collect.ImmutableCollection) Id(org.apache.atlas.typesystem.persistence.Id)

Aggregations

Id (org.apache.atlas.typesystem.persistence.Id)94 Referenceable (org.apache.atlas.typesystem.Referenceable)50 Test (org.testng.annotations.Test)37 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)28 List (java.util.List)17 ArrayList (java.util.ArrayList)12 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)12 ImmutableList (com.google.common.collect.ImmutableList)10 TraitType (org.apache.atlas.typesystem.types.TraitType)10 JSONObject (org.codehaus.jettison.json.JSONObject)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AtlasServiceException (org.apache.atlas.AtlasServiceException)7 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)7 Struct (org.apache.atlas.typesystem.Struct)7 ClassType (org.apache.atlas.typesystem.types.ClassType)7 AtlasException (org.apache.atlas.AtlasException)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)6 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)5