2023-01-20 16:57:03 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2023-01-26 10:55:02 +01:00
|
|
|
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
2023-02-08 15:12:39 +01:00
|
|
|
import { Page, DsmConf, ResourceType, Protocol, WfHistoryEntry, SimpleResource, Context, ContextNode, Vocabulary, VocabularyTerm, KeyValue, BrowseTerm, Datasource, MDStore, MDStoreVersion, MDStoreRecord } from './is.model';
|
2023-01-27 08:58:33 +01:00
|
|
|
import { FormGroup } from '@angular/forms';
|
|
|
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
2023-01-20 16:57:03 +01:00
|
|
|
|
|
|
|
@Injectable({
|
2023-02-08 15:12:39 +01:00
|
|
|
providedIn: 'root'
|
2023-01-20 16:57:03 +01:00
|
|
|
})
|
|
|
|
export class ISService {
|
|
|
|
|
2023-02-08 15:12:39 +01:00
|
|
|
constructor(public client: HttpClient, public snackBar: MatSnackBar) { }
|
|
|
|
|
|
|
|
loadResourceTypes(onSuccess: Function): void {
|
|
|
|
this.client.get<ResourceType[]>("/ajax/resourceTypes").subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadResourceType(id: string, onSuccess: Function): void {
|
|
|
|
this.client.get<ResourceType>("/ajax/resourceTypes/" + encodeURIComponent(id)).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadInfo(onSuccess: Function): void {
|
|
|
|
this.client.get<any[]>("/ajax/info/").subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadProtocols(onSuccess: Function): void {
|
|
|
|
this.client.get<Protocol[]>("/ajax/protocols/").subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadSimpleResources(type: string, onSuccess: Function): void {
|
|
|
|
this.client.get<SimpleResource[]>("/ajax/resources/" + encodeURIComponent(type)).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadSimpleResourceContent(id: any, onSuccess: Function): void {
|
|
|
|
const headers = new HttpHeaders().set('Content-Type', 'text/plain; charset=utf-8');
|
|
|
|
this.client.get<string>("/ajax/resources/" + encodeURIComponent(id) + '/content', {
|
|
|
|
headers, responseType: 'text' as 'json'
|
|
|
|
}).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
saveSimpleResourceMedatata(res: SimpleResource, onSuccess: Function, relatedForm?: FormGroup): void {
|
|
|
|
this.client.post<void>('/ajax/resources/' + encodeURIComponent(res.id) + '/metadata', res).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error, relatedForm)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
saveSimpleResourceContent(id: string, content: string, onSuccess: Function, relatedForm?: FormGroup): void {
|
|
|
|
const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
|
|
|
|
let body = new HttpParams().set('content', content);
|
|
|
|
this.client.post<void>('/ajax/resources/' + encodeURIComponent(id) + '/content', body, { headers: headers }).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error, relatedForm)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addSimpleResource(name: string, type: string, description: string, content: string, onSuccess: Function, relatedForm?: FormGroup): void {
|
|
|
|
const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
|
|
|
|
let body = new HttpParams()
|
|
|
|
.set('name', name)
|
|
|
|
.set('type', type)
|
|
|
|
.set('description', description)
|
|
|
|
.set('content', content);
|
|
|
|
this.client.post<void>('/ajax/resources/', body, { headers: headers }).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error, relatedForm)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteSimpleResource(resourceId: string, onSuccess: Function): void {
|
|
|
|
this.client.delete<void>('/ajax/resources/' + encodeURIComponent(resourceId)).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadWfHistory(total: number, from: number, to: number, onSuccess: Function): void {
|
|
|
|
let params = new HttpParams();
|
|
|
|
if (total && total > 0) { params = params.append('total', total); }
|
|
|
|
if (from && from > 0) { params = params.append('from', from); }
|
|
|
|
if (to && to > 0) { params = params.append('to', to); }
|
|
|
|
|
|
|
|
this.client.get<WfHistoryEntry[]>('/ajax/wfs/', { params: params }).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadContexts(onSuccess: Function): void {
|
|
|
|
this.client.get<Context[]>('./ajax/contexts/').subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadContext(ctxId: string, onSuccess: Function): void {
|
|
|
|
this.client.get<Context>('./ajax/contexts/' + encodeURIComponent(ctxId)).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadContextCategories(ctxId: string, onSuccess: Function): void {
|
|
|
|
this.client.get<ContextNode[]>('./ajax/contexts/' + encodeURIComponent(ctxId) + '/categories').subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadContextConcepts(level: number, nodeId: string, onSuccess: Function): void {
|
|
|
|
this.client.get<ContextNode[]>('./ajax/contexts/' + encodeURIComponent(level) + '/' + encodeURIComponent(nodeId) + '/concepts').subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadVocabularies(onSuccess: Function): void {
|
|
|
|
this.client.get<Vocabulary[]>('./ajax/vocs/').subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadVocabulary(vocId: string, onSuccess: Function): void {
|
|
|
|
this.client.get<Vocabulary>('./ajax/vocs/' + encodeURIComponent(vocId)).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadVocabularyTerms(vocId: string, onSuccess: Function): void {
|
|
|
|
this.client.get<VocabularyTerm[]>('./ajax/vocs/' + encodeURIComponent(vocId) + '/terms').subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
saveVocabulary(voc: Vocabulary, onSuccess: Function, relatedForm?: FormGroup): void {
|
|
|
|
this.client.post<void>('./ajax/vocs/', voc).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error, relatedForm)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
saveVocabularyTerm(vocId: string, term: VocabularyTerm, onSuccess: Function, relatedForm?: FormGroup): void {
|
|
|
|
this.client.post<void>('./ajax/vocs/' + encodeURIComponent(vocId) + '/terms', term).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error, relatedForm)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteVocabulary(vocId: string, onSuccess: Function): void {
|
|
|
|
this.client.delete<void>('./ajax/vocs/' + encodeURIComponent(vocId)).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteVocabularyTerm(vocId: string, termCode: string, onSuccess: Function): void {
|
|
|
|
this.client.delete<void>('./ajax/vocs/'
|
|
|
|
+ encodeURIComponent(vocId)
|
|
|
|
+ '/terms/'
|
|
|
|
+ encodeURIComponent(termCode)
|
|
|
|
).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
dsmConf(onSuccess: Function) {
|
|
|
|
this.client.get<DsmConf>('./ajax/dsm/conf').subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
dsmBrowsableFields(onSuccess: Function) {
|
|
|
|
this.client.get<KeyValue[]>('./ajax/dsm/browsableFields').subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
dsmBrowse(field: string, onSuccess: Function) {
|
|
|
|
this.client.get<BrowseTerm[]>('./ajax/dsm/browse/' + encodeURIComponent(field)).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
dsmSearchByField(field: string, value: string, page: number, pageSize: number, onSuccess: Function) {
|
|
|
|
this.client.get<Page<Datasource>>('./ajax/dsm/searchByField/' + encodeURIComponent(field) + '/' + page + '/' + pageSize + '?value=' + encodeURIComponent(value)).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
dsmSearch(value: string, page: number, pageSize: number, onSuccess: Function) {
|
|
|
|
this.client.get<Page<Datasource>>('./ajax/dsm/search/' + page + '/' + pageSize + '?value=' + encodeURIComponent(value)).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadMDStores(onSuccess: Function): void {
|
|
|
|
this.client.get<MDStore[]>("/ajax/mdstores/").subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadMDStore(mdId: string, onSuccess: Function): void {
|
|
|
|
this.client.get<MDStore>('./ajax/mdstores/mdstore/' + encodeURIComponent(mdId)).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-02-10 12:18:06 +01:00
|
|
|
addMDStore(format: string, layout: string, interpretation: string, type: string, dsName: string, dsId: string, apiId: string, onSuccess: Function, relatedForm?: FormGroup) {
|
2023-02-08 15:12:39 +01:00
|
|
|
const headers = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
|
|
|
|
|
|
|
|
let body = new HttpParams()
|
|
|
|
.set('dsName', dsName)
|
|
|
|
.set('dsId', dsId)
|
|
|
|
.set('apiId', apiId);
|
|
|
|
|
|
|
|
this.client.post<void>('/ajax/mdstores/new/'
|
|
|
|
+ encodeURIComponent(format)
|
|
|
|
+ '/'
|
|
|
|
+ encodeURIComponent(layout)
|
|
|
|
+ '/'
|
2023-02-10 12:18:06 +01:00
|
|
|
+ encodeURIComponent(interpretation)
|
|
|
|
+ '/'
|
|
|
|
+ encodeURIComponent(type),
|
2023-02-08 15:12:39 +01:00
|
|
|
body, { headers: headers }).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error, relatedForm)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteMDStore(mdId: string, onSuccess: Function): void {
|
|
|
|
this.client.delete<void>('./ajax/mdstores/mdstore/' + encodeURIComponent(mdId)).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
prepareNewMDStoreVersion(mdId: string, onSuccess: Function): void {
|
|
|
|
this.client.get<MDStoreVersion>('./ajax/mdstores/mdstore/' + encodeURIComponent(mdId) + '/newVersion').subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
commitMDStoreVersion(versionId: string, size: number, onSuccess: Function) {
|
|
|
|
this.client.get<any>('./ajax/mdstores/version/' + encodeURIComponent(versionId) + '/commit/' + size).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
abortMDStoreVersion(versionId: string, onSuccess: Function) {
|
|
|
|
this.client.get<any>('./ajax/mdstores/version/' + encodeURIComponent(versionId) + '/abort').subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteMDStoreVersion(versionId: string, onSuccess: Function) {
|
|
|
|
this.client.delete<any>('./ajax/mdstores/version/' + encodeURIComponent(versionId)).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
resetReadingMDStoreVersion(versionId: string, onSuccess: Function) {
|
|
|
|
this.client.get<any>('./ajax/mdstores/version/' + encodeURIComponent(versionId) + '/resetReading').subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadMDStoreVersions(mdId: string, onSuccess: Function): void {
|
|
|
|
this.client.get<MDStoreVersion[]>('./ajax/mdstores/mdstore/' + encodeURIComponent(mdId) + '/versions').subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadMDStoreVersion(versionId: string, onSuccess: Function): void {
|
|
|
|
this.client.get<MDStoreVersion>('./ajax/mdstores/version/' + encodeURIComponent(versionId)).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadMDStoreVersionRecords(versionId: string, limit: number, onSuccess: Function): void {
|
|
|
|
this.client.get<MDStoreRecord[]>('./ajax/mdstores/version/' + encodeURIComponent(versionId) + '/parquet/content/' + limit).subscribe({
|
|
|
|
next: data => onSuccess(data),
|
|
|
|
error: error => this.showError(error)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private showError(error: any, form?: FormGroup) {
|
|
|
|
const msg = this.errorMessage(error);
|
|
|
|
if (form) {
|
|
|
|
form.setErrors({ serverError: msg })
|
|
|
|
} else if (this.snackBar) {
|
|
|
|
this.snackBar.open(msg, 'ERROR', {
|
|
|
|
duration: 5000,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
alert(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private errorMessage(error: any) {
|
|
|
|
if (error.error && error.error.message) {
|
|
|
|
return error.error.message;
|
|
|
|
} else if (error.message) {
|
|
|
|
return error.message;
|
|
|
|
} else {
|
|
|
|
return 'Generic server side error';
|
|
|
|
}
|
|
|
|
}
|
2023-01-27 08:58:33 +01:00
|
|
|
|
2023-01-20 16:57:03 +01:00
|
|
|
}
|