Skip to main content

Creating asset

All objects in the SDK that you can create within Atlan implement the builder pattern. This allows you to progressively build-up the object you want to create. In addition, each object provides a method that takes the minimal set of required fields to create that asset.

Each type of asset has a different containment hierarchy

Every asset in Atlan can have slightly different parent objects in which they exist. For example, a GlossaryTerm can't exist outside a Glossary. A Column can't exist outside a Table, View or MaterializedView; these can't exist outside a Schema; which can't exist outside a Database; which can't exist outside a Connection.

The minimal required fields for each asset type will therefore be slightly different.

Creation order is important

As a result of this containment, creation order is important. Parent objects must be created (exist) before child objects can be created.

:::

Build minimal object needed

For example, to create a glossary term you need to provide the name of the term and either the GUID or qualifiedName of the glossary in which to create the term:

Build minimal asset necessary for creation
GlossaryTermBuilder<?,?> termCreator = GlossaryTerm
.creator("Example Term", // (1)
"b4113341-251b-4adc-81fb-2420501c30e6"); // (2)
  1. A name for the new term.
  2. The GUID or qualifiedName of the glossary in which to create the term.

Create asset from object

This term object will have the minimal required information for Atlan to create it. You must then actually persist the object in Atlan1:

Create the asset
GlossaryTerm term = termCreator.build(); // (1)
AssetMutationResponse response = term.save(client); // (2)
Asset created = response.getCreatedAssets().get(0); // (3)
if (created instanceof GlossaryTerm)
Asset updated = response.getUpdatedAssets().get(0); // (5)
Glossary glossary;
if (updated instanceof Glossary)
  1. Before you can take actions on the builder object you've been interacting with, you need to build() it into a full object.

  2. Then you can do operations, like save(), which will either:

    • create a new asset, if Atlan doesn't have a term with the same name in the same glossary
    • update an existing asset, if Atlan already has a term with the same name in the same glossary

    Because this operation will persist the asset in Atlan, you must provide it an AtlanClient through which to connect to the tenant.

  3. You can distinguish what was created or updated:

    • getCreatedAssets() lists assets that were created
    • getUpdatedAssets() lists assets that were updated

    Note that the save() method always returns objects of type Asset, though.

  4. The Asset class is a superclass of all assets. So you need to cast to more specific types (like GlossaryTerm) after verifying the object that was actually returned.

  5. In this example, creating the GlossaryTerm actually also updates the parent Glossary. This is why the response contains generic Asset objects rather than specific types—any operation could side-effect a number of different assets.

  6. Like with the GlossaryTerm, you can check and cast the generic Asset returned by the response into its more specific type (Glossary).

(Optional) Enrich before creating

If you want to further enrich the asset before creating it, you can do this using the builder pattern:

Alternatively, further enrich the asset before creating it
GlossaryTerm term = termCreator // (1)
.certificateStatus(CertificateStatus.VERIFIED) // (2)
.announcementType(AtlanAnnouncementType.INFORMATION)
.announcementTitle("Imported")
.announcementMessage("This term was imported from ...")
.build(); // (3)
AssetMutationResponse response = term.save(client); // (4)
  1. We'll create an object you can take actions on from this creator.
  2. In this example, you're adding a certificate and announcement to the object.
  3. To persist the enrichment back to the object, you must build() the builder.
  4. You can call the save() operation against this enriched object, the same as shown earlier. Because this operation will persist the asset in Atlan, you must provide it an AtlanClient through which to connect to the tenant.
Assign the result back

Remember to assign the result of the build() operation back to a variable! (In the example above this happens on line 5 with GlossaryTerm term =.)

Footnotes

  1. Why no distinction between creation and update? This has to do with how Atlan detects changes—see the Importance of identifiers for a more detailed explanation.

Was this page helpful?