use of org.apache.atlas.typesystem.IStruct in project incubator-atlas by apache.
the class SoftDeleteHandlerV1Test method assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes.
@Override
protected void assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes(final String structContainerGuid) throws Exception {
// Verify that the unidirectional references from the struct and trait instances
// to the deleted entities were not disconnected.
ITypedReferenceableInstance structContainerConvertedEntity = metadataService.getEntityDefinition(structContainerGuid);
ITypedStruct struct = (ITypedStruct) structContainerConvertedEntity.get("struct");
assertNotNull(struct.get("target"));
IStruct trait = structContainerConvertedEntity.getTrait("TestTrait");
assertNotNull(trait);
assertNotNull(trait.get("target"));
}
use of org.apache.atlas.typesystem.IStruct in project incubator-atlas by apache.
the class HardDeleteHandlerV1Test method assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes.
@Override
protected void assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes(String structContainerGuid) throws Exception {
// Verify that the unidirectional references from the struct and trait instances
// to the deleted entities were disconnected.
ITypedReferenceableInstance structContainerConvertedEntity = metadataService.getEntityDefinition(structContainerGuid);
ITypedStruct struct = (ITypedStruct) structContainerConvertedEntity.get("struct");
assertNull(struct.get("target"));
IStruct trait = structContainerConvertedEntity.getTrait("TestTrait");
assertNotNull(trait);
assertNull(trait.get("target"));
}
use of org.apache.atlas.typesystem.IStruct in project incubator-atlas by apache.
the class DefaultMetadataServiceTest method assertReferenceableEquals.
//equals excluding the id
private void assertReferenceableEquals(Referenceable actual, Referenceable expected) {
List<String> traits = actual.getTraits();
Map<String, IStruct> traitsMap = new HashMap<>();
for (String trait : traits) {
traitsMap.put(trait, actual.getTrait(trait));
}
Referenceable newActual = new Referenceable(expected.getId(), actual.getTypeName(), actual.getValuesMap(), traits, traitsMap);
assertEquals(newActual, expected);
}
use of org.apache.atlas.typesystem.IStruct in project incubator-atlas by apache.
the class AtlasStructFormatConverter method fromV1ToV2.
@Override
public Object fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext converterContext) throws AtlasBaseException {
AtlasStruct ret = null;
if (v1Obj != null) {
AtlasStructType structType = (AtlasStructType) type;
if (v1Obj instanceof Map) {
final Map v1Map = (Map) v1Obj;
final Map v1Attribs = (Map) v1Map.get(ATTRIBUTES_PROPERTY_KEY);
if (MapUtils.isNotEmpty(v1Attribs)) {
ret = new AtlasStruct(type.getTypeName(), fromV1ToV2(structType, v1Attribs, converterContext));
} else {
ret = new AtlasStruct(type.getTypeName());
}
} else if (v1Obj instanceof IStruct) {
IStruct struct = (IStruct) v1Obj;
Map<String, Object> v1Attribs = null;
try {
v1Attribs = struct.getValuesMap();
} catch (AtlasException excp) {
LOG.error("IStruct.getValuesMap() failed", excp);
}
ret = new AtlasStruct(type.getTypeName(), fromV1ToV2(structType, v1Attribs, converterContext));
} else {
throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or IStruct", v1Obj.getClass().getCanonicalName());
}
}
return ret;
}
use of org.apache.atlas.typesystem.IStruct in project incubator-atlas by apache.
the class GraphBackedMetadataRepositoryTest method testAddTraitWithAttribute.
@Test(dependsOnMethods = "testAddTrait")
public void testAddTraitWithAttribute() throws Exception {
final String aGUID = getGUID();
final String traitName = "P_I_I";
HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
TraitType traitType = typeSystem.defineTraitType(piiTrait);
ITypedStruct traitInstance = traitType.createInstance();
traitInstance.set("type", "SSN");
repositoryService.addTrait(aGUID, traitInstance);
TestUtils.dumpGraph(TestUtils.getGraph());
// refresh trait names
List<String> traitNames = repositoryService.getTraitNames(aGUID);
Assert.assertEquals(traitNames.size(), 3);
Assert.assertTrue(traitNames.contains(traitName));
ITypedReferenceableInstance instance = repositoryService.getEntityDefinition(aGUID);
IStruct traitInstanceRef = instance.getTrait(traitName);
String type = (String) traitInstanceRef.get("type");
Assert.assertEquals(type, "SSN");
}
Aggregations