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\""));
}
}
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);
}
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");
}
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);
}
}
}
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();
}
Aggregations