Search in sources :

Example 31 with Struct

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;
}
Also used : ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) AtlasType(org.apache.atlas.type.AtlasType) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 32 with Struct

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;
}
Also used : AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) HashMap(java.util.HashMap) Map(java.util.Map) AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 33 with Struct

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));
}
Also used : EntityNotificationV1(org.apache.atlas.v1.model.notification.EntityNotificationV1) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) EntityNotification(org.apache.atlas.model.notification.EntityNotification) ArrayList(java.util.ArrayList) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Example 34 with Struct

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());
}
Also used : EntityNotificationV1(org.apache.atlas.v1.model.notification.EntityNotificationV1) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Test(org.testng.annotations.Test)

Example 35 with Struct

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);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) Struct(org.apache.atlas.v1.model.instance.Struct)

Aggregations

Struct (org.apache.atlas.v1.model.instance.Struct)36 Referenceable (org.apache.atlas.v1.model.instance.Referenceable)22 Test (org.testng.annotations.Test)17 HashMap (java.util.HashMap)9 Map (java.util.Map)9 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)9 EntityNotificationV1 (org.apache.atlas.v1.model.notification.EntityNotificationV1)7 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)6 Id (org.apache.atlas.v1.model.instance.Id)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)5 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)3 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 AtlasException (org.apache.atlas.AtlasException)2 AtlasServiceException (org.apache.atlas.AtlasServiceException)2 EntityAuditEvent (org.apache.atlas.EntityAuditEvent)2 EntityChangeListener (org.apache.atlas.listener.EntityChangeListener)2 EntityChangeListenerV2 (org.apache.atlas.listener.EntityChangeListenerV2)2