88import com .atlan .api .TypeDefsEndpoint ;
99import com .atlan .live .AtlanLiveTest ;
1010import com .atlan .model .enums .AtlanTypeCategory ;
11- import com .atlan .model .typedefs .AttributeDef ;
12- import com .atlan .model .typedefs .EntityDef ;
13- import com .atlan .model .typedefs .RelationshipAttributeDef ;
14- import com .atlan .model .typedefs .TypeDefResponse ;
11+ import com .atlan .model .typedefs .*;
1512import java .io .BufferedReader ;
1613import java .io .File ;
1714import java .io .IOException ;
@@ -35,20 +32,26 @@ public abstract class AbstractGenerator extends AtlanLiveTest {
3532 protected static final String [] CSV_HEADER = {CSV_TYPE_NAME , CSV_TYPE_DESC , CSV_ATTR_NAME , CSV_ATTR_DESC };
3633
3734 private static final String DESCRIPTIONS_FILE =
38- "" + "src" + File .separator + "liveTest " + File .separator + "resources" + File .separator + "attributes.csv" ;
35+ "" + "src" + File .separator + "main " + File .separator + "resources" + File .separator + "attributes.csv" ;
3936
4037 // We'll use our own class names for these types, as the existing type names are either overly
4138 // verbose, too easily conflicting with native Java classes, or have a level of inheritance that is
4239 // unnecessary
43- protected static final Map <String , String > NAME_MAPPINGS = Map .of (
44- "Referenceable" , "Asset" ,
45- "Process" , "LineageProcess" ,
46- "Collection" , "AtlanCollection" ,
47- "Query" , "AtlanQuery" ,
48- "AtlasGlossary" , "Glossary" ,
49- "AtlasGlossaryCategory" , "GlossaryCategory" ,
50- "AtlasGlossaryTerm" , "GlossaryTerm" ,
51- "MaterialisedView" , "MaterializedView" );
40+ protected static final Map <String , String > NAME_MAPPINGS = Map .ofEntries (
41+ Map .entry ("Referenceable" , "Asset" ),
42+ Map .entry ("Process" , "LineageProcess" ),
43+ Map .entry ("Collection" , "AtlanCollection" ),
44+ Map .entry ("Query" , "AtlanQuery" ),
45+ Map .entry ("AtlasGlossary" , "Glossary" ),
46+ Map .entry ("AtlasGlossaryCategory" , "GlossaryCategory" ),
47+ Map .entry ("AtlasGlossaryTerm" , "GlossaryTerm" ),
48+ Map .entry ("MaterialisedView" , "MaterializedView" ),
49+ Map .entry ("certificate_status" , "AtlanCertificateStatus" ),
50+ Map .entry ("AwsTag" , "AWSTag" ),
51+ Map .entry ("AwsCloudWatchMetric" , "AWSCloudWatchMetric" ),
52+ Map .entry ("google_datastudio_asset_type" , "GoogleDataStudioAssetType" ),
53+ Map .entry ("icon_type" , "LinkIconType" ),
54+ Map .entry ("powerbi_endorsement" , "PowerBIEndorsementType" ));
5255
5356 // Map attribute types to native Java types
5457 protected static final Map <String , String > TYPE_MAPPINGS = Map .ofEntries (
@@ -62,10 +65,7 @@ public abstract class AbstractGenerator extends AtlanLiveTest {
6265 Map .entry ("map<string,string>" , "Map<String, String>" ),
6366 Map .entry ("map<string,long>" , "Map<String, Long>" ),
6467 Map .entry ("array<map<string,string>>" , "List<Map<String, String>>" ),
65- Map .entry ("icon_type" , "LinkIconType" ),
66- Map .entry ("google_datastudio_asset_type" , "GoogleDataStudioAssetType" ),
6768 Map .entry ("array<AwsTag>" , "List<AWSTag>" ),
68- Map .entry ("powerbi_endorsement" , "PowerBIEndorsementType" ),
6969 Map .entry ("array<GoogleLabel>" , "List<GoogleLabel>" ),
7070 Map .entry ("array<GoogleTag>" , "List<GoogleTag>" ),
7171 Map .entry ("array<DbtMetricFilter>" , "List<DbtMetricFilter>" ),
@@ -107,7 +107,9 @@ public abstract class AbstractGenerator extends AtlanLiveTest {
107107 protected static final Map <String , String > CREATE_NON_ABSTRACT = Map .ofEntries (
108108 Map .entry ("LineageProcess" , "AbstractProcess" ), Map .entry ("ColumnProcess" , "AbstractColumnProcess" ));
109109
110- protected static final Map <String , EntityDef > typeDefCache = new ConcurrentHashMap <>();
110+ protected static final Map <String , EntityDef > entityDefCache = new ConcurrentHashMap <>();
111+ protected static final Map <String , RelationshipDef > relationshipDefCache = new ConcurrentHashMap <>();
112+ protected static final Map <String , TypeDef > typeDefCache = new ConcurrentHashMap <>();
111113 protected static final Map <String , Set <String >> relationshipsForType = new ConcurrentHashMap <>();
112114 protected static final SortedSet <String > typesWithMaps = new TreeSet <>();
113115 private static final Map <String , String > subTypeToSuperType = new ConcurrentHashMap <>();
@@ -120,16 +122,22 @@ private static void printUsage() {
120122
121123 /** Cache all type definition information we can find from Atlan itself. */
122124 protected static void cacheModels () {
123- if (typeDefCache .isEmpty ()) {
125+ if (entityDefCache .isEmpty ()) {
124126 try {
125127 if (Atlan .getApiToken ().equals ("" ) || Atlan .getBaseUrl ().equals ("" )) {
126128 System .out .println ("Inadequate parameters provided." );
127129 printUsage ();
128130 System .exit (1 );
129131 }
130- TypeDefResponse response = TypeDefsEndpoint .getTypeDefs (AtlanTypeCategory .ENTITY );
131- List <EntityDef > entityDefs = response .getEntityDefs ();
132- cacheTypeDefs (entityDefs );
132+ TypeDefResponse entities = TypeDefsEndpoint .getTypeDefs (AtlanTypeCategory .ENTITY );
133+ TypeDefResponse relationships = TypeDefsEndpoint .getTypeDefs (AtlanTypeCategory .RELATIONSHIP );
134+ TypeDefResponse enums = TypeDefsEndpoint .getTypeDefs (AtlanTypeCategory .ENUM );
135+ TypeDefResponse structs = TypeDefsEndpoint .getTypeDefs (AtlanTypeCategory .STRUCT );
136+ List <EntityDef > entityDefs = entities .getEntityDefs ();
137+ cacheEntityDefs (entityDefs );
138+ cacheRelationshipDefs (relationships .getRelationshipDefs ());
139+ cacheOtherTypeDefs (enums .getEnumDefs ());
140+ cacheOtherTypeDefs (structs .getStructDefs ());
133141 cacheTypesWithMaps (entityDefs );
134142 cacheRelationshipsForInheritance (entityDefs );
135143 } catch (Exception e ) {
@@ -188,14 +196,78 @@ protected static String getTypeDescription(String typeName) {
188196 return typeNameToDescription .getOrDefault (typeName , "TBC" );
189197 }
190198
199+ /**
200+ * Retrieve a list of all attribute definitions that are inherited by this type from all
201+ * of its supertypes (and their supertypes).
202+ *
203+ * @param typeDef type definition from which to retrieve the inherited attributes
204+ * @return a map of the list of inherited attributes, keyed by the name of the type that owns each set of attributes
205+ */
206+ protected static Map <String , List <AttributeDef >> getAllInheritedAttributes (TypeDef typeDef ) {
207+ if (typeDef instanceof EntityDef ) {
208+ EntityDef entityDef = (EntityDef ) typeDef ;
209+ List <String > superTypes = entityDef .getSuperTypes ();
210+ if (superTypes == null || superTypes .isEmpty ()) {
211+ return new LinkedHashMap <>();
212+ } else {
213+ Map <String , List <AttributeDef >> allInherited = new LinkedHashMap <>();
214+ for (String superTypeName : superTypes ) {
215+ EntityDef superTypeDef = entityDefCache .get (superTypeName );
216+ allInherited .putAll (getAllInheritedAttributes (superTypeDef ));
217+ allInherited .put (superTypeName , superTypeDef .getAttributeDefs ());
218+ }
219+ return allInherited ;
220+ }
221+ } else {
222+ return Collections .emptyMap ();
223+ }
224+ }
225+
226+ /**
227+ * Retrieve a list of all relationship attribute definitions that are inherited by this type from all
228+ * of its supertypes (and their supertypes).
229+ *
230+ * @param entityDef entity type definition from which to retrieve the inherited relationship attributes
231+ * @return a map of the list of inherited relationship attributes, keyed by the name of the type that owns each set of relationship attributes
232+ */
233+ protected static Map <String , List <RelationshipAttributeDef >> getAllInheritedRelationshipAttributes (
234+ EntityDef entityDef ) {
235+ List <String > superTypes = entityDef .getSuperTypes ();
236+ if (superTypes == null || superTypes .isEmpty ()) {
237+ return new LinkedHashMap <>();
238+ } else {
239+ Map <String , List <RelationshipAttributeDef >> allInherited = new LinkedHashMap <>();
240+ for (String superTypeName : superTypes ) {
241+ EntityDef superTypeDef = entityDefCache .get (superTypeName );
242+ allInherited .putAll (getAllInheritedRelationshipAttributes (superTypeDef ));
243+ allInherited .put (superTypeName , superTypeDef .getRelationshipAttributeDefs ());
244+ }
245+ return allInherited ;
246+ }
247+ }
248+
191249 private static String getAttrQualifiedName (String typeName , String attrName ) {
192250 return typeName + "|" + attrName ;
193251 }
194252
195- private static void cacheTypeDefs (List <EntityDef > entityDefs ) {
253+ private static void cacheEntityDefs (List <EntityDef > entityDefs ) {
196254 for (EntityDef entityDef : entityDefs ) {
197255 String name = entityDef .getName ();
198- typeDefCache .put (name , entityDef );
256+ entityDefCache .put (name , entityDef );
257+ }
258+ }
259+
260+ private static void cacheRelationshipDefs (List <RelationshipDef > relationshipDefs ) {
261+ for (RelationshipDef relationshipDef : relationshipDefs ) {
262+ String name = relationshipDef .getName ();
263+ relationshipDefCache .put (name , relationshipDef );
264+ }
265+ }
266+
267+ private static <T extends TypeDef > void cacheOtherTypeDefs (List <T > typeDefs ) {
268+ for (TypeDef typeDef : typeDefs ) {
269+ String name = typeDef .getName ();
270+ typeDefCache .put (name , typeDef );
199271 }
200272 }
201273
0 commit comments