@knora/core
Version:
Knora ui module: core
16 lines (14 loc) • 34 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@knora/api"),require("moment"),require("json2typescript"),require("rxjs"),require("@angular/common/http"),require("rxjs/internal/observable/throwError"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@knora/core",["exports","@angular/core","@knora/api","moment","json2typescript","rxjs","@angular/common/http","rxjs/internal/observable/throwError","rxjs/operators"],e):e(((t=t||self).knora=t.knora||{},t.knora.core={}),t.ng.core,t.api,t.momentImported,t.json2typescript,t.rxjs,t.ng.common.http,t.rxjs["internal/observable/throwError"],t.rxjs.operators)}(this,(function(t,e,o,r,n,a,i,s,p){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */var l=function(t,e){return(l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(t,e)};function u(t,e){function o(){this.constructor=t}l(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}function c(t,e,o,r){var n,a=arguments.length,i=a<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(t,e,o,r);else for(var s=t.length-1;s>=0;s--)(n=t[s])&&(i=(a<3?n(i):a>3?n(e,o,i):n(e,o))||i);return a>3&&i&&Object.defineProperty(e,o,i),i}function h(t,e){return function(o,r){e(o,r,t)}}function f(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function y(t){var e="function"==typeof Symbol&&t[Symbol.iterator],o=0;return e?e.call(t):{next:function(){return t&&o>=t.length&&(t=void 0),{value:t&&t[o++],done:!t}}}}var g,d=new e.InjectionToken("Knora api configuration"),m=new e.InjectionToken("Knora api connection configuration"),v=new e.InjectionToken("Main configuration for knora-ui modules"),C=function(){function t(){}var o;return o=t,t.forRoot=function(t){return{ngModule:o,providers:[{provide:v,useValue:t}]}},t=o=c([e.NgModule({imports:[],declarations:[],exports:[]})],t)}(),O=function(t,e){this.knora=t,this.app=e},b=r,w=function(){function t(t,e){this.knoraApiConnection=t,this.knoraApiConfig=e,this.MAX_SESSION_TIME=864e5}return t.prototype.setSession=function(t,e,r){var n,a=this;this.updateKnoraApiConnection(t),this.knoraApiConnection.admin.usersEndpoint.getUser(r,e).subscribe((function(e){var r,i,s=!1,p=[],l=Object.keys(e.body.user.permissions.groupsPerProject);try{for(var u=y(l),c=u.next();!c.done;c=u.next()){var h=c.value;h===o.Constants.SystemProjectIRI&&(s=e.body.user.permissions.groupsPerProject[h].indexOf(o.Constants.SystemAdminGroupIRI)>-1),e.body.user.permissions.groupsPerProject[h].indexOf(o.Constants.ProjectAdminGroupIRI)>-1&&p.push(h)}}catch(t){r={error:t}}finally{try{c&&!c.done&&(i=u.return)&&i.call(u)}finally{if(r)throw r.error}}n={id:a.setTimestamp(),user:{name:e.body.user.username,jwt:t,lang:e.body.user.lang,sysAdmin:s,projectAdmin:p}},localStorage.setItem("session",JSON.stringify(n))}),(function(t){localStorage.removeItem("session"),console.error(t)}))},t.prototype.validateSession=function(){var t=this,e=JSON.parse(localStorage.getItem("session")),o=this.setTimestamp();return e?(this.updateKnoraApiConnection(e.user.jwt),!(e.id+this.MAX_SESSION_TIME<=o)||void this.knoraApiConnection.v2.auth.checkCredentials().subscribe((function(r){return t.updateKnoraApiConnection(e.user.jwt),e.id=o,localStorage.setItem("session",JSON.stringify(e)),!0}),(function(e){return t.destroySession(),!1}))):(this.updateKnoraApiConnection(),!1)},t.prototype.updateSession=function(t,e){return!(!t||!e)&&(this.setSession(t,e,"username"),!0)},t.prototype.destroySession=function(){localStorage.removeItem("session")},t.prototype.updateKnoraApiConnection=function(t){this.knoraApiConfig.jsonWebToken=t||"",this.knoraApiConnection=new o.KnoraApiConnection(this.knoraApiConfig)},t.prototype.setTimestamp=function(){return b().add(0,"second").valueOf()},t.ctorParameters=function(){return[{type:o.KnoraApiConnection,decorators:[{type:e.Inject,args:[m]}]},{type:o.KnoraApiConfig,decorators:[{type:e.Inject,args:[d]}]}]},t.ngInjectableDef=e.ɵɵdefineInjectable({factory:function(){return new t(e.ɵɵinject(m),e.ɵɵinject(d))},token:t,providedIn:"root"}),t=c([e.Injectable({providedIn:"root"}),h(0,e.Inject(m)),h(1,e.Inject(d)),f("design:paramtypes",[o.KnoraApiConnection,o.KnoraApiConfig])],t)}(),S=function(){function t(){this.status=0,this.statusText="",this.url=""}return t.prototype.getBody=function(e){return t.jsonConvert.deserialize(this.body,e)},t.jsonConvert=new n.JsonConvert(n.OperationMode.ENABLE,n.ValueCheckingMode.ALLOW_NULL),t}(),k=function(){this.status=0,this.statusText="",this.url="",this.errorInfo=""},I=function(){function t(){}return t.KnoraVersion="12.0.0",t.KnoraApi="http://api.knora.org/ontology/knora-api",t.PathSeparator="#",t.KnoraApiV2SimplePath=t.KnoraApi+"/simple/v2"+t.PathSeparator,t.resourceSimple=t.KnoraApiV2SimplePath+"Resource",t.dateSimple=t.KnoraApiV2SimplePath+"Date",t.intervalSimple=t.KnoraApiV2SimplePath+"Interval",t.geomSimple=t.KnoraApiV2SimplePath+"Geom",t.colorSimple=t.KnoraApiV2SimplePath+"Color",t.geonameSimple=t.KnoraApiV2SimplePath+"Geoname",t.fileSimple=t.KnoraApiV2SimplePath+"File",t.listNodeSimple=t.KnoraApiV2SimplePath+"ListNode",t.EqualsComparisonOperator="=",t.EqualsComparisonLabel="is equal to",t.NotEqualsComparisonOperator="!=",t.NotEqualsComparisonLabel="is not equal to",t.GreaterThanComparisonOperator=">",t.GreaterThanComparisonLabel="is greater than",t.GreaterThanEqualsComparisonOperator=">=",t.GreaterThanEqualsComparisonLabel="is greater than equals to",t.LessThanComparisonOperator="<",t.LessThanComparisonLabel="is less than",t.LessThanEqualsComparisonOperator="<=",t.LessThanQualsComparisonLabel="is less than equals to",t.ExistsComparisonOperator="E",t.ExistsComparisonLabel="exists",t.LikeComparisonOperator="regex",t.LikeComparisonLabel="is like",t.MatchComparisonOperator="contains",t.MatchComparisonLabel="matches",t.MatchFunction=t.KnoraApi+"/v2"+t.PathSeparator+"match",t}();(g=t.KnoraSchema||(t.KnoraSchema={}))[g.complex=0]="complex",g[g.simple=1]="simple";var P,x=function(t){this.generateGravsearch=t},E=function(){function t(){this._currentSearchParams=new a.BehaviorSubject(new x((function(t){return!1})))}return t.prototype.changeSearchParamsMsg=function(t){this._currentSearchParams.next(t)},t.prototype.getSearchParams=function(){return this._currentSearchParams.getValue()},t.ngInjectableDef=e.ɵɵdefineInjectable({factory:function(){return new t},token:t,providedIn:"root"}),t=c([e.Injectable({providedIn:"root"}),f("design:paramtypes",[])],t)}(),A=function(){function r(t){this._searchParamsService=t}var n;return n=r,r.prototype.createGravsearchQuery=function(e,r,a){void 0===a&&(a=0);var i="";void 0!==r&&(i="?mainRes a <"+r+"> .");var s=[],p=[],l=e.map((function(e,r){var a;a=e.property.isLinkProperty&&"Exists"!==e.valueLiteral.comparisonOperator.getClassName()?e.valueLiteral.value.toSparql(t.KnoraSchema.complex):"?propVal"+r;var i="?mainRes <"+e.property.id+"> "+a+" .";e.property.isLinkProperty&&"NotEquals"===e.valueLiteral.comparisonOperator.getClassName()?i="FILTER NOT EXISTS {\n"+i+"\n\n\n}":(p.push(i),i="\n"+i+"\n\n\n");var l="";if(!e.property.isLinkProperty&&"Exists"!==e.valueLiteral.comparisonOperator.getClassName()){var u=a+"Literal";"Like"===e.valueLiteral.comparisonOperator.getClassName()?(l=a+" <"+n.complexTypeToProp[e.property.objectType]+"> "+u+"\n",l+="FILTER regex("+u+", "+e.valueLiteral.value.toSparql(t.KnoraSchema.complex)+', "i")'):"Match"===e.valueLiteral.comparisonOperator.getClassName()?(l=a+" <"+n.complexTypeToProp[e.property.objectType]+"> "+u+"\n",l+="FILTER <"+I.MatchFunction+">("+u+", "+e.valueLiteral.value.toSparql(t.KnoraSchema.complex)+")"):e.property.objectType===o.Constants.DateValue?l="FILTER(knora-api:toSimpleDate("+a+") "+e.valueLiteral.comparisonOperator.type+" "+e.valueLiteral.value.toSparql(t.KnoraSchema.complex)+")":e.property.objectType===o.Constants.ListValue?(l=a+" <"+n.complexTypeToProp[e.property.objectType]+"> "+e.valueLiteral.value.toSparql(t.KnoraSchema.complex)+"\n","NotEquals"===e.valueLiteral.comparisonOperator.getClassName()&&(l="FILTER NOT EXISTS {\n "+l+"\n }")):(l=a+" <"+n.complexTypeToProp[e.property.objectType]+"> "+u+"\n",l+="FILTER("+u+" "+e.valueLiteral.comparisonOperator.type+" "+e.valueLiteral.value.toSparql(t.KnoraSchema.complex)+")")}return e.isSortCriterion&&s.push(a),i+"\n"+l+"\n"})),u="";s.length>0&&(u="\nORDER BY "+s.join(" ")+"\n");var c="\nPREFIX knora-api: <http://api.knora.org/ontology/knora-api/v2#>\nCONSTRUCT {\n\n?mainRes knora-api:isMainResource true .\n\n"+p.join("\n")+"\n\n} WHERE {\n\n?mainRes a knora-api:Resource .\n\n"+i+"\n\n"+l.join("")+"\n\n}\n"+u,h="\nOFFSET "+a+"\n";return 0===a&&this._searchParamsService.changeSearchParamsMsg(new x((function(t){return c+("\nOFFSET "+t+"\n")}))),c+h},r.typeConversionComplexToSimple={"http://api.knora.org/ontology/knora-api/v2#IntValue":o.Constants.XsdInteger,"http://api.knora.org/ontology/knora-api/v2#DecimalValue":o.Constants.XsdDecimal,"http://api.knora.org/ontology/knora-api/v2#BooleanValue":o.Constants.XsdBoolean,"http://api.knora.org/ontology/knora-api/v2#TextValue":o.Constants.XsdString,"http://api.knora.org/ontology/knora-api/v2#UriValue":o.Constants.XsdAnyUri,"http://api.knora.org/ontology/knora-api/v2#DateValue":I.dateSimple,"http://api.knora.org/ontology/knora-api/v2#IntervalValue":I.intervalSimple,"http://api.knora.org/ontology/knora-api/v2#GeomValue":I.geomSimple,"http://api.knora.org/ontology/knora-api/v2#ColorValue":I.colorSimple,"http://api.knora.org/ontology/knora-api/v2#GeonameValue":I.geonameSimple,"http://api.knora.org/ontology/knora-api/v2#StillImageFileValue":I.fileSimple,"http://api.knora.org/ontology/knora-api/v2#FileValue":I.fileSimple,"http://api.knora.org/ontology/knora-api/v2#MovingImageFileValue":I.fileSimple,"http://api.knora.org/ontology/knora-api/v2#DDDFileValue":I.fileSimple,"http://api.knora.org/ontology/knora-api/v2#AudioFileValue":I.fileSimple,"http://api.knora.org/ontology/knora-api/v2#DocumentFileValue":I.fileSimple,"http://api.knora.org/ontology/knora-api/v2#TextFileValue":I.fileSimple,"http://api.knora.org/ontology/knora-api/v2#ListValue":I.listNodeSimple},r.complexTypeToProp={"http://api.knora.org/ontology/knora-api/v2#IntValue":o.Constants.IntValueAsInt,"http://api.knora.org/ontology/knora-api/v2#DecimalValue":o.Constants.DecimalValueAsDecimal,"http://api.knora.org/ontology/knora-api/v2#BooleanValue":o.Constants.BooleanValueAsBoolean,"http://api.knora.org/ontology/knora-api/v2#TextValue":o.Constants.ValueAsString,"http://api.knora.org/ontology/knora-api/v2#UriValue":o.Constants.UriValueAsUri,"http://api.knora.org/ontology/knora-api/v2#ListValue":o.Constants.ListValueAsListNode},r.ctorParameters=function(){return[{type:E}]},r.ngInjectableDef=e.ɵɵdefineInjectable({factory:function(){return new r(e.ɵɵinject(E))},token:r,providedIn:"root"}),r=n=c([e.Injectable({providedIn:"root"}),f("design:paramtypes",[E])],r)}(),T=function(){function t(){this.type=I.EqualsComparisonOperator,this.label=I.EqualsComparisonLabel}return t.prototype.getClassName=function(){return"Equals"},t}(),L=function(){function t(){this.type=I.NotEqualsComparisonOperator,this.label=I.NotEqualsComparisonLabel}return t.prototype.getClassName=function(){return"NotEquals"},t}(),j=function(){function t(){this.type=I.GreaterThanEqualsComparisonOperator,this.label=I.GreaterThanEqualsComparisonLabel}return t.prototype.getClassName=function(){return"GreaterThanEquals"},t}(),R=function(){function t(){this.type=I.GreaterThanComparisonOperator,this.label=I.GreaterThanComparisonLabel}return t.prototype.getClassName=function(){return"GreaterThan"},t}(),F=function(){function t(){this.type=I.LessThanComparisonOperator,this.label=I.LessThanComparisonLabel}return t.prototype.getClassName=function(){return"LessThan"},t}(),V=function(){function t(){this.type=I.LessThanEqualsComparisonOperator,this.label=I.LessThanQualsComparisonLabel}return t.prototype.getClassName=function(){return"LessThanEquals"},t}(),D=function(){function t(){this.type=I.ExistsComparisonOperator,this.label=I.ExistsComparisonLabel}return t.prototype.getClassName=function(){return"Exists"},t}(),K=function(){function t(){this.type=I.LikeComparisonOperator,this.label=I.LikeComparisonLabel}return t.prototype.getClassName=function(){return"Like"},t}(),q=function(){function t(){this.type=I.MatchComparisonOperator,this.label=I.MatchComparisonLabel}return t.prototype.getClassName=function(){return"Match"},t}(),M=function(t,e){this.comparisonOperator=t,this.value=e},N=function(){function e(t,e){this.value=t,this.type=e}return e.prototype.toSparql=function(e){var o;return o=e===t.KnoraSchema.simple&&void 0!==A.typeConversionComplexToSimple[this.type]?A.typeConversionComplexToSimple[this.type]:this.type,'"'+this.value+'"^^<'+o+">"},e}(),G=function(){function t(t){this.iri=t}return t.prototype.toSparql=function(t){return"<"+this.iri+">"},t}(),_=function(t,e,o){this.property=t,this.valueLiteral=e,this.isSortCriterion=o},U=function(){function t(){}return t.getOntologyIriFromEntityIri=function(t){var e=t.split(I.PathSeparator);return 2!==e.length&&console.error("Error: "+t+" is not a valid entity IRI."),e[0]},t.convertComplexKnoraApiEntityIritoSimple=function(t){var e=t.split("v2"+I.PathSeparator);return 2!==e.length&&console.error("Error: "+t+" is not a valid entity IRI."),e[0]+"simple/v2"+I.PathSeparator+e[1]},t.RegexEmail=/^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i,t.RegexUsername=/^[a-zA-Z0-9]+$/,t.RegexUrl=/^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}(:[0-9]{1,5})?(\/.*)?$/i,t.RegexPassword=/^(?=.*\d)(?=.*[a-zA-Z]).{8,}$/i,t.RegexHex=/^[0-9A-Fa-f]+$/,t.RegexShortname=/^[a-zA-Z]+\S*$/,t.filterOutDuplicates=function(t,e,o){return e===o.indexOf(t)},t}(),H=function(){function t(t){this.regionResource=t}return t.prototype.getGeometries=function(){return this.regionResource.properties[o.Constants.HasGeometry]},t}(),X=require("jsonld"),J=require("semver"),W=function(){function t(t,e){this.http=t,this.knoraApiConfig=e,this.loading=!1}return t.prototype.httpGet=function(t,e){var o=this;this.loading=!0;var r=this.setHeaders();return this.http.get(this.knoraApiConfig.apiUrl+t,{headers:r,observe:"response",params:e}).pipe(p.map((function(e){o.loading=!1;var r=new S;return r.header={server:e.headers.get("Server")},o.compareVersion(e.headers.get("Server")),r.status=e.status,r.statusText=e.statusText,r.url=t,r.body=e.body,r})),p.catchError((function(t){return o.loading=!1,o.handleRequestError(t)})))},t.prototype.processJSONLD=function(t){var e=X.promises.compact(t.body,{});return a.from(e)},t.prototype.httpPost=function(t,e){var o=this;this.loading=!0;var r=this.setHeaders();return this.http.post(this.knoraApiConfig.apiUrl+t,e,{headers:r,observe:"response"}).pipe(p.map((function(e){o.loading=!1;var r=new S;return r.header={server:e.headers.get("Server")},o.compareVersion(r.header.server),r.status=e.status,r.statusText=e.statusText,r.url=t,r.body=e.body,r})),p.catchError((function(t){return o.loading=!1,o.handleRequestError(t)})))},t.prototype.httpPut=function(t,e){var o=this;this.loading=!0;var r=this.setHeaders();return this.http.put(this.knoraApiConfig.apiUrl+t,e,{headers:r,observe:"response"}).pipe(p.map((function(e){o.loading=!1;var r=new S;return r.header={server:e.headers.get("Server")},o.compareVersion(r.header.server),r.status=e.status,r.statusText=e.statusText,r.url=t,r.body=e.body,r})),p.catchError((function(t){return o.loading=!1,o.handleRequestError(t)})))},t.prototype.httpDelete=function(t){var e=this;this.loading=!0;var o=this.setHeaders();return this.http.delete(this.knoraApiConfig.apiUrl+t,{headers:o,observe:"response"}).pipe(p.map((function(o){e.loading=!1;var r=new S;return r.header={server:o.headers.get("Server")},e.compareVersion(r.header.server),r.status=o.status,r.statusText=o.statusText,r.url=t,r.body=o.body,r})),p.catchError((function(t){return e.loading=!1,e.handleRequestError(t)})))},t.prototype.handleRequestError=function(t){var e=new k;return e.header={server:t.headers.get("Server")},e.status=t.status,e.statusText=t.statusText,e.errorInfo=t.message,e.url=t.url,s.throwError(e)},t.prototype.handleJsonError=function(t){if(t instanceof k)return s.throwError(t);var e=new k;return e.header={server:t.headers.get("Server")},e.status=-1,e.statusText="Invalid JSON",e.errorInfo=t,e.url="",s.throwError(e)},t.prototype.compareVersion=function(t){var e=I.KnoraVersion;if(t){var o=t.split(" ")[0].split("/")[1];"major"===J.diff(o,e)&&console.warn("The version of the /core module works with Knora v"+e+", but you are using it with Knora v"+o)}},t.prototype.setHeaders=function(){var t=JSON.parse(localStorage.getItem("session"));return t&&null!==t?new i.HttpHeaders({Authorization:"Bearer "+t.user.jwt}):new i.HttpHeaders},t.ctorParameters=function(){return[{type:i.HttpClient},{type:o.KnoraApiConfig,decorators:[{type:e.Inject,args:[d]}]}]},t.ngInjectableDef=e.ɵɵdefineInjectable({factory:function(){return new t(e.ɵɵinject(i.HttpClient),e.ɵɵinject(d))},token:t,providedIn:"root"}),t=c([e.Injectable({providedIn:"root"}),h(1,e.Inject(d)),f("design:paramtypes",[i.HttpClient,o.KnoraApiConfig])],t)}(),B=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return u(r,t),r.prototype.getOntologiesMetadata=function(){return this.httpGet("/v2/ontologies/metadata")},r.prototype.getAllOntologies=function(){return this.httpGet("/v2/ontologies/metadata")},r.prototype.getProjectOntologies=function(t){return this.httpGet("/v2/ontologies/metadata/"+encodeURIComponent(t))},r.prototype.getAllEntityDefinitionsForOntologies=function(t){return this.httpGet("/v2/ontologies/allentities/"+encodeURIComponent(t))},r.prototype.getResourceClasses=function(t){if(0===t.length)return a.Observable.create((function(t){return t.error("No resource class Iris given for call of OntologyService.getResourceClasses")}));var e="";return t.forEach((function(t){e=e+"/"+encodeURIComponent(t.toString())})),this.httpGet("/v2/ontologies/classes"+e)},r.prototype.getProperties=function(t){if(0===t.length)return a.Observable.create((function(t){return t.error("No property Iris given for call of OntologyService.getProperties")}));var e="";return t.forEach((function(t){e=e+"/"+encodeURIComponent(t.toString())})),this.httpGet("/v2/ontologies/properties"+e)},r.prototype.createOntology=function(t){var e={"knora-api:ontologyName":t.name,"knora-api:attachedToProject":{"@id":t.projectIri},"rdfs:label":t.label,"@context":{rdfs:o.Constants.Rdfs+o.Constants.Delimiter,"knora-api":o.Constants.KnoraApiV2+o.Constants.Delimiter}};return this.httpPost("/v2/ontologies",e).pipe(p.map((function(t){return t.body})),p.catchError(this.handleJsonError))},r.prototype.createResourceClass=function(t){var e={"@id":void 0,"@type":"owl:Ontology","knora-api:lastModificationDate":void 0,"@graph":[{"@id":void 0+":"+t.name,"@type":"owl:Class","rdfs:label":t.labels,"rdfs:comment":t.comments,"rdfs:subClassOf":{"@id":t.subClassOf}}],"@context":{rdf:"http://www.w3.org/1999/02/22-rdf-syntax-ns#","knora-api":"http://api.knora.org/ontology/knora-api/v2#",owl:"http://www.w3.org/2002/07/owl#",rdfs:"http://www.w3.org/2000/01/rdf-schema#",xsd:"http://www.w3.org/2001/XMLSchema#",onto_name:void 0+"#"}};return this.httpPost("/v2/ontologies/classes",e).pipe(p.map((function(t){return t.body})),p.catchError(this.handleJsonError))},r.prototype.createProperty=function(t){var e,o,r=[];try{for(var n=y(t),a=n.next();!a.done;a=n.next()){var i=a.value,s={"@id":void 0+":"+i.name,"@type":"owl:ObjectProperty","rdfs:label":i.labels,"rdfs:comment":i.comments,"rdfs:subPropertyOf":i.subPropertyOf,"salsah-gui:guiElement":{"@id":i.guiElement}};r.push(s)}}catch(t){e={error:t}}finally{try{a&&!a.done&&(o=n.return)&&o.call(n)}finally{if(e)throw e.error}}var l={"@id":void 0,"@type":"owl:Ontology","knora-api:lastModificationDate":void 0,"@graph":[r],"@context":{rdf:"http://www.w3.org/1999/02/22-rdf-syntax-ns#","knora-api":"http://api.knora.org/ontology/knora-api/v2#","salsah-gui":"http://api.knora.org/ontology/salsah-gui/v2#",owl:"http://www.w3.org/2002/07/owl#",rdfs:"http://www.w3.org/2000/01/rdf-schema#",xsd:"http://www.w3.org/2001/XMLSchema#",onto_name:void 0+"#"}};return this.httpPost("/v2/ontologies/properties",l).pipe(p.map((function(t){return t.body})),p.catchError(this.handleJsonError))},r.prototype.setCardinality=function(t){var e={"@id":void 0,"@type":"owl:Ontology","knora-api:lastModificationDate":void 0,"@graph":[{"@id":void 0,"@type":"owl:Class","rdfs:subClassOf":{"@type":"owl:Restriction","owl:onProperty":{"@id":void 0}}}],"@context":{rdf:"http://www.w3.org/1999/02/22-rdf-syntax-ns#","knora-api":"http://api.knora.org/ontology/knora-api/v2#",owl:"http://www.w3.org/2002/07/owl#",rdfs:"http://www.w3.org/2000/01/rdf-schema#",xsd:"http://www.w3.org/2001/XMLSchema#",onto_name:void 0+"#"}};return this.httpPost("/v2/ontologies/cardinalities",e).pipe(p.map((function(t){return t.body})),p.catchError(this.handleJsonError))},r.ngInjectableDef=e.ɵɵdefineInjectable({factory:function(){return new r(e.ɵɵinject(i.HttpClient),e.ɵɵinject(d))},token:r,providedIn:"root"}),r=c([e.Injectable({providedIn:"root"})],r)}(W),z=require("jsonld"),$=function(t){function e(e){var o=t.call(this,e)||this;return o.message=e,o}return u(e,t),e}(Error),Q=function(t,e){this.id=t,this.label=e};(P=t.CardinalityOccurrence||(t.CardinalityOccurrence={}))[P.minCard=0]="minCard",P[P.card=1]="card",P[P.maxCard=2]="maxCard";var Z=function(t,e,o){this.occurrence=t,this.value=e,this.property=o},Y=function(t,e){this.value=t,this.property=e},tt=function(t,e,o,r,n,a){this.id=t,this.icon=e,this.comment=o,this.label=r,this.cardinalities=n,this.guiOrder=a},et=function(){},ot=function(t,e,o,r,n,a,i,s,p){this.id=t,this.objectType=e,this.comment=o,this.label=r,this.subPropertyOf=n,this.isEditable=a,this.isLinkProperty=i,this.isLinkValueProperty=s,this.guiAttribute=p},rt=function(){},nt=function(){},at=function(){this.ontologies=[],this.resourceClassIrisForOntology=new nt,this.resourceClasses=new et,this.properties=new rt},it=function(){function t(t,e,o){this.resourceClassesForOntology=t,this.resourceClasses=e,this.properties=o}return t.sortFunc=function(t,e){if(void 0===t.label)return 1;if(void 0===e.label)return-1;var o=t.label.toLowerCase(),r=e.label.toLowerCase();return o<r?-1:o>r?1:0},t.prototype.updateOntologyInformation=function(t){var e=t.getResourceClassForOntology();for(var o in e)this.resourceClassesForOntology[o]=e[o];var r=t.getResourceClasses();for(var n in r)this.resourceClasses[n]=r[n];var a=t.getProperties();for(var i in a)this.properties[i]=a[i]},t.prototype.getResourceClassForOntology=function(){return this.resourceClassesForOntology},t.prototype.getResourceClasses=function(){return this.resourceClasses},t.prototype.getResourceClassesAsArray=function(e){void 0===e&&(e=!0);var o=[];for(var r in this.resourceClasses){var n=this.resourceClasses[r];o.push(n)}return o.sort(t.sortFunc),e||o.reverse(),o},t.prototype.getLabelForResourceClass=function(t){if(void 0!==t){var e=this.resourceClasses[t];if(void 0!==e&&void 0!==e.label)return e.label;console.log("cannot get label for "+t)}else console.log("call of OntologyInformation.getLabelForResourceClass without argument resClass")},t.prototype.getProperties=function(){return this.properties},t.prototype.getPropertiesAsArray=function(e){void 0===e&&(e=!0);var o=[];for(var r in this.properties){var n=this.properties[r];o.push(n)}return o.sort(t.sortFunc),e||o.reverse(),o},t.prototype.getLabelForProperty=function(t){if(void 0!==t){var e=this.properties[t];if(void 0!==e&&void 0!==e.label)return e.label;console.log("cannot get label for "+t)}else console.log("call of OntologyInformation.getLabelForProperty without argument property")},t}(),st=function(){function r(t){this._ontologyService=t,this.excludedOntologies=[o.Constants.SalsahGui,o.Constants.StandoffOntology],this.excludedProperties=[o.Constants.Label],this.nonResourceClasses=[o.Constants.ForbiddenResource,o.Constants.XMLToStandoffMapping,o.Constants.ListNode],this.cacheOntology=new at}return r.prototype.getOntologiesMetadataFromKnora=function(){return this._ontologyService.getOntologiesMetadata().pipe(p.mergeMap((function(t){var e=z.promises.compact(t.body,{});return a.from(e)})))},r.prototype.getAllEntityDefinitionsForOntologyFromKnora=function(t){return this._ontologyService.getAllEntityDefinitionsForOntologies(t).pipe(p.mergeMap((function(t){var e=z.promises.compact(t.body,{});return a.from(e)})))},r.prototype.convertAndWriteOntologiesMetadataToCache=function(t){this.cacheOntology.ontologies=t.map((function(t){return new Q(t["@id"],t[o.Constants.Label])}))},r.prototype.getAllOntologiesMetadataFromCache=function(){return this.cacheOntology.ontologies},r.prototype.getResourceClassIrisFromOntologyResponse=function(t){var e,r,n=[];try{for(var a=y(t),i=a.next();!i.done;i=a.next()){var s=i.value,p=s["@id"];p!==o.Constants.Resource&&-1===this.nonResourceClasses.indexOf(p)&&void 0!==s[o.Constants.IsResourceClass]&&!0===s[o.Constants.IsResourceClass]&&n.push(p)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}return n},r.prototype.convertAndWriteAllEntityDefinitionsForOntologyToCache=function(t){var e=t["@graph"],r=e.filter((function(t){return t["@type"]===o.Constants.Class})),n=e.filter((function(t){var e=t["@type"];return e===o.Constants.ObjectProperty||e===o.Constants.DataTypeProperty||e===o.Constants.Owl+o.Constants.Delimiter+"AnnotationProperty"||e===o.Constants.RdfProperty}));this.cacheOntology.resourceClassIrisForOntology[t["@id"]]=this.getResourceClassIrisFromOntologyResponse(r),this.convertAndWriteEntityDefinitionsToCache(r,n)},r.prototype.getOntologyInformationFromCache=function(t){var e,o,r=new nt,n=[];try{for(var a=y(t),i=a.next();!i.done;i=a.next()){var s=i.value;if(void 0===this.cacheOntology.resourceClassIrisForOntology[s])throw new $("getResourceClassesForOntologiesFromCache: ontology not found in cache: "+s);r[s]=this.cacheOntology.resourceClassIrisForOntology[s],n=n.concat(this.cacheOntology.resourceClassIrisForOntology[s])}}catch(t){e={error:t}}finally{try{i&&!i.done&&(o=a.return)&&o.call(a)}finally{if(e)throw e.error}}return this.getResourceClassDefinitions(n).pipe(p.map((function(t){return new it(r,t.getResourceClasses(),t.getProperties())})))},r.prototype.convertAndWriteEntityDefinitionsToCache=function(e,r){var n,a,i,s;try{for(var p=y(e),l=p.next();!l.done;l=p.next()){var u=l.value,c=u["@id"],h=[],f=[];if(void 0!==u[o.Constants.SubClassOf]){var g=void 0;g=Array.isArray(u[o.Constants.SubClassOf])?u[o.Constants.SubClassOf]:[u[o.Constants.SubClassOf]];try{for(var d=y(g),m=d.next();!m.done;m=d.next()){var v=m.value;if(v instanceof Object&&void 0!==v["@type"]&&v["@type"]===o.Constants.Restriction){var C=void 0;if(void 0!==v[o.Constants.MinCardinality])C=new Z(t.CardinalityOccurrence.minCard,v[o.Constants.MinCardinality],v[o.Constants.OnProperty]["@id"]);else if(void 0!==v[o.Constants.Cardinality])C=new Z(t.CardinalityOccurrence.card,v[o.Constants.Cardinality],v[o.Constants.OnProperty]["@id"]);else{if(void 0===v[o.Constants.MaxCardinality])throw new TypeError("cardinality type invalid for "+u["@id"]+" "+v[o.Constants.OnProperty]);C=new Z(t.CardinalityOccurrence.maxCard,v[o.Constants.MaxCardinality],v[o.Constants.OnProperty]["@id"])}h.push(C);var O=void 0;void 0!==v[o.Constants.GuiOrder]&&(O=new Y(v[o.Constants.GuiOrder],v[o.Constants.OnProperty]["@id"]),f.push(O))}}}catch(t){i={error:t}}finally{try{m&&!m.done&&(s=d.return)&&s.call(d)}finally{if(i)throw i.error}}}var b=new tt(c,u[o.Constants.ResourceIcon],u[o.Constants.Comment],u[o.Constants.Label],h,f);this.cacheOntology.resourceClasses[c]=b}}catch(t){n={error:t}}finally{try{l&&!l.done&&(a=p.return)&&a.call(p)}finally{if(n)throw n.error}}this.convertAndWriteKnoraPropertyDefinitionsToOntologyCache(r)},r.prototype.getResourceClassDefinitionsFromCache=function(t){var e=this,o=new et,r=[];return t.forEach((function(t){o[t]=e.cacheOntology.resourceClasses[t],e.cacheOntology.resourceClasses[t].cardinalities.forEach((function(t){r.push(t.property)}))})),this.getPropertyDefinitions(r).pipe(p.map((function(t){return new it(new nt,o,t.getProperties())})))},r.prototype.convertAndWriteKnoraPropertyDefinitionsToOntologyCache=function(t){var e,r,n,a;try{for(var i=y(t),s=i.next();!s.done;s=i.next()){var p=s.value,l=p["@id"],u=!1;void 0!==p[o.Constants.IsEditable]&&!0===p[o.Constants.IsEditable]&&(u=!0);var c=!1;void 0!==p[o.Constants.IsLinkProperty]&&!0===p[o.Constants.IsLinkProperty]&&(c=!0);var h=!1;void 0!==p[o.Constants.IsLinkValueProperty]&&!0===p[o.Constants.IsLinkValueProperty]&&(h=!0);var f=[];void 0!==p[o.Constants.SubPropertyOf]&&Array.isArray(p[o.Constants.SubPropertyOf])?f=p[o.Constants.SubPropertyOf].map((function(t){return t["@id"]})):void 0!==p[o.Constants.SubPropertyOf]&&f.push(p[o.Constants.SubPropertyOf]["@id"]);var g=void 0;void 0!==p[o.Constants.ObjectType]&&(g=p[o.Constants.ObjectType]["@id"]);var d=[];if(void 0!==p[o.Constants.GuiAttribute])if(Array.isArray(p[o.Constants.GuiAttribute]))try{for(var m=y(p[o.Constants.GuiAttribute]),v=m.next();!v.done;v=m.next()){var C=v.value;d.push(C)}}catch(t){n={error:t}}finally{try{v&&!v.done&&(a=m.return)&&a.call(m)}finally{if(n)throw n.error}}else d.push(p[o.Constants.GuiAttribute]);this.cacheOntology.properties[l]=new ot(l,g,p[o.Constants.Comment],p[o.Constants.Label],f,u,c,h,d)}}catch(t){e={error:t}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}},r.prototype.getPropertyDefinitionsFromCache=function(t){var e=this,o=new rt;return t.forEach((function(t){if(!(e.excludedProperties.indexOf(t)>-1)){if(void 0===e.cacheOntology.properties[t])throw new $("getPropertyDefinitionsFromCache: property not found in cache: "+t);o[t]=e.cacheOntology.properties[t]}})),new it(new nt,new et,o)},r.prototype.getOntologiesMetadata=function(){var t=this;return 0===this.cacheOntology.ontologies.length?this.getOntologiesMetadataFromKnora().pipe(p.map((function(e){return t.convertAndWriteOntologiesMetadataToCache(e["@graph"].filter((function(e){return-1===t.excludedOntologies.indexOf(e["@id"])}))),t.getAllOntologiesMetadataFromCache()}))):a.of(this.getAllOntologiesMetadataFromCache())},r.prototype.getAndCacheOntologies=function(t){var e=this,o=[];return t.forEach((function(t){o.push(e.getAllEntityDefinitionsForOntologyFromKnora(t).pipe(p.map((function(t){e.convertAndWriteAllEntityDefinitionsForOntologyToCache(t)}))))})),a.forkJoin(o)},r.prototype.getEntityDefinitionsForOntologies=function(t){var e=this,o=t.filter((function(t){return void 0===e.cacheOntology.resourceClassIrisForOntology[t]}));return o.length>0?this.getAndCacheOntologies(o).pipe(p.mergeMap((function(){return e.getOntologyInformationFromCache(t)}))):this.getOntologyInformationFromCache(t)},r.prototype.getResourceClassDefinitions=function(t){var e=this,o=t.filter((function(t){return void 0===e.cacheOntology.resourceClasses[t]}));if(o.length>0){var r=o.map((function(t){return U.getOntologyIriFromEntityIri(t)})).filter(U.filterOutDuplicates);return this.getAndCacheOntologies(r).pipe(p.mergeMap((function(){return e.getResourceClassDefinitionsFromCache(t)})))}return this.getResourceClassDefinitionsFromCache(t)},r.prototype.getPropertyDefinitions=function(t){var e=this,o=t.filter((function(t){return!(e.excludedProperties.indexOf(t)>-1)&&void 0===e.cacheOntology.properties[t]}));if(o.length>0){var r=o.map((function(t){return U.getOntologyIriFromEntityIri(t)})).filter(U.filterOutDuplicates);return this.getAndCacheOntologies(r).pipe(p.map((function(o){if(o)return e.getPropertyDefinitionsFromCache(t);throw new Error("Problem with: return this.getPropertyDefinitionsFromCache(propertyIris);")})))}return a.of(this.getPropertyDefinitionsFromCache(t))},r.ctorParameters=function(){return[{type:B}]},r.ngInjectableDef=e.ɵɵdefineInjectable({factory:function(){return new r(e.ɵɵinject(B))},token:r,providedIn:"root"}),r=c([e.Injectable({providedIn:"root"}),f("design:paramtypes",[B])],r)}();t.ApiService=W,t.ApiServiceError=k,t.ApiServiceResult=S,t.Cardinality=Z,t.ComparisonOperatorAndValue=M,t.Equals=T,t.Exists=D,t.ExtendedSearchParams=x,t.GravsearchGenerationService=A,t.GreaterThan=R,t.GreaterThanEquals=j,t.GuiOrder=Y,t.IRI=G,t.KnoraApiConfigToken=d,t.KnoraApiConnectionToken=m,t.KnoraConstants=I,t.KuiConfig=O,t.KuiConfigToken=v,t.KuiCoreModule=C,t.LessThan=F,t.LessThanEquals=V,t.Like=K,t.Match=q,t.NotEquals=L,t.OntologyCacheService=st,t.OntologyInformation=it,t.OntologyMetadata=Q,t.OntologyService=B,t.Properties=rt,t.Property=ot,t.PropertyWithValue=_,t.Region=H,t.ResourceClass=tt,t.ResourceClassIrisForOntology=nt,t.ResourceClasses=et,t.SearchParamsService=E,t.SessionService=w,t.Utils=U,t.ValueLiteral=N,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=knora-core.umd.min.js.map