ATLAS-3376: UI V2 Fixed When no Catalogs are present, user should be presented with an appropriate message when trying to associate Category to Term.
diff --git a/dashboardv2/public/js/views/detail_page/DetailPageLayoutView.js b/dashboardv2/public/js/views/detail_page/DetailPageLayoutView.js
index b878f6d..e83212f 100644
--- a/dashboardv2/public/js/views/detail_page/DetailPageLayoutView.js
+++ b/dashboardv2/public/js/views/detail_page/DetailPageLayoutView.js
@@ -558,29 +558,46 @@
                     });
                 });
             },
-            onClickAddTermBtn: function(e) {
+            assignTermModalView: function(glossaryCollection, obj) {
                 var that = this,
-                    entityGuid = that.id,
-                    entityObj = this.collection.first().get('entity'),
-                    associatedTerms = [];
-                if (entityObj && entityObj.relationshipAttributes && entityObj.relationshipAttributes.meanings) {
-                    associatedTerms = entityObj.relationshipAttributes.meanings;
-                }
-                require(['views/glossary/AssignTermLayoutView'], function(AssignTermLayoutView) {
-                    var view = new AssignTermLayoutView({
-                        guid: that.id,
-                        callback: function() {
-                            that.fetchCollection();
-                        },
-                        associatedTerms: associatedTerms,
-                        showLoader: that.showLoader.bind(that),
-                        hideLoader: that.hideLoader.bind(that),
-                        glossaryCollection: that.glossaryCollection
-                    });
-                    view.modal.on('ok', function() {
-                        Utils.showTitleLoader(that.$('.page-title .fontLoader'), that.$('.entityDetail'));
-                    });
+                    terms = 0;
+                _.each(glossaryCollection.fullCollection.models, function(model) {
+                    if (model.get('terms')) {
+                        terms += model.get('terms').length;
+                    };
                 });
+                if (terms) {
+                    require(['views/glossary/AssignTermLayoutView'], function(AssignTermLayoutView) {
+                        var view = new AssignTermLayoutView({
+                            guid: obj.guid,
+                            callback: function() {
+                                that.fetchCollection();
+                            },
+                            associatedTerms: obj.associatedTerms,
+                            showLoader: that.showLoader.bind(that),
+                            hideLoader: that.hideLoader.bind(that),
+                            glossaryCollection: glossaryCollection
+                        });
+                        view.modal.on('ok', function() {
+                            Utils.showTitleLoader(that.$('.page-title .fontLoader'), that.$('.entityDetail'));
+                        });
+                    });
+                } else {
+                    Utils.notifyInfo({
+                        content: "There are no available terms that can be associated with this entity"
+                    });
+                }
+            },
+            onClickAddTermBtn: function(e) {
+                var entityObj = this.collection.first().get('entity'),
+                    obj = {
+                        guid: this.id,
+                        associatedTerms: [],
+                    };
+                this.assignTermModalView(this.glossaryCollection, obj);
+                if (entityObj && entityObj.relationshipAttributes && entityObj.relationshipAttributes.meanings) {
+                    obj.associatedTerms = entityObj.relationshipAttributes.meanings;
+                }
             },
             renderEntityDetailTableLayoutView: function(obj) {
                 var that = this;
diff --git a/dashboardv2/public/js/views/glossary/GlossaryDetailLayoutView.js b/dashboardv2/public/js/views/glossary/GlossaryDetailLayoutView.js
index d9f1fb9..bb8fe8f 100644
--- a/dashboardv2/public/js/views/glossary/GlossaryDetailLayoutView.js
+++ b/dashboardv2/public/js/views/glossary/GlossaryDetailLayoutView.js
@@ -165,7 +165,7 @@
                     }
                 };
                 events["click " + this.ui.addTerm] = 'onClickAddTermBtn';
-                events["click " + this.ui.addCategory] = 'onClickAddCategoryBtn';
+                events["click " + this.ui.addCategory] = 'onClickAddTermBtn';
                 events["click " + this.ui.addTag] = 'onClickAddTagBtn';
                 return events;
             },
@@ -336,60 +336,63 @@
                 this.ui.tagList.find("span.btn").remove();
                 this.ui.tagList.prepend(tagData);
             },
