Search in sources :

Example 56 with ITypedReferenceableInstance

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());
                }
            }
        }
    }
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList) List(java.util.List) IDataType(org.apache.atlas.typesystem.types.IDataType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 57 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 58 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)

Example 59 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 60 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)

Aggregations

ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)142 Test (org.testng.annotations.Test)54 List (java.util.List)34 ArrayList (java.util.ArrayList)29 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 AtlasException (org.apache.atlas.AtlasException)16 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)16 HashMap (java.util.HashMap)15 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