Skip to content
Snippets Groups Projects
Commit 361edcd8 authored by Marcel Nellesen's avatar Marcel Nellesen
Browse files

New: created external Api, removed circular dependencies (coscine/issues#313)

Fix: Upgrade DataSource (coscine/issues#318)
parent 8c4e8449
No related branches found
No related tags found
No related merge requests found
......@@ -12,16 +12,9 @@ export { VisibilityApi } from './requests/visibility-api'
export { InstituteApi } from './requests/institute-api'
export { DisciplineApi } from './requests/discipline-api'
export { LicenseApi } from './requests/license-api'
export { MetadataApi } from './requests/metadata-api'
const headerKey = 'Authorization'
let hostName = window.location.hostname
if (hostName.indexOf(':') !== -1) {
if (hostName.indexOf('https://') !== -1) {
hostName = hostName.replace('https://', '')
}
hostName = hostName.substr(0, hostName.indexOf(':'))
}
import apiConnectionBasic from './basic/api-connection-basic'
export function defaultOnCatch(error: any) {
// TODO: Do something with the error
......@@ -36,17 +29,8 @@ export function redirectToProject(project: any) {
project.id === '' ||
project.id === '00000000-0000-0000-0000-000000000000'
) {
window.location.href = 'https://' + hostName + '/'
window.location.href = 'https://' + apiConnectionBasic.getHostName() + '/'
} else {
window.location.href = 'https://' + hostName + '/p/' + project.id + '/'
}
}
export default {
getHostName() {
return hostName
},
setHeader() {
axios.defaults.headers.common[headerKey] = 'Bearer ' + (coscine as any).authorization.bearer
window.location.href = 'https://' + apiConnectionBasic.getHostName() + '/p/' + project.id + '/'
}
}
const axios = require('axios')
const headerKey = 'Authorization'
let hostName = window.location.hostname
if (hostName.indexOf(':') !== -1) {
if (hostName.indexOf('https://') !== -1) {
hostName = hostName.replace('https://', '')
}
hostName = hostName.substr(0, hostName.indexOf(':'))
}
export default {
getHostName() {
return hostName
},
setHeader() {
axios.defaults.headers.common[headerKey] = 'Bearer ' + (coscine as any).authorization.bearer
}
}
const axios = require('axios')
import fileSaver from 'file-saver'
import apiConnection from '../api-connection'
import apiConnectionBasic from '../basic/api-connection-basic'
function getDataSourceApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/DataSource/'
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/DataSource/'
)
}
export class DataSourceApi {
......@@ -14,7 +16,7 @@ export class DataSourceApi {
thenHandler: any,
catchHandler: any
) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.get(getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path))
.then(thenHandler)
......@@ -26,7 +28,7 @@ export class DataSourceApi {
name: string,
catchHandler: any
) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.get(getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path), {
responseType: 'blob'
......@@ -39,7 +41,7 @@ export class DataSourceApi {
.catch(catchHandler)
}
public static getDataSource(resourceId: any, path: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.get(getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path))
.then(thenHandler)
......@@ -47,7 +49,7 @@ export class DataSourceApi {
}
public static delete(resourceId: any, path: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.delete(getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path))
.then(thenHandler)
......@@ -62,7 +64,7 @@ export class DataSourceApi {
thenHandler: any,
catchHandler: any
) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios({
method: 'PUT',
url: getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path),
......@@ -83,7 +85,7 @@ export class DataSourceApi {
thenHandler: any,
catchHandler: any
) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios({
method: 'PUT',
url: getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path) + '/update',
......@@ -97,7 +99,7 @@ export class DataSourceApi {
}
public static isValidDataSource(body: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.post(getDataSourceApiUrl() + 'validate', body)
.then(thenHandler)
......
......
const axios = require('axios');
const axios = require('axios')
import apiConnection from '../api-connection';
import apiConnectionBasic from '../basic/api-connection-basic'
function getDisciplineApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/Discipline/';
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Discipline/'
)
}
export class DisciplineApi {
public static getDisciplines(thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
apiConnectionBasic.setHeader()
axios
.get(getDisciplineApiUrl())
.then(thenHandler)
.catch(catchHandler);
.catch(catchHandler)
}
}
const axios = require('axios');
const axios = require('axios')
import apiConnection from '../api-connection';
import apiConnectionBasic from '../basic/api-connection-basic'
function getInstituteApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/Institute/';
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Institute/'
)
}
export class InstituteApi {
public static getInstitutes(thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
apiConnectionBasic.setHeader()
axios
.get(getInstituteApiUrl())
.then(thenHandler)
.catch(catchHandler);
.catch(catchHandler)
}
}
const axios = require('axios')
import apiConnection from '../api-connection'
import apiConnectionBasic from '../basic/api-connection-basic'
function getLicenseApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/License/'
return 'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/License/'
}
export class LicenseApi {
public static getLicenses(thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.get(getLicenseApiUrl())
.then(thenHandler)
......
......
const axios = require('axios')
import apiConnectionBasic from '../basic/api-connection-basic'
function getMetadataApiUrl() {
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Metadata/'
)
}
export class MetadataApi {
public static getMetadataForFile(
resourceId: string,
filename: string,
version: string,
thenHandler: any,
catchHandler: any
) {
apiConnectionBasic.setHeader()
axios
.get(
getMetadataApiUrl() +
'resource/' +
resourceId +
'/filename/' +
encodeURIComponent(filename) +
'/ver/' +
version
)
.then(thenHandler)
.catch(catchHandler)
}
public static storeMetadataForFile(
resourceId: string,
filename: string,
version: string,
body: any,
thenHandler: any,
catchHandler: any
) {
apiConnectionBasic.setHeader()
axios
.put(
getMetadataApiUrl() +
'resource/' +
resourceId +
'/filename/' +
encodeURIComponent(filename) +
'/ver/' +
version,
body
)
.then(thenHandler)
.catch(catchHandler)
}
public static getApplicationProfile(
resourceId: string,
applicationProfileId: string,
thenHandler: any,
catchHandler: any
) {
apiConnectionBasic.setHeader()
axios
.get(
getMetadataApiUrl() +
'resource/' +
resourceId +
'/ap/' +
encodeURIComponent(encodeURIComponent(applicationProfileId))
)
.then(thenHandler)
.catch(catchHandler)
}
public static listAllApplicationProfiles(
resourceId: string,
thenHandler: any,
catchHandler: any
) {
apiConnectionBasic.setHeader()
axios
.get(getMetadataApiUrl() + 'resource/' + resourceId + '/aplist/')
.then(thenHandler)
.catch(catchHandler)
}
public static getVocabulary(
resourceId: string,
path: string,
thenHandler: any,
catchHandler: any
) {
apiConnectionBasic.setHeader()
axios
.get(getMetadataApiUrl() + 'vocabulary/' + resourceId + '/' + encodeURIComponent(path))
.then(thenHandler)
.catch(catchHandler)
}
public static getFilteredVocabulary(
resourceId: string,
path: string,
searchedWord: string,
thenHandler: any,
catchHandler: any
) {
apiConnectionBasic.setHeader()
axios
.get(
getMetadataApiUrl() +
'vocabulary/' +
resourceId +
'/' +
encodeURIComponent(path) +
'/' +
encodeURIComponent(searchedWord)
)
.then(thenHandler)
.catch(catchHandler)
}
}
const axios = require('axios')
import apiConnection from '../api-connection'
import apiConnectionBasic from '../basic/api-connection-basic'
function getProjectApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/Project/'
return 'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Project/'
}
export class ProjectApi {
public static getProjectInformation(projectId: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.get(getProjectApiUrl() + projectId)
.then(thenHandler)
.catch(catchHandler)
}
public static storeProject(body: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.post(getProjectApiUrl(), body)
.then(thenHandler)
.catch(catchHandler)
}
public static updateProject(projectId: string, body: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.post(getProjectApiUrl() + projectId, body)
.then(thenHandler)
.catch(catchHandler)
}
public static getResources(parentId: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.get(getProjectApiUrl() + parentId + '/resources')
.then(thenHandler)
.catch(catchHandler)
}
public static deleteProject(projectId: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.delete(getProjectApiUrl() + projectId)
.then(thenHandler)
.catch(catchHandler)
}
public static getProjects(thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.get(getProjectApiUrl())
.then(thenHandler)
......
......
const axios = require('axios')
import apiConnection from '../api-connection'
import apiConnectionBasic from '../basic/api-connection-basic'
function getProjectRoleApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/ProjectRole/'
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/ProjectRole/'
)
}
export class ProjectRoleApi {
public static getProjectRoles(parentId: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.get(getProjectRoleApiUrl() + parentId + '/')
.then(thenHandler)
.catch(catchHandler)
}
public static getUserRoles(projectId: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.get(getProjectRoleApiUrl() + 'project/' + projectId + '/')
.then(thenHandler)
.catch(catchHandler)
}
public static setProjectRole(body: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.post(getProjectRoleApiUrl(), body)
.then(thenHandler)
......@@ -35,7 +37,7 @@ export class ProjectRoleApi {
thenHandler: any,
catchHandler: any
) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.delete(
getProjectRoleApiUrl() + 'project/' + parentId + '/user/' + userId + '/role/' + roleId
......
......
const axios = require('axios')
import apiConnection from '../api-connection'
import apiConnectionBasic from '../basic/api-connection-basic'
function getResourceApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/Resource/'
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Resource/'
)
}
export class ResourceApi {
public static getResourceInformation(resourceId: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.get(getResourceApiUrl() + resourceId)
.then(thenHandler)
.catch(catchHandler)
}
public static storeResource(parentId: string, body: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.post(getResourceApiUrl() + 'Project/' + parentId, body)
.then(thenHandler)
.catch(catchHandler)
}
public static deleteResource(resourceId: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.delete(getResourceApiUrl() + resourceId)
.then(thenHandler)
.catch(catchHandler)
}
public static updateResource(resourceId: string, body: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
apiConnectionBasic.setHeader()
axios
.post(getResourceApiUrl() + resourceId, body)
.then(thenHandler)
......
......
const axios = require('axios');
const axios = require('axios')
import apiConnection from '../api-connection';
import apiConnectionBasic from '../basic/api-connection-basic'
function getResourceTypeApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/ResourceType/';
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/ResourceType/'
)
}
export class ResourceTypeApi {
public static getResourceTypes(thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
apiConnectionBasic.setHeader()
axios
.get(getResourceTypeApiUrl())
.then(thenHandler)
.catch(catchHandler);
.catch(catchHandler)
}
public static getFields(resourceTypeId: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
apiConnectionBasic.setHeader()
axios
.get(getResourceTypeApiUrl() + resourceTypeId + '/fields')
.then(thenHandler)
.catch(catchHandler);
.catch(catchHandler)
}
}
const axios = require('axios');
const axios = require('axios')
import apiConnection from '../api-connection';
import apiConnectionBasic from '../basic/api-connection-basic'
function getRoleApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/Role/';
return 'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Role/'
}
export class RoleApi {
public static getRoles(thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
apiConnectionBasic.setHeader()
axios
.get(getRoleApiUrl())
.then(thenHandler)
.catch(catchHandler);
.catch(catchHandler)
}
}
const axios = require('axios');
const axios = require('axios')
import apiConnection from '../api-connection';
import apiConnectionBasic from '../basic/api-connection-basic'
function getSubProjectApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/SubProject/';
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/SubProject/'
)
}
export class SubProjectApi {
public static getSubProjects(parentId: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
apiConnectionBasic.setHeader()
axios
.get(getSubProjectApiUrl() + parentId + '/')
.then(thenHandler)
.catch(catchHandler);
.catch(catchHandler)
}
}
const axios = require('axios');
const axios = require('axios')
import apiConnection from '../api-connection';
import apiConnectionBasic from '../basic/api-connection-basic'
function getUserApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.User/User/';
return 'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.User/User/'
}
export class UserApi {
public static queryUsers(query: string, parentId: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
apiConnectionBasic.setHeader()
axios
.get(getUserApiUrl() + 'query/' + query + '/project/' + parentId + '/')
.then(thenHandler)
.catch(catchHandler);
.catch(catchHandler)
}
public static getUser(thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
axios
.get(getUserApiUrl() + 'user')
.then(thenHandler)
.catch(catchHandler)
}
}
const axios = require('axios');
const axios = require('axios')
import apiConnection from '../api-connection';
import apiConnectionBasic from '../basic/api-connection-basic'
function getVisibilityApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/Visibility/';
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Visibility/'
)
}
export class VisibilityApi {
public static getVisibilities(thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
apiConnectionBasic.setHeader()
axios
.get(getVisibilityApiUrl())
.then(thenHandler)
.catch(catchHandler);
.catch(catchHandler)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment