Skip to content

Commit

Permalink
flexible endpoint url, override ontology notation
Browse files Browse the repository at this point in the history
  • Loading branch information
StiftungAusNachlass committed Aug 1, 2023
1 parent 3617c4f commit 2e7453d
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 37 deletions.
3 changes: 3 additions & 0 deletions l10n/customDataTypeGfbio.csv
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ custom.data.type.gfbio.modal.form.popup.choose_expertsearchmode_.include_childre
custom.data.type.gfbio.modal.form.popup.choose_expertsearchmode_label,Suchmodus für Expertensuche wählen,Select search mode for expert search
custom.data.type.gfbio.modal.form.popup.choose_expertsearchmode_label2,Was wollen Sie finden? Nur exakte Treffer oder auch alle Kinder und Kindeskinder ihrer Suchauswahl?,What do you want to find? Only exact hits or also all children and grandchildren in your search selection?
custom.data.type.gfbio.modal.form.popup.choose_expertsearchmode_label3,Ausgewählt,Selected
server.config.name.system.endpointurl,API-URL,API-URL
server.config.parameter.system.endpointurl.endpointurl.label,API-URL,API-URL
custom.data.type.commons.popover.choose.label,Auswahl treffen,choose
custom.data.type.commons.modal.form.popup.loadingstring,Lade Informationen,loading
custom.data.type.commons.controls.search.label,Suchen,Search
custom.data.type.commons.controls.detailinfo.label,Detailinfo, Details
custom.data.type.commons.controls.calluri.label,Uri aufrufen,Call URI
custom.data.type.commons.controls.delete.label,Löschen,Delete
custom.data.type.gfbio.config.parameter.mask.overwrite_ontology_configuration.value.label,Ontology-Konfiguration aus Schema überschreiben,Overwrite ontology-configuration from schema
14 changes: 12 additions & 2 deletions manifest.master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ custom_types:
value:
type: select
options: ["popover", "popover_treeview"]
- name: overwrite_ontology_configuration
parameters:
value:
type: text
update:
exec:
service: "node"
Expand All @@ -59,17 +63,23 @@ custom_types:
expires_days: 1
interval_base_config: update_interval_gfbio.days
base_config:
- name: endpointurl
group: endpointurl
parameters:
endpointurl:
type: text
position: 0
- name: apikey
group: apikey
parameters:
apikey:
type: text
position: 0
position: 1
- name: update_interval_gfbio
group: update_custom_data_type
parameters:
days:
type: int
min: 0
default: 0
position: 0
position: 2
59 changes: 34 additions & 25 deletions src/updater/GFBIOUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const fetch = (...args) => import('node-fetch').then(({
let databaseLanguages = [];
let frontendLanguages = [];
let gfbio_apikey = '';
let endpointurl = '';


function hasChanges(objectOne, objectTwo) {
Expand Down Expand Up @@ -49,8 +50,8 @@ main = (payload) => {
let requests = [];

URIList.forEach((uri) => {
let dataRequestUrl = 'https://data.bioontology.org/ontologies/' + GFBIOUtilities.getVocNotationFromURI(uri) + '/classes/' + encodeURIComponent(uri) + '?apikey=' + gfbio_apikey
let hierarchieRequestUrl = 'https://data.bioontology.org/ontologies/' + GFBIOUtilities.getVocNotationFromURI(uri) + '/classes/' + encodeURIComponent(uri) + '/ancestors' + '?apikey=' + gfbio_apikey
let dataRequestUrl = endpointurl + '/ontologies/' + GFBIOUtilities.getVocNotationFromURI(uri) + '/classes/' + encodeURIComponent(uri) + '?apikey=' + gfbio_apikey
let hierarchieRequestUrl = endpointurl + '/ontologies/' + GFBIOUtilities.getVocNotationFromURI(uri) + '/classes/' + encodeURIComponent(uri) + '/ancestors' + '?apikey=' + gfbio_apikey

let dataRequest = fetch(dataRequestUrl);
let hierarchieRequest = fetch(hierarchieRequestUrl);
Expand Down Expand Up @@ -113,8 +114,6 @@ main = (payload) => {
let cdataList = [];
payload.objects.forEach((result, index) => {
let originalCdata = payload.objects[index].data;
//console.error("originalCdata");
//console.error(originalCdata);
let newCdata = {};
let originalURI = originalCdata.conceptURI;

Expand Down Expand Up @@ -153,29 +152,31 @@ main = (payload) => {
// ancestors
if (matchingRecordHierarchy.requestType == 'broader') {
let hierarchyJSON = matchingRecordHierarchy.data
// save ancestors if treeview, add ancestors
newCdata.conceptAncestors = [];
if (hierarchyJSON) {
// save ancestors if treeview, add ancestors
newCdata.conceptAncestors = [];

for (hierarchyKey = i = 0, len = hierarchyJSON.length; i < len; hierarchyKey = ++i) {
hierarchyValue = hierarchyJSON[hierarchyKey];
if (hierarchyKey !== resultJSON['@id']) {
newCdata.conceptAncestors.push(hierarchyValue['@id']);
for (hierarchyKey = i = 0, len = hierarchyJSON.length; i < len; hierarchyKey = ++i) {
hierarchyValue = hierarchyJSON[hierarchyKey];
if (hierarchyKey !== resultJSON['@id']) {
newCdata.conceptAncestors.push(hierarchyValue['@id']);
}
}
}

// add own uri to ancestor-uris
newCdata.conceptAncestors.push(resultJSON['@id']);

// merge ancestors to string
newCdata.conceptAncestors = newCdata.conceptAncestors.join(' ');
// add own uri to ancestor-uris
newCdata.conceptAncestors.push(resultJSON['@id']);

//console.error("newCdata");
//console.error(newCdata);
// merge ancestors to string
newCdata.conceptAncestors = newCdata.conceptAncestors.join(' ');
}

if (hasChanges(payload.objects[index].data, newCdata)) {
//console.error("_________________________has changes!!________________");
payload.objects[index].data = newCdata;
} else {}
if (newCdata.conceptURI) {
if (hasChanges(payload.objects[index].data, newCdata)) {
console.error("_________________________has changes!!________________");
payload.objects[index].data = newCdata;
}
} else {
console.error("_________________________updatedata is empty!!________________");
}
}
} else {
console.error('No matching record found');
Expand Down Expand Up @@ -237,6 +238,13 @@ outputErr = (err2) => {
// apikey from baseconfig
gfbio_apikey = config.config['plugin']['custom-data-type-gfbio'].config.apikey.apikey;

// endpointurl from baseconfig
endpointurl = config.config['plugin']['custom-data-type-gfbio'].config.endpointurl.endpointurl;

if (endpointurl.charAt(endpointurl.length - 1) === '/') {
endpointurl = endpointurl.slice(0, -1);
}

// database-languages
databaseLanguages = config.config.system.config.languages.database;
databaseLanguages = databaseLanguages.map((value, key, array) => {
Expand All @@ -249,14 +257,15 @@ outputErr = (err2) => {
////////////////////////////////////////////////////////////////////////////
// availabilityCheck for gfbio-api
////////////////////////////////////////////////////////////////////////////
https.get('https://data.bioontology.org/ontologies/NCBITAXON?apikey=' + gfbio_apikey, res => {
let testURL = endpointurl + '/ontologies/ITIS?apikey=' + gfbio_apikey;
https.get(testURL, res => {
let testData = [];
res.on('data', chunk => {
testData.push(chunk);
});
res.on('end', () => {
const testVocab = JSON.parse(Buffer.concat(testData).toString());
if (testVocab.acronym == 'NCBITAXON') {
if (testVocab.acronym == 'ITIS') {
////////////////////////////////////////////////////////////////////////////
// test successfull --> continue with custom-data-type-update
////////////////////////////////////////////////////////////////////////////
Expand Down
28 changes: 22 additions & 6 deletions src/webfrontend/CustomDataTypeGFBIO.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class CustomDataTypeGFBIO extends CustomDataTypeWithCommons
#######################################################################
# returns name of the given vocabulary from datamodel
getVocabularyNameFromDatamodel: (opts = {}) ->
# if vocnotation is given in mask, use from masksettings
fromMask = @getCustomMaskSettings()?.overwrite_ontology_configuration?.value
if fromMask
return fromMask

# else use from datamodel-config
vocNotation = @getCustomSchemaSettings().vocabulary_notation?.value
return vocNotation

Expand All @@ -55,6 +61,15 @@ class CustomDataTypeGFBIO extends CustomDataTypeWithCommons
apikey = baseConfig?.apikey?.apikey
return apikey

#######################################################################
# returns api-key from baseconfig
getApiEndpointFromBaseconfig: ->
baseConfig = ez5.session.getBaseConfig("plugin", "custom-data-type-gfbio")
endpointurl = baseConfig?.endpointurl?.endpointurl
if endpointurl.charAt(endpointurl.length - 1) == '/'
endpointurl = endpointurl.slice(0, -1)
return endpointurl

#######################################################################
# returns name of the needed or configures language for the labels of api-requests
getLanguageParameterForRequests: () ->
Expand Down Expand Up @@ -309,7 +324,7 @@ class CustomDataTypeGFBIO extends CustomDataTypeWithCommons
vocParameter = that.getActiveVocabularyName(cdata)

# start request
url = 'https://data.bioontology.org/search?q=' + gfbio_searchstring + '&ontologies=' + vocParameter + '&apikey=' + that.getApiKeyFromBaseconfig() + '&suggest=true&pagesize=' + gfbio_countSuggestions
url = that.getApiEndpointFromBaseconfig() + '/search?q=' + gfbio_searchstring + '&ontologies=' + vocParameter + '&apikey=' + that.getApiKeyFromBaseconfig() + '&suggest=true&pagesize=' + gfbio_countSuggestions
searchsuggest_xhr.xhr = new (CUI.XHR)(url: url)
searchsuggest_xhr.xhr.start().done((data, status, statusText) ->

Expand Down Expand Up @@ -450,7 +465,7 @@ class CustomDataTypeGFBIO extends CustomDataTypeWithCommons
uriInfoParts = searchUri.split('@')
searchUri = uriInfoParts[0]
vocNotation = uriInfoParts[1]
allDataAPIPath = 'https://data.bioontology.org/ontologies/' + vocNotation + '/classes/' + encodeURIComponent(searchUri) + '?apikey=' + that.getApiKeyFromBaseconfig()
allDataAPIPath = that.getApiEndpointFromBaseconfig() + '/ontologies/' + vocNotation + '/classes/' + encodeURIComponent(searchUri) + '?apikey=' + that.getApiKeyFromBaseconfig()
# XHR for basic information
dataEntry_xhr = new (CUI.XHR)(url: allDataAPIPath)
dataEntry_xhr.start().done((resultJSON, status, statusText) ->
Expand Down Expand Up @@ -577,7 +592,7 @@ class CustomDataTypeGFBIO extends CustomDataTypeWithCommons
splittedVocs = that.getVocabularyNameFromDatamodel()
splittedVocs = splittedVocs.split(',')
if splittedVocs.includes vocNotation
allDataAPIPath = 'https://data.bioontology.org/ontologies/' + vocNotation + '/classes/' + uri + '?apikey=' + that.getApiKeyFromBaseconfig()
allDataAPIPath = that.getApiEndpointFromBaseconfig() + '/ontologies/' + vocNotation + '/classes/' + uri + '?apikey=' + that.getApiKeyFromBaseconfig()
extendedInfo_xhr.xhr = new (CUI.XHR)(url: allDataAPIPath)
extendedInfo_xhr.xhr.start()
.done((resultJSON, status, statusText) ->
Expand Down Expand Up @@ -614,7 +629,8 @@ class CustomDataTypeGFBIO extends CustomDataTypeWithCommons
vocParameter = vocParameter[0]

apikey = that.getApiKeyFromBaseconfig()
treeview = new GFBIO_ListViewTree(popover, layout, cdata, cdata_form, that, opts, vocParameter, apikey)
endpointurl = that.getApiEndpointFromBaseconfig()
treeview = new GFBIO_ListViewTree(popover, layout, cdata, cdata_form, that, opts, vocParameter, apikey, endpointurl)

# maybe deferred is wanted?
if returnDfr == false
Expand Down Expand Up @@ -734,7 +750,7 @@ class CustomDataTypeGFBIO extends CustomDataTypeWithCommons
#for uri in items
vocnotation = items[0]
originalDANTEUri = uri
uri = 'https://data.bioontology.org/ontologies/' + vocnotation + '?apikey=' + that.getApiKeyFromBaseconfig()
uri = that.getApiEndpointFromBaseconfig() + '/ontologies/' + vocnotation + '?apikey=' + that.getApiKeyFromBaseconfig()
deferred = new CUI.Deferred()
extendedInfo_xhr = new (CUI.XHR)(url: uri)
extendedInfo_xhr.start()
Expand Down Expand Up @@ -839,7 +855,7 @@ class CustomDataTypeGFBIO extends CustomDataTypeWithCommons
class: "pluginResultButton"
appearance: "link"
size: "normal"
href: 'https://uri.gbv.de/terminology/?uri=' + encodedURI
href: that.getApiEndpointFromBaseconfig() + '/?uri=' + encodedURI
target: "_blank"
class: "cdt_gfbio_smallMarginTop"
tooltip:
Expand Down
14 changes: 10 additions & 4 deletions src/webfrontend/CustomDataTypeGFBIOTreeview.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GFBIO_ListViewTree
#############################################################################
# construct
#############################################################################
constructor: (@popover = null, @editor_layout = null, @cdata = null, @cdata_form = null, @context = null, @gfbio_opts = {}, @vocParameter = 'ITIS', @apikey = '') ->
constructor: (@popover = null, @editor_layout = null, @cdata = null, @cdata_form = null, @context = null, @gfbio_opts = {}, @vocParameter = 'ITIS', @apikey = '', @endpointurl) ->

options =
class: "gfbioPlugin_Treeview"
Expand Down Expand Up @@ -50,7 +50,7 @@ class GFBIO_ListViewTree
topTree_xhr = { "xhr" : undefined }

# start new request to GFBIO-API and get topconcepts of vocabulary
url = 'https://data.bioontology.org/ontologies/' + vocName + '/classes/roots' + '?apikey=' + that.apikey + '&include=hasChildren,prefLabel&pagesize=1000'
url = that.endpointurl + '/ontologies/' + vocName + '/classes/roots' + '?apikey=' + that.apikey + '&include=hasChildren,prefLabel&pagesize=100'
topTree_xhr.xhr = new (CUI.XHR)(url: url)
topTree_xhr.xhr.start().done((data, status, statusText) ->
# remove loading row (if there is one)
Expand Down Expand Up @@ -93,6 +93,7 @@ class GFBIO_ListViewTree
gfbio_opts: that.gfbio_opts
editor_layout: that.editor_layout
apikey: that.apikey
endpointurl: that.endpointurl

that.treeview.addNode(newNode)
# refresh popup, because its content has changed (new height etc)
Expand Down Expand Up @@ -148,6 +149,8 @@ class GFBIO_ListViewTreeNode extends CUI.ListViewTreeNode
check: CUI.HorizontalLayout
apikey:
check: String
endpointurl:
check: String

readOpts: ->
super()
Expand All @@ -168,7 +171,9 @@ class GFBIO_ListViewTreeNode extends CUI.ListViewTreeNode

# start new request to GFBIO-API
# https://data.bioontology.org/ontologies/NCBITAXON/classes/http%3A%2F%2Fpurl.bioontology.org%2Fontology%2FNCBITAXON%2F10239/children
url = ' https://data.bioontology.org/ontologies/' + @_vocParameter + '/classes/' + encodeURIComponent(@_uri) + '/children?apikey=' + that.opts.apikey + '&include=hasChildren,prefLabel&pagesize=1000'
console.log "that", that
console.log "that.endpointurl", that.opts.endpointurl
url = that.opts.endpointurl + '/ontologies/' + @_vocParameter + '/classes/' + encodeURIComponent(@_uri) + '/children?apikey=' + that.opts.apikey + '&include=hasChildren,prefLabel&pagesize=100'
getChildren_xhr ={ "xhr" : undefined }
getChildren_xhr.xhr = new (CUI.XHR)(url: url)
getChildren_xhr.xhr.start().done((data, status, statusText) ->
Expand Down Expand Up @@ -207,6 +212,7 @@ class GFBIO_ListViewTreeNode extends CUI.ListViewTreeNode
gfbio_opts: that._gfbio_opts
editor_layout: that._editor_layout
apikey: that.opts.apikey
endpointurl: that.opts.endpointurl
children.push(newNode)
dfr.resolve(children)
)
Expand Down Expand Up @@ -245,7 +251,7 @@ class GFBIO_ListViewTreeNode extends CUI.ListViewTreeNode
tooltip:
text: tooltipText
onClick: =>
allDataAPIPath = 'https://data.bioontology.org/ontologies/' + that.opts.vocParameter + '/classes/' + encodeURIComponent(that.opts.uri) + '?apikey=' + that.opts.apikey
allDataAPIPath = that.opts.endpointurl + '/ontologies/' + that.opts.vocParameter + '/classes/' + encodeURIComponent(that.opts.uri) + '?apikey=' + that.opts.apikey
# XHR for basic information
dataEntry_xhr = new (CUI.XHR)(url: allDataAPIPath)
dataEntry_xhr.start().done((resultJSON, status, statusText) ->
Expand Down

0 comments on commit 2e7453d

Please sign in to comment.