Package com.atlan.events
Interface AtlanEventHandler
public interface AtlanEventHandler
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptioncalculateChanges
(Asset currentView, org.slf4j.Logger log) Calculate any changes to apply to assets, and return a collection of the minimally-updated form of the assets with those changes applied (in-memory).static AtlanEvent
getAtlanEvent
(AtlanClient client, byte[] data) Translate the JSON payload into an Atlan event object.static AtlanEvent
getAtlanEvent
(AtlanClient client, String data) Translate the JSON payload into an Atlan event object.static Asset
getCurrentFullAsset
(AtlanClient client, AtlanEvent event) Retrieve the full asset from Atlan, to ensure we have the latest information about it.default Asset
getCurrentState
(AtlanClient client, Asset fromEvent, org.slf4j.Logger log) Retrieve the current state of the asset, with minimal required info to handle any logic the event handler requires to make its decisions.static Asset
getCurrentViewOfAsset
(AtlanClient client, Asset fromEvent, Collection<String> limitedToAttributes, boolean includeMeanings, boolean includeAtlanTags) Retrieve a limited set of information about the asset in Atlan, as up-to-date as is available in the search index, to ensure we have reasonably up-to-date information about it.static Asset
getCurrentViewOfAsset
(AtlanClient client, AtlanEvent event, Collection<String> limitedToAttributes, boolean includeMeanings, boolean includeAtlanTags) Retrieve a limited set of information about the asset in Atlan, as up-to-date as is available in the search index, to ensure we have reasonably up-to-date information about it.static boolean
hasAssignedTerms
(Asset asset) Check if the asset has any assigned terms.static boolean
hasAtlanTags
(Asset asset) Check if the asset has any Atlan tags.default boolean
hasChanges
(Asset current, Asset modified, org.slf4j.Logger log) Check the key information this event processing is meant to handle between the original asset and the in-memory-modified asset.static boolean
hasDescription
(Asset asset) Check if the asset has either a user-provided or system-provided description.static boolean
hasLineage
(Asset asset) Check if the asset has any lineage.static boolean
Check if the asset has any individual or group owners.static boolean
Check if the asset has a README assigned (with content).static boolean
isValidationRequest
(String data) default void
saveChanges
(AtlanClient client, Collection<Asset> changedAssets, org.slf4j.Logger log) Actually send the changed assets to Atlan so that they are persisted.default boolean
validatePrerequisites
(AtlanEvent event, org.slf4j.Logger log) Validate the prerequisites expected by the event handler.static boolean
validSignature
(String expectedSignature, Map<String, String> headers) Validate the signing secret provided with a request matches the expected signing secret.
-
Field Details
-
WEBHOOK_VALIDATION_REQUEST
- See Also:
-
-
Method Details
-
validatePrerequisites
Validate the prerequisites expected by the event handler. These should generally run before trying to do any other actions. This default implementation will only confirm that an event has been received and there are details of an asset embedded within the event.- Parameters:
event
- the event to be processedlog
- a logger to log anything you want- Returns:
- true if the prerequisites are met, otherwise false
- Throws:
AtlanException
- optionally throw any errors on unexpected problems
-
getCurrentState
default Asset getCurrentState(AtlanClient client, Asset fromEvent, org.slf4j.Logger log) throws AtlanException Retrieve the current state of the asset, with minimal required info to handle any logic the event handler requires to make its decisions. This default implementation will only really check that the asset still exists in Atlan.- Parameters:
client
- connectivity to AtlanfromEvent
- the asset from the event (which could be stale at this point)log
- a logger to log anything you want- Returns:
- the current state of the asset, as retrieved from Atlan
- Throws:
AtlanException
- if there are any problems retrieving the current state of the asset from Atlan
-
calculateChanges
Calculate any changes to apply to assets, and return a collection of the minimally-updated form of the assets with those changes applied (in-memory). Typically, you will want to callAsset.trimToRequired()
on the currentView of each asset before making any changes, to ensure a minimal set of changes are applied to the asset (minimizing the risk of accidentally clobbering any other changes someone may make to the asset between this in-memory set of changes and the subsequent application of those changes to Atlan itself). Also, you should call yourhasChanges(Asset, Asset, Logger)
method for each asset to determine whether it actually has any changes to include before returning it from this method. NOTE: The returned assets from this method should be ONLY those assets on which updates are actually being applied, or you will risk an infinite loop of events triggering changes, more events, more changes, etc.- Parameters:
currentView
- the current view / state of the asset in Atlan, as the starting point for any changeslog
- a logger to log anything you want- Returns:
- a collection of only those assets that have changes to send to Atlan (empty, if there are no changes to send)
- Throws:
AtlanException
- if there are any problems calculating or applying changes (in-memory) to the asset
-
hasChanges
Check the key information this event processing is meant to handle between the original asset and the in-memory-modified asset. Only return true if there is actually a change to be applied to this asset in Atlan - this ensures idempotency, and avoids an infinite loop of making changes repeatedly in Atlan, which triggers a new event, a new change, a new event, and so on. This default implementation only blindly checks for equality. It is likely you would want to check specific attributes' values, rather than the entire object, for equality when determining whether a relevant change has been made (or not) to the asset.- Parameters:
current
- the current view / state of the asset in Atlan, that was the starting point for any change calculationsmodified
- the in-memory-modified asset against which to check if any changes actually need to be sent to Atlanlog
- a logger to log anything you want- Returns:
- true if the modified asset should be sent on to (updated in) Atlan, or false if there are no actual changes to apply
-
saveChanges
default void saveChanges(AtlanClient client, Collection<Asset> changedAssets, org.slf4j.Logger log) throws AtlanException Actually send the changed assets to Atlan so that they are persisted.- Parameters:
client
- connectivity to AtlanchangedAssets
- the in-memory-modified assets to send to Atlanlog
- a logger to log anything you want- Throws:
AtlanException
- if there are any problems actually updating the asset in Atlan
-
isValidationRequest
-
validSignature
Validate the signing secret provided with a request matches the expected signing secret.- Parameters:
expectedSignature
- signature that must be found for a valid requestheaders
- that were sent with the request- Returns:
- true if and only if the headers contain a signing secret that matches the expected signature
-
getAtlanEvent
Translate the JSON payload into an Atlan event object.- Parameters:
client
- connectivity to Atlandata
- the JSON payload- Returns:
- an Atlan event object representation of the payload
- Throws:
IOException
- on any problems deserializing the event details
-
getAtlanEvent
Translate the JSON payload into an Atlan event object.- Parameters:
client
- connectivity to Atlandata
- the JSON payload- Returns:
- an Atlan event object representation of the payload
- Throws:
IOException
- on any problems deserializing the event details
-
getCurrentFullAsset
Retrieve the full asset from Atlan, to ensure we have the latest information about it. Note: this will be slower than getCurrentViewOfAsset, but does not rely on the eventual consistency of the search index so will have the absolute latest information about an asset.- Parameters:
client
- connectivity to Atlanevent
- containing details about an asset- Returns:
- the current information about the asset in Atlan, in its entirety
- Throws:
AtlanException
- on any issues communicating with the API
-
getCurrentViewOfAsset
static Asset getCurrentViewOfAsset(AtlanClient client, AtlanEvent event, Collection<String> limitedToAttributes, boolean includeMeanings, boolean includeAtlanTags) throws AtlanException Retrieve a limited set of information about the asset in Atlan, as up-to-date as is available in the search index, to ensure we have reasonably up-to-date information about it. Note: this will be faster than getCurrentFullAsset, but relies on the eventual consistency of the search index so may not have the absolute latest information about an asset.- Parameters:
client
- connectivity to Atlanevent
- containing details about an assetlimitedToAttributes
- the limited set of attributes to retrieve about the assetincludeMeanings
- if true, include any assigned termsincludeAtlanTags
- if true, include any assigned Atlan tags- Returns:
- the current information about the asset in Atlan, limited to what was requested
- Throws:
AtlanException
- on any issues communicating with the API
-
getCurrentViewOfAsset
static Asset getCurrentViewOfAsset(AtlanClient client, Asset fromEvent, Collection<String> limitedToAttributes, boolean includeMeanings, boolean includeAtlanTags) throws AtlanException Retrieve a limited set of information about the asset in Atlan, as up-to-date as is available in the search index, to ensure we have reasonably up-to-date information about it. Note: this will be faster than getCurrentFullAsset, but relies on the eventual consistency of the search index so may not have the absolute latest information about an asset.- Parameters:
client
- connectivity to AtlanfromEvent
- details of the asset in the eventlimitedToAttributes
- the limited set of attributes to retrieve about the assetincludeMeanings
- if true, include any assigned termsincludeAtlanTags
- if true, include any assigned Atlan tags- Returns:
- the current information about the asset in Atlan, limited to what was requested
- Throws:
AtlanException
- on any issues communicating with the API
-
hasDescription
Check if the asset has either a user-provided or system-provided description.- Parameters:
asset
- to check for the presence of a description- Returns:
- true if there is either a user-provided or system-provided description
-
hasOwner
Check if the asset has any individual or group owners.- Parameters:
asset
- to check for the presence of an owner- Returns:
- true if there is at least one individual or group owner
-
hasAssignedTerms
Check if the asset has any assigned terms.- Parameters:
asset
- to check for the presence of an assigned term- Returns:
- true if there is at least one assigned term
-
hasAtlanTags
Check if the asset has any Atlan tags.- Parameters:
asset
- to check for the presence of an Atlan tag- Returns:
- true if there is at least one assigned Atlan tag
-
hasLineage
Check if the asset has any lineage.- Parameters:
asset
- to check for the presence of lineage- Returns:
- true if the asset is input to or output from at least one process
-
hasReadme
Check if the asset has a README assigned (with content).- Parameters:
asset
- to check for the presence of a README- Returns:
- true if the asset has a README, and the README is not empty
-