Search in sources :

Example 11 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class EntityAuditListener method onEntitiesUpdated.

@Override
public void onEntitiesUpdated(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException {
    List<EntityAuditEvent> events = new ArrayList<>();
    for (ITypedReferenceableInstance entity : entities) {
        EntityAuditEvent event = createEvent(entity, isImport ? EntityAuditAction.ENTITY_IMPORT_UPDATE : EntityAuditAction.ENTITY_UPDATE);
        events.add(event);
    }
    auditRepository.putEvents(events);
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList)

Example 12 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class EntityAuditListener method restoreEntityAttributes.

private void restoreEntityAttributes(ITypedReferenceableInstance entity, Map<String, Object> prunedAttributes) throws AtlasException {
    if (MapUtils.isEmpty(prunedAttributes)) {
        return;
    }
    Map<String, Object> entityAttributes = entity.getValuesMap();
    if (MapUtils.isNotEmpty(entityAttributes)) {
        Map<String, AttributeInfo> attributeInfoMap = entity.fieldMapping().fields;
        for (String attrName : entityAttributes.keySet()) {
            Object attrValue = entityAttributes.get(attrName);
            AttributeInfo attrInfo = attributeInfoMap.get(attrName);
            if (prunedAttributes.containsKey(attrName)) {
                entity.set(attrName, prunedAttributes.get(attrName));
            } else if (attrInfo.isComposite) {
                if (attrValue instanceof Collection) {
                    for (Object attributeEntity : (Collection) attrValue) {
                        if (attributeEntity instanceof ITypedReferenceableInstance) {
                            restoreAttributes(prunedAttributes, (ITypedReferenceableInstance) attributeEntity);
                        }
                    }
                } else if (attrValue instanceof ITypedReferenceableInstance) {
                    restoreAttributes(prunedAttributes, (ITypedReferenceableInstance) attrValue);
                }
            }
        }
    }
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Collection(java.util.Collection)

Example 13 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class EntityAuditListener method onEntitiesAdded.

@Override
public void onEntitiesAdded(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException {
    List<EntityAuditEvent> events = new ArrayList<>();
    for (ITypedReferenceableInstance entity : entities) {
        EntityAuditEvent event = createEvent(entity, isImport ? EntityAuditAction.ENTITY_IMPORT_CREATE : EntityAuditAction.ENTITY_CREATE);
        events.add(event);
    }
    auditRepository.putEvents(events);
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList)

Example 14 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class EntityAuditListener method onEntitiesDeleted.

@Override
public void onEntitiesDeleted(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException {
    List<EntityAuditEvent> events = new ArrayList<>();
    for (ITypedReferenceableInstance entity : entities) {
        EntityAuditEvent event = createEvent(entity, isImport ? EntityAuditAction.ENTITY_IMPORT_DELETE : EntityAuditAction.ENTITY_DELETE, "Deleted entity");
        events.add(event);
    }
    auditRepository.putEvents(events);
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList)

Example 15 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class EntityAuditListener method pruneEntityAttributesForAudit.

private Map<String, Object> pruneEntityAttributesForAudit(ITypedReferenceableInstance entity) throws AtlasException {
    Map<String, Object> ret = null;
    Map<String, Object> entityAttributes = entity.getValuesMap();
    List<String> excludeAttributes = auditRepository.getAuditExcludeAttributes(entity.getTypeName());
    if (CollectionUtils.isNotEmpty(excludeAttributes) && MapUtils.isNotEmpty(entityAttributes)) {
        Map<String, AttributeInfo> attributeInfoMap = entity.fieldMapping().fields;
        for (String attrName : entityAttributes.keySet()) {
            Object attrValue = entityAttributes.get(attrName);
            AttributeInfo attrInfo = attributeInfoMap.get(attrName);
            if (excludeAttributes.contains(attrName)) {
                if (ret == null) {
                    ret = new HashMap<>();
                }
                ret.put(attrName, attrValue);
                entity.setNull(attrName);
            } else if (attrInfo.isComposite) {
                if (attrValue instanceof Collection) {
                    for (Object attribute : (Collection) attrValue) {
                        if (attribute instanceof ITypedReferenceableInstance) {
                            ret = pruneAttributes(ret, (ITypedReferenceableInstance) attribute);
                        }
                    }
                } else if (attrValue instanceof ITypedReferenceableInstance) {
                    ret = pruneAttributes(ret, (ITypedReferenceableInstance) attrValue);
                }
            }
        }
    }
    return ret;
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Collection(java.util.Collection)

Aggregations

ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)142 Test (org.testng.annotations.Test)54 List (java.util.List)34 ArrayList (java.util.ArrayList)30 Id (org.apache.atlas.typesystem.persistence.Id)28 Referenceable (org.apache.atlas.typesystem.Referenceable)22 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)21 ImmutableList (com.google.common.collect.ImmutableList)20 ClassType (org.apache.atlas.typesystem.types.ClassType)19 HashMap (java.util.HashMap)16 AtlasException (org.apache.atlas.AtlasException)16 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)16 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)14 EntityResult (org.apache.atlas.model.legacy.EntityResult)12 IStruct (org.apache.atlas.typesystem.IStruct)10 Map (java.util.Map)9 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)9 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)9 RepositoryException (org.apache.atlas.repository.RepositoryException)9 BeforeTest (org.testng.annotations.BeforeTest)9