Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let sourceType = params.data.sourceType && params.data.sourceType.toLowerCase();
if (!sourceType || sourceType === 'hive') {
huePubSub.publish('cluster.config.get.config', clusterConfig => {
if (clusterConfig) {
const defaultEditor = clusterConfig['default_sql_interpreter'];
if (!sourceType || (sourceType === 'hive' && defaultEditor === 'impala')) {
sourceType = defaultEditor;
}
}
});
}
if (self.isCatalogEntry) {
contextCatalog.getNamespaces({ sourceType: sourceType }).done(context => {
// TODO: Namespace and compute selection for global search results?
dataCatalog
.getEntry({
sourceType: sourceType,
namespace: context.namespaces[0],
compute: context.namespaces[0].computes[0],
path: path,
definition: { type: params.data.type.toLowerCase() }
})
.done(catalogEntry => {
catalogEntry.navigatorMeta = params.data;
catalogEntry.navigatorMetaPromise = $.Deferred().resolve(catalogEntry.navigatorMeta);
catalogEntry.saveLater();
self.contents(new DataCatalogContext({ popover: self, catalogEntry: catalogEntry }));
});
});
loadNamespaces(refresh) {
const self = this;
self.loading(true);
if (refresh) {
contextCatalog.getComputes({ sourceType: self.sourceType, clearCache: true });
}
return contextCatalog
.getNamespaces({ sourceType: self.sourceType, clearCache: refresh })
.done(context => {
const assistNamespaces = [];
let activeNamespace;
let activeCompute;
context.namespaces.forEach(namespace => {
const assistNamespace = new AssistDbNamespace({
sourceType: self.sourceType,
namespace: namespace,
i18n: self.i18n,
nonSqlType: self.nonSqlType,
navigationSettings: self.navigationSettings
});
if (self.initialNamespace && namespace.id === self.initialNamespace.id) {
activeNamespace = assistNamespace;
function Plugin(element, options) {
const self = this;
self.element = element;
self.options = $.extend({}, defaults, options);
self._defaults = defaults;
self._name = pluginName;
self.namespaceDeferred = $.Deferred();
self.computeDeferred = $.Deferred();
if (self.options.namespace) {
self.namespaceDeferred.resolve(self.options.namespace);
} else {
contextCatalog.getNamespaces({ sourceType: options.apiHelperType }).done(context => {
if (context.namespaces && context.namespaces.length) {
self.namespaceDeferred.resolve(context.namespaces[0]);
} else {
self.namespaceDeferred.reject();
}
});
}
self.namespaceDeferred.done(namespace => {
if (
!self.options.compute ||
!namespace.computes.some(compute => {
if (compute.id === self.options.compute.id) {
self.computeDeferred.resolve(compute);
return true;
}
})
huePubSub.subscribe('context.catalog.namespaces.refreshed', sourceType => {
if (self.sourceType !== sourceType) {
return;
}
self.loading(true);
contextCatalog
.getNamespaces({ sourceType: self.sourceType })
.done(context => {
const newNamespaces = [];
const existingNamespaceIndex = {};
self.namespaces().forEach(assistNamespace => {
existingNamespaceIndex[assistNamespace.namespace.id] = assistNamespace;
});
context.namespaces.forEach(newNamespace => {
if (existingNamespaceIndex[newNamespace.id]) {
existingNamespaceIndex[newNamespace.id].namespace = newNamespace;
existingNamespaceIndex[newNamespace.id].name = newNamespace.name;
existingNamespaceIndex[newNamespace.id].status(newNamespace.status);
newNamespaces.push(existingNamespaceIndex[newNamespace.id]);
} else {
newNamespaces.push(
new AssistDbNamespace({
loadNamespaces() {
this.loading(true);
contextCatalog
.getNamespaces({ sourceType: this.type })
.done(context => {
const namespacesWithComputes = context.namespaces.filter(
namespace => namespace.computes.length
);
this.namespaces(
namespacesWithComputes.map(
namespace =>
new MetastoreNamespace({
metastoreViewModel: this.metastoreViewModel,
sourceType: this.type,
navigatorEnabled: this.metastoreViewModel.navigatorEnabled,
optimizerEnabled: this.metastoreViewModel.optimizerEnabled,
namespace: namespace
})
)