22/* Copyright Contributors to the ODPi Egeria project. */
33package org .odpi .openmetadata .commonservices .generichandlers ;
44
5- import org .odpi .openmetadata .commonservices .generichandlers .OMFConverter ;
5+ import org .odpi .openmetadata .commonservices .mermaid .GlossaryMermaidGraphBuilder ;
6+ import org .odpi .openmetadata .frameworks .openmetadata .ffdc .PropertyServerException ;
7+ import org .odpi .openmetadata .frameworks .openmetadata .metadataelements .ChildCategoryElement ;
68import org .odpi .openmetadata .frameworks .openmetadata .metadataelements .GlossaryElement ;
9+ import org .odpi .openmetadata .frameworks .openmetadata .metadataelements .RelatedMetadataElementSummary ;
710import org .odpi .openmetadata .frameworks .openmetadata .properties .glossaries .GlossaryProperties ;
8- import org .odpi .openmetadata .frameworks .openmetadata .ffdc .PropertyServerException ;
9- import org .odpi .openmetadata .repositoryservices .connectors .stores .metadatacollectionstore .properties .instances .*;
11+ import org .odpi .openmetadata .frameworks .openmetadata .types .OpenMetadataType ;
12+ import org .odpi .openmetadata .repositoryservices .connectors .stores .metadatacollectionstore .properties .instances .EntityDetail ;
13+ import org .odpi .openmetadata .repositoryservices .connectors .stores .metadatacollectionstore .properties .instances .InstanceProperties ;
14+ import org .odpi .openmetadata .repositoryservices .connectors .stores .metadatacollectionstore .properties .instances .Relationship ;
1015import org .odpi .openmetadata .repositoryservices .connectors .stores .metadatacollectionstore .properties .typedefs .TypeDefCategory ;
1116import org .odpi .openmetadata .repositoryservices .connectors .stores .metadatacollectionstore .repositoryconnector .OMRSRepositoryHelper ;
1217
1318import java .lang .reflect .InvocationTargetException ;
19+ import java .util .ArrayList ;
20+ import java .util .HashMap ;
21+ import java .util .List ;
22+ import java .util .Map ;
1423
1524/**
1625 * GlossaryConverter transfers the relevant properties from an Open Metadata Repository Services (OMRS)
@@ -34,19 +43,23 @@ public GlossaryConverter(OMRSRepositoryHelper repositoryHelper,
3443
3544
3645 /**
37- * Using the supplied instances, return a new instance of the bean. This is used for beans that
38- * contain a combination of the properties from an entity and that of a connected relationship.
46+ * Using the supplied instances, return a new instance of the bean.
3947 *
4048 * @param beanClass name of the class to create
41- * @param entity entity containing the properties
49+ * @param primaryEntity entity that is the root of the collection of entities that make up the
50+ * content of the bean
51+ * @param relationship relationship used to access the entity
52+ * @param relatedEntities relationships linking the entities
4253 * @param methodName calling method
4354 * @return bean populated with properties from the instances supplied
4455 * @throws PropertyServerException there is a problem instantiating the bean
4556 */
46- @ Override
47- public B getNewBean (Class <B > beanClass ,
48- EntityDetail entity ,
49- String methodName ) throws PropertyServerException
57+ public B getNewComplexBean (Class <B > beanClass ,
58+ EntityDetail primaryEntity ,
59+ Relationship relationship ,
60+ List <RelatedEntity > relatedEntities ,
61+ String methodName ) throws PropertyServerException
62+
5063 {
5164 try
5265 {
@@ -57,16 +70,16 @@ public B getNewBean(Class<B> beanClass,
5770
5871 if (returnBean instanceof GlossaryElement bean )
5972 {
60- GlossaryProperties glossaryProperties = new GlossaryProperties ();
6173
62- if (entity != null )
74+ if (primaryEntity != null )
6375 {
64- bean .setElementHeader (this .getMetadataElementHeader (beanClass , entity , methodName ));
76+ bean .setElementHeader (this .getMetadataElementHeader (beanClass , primaryEntity , methodName ));
77+ GlossaryProperties glossaryProperties = new GlossaryProperties ();
6578
6679 /*
6780 * The initial set of values come from the entity.
6881 */
69- InstanceProperties instanceProperties = new InstanceProperties (entity .getProperties ());
82+ InstanceProperties instanceProperties = new InstanceProperties (primaryEntity .getProperties ());
7083
7184 glossaryProperties .setQualifiedName (this .removeQualifiedName (instanceProperties ));
7285 glossaryProperties .setAdditionalProperties (this .removeAdditionalProperties (instanceProperties ));
@@ -76,6 +89,102 @@ public B getNewBean(Class<B> beanClass,
7689 glossaryProperties .setUsage (this .removeUsage (instanceProperties ));
7790
7891 bean .setGlossaryProperties (glossaryProperties );
92+
93+ if (relatedEntities != null )
94+ {
95+ List <RelatedMetadataElementSummary > externalReferences = new ArrayList <>();
96+ Map <String , ChildCategoryElement > categories = new HashMap <>();
97+ List <RelatedEntity > categoryHierarchyLinks = new ArrayList <>();
98+ List <String > childCategories = new ArrayList <>();
99+ List <RelatedMetadataElementSummary > otherRelatedElements = new ArrayList <>();
100+
101+ for (RelatedEntity relatedEntity : relatedEntities )
102+ {
103+ if ((relatedEntity != null ) && (relatedEntity .relationship () != null ) && (relatedEntity .entityDetail () != null ))
104+ {
105+ if (repositoryHelper .isTypeOf (serviceName ,
106+ relatedEntity .relationship ().getType ().getTypeDefName (),
107+ OpenMetadataType .CATEGORY_ANCHOR_RELATIONSHIP .typeName ))
108+ {
109+ ChildCategoryElement childCategoryElement = new ChildCategoryElement (super .getRelatedMetadataElementSummary (beanClass , relatedEntity , methodName ));
110+
111+ categories .put (childCategoryElement .getRelatedElement ().getElementHeader ().getGUID (), childCategoryElement );
112+ }
113+ else if (repositoryHelper .isTypeOf (serviceName ,
114+ relatedEntity .relationship ().getType ().getTypeDefName (),
115+ OpenMetadataType .CATEGORY_HIERARCHY_LINK_RELATIONSHIP .typeName ))
116+ {
117+ categoryHierarchyLinks .add (relatedEntity );
118+ }
119+ else if (repositoryHelper .isTypeOf (serviceName ,
120+ relatedEntity .relationship ().getType ().getTypeDefName (),
121+ OpenMetadataType .EXTERNAL_REFERENCE_LINK_RELATIONSHIP .typeName ))
122+ {
123+ externalReferences .add (super .getRelatedMetadataElementSummary (beanClass , relatedEntity , methodName ));
124+ }
125+ else if (! repositoryHelper .isTypeOf (serviceName ,
126+ relatedEntity .relationship ().getType ().getTypeDefName (),
127+ OpenMetadataType .TERM_ANCHOR_RELATIONSHIP .typeName ))
128+ {
129+ otherRelatedElements .add (super .getRelatedMetadataElementSummary (beanClass , relatedEntity , methodName ));
130+ }
131+ }
132+ }
133+
134+ if (! categoryHierarchyLinks .isEmpty ())
135+ {
136+ for (RelatedEntity relatedEntity : categoryHierarchyLinks )
137+ {
138+ ChildCategoryElement parentCategory = categories .get (relatedEntity .relationship ().getEntityOneProxy ().getGUID ());
139+ ChildCategoryElement childCategory = categories .get (relatedEntity .relationship ().getEntityTwoProxy ().getGUID ());
140+
141+ if ((parentCategory != null ) && (childCategory != null ))
142+ {
143+ List <ChildCategoryElement > currentChildCategories = parentCategory .getChildCategories ();
144+
145+ if (currentChildCategories == null )
146+ {
147+ currentChildCategories = new ArrayList <>();
148+ }
149+
150+ currentChildCategories .add (childCategory );
151+ parentCategory .setChildCategories (currentChildCategories );
152+ childCategories .add (childCategory .getRelatedElement ().getElementHeader ().getGUID ());
153+ }
154+ }
155+ }
156+
157+ if (! externalReferences .isEmpty ())
158+ {
159+ bean .setExternalReferences (externalReferences );
160+ }
161+ if (! categories .isEmpty ())
162+ {
163+ /*
164+ * Only need to return the top-level categories - all other
165+ * categories are nested.
166+ */
167+ List <ChildCategoryElement > parentCategories = new ArrayList <>();
168+
169+ for (ChildCategoryElement categoryElement : categories .values ())
170+ {
171+ if (! childCategories .contains (categoryElement .getRelatedElement ().getElementHeader ().getGUID ()))
172+ {
173+ parentCategories .add (categoryElement );
174+ }
175+ }
176+
177+ bean .setCategories (parentCategories );
178+ }
179+ if (! otherRelatedElements .isEmpty ())
180+ {
181+ bean .setOtherRelatedElements (otherRelatedElements );
182+ }
183+ }
184+
185+ GlossaryMermaidGraphBuilder graphBuilder = new GlossaryMermaidGraphBuilder (bean );
186+
187+ bean .setMermaidGraph (graphBuilder .getMermaidGraph ());
79188 }
80189 else
81190 {
@@ -94,6 +203,25 @@ public B getNewBean(Class<B> beanClass,
94203 }
95204
96205
206+ /**
207+ * Using the supplied instances, return a new instance of the bean. This is used for beans that
208+ * contain a combination of the properties from an entity and that of a connected relationship.
209+ *
210+ * @param beanClass name of the class to create
211+ * @param entity entity containing the properties
212+ * @param methodName calling method
213+ * @return bean populated with properties from the instances supplied
214+ * @throws PropertyServerException there is a problem instantiating the bean
215+ */
216+ @ Override
217+ public B getNewBean (Class <B > beanClass ,
218+ EntityDetail entity ,
219+ String methodName ) throws PropertyServerException
220+ {
221+ return getNewComplexBean (beanClass , entity , (Relationship ) null , null , methodName );
222+ }
223+
224+
97225 /**
98226 * Using the supplied instances, return a new instance of the bean. This is used for beans that
99227 * contain a combination of the properties from an entity and that of a connected relationship.
@@ -111,6 +239,6 @@ public B getNewBean(Class<B> beanClass,
111239 Relationship relationship ,
112240 String methodName ) throws PropertyServerException
113241 {
114- return getNewBean (beanClass , entity , methodName );
242+ return getNewComplexBean (beanClass , entity , relationship , null , methodName );
115243 }
116244}
0 commit comments