@@ -167,6 +167,7 @@ private void processParentCategory(AtlasGlossaryCategory storeObject, AtlasGloss
167
167
} else {
168
168
// Delete link to existing parent and link to new parent
169
169
relationshipStore .deleteById (parentRelationship .getGuid (), true );
170
+ updateQualifiedName (storeObject , newParent .getCategoryGuid ());
170
171
createRelationship (defineCategoryHierarchyLink (newParent , storeObject .getGuid ()));
171
172
}
172
173
}
@@ -187,8 +188,7 @@ private void processNewParent(AtlasGlossaryCategory storeObject, AtlasRelatedCat
187
188
188
189
// New parent added, qualifiedName needs recomputation
189
190
// Derive the qualifiedName of the Glossary
190
- AtlasGlossaryCategory parentCategory = dataAccess .load (getAtlasGlossaryCategorySkeleton (newParent .getCategoryGuid ()));
191
- storeObject .setQualifiedName (storeObject .getName () + "." + parentCategory .getQualifiedName ());
191
+ updateQualifiedName (storeObject , newParent .getCategoryGuid ());
192
192
193
193
if (LOG .isDebugEnabled ()) {
194
194
LOG .debug ("Derived qualifiedName = {}" , storeObject .getQualifiedName ());
@@ -197,6 +197,14 @@ private void processNewParent(AtlasGlossaryCategory storeObject, AtlasRelatedCat
197
197
updateChildCategories (storeObject , storeObject .getChildrenCategories (), impactedCategories , false );
198
198
}
199
199
200
+ private void updateQualifiedName (AtlasGlossaryCategory storeObject , String guid ) throws AtlasBaseException {
201
+ AtlasRelatedCategoryHeader parentCat = new AtlasRelatedCategoryHeader ();
202
+ parentCat .setCategoryGuid (guid );
203
+ AtlasGlossaryCategory glossaryCategory = new AtlasGlossaryCategory (storeObject );
204
+ glossaryCategory .setParentCategory (parentCat );
205
+ storeObject .setQualifiedName (createQualifiedName (glossaryCategory ));
206
+ }
207
+
200
208
private void processParentRemoval (AtlasGlossaryCategory storeObject , AtlasGlossaryCategory updatedCategory , AtlasRelatedCategoryHeader existingParent , Map <String , AtlasGlossaryCategory > impactedCategories ) throws AtlasBaseException {
201
209
if (DEBUG_ENABLED ) {
202
210
LOG .debug ("Removing category parent, category = {}, parent = {}" , storeObject .getGuid (), existingParent .getDisplayText ());
@@ -207,8 +215,9 @@ private void processParentRemoval(AtlasGlossaryCategory storeObject, AtlasGlossa
207
215
208
216
// Derive the qualifiedName of the Glossary
209
217
String anchorGlossaryGuid = updatedCategory .getAnchor ().getGlossaryGuid ();
210
- AtlasGlossary glossary = dataAccess .load (getGlossarySkeleton (anchorGlossaryGuid ));
211
- storeObject .setQualifiedName (storeObject .getName () + "@" + glossary .getQualifiedName ());
218
+ AtlasGlossaryCategory glossaryCategory = new AtlasGlossaryCategory (storeObject );
219
+ glossaryCategory .setAnchor (new AtlasGlossaryHeader (anchorGlossaryGuid ));
220
+ storeObject .setQualifiedName (createQualifiedName (glossaryCategory , true ));
212
221
213
222
if (LOG .isDebugEnabled ()) {
214
223
LOG .debug ("Derived qualifiedName = {}" , storeObject .getQualifiedName ());
@@ -393,6 +402,7 @@ private void processCategoryChildren(AtlasGlossaryCategory storeObject, AtlasGlo
393
402
.stream ()
394
403
.filter (c -> updatedExistingCategoryRelation (existingChildren , c ))
395
404
.collect (Collectors .toSet ());
405
+ updateChildCategories (storeObject , toUpdate , impactedCategories , false );
396
406
updateCategoryRelationships (storeObject , toUpdate );
397
407
398
408
Set <AtlasRelatedCategoryHeader > toDelete = existingChildren
@@ -535,20 +545,25 @@ private void updateChildCategories(AtlasGlossaryCategory parentCategory, Collect
535
545
536
546
for (AtlasRelatedCategoryHeader childCategoryHeader : childCategories ) {
537
547
AtlasGlossaryCategory child = dataAccess .load (getAtlasGlossaryCategorySkeleton (childCategoryHeader .getCategoryGuid ()));
538
- String qualifiedName = child .getName () + "." ;
539
548
String childAnchorGuid = child .getAnchor ().getGlossaryGuid ();
549
+ String qualifiedName = "" ;
550
+
540
551
if (isParentRemoved ) {
541
552
if (LOG .isDebugEnabled ()) {
542
553
LOG .debug ("Parent removed, deriving qualifiedName using Glossary" );
543
554
}
544
555
AtlasGlossary glossary = dataAccess .load (getGlossarySkeleton (childAnchorGuid ));
545
- qualifiedName += glossary .getQualifiedName ();
556
+ qualifiedName = getNanoid ( child . getQualifiedName ()) + glossary .getQualifiedName ();
546
557
child .setParentCategory (null );
547
558
} else {
548
559
if (LOG .isDebugEnabled ()) {
549
560
LOG .debug ("Using parent to derive qualifiedName" );
550
561
}
551
- qualifiedName += parentCategory .getQualifiedName ();
562
+ AtlasGlossaryCategory category = new AtlasGlossaryCategory (child );
563
+ AtlasRelatedCategoryHeader parentCat = new AtlasRelatedCategoryHeader ();
564
+ parentCat .setCategoryGuid (parentCategory .getGuid ());
565
+ category .setParentCategory (parentCat );
566
+ qualifiedName = createQualifiedName (category , parentCategory , false );
552
567
}
553
568
child .setQualifiedName (qualifiedName );
554
569
@@ -576,4 +591,52 @@ private void updateChildCategories(AtlasGlossaryCategory parentCategory, Collect
576
591
}
577
592
}
578
593
594
+ protected String createQualifiedName (AtlasGlossaryCategory cat ) throws AtlasBaseException {
595
+ return createQualifiedName (cat , null , false );
596
+ }
597
+
598
+ protected String createQualifiedName (AtlasGlossaryCategory cat , boolean parentRemoval ) throws AtlasBaseException {
599
+ return createQualifiedName (cat , null , parentRemoval );
600
+ }
601
+
602
+ protected String createQualifiedName (AtlasGlossaryCategory cat , AtlasGlossaryCategory parentCategory , boolean parentRemoval ) throws AtlasBaseException {
603
+ String ret = "" ;
604
+ String qName = "" ;
605
+
606
+ if (!StringUtils .isEmpty (cat .getQualifiedName ())) {
607
+ //extract existing nanoid for category
608
+ String [] t1 = cat .getQualifiedName ().split ("\\ ." );
609
+ qName = t1 [t1 .length -1 ].split ("@" )[0 ];
610
+ }
611
+
612
+ qName = StringUtils .isEmpty (qName ) ? getUUID () : qName ;
613
+ if (parentRemoval ) {
614
+ AtlasGlossary glossary = dataAccess .load (getGlossarySkeleton (cat .getAnchor ().getGlossaryGuid ()));
615
+ ret = qName + "@" + glossary .getQualifiedName ();
616
+
617
+ } else if (parentCategory != null ) {
618
+ String [] parentCatQname = parentCategory .getQualifiedName ().split ("@" );
619
+ ret = parentCatQname [0 ] + "." + qName + "@" + parentCatQname [1 ];
620
+
621
+ } else if (cat .getParentCategory () != null ) {
622
+ AtlasGlossaryCategory parentCat = dataAccess .load (getAtlasGlossaryCategorySkeleton (cat .getParentCategory ().getCategoryGuid ()));
623
+ String [] parentCatQname = parentCat .getQualifiedName ().split ("@" );
624
+ ret = parentCatQname [0 ] + "." + qName + "@" + parentCatQname [1 ];
625
+
626
+ } else {
627
+ String anchorGlossaryGuid = cat .getAnchor ().getGlossaryGuid ();
628
+ AtlasGlossary glossary = dataAccess .load (getGlossarySkeleton (anchorGlossaryGuid ));
629
+ if (glossary == null ) {
630
+ throw new AtlasBaseException ("Glossary not found with guid: " + anchorGlossaryGuid );
631
+ }
632
+ ret = qName + "@" + glossary .getQualifiedName ();
633
+ }
634
+ return ret ;
635
+ }
636
+
637
+ private String getNanoid (String qualifiedName ){
638
+ String [] split_0 = qualifiedName .split ("@" );
639
+ String [] split_1 = split_0 [0 ].split ("\\ ." );
640
+ return split_1 [split_1 .length -1 ];
641
+ }
579
642
}
0 commit comments