graphdb-workbench
Version:
The web application for GraphDB APIs
2 lines • 12.1 kB
JavaScript
export const __webpack_id__=66014;export const __webpack_ids__=[15435,56139,56413,66014,71156,83610,84923];export const __webpack_modules__={15435:(n,e,t)=>{t.r(e),t.d(e,{RenderingMode:()=>o});const o={YASGUI:"mode-yasgui",YASQE:"mode-yasqe",YASR:"mode-yasr"}},56139:()=>{function n(n,e){return{showToastMessageWithDelay:function(t){return new Promise(o=>{n.success(e.instant(t)),setTimeout(o,300)})}}}angular.module("graphdb.framework.utils.notifications",[]).factory("Notifications",n),n.$inject=["toastr","$translate"]},56413:(n,e,t)=>{t.r(e),t.d(e,{DEFAULT_SPARQL_QUERY:()=>o,JdbcConfigurationInfo:()=>i});const o="PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n\n# Selects two variables to use as columns\nSELECT ?id ?label {\n ?id rdfs:label ?label\n # The following placeholder must be present in the query\n #!filter\n}";class i{constructor(n=o,e=!0,t=void 0){this.query=n,this.jdbcConfigurationName=t,this.isNewJdbcConfiguration=e,this.isValidQuery=!0,this.isValidQueryType=!0,this.hasUndefinedColumns=!1,this.isColumnsEmpty=!1,this.columns=[]}}},66014:(n,e,t)=>{t.r(e),t(76933),t(83351),t(56139),t(82493),t(81655);var o=t(56413),i=t(71156),r=t(84923),s=t(15435),a=t(83610),c=t(85727),u=t(27030),l=t(57154),g=t(304);angular.module("graphdb.framework.jdbc.controllers",["ui.bootstrap","graphdb.framework.core.services.repositories","graphdb.framework.rest.monitoring.service","toastr","graphdb.framework.utils.event-emitter-service"],["graphdb.framework.utils.notifications"]).controller("JdbcListCtrl",f).controller("JdbcCreateCtrl",m),f.$inject=["$scope","$repositories","JdbcRestService","toastr","ModalService","$translate"];const d=g.LoggerProvider.logger;function f(n,e,t,o,i,r){n.getSqlConfigurations=function(){!e.getActiveRepository()||e.isActiveRepoOntopType()||e.isActiveRepoFedXType()?n.jdbcConfigurations=[]:t.getJdbcConfigurations().success(function(e){n.jdbcConfigurations=e}).error(function(n){const e=getError(n);o.error(e,r.instant("jdbc.not.get.SQL.msg"))})},n.$watch(function(){return e.getActiveRepository()},function(){n.getSqlConfigurations()}),n.deleteConfiguration=function(e){i.openSimpleModal({title:r.instant("common.warning"),message:r.instant("jdbc.delete.sql.table.warning.msg",{name:e}),warning:!0}).result.then(function(){t.deleteJdbcConfiguration(e).success(function(){n.getSqlConfigurations()}).error(function(n){o.error(getError(n),r.instant("jdbc.not.delete.sql.msg"))})})}}function m(n,e,t,g,f,m,b,p,C,y,h,j,w,v,R,S){e.emptySparqlResponse='{"head": {"vars": []},"results": {"bindings": []}}',e.getSuggestionSqlType="",e.sqlTypes=[],e.activeTab=1,e.jdbcConfigurationInfo=new o.JdbcConfigurationInfo,e.jdbcConfigurationInfo.jdbcConfigurationName=g.search().name||"",e.saveOrUpdateExecuted=!1,e.jdbcConfigurationInfo.isNewJdbcConfiguration=!e.jdbcConfigurationInfo.jdbcConfigurationName,e.language=R.getLanguage(),e.isDirty=!1,e.prefixes=[],e.loadingControllerResources=!1,e.isQueryRunning=!1,e.canEditActiveRepo=!1;let q=!0,E=!0;e.saveJdbcConfiguration=()=>{if(e.saveOrUpdateExecuted=!0,!e.jdbcConfigurationInfo.jdbcConfigurationName)return;if(!e.isDirty)return void B();const n=e.jdbcConfigurationInfo.isNewJdbcConfiguration?A:J;Q(e.jdbcConfigurationInfo).then(D).then($).then(Y).then(n).catch(n=>{if(!(n instanceof r.JdbcConfigurationError)){const e=getError(n);f.error(e,v.instant("jdbc.not.saved.configuration"))}})},e.getPreview=()=>{e.activeTab=1,e.isQueryRunning=!0,Q(e.jdbcConfigurationInfo).then(D).then($).then(Y).then(n=>(N({render:s.RenderingMode.YASQE,initialQuery:n.query}),n)).then(I).then(([n,e])=>{const t=n&&n.results.bindings&&n.results.bindings.length>0;let o=s.RenderingMode.YASGUI;t||(o=s.RenderingMode.YASQE,f.info(v.instant("jdbc.table.definition"),v.instant("jdbc.preview.sql"))),N({render:o,sparqlResponse:n,initialQuery:e.query})}).catch(n=>{n instanceof r.JdbcConfigurationError?n.jdbcConfigurationInfo&&(n.jdbcConfigurationInfo.isColumnsEmpty||n.jdbcConfigurationInfo.hasUndefinedColumns)&&(x(),e.activeTab=2):f.error(getError(n,0,100),v.instant("jdbc.not.show.preview"))}).finally(()=>{e.isQueryRunning=!1})},e.setActiveTab=n=>{e.activeTab=n;const t=e.jdbcConfigurationInfo.columns;2!==e.activeTab||t&&0!==t.length||Q(e.jdbcConfigurationInfo).then(D).then(()=>{e.getColumnsSuggestions()})},e.setDirty=()=>{e.isDirty=!0},e.getTypeLabel=n=>{switch(n){case"iri":return"VARCHAR: IRI";case"string":return"VARCHAR: String";default:return n.indexOf(" ")>0?n:n.toUpperCase()}},e.selectColumnType=(n,t)=>{e.setDirty();const o=e.jdbcConfigurationInfo.columns.find(e=>e.column_name===n);o.column_type===e.getSuggestionSqlType&&Y(e.jdbcConfigurationInfo).then(e=>y.getColumnsTypeSuggestion(e.query,[n])).then(n=>n.data).then(n=>{(0,a.updateColumn)(o,n),T(o.column_type,t)}).catch(n=>{f.error(getError(n),v.instant("jdbc.not.suggest.column.type"))})},e.deleteColumn=function(n,t){w.openSimpleModal({title:v.instant("common.warning"),message:v.instant("jdbc.warning.delete.column.msg",{columnName:n}),warning:!0}).result.then(function(){e.jdbcConfigurationInfo.columns.splice(t,1),e.setDirty()})},e.getColumnsSuggestions=()=>{e.jdbcConfigurationInfo.columns&&e.jdbcConfigurationInfo.columns.length>0?w.openSimpleModal({title:v.instant("common.warning"),message:v.instant("jdbc.warning.column.type.msg"),warning:!0}).result.then(function(){x()}):x()},e.hasPrecision=n=>"iri"===n||"string"===n||"decimal"===n,e.containsColumnsWithPrecision=n=>n&&n.some(n=>e.hasPrecision(n.column_type)),e.containsColumnsWithScale=n=>n&&n.some(n=>O(n.column_type)),e.isLiteral=n=>"iri"!==n&&"unknown"!==n,e.containsNonLiteralColumnsOnly=n=>n&&n.every(n=>!e.isLiteral(n.column_type));const I=n=>{if(e.canWriteActiveRepo){const t=JSON.stringify({name:e.jdbcConfigurationInfo.jdbcConfigurationName,query:e.jdbcConfigurationInfo.query,columns:e.jdbcConfigurationInfo.columns||[]});return Promise.all([y.getNewSqlTablePreview(t).then(n=>n.data),Promise.resolve(n)])}return Promise.all([y.getExistingSqlTablePreview(e.jdbcConfigurationInfo.jdbcConfigurationName).then(n=>n.data),Promise.resolve(n)])},T=(n,e)=>{n===e?f.info((0,u.Gz)(v.instant("jdbc.same.suggested.sql.type",{type:n})),v.instant("jdbc.suggest.sql.type"),{allowHtml:!0}):f.success((0,u.Gz)(v.instant("jdbc.suggested.sql.type",{type:n})),v.instant("jdbc.suggest.sql.type"),{allowHtml:!0})},_=(n,t=new o.JdbcConfigurationInfo)=>{e.jdbcConfigurationInfo.columns=t.columns,e.jdbcConfigurationInfo.query=t.query,e.jdbcConfigurationInfo.jdbcConfigurationName=g.search().name||"",e.jdbcConfigurationInfo.isNewJdbcConfiguration=!e.jdbcConfigurationInfo.jdbcConfigurationName,e.prefixes=n,N(),W()},A=n=>{const t={name:n.jdbcConfigurationName,query:n.query,columns:n.columns};return y.createNewJdbcConfiguration(t).then(()=>{e.isDirty=!1,e.jdbcConfigurationInfo.isNewConfiguration=!1,f.success(v.instant("jdbc.saved.configuration")),F()})},J=n=>{const t={name:n.jdbcConfigurationName,query:n.query,columns:n.columns};return y.updateJdbcConfiguration(t).then(()=>{e.isDirty=!1,e.jdbcConfigurationInfo.isNewConfiguration=!1,f.success(v.instant("jdbc.configuration.updated")),F()})},N=(n={})=>{const t={};angular.extend(t,e.yasguiConfig||P(),n),e.yasguiConfig=t},P=()=>({showEditorTabs:!1,showToolbar:!1,showResultTabs:!1,showQueryButton:!1,showResultInfo:!1,downloadAsOn:!1,showYasqeResizer:!1,initialQuery:e.jdbcConfigurationInfo.query,componentId:"jdbc-component",prefixes:e.prefixes,maxPersistentResponseSize:0,render:s.RenderingMode.YASQE,getCellContent:k,sparqlResponse:e.emptySparqlResponse,yasqeActionButtons:c.DISABLE_YASQE_BUTTONS_CONFIGURATION,yasqeMode:e.canEditActiveRepo?i.YasqeMode.WRITE:i.YasqeMode.READ}),Q=n=>U().getQueryType().then(e=>(n.isValidQueryType="SELECT"===e,n.isValidQueryType?n:Promise.reject(new r.JdbcConfigurationError("Query type is not valid.")))),D=n=>U().isQueryValid().then(e=>(n.isValidQuery=e,n.isValidQuery?n:Promise.reject(new r.JdbcConfigurationError("Invalid query.")))),$=n=>n.columns&&0!==n.columns.length?e.jdbcConfigurationInfo.columns&&e.jdbcConfigurationInfo.columns.find(n=>"unknown"===n.column_type)?(n.hasUndefinedColumns=!0,Promise.reject(new r.JdbcConfigurationError("There are columns without defined type.",n))):Promise.resolve(n):(n.isColumnsEmpty=!0,f.error(v.instant("jdbc.warning.one.column.msg")),Promise.reject(new r.JdbcConfigurationError("There are not defined columns.",n))),x=()=>{Q(e.jdbcConfigurationInfo).then(D).then(Y).then(L).then(M).then(n=>e.jdbcConfigurationInfo=n).catch(n=>{d.info(n)})},L=n=>y.getColumnNames(n.query).then(e=>[n,e.data]).catch(function(n){f.error(getError(n),v.instant("jdbc.not.suggest.column.names"))}),M=([n,t])=>y.getColumnsTypeSuggestion(n.query,t).then(function(o){return n.columns=(0,a.toJDBCColumns)(t,o.data),n.isColumnsEmpty=n.columns.length,e.setDirty(),n}).catch(function(n){f.error(getError(n),v.instant("jdbc.not.suggest.column.types"))}),U=()=>c.YasguiComponentDirectiveUtil.getOntotextYasguiElement("#query-editor"),Y=n=>U().getQuery().then(e=>(n.query=e,n)),O=n=>"decimal"===n,k=(n,e)=>{let t=n.value;return t=t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),"<div class = 'literal-cell'><p class='nonUri' style='border: none; background-color: transparent; padding: 0; margin: 0'>"+t+"</p></div>"},V=(n,e,t,o)=>{w.openSimpleModal({title:n,message:e,warning:!0}).result.then(function(){angular.isFunction(t)&&t()},function(){angular.isFunction(o)&&o()})},W=()=>{e.getSuggestionSqlType=v.instant("view.jdbc.create.get_suggestion_sql_type"),e.sqlTypes=["string","iri","boolean","byte","short","int","long","float","double","decimal","date","time","timestamp",e.getSuggestionSqlType]},F=()=>{setTimeout(function(){B()},1e3)},B=()=>{g.url("/jdbc")},G=n=>{e.isDirty&&(n.returnValue=!0)},z=()=>{window.removeEventListener("beforeunload",G),H.forEach(n=>n())},H=[],X=l.ServiceProvider.get(l.RepositoryContextService).onSelectedRepositoryChanged(n=>{n&&(E?E=!1:U().abortQuery().then(B))},()=>new Promise(function(n){if(e.jdbcConfigurationInfo.isNewJdbcConfiguration)return void n(!0);const t=()=>{e.isDirty=!1,n(!0)};if(e.isDirty){const e=()=>{n(!1)},o=v.instant("common.confirm"),i=v.instant("jdbc.warning.unsaved.changes");V(o,i,t,e)}else t()}));H.push(X),H.push(t.$on("$translateChangeSuccess",()=>{e.language=R.getLanguage(),W()})),H.push(e.$on("$locationChangeStart",(n,t)=>{if(e.isDirty){n.preventDefault();const e=v.instant("common.confirm"),o=v.instant("jdbc.warning.unsaved.changes");V(e,o,()=>{z();const n=g.absUrl().length-g.url().length,e=t.substring(n);g.path(e)})}else z()})),H.push(e.$on("$destroy",z)),window.addEventListener("beforeunload",G),H.push(e.$watch(e.getActiveRepositoryObject,n=>{n&&(e.canEditActiveRepo=e.canWriteActiveRepo(),q?((()=>{e.loadingControllerResources=!0;const n=m.getActiveRepository();e.jdbcConfigurationInfo.jdbcConfigurationName?Promise.all([m.getPrefixes(n),y.getJdbcConfiguration(e.jdbcConfigurationInfo.jdbcConfigurationName)]).then(([n,e])=>{_(n,e.data)}).finally(()=>e.loadingControllerResources=!1):m.getPrefixes(n).then(n=>_(n)).finally(()=>e.loadingControllerResources=!1)})(),q=!1):U().abortQuery().then(B))}))}m.$inject=["$q","$scope","$rootScope","$location","toastr","$repositories","$window","$timeout","$interval","JdbcRestService","RDF4JRepositoriesRestService","SparqlRestService","ModalService","$translate","$languageService","EventEmitterService"]},71156:(n,e,t)=>{t.r(e),t.d(e,{YasqeMode:()=>o});const o={WRITE:"WRITE",READ:"READ",PROTECTED:"PROTECTED"}},83610:(n,e,t)=>{t.r(e),t.d(e,{JdbcColumn:()=>o,toJDBCColumns:()=>i,updateColumn:()=>r});class o{constructor(){this.column_name="",this.column_type="",this.sparql_type="",this.nullable=!0}}const i=(n=[],e)=>n.map(n=>({column_name:n,column_type:e[n].column_type,nullable:!0,sparql_type:e[n].sparql_type})),r=(n,e)=>{n.column_type=e[n.column_name].column_type,n.sparql_type=e[n.column_name].sparql_type}},84923:(n,e,t)=>{t.r(e),t.d(e,{JdbcConfigurationError:()=>o});class o extends Error{constructor(n,e){super(n),this.jdbcConfigurationInfo=e}}}};
//# sourceMappingURL=66014.a16167f9ccdae29c662b.bundle.js.map