Skip to content

Commit

Permalink
Merge pull request #665 from inab/658-evaluator-unable-to-run-tool-wh…
Browse files Browse the repository at this point in the history
…en-using-metadata-file-url-or-upload-as-input

658 evaluator unable to run tool when using metadata file url or upload as input
  • Loading branch information
EvaMart authored Oct 15, 2024
2 parents df8a2b3 + 3ca23a6 commit 157c455
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 103 deletions.
101 changes: 5 additions & 96 deletions components/observatory/evaluation/MetadataFile/MetadataFileURL.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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',
Expand All @@ -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 = '';
Expand Down
14 changes: 12 additions & 2 deletions components/observatory/evaluation/Results/MetadataActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@
previous step. It is in JSON-LD format and incorporates
<a href="https://schema.org/" target="_blank">Schema.org</a>,
<a href="https://bioschemas.org/" target="_blank">Bioschemas</a>, and
<a href="" target="_blank">maSMP</a>
<a href="https://zbmed-semtec.github.io/maSMPs/" target="_blank"
>maSMP</a
>
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
<a href="https://osf.io/preprints/biohackrxiv/k8znb" target="_blank"
>ELIXIR software management plan</a
>
for your software in the
<a href="https://smw.dsw.elixir-europe.org/wizard/" target="_blank"
>Software Management Wizard (SMW)</a
>.
</p>
<p>
Below, you have several options to preview, download, or directly
Expand Down
2 changes: 1 addition & 1 deletion plugins/githubapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion plugins/observatory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
46 changes: 43 additions & 3 deletions store/observatory/evaluation/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export const actions = {
if (response) {
const fileContent = response.content;

dispatch('parseMetadataFile', fileContent);
dispatch('mapMetadata', fileContent);
} else {
commit('setErrorDialogParseMetadata', true);
commit(
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -432,9 +471,10 @@ export const actions = {
'</pre>';
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(
Expand Down
1 change: 1 addition & 0 deletions store/observatory/evaluation/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 157c455

Please sign in to comment.