ATLAS-4213: Atlas UI is taking lot of time to load when there are more classifications.

Signed-off-by: nixonrodrigues <nixon@apache.org>
diff --git a/dashboardv2/public/js/main.js b/dashboardv2/public/js/main.js
index 64be5b4..85f3d82 100644
--- a/dashboardv2/public/js/main.js
+++ b/dashboardv2/public/js/main.js
@@ -205,7 +205,7 @@
     'select2'
 ], function(App, Router, Helper, CommonViewFunction, Globals, UrlLinks, VEntityList, VTagList, Enums) {
     var that = this;
-    this.asyncFetchCounter = 7 + (Enums.addOnEntities.length + 1);
+    this.asyncFetchCounter = 5 + (Enums.addOnEntities.length + 1);
     // entity
     this.entityDefCollection = new VEntityList();
     this.entityDefCollection.url = UrlLinks.entitiesDefApiUrl();
@@ -222,6 +222,7 @@
     this.metricCollection = new VTagList();
     this.metricCollection.url = UrlLinks.metricsApiUrl();
     this.metricCollection.modelAttrName = "data";
+    this.classificationAndMetricEvent = new Backbone.Wreqr.EventAggregator();
     // businessMetadata
     this.businessMetadataDefCollection = new VEntityList();
     this.businessMetadataDefCollection.url = UrlLinks.businessMetadataDefApiUrl();
@@ -233,6 +234,7 @@
         enumDefCollection: this.enumDefCollection,
         classificationDefCollection: this.classificationDefCollection,
         metricCollection: this.metricCollection,
+        classificationAndMetricEvent: this.classificationAndMetricEvent,
         businessMetadataDefCollection: this.businessMetadataDefCollection
     });
 
