graphdb-workbench
Version:
The web application for GraphDB APIs
2 lines • 13.7 kB
JavaScript
export const __webpack_id__=33524;export const __webpack_ids__=[15435,33524,42826,56139,56413,66014,71156,83610,84923];export const __webpack_modules__={15435:(e,n,t)=>{t.r(n),t.d(n,{RenderingMode:()=>o});const o={YASGUI:"mode-yasgui",YASQE:"mode-yasqe",YASR:"mode-yasr"}},33524:(e,n,t)=>{t.r(n),t(82493),t(5687),t(25222),t(76933),t(66014),t(42826),t(93098),angular.module("graphdb.framework.jdbc",["toastr","ui.bootstrap","graphdb.framework.jdbc.controllers","graphdb.framework.core.services.repositories","graphdb.framework.core.directives","graphdb.framework.rest.jdbc.service","graphdb.framework.core.directives.yasgui-component"])},42826:()=>{angular.module("graphdb.framework.rest.jdbc.service",[]).factory("JdbcRestService",n),n.$inject=["$http","$repositories","$translate"];const e="rest/sql-views";function n(n,t){return{getJdbcConfigurations:function(){return n.get(`${e}/tables`)},getJdbcConfiguration:function(t){return n.get(`${e}/tables/${t}`)},createNewJdbcConfiguration:function(e){return o("POST","",e)},updateJdbcConfiguration:function(e){return o("PUT",e.name,e)},deleteJdbcConfiguration:function(t){return n.delete(`${e}/tables/${t}`)},getColumnNames:function(t){return n.post(`${e}/columns`,t,{headers:{Accept:"application/json","Content-Type":"text/plain"}})},getColumnsTypeSuggestion:function(o,i){if(!Array.isArray(i))throw new Error(t.instant("jdbc.column.names.constraint"));return n({method:"POST",url:`${e}/types`,data:{query:o,column_names:i}})},getExistingSqlTablePreview:function(e,t){return n({method:"GET",url:`rest/sql-views/preview/${e}`,params:{limit:t}})},getNewSqlTablePreview:function(e,t){return n({method:"POST",url:"rest/sql-views/preview",contentType:"application/json; charset=utf-8",dataType:"json",data:e,params:{limit:t},headers:{Accept:"application/sparql-results+json"}})}};function o(t,o,i){return n({method:t,url:o?`${e}/tables/${o}`:`${e}/tables`,noCancelOnRouteChange:!0,data:{name:i.name,query:i.query,columns:i.columns||[]}})}}},56139:()=>{function e(e,n){return{showToastMessageWithDelay:function(t){return new Promise(o=>{e.success(n.instant(t)),setTimeout(o,300)})}}}angular.module("graphdb.framework.utils.notifications",[]).factory("Notifications",e),e.$inject=["toastr","$translate"]},56413:(e,n,t)=>{t.r(n),t.d(n,{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(e=o,n=!0,t=void 0){this.query=e,this.jdbcConfigurationName=t,this.isNewJdbcConfiguration=n,this.isValidQuery=!0,this.isValidQueryType=!0,this.hasUndefinedColumns=!1,this.isColumnsEmpty=!1,this.columns=[]}}},66014:(e,n,t)=>{t.r(n),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(69937),l=t(57154);function d(e,n,t,o,i,r){e.getSqlConfigurations=function(){!n.getActiveRepository()||n.isActiveRepoOntopType()||n.isActiveRepoFedXType()?e.jdbcConfigurations=[]:t.getJdbcConfigurations().success(function(n){e.jdbcConfigurations=n}).error(function(e){const n=getError(e);o.error(n,r.instant("jdbc.not.get.SQL.msg"))})},e.$watch(function(){return n.getActiveRepository()},function(){e.getSqlConfigurations()}),e.deleteConfiguration=function(n){i.openSimpleModal({title:r.instant("common.warning"),message:r.instant("jdbc.delete.sql.table.warning.msg",{name:n}),warning:!0}).result.then(function(){t.deleteJdbcConfiguration(n).success(function(){e.getSqlConfigurations()}).error(function(e){o.error(getError(e),r.instant("jdbc.not.delete.sql.msg"))})})}}function g(e,n,t,d,g,f,m,p,b,y,C,h,j,w,v,q){n.emptySparqlResponse='{"head": {"vars": []},"results": {"bindings": []}}',n.getSuggestionSqlType="",n.sqlTypes=[],n.activeTab=1,n.jdbcConfigurationInfo=new o.JdbcConfigurationInfo,n.jdbcConfigurationInfo.jdbcConfigurationName=d.search().name||"",n.saveOrUpdateExecuted=!1,n.jdbcConfigurationInfo.isNewJdbcConfiguration=!n.jdbcConfigurationInfo.jdbcConfigurationName,n.language=v.getLanguage(),n.isDirty=!1,n.prefixes=[],n.loadingControllerResources=!1,n.isQueryRunning=!1,n.canEditActiveRepo=!1;let S=!0,R=!0;n.saveJdbcConfiguration=()=>{if(n.saveOrUpdateExecuted=!0,!n.jdbcConfigurationInfo.jdbcConfigurationName)return;if(!n.isDirty)return void F();const e=n.jdbcConfigurationInfo.isNewJdbcConfiguration?_:$;N(n.jdbcConfigurationInfo).then(P).then(Q).then(M).then(e).catch(e=>{if(!(e instanceof r.JdbcConfigurationError)){const n=getError(e);g.error(n,w.instant("jdbc.not.saved.configuration"))}})},n.getPreview=()=>{n.activeTab=1,n.isQueryRunning=!0,N(n.jdbcConfigurationInfo).then(P).then(Q).then(M).then(e=>(A({render:s.RenderingMode.YASQE,initialQuery:e.query}),e)).then(E).then(([e,n])=>{const t=e&&e.results.bindings&&e.results.bindings.length>0;let o=s.RenderingMode.YASGUI;t||(o=s.RenderingMode.YASQE,g.info(w.instant("jdbc.table.definition"),w.instant("jdbc.preview.sql"))),A({render:o,sparqlResponse:e,initialQuery:n.query})}).catch(e=>{e instanceof r.JdbcConfigurationError?e.jdbcConfigurationInfo&&(e.jdbcConfigurationInfo.isColumnsEmpty||e.jdbcConfigurationInfo.hasUndefinedColumns)&&(D(),n.activeTab=2):g.error(getError(e,0,100),w.instant("jdbc.not.show.preview"))}).finally(()=>{n.isQueryRunning=!1})},n.setActiveTab=e=>{n.activeTab=e;const t=n.jdbcConfigurationInfo.columns;2!==n.activeTab||t&&0!==t.length||N(n.jdbcConfigurationInfo).then(P).then(()=>{n.getColumnsSuggestions()})},n.setDirty=()=>{n.isDirty=!0},n.getTypeLabel=e=>{switch(e){case"iri":return"VARCHAR: IRI";case"string":return"VARCHAR: String";default:return e.indexOf(" ")>0?e:e.toUpperCase()}},n.selectColumnType=(e,t)=>{n.setDirty();const o=n.jdbcConfigurationInfo.columns.find(n=>n.column_name===e);o.column_type===n.getSuggestionSqlType&&M(n.jdbcConfigurationInfo).then(n=>y.getColumnsTypeSuggestion(n.query,[e])).then(e=>e.data).then(e=>{(0,a.updateColumn)(o,e),T(o.column_type,t)}).catch(e=>{g.error(getError(e),w.instant("jdbc.not.suggest.column.type"))})},n.deleteColumn=function(e,t){j.openSimpleModal({title:w.instant("common.warning"),message:w.instant("jdbc.warning.delete.column.msg",{columnName:e}),warning:!0}).result.then(function(){n.jdbcConfigurationInfo.columns.splice(t,1),n.setDirty()})},n.getColumnsSuggestions=()=>{n.jdbcConfigurationInfo.columns&&n.jdbcConfigurationInfo.columns.length>0?j.openSimpleModal({title:w.instant("common.warning"),message:w.instant("jdbc.warning.column.type.msg"),warning:!0}).result.then(function(){D()}):D()},n.hasPrecision=e=>"iri"===e||"string"===e||"decimal"===e,n.containsColumnsWithPrecision=e=>e&&e.some(e=>n.hasPrecision(e.column_type)),n.containsColumnsWithScale=e=>e&&e.some(e=>U(e.column_type)),n.isLiteral=e=>"iri"!==e&&"unknown"!==e,n.containsNonLiteralColumnsOnly=e=>e&&e.every(e=>!n.isLiteral(e.column_type));const E=e=>{if(n.canWriteActiveRepo){const t=JSON.stringify({name:n.jdbcConfigurationInfo.jdbcConfigurationName,query:n.jdbcConfigurationInfo.query,columns:n.jdbcConfigurationInfo.columns||[]});return Promise.all([y.getNewSqlTablePreview(t).then(e=>e.data),Promise.resolve(e)])}return Promise.all([y.getExistingSqlTablePreview(n.jdbcConfigurationInfo.jdbcConfigurationName).then(e=>e.data),Promise.resolve(e)])},T=(e,n)=>{e===n?g.info((0,u.Gz)(w.instant("jdbc.same.suggested.sql.type",{type:e})),w.instant("jdbc.suggest.sql.type"),{allowHtml:!0}):g.success((0,u.Gz)(w.instant("jdbc.suggested.sql.type",{type:e})),w.instant("jdbc.suggest.sql.type"),{allowHtml:!0})},I=(e,t=new o.JdbcConfigurationInfo)=>{n.jdbcConfigurationInfo.columns=t.columns,n.jdbcConfigurationInfo.query=t.query,n.jdbcConfigurationInfo.jdbcConfigurationName=d.search().name||"",n.jdbcConfigurationInfo.isNewJdbcConfiguration=!n.jdbcConfigurationInfo.jdbcConfigurationName,n.prefixes=e,A(),V()},_=e=>{const t={name:e.jdbcConfigurationName,query:e.query,columns:e.columns};return y.createNewJdbcConfiguration(t).then(()=>{n.isDirty=!1,n.jdbcConfigurationInfo.isNewConfiguration=!1,g.success(w.instant("jdbc.saved.configuration")),W()})},$=e=>{const t={name:e.jdbcConfigurationName,query:e.query,columns:e.columns};return y.updateJdbcConfiguration(t).then(()=>{n.isDirty=!1,n.jdbcConfigurationInfo.isNewConfiguration=!1,g.success(w.instant("jdbc.configuration.updated")),W()})},A=(e={})=>{const t={};angular.extend(t,n.yasguiConfig||J(),e),n.yasguiConfig=t},J=()=>({showEditorTabs:!1,showToolbar:!1,showResultTabs:!1,showQueryButton:!1,showResultInfo:!1,downloadAsOn:!1,showYasqeResizer:!1,initialQuery:n.jdbcConfigurationInfo.query,componentId:"jdbc-component",prefixes:n.prefixes,maxPersistentResponseSize:0,render:s.RenderingMode.YASQE,getCellContent:L,sparqlResponse:n.emptySparqlResponse,yasqeActionButtons:c.DISABLE_YASQE_BUTTONS_CONFIGURATION,yasqeMode:n.canEditActiveRepo?i.YasqeMode.WRITE:i.YasqeMode.READ}),N=e=>O().getQueryType().then(n=>(e.isValidQueryType="SELECT"===n,e.isValidQueryType?e:Promise.reject(new r.JdbcConfigurationError("Query type is not valid.")))),P=e=>O().isQueryValid().then(n=>(e.isValidQuery=n,e.isValidQuery?e:Promise.reject(new r.JdbcConfigurationError("Invalid query.")))),Q=e=>e.columns&&0!==e.columns.length?n.jdbcConfigurationInfo.columns&&n.jdbcConfigurationInfo.columns.find(e=>"unknown"===e.column_type)?(e.hasUndefinedColumns=!0,Promise.reject(new r.JdbcConfigurationError("There are columns without defined type.",e))):Promise.resolve(e):(e.isColumnsEmpty=!0,g.error(w.instant("jdbc.warning.one.column.msg")),Promise.reject(new r.JdbcConfigurationError("There are not defined columns.",e))),D=()=>{N(n.jdbcConfigurationInfo).then(P).then(M).then(x).then(k).then(e=>n.jdbcConfigurationInfo=e).catch(e=>{console.log(e)})},x=e=>y.getColumnNames(e.query).then(n=>[e,n.data]).catch(function(e){g.error(getError(e),w.instant("jdbc.not.suggest.column.names"))}),k=([e,t])=>y.getColumnsTypeSuggestion(e.query,t).then(function(o){return e.columns=(0,a.toJDBCColumns)(t,o.data),e.isColumnsEmpty=e.columns.length,n.setDirty(),e}).catch(function(e){g.error(getError(e),w.instant("jdbc.not.suggest.column.types"))}),O=()=>c.YasguiComponentDirectiveUtil.getOntotextYasguiElement("#query-editor"),M=e=>O().getQuery().then(n=>(e.query=n,e)),U=e=>"decimal"===e,L=(e,n)=>{let t=e.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>"},Y=(e,n,t,o)=>{j.openSimpleModal({title:e,message:n,warning:!0}).result.then(function(){angular.isFunction(t)&&t()},function(){angular.isFunction(o)&&o()})},V=()=>{n.getSuggestionSqlType=w.instant("view.jdbc.create.get_suggestion_sql_type"),n.sqlTypes=["string","iri","boolean","byte","short","int","long","float","double","decimal","date","time","timestamp",n.getSuggestionSqlType]},W=()=>{setTimeout(function(){F()},1e3)},F=()=>{d.url("/jdbc")},B=e=>{n.isDirty&&(e.returnValue=!0)},G=()=>{window.removeEventListener("beforeunload",B),z.forEach(e=>e())},z=[],H=l.ServiceProvider.get(l.RepositoryContextService).onSelectedRepositoryChanged(e=>{e&&(R?R=!1:O().abortQuery().then(F))},()=>new Promise(function(e){if(n.jdbcConfigurationInfo.isNewJdbcConfiguration)return void e(!0);const t=()=>{n.isDirty=!1,e(!0)};if(n.isDirty){const n=()=>{e(!1)},o=w.instant("common.confirm"),i=w.instant("jdbc.warning.unsaved.changes");Y(o,i,t,n)}else t()}));z.push(H),z.push(t.$on("$translateChangeSuccess",()=>{n.language=v.getLanguage(),V()})),z.push(n.$on("$locationChangeStart",(e,t)=>{if(n.isDirty){e.preventDefault();const n=w.instant("common.confirm"),o=w.instant("jdbc.warning.unsaved.changes");Y(n,o,()=>{G();const e=d.absUrl().length-d.url().length,n=t.substring(e);d.path(n)})}else G()})),z.push(n.$on("$destroy",G)),window.addEventListener("beforeunload",B),z.push(n.$watch(n.getActiveRepositoryObject,e=>{e&&(n.canEditActiveRepo=n.canWriteActiveRepo(),S?((()=>{n.loadingControllerResources=!0;const e=f.getActiveRepository();n.jdbcConfigurationInfo.jdbcConfigurationName?Promise.all([f.getPrefixes(e),y.getJdbcConfiguration(n.jdbcConfigurationInfo.jdbcConfigurationName)]).then(([e,n])=>{I(e,n.data)}).finally(()=>n.loadingControllerResources=!1):f.getPrefixes(e).then(e=>I(e)).finally(()=>n.loadingControllerResources=!1)})(),S=!1):O().abortQuery().then(F))}))}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",d).controller("JdbcCreateCtrl",g),d.$inject=["$scope","$repositories","JdbcRestService","toastr","ModalService","$translate"],g.$inject=["$q","$scope","$rootScope","$location","toastr","$repositories","$window","$timeout","$interval","JdbcRestService","RDF4JRepositoriesRestService","SparqlRestService","ModalService","$translate","$languageService","EventEmitterService"]},71156:(e,n,t)=>{t.r(n),t.d(n,{YasqeMode:()=>o});const o={WRITE:"WRITE",READ:"READ",PROTECTED:"PROTECTED"}},83610:(e,n,t)=>{t.r(n),t.d(n,{JdbcColumn:()=>o,toJDBCColumns:()=>i,updateColumn:()=>r});class o{constructor(){this.column_name="",this.column_type="",this.sparql_type="",this.nullable=!0}}const i=(e=[],n)=>e.map(e=>({column_name:e,column_type:n[e].column_type,nullable:!0,sparql_type:n[e].sparql_type})),r=(e,n)=>{e.column_type=n[e.column_name].column_type,e.sparql_type=n[e.column_name].sparql_type}},84923:(e,n,t)=>{t.r(n),t.d(n,{JdbcConfigurationError:()=>o});class o extends Error{constructor(e,n){super(e),this.jdbcConfigurationInfo=n}}}};
//# sourceMappingURL=33524.35fe079bcb99a78babaf.bundle.js.map