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);
}
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);
}
}
}
}
}
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);
}
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);
}
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;
}
Aggregations