@@ -294,6 +296,7 @@
         }
     });
     this.typeHeaders.fetch({
+        async: true,
         complete: function() {
             that.typeHeaders.fullCollection.comparator = function(model) {
                 return model.get('name').toLowerCase();
@@ -314,23 +317,22 @@
         }
     });
     this.classificationDefCollection.fetch({
+        async: true,
         complete: function() {
             that.classificationDefCollection.fullCollection.comparator = function(model) {
                 return model.get('name').toLowerCase();
             };
             that.classificationDefCollection.fullCollection.sort({ silent: true });
-            --that.asyncFetchCounter;
-            startApp();
+            that.classificationAndMetricEvent.trigger("classification:Update:ClassificationTab");
+            that.classificationAndMetricEvent.trigger("classification:Update:Search");
         }
     });
-
     this.metricCollection.fetch({
-        complete: function() {
-            --that.asyncFetchCounter;
-            startApp();
+        async: true,
+        success: function() {
+            that.classificationAndMetricEvent.trigger("metricCollection:Update");
         }
     });
-
     this.businessMetadataDefCollection.fetch({
         complete: function() {
             that.businessMetadataDefCollection.fullCollection.comparator = function(model) {
@@ -341,7 +343,6 @@
             startApp();
         }
     });
-
     CommonViewFunction.fetchRootEntityAttributes({
         url: UrlLinks.rootEntityDefUrl(Enums.addOnEntities[0]),
         entity: Enums.addOnEntities,
@@ -350,7 +351,6 @@
             startApp();
         }
     });
-
     CommonViewFunction.fetchRootClassificationAttributes({
         url: UrlLinks.rootClassificationDefUrl(Enums.addOnClassification[0]),
         classification: Enums.addOnClassification,
diff --git a/dashboardv2/public/js/router/Router.js b/dashboardv2/public/js/router/Router.js
index 97635b9..392f30d 100644
--- a/dashboardv2/public/js/router/Router.js
+++ b/dashboardv2/public/js/router/Router.js
@@ -50,7 +50,7 @@
             '*actions': 'defaultAction'
         },
         initialize: function(options) {
-            _.extend(this, _.pick(options, 'entityDefCollection', 'typeHeaders', 'enumDefCollection', 'classificationDefCollection', 'metricCollection', 'businessMetadataDefCollection'));
+            _.extend(this, _.pick(options, 'entityDefCollection', 'typeHeaders', 'enumDefCollection', 'classificationDefCollection', 'metricCollection', 'classificationAndMetricEvent', 'businessMetadataDefCollection'));
             this.showRegions();
             this.bindCommonEvents();
             this.listenTo(this, 'route', this.postRouteExecute, this);
@@ -68,6 +68,7 @@
                 'classificationDefCollection': this.classificationDefCollection,
                 'glossaryCollection': this.glossaryCollection,
                 'metricCollection': this.metricCollection,
+                'classificationAndMetricEvent': this.classificationAndMetricEvent,
                 'businessMetadataDefCollection': this.businessMetadataDefCollection
             }
             this.ventObj = {
@@ -259,10 +260,12 @@
             require([
                 'views/site/Header',
                 'views/site/SideNavLayoutView',
-                'views/search/SearchDetailLayoutView'
-            ], function(Header, SideNavLayoutView, SearchDetailLayoutView) {
+                'views/search/SearchDetailLayoutView',
+                'collection/VTagList'
+            ], function(Header, SideNavLayoutView, SearchDetailLayoutView, VTagList) {
                 var paramObj = Utils.getUrlState.getQueryParams(),
-                    options = _.extend({}, that.preFetchedCollectionLists, that.sharedObj, that.ventObj);
+                    options = _.extend({}, that.preFetchedCollectionLists, that.sharedObj, that.ventObj),
+                    tag = new VTagList();
                 if (paramObj.tag) {
                     var tagValidate = paramObj.tag,
                         isTagPresent = false;
@@ -283,34 +286,54 @@
                             }
                         });
                         if (!isTagPresent) {
-                            paramObj.tag = null;
+                            tag.url = UrlLinks.classicationApiUrl(tagValidate);
+                            tag.fetch({
+                                success: function(tagCollection) {
+                                    isTagPresent = true;
+                                },
+                                cust_error: function(model, response) {
+                                    paramObj.tag = null;
+                                },
+                                complete: function() {
+                                    renderSearchView.call();
+                                }
+                            });
+                        } else {
+                            renderSearchView();
                         }
+                    } else {
+                        renderSearchView();
                     }
+                } else {
+                    renderSearchView();
                 }
-                var isinitialView = true,
-                    isTypeTagNotExists = false,
-                    tempParam = $.extend(true, {}, paramObj);
-                that.renderViewIfNotExists(that.getHeaderOptions(Header));
-                that.renderViewIfNotExists({
-                    view: App.rSideNav,
-                    manualRender: function() {
-                        this.view.currentView.RSearchLayoutView.currentView.manualRender(tempParam);
-                    },
-                    render: function() {
-                        return new SideNavLayoutView(_.extend({ 'value': tempParam }, options));
+
+                function renderSearchView() {
+                    var isinitialView = true,
+                        isTypeTagNotExists = false,
+                        tempParam = $.extend(true, {}, paramObj);
+                    that.renderViewIfNotExists(that.getHeaderOptions(Header));
+                    that.renderViewIfNotExists({
+                        view: App.rSideNav,
+                        manualRender: function() {
+                            this.view.currentView.RSearchLayoutView.currentView.manualRender(tempParam);
+                        },
+                        render: function() {
+                            return new SideNavLayoutView(_.extend({ 'value': tempParam }, options));
+                        }
+                    });
+                    App.rSideNav.currentView.selectTab();
+                    if (paramObj) {
+                        isinitialView = (paramObj.type || (paramObj.dslChecked == "true" ? "" : (paramObj.tag || paramObj.term)) || (paramObj.query ? paramObj.query.trim() : "")).length === 0;
                     }
-                });
-                App.rSideNav.currentView.selectTab();
-                if (paramObj) {
-                    isinitialView = (paramObj.type || (paramObj.dslChecked == "true" ? "" : (paramObj.tag || paramObj.term)) || (paramObj.query ? paramObj.query.trim() : "")).length === 0;
+                    App.rNContent.show(new SearchDetailLayoutView(
+                        _.extend({
+                            'value': paramObj,
+                            'initialView': isinitialView,
+                            'isTypeTagNotExists': ((paramObj.type != tempParam.type) || (tempParam.tag != paramObj.tag))
+                        }, options)
+                    ));
                 }
-                App.rNContent.show(new SearchDetailLayoutView(
-                    _.extend({
-                        'value': paramObj,
-                        'initialView': isinitialView,
-                        'isTypeTagNotExists': ((paramObj.type != tempParam.type) || (tempParam.tag != paramObj.tag))
-                    }, options)
-                ));
             });
         },
         administrator: function() {
diff --git a/dashboardv2/public/js/templates/tag/TagLayoutView_tmpl.html b/dashboardv2/public/js/templates/tag/TagLayoutView_tmpl.html
index 598591a..b6135c8 100644
--- a/dashboardv2/public/js/templates/tag/TagLayoutView_tmpl.html
+++ b/dashboardv2/public/js/templates/tag/TagLayoutView_tmpl.html
@@ -48,4 +48,7 @@
             </ul>
         </div>
     </div>
+    <div class="col-sm-12 text-center" data-id="tagTreeTextLoader">
+        Loading Classifications <i class="fa fa-refresh fa-spin-custom"> </i>
+    </div>
 </div>
\ No newline at end of file
diff --git a/dashboardv2/public/js/views/search/SearchLayoutView.js b/dashboardv2/public/js/views/search/SearchLayoutView.js
index 4b643bb..1dbda7f 100644
--- a/dashboardv2/public/js/views/search/SearchLayoutView.js
+++ b/dashboardv2/public/js/views/search/SearchLayoutView.js
@@ -90,9 +90,9 @@
              * @constructs
              */
             initialize: function(options) {
-                _.extend(this, _.pick(options, 'value', 'typeHeaders', 'searchVent', 'entityDefCollection', 'enumDefCollection', 'classificationDefCollection', 'businessMetadataDefCollection', 'searchTableColumns', 'searchTableFilters', 'metricCollection'));
+                _.extend(this, _.pick(options, 'value', 'typeHeaders', 'searchVent', 'entityDefCollection', 'enumDefCollection', 'classificationDefCollection', 'businessMetadataDefCollection', 'searchTableColumns', 'searchTableFilters', 'metricCollection', 'classificationAndMetricEvent'));
                 this.type = "basic";
-                this.entityCountObj = _.first(this.metricCollection.toJSON());
+                this.entityCountObj = _.first(this.metricCollection.toJSON()) || { entity: { entityActive: {}, entityDeleted: {} }, tag: { tagEntities: {} } };
                 this.selectedFilter = {
                     'basic': [],
                     'dsl': []
@@ -207,12 +207,19 @@
                 });
             },
             bindEvents: function(param) {
+                var that = this;
                 this.listenTo(this.typeHeaders, "reset", function(value) {
                     this.initializeValues();
                 }, this);
                 this.listenTo(this.searchVent, "entityList:refresh", function(model, response) {
                     this.onRefreshButton();
                 }, this);
+                this.classificationAndMetricEvent.on("classification:Update:Search", function(options) {
+                    that.entityCountObj = _.first(that.metricCollection.toJSON());
+                    that.value = Utils.getUrlState.getQueryParams() || {};
+                    if (!that.value.type) that.setInitialEntityVal = true;
+                    that.initializeValues();
+                });
             },
             initializeValues: function() {
                 this.renderTypeTagList();
@@ -743,24 +750,29 @@
                     params['term'] = termLovValue || null;
                     var entityFilterObj = this.searchTableFilters['entityFilters'],
                         tagFilterObj = this.searchTableFilters['tagFilters'];
-                    if (this.value.tag) {
-                        params['tagFilters'] = tagFilterObj[this.value.tag]
+                    params['includeDE'] = false;
+                    params['excludeST'] = false;
+                    params['excludeSC'] = false;
+                    if (this.value) {
+                        if (this.value.tag) {
+                            params['tagFilters'] = tagFilterObj[this.value.tag]
+                        }
+                        if (this.value.type) {
+                            params['entityFilters'] = entityFilterObj[this.value.type]
+                        }
+                        var columnList = this.value.type && this.searchTableColumns ? this.searchTableColumns[this.value.type] : null;
+                        if (columnList) {
+                            params['attributes'] = columnList.join(',');
+                        }
+                        params['includeDE'] = _.isUndefinedNull(this.value.includeDE) ? false : this.value.includeDE;
+                        params['excludeST'] = _.isUndefinedNull(this.value.excludeST) ? false : this.value.excludeST;
+                        params['excludeSC'] = _.isUndefinedNull(this.value.excludeSC) ? false : this.value.excludeSC;
                     }
-                    if (this.value.type) {
-                        params['entityFilters'] = entityFilterObj[this.value.type]
-                    }
-                    var columnList = this.value && this.value.type && this.searchTableColumns ? this.searchTableColumns[this.value.type] : null;
-                    if (columnList) {
-                        params['attributes'] = columnList.join(',');
-                    }
-                    params['includeDE'] = _.isUndefinedNull(this.value.includeDE) ? false : this.value.includeDE;
-                    params['excludeST'] = _.isUndefinedNull(this.value.excludeST) ? false : this.value.excludeST;
-                    params['excludeSC'] = _.isUndefinedNull(this.value.excludeSC) ? false : this.value.excludeSC;
                 }
-                if (!_.isUndefinedNull(this.value.pageLimit)) {
+                if (this.value && !_.isUndefinedNull(this.value.pageLimit)) {
                     params['pageLimit'] = this.value.pageLimit;
                 }
-                if (!_.isUndefinedNull(this.value.pageOffset)) {
+                if (this.value && !_.isUndefinedNull(this.value.pageOffset)) {
                     if (!_.isUndefinedNull(this.query[this.type]) && this.query[this.type].query != value) {
                         params['pageOffset'] = 0;
                     } else {
diff --git a/dashboardv2/public/js/views/tag/TagLayoutView.js b/dashboardv2/public/js/views/tag/TagLayoutView.js
index 61f694c..e2155f1 100644
--- a/dashboardv2/public/js/views/tag/TagLayoutView.js
+++ b/dashboardv2/public/js/views/tag/TagLayoutView.js
@@ -23,8 +23,8 @@
     'utils/Messages',
     'utils/Globals',
     'utils/UrlLinks',
-    'models/VTag'
-], function(require, Backbone, TagLayoutViewTmpl, Utils, Messages, Globals, UrlLinks, VTag) {
+    'collection/VTagList'
+], function(require, Backbone, TagLayoutViewTmpl, Utils, Messages, Globals, UrlLinks, VTagList) {
     'use strict';
 
     var TagLayoutView = Backbone.Marionette.LayoutView.extend(
@@ -49,6 +49,7 @@
                 tagView: 'input[name="tagView"]',
                 expandArrow: '[data-id="expandArrow"]',
                 tagTreeLoader: '[data-id="tagTreeLoader"]',
+                tagTreeTextLoader: '[data-id="tagTreeTextLoader"]',
                 tagTreeView: '[data-id="tagTreeView"]'
             },
             /** ui events hash */
@@ -68,7 +69,7 @@
              * @constructs
              */
             initialize: function(options) {
-                _.extend(this, _.pick(options, 'tag', 'collection', 'typeHeaders', 'value', 'enumDefCollection'));
+                _.extend(this, _.pick(options, 'tag', 'collection', 'typeHeaders', 'value', 'enumDefCollection', 'classificationAndMetricEvent'));
                 this.viewType = "flat";
                 this.query = {
                     flat: {
@@ -87,6 +88,7 @@
                 var that = this;
                 this.listenTo(this.collection.fullCollection, "reset add remove", function() {
                     this.tagsGenerator();
+                    this.changeLoaderTextState(false);
                 }, this);
                 this.ui.tagsList.on('click', 'li.parent-node a', function() {
                     that.setUrl(this.getAttribute("href"));
@@ -95,12 +97,36 @@
                     that.$('.tagPopover').popover('hide');
                     that[$(this).find('a').data('fn')](e)
                 });
+                this.classificationAndMetricEvent.on("classification:Update:ClassificationTab", function(options) {
+                    that.changeLoaderTextState(false);
+                });
             },
             onRender: function() {
                 var that = this;
+                this.changeLoaderTextState(false);
                 this.changeLoaderState(true);
                 this.bindEvents();
-                this.tagsGenerator();
+                this.checkTagOnRefresh();
+            },
+            checkTagOnRefresh: function() {
+                var that = this,
+                    tagName = this.options.tag,
+                    presentTag = this.collection.fullCollection.findWhere({ name: tagName }),
+                    tag = new VTagList();
+                if (!presentTag && tagName) {
+                    tag.url = UrlLinks.classicationApiUrl(tagName);
+                    tag.fetch({
+                        success: function(dataOrCollection, tagDetails) {
+                            that.collection.fullCollection.add(tagDetails);
+                            that.changeLoaderTextState(true);
+                        },
+                        cust_error: function(model, response) {
+                            that.tagsGenerator();
+                        }
+                    });
+                } else {
+                    this.tagsGenerator();
+                }
             },
             changeLoaderState: function(showLoader) {
                 if (showLoader) {
@@ -111,6 +137,13 @@
                     this.ui.tagTreeView.show();
                 }
             },
+            changeLoaderTextState: function(showLoader) {
+                if (showLoader) {
+                    this.ui.tagTreeTextLoader.show();
+                } else {
+                    this.ui.tagTreeTextLoader.hide();
+                }
+            },
             fetchCollections: function() {
                 this.changeLoaderState(true);
                 this.ui.refreshTag.attr("disabled", true);
@@ -123,6 +156,7 @@
                 this.query[this.viewType].tagName = this.tag;
                 if (options && options.viewType) {
                     this.viewType = options.viewType;
+                    this.changeLoaderTextState(false);
                 }
                 if (!this.createTag) {
                     this.setValues(true);
@@ -209,6 +243,7 @@
                                 return false;
                             }
                         });
+
                     }
                 }
             },
diff --git a/dashboardv3/public/js/main.js b/dashboardv3/public/js/main.js
index 1c7bf8c..a4165ae 100644
--- a/dashboardv3/public/js/main.js
+++ b/dashboardv3/public/js/main.js
@@ -234,7 +234,7 @@
     'select2'
 ], function(App, Router, Helper, CommonViewFunction, Globals, UrlLinks, VEntityList, VTagList, Enums) {
     var that = this;
-    this.asyncFetchCounter = 7 + (Enums.addOnEntities.length + 1);
+    this.asyncFetchCounter = 5 + (Enums.addOnEntities.length + 1);
     // entity
     this.entityDefCollection = new VEntityList();
     this.entityDefCollection.url = UrlLinks.entitiesDefApiUrl();
@@ -251,6 +251,7 @@
     this.metricCollection = new VTagList();
     this.metricCollection.url = UrlLinks.metricsApiUrl();
     this.metricCollection.modelAttrName = "data";
+    this.classificationAndMetricEvent = new Backbone.Wreqr.EventAggregator();
     // businessMetadata
     this.businessMetadataDefCollection = new VEntityList();
     this.businessMetadataDefCollection.url = UrlLinks.businessMetadataDefApiUrl();
@@ -262,6 +263,7 @@
         enumDefCollection: this.enumDefCollection,
         classificationDefCollection: this.classificationDefCollection,
         metricCollection: this.metricCollection,
+        classificationAndMetricEvent: this.classificationAndMetricEvent,
         businessMetadataDefCollection: this.businessMetadataDefCollection
     });
 
@@ -343,22 +345,25 @@
         }
     });
     this.classificationDefCollection.fetch({
+        async: true,
         complete: function() {
             that.classificationDefCollection.fullCollection.comparator = function(model) {
                 return model.get('name').toLowerCase();
             };
             that.classificationDefCollection.fullCollection.sort({ silent: true });
-            --that.asyncFetchCounter;
+            that.classificationAndMetricEvent.trigger("Classification:Count:Update");
+            //--that.asyncFetchCounter;
             startApp();
         }
     });
