Search in sources :

Example 1 with Struct

use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.

the class AtlasEntityChangeNotifier method onClassificationAddedToEntity.

public void onClassificationAddedToEntity(AtlasEntity entity, List<AtlasClassification> addedClassifications) throws AtlasBaseException {
    if (isV2EntityNotificationEnabled()) {
        doFullTextMapping(entity.getGuid());
        for (EntityChangeListenerV2 listener : entityChangeListenersV2) {
            listener.onClassificationsAdded(entity, addedClassifications);
        }
    } else {
        updateFullTextMapping(entity.getGuid(), addedClassifications);
        Referenceable entityRef = toReferenceable(entity.getGuid());
        List<Struct> traits = toStruct(addedClassifications);
        if (entity == null || CollectionUtils.isEmpty(traits)) {
            return;
        }
        for (EntityChangeListener listener : entityChangeListeners) {
            try {
                listener.onTraitsAdded(entityRef, traits);
            } catch (AtlasException e) {
                throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitAdd");
            }
        }
    }
}
Also used : EntityChangeListener(org.apache.atlas.listener.EntityChangeListener) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) EntityChangeListenerV2(org.apache.atlas.listener.EntityChangeListenerV2) AtlasException(org.apache.atlas.AtlasException) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 2 with Struct

use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.

the class AtlasEntityChangeNotifier method onClassificationUpdatedToEntity.

public void onClassificationUpdatedToEntity(AtlasEntity entity, List<AtlasClassification> updatedClassifications) throws AtlasBaseException {
    if (isV2EntityNotificationEnabled()) {
        doFullTextMapping(entity.getGuid());
        for (EntityChangeListenerV2 listener : entityChangeListenersV2) {
            listener.onClassificationsUpdated(entity, updatedClassifications);
        }
    } else {
        doFullTextMapping(entity.getGuid());
        Referenceable entityRef = toReferenceable(entity.getGuid());
        List<Struct> traits = toStruct(updatedClassifications);
        if (entityRef == null || CollectionUtils.isEmpty(traits)) {
            return;
        }
        for (EntityChangeListener listener : entityChangeListeners) {
            try {
                listener.onTraitsUpdated(entityRef, traits);
            } catch (AtlasException e) {
                throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitUpdate");
            }
        }
    }
}
Also used : EntityChangeListener(org.apache.atlas.listener.EntityChangeListener) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) EntityChangeListenerV2(org.apache.atlas.listener.EntityChangeListenerV2) AtlasException(org.apache.atlas.AtlasException) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 3 with Struct

use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.

the class AtlasStructFormatConverter method fromV2ToV1.

@Override
public Object fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext converterContext) throws AtlasBaseException {
    Struct ret = null;
    if (v2Obj != null) {
        AtlasStructType structType = (AtlasStructType) type;
        if (v2Obj instanceof Map) {
            final Map v2Map = (Map) v2Obj;
            final Map v2Attribs;
            if (v2Map.containsKey(ATTRIBUTES_PROPERTY_KEY)) {
                v2Attribs = (Map) v2Map.get(ATTRIBUTES_PROPERTY_KEY);
            } else {
                v2Attribs = v2Map;
            }
            if (MapUtils.isNotEmpty(v2Attribs)) {
                ret = new Struct(type.getTypeName(), fromV2ToV1(structType, v2Attribs, converterContext));
            } else {
                ret = new Struct(type.getTypeName());
            }
        } else if (v2Obj instanceof AtlasStruct) {
            AtlasStruct struct = (AtlasStruct) v2Obj;
            ret = new Struct(type.getTypeName(), fromV2ToV1(structType, struct.getAttributes(), converterContext));
        } else {
            throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or AtlasStruct", v2Obj.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 4 with Struct

use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.

the class EntityAuditListener method onTraitsUpdated.

@Override
public void onTraitsUpdated(Referenceable entity, Collection<? extends Struct> traits) throws AtlasException {
    if (traits != null) {
        for (Struct trait : traits) {
            EntityAuditEvent event = createEvent(entity, EntityAuditAction.TAG_UPDATE, "Updated trait: " + AtlasType.toV1Json(trait));
            auditRepository.putEventsV1(event);
        }
    }
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) Struct(org.apache.atlas.v1.model.instance.Struct)

Example 5 with Struct

use of org.apache.atlas.v1.model.instance.Struct in project atlas by apache.

the class EntityAuditListener method onTraitsAdded.

@Override
public void onTraitsAdded(Referenceable entity, Collection<? extends Struct> traits) throws AtlasException {
    if (traits != null) {
        for (Struct trait : traits) {
            EntityAuditEvent event = createEvent(entity, EntityAuditAction.TAG_ADD, "Added trait: " + AtlasType.toV1Json(trait));
            auditRepository.putEventsV1(event);
        }
    }
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) 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