From d1161bd5e2f0775de2f1447027b8eb4a799c0da6 Mon Sep 17 00:00:00 2001 From: Eva Martin del Pico Date: Tue, 15 Oct 2024 12:14:03 +0200 Subject: [PATCH 1/2] fix: remove unecessary functions --- .../MetadataFile/MetadataFileURL.vue | 101 +----------------- plugins/githubapp.js | 2 +- plugins/observatory.js | 3 +- store/observatory/evaluation/file.js | 46 +++++++- store/observatory/evaluation/github.js | 1 + 5 files changed, 52 insertions(+), 101 deletions(-) diff --git a/components/observatory/evaluation/MetadataFile/MetadataFileURL.vue b/components/observatory/evaluation/MetadataFile/MetadataFileURL.vue index 93362763..bc49eb0f 100644 --- a/components/observatory/evaluation/MetadataFile/MetadataFileURL.vue +++ b/components/observatory/evaluation/MetadataFile/MetadataFileURL.vue @@ -84,8 +84,8 @@ export default { }, exampleValues: [ { - title: 'FAIRsoft-indicators', - URL: 'https://raw.githubusercontent.com/EvaMart/FAIRsoft-indicators/master/FAIRsoft-indicators.metadata.jsonld', + title: 'oeb-visualizations', + URL: 'https://raw.githubusercontent.com/inab/oeb-visualizations/refs/heads/main/metadata.jsonld', }, ], installDialogParameters: { @@ -96,40 +96,12 @@ export default { methods: { submitURL() { - this.payload = this.ParseGitHubURL(this.URL); - if (this.payload) { - this.submitGitHubLink(); - } else { - this.$store.dispatch( - 'observatory/evaluation/file/parseFromURL', - this.URL - ); - } + this.$store.dispatch('observatory/evaluation/file/downloadFile', { + url: this.URL, + }); this.$store.dispatch('observatory/evaluation/changeStep', 3); }, - ParseGitHubURL(url) { - /* - Check if the URL is a raw GitHub URL: - raw.githubusercontent.com/${user}/${repo}/${branch}/${path} - If it is, return the payload to fetch the file content. - Else, return null. - */ - const pattern = /^(http(s?):\/\/)?raw\.githubusercontent\.com\/(.*)$/i; - if (pattern.test(url)) { - const payload = { - repo: url.split('/')[4], - owner: url.split('/')[3], - branch: url.split('/')[5], - path: url.split('/').slice(6).join('/'), - }; - - return payload; - } else { - return null; - } - }, - cancel() { this.$store.dispatch( 'observatory/evaluation/file/updateDialogInstallApp', @@ -141,69 +113,6 @@ export default { ); }, - async submitGitHubLink() { - /* - This function is called when the URL introduced by the user is a github one. - It checks if the app is installed in the repository and, if it is, fetches the metadata. - If it is not installed, it opens a dialog to install it. - */ - - // 1.1 Open dialog to show progress - - this.$store.dispatch('observatory/evaluation/github/updateRepository', { - owner: this.payload.owner, - repo: this.payload.repo, - }); - - this.$store.dispatch( - 'observatory/evaluation/file/updateDialogParseMetadata', - true - ); - console.log('open dialog'); - - // 1.2 Get installation ID - console.log('Get installation ID'); - await this.$store.dispatch( - 'observatory/evaluation/github/getInstallationID', - { - owner: this.payload.owner, - repo: this.payload.repo, - } - ); - - const installationID = - this.$store.getters['observatory/evaluation/github/getInstallationID']; - console.log('installation ID: ' + installationID); - - // 2. If it is installed, fetch file content - if (installationID) { - const payload = { - installationID, - repo: this.payload.repo, - owner: this.payload.owner, - path: this.payload.path, - }; - - this.$store.dispatch( - 'observatory/evaluation/file/parseFromGitHubURL', - payload - ); - } else { - // 3. If it is not installed, open dialog to install it - this.$store.dispatch( - 'observatory/evaluation/file/updateDialogParseMetadata', - false - ); - this.$store.dispatch( - 'observatory/evaluation/file/updateDialogInstallApp', - true - ); - - // this.$store.dispatch('evaluation/changeLoading', { github : false}) // close loading dialog - // this.dialogAppNotInstalled = true // open "app installation" dialog - } - }, - goBack() { this.$store.dispatch('observatory/evaluation/changeStep', 1); this.value = ''; diff --git a/plugins/githubapp.js b/plugins/githubapp.js index 9c7baad7..6d502637 100644 --- a/plugins/githubapp.js +++ b/plugins/githubapp.js @@ -10,9 +10,9 @@ export default function ({ $axios, $config: { GITHUBAPP_API_URL } }, inject) { // Set baseURL to something different // githubapp.setBaseURL('https://observatory-dev.openebench.bsc.es/github-metadata-api'); + // githubapp.setBaseURL('http://localhost:3800'); githubapp.setBaseURL(GITHUBAPP_API_URL); - // githubapp.setBaseURL('http://localhost:3500'); // Inject to context as $api inject('githubapp', githubapp); diff --git a/plugins/observatory.js b/plugins/observatory.js index 47966ae2..0eb070ef 100644 --- a/plugins/observatory.js +++ b/plugins/observatory.js @@ -9,9 +9,10 @@ export default function ({ $axios, $config: { OBSERVATORY_API_URL } }, inject) { }); // Set baseURL to something different - observatory.setBaseURL(OBSERVATORY_API_URL); // observatory.setBaseURL('http://0.0.0.0:3500'); + observatory.setBaseURL(OBSERVATORY_API_URL); + // Inject to context as $api inject('observatory', observatory); } diff --git a/store/observatory/evaluation/file.js b/store/observatory/evaluation/file.js index 9cb7674b..a0a89a9e 100644 --- a/store/observatory/evaluation/file.js +++ b/store/observatory/evaluation/file.js @@ -322,7 +322,7 @@ export const actions = { if (response) { const fileContent = response.content; - dispatch('parseMetadataFile', fileContent); + dispatch('mapMetadata', fileContent); } else { commit('setErrorDialogParseMetadata', true); commit( @@ -345,7 +345,8 @@ export const actions = { const fileContent = response.data; console.debug('Downloaded file content:', fileContent); - await dispatch('parseMetadataFile', JSON.stringify(fileContent)); + parsedContent = JSON.parse(fileContent); + dispatch('mapMetadata', parsedContent); } catch (error) { console.error('Error fetching or parsing file from URL:', error); commit('setErrorDialogParseMetadata', true); @@ -395,6 +396,42 @@ export const actions = { }); }, + async downloadFile({ commit, dispatch }, payload) { + commit('setParseProgressText', 'Downloading file from URL...'); + commit('setDialogParseMetadata', true); + + try { + const URL = '/downloads/download-content/'; + + const data = { + url: payload.url, + }; + + console.log(data); + + const response = await this.$observatory.post(URL, data, { + headers: { + 'Content-Type': 'application/json', + }, + }); + + let fileContent = response.data.content; + fileContent = fileContent.trim(); + fileContent = JSON.parse(fileContent); + + console.log('name', fileContent['schema:name']); + await dispatch('mapMetadata', fileContent); + console.debug('Downloaded file content:', fileContent); + } catch (error) { + console.error('Error fetching or parsing file from URL:', error); + commit('setErrorDialogParseMetadata', true); + commit( + 'setErrorProgressText', + `Error fetching file from URL: ${error.message}` + ); + } + }, + async parseMetadataFile({ commit, dispatch }, file) { commit('setParseProgressText', 'Parsing metadata file content...'); commit('setDialogParseMetadata', true); @@ -419,8 +456,10 @@ export const actions = { fileContent = fileContent.trim(); let parsedContent; + try { parsedContent = JSON.parse(fileContent); + dispatch('mapMetadata', parsedContent); } catch (error) { console.error('Error parsing JSON:', error); commit('setDialogParseMetadata', false); @@ -432,9 +471,10 @@ export const actions = { ''; commit('setErrorProgressText', errorMessage); dispatch('observatory/evaluation/changeStep', 2, { root: true }); - return; } + }, + mapMetadata({ commit, dispatch }, parsedContent) { // Transform file fields into the UI metadata model fields let metadata = { topics: buildFeTopicsOperations( diff --git a/store/observatory/evaluation/github.js b/store/observatory/evaluation/github.js index d38503c5..8a6a95ac 100644 --- a/store/observatory/evaluation/github.js +++ b/store/observatory/evaluation/github.js @@ -82,6 +82,7 @@ export const actions = { commit('setExtractorInstallationID', installationID); } catch (error) { console.debug('Error while getting installation ID: ' + error); + commit('setExtractorInstallationID', null); commit( 'setImportProgressText', "error while fetching the repositorie's installation ID for app metadata extractor for FAIRsoft" From 3ca23a660a3545f24fc2df9a2c19ce5f873aabb1 Mon Sep 17 00:00:00 2001 From: Eva Martin del Pico Date: Tue, 15 Oct 2024 12:25:37 +0200 Subject: [PATCH 2/2] doc: add mention to elixir smp --- .../evaluation/Results/MetadataActions.vue | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/components/observatory/evaluation/Results/MetadataActions.vue b/components/observatory/evaluation/Results/MetadataActions.vue index 0c0e1324..6ade914f 100644 --- a/components/observatory/evaluation/Results/MetadataActions.vue +++ b/components/observatory/evaluation/Results/MetadataActions.vue @@ -8,10 +8,20 @@ previous step. It is in JSON-LD format and incorporates Schema.org, Bioschemas, and - maSMP + maSMP entities. This ensures your metadata is highly interoperable on the internet, making it easy to be understood and utilized by a wide range - of systems and services. + of systems and services. Additionally, this metadata can be used to + pre-fill an + ELIXIR software management plan + for your software in the + Software Management Wizard (SMW).

Below, you have several options to preview, download, or directly