+    this.metricCollection.fetch({
+        async: true,
+        success: function() {
+            // that.classificationAndMetricEvent.trigger("metricCollection:Update");
+        },
+        complete: function() {}
+    });
 
-    this.metricCollection.fetch({
-        complete: function() {
-            --that.asyncFetchCounter;
-            startApp();
-        }
-    });
     this.businessMetadataDefCollection.fetch({
         complete: function() {
             that.businessMetadataDefCollection.fullCollection.comparator = function(model) {
@@ -369,7 +374,6 @@
             startApp();
         }
     });
-
     CommonViewFunction.fetchRootEntityAttributes({
         url: UrlLinks.rootEntityDefUrl(Enums.addOnEntities[0]),
         entity: Enums.addOnEntities,
@@ -378,7 +382,6 @@
             startApp();
         }
     });
-
     CommonViewFunction.fetchRootClassificationAttributes({
         url: UrlLinks.rootClassificationDefUrl(Enums.addOnClassification[0]),
         classification: Enums.addOnClassification,
diff --git a/dashboardv3/public/js/router/Router.js b/dashboardv3/public/js/router/Router.js
index 69f39f5..3cacd78 100644
--- a/dashboardv3/public/js/router/Router.js
+++ b/dashboardv3/public/js/router/Router.js
@@ -53,7 +53,7 @@
         initialize: function(options) {
             _.extend(
                 this,
-                _.pick(options, "entityDefCollection", "typeHeaders", "enumDefCollection", "classificationDefCollection", "metricCollection", "businessMetadataDefCollection")
+                _.pick(options, "entityDefCollection", "typeHeaders", "enumDefCollection", "classificationDefCollection", "metricCollection", "classificationAndMetricEvent", "businessMetadataDefCollection")
             );
             this.showRegions();
             this.bindCommonEvents();
@@ -72,6 +72,7 @@
                 classificationDefCollection: this.classificationDefCollection,
                 glossaryCollection: this.glossaryCollection,
                 metricCollection: this.metricCollection,
+                classificationAndMetricEvent: this.classificationAndMetricEvent,
                 businessMetadataDefCollection: this.businessMetadataDefCollection
             };
             this.ventObj = {
@@ -267,8 +268,9 @@
         },
         renderDefaultSearchLayoutView: function(opt) {
             var that = this;
-            require(["views/site/Header", "views/search/SearchDefaultLayoutView", "views/site/SideNavLayoutView"], function(Header, SearchDefaultLayoutView, SideNavLayoutView) {
+            require(["views/site/Header", "views/search/SearchDefaultLayoutView", "views/site/SideNavLayoutView", "collection/VTagList"], function(Header, SearchDefaultLayoutView, SideNavLayoutView, VTagList) {
                 var paramObj = Utils.getUrlState.getQueryParams();
+                tag = new VTagList();
                 if (paramObj && (paramObj.type || paramObj.tag || paramObj.term || paramObj.query || paramObj.udKeys || paramObj.udLabels) === undefined) {
                     Utils.setUrl({
                         url: "#!/search",
@@ -297,6 +299,7 @@
                         if (paramObj.tagFilters) {
                             paramObj.tagFilters = null;
                         }
+                        renderSearchView();
                     } else {
                         var tagValidate = paramObj.tag,
                             isTagPresent = false;
@@ -317,59 +320,78 @@
                                 }
                             });
                             if (!isTagPresent) {
-                                paramObj.tag = null;
+                                tag.url = UrlLinks.classificationDefApiUrl(tagValidate);
+                                tag.fetch({
+                                    success: function(tagCollection) {
+                                        isTagPresent = true;
+                                    },
+                                    cust_error: function(model, response) {
+                                        paramObj.tag = null;
+                                    },
+                                    complete: function() {
+                                        renderSearchView.call();
+                                    }
+                                });
+                            } else {
+                                renderSearchView();
                             }
+                        } else {
+                            renderSearchView();
                         }
                     }
+                } else {
+                    renderSearchView();
+                }
 
-                }
-                var isinitialView = true,
-                    isTypeTagNotExists = false,
-                    tempParam = _.extend({}, paramObj);
-                if (paramObj) {
-                    isinitialView =
-                        (
-                            paramObj.type ||
-                            (paramObj.dslChecked == "true" ? "" : paramObj.tag || paramObj.term) ||
-                            (paramObj.query ? paramObj.query.trim() : "")
-                        ).length === 0;
-                }
-                var options = _.extend({
-                        value: paramObj,
-                        initialView: isinitialView,
-                        fromDefaultSearch: opt ? (opt && !opt.fromSearchResultView) : true,
-                        fromSearchResultView: (opt && opt.fromSearchResultView) || false,
-                        fromCustomFilterView: (opt && opt.fromCustomFilterView) || false,
-                        isTypeTagNotExists: paramObj && (paramObj.type != tempParam.type || tempParam.tag != paramObj.tag)
-                    },
-                    that.preFetchedCollectionLists,
-                    that.sharedObj,
-                    that.ventObj
-                );
-                that.renderViewIfNotExists(
-                    that.getHeaderOptions(Header, {
-                        fromDefaultSearch: options.fromDefaultSearch
-                    })
-                );
-                that.renderViewIfNotExists({
-                    view: App.rSideNav,
-                    manualRender: function() {
-                        this.view.currentView.manualRender(options);
-                    },
-                    render: function() {
-                        return new SideNavLayoutView(options);
+                function renderSearchView() {
+                    var isinitialView = true,
+                        isTypeTagNotExists = false,
+                        tempParam = _.extend({}, paramObj);
+                    if (paramObj) {
+                        isinitialView =
+                            (
+                                paramObj.type ||
+                                (paramObj.dslChecked == "true" ? "" : paramObj.tag || paramObj.term) ||
+                                (paramObj.query ? paramObj.query.trim() : "")
+                            ).length === 0;
                     }
-                });
-                that.renderViewIfNotExists({
-                    view: App.rContent,
-                    viewName: "SearchDefaultlLayoutView",
-                    manualRender: function() {
-                        this.view.currentView.manualRender(options);
-                    },
-                    render: function() {
-                        return new SearchDefaultLayoutView(options);
-                    }
-                });
+                    var options = _.extend({
+                            value: paramObj,
+                            initialView: isinitialView,
+                            fromDefaultSearch: opt ? (opt && !opt.fromSearchResultView) : true,
+                            fromSearchResultView: (opt && opt.fromSearchResultView) || false,
+                            fromCustomFilterView: (opt && opt.fromCustomFilterView) || false,
+                            isTypeTagNotExists: paramObj && (paramObj.type != tempParam.type || tempParam.tag != paramObj.tag)
+                        },
+                        that.preFetchedCollectionLists,
+                        that.sharedObj,
+                        that.ventObj
+                    );
+                    that.renderViewIfNotExists(
+                        that.getHeaderOptions(Header, {
+                            fromDefaultSearch: options.fromDefaultSearch
+                        })
+                    );
+                    that.renderViewIfNotExists({
+                        view: App.rSideNav,
+                        manualRender: function() {
+                            this.view.currentView.manualRender(options);
+                        },
+                        render: function() {
+                            return new SideNavLayoutView(options);
+                        }
+                    });
+                    that.renderViewIfNotExists({
+                        view: App.rContent,
+                        viewName: "SearchDefaultlLayoutView",
+                        manualRender: function() {
+                            this.view.currentView.manualRender(options);
+                        },
+                        render: function() {
+                            return new SearchDefaultLayoutView(options);
+                        }
+                    });
+                }
             });
         },
         administrator: function() {
@@ -390,6 +412,25 @@
                 App.rContent.show(new AdministratorLayoutView(_.extend({ value: paramObj, guid: null }, options)));
             });
         },
