Java Code Examples for org.apache.atlas.v1.model.instance.Referenceable#getValuesMap()
The following examples show how to use
org.apache.atlas.v1.model.instance.Referenceable#getValuesMap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotificationEntityChangeListener.java From atlas with Apache License 2.0 | 5 votes |
private void notifyOfEntityEvent(Collection<Referenceable> entityDefinitions, OperationType operationType) throws AtlasException { MetricRecorder metric = RequestContext.get().startMetricRecord("entityNotification"); List<EntityNotificationV1> messages = new ArrayList<>(); for (Referenceable entityDefinition : entityDefinitions) { if(GraphHelper.isInternalType(entityDefinition.getTypeName())) { continue; } Referenceable entity = new Referenceable(entityDefinition); Map<String, Object> attributesMap = entity.getValuesMap(); List<String> entityNotificationAttrs = getNotificationAttributes(entity.getTypeName()); if (MapUtils.isNotEmpty(attributesMap) && CollectionUtils.isNotEmpty(entityNotificationAttrs)) { Collection<String> attributesToRemove = CollectionUtils.subtract(attributesMap.keySet(), entityNotificationAttrs); for (String attributeToRemove : attributesToRemove) { attributesMap.remove(attributeToRemove); } } EntityNotificationV1 notification = new EntityNotificationV1(entity, operationType, getAllTraits(entity, typeRegistry)); messages.add(notification); } if (!messages.isEmpty()) { notificationSender.send(messages); } RequestContext.get().endMetricRecord(metric); }
Example 2
Source File: EntityJerseyResourceIT.java From atlas with Apache License 2.0 | 5 votes |
private Referenceable getReferenceable(List<Referenceable> refs, String name) { Referenceable ret = null; for (Referenceable ref : refs) { Map<String, Object> values = ref.getValuesMap(); String entityName = (String) values.get("name"); if (StringUtils.equalsIgnoreCase(name, entityName)) { ret = ref; break; } } return ret; }
Example 3
Source File: EntityAuditListener.java From atlas with Apache License 2.0 | 5 votes |
private String getAuditEventDetail(Referenceable entity, EntityAuditAction action) throws AtlasException { Map<String, Object> prunedAttributes = pruneEntityAttributesForAudit(entity); String auditPrefix = getV1AuditPrefix(action); String auditString = auditPrefix + AtlasType.toV1Json(entity); byte[] auditBytes = auditString.getBytes(StandardCharsets.UTF_8); long auditSize = auditBytes != null ? auditBytes.length : 0; long auditMaxSize = auditRepository.repositoryMaxSize(); if (auditMaxSize >= 0 && auditSize > auditMaxSize) { // don't store attributes in audit LOG.warn("audit record too long: entityType={}, guid={}, size={}; maxSize={}. entity attribute values not stored in audit", entity.getTypeName(), entity.getId()._getId(), auditSize, auditMaxSize); Map<String, Object> attrValues = entity.getValuesMap(); entity.setValues(null); auditString = auditPrefix + AtlasType.toV1Json(entity); auditBytes = auditString.getBytes(StandardCharsets.UTF_8); // recheck auditString size auditSize = auditBytes != null ? auditBytes.length : 0; if (auditMaxSize >= 0 && auditSize > auditMaxSize) { // don't store classifications as well LOG.warn("audit record still too long: entityType={}, guid={}, size={}; maxSize={}. audit will have only summary details", entity.getTypeName(), entity.getId()._getId(), auditSize, auditMaxSize); Referenceable shallowEntity = new Referenceable(entity.getId(), entity.getTypeName(), null, entity.getSystemAttributes(), null, null); auditString = auditPrefix + AtlasType.toJson(shallowEntity); } entity.setValues(attrValues); } restoreEntityAttributes(entity, prunedAttributes); return auditString; }
Example 4
Source File: EntityAuditListener.java From atlas with Apache License 2.0 | 5 votes |
private Map<String, Object> pruneEntityAttributesForAudit(Referenceable entity) throws AtlasException { Map<String, Object> ret = null; Map<String, Object> entityAttributes = entity.getValuesMap(); List<String> excludeAttributes = auditRepository.getAuditExcludeAttributes(entity.getTypeName()); AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName()); if (CollectionUtils.isNotEmpty(excludeAttributes) && MapUtils.isNotEmpty(entityAttributes) && entityType != null) { for (AtlasStructType.AtlasAttribute attribute : entityType.getAllAttributes().values()) { String attrName = attribute.getName(); Object attrValue = entityAttributes.get(attrName); if (excludeAttributes.contains(attrName)) { if (ret == null) { ret = new HashMap<>(); } ret.put(attrName, attrValue); entityAttributes.remove(attrName); } else if (attribute.isOwnedRef()) { if (attrValue instanceof Collection) { for (Object arrElem : (Collection) attrValue) { if (arrElem instanceof Referenceable) { ret = pruneAttributes(ret, (Referenceable) arrElem); } } } else if (attrValue instanceof Referenceable) { ret = pruneAttributes(ret, (Referenceable) attrValue); } } } } return ret; }
Example 5
Source File: EntityAuditListener.java From atlas with Apache License 2.0 | 5 votes |
private void restoreEntityAttributes(Referenceable entity, Map<String, Object> prunedAttributes) throws AtlasException { if (MapUtils.isEmpty(prunedAttributes)) { return; } AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName()); if (entityType != null && MapUtils.isNotEmpty(entityType.getAllAttributes())) { Map<String, Object> entityAttributes = entity.getValuesMap(); for (AtlasStructType.AtlasAttribute attribute : entityType.getAllAttributes().values()) { String attrName = attribute.getName(); Object attrValue = entityAttributes.get(attrName); if (prunedAttributes.containsKey(attrName)) { entity.set(attrName, prunedAttributes.get(attrName)); } else if (attribute.isOwnedRef()) { if (attrValue instanceof Collection) { for (Object arrElem : (Collection) attrValue) { if (arrElem instanceof Referenceable) { restoreAttributes(prunedAttributes, (Referenceable) arrElem); } } } else if (attrValue instanceof Referenceable) { restoreAttributes(prunedAttributes, (Referenceable) attrValue); } } } } }