# src/api/icat/icatPlus.js

## Maintainability

88.17

## Lines of code

256

## Difficulty

30.29

## Estimated Errors

1.56

## Function weight

### By Complexity

### By SLOC

import ICATPLUS from '../../config/icat/icatPlus.js' /** * This class contains all the URL used to communicate with the icat-plus server. */ export class URL { /** * Get URL needed to retrieve events for a given investigation * @param {String} sessionId the session identifier * @param {String} investigationId the session identifier * @return {String} the URL to get the requested events. Null if investigationId or sessionId is missing. */ static getEventsByInvestigationId(sessionId, investigationId) { return ICATPLUS.server + "/logbook/sessionId/investigation/id/investigationId/event/query" .replace("sessionId", sessionId) .replace("investigationId", investigationId); } /** * Get URL needed to retrieve the event count for a given investigation * @param {string} sessionId the session identifier * @param {String} investigationId the investigation identifier * @return {String} the URL to get the requested event count */ static getEventCountByInvestigationId(sessionId, investigationId) { return ICATPLUS.server + "/logbook/sessionId/investigation/id/investigationId/event/count" .replace("sessionId", sessionId) .replace("investigationId", investigationId); } /** * Get URL used to create a new event for a given investigation on ICAT+ * @param {*} investigationId investigation indentifier * @param {String} sessionId session identifier * @return {String} URL to get the requested events */ static createEvent(sessionId, investigationId) { return ICATPLUS.server + "/logbook/sessionId/investigation/id/investigationId/event/create" .replace("sessionId", sessionId) .replace("investigationId", investigationId); } /** * Get URL used to update an event on a given investigation on ICAT+ * @param {String} sessionId the session identifier * @param {String} investigationId the investigation indentifier * @return {String} the URL to get the requested events */ static updateEvent(sessionId, investigationId) { return ICATPLUS.server + "/logbook/sessionId/investigation/id/investigationId/event/update" .replace("sessionId", sessionId) .replace("investigationId", investigationId); } /** * Get URL used to upload data such as a file to ICAT+. * @param {*} investigationId the investigationId */ static uploadFile(sessionId, investigationId) { return ICATPLUS.server + "/resource/sessionId/file/investigation/id/investigationId/upload" .replace("sessionId", sessionId) .replace("investigationId", investigationId); } /** * Get URL used to retrieve the file of an event which category is 'file' * @param {string} sessionId session identifier * @param {*} investigationId investigation identifier * @param {string} eventId event identifier where the file is stored * @return {String} URL to get the file */ static getFileByEventId(sessionId, investigationId, eventId) { return ICATPLUS.server + "/resource/sessionId/file/id/eventId/investigation/id/investigationId/download" .replace("sessionId", sessionId) .replace("investigationId", investigationId) .replace("eventId", eventId); } /** * Get URL used to download a PDF file for a given investigation from the logbook * @param {string} sessionId session identifier * @param {*} investigationId investigation identifier * @param {object} selectionFilter selection filter used to retrieve part of the logbook. This is URI encoded and passed as query string */ static getPDF(sessionId, investigationId, selectionFilter) { let url = ICATPLUS.server + "/logbook/sessionId/investigation/id/investigationId/event/pdf?find=&sort=&skip=&limit=" .replace("sessionId", sessionId) .replace("investigationId", investigationId) .replace("find=", 'find=' + JSON.stringify(selectionFilter.find)) .replace("&sort=", '&sort=' + JSON.stringify(selectionFilter.sort)) .replace("&skip=", '&skip=' + JSON.stringify(selectionFilter.skip)) .replace("&limit=", '&limit=' + JSON.stringify(selectionFilter.limit)); return url; } /** * Get the URL used to mint a DOI * @param {*} sessionId session identifier * @return {string} URL used to mint a DOI */ static getMintDOI(sessionId) { return ICATPLUS.server + "/doi/sessionId/mint" .replace("sessionId", sessionId); } /** Get the tags associated to a given investigation * @param {string} sessionId session identifier * @param {*} investigationId investigation identifier */ static getTagsByInvestigationId(sessionId, investigationId) { return ICATPLUS.server + "/logbook/" + sessionId + "/investigation/id/" + investigationId + "/tag"; } /** Create a given tag associated to a given investigation */ static createTagsByInvestigationId(sessionId, investigationId) { return ICATPLUS.server + '/logbook/' + sessionId + '/investigation/id/' + investigationId + '/tag/create'; } /** Update a given tag associated to a given investigation */ static updateTagsByInvestigationId(sessionId, investigationId, tagId) { return ICATPLUS.server + "/logbook/" + sessionId + "/investigation/id/" + investigationId + "/tag/id/" + tagId + "/tag/update"; } /** * Get URL used to retrieve the file of an event which category is 'file' * @param {string} sessionId session identifier * @param {*} investigationId investigation identifier * @param {string} eventId event identifier where the file is stored * @return {String} URL to get the file */ static getFileByEventId(sessionId, investigationId, eventId) { return ICATPLUS.server + "/resource/sessionId/file/id/eventId/investigation/id/investigationId/download" .replace("sessionId", sessionId) .replace("investigationId", investigationId) .replace("eventId", eventId); } } /** To be removed from here */ var IDS = { //server: "https://ovm-icat-test.esrf.fr:8181", server: "https://ids.esrf.fr/ids", connection: { plugins: ['esrf'] } }; export function getDownloadURLByDatasetId(sessionId, datasetIds) { console.log(sessionId) console.log(datasetIds); return IDS.server + "/getData?sessionId=" + sessionId + "&datasetIds=" + datasetIds; } export function getDownloadURLByDatafileId(sessionId, datafileIds) { return IDS.server + "/getData?sessionId=" + sessionId + "&datafileIds=" + datafileIds; } export function getFilesByDatasetId(sessionId, datasetIds) { return ICATPLUS.server + "/catalogue/sessionId/dataset/id/datasetIds/datafile" .replace("sessionId", sessionId) .replace("datasetIds", datasetIds); } /** * Retrieve the file of an event which category is 'file' * @param {*} investigationId the investigationId * @param {*} eventId the eventId * @return {String} the url to access the file */ export function getFileByEventIdHTTPRequest(sessionId, investigationId, eventId) { return ICATPLUS.server + "/resource/sessionId/file/id/eventId/investigation/id/investigationId/download" .replace("sessionId", sessionId) .replace("investigationId", investigationId) .replace("eventId", eventId); } export function getUsersByInvestigationIds(sessionId, investigationIds) { return ICATPLUS.server + "/catalogue/sessionId/investigation/id/investigationIds/investigationusers" .replace("sessionId", sessionId) .replace("investigationIds", investigationIds); } export function getDatasetsByInvestigationId(sessionId, investigationId) { return ICATPLUS.server + "/catalogue/sessionId/investigation/id/investigationId/dataset" .replace("sessionId", sessionId) .replace("investigationId", investigationId); } export function getDatasetsById(sessionId, datasetIds) { return ICATPLUS.server + "/catalogue/sessionId/dataset/id/datasetIds/dataset" .replace("sessionId", sessionId) .replace("datasetIds", datasetIds); } export function getDatasetByInvestigationId(sessionId, investigationId) { return ICATPLUS.server + "/catalogue/sessionId/investigation/id/investigationId/dataset" .replace("sessionId", sessionId) .replace("investigationId", investigationId); } export function getInvestigationById(sessionId, investigationId) { return ICATPLUS.server + "/catalogue/sessionId/investigation/id/investigationId/investigation" .replace("sessionId", sessionId) .replace("investigationId", investigationId); } export function getDataCollectionByDatasetId(sessionId, datasetId) { return ICATPLUS.server + "/datasets/" + datasetId + "/datacollection?sessionId=" + sessionId; } export function getInvestigationsByUser(sessionId) { return ICATPLUS.server + "/catalogue/sessionId/investigation" .replace("sessionId", sessionId); } export function getEmbargoedInvestigations(sessionId) { return ICATPLUS.server + "/catalogue/sessionId/investigation/status/embargoed/investigation".replace("sessionId", sessionId); } export function getReleasedInvestigations(sessionId) { return ICATPLUS.server + "/catalogue/sessionId/investigation/status/released/investigation".replace("sessionId", sessionId); } export function getDatasetByDOI(sessionId, doi) { return ICATPLUS.server + "/doi/" + doi + "/datasets?sessionId=" + sessionId; } export function getDataCollections(sessionId) { return ICATPLUS.server + "/catalogue/sessionId/datacollection" .replace("sessionId", sessionId); } export function getDatasetStatus(sessionId, datasetIds) { return ICATPLUS.server + "/catalogue/sessionId/dataset/id/datasetIds/status" .replace("sessionId", sessionId) .replace("datasetIds", datasetIds); } export function createEventFromBase64(sessionId, investigationId) { return ICATPLUS.server + "/logbook/sessionId/investigation/id/investigationId/event/createfrombase64" .replace("sessionId", sessionId) .replace("investigationId", investigationId); }