From 4e92795b4a44005a13769a5de99f13c4f561e7af Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Thu, 23 Mar 2023 08:42:47 +0100 Subject: [PATCH] ajax calls --- .../src/app/common/is.service.ts | 323 ++++++------------ 1 file changed, 100 insertions(+), 223 deletions(-) diff --git a/frontends/dnet-is-application/src/app/common/is.service.ts b/frontends/dnet-is-application/src/app/common/is.service.ts index f3554e31..8788d34e 100644 --- a/frontends/dnet-is-application/src/app/common/is.service.ts +++ b/frontends/dnet-is-application/src/app/common/is.service.ts @@ -12,64 +12,40 @@ export class ISService { constructor(public client: HttpClient, public snackBar: MatSnackBar) { } loadResourceTypes(onSuccess: Function): void { - this.client.get("/ajax/resourceTypes").subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet("/ajax/resourceTypes", onSuccess); } loadResourceType(id: string, onSuccess: Function): void { - this.client.get("/ajax/resourceTypes/" + encodeURIComponent(id)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet("/ajax/resourceTypes/" + encodeURIComponent(id), onSuccess); } loadInfo(onSuccess: Function): void { - this.client.get("/ajax/info/").subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet("/ajax/info/", onSuccess); } loadProtocols(onSuccess: Function): void { - this.client.get("/ajax/protocols/").subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet("/ajax/protocols/", onSuccess); } loadSimpleResources(type: string, onSuccess: Function): void { - this.client.get("/ajax/resources/" + encodeURIComponent(type)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet("/ajax/resources/" + encodeURIComponent(type), onSuccess); } loadSimpleResourceContent(id: any, onSuccess: Function): void { const headers = new HttpHeaders().set('Content-Type', 'text/plain; charset=utf-8'); - this.client.get("/ajax/resources/" + encodeURIComponent(id) + '/content', { + this.httpGetWithOptions("/ajax/resources/" + encodeURIComponent(id) + '/content', { headers, responseType: 'text' as 'json' - }).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + }, onSuccess); } saveSimpleResourceMedatata(res: SimpleResource, onSuccess: Function, relatedForm?: FormGroup): void { - this.client.post('/ajax/resources/' + encodeURIComponent(res.id) + '/metadata', res).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error, relatedForm) - }); + this.httpPost('/ajax/resources/' + encodeURIComponent(res.id) + '/metadata', res, onSuccess, 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('/ajax/resources/' + encodeURIComponent(id) + '/content', body, { headers: headers }).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error, relatedForm) - }); + this.httpPostWithOptions('/ajax/resources/' + encodeURIComponent(id) + '/content', body, { headers: headers }, onSuccess, relatedForm); } addSimpleResource(name: string, type: string, subtype: string, description: string, content: string, onSuccess: Function, relatedForm?: FormGroup): void { @@ -80,17 +56,11 @@ export class ISService { .set('subtype', subtype) .set('description', description) .set('content', content); - this.client.post('/ajax/resources/', body, { headers: headers }).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error, relatedForm) - }); + this.httpPostWithOptions('/ajax/resources/', body, { headers: headers }, onSuccess, relatedForm); } deleteSimpleResource(resourceId: string, onSuccess: Function): void { - this.client.delete('/ajax/resources/' + encodeURIComponent(resourceId)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpDelete('/ajax/resources/' + encodeURIComponent(resourceId), onSuccess); } loadWfHistory(total: number, from: number, to: number, onSuccess: Function): void { @@ -99,140 +69,83 @@ export class ISService { if (from && from > 0) { params = params.append('from', from); } if (to && to > 0) { params = params.append('to', to); } - this.client.get('/ajax/wf_history/', { params: params }).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGetWithOptions('/ajax/wf_history/', { params: params }, onSuccess); } loadContexts(onSuccess: Function): void { - this.client.get('./ajax/contexts/').subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/contexts/', onSuccess); } loadContext(ctxId: string, onSuccess: Function): void { - this.client.get('./ajax/contexts/' + encodeURIComponent(ctxId)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/contexts/' + encodeURIComponent(ctxId), onSuccess); } loadContextCategories(ctxId: string, onSuccess: Function): void { - this.client.get('./ajax/contexts/' + encodeURIComponent(ctxId) + '/categories').subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/contexts/' + encodeURIComponent(ctxId) + '/categories', onSuccess); } loadContextConcepts(level: number, nodeId: string, onSuccess: Function): void { - this.client.get('./ajax/contexts/' + encodeURIComponent(level) + '/' + encodeURIComponent(nodeId) + '/concepts').subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/contexts/' + encodeURIComponent(level) + '/' + encodeURIComponent(nodeId) + '/concepts', onSuccess); } loadVocabularies(onSuccess: Function): void { - this.client.get('./ajax/vocs/').subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/vocs/', onSuccess); } loadVocabulary(vocId: string, onSuccess: Function): void { - this.client.get('./ajax/vocs/' + encodeURIComponent(vocId)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/vocs/' + encodeURIComponent(vocId), onSuccess); } loadVocabularyTerms(vocId: string, onSuccess: Function): void { - this.client.get('./ajax/vocs/' + encodeURIComponent(vocId) + '/terms').subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/vocs/' + encodeURIComponent(vocId) + '/terms', onSuccess); } saveVocabulary(voc: Vocabulary, onSuccess: Function, relatedForm?: FormGroup): void { - this.client.post('./ajax/vocs/', voc).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error, relatedForm) - }); + this.httpPost('./ajax/vocs/', voc, onSuccess, relatedForm); } saveVocabularyTerm(vocId: string, term: VocabularyTerm, onSuccess: Function, relatedForm?: FormGroup): void { - this.client.post('./ajax/vocs/' + encodeURIComponent(vocId) + '/terms', term).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error, relatedForm) - }); + this.httpPost('./ajax/vocs/' + encodeURIComponent(vocId) + '/terms', term, onSuccess, relatedForm); } deleteVocabulary(vocId: string, onSuccess: Function): void { - this.client.delete('./ajax/vocs/' + encodeURIComponent(vocId)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpDelete('./ajax/vocs/' + encodeURIComponent(vocId), onSuccess); } deleteVocabularyTerm(vocId: string, termCode: string, onSuccess: Function): void { - this.client.delete('./ajax/vocs/' + this.httpDelete('./ajax/vocs/' + encodeURIComponent(vocId) + '/terms/' + encodeURIComponent(termCode) - ).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + , onSuccess); } dsmConf(onSuccess: Function) { - this.client.get('./ajax/dsm/conf').subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/dsm/conf', onSuccess); } dsmBrowsableFields(onSuccess: Function) { - this.client.get('./ajax/dsm/browsableFields').subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/dsm/browsableFields', onSuccess); } dsmBrowse(field: string, onSuccess: Function) { - this.client.get('./ajax/dsm/browse/' + encodeURIComponent(field)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/dsm/browse/' + encodeURIComponent(field), onSuccess); } dsmSearchByField(field: string, value: string, page: number, pageSize: number, onSuccess: Function) { - this.client.get>('./ajax/dsm/searchByField/' + encodeURIComponent(field) + '/' + page + '/' + pageSize + '?value=' + encodeURIComponent(value)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet>('./ajax/dsm/searchByField/' + encodeURIComponent(field) + '/' + page + '/' + pageSize + '?value=' + encodeURIComponent(value), onSuccess); } dsmSearch(value: string, page: number, pageSize: number, onSuccess: Function) { - this.client.get>('./ajax/dsm/search/' + page + '/' + pageSize + '?value=' + encodeURIComponent(value)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet>('./ajax/dsm/search/' + page + '/' + pageSize + '?value=' + encodeURIComponent(value), onSuccess); } loadMDStores(onSuccess: Function): void { - this.client.get("/ajax/mdstores/").subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet("/ajax/mdstores/", onSuccess); } loadMDStore(mdId: string, onSuccess: Function): void { - this.client.get('./ajax/mdstores/mdstore/' + encodeURIComponent(mdId)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/mdstores/mdstore/' + encodeURIComponent(mdId), onSuccess); } addMDStore(format: string, layout: string, interpretation: string, type: string, dsName: string, dsId: string, apiId: string, onSuccess: Function, relatedForm?: FormGroup) { @@ -243,7 +156,7 @@ export class ISService { .set('dsId', dsId) .set('apiId', apiId); - this.client.post('/ajax/mdstores/new/' + this.httpPostWithOptions('/ajax/mdstores/new/' + encodeURIComponent(format) + '/' + encodeURIComponent(layout) @@ -251,170 +164,134 @@ export class ISService { + encodeURIComponent(interpretation) + '/' + encodeURIComponent(type), - body, { headers: headers }).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error, relatedForm) - }); + body, { headers: headers }, onSuccess, relatedForm); } deleteMDStore(mdId: string, onSuccess: Function): void { - this.client.delete('./ajax/mdstores/mdstore/' + encodeURIComponent(mdId)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpDelete('./ajax/mdstores/mdstore/' + encodeURIComponent(mdId), onSuccess); } prepareNewMDStoreVersion(mdId: string, onSuccess: Function): void { - this.client.get('./ajax/mdstores/mdstore/' + encodeURIComponent(mdId) + '/newVersion').subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/mdstores/mdstore/' + encodeURIComponent(mdId) + '/newVersion', onSuccess); } commitMDStoreVersion(versionId: string, size: number, onSuccess: Function) { - this.client.get('./ajax/mdstores/version/' + encodeURIComponent(versionId) + '/commit/' + size).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/mdstores/version/' + encodeURIComponent(versionId) + '/commit/' + size, onSuccess); } abortMDStoreVersion(versionId: string, onSuccess: Function) { - this.client.get('./ajax/mdstores/version/' + encodeURIComponent(versionId) + '/abort').subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/mdstores/version/' + encodeURIComponent(versionId) + '/abort', onSuccess); } deleteMDStoreVersion(versionId: string, onSuccess: Function) { - this.client.delete('./ajax/mdstores/version/' + encodeURIComponent(versionId)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpDelete('./ajax/mdstores/version/' + encodeURIComponent(versionId), onSuccess); } resetReadingMDStoreVersion(versionId: string, onSuccess: Function) { - this.client.get('./ajax/mdstores/version/' + encodeURIComponent(versionId) + '/resetReading').subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/mdstores/version/' + encodeURIComponent(versionId) + '/resetReading', onSuccess); } loadMDStoreVersions(mdId: string, onSuccess: Function): void { - this.client.get('./ajax/mdstores/mdstore/' + encodeURIComponent(mdId) + '/versions').subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/mdstores/mdstore/' + encodeURIComponent(mdId) + '/versions', onSuccess); } loadMDStoreVersion(versionId: string, onSuccess: Function): void { - this.client.get('./ajax/mdstores/version/' + encodeURIComponent(versionId)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/mdstores/version/' + encodeURIComponent(versionId), onSuccess); } loadMDStoreVersionRecords(versionId: string, limit: number, onSuccess: Function): void { - this.client.get('./ajax/mdstores/version/' + encodeURIComponent(versionId) + '/content/' + limit).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/mdstores/version/' + encodeURIComponent(versionId) + '/content/' + limit, onSuccess); } testCleaning(rule: string, xml: string, onSuccess: Function, relatedForm?: FormGroup): void { var headers = new HttpHeaders().set('Content-Type', 'text/plain; charset=utf-8'); - - this.client.post('./ajax/mapping/clean?rule=' + encodeURIComponent(rule), xml, { headers, responseType: 'text' as 'json' }).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error, relatedForm) - }); + this.httpPostWithOptions('./ajax/mapping/clean?rule=' + encodeURIComponent(rule), xml, { headers, responseType: 'text' as 'json' }, onSuccess, relatedForm); } loadEmailTemplates(onSuccess: Function): void { - this.client.get('./ajax/templates/email/').subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); + this.httpGet('./ajax/templates/email/', onSuccess); } saveEmailTemplate(email: EmailTemplate, onSuccess: Function, relatedForm?: FormGroup): void { - this.client.post('./ajax/templates/email/', email).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error, relatedForm) - }); + this.httpPost('./ajax/templates/email/', email, onSuccess, relatedForm); } deleteEmailTemplate(id: string, onSuccess: Function): void { - this.client.delete('./ajax/templates/email/' + encodeURIComponent(id)).subscribe({ + this.httpDelete('./ajax/templates/email/' + encodeURIComponent(id), onSuccess); + } + + loadWfConfigurationSections(onSuccess: Function): void { + this.httpGet('./ajax/wfs/sections', onSuccess); + } + + loadWfConfigurations(section: string, onSuccess: Function): void { + this.httpGet('./ajax/wfs/search?section=' + encodeURIComponent(section), onSuccess); + } + + loadWfConfiguration(id: string, onSuccess: Function): void { + this.httpGet('./ajax/wfs/conf/' + encodeURIComponent(id), onSuccess); + } + + + + saveWfConfiguration(conf: WfConf, onSuccess: Function, relatedForm?: FormGroup): void { + this.httpPost('./ajax/wfs/conf', conf, onSuccess, relatedForm); + } + + deleteWfConfiguration(id: string, onSuccess: Function): void { + this.httpDelete('./ajax/wfs/conf/' + encodeURIComponent(id), onSuccess); + } + + startWfConfiguration(id: string, onSuccess: Function): void { + this.httpGet('./ajax/wfs/conf/' + encodeURIComponent(id) + '/start', onSuccess); + } + + findProcess(id: string, onSuccess: Function): void { + this.httpGet('./ajax/wfs/process/' + encodeURIComponent(id), onSuccess); + } + + killProcess(id: string, onSuccess: Function): void { + this.httpDelete('./ajax/wfs/process/' + encodeURIComponent(id), onSuccess); + } + + findWfSubscriptions(id: string, onSuccess: Function): void { + this.httpGet('./ajax/wfs/conf/' + encodeURIComponent(id) + '/subscriptions', onSuccess); + } + + saveWfSubscriptions(id: string, subscriptions: WfSubscription[], onSuccess: Function, relatedForm?: FormGroup): void { + this.httpPost('./ajax/wfs/conf/' + encodeURIComponent(id) + '/subscriptions', subscriptions, onSuccess, relatedForm); + } + + private httpGet(url: string, onSuccess: Function) { + this.client.get(url).subscribe({ next: data => onSuccess(data), error: error => this.showError(error) }); } - loadWfIntancesSections(onSuccess: Function): void { - this.client.get('./ajax/wfs/sections').subscribe({ + private httpGetWithOptions(url: string, options: any, onSuccess: Function) { + this.client.get(url, options).subscribe({ next: data => onSuccess(data), error: error => this.showError(error) }); } - loadWfIntances(section: string, onSuccess: Function): void { - this.client.get('./ajax/wfs/search?section=' + encodeURIComponent(section)).subscribe({ + private httpDelete(url: string, onSuccess: Function) { + this.client.delete(url).subscribe({ next: data => onSuccess(data), error: error => this.showError(error) }); } - loadWfIntance(id: string, onSuccess: Function): void { - this.client.get('./ajax/wfs/conf/' + encodeURIComponent(id)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); - } - - saveWfIntance(conf: WfConf, onSuccess: Function, relatedForm?: FormGroup): void { - this.client.post('./ajax/wfs/conf', conf).subscribe({ + private httpPost(url: string, body: any, onSuccess: Function, relatedForm?: FormGroup) { + this.client.post(url, body).subscribe({ next: data => onSuccess(data), error: error => this.showError(error, relatedForm) }); } - deleteWfIntance(id: string, onSuccess: Function): void { - this.client.delete('./ajax/wfs/conf/' + encodeURIComponent(id)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); - } - - startWfIntance(id: string, onSuccess: Function): void { - this.client.get('./ajax/wfs/conf/' + encodeURIComponent(id) + '/start').subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); - } - - findProcess(id: string, onSuccess: Function): void { - this.client.get('./ajax/wfs/process/' + encodeURIComponent(id)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); - } - - killProcess(id: string, onSuccess: Function): void { - this.client.delete('./ajax/wfs/process/' + encodeURIComponent(id)).subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); - } - - findWfSubscriptions(id: string, onSuccess: Function): void { - this.client.get('./ajax/wfs/conf/' + encodeURIComponent(id) + '/subscriptions').subscribe({ - next: data => onSuccess(data), - error: error => this.showError(error) - }); - } - - saveWfSubscriptions(id: string, subscriptions: WfSubscription[], onSuccess: Function, relatedForm?: FormGroup): void { - this.client.post('./ajax/wfs/conf/' + encodeURIComponent(id) + '/subscriptions', subscriptions).subscribe({ + private httpPostWithOptions(url: string, body: any, options: any, onSuccess: Function, relatedForm?: FormGroup) { + this.client.post(url, body, options).subscribe({ next: data => onSuccess(data), error: error => this.showError(error, relatedForm) });