use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.
the class VertexLookupContext method findReferencedInstancesToPreLoad.
private void findReferencedInstancesToPreLoad(ITypedReferenceableInstance newInstance) throws AtlasException {
//pre-load vertices for reference fields
for (AttributeInfo info : newInstance.fieldMapping().fields.values()) {
if (info.dataType().getTypeCategory() == TypeCategory.CLASS) {
ITypedReferenceableInstance newAttributeValue = (ITypedReferenceableInstance) newInstance.get(info.name);
addAdditionalInstance(newAttributeValue);
}
if (info.dataType().getTypeCategory() == TypeCategory.ARRAY) {
IDataType elementType = ((DataTypes.ArrayType) info.dataType()).getElemType();
if (elementType.getTypeCategory() == TypeCategory.CLASS) {
List<ITypedReferenceableInstance> newElements = (List) newInstance.get(info.name);
addAdditionalInstances(newElements);
}
}
if (info.dataType().getTypeCategory() == TypeCategory.MAP) {
IDataType elementType = ((DataTypes.MapType) info.dataType()).getValueType();
if (elementType.getTypeCategory() == TypeCategory.CLASS) {
Map<Object, ITypedReferenceableInstance> newAttribute = (Map<Object, ITypedReferenceableInstance>) newInstance.get(info.name);
if (newAttribute != null) {
addAdditionalInstances(newAttribute.values());
}
}
}
}
}
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 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;
}
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);
}
}
}
}
}
Aggregations