-            onClickAddTermBtn: function(e) {
-                var that = this;
-                require(['views/glossary/AssignTermLayoutView'], function(AssignTermLayoutView) {
-                    var glossary = that.glossaryCollection;
-                    if (that.value && that.value.gId) {
-                        var foundModel = that.glossaryCollection.find({ guid: that.value.gId });
-                        if (foundModel) {
-                            glossary = new VGlossaryList([foundModel.toJSON()], {
-                                comparator: function(item) {
-                                    return item.get("name");
-                                }
-                            });
-                        }
+            getCategoryTermCount: function(collection, matchString) {
+                var terms = 0;
+                _.each(collection, function(model) {
+                    if (model.get(matchString)) {
+                        terms += model.get(matchString).length;
                     }
-
-                    var view = new AssignTermLayoutView({
-                        categoryData: that.data,
-                        associatedTerms: that.data && that.data.terms && that.data.terms.length > 0 ? that.data.terms : [],
-                        isCategoryView: that.isCategoryView,
-                        callback: function() {
-                            that.getData();
-                        },
-                        glossaryCollection: glossary
-                    });
-                    view.modal.on('ok', function() {
-                        that.hideLoader();
-                    });
                 });
+                return terms;
             },
-            onClickAddCategoryBtn: function(e) {
+            onClickAddTermBtn: function(e) {
+                var glossary = this.glossaryCollection;
+                if (this.value && this.value.gId) {
+                    var foundModel = this.glossaryCollection.find({ guid: this.value.gId });
+                    if (foundModel) {
+                        glossary = new VGlossaryList([foundModel.toJSON()], {
+                            comparator: function(item) {
+                                return item.get("name");
+                            }
+                        });
+                    }
+                }
+                var obj = {
+                        callback: function() {
+                            this.getData();
+                        },
+                        glossaryCollection: glossary,
+                    },
+                    emptyListMessage = this.isCategoryView ? "There are no available terms that can be associated with this category" : "There are no available categories that can be associated with this term";
+
+                if (this.isCategoryView) {
+                    obj = _.extend(obj, {
+                        categoryData: this.data,
+                        associatedTerms: (this.data && this.data.terms && this.data.terms.length > 0) ? this.data.terms : [],
+                        isCategoryView: this.isCategoryView,
+                    });
+                } else {
+                    obj = _.extend(obj, {
+                        termData: this.data,
+                        isTermView: this.isTermView,
+                    });
+                }
+                if (this.getCategoryTermCount(glossary.fullCollection.models, this.isCategoryView ? "terms" : "categories")) {
+                    this.AssignTermLayoutViewModal(obj);
+                } else {
+                    Utils.notifyInfo({
+                        content: emptyListMessage
+                    });
+                }
+            },
+            AssignTermLayoutViewModal: function(termCategoryObj) {
                 var that = this;
                 require(['views/glossary/AssignTermLayoutView'], function(AssignTermLayoutView) {
-                    var glossary = that.glossaryCollection;
-                    if (that.value && that.value.gId) {
-                        var foundModel = that.glossaryCollection.find({ guid: that.value.gId });
-                        if (foundModel) {
-                            glossary = new VGlossaryList([foundModel.toJSON()], {
-                                comparator: function(item) {
-                                    return item.get("name");
-                                }
-                            });
-                        }
-                    }
-                    var view = new AssignTermLayoutView({
-                        termData: that.data,
-                        isTermView: that.isTermView,
-                        callback: function() {
-                            that.getData();
-                        },
-                        glossaryCollection: glossary
-                    });
+                    var view = new AssignTermLayoutView(termCategoryObj);
                     view.modal.on('ok', function() {
                         that.hideLoader();
                     });
+
                 });
             },
             onClickAddTagBtn: function(e) {
diff --git a/dashboardv2/public/js/views/search/SearchResultLayoutView.js b/dashboardv2/public/js/views/search/SearchResultLayoutView.js
index 9db1b54..98c9ec0 100644
--- a/dashboardv2/public/js/views/search/SearchResultLayoutView.js
+++ b/dashboardv2/public/js/views/search/SearchResultLayoutView.js
@@ -15,7 +15,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 define(['require',
     'backbone',
     'table-dragger',
@@ -1123,31 +1122,52 @@
                     that.addTagModalView(guid);
                 }
             },
+            //This function checks for the lenght of Available terms and modal for adding terms is displayed accordingly.
+            assignTermModalView: function(glossaryCollection, obj) {
+                var that = this,
+                    terms = 0;
+                _.each(glossaryCollection.fullCollection.models, function(model) {
+                    if (model.get('terms')) {
+                        terms += model.get('terms').length;
+                    };
+                });
+                if (terms) {
+                    require(['views/glossary/AssignTermLayoutView'], function(AssignTermLayoutView) {
+                        var view = new AssignTermLayoutView({
+                            guid: obj.guid,
+                            multiple: obj.multiple,
+                            associatedTerms: obj.associatedTerms,
+                            callback: function() {
+                                that.multiSelectEntity = [];
+                                that.$('.multiSelectTag,.multiSelectTerm').hide();
+                                that.fetchCollection();
+                            },
+                            glossaryCollection: glossaryCollection,
+                        });
+                    });
+                } else {
+                    Utils.notifyInfo({
+                        content: "There are no available terms"
+                    });
+                }
+            },
             onClickAddTermBtn: function(e) {
                 var that = this,
                     guid = "",
                     entityGuid = $(e.currentTarget).data("guid"),
-                    associatedTerms = undefined,
-                    multiple = undefined,
-                    isTermMultiSelect = $(e.currentTarget).hasClass('multiSelectTerm');
-                if (isTermMultiSelect && this.multiSelectEntity && this.multiSelectEntity.length) {
-                    multiple = this.multiSelectEntity;
-                } else if (entityGuid) {
-                    associatedTerms = this.searchCollection.find({ guid: entityGuid }).get('meanings');
-                }
-                require(['views/glossary/AssignTermLayoutView'], function(AssignTermLayoutView) {
-                    var view = new AssignTermLayoutView({
+                    obj = {
                         guid: entityGuid,
-                        multiple: multiple,
-                        associatedTerms: associatedTerms,
-                        callback: function() {
-                            that.multiSelectEntity = [];
-                            that.$('.multiSelectTag,.multiSelectTerm').hide();
-                            that.fetchCollection();
-                        },
-                        glossaryCollection: that.glossaryCollection,
-                    });
-                });
+                        multiple: undefined,
+                        associatedTerms: undefined,
+                    },
+                    isTermMultiSelect = $(e.currentTarget).hasClass('multiSelectTerm');
+
+                that.assignTermModalView(this.glossaryCollection, obj);
+                if (isTermMultiSelect && this.multiSelectEntity && this.multiSelectEntity.length) {
+                    obj.multiple = this.multiSelectEntity;
+                } else if (entityGuid) {
+                    obj.associatedTerms = this.searchCollection.find({ guid: entityGuid }).get('meanings');
+                }
             },
             onClickTagCross: function(e) {
                 var that = this,
diff --git a/dashboardv3/public/js/views/detail_page/DetailPageLayoutView.js b/dashboardv3/public/js/views/detail_page/DetailPageLayoutView.js
index dbbbcde..a18984e 100644
--- a/dashboardv3/public/js/views/detail_page/DetailPageLayoutView.js
+++ b/dashboardv3/public/js/views/detail_page/DetailPageLayoutView.js
@@ -565,29 +565,54 @@
                     });
                 });
             },
+            //This function checks for the lenght of Available terms and modal for adding terms is displayed accordingly.
+            assignTermModalView: function(glossaryCollection, obj) {
+                var that = this,
+                    terms = 0;
+                _.each(glossaryCollection.fullCollection.models, function(model) {
+                    if (model.get('terms')) {
+                        terms += model.get('terms').length;
+                    };
+                });
+                if (terms) {
+                    require(['views/glossary/AssignTermLayoutView'], function(AssignTermLayoutView) {
+                        var view = new AssignTermLayoutView({
+                            guid: obj.guid,
+                            callback: function() {
+                                that.fetchCollection();
+                            },
+                            associatedTerms: obj.associatedTerms,
+                            showLoader: that.showLoader.bind(that),
+                            hideLoader: that.hideLoader.bind(that),
+                            glossaryCollection: glossaryCollection
+                        });
+                        view.modal.on('ok', function() {
+                            Utils.showTitleLoader(that.$('.page-title .fontLoader'), that.$('.entityDetail'));
+                        });
+                    });
+                } else {
+                    Utils.notifyInfo({
+                        content: "There are no available terms that can be associated with this entity"
+                    });
+                }
+            },
             onClickAddTermBtn: function(e) {
                 var that = this,
-                    entityGuid = that.id,
                     entityObj = this.collection.first().get('entity'),
-                    associatedTerms = [];
-                if (entityObj && entityObj.relationshipAttributes && entityObj.relationshipAttributes.meanings) {
-                    associatedTerms = entityObj.relationshipAttributes.meanings;
-                }
-                require(['views/glossary/AssignTermLayoutView'], function(AssignTermLayoutView) {
-                    var view = new AssignTermLayoutView({
-                        guid: that.id,
-                        callback: function() {
-                            that.fetchCollection();
-                        },
-                        associatedTerms: associatedTerms,
-                        showLoader: that.showLoader.bind(that),
-                        hideLoader: that.hideLoader.bind(that),
-                        glossaryCollection: that.glossaryCollection
-                    });
-                    view.modal.on('ok', function() {
-                        Utils.showTitleLoader(that.$('.page-title .fontLoader'), that.$('.entityDetail'));
-                    });
+                    glossaryData = null,
+                    obj = {
+                        guid: this.id,
+                        associatedTerms: [],
+                    };
+                this.glossaryCollection.fetch({
+                    success: function(glossaryCollection) {
+                        that.assignTermModalView(glossaryCollection, obj);
+                    },
+                    reset: true,
                 });
+                if (entityObj && entityObj.relationshipAttributes && entityObj.relationshipAttributes.meanings) {
+                    obj.associatedTerms = entityObj.relationshipAttributes.meanings;
+                }
             },
             renderEntityDetailTableLayoutView: function(obj) {
                 var that = this;
diff --git a/dashboardv3/public/js/views/glossary/GlossaryDetailLayoutView.js b/dashboardv3/public/js/views/glossary/GlossaryDetailLayoutView.js
index 951281c..551e229 100644
--- a/dashboardv3/public/js/views/glossary/GlossaryDetailLayoutView.js
+++ b/dashboardv3/public/js/views/glossary/GlossaryDetailLayoutView.js
@@ -171,7 +171,7 @@
                     Utils.backButtonClick();
                 }
                 events["click " + this.ui.addTerm] = 'onClickAddTermBtn';
-                events["click " + this.ui.addCategory] = 'onClickAddCategoryBtn';
+                events["click " + this.ui.addCategory] = 'onClickAddTermBtn';
                 events["click " + this.ui.addTag] = 'onClickAddTagBtn';
                 return events;
             },
@@ -351,60 +351,63 @@
                 this.ui.tagList.find("span.btn").remove();
                 this.ui.tagList.prepend(tagData);
             },
-            onClickAddTermBtn: function(e) {
-                var that = this;
-                require(['views/glossary/AssignTermLayoutView'], function(AssignTermLayoutView) {
-                    var glossary = that.glossaryCollection;
-                    if (that.value && that.value.gId) {
-                        var foundModel = that.glossaryCollection.find({ guid: that.value.gId });
-                        if (foundModel) {
-                            glossary = new VGlossaryList([foundModel.toJSON()], {
-                                comparator: function(item) {
-                                    return item.get("name");
-                                }
-                            });
-                        }
+            getCategoryTermCount: function(collection, matchString) {
+                var terms = 0;
+                _.each(collection, function(model) {
+                    if (model.get(matchString)) {
+                        terms += model.get(matchString).length;
                     }
-
-                    var view = new AssignTermLayoutView({
-                        categoryData: that.data,
-                        associatedTerms: that.data && that.data.terms && that.data.terms.length > 0 ? that.data.terms : [],
-                        isCategoryView: that.isCategoryView,
-                        callback: function() {
-                            that.getData();
-                        },
-                        glossaryCollection: glossary
-                    });
-                    view.modal.on('ok', function() {
-                        that.hideLoader();
-                    });
                 });
+                return terms;
             },
-            onClickAddCategoryBtn: function(e) {
+            onClickAddTermBtn: function(e) {
+                var glossary = this.glossaryCollection;
+                if (this.value && this.value.gId) {
+                    var foundModel = this.glossaryCollection.find({ guid: this.value.gId });
+                    if (foundModel) {
+                        glossary = new VGlossaryList([foundModel.toJSON()], {
+                            comparator: function(item) {
+                                return item.get("name");
+                            }
+                        });
+                    }
+                }
+                var obj = {
+                        callback: function() {
+                            this.getData();
+                        },
+                        glossaryCollection: glossary,
+                    },
+                    emptyListMessage = this.isCategoryView ? "There are no available terms that can be associated with this category" : "There are no available categories that can be associated with this term";
+
+                if (this.isCategoryView) {
+                    obj = _.extend(obj, {
+                        categoryData: this.data,
+                        associatedTerms: (this.data && this.data.terms && this.data.terms.length > 0) ? this.data.terms : [],
+                        isCategoryView: this.isCategoryView,
+                    });
+                } else {
+                    obj = _.extend(obj, {
+                        termData: this.data,
+                        isTermView: this.isTermView,
+                    });
+                }
+                if (this.getCategoryTermCount(glossary.fullCollection.models, this.isCategoryView ? "terms" : "categories")) {
+                    this.AssignTermLayoutViewModal(obj);
+                } else {
+                    Utils.notifyInfo({
+                        content: emptyListMessage
+                    });
+                }
+            },
+            AssignTermLayoutViewModal: function(termCategoryObj) {
                 var that = this;
                 require(['views/glossary/AssignTermLayoutView'], function(AssignTermLayoutView) {
-                    var glossary = that.glossaryCollection;
-                    if (that.value && that.value.gId) {
-                        var foundModel = that.glossaryCollection.find({ guid: that.value.gId });
-                        if (foundModel) {
-                            glossary = new VGlossaryList([foundModel.toJSON()], {
-                                comparator: function(item) {
-                                    return item.get("name");
-                                }
-                            });
-                        }
-                    }
-                    var view = new AssignTermLayoutView({
-                        termData: that.data,
-                        isTermView: that.isTermView,
-                        callback: function() {
-                            that.getData();
-                        },
-                        glossaryCollection: glossary
-                    });
+                    var view = new AssignTermLayoutView(termCategoryObj);
                     view.modal.on('ok', function() {
                         that.hideLoader();
                     });
+
                 });
             },
             onClickAddTagBtn: function(e) {
diff --git a/dashboardv3/public/js/views/search/SearchResultLayoutView.js b/dashboardv3/public/js/views/search/SearchResultLayoutView.js
index d98d6e2..d5883ca 100644
--- a/dashboardv3/public/js/views/search/SearchResultLayoutView.js
+++ b/dashboardv3/public/js/views/search/SearchResultLayoutView.js
@@ -153,7 +153,7 @@
              * @constructs
              */
             initialize: function(options) {
-                _.extend(this, _.pick(options, 'value', 'guid', 'initialView', 'isTypeTagNotExists', 'classificationDefCollection', 'entityDefCollection', 'typeHeaders', 'searchVent', 'enumDefCollection', 'tagCollection', 'searchTableColumns', 'isTableDropDisable', 'fromView', 'glossaryCollection', 'termName', 'businessMetadataDefCollection', 'profileDBView'));
+                _.extend(this, _.pick(options, 'value', 'guid', 'initialView', 'isTypeTagNotExists', 'classificationDefCollection', 'entityDefCollection', 'typeHeaders', 'searchVent', 'categoryEvent', 'enumDefCollection', 'tagCollection', 'searchTableColumns', 'isTableDropDisable', 'fromView', 'glossaryCollection', 'termName', 'businessMetadataDefCollection', 'profileDBView'));
                 this.entityModel = new VEntity();
                 this.searchCollection = new VSearchList();
                 this.limit = 25;
@@ -248,13 +248,17 @@
                 }, this);
                 this.listenTo(this.searchCollection, "backgrid:sorted", function(model, response) {
                     this.checkTableFetch();
-                }, this)
+                }, this);
+                this.listenTo(this.categoryEvent, "Sucess:TermSearchResultPage", function() {
+                    this.glossaryCollection.fetch({ reset: true });
+                });
             },
             onRender: function() {
                 var that = this;
                 if (Utils.getUrlState.isSearchTab()) {
                     this.$(".action-box").hide();
                 }
+
                 this.checkEntityImage = {};
                 this.commonTableOptions = {
                     collection: this.searchCollection,
@@ -1134,32 +1138,57 @@
                     that.addTagModalView(guid);
                 }
             },
+            //This function checks for the lenght of Available terms and modal for adding terms is displayed accordingly.
+            assignTermModalView: function(glossaryCollection, obj) {
+                var that = this,
+                    terms = 0;
+                _.each(glossaryCollection.fullCollection.models, function(model) {
+                    if (model.get('terms')) {
+                        terms += model.get('terms').length;
+                    };
+                });
+                if (terms) {
+                    require(['views/glossary/AssignTermLayoutView'], function(AssignTermLayoutView) {
+                        var view = new AssignTermLayoutView({
+                            guid: obj.guid,
+                            multiple: obj.multiple,
+                            associatedTerms: obj.associatedTerms,
+                            callback: function() {
+                                that.multiSelectEntity = [];
+                                that.$('.multiSelectTag,.multiSelectTerm').hide();
+                                that.fetchCollection();
+                            },
+                            glossaryCollection: glossaryCollection,
+                        });
+                    });
+                } else {
+                    Utils.notifyInfo({
+                        content: "There are no available terms"
+                    });
+                }
+            },
             onClickAddTermBtn: function(e) {
                 var that = this,
                     guid = "",
                     entityGuid = $(e.currentTarget).data("guid"),
-                    associatedTerms = undefined,
-                    multiple = undefined,
-                    isTermMultiSelect = $(e.currentTarget).hasClass('multiSelectTerm');
-                if (isTermMultiSelect && this.multiSelectEntity && this.multiSelectEntity.length) {
-                    multiple = this.multiSelectEntity;
-                } else if (entityGuid) {
-                    associatedTerms = this.searchCollection.find({ guid: entityGuid }).get('meanings');
-                }
-                require(['views/glossary/AssignTermLayoutView'], function(AssignTermLayoutView) {
-                    var view = new AssignTermLayoutView({
+                    obj = {
                         guid: entityGuid,
-                        multiple: multiple,
-                        associatedTerms: associatedTerms,
-                        callback: function() {
-                            that.multiSelectEntity = [];
-                            that.$('.multiSelectTag,.multiSelectTerm').hide();
-                            that.fetchCollection();
-
-                        },
-                        glossaryCollection: that.glossaryCollection,
-                    });
+                        multiple: undefined,
+                        associatedTerms: undefined,
+                    },
+                    isTermMultiSelect = $(e.currentTarget).hasClass('multiSelectTerm');
+                this.glossaryCollection.fetch({
+                    success: function(glossaryCollection) {
+                        that.assignTermModalView(glossaryCollection, obj);
+                    },
+                    reset: true,
                 });
+                if (isTermMultiSelect && this.multiSelectEntity && this.multiSelectEntity.length) {
+                    obj.multiple = this.multiSelectEntity;
+                } else if (entityGuid) {
+                    obj.associatedTerms = this.searchCollection.find({ guid: entityGuid }).get('meanings');
+                }
+
             },
             onClickTagCross: function(e) {
                 var that = this,