use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.
the class AtlasInstanceConverter method getTrait.
public Struct getTrait(AtlasClassification classification) throws AtlasBaseException {
AtlasFormatConverter converter = instanceFormatters.getConverter(TypeCategory.CLASSIFICATION);
AtlasType classificationType = typeRegistry.getType(classification.getTypeName());
Struct trait = (Struct) converter.fromV2ToV1(classification, classificationType, new ConverterContext());
return trait;
}
use of org.apache.atlas.v1.model.instance.Struct in project 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 Struct) {
Struct struct = (Struct) v1Obj;
ret = new AtlasStruct(type.getTypeName(), fromV1ToV2(structType, struct.getValues(), converterContext));
} else {
throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or Struct", v1Obj.getClass().getCanonicalName());
}
}
return ret;
}
use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.
the class EntityNotificationDeserializerTest method testDeserialize.
@Test
public void testDeserialize() throws Exception {
Referenceable entity = EntityNotificationTest.getEntity("id");
String traitName = "MyTrait";
List<Struct> traits = Collections.singletonList(new Struct(traitName, Collections.<String, Object>emptyMap()));
EntityNotificationV1 notification = new EntityNotificationV1(entity, EntityNotificationV1.OperationType.TRAIT_ADD, traits);
List<String> jsonMsgList = new ArrayList<>();
AbstractNotification.createNotificationMessages(notification, jsonMsgList);
EntityNotification deserializedNotification = null;
for (String jsonMsg : jsonMsgList) {
deserializedNotification = deserializer.deserialize(jsonMsg);
if (deserializedNotification != null) {
break;
}
}
assertTrue(deserializedNotification instanceof EntityNotificationV1);
EntityNotificationV1 entityNotificationV1 = (EntityNotificationV1) deserializedNotification;
assertEquals(entityNotificationV1.getOperationType(), notification.getOperationType());
assertEquals(entityNotificationV1.getEntity().getId(), notification.getEntity().getId());
assertEquals(entityNotificationV1.getEntity().getTypeName(), notification.getEntity().getTypeName());
assertEquals(entityNotificationV1.getEntity().getTraits(), notification.getEntity().getTraits());
assertEquals(entityNotificationV1.getEntity().getTrait(traitName), notification.getEntity().getTrait(traitName));
}
use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.
the class EntityNotificationTest method testGetEntity.
@Test
public void testGetEntity() throws Exception {
Referenceable entity = getEntity("id");
EntityNotificationV1 entityNotification = new EntityNotificationV1(entity, OperationType.ENTITY_CREATE, Collections.<Struct>emptyList());
assertEquals(entity, entityNotification.getEntity());
}
use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.
the class EntityNotificationTest method getEntity.
public static Referenceable getEntity(String id, Struct... traits) {
String typeName = "typeName";
List<String> traitNames = new LinkedList<>();
Map<String, Struct> traitMap = new HashMap<>();
for (Struct trait : traits) {
String traitName = trait.getTypeName();
traitNames.add(traitName);
traitMap.put(traitName, trait);
}
return new Referenceable(id, typeName, new HashMap<String, Object>(), traitNames, traitMap);
}
Aggregations