+        devDebugging: function() {
+            var that = this;
+            require(["views/site/Header", "views/site/SideNavLayoutView", 'views/dev_debug/DevDebuggingLayoutView'], function(Header, SideNavLayoutView, DevDebuggingLayoutView) {
+                var paramObj = Utils.getUrlState.getQueryParams(),
+                    options = _.extend({}, that.preFetchedCollectionLists, that.sharedObj, that.ventObj);
+                that.renderViewIfNotExists(that.getHeaderOptions(Header));
+                that.renderViewIfNotExists({
+                    view: App.rSideNav,
+                    manualRender: function() {
+                        this.view.currentView.manualRender(options);
+                    },
+                    render: function() {
+                        return new SideNavLayoutView(options);
+                    }
+                });
+                App.rContent.show(new DevDebuggingLayoutView(options));
+            });
+        },
+
         businessMetadataDetailPage: function(guid) {
             var that = this;
             require(["views/site/Header", "views/site/SideNavLayoutView", "views/business_metadata/BusinessMetadataContainerLayoutView", ], function(Header, SideNavLayoutView, BusinessMetadataContainerLayoutView) {
diff --git a/dashboardv3/public/js/views/search/SearchLayoutView.js b/dashboardv3/public/js/views/search/SearchLayoutView.js
index c604d13..9a38256 100644
--- a/dashboardv3/public/js/views/search/SearchLayoutView.js
+++ b/dashboardv3/public/js/views/search/SearchLayoutView.js
@@ -93,7 +93,7 @@
             initialize: function(options) {
                 _.extend(this, _.pick(options, 'value', 'typeHeaders', 'searchVent', 'entityDefCollection', 'enumDefCollection', 'classificationDefCollection', 'searchTableColumns', 'searchTableFilters', 'metricCollection', 'onSubmit'));
                 this.type = "dsl";
-                this.entityCountObj = _.first(this.metricCollection.toJSON());
+                this.entityCountObj = _.first(this.metricCollection.toJSON()) || { entity: { entityActive: {}, entityDeleted: {} }, tag: { tagEntities: {} } };
                 this.filterTypeSelected = [];
                 var param = Utils.getUrlState.getQueryParams();
                 this.query = {
diff --git a/dashboardv3/public/js/views/search/tree/ClassificationTreeLayoutView.js b/dashboardv3/public/js/views/search/tree/ClassificationTreeLayoutView.js
index a1f3f3f..d23ddea 100644
--- a/dashboardv3/public/js/views/search/tree/ClassificationTreeLayoutView.js
+++ b/dashboardv3/public/js/views/search/tree/ClassificationTreeLayoutView.js
@@ -26,8 +26,9 @@
     "collection/VSearchList",
     "collection/VGlossaryList",
     "utils/Enums",
+    "collection/VTagList",
     "jstree"
-], function(require, ClassificationTreeLayoutViewTmpl, Utils, Messages, Globals, UrlLinks, CommonViewFunction, VSearchList, VGlossaryList, Enums) {
+], function(require, ClassificationTreeLayoutViewTmpl, Utils, Messages, Globals, UrlLinks, CommonViewFunction, VSearchList, VGlossaryList, Enums, VTagList) {
     "use strict";
 
     var ClassificationTreeLayoutView = Marionette.LayoutView.extend({
@@ -162,11 +163,30 @@
         },
         onRender: function() {
             this.changeLoaderState(true);
-            this.renderClassificationTree();
+            this.checkTagOnRefresh();
             this.createClassificationAction();
             this.ui.clearWildCard.addClass('hide-icon');
             this.changeLoaderState(false);
         },
+        checkTagOnRefresh: function() {
+            var that = this,
+                tagName = (this.options && this.options.value) ? this.options.value.tag : null,
+                presentTag = this.classificationDefCollection.fullCollection.findWhere({ name: tagName }),
+                tag = new VTagList();
+            if (!presentTag && tagName) {
+                tag.url = UrlLinks.classificationDefApiUrl(tagName);
+                tag.fetch({
+                    success: function(dataOrCollection, tagDetails) {
+                        that.classificationDefCollection.fullCollection.add(tagDetails);
+                    },
+                    cust_error: function(model, response) {
+                        that.renderClassificationTree();
+                    }
+                });
+            } else {
+                this.renderClassificationTree();
+            }
+        },
         changeLoaderState: function(showLoader) {
             if (showLoader) {
                 this.ui.classificationSearchTree.hide();
@@ -184,6 +204,7 @@
                 "reset add remove",
                 function() {
                     if (this.ui.classificationSearchTree.jstree(true)) {
+                        that.classificationTreeUpdate = true;
                         that.ui.classificationSearchTree.jstree(true).refresh();
                     } else {
                         this.renderClassificationTree();
@@ -442,7 +463,7 @@
                             var child = collection.find({
                                 name: name
                             });
-                            var tagEntityCount = that.entityCountObj.tag.tagEntities[name];
+                            var tagEntityCount = that.entityCountObj?that.entityCountObj.tag.tagEntities[name]:null;
                             var tagname = tagEntityCount ? name + " (" + _.numberFormatWithComma(tagEntityCount) + ")" : name;
 
                             if (that.options.value) {
@@ -483,10 +504,11 @@
                     return tagData;
                 }
             collection.each(function(model) {
-                var modelJSON = model.toJSON();
-                var name = modelJSON.name;
-                var tagEntityCount = that.entityCountObj.tag.tagEntities[name];
-                var tagname = tagEntityCount ? name + " (" + _.numberFormatWithComma(tagEntityCount) + ")" : name,
+                var modelJSON = model.toJSON(),
+                    name = modelJSON.name,
+                    tagEntityCount = that.entityCountObj?that.entityCountObj.tag.tagEntities[name]:null,
+                    tagname = tagEntityCount ? name + " (" + _.numberFormatWithComma(tagEntityCount) + ")" : name,
+                    isSelectedChildted = false,
                     isSelected = false;
 
                 if (that.options.value) {
@@ -540,22 +562,22 @@
         pushRootClassificationToJstree: function(data) {
             var that = this;
             _.each(Enums.addOnClassification, function(addOnClassification) {
-                var rootClassification = Globals[addOnClassification];
-                var isSelected = that.options.value && that.options.value.tag ? that.options.value.tag == rootClassification.name : false;
-                var rootClassificationNode = {
-                    text: _.escape(rootClassification.name),
-                    name: rootClassification.name,
-                    type: rootClassification.category,
-                    gType: "Classification",
-                    guid: rootClassification.guid,
-                    id: rootClassification.guid,
-                    model: rootClassification,
-                    children: [],
-                    icon: "fa fa-tag",
-                    state: {
-                        selected: isSelected
+                var rootClassification = Globals[addOnClassification],
+                    isSelected = (that.options.value && that.options.value.tag) ? that.options.value.tag == rootClassification.name : false,
+                    rootClassificationNode = {
+                        text: _.escape(rootClassification.name),
+                        name: rootClassification.name,
+                        type: rootClassification.category,
+                        gType: "Classification",
+                        guid: rootClassification.guid,
+                        id: rootClassification.guid,
+                        model: rootClassification,
+                        children: [],
+                        icon: "fa fa-tag",
+                        state: {
+                            selected: isSelected
+                        }
                     }
-                }
                 data.push(rootClassificationNode);
             });
             return data;
@@ -798,7 +820,7 @@
         onViewEditClassification: function() {
             var selectedNode = this.ui.classificationSearchTree.jstree("get_selected", true);
             if (selectedNode && selectedNode[0]) {
-                var url = "#!/tag/tagAttribute/" + selectedNode[0].original.name;
+                var url = "#!/tag/tagAttribute/" + selectedNode[0].original.name + "?tag=" + selectedNode[0].original.name;
                 this.onClassificationUpdate(url);
             }
         },
diff --git a/dashboardv3/public/js/views/search/tree/CustomFilterTreeLayoutView.js b/dashboardv3/public/js/views/search/tree/CustomFilterTreeLayoutView.js
index ac70024..d7106d6 100644
--- a/dashboardv3/public/js/views/search/tree/CustomFilterTreeLayoutView.js
+++ b/dashboardv3/public/js/views/search/tree/CustomFilterTreeLayoutView.js
@@ -17,39 +17,40 @@
  */
 define([
     "require",
-    "hbs!tmpl/search/tree/CustomFilterTreeLayoutView_tmpl",
+    "hbs!tmpl/search/tree/EntityTreeLayoutView_tmpl",
     "utils/Utils",
-    "utils/Messages",
     "utils/Globals",
     "utils/UrlLinks",
     "utils/CommonViewFunction",
     "collection/VSearchList",
     "collection/VGlossaryList",
+    'utils/Enums',
     "jstree"
-], function(require, CustomFilterTreeLayoutViewTmpl, Utils, Messages, Globals, UrlLinks, CommonViewFunction, VSearchList, VGlossaryList) {
+], function(require, EntityLayoutViewTmpl, Utils, Globals, UrlLinks, CommonViewFunction, VSearchList, VGlossaryList, Enums) {
     "use strict";
 
-    var CustomFilterTreeLayoutView = Marionette.LayoutView.extend({
+    var EntityTreeLayoutview = Marionette.LayoutView.extend({
+        template: EntityLayoutViewTmpl,
 
-        _viewName: 'CustomFilterTreeLayoutView',
-
-        template: CustomFilterTreeLayoutViewTmpl,
-
-        regions: {
-
-            RSaveSearchBasic: '[data-id="r_saveSearchBasic"]'
-        },
+        regions: {},
         ui: {
             //refresh
             refreshTree: '[data-id="refreshTree"]',
             groupOrFlatTree: '[data-id="groupOrFlatTreeView"]',
-            customFilterSearchTree: '[data-id="customFilterSearchTree"]',
-            showCustomFilter: '[data-id="showCustomFilter"]',
-            customFilterTreeLoader: '[data-id="customFilterTreeLoader"]'
+
+            // tree el
+            entitySearchTree: '[data-id="entitySearchTree"]',
+
+            // Show/hide empty values in tree
+            showEmptyServiceType: '[data-id="showEmptyServiceType"]',
+            entityTreeLoader: '[data-id="entityTreeLoader"]',
+            importBusinessMetadata: "[data-id='importBusinessMetadata']",
+            downloadBusinessMetadata: "[data-id='downloadBusinessMetadata']"
         },
         templateHelpers: function() {
             return {
-                apiBaseUrl: UrlLinks.apiBaseUrl
+                apiBaseUrl: UrlLinks.apiBaseUrl,
+                importTmplUrl: UrlLinks.businessMetadataImportTempUrl()
             };
         },
         events: function() {
@@ -57,62 +58,69 @@
                 that = this;
             events["click " + this.ui.refreshTree] = function(e) {
                 that.changeLoaderState(true);
-                that.ui.refreshTree.attr("disabled", true).tooltip("hide");
+                this.ui.refreshTree.attr("disabled", true).tooltip("hide");
                 var type = $(e.currentTarget).data("type");
                 e.stopPropagation();
-                that.refreshCustomFilterTree();
+                that.ui[type + "SearchTree"].jstree(true).destroy();
+                that.refresh({ type: type });
             };
-            events["click " + this.ui.showCustomFilter] = function(e) {
-                that.isBasic = !that.isBasic;
-                this.customFilterSwitchBtnUpdate();
+
+            // show and hide entities and classifications with 0 numbers
+            events["click " + this.ui.showEmptyServiceType] = function(e) {
+                e.stopPropagation();
+                this.isEmptyServicetype = !this.isEmptyServicetype;
+                this.entitySwitchBtnUpdate();
             };
+            // refresh individual tree
             events["click " + this.ui.groupOrFlatTree] = function(e) {
-                that.changeLoaderState(true);
                 var type = $(e.currentTarget).data("type");
                 e.stopPropagation();
                 this.isGroupView = !this.isGroupView;
-                this.ui.groupOrFlatTree.attr("data-original-title", (this.isGroupView ? "Show all" : "Show type"));
                 this.ui.groupOrFlatTree.tooltip('hide');
-                this.ui.groupOrFlatTree.find("i").toggleClass("group-tree-deactivate");
+                this.ui.groupOrFlatTree.find("i").toggleClass("fa-sitemap fa-list-ul");
                 this.ui.groupOrFlatTree.find("span").html(this.isGroupView ? "Show flat tree" : "Show group tree");
                 that.ui[type + "SearchTree"].jstree(true).destroy();
-                that.fetchCustomFilter();
+                that.renderEntityTree();
+            };
+            events["click " + this.ui.importBusinessMetadata] = function(e) {
+                e.stopPropagation();
+                that.onClickImportBusinessMetadata();
+            };
+            events["click " + this.ui.downloadBusinessMetadata] = function(e) {
+                e.stopPropagation();
             };
 
             return events;
         },
         bindEvents: function() {
             var that = this;
-            this.listenTo(
-                this.saveSearchBaiscCollection.fullCollection,
-                "reset add change remove",
-                function() {
-                    if (this.ui.customFilterSearchTree.jstree(true)) {
-                        this.ui.customFilterSearchTree.jstree(true).refresh();
-                    } else {
-                        this.renderCustomFilterTree();
-                    }
-                },
-                this
-            );
-            this.listenTo(
-                this.saveSearchAdvanceCollection.fullCollection,
-                "reset add change remove",
-                function() {
-                    if (this.ui.customFilterSearchTree.jstree(true)) {
-                        this.ui.customFilterSearchTree.jstree(true).refresh();
-                    } else {
-                        this.renderCustomFilterTree();
-                    }
-                },
-                this
-            );
-            this.searchVent.on("Save:Filter", function(data) {
-                that.saveAs();
-            })
-            $('body').on('click', '.customFilterPopoverOptions li', function(e) {
-                that.$('.customFilterPopoverOptions').popover('hide');
-                that[$(this).find('a').data('fn') + "CustomFilter"](e)
+            $('body').on('click', '.entityPopoverOptions li', function(e) {
+                that.$('.entityPopover').popover('hide');
+                that[$(this).find('a').data('fn') + "Entity"](e)
+            });
+            this.searchVent.on("Entity:Count:Update", function(options) {
+                that.changeLoaderState(true);
+                var opt = options || {};
+                if (opt && !opt.metricData) {
+                    that.metricCollection.fetch({
+                        complete: function() {
+                            that.entityCountObj = _.first(that.metricCollection.toJSON());
+                            that.fromManualRender = true;
+                            that.ui.entitySearchTree.jstree(true).refresh();
+                            that.changeLoaderState(false);
+                        }
+                    });
+                } else {
+                    that.entityCountObj = opt.metricData;
+                    that.ui.entitySearchTree.jstree(true).refresh();
+                    that.changeLoaderState(false);
+                }
+            });
+            this.classificationAndMetricEvent.on("metricCollection:Update", function(options) {
+                that.changeLoaderState(true);
+                that.ui.refreshTree.attr("disabled", true).tooltip("hide");
+                that.ui["entitySearchTree"].jstree(true).destroy();
+                that.refresh({ type: "entity", apiCount: 0 });
             });
         },
         initialize: function(options) {
@@ -128,84 +136,338 @@
                     "classificationDefCollection",
                     "searchTableColumns",
                     "searchTableFilters",
-                    "metricCollection"
+                    "metricCollection",
+                    "classificationAndMetricEvent"
                 )
             );
-            this.saveSearchBaiscCollection = new VSearchList();
-            this.saveSearchCollection = new VSearchList();
-            this.saveSearchAdvanceCollection = new VSearchList();
-            this.saveSearchCollection.url = UrlLinks.saveSearchApiUrl();
-            this.saveSearchBaiscCollection.fullCollection.comparator = function(model) {
-                return getModelName(model);
-            }
-            this.saveSearchAdvanceCollection.fullCollection.comparator = function(model) {
-                return getModelName(model);
-            }
-
-            function getModelName(model) {
-                if (model.get('name')) {
-                    return model.get('name').toLowerCase();
-                }
-            };
             this.bindEvents();
-            this.customFilterData = null;
-            this.isBasic = true;
-            this.customFilterId = null;
+            this.entityCountObj = _.first(this.metricCollection.toJSON()) || { entity: { entityActive: {}, entityDeleted: {} }, tag: { tagEntities: {} } };
+            this.isEmptyServicetype = true;
+            this.entityTreeData = {};
+            this.typeId = null;
             this.isGroupView = true;
         },
         onRender: function() {
             this.changeLoaderState(true);
-            this.fetchCustomFilter();
+            this.renderEntityTree();
+            this.createEntityAction();
+            this.changeLoaderState(false);
         },
         changeLoaderState: function(showLoader) {
             if (showLoader) {
-                this.ui.customFilterSearchTree.hide();
-                this.ui.customFilterTreeLoader.show();
+                this.ui.entitySearchTree.hide();
+                this.ui.entityTreeLoader.show();
             } else {
-                this.ui.customFilterSearchTree.show();
-                this.ui.customFilterTreeLoader.hide();
+                this.ui.entitySearchTree.show();
+                this.ui.entityTreeLoader.hide();
             }
         },
+        createEntityAction: function() {
+            var that = this;
+            Utils.generatePopover({
+                el: this.$el,
+                contentClass: 'entityPopoverOptions',
+                popoverOptions: {
+                    selector: '.entityPopover',
+                    content: function() {
+                        var type = $(this).data('detail'),
+                            liString = "<li><i class='fa fa-search'></i><a href='javascript:void(0)' data-fn='onSelectedSearch'>Search</a></li>"
+                        return "<ul>" + liString + "</ul>";
+                    }
+                }
+            });
+        },
+        renderEntityTree: function() {
+            var that = this;
+            this.generateSearchTree({
+                $el: that.ui.entitySearchTree
+            });
+        },
+        onSearchEntityNode: function(showEmptyType) {
+            // on tree search by text, searches for all entity node, called by searchfilterBrowserLayoutView.js
+            this.isEmptyServicetype = showEmptyType;
+            this.entitySwitchBtnUpdate();
+        },
+        entitySwitchBtnUpdate: function() {
+            this.ui.showEmptyServiceType.attr("data-original-title", (this.isEmptyServicetype ? "Show" : "Hide") + " empty service types");
+            this.ui.showEmptyServiceType.tooltip('hide');
+            this.ui.showEmptyServiceType.find("i").toggleClass("fa-toggle-on fa-toggle-off");
+            this.ui.entitySearchTree.jstree(true).refresh();
+        },
         manualRender: function(options) {
+            var that = this;
             _.extend(this.options, options);
-
             if (this.options.value === undefined) {
                 this.options.value = {};
             }
-            if (!this.options.value.isCF) {
-                this.ui.customFilterSearchTree.jstree(true).deselect_all();
-                this.customFilterId = null;
+            if (!this.options.value.type) {
+                this.ui.entitySearchTree.jstree(true).deselect_all();
+                this.typeId = null;
+            } else {
+                if (that.options.value.type === "_ALL_ENTITY_TYPES" && this.typeId !== "_ALL_ENTITY_TYPES") {
+                    this.fromManualRender = true;
+                    if (this.typeId) {
+                        this.ui.entitySearchTree.jstree(true).deselect_node(this.typeId);
+                    }
+                    this.typeId = Globals[that.options.value.type].guid;
+                    this.ui.entitySearchTree.jstree(true).select_node(this.typeId);
+                } else if (this.typeId !== "_ALL_ENTITY_TYPES" && that.options.value.type !== this.typeId) {
+                    var dataFound = this.typeHeaders.fullCollection.find(function(obj) {
+                        return obj.get("name") === that.options.value.type
+                    });
+                    if (dataFound) {
+                        if ((this.typeId && this.typeId !== dataFound.get("guid")) || this.typeId === null) {
+                            if (this.typeId) {
+                                this.ui.entitySearchTree.jstree(true).deselect_node(this.typeId);
+                            }
+                            this.fromManualRender = true;
+                            this.typeId = dataFound.get("guid");
+                            this.ui.entitySearchTree.jstree(true).select_node(dataFound.get("guid"));
+                        }
+                    }
+                }
             }
+        },
+        onNodeSelect: function(options) {
+            var that = this,
+                type,
+                name = options.node.original.name,
+                selectedNodeId = options.node.id,
+                typeValue = null,
+                params = {
+                    searchType: "basic",
+                    dslChecked: false
+                };
+            if (this.options.value) {
+                if (this.options.value.type) {
+                    params["type"] = this.options.value.type;
+                }
+                if (this.options.value.isCF) {
+                    this.options.value.isCF = null;
+                }
+                if (this.options.value.entityFilters) {
+                    params["entityFilters"] = null;
+                }
+            }
+            var getUrl = Utils.getUrlState.isSearchTab();
+            if (!getUrl) { that.typeId = null; }
+            if (that.typeId != selectedNodeId) {
+                that.typeId = selectedNodeId;
+                typeValue = name;
+                params['type'] = typeValue;
+            } else {
+                that.typeId = params["type"] = null;
+                that.ui.entitySearchTree.jstree(true).deselect_all(true);
+                if (!that.options.value.type && !that.options.value.tag && !that.options.value.term && !that.options.value.query && !this.options.value.udKeys && !this.options.value.ugLabels) {
+                    that.showDefaultPage();
+                    return;
+                }
+            }
+            var searchParam = _.extend({}, this.options.value, params);
+            this.triggerSearch(searchParam);
+        },
+        showDefaultPage: function() {
+            Utils.setUrl({
+                url: '!/search',
+                mergeBrowserUrl: false,
+                trigger: true,
+                updateTabState: true
+            });
+        },
+        triggerSearch: function(params, url) {
+            var serachUrl = url ? url : '#!/search/searchResult';
+            Utils.setUrl({
+                url: serachUrl,
+                urlParams: params,
+                mergeBrowserUrl: false,
+                trigger: true,
+                updateTabState: true
+            });
+        },
+        onSelectedSearchEntity: function() {
+            var params = {
+                searchType: "basic",
+                dslChecked: false,
+                type: this.options.value.type
+            };
+            this.triggerSearch(params);
+        },
+        getEntityTree: function() {
+            var that = this,
+                serviceTypeArr = [],
+                serviceTypeWithEmptyEntity = [],
+                type = "ENTITY",
+                entityTreeContainer = this.ui.entitytreeStructure,
+                generateTreeData = function(data) {
+                    that.typeHeaders.fullCollection.each(function(model) {
+                        var totalCount = 0,
+                            serviceType = model.toJSON().serviceType,
+                            isSelected = false,
+                            categoryType = model.toJSON().category,
+                            generateServiceTypeArr = function(entityCountArr, serviceType, children, entityCount) {
+                                if (that.isGroupView) {
+                                    if (entityCountArr[serviceType]) {
+                                        entityCountArr[serviceType]["children"].push(children);
+                                        entityCountArr[serviceType]["totalCounter"] = +entityCountArr[serviceType]["totalCounter"] + entityCount;
+                                    } else {
+                                        entityCountArr[serviceType] = [];
+                                        entityCountArr[serviceType]["name"] = serviceType;
+                                        entityCountArr[serviceType]["children"] = [];
+                                        entityCountArr[serviceType]["children"].push(children);
+                                        entityCountArr[serviceType]["totalCounter"] = entityCount;
+                                    }
+                                } else {
+                                    entityCountArr.push(children)
+                                }
+                            };
+                        if (!serviceType) {
+                            serviceType = "other_types";
+                        }
+                        if (categoryType == "ENTITY") {
+                            var entityCount = that.entityCountObj ?
+                                (that.entityCountObj.entity.entityActive[model.get("name")] || 0) +
+                                (that.entityCountObj.entity.entityDeleted[model.get("name")] || 0) : 0,
+                                modelname = entityCount ? model.get("name") + " (" + _.numberFormatWithComma(entityCount) + ")" : model.get("name");
+                            if (that.options.value) {
+                                isSelected = that.options.value.type ? that.options.value.type == model.get("name") : false;
+                                if (!that.typeId) {
+                                    that.typeId = isSelected ? model.get("guid") : null;
+                                }
+                            }
 
-        },
-        renderCustomFilterTree: function() {
-            this.generateCustomFilterTree({
-                $el: this.ui.customFilterSearchTree
-            });
-            this.createCustomFilterAction();
-        },
-        fetchCustomFilter: function() {
-            var that = this;
-            this.saveSearchCollection.fetch({
-                success: function(collection, data) {
-                    that.saveSearchBaiscCollection.fullCollection.reset(_.where(data, { searchType: "BASIC" }));
-                    that.saveSearchAdvanceCollection.fullCollection.reset(_.where(data, { searchType: "ADVANCED" }));
-                    that.changeLoaderState(false);
-                    that.ui.refreshTree.attr("disabled", false);
+                            var children = {
+                                text: _.escape(modelname),
+                                name: model.get("name"),
+                                type: model.get("category"),
+                                gType: "Entity",
+                                guid: model.get("guid"),
+                                id: model.get("guid"),
+                                model: model,
+                                parent: "#",
+                                icon: "fa fa-file-o",
+                                state: {
+                                    disabled: false,
+                                    selected: isSelected
+                                },
+                            };
+
+                            entityCount = _.isNaN(entityCount) ? 0 : entityCount;
+                            generateServiceTypeArr(serviceTypeArr, serviceType, children, entityCount);
+                            if (entityCount) {
+                                generateServiceTypeArr(serviceTypeWithEmptyEntity, serviceType, children, entityCount);
+                            }
+                        }
+                    });
+
+                    var serviceTypeData = that.isEmptyServicetype ? serviceTypeWithEmptyEntity : serviceTypeArr;
+                    if (that.isGroupView) {
+                        var serviceDataWithRootEntity = pushRootEntityToJstree.call(that, 'group', serviceTypeData);
+                        return getParentsData.call(that, serviceDataWithRootEntity);
+                    } else {
+                        return pushRootEntityToJstree.call(that, null, serviceTypeData);
+                    }
                 },
-                silent: true
-            });
+                pushRootEntityToJstree = function(type, data) {
+                    var rootEntity = Globals[Enums.addOnEntities[0]];
+                    var isSelected = this.options.value && this.options.value.type ? this.options.value.type == rootEntity.name : false;
+                    var rootEntityNode = {
+                        text: _.escape(rootEntity.name),
+                        name: rootEntity.name,
+                        type: rootEntity.category,
+                        gType: "Entity",
+                        guid: rootEntity.guid,
+                        id: rootEntity.guid,
+                        model: rootEntity,
+                        parent: "#",
+                        icon: "fa fa-file-o",
+                        state: {
+                            // disabled: entityCount == 0 ? true : false,
+                            selected: isSelected
+                        },
+                    };
+                    if (type === 'group') {
+                        if (data.other_types === undefined) {
+                            data.other_types = { name: "other_types", children: [] };
+                        }
+                        data.other_types.children.push(rootEntityNode);
+                    } else {
+                        data.push(rootEntityNode);
+                    }
+                    return data;
+                },
+                getParentsData = function(data) {
+                    var parents = Object.keys(data),
+                        treeData = [],
+                        withoutEmptyServiceType = [],
+                        treeCoreData = null,
+                        openEntityNodesState = function(treeDate) {
+                            if (treeDate.length == 1) {
+                                _.each(treeDate, function(model) {
+                                    model.state = { opened: true }
+                                })
+                            }
+                        },
+                        generateNode = function(children) {
+                            var nodeStructure = {
+                                text: "Service Types",
+                                children: children,
+                                icon: "fa fa-folder-o",
+                                type: "ENTITY",
+                                state: { opened: true },
+                                parent: "#"
+                            }
+                            return nodeStructure;
+                        };
+                    for (var i = 0; i < parents.length; i++) {
+
+                        var checkEmptyServiceType = false,
+                            getParrent = data[parents[i]],
+                            totalCounter = getParrent.totalCounter,
+                            textName = getParrent.totalCounter ? parents[i] + " (" + _.numberFormatWithComma(totalCounter) + ")" : parents[i],
+                            parent = {
+                                icon: "fa fa-folder-o",
+                                type: type,
+                                gType: "ServiceType",
+                                children: getParrent.children,
+                                text: _.escape(textName),
+                                name: data[parents[i]].name,
+                                id: i,
+                                state: { opened: true }
+                            };
+                        if (that.isEmptyServicetype) {
+                            if (data[parents[i]].totalCounter == 0) {
+                                checkEmptyServiceType = true;
+                            }
+                        }
+                        treeData.push(parent);
+                        if (!checkEmptyServiceType) {
+                            withoutEmptyServiceType.push(parent);
+                        }
+                    }
+                    that.entityTreeData = {
+                        withoutEmptyServiceTypeEntity: generateNode(withoutEmptyServiceType),
+                        withEmptyServiceTypeEntity: generateNode(treeData)
+                    };
+
+                    treeCoreData = that.isEmptyServicetype ? withoutEmptyServiceType : treeData;
+
+                    openEntityNodesState(treeCoreData);
+                    return treeCoreData;
+                };
+            return generateTreeData();
         },
-        generateCustomFilterTree: function(options) {
+        generateSearchTree: function(options) {
             var $el = options && options.$el,
+                data = options && options.data,
+                type = options && options.type,
                 that = this,
                 getEntityTreeConfig = function(opt) {
                     return {
                         plugins: ["search", "core", "sort", "conditionalselect", "changed", "wholerow", "node_customize"],
                         conditionalselect: function(node) {
                             var type = node.original.type;
-                            if (type == "customFilterFolder") {
-                                if (node.children.length) {
+                            if (type == "ENTITY" || type == "GLOSSARY") {
+                                if (node.children.length || type == "GLOSSARY") {
                                     return false;
                                 } else {
                                     return true;
@@ -221,10 +483,10 @@
                         },
                         node_customize: {
                             default: function(el) {
-                                var aFilter = $(el).find(">a.jstree-anchor");
-                                aFilter.append("<span class='tree-tooltip'>" + _.escape(aFilter.text()) + "</span>");
+                                var aType = $(el).find(">a.jstree-anchor");
+                                aType.append("<span class='tree-tooltip'>" + aType.text() + "</span>");
                                 if ($(el).find(".fa-ellipsis-h").length === 0) {
-                                    $(el).append('<div class="tools"><i class="fa fa-ellipsis-h customFilterPopover" rel="popover"></i></div>');
+                                    $(el).append('<div class="tools"><i class="fa fa-ellipsis-h entityPopover" rel="popover"></i></div>');
                                 }
                             }
                         },
@@ -232,7 +494,9 @@
                             multiple: false,
                             data: function(node, cb) {
                                 if (node.id === "#") {
-                                    cb(that.getCustomFilterTree());
+                                    cb(
+                                        that.getEntityTree()
+                                    );
                                 }
                             }
                         }
@@ -246,7 +510,11 @@
             ).on("open_node.jstree", function(e, data) {
                 that.isTreeOpen = true;
             }).on("select_node.jstree", function(e, data) {
-                that.onNodeSelect(data);
+                if (!that.fromManualRender) {
+                    that.onNodeSelect(data);
+                } else {
+                    that.fromManualRender = false;
+                }
             }).on("search.jstree", function(nodes, str, res) {
                 if (str.nodes.length === 0) {
                     $el.jstree(true).hide_all();
@@ -255,13 +523,13 @@
                     $el.parents(".panel").removeClass("hide");
                 }
             }).on("hover_node.jstree", function(nodes, str, res) {
-                var aFilter = that.$("#" + str.node.a_attr.id),
-                    filterOffset = aFilter.find(">.jstree-icon").offset();
+                var aType = that.$("#" + str.node.a_attr.id),
+                    typeOffset = aType.find(">.jstree-icon").offset();
                 that.$(".tree-tooltip").removeClass("show");
                 setTimeout(function() {
-                    if (aFilter.hasClass("jstree-hovered") && filterOffset.top && filterOffset.left) {
-                        aFilter.find(">span.tree-tooltip").css({
-                            top: "calc(" + filterOffset.top + "px - 45px)",
+                    if (aType.hasClass("jstree-hovered") && typeOffset.top && typeOffset.left) {
+                        aType.find(">span.tree-tooltip").css({
+                            top: "calc(" + typeOffset.top + "px - 45px)",
                             left: "24px"
                         }).addClass("show");
                     }
@@ -270,231 +538,61 @@
                 that.$(".tree-tooltip").removeClass("show");
             });
         },
-        createCustomFilterAction: function() {
-            var that = this;
-            Utils.generatePopover({
-                el: this.$el,
-                contentClass: 'customFilterPopoverOptions',
-                popoverOptions: {
-                    selector: '.customFilterPopover',
-                    content: function() {
-                        var type = $(this).data('detail'),
-                            liString = "";
-                        liString = "<li data-type=" + type + " class='listTerm'><i class='fa fa-pencil'></i><a href='javascript:void(0)' data-fn='rename'>Rename</a></li>" +
-                            "<li data-type=" + type + " class='listTerm'><i class='fa fa-trash-o'></i><a href='javascript:void(0)' data-fn='delete'>Delete</a></li>"
-
-                        return "<ul>" + liString + "</ul>";
-                    }
-                }
-            });
-        },
-        customFilterSwitchBtnUpdate: function() {
+        refresh: function(options) {
             var that = this,
-                getTreeData, displayText;
-            that.ui.showCustomFilter.attr("data-original-title", (that.isBasic ? "Show Advanced search" : "Show Basic search"));
-            that.ui.showCustomFilter.tooltip('hide');
-            that.ui.showCustomFilter.find("i").toggleClass("switch-button");
-            that.ui.customFilterSearchTree.jstree(true).refresh();
-        },
-        getCustomFilterTree: function(options) {
-            var that = this,
-                customFilterBasicList = [],
-                customFilterAdvanceList = [],
-                allCustomFilter = [],
-                customFilterBasicTreeData = that.saveSearchBaiscCollection.fullCollection.models,
-                customFilterAdvanceTreeData = that.saveSearchAdvanceCollection.fullCollection.models,
-                openClassificationNodesState = function(treeDate) {
-                    if (treeDate.length == 1) {
-                        _.each(treeDate, function(model) {
-                            model.state['opeaned'] = true;
-                        })
+                apiCount = (options && options.apiCount == 0) ? options.apiCount : 3,
+                renderTree = function() {
+                    if (apiCount === 0) {
+                        that.renderEntityTree();
+                        that.changeLoaderState(false);
+                        that.ui.refreshTree.attr("disabled", false);
                     }
-                },
-                generateNode = function(nodeOptions) {
-                    var searchType = nodeOptions.get('searchType');
-                    var nodeStructure = {
-                        text: _.escape(nodeOptions.get('name')),
-                        name: _.escape(nodeOptions.get('name')),
-                        type: "customFilter",
-                        id: nodeOptions.get('guid'),
-                        icon: (searchType === 'BASIC' ? "fa fa-circle-thin basic-tree" : "fa fa-circle-thin advance-tree"),
-                        gType: "CustomFilter",
-                        model: nodeOptions
-                    }
-                    return nodeStructure;
-
-                }
-            that.customFilterId = null;
-            _.each(customFilterBasicTreeData, function(filterNode) {
-                customFilterBasicList.push(generateNode(filterNode));
-                allCustomFilter.push(generateNode(filterNode));
-            });
-            _.each(customFilterAdvanceTreeData, function(filterNode) {
-                customFilterAdvanceList.push(generateNode(filterNode));
-                allCustomFilter.push(generateNode(filterNode));
-            });
-
-            var treeView = [{
-                icon: "fa fa-folder-o",
-                gType: "customFilter",
-                type: "customFilterFolder",
-                children: customFilterBasicList,
-                text: "Basic Search",
-                name: "Basic Search",
-                state: { opened: true }
-            }, {
-                icon: "fa fa-folder-o",
-                gType: "customFilter",
-                type: "customFilterFolder",
-                children: customFilterAdvanceList,
-                text: "Advance Search",
-                name: "Advance Search",
-                state: { opened: true }
-            }];
-            var customFilterList = that.isGroupView ? treeView : allCustomFilter;
-            return customFilterList;
-        },
-        onNodeSelect: function(nodeData) {
-            var that = this,
-                options = nodeData.node.original,
-                selectedNodeId = options.id;
-            if (that.customFilterId != selectedNodeId) {
-                that.customFilterId = selectedNodeId;
-                if (options && options.model) {
-                    var searchParameters = options.model.get('searchParameters'),
-                        searchType = options.model.get('searchType'),
-                        params = CommonViewFunction.generateUrlFromSaveSearchObject({
-                            value: { "searchParameters": searchParameters },
-                            classificationDefCollection: that.classificationDefCollection,
-                            entityDefCollection: that.entityDefCollection
-                        });
-                    searchType === 'ADVANCED' ? that.isBasic = false : that.isBasic = true;
-                    _.extend({}, this.options.value, params);
-                    // Utils.notifyInfo({
-                    //     content: "Saved values are selected."
-                    // })
-
-                    Utils.setUrl({
-                        url: '#!/search/searchResult',
-                        urlParams: _.extend({}, { 'searchType': that.isBasic ? 'basic' : 'dsl', 'isCF': true }, params),
-                        mergeBrowserUrl: false,
-                        trigger: true,
-                        updateTabState: true
-                    });
-                }
-
+                };
+            if (apiCount == 0) {
+                that.entityDefCollection.fullCollection.sort({ silent: true });
+                that.entityCountObj = _.first(that.metricCollection.toJSON());
+                that.typeHeaders.fullCollection.sort({ silent: true });
+                renderTree();
             } else {
-                that.customFilterId = null;
-                that.ui.customFilterSearchTree.jstree(true).deselect_all(true);
-                that.showDefaultPage();
-            }
-        },
-        showDefaultPage: function() {
-            Utils.setUrl({
-                url: '#!/search',
-                mergeBrowserUrl: false,
-                trigger: true,
-                updateTabState: true
-            });
-        },
-        getValue: function() {
-            return this.options.value;
-        },
-        callSaveModalLayoutView: function(options) {
-            require([
-                'views/search/save/SaveModalLayoutView'
-            ], function(SaveModalLayoutView) {
-                new SaveModalLayoutView(options);
-            });
-        },
-        renameCustomFilter: function(opt) {
-            var that = this,
-                selectednode = that.ui.customFilterSearchTree.jstree("get_selected", true),
-                options = selectednode[0].original;
-            if (options && options.model.attributes) {
-                var that = this;
-                require([
-                    'views/search/save/SaveModalLayoutView'
-                ], function(SaveModalLayoutView) {
-                    new SaveModalLayoutView({ 'rename': true, 'selectedModel': options.model.clone(), 'collection': that.isBasic ? that.saveSearchBaiscCollection.fullCollection : that.saveSearchAdvanceCollection.fullCollection, 'getValue': that.getValue, 'isBasic': that.isBasic });
-                });
-            }
-        },
-        deleteCustomFilter: function(opt) {
-            var that = this,
-                selectednode = that.ui.customFilterSearchTree.jstree("get_selected", true),
-                options = selectednode[0].original;
-            if (options && options.model) {
-                var that = this;
-                var notifyObj = {
-                    modal: true,
-                    html: true,
-                    text: Messages.conformation.deleteMessage + "<b>" + _.escape(options.model.get('name')) + "</b>" + " ?",
-                    ok: function(obj) {
-                        that.notificationModal = obj;
-                        obj.showButtonLoader();
-                        that.onDeleteNotifyOk(options);
-                    },
-                    okCloses: false,
-                    cancel: function(argument) {}
-                }
-                Utils.notifyConfirm(notifyObj);
-            }
-        },
-        onDeleteNotifyOk: function(options) {
-            var that = this;
-            options.model.urlRoot = UrlLinks.saveSearchApiUrl();
-            if (options.model) {
-                options.model.id = options.model.get("guid");
-                options.model.idAttribute = "guid";
-                options.model.destroy({
-                    wait: true,
-                    success: function(model, data) {
-                        that.showDefaultPage();
-                        Utils.notifySuccess({
-                            content: options.model.attributes.name + Messages.getAbbreviationMsg(false, 'deleteSuccessMessage')
-                        });
-                    },
+                this.entityDefCollection.fetch({
                     complete: function() {
-                        that.notificationModal.hideButtonLoader();
-                        that.notificationModal.remove();
+                        that.entityDefCollection.fullCollection.comparator = function(model) {
+                            return model.get('name').toLowerCase();
+                        };
+                        that.entityDefCollection.fullCollection.sort({ silent: true });
+                        --apiCount;
+                        renderTree();
                     }
                 });
-            } else {
-                Utils.notifyError({
-                    content: Messages.defaultErrorMessage
-                });
-            }
-        },
-        saveAs: function(e) {
-            var value = this.getValue();
-            if (value && (value.type || value.tag || value.query || value.term)) {
-                value.searchType == "basic" ? this.isBasic = true : this.isBasic = false;
-                var urlObj = Utils.getUrlState.getQueryParams();
-                if (urlObj) {
-                    // includeDE value in because we need to send "true","false" to the server.
-                    urlObj.includeDE = urlObj.includeDE == "true" ? true : false;
-                    urlObj.excludeSC = urlObj.excludeSC == "true" ? true : false;
-                    urlObj.excludeST = urlObj.excludeST == "true" ? true : false;
-                }
-                this.customFilterSwitchBtnUpdate();
-                this.callSaveModalLayoutView({
-                    'collection': this.isBasic ? this.saveSearchBaiscCollection.fullCollection : this.saveSearchAdvanceCollection.fullCollection,
-                    getValue: function() {
-                        return _.extend({}, value, urlObj);
-                    },
-                    'isBasic': this.isBasic
-                });
-            } else {
-                Utils.notifyInfo({
-                    content: Messages.search.favoriteSearch.notSelectedSearchFilter
-                })
-            }
-        },
-        refreshCustomFilterTree: function() {
-            this.fetchCustomFilter();
-        }
 
+                this.metricCollection.fetch({
+                    complete: function() {
+                        --apiCount;
+                        that.entityCountObj = _.first(that.metricCollection.toJSON());
+                        renderTree();
+                    }
+                });
+
+                this.typeHeaders.fetch({
+                    complete: function() {
+                        that.typeHeaders.fullCollection.comparator = function(model) {
+                            return model.get('name').toLowerCase();
+                        }
+                        that.typeHeaders.fullCollection.sort({ silent: true });
+                        --apiCount;
+                        renderTree();
+                    }
+                });
+            }
+        },
+        onClickImportBusinessMetadata: function() {
+            var that = this;
+            require([
+                'views/import/ImportLayoutView'
+            ], function(ImportLayoutView) {
+                var view = new ImportLayoutView({});
+            });
+        }
     });
-    return CustomFilterTreeLayoutView;
+    return EntityTreeLayoutview;
 });
\ No newline at end of file