From 196b89358efd7f82819a09066f2bdc6bd51e0fac Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Wed, 31 Jan 2024 12:48:42 +0100 Subject: [PATCH] oai explorer page --- .../is/src/app/app-routing.module.ts | 2 + dnet-app/frontends/is/src/app/app.module.ts | 2 + .../main-menu-panels.component.html | 1 + .../oai-explorer/oai-explorer.component.html | 26 +++++++ .../oai-explorer/oai-explorer.component.ts | 77 +++++++++++++++++++ .../java/eu/dnetlib/common/oai/OaiClient.java | 20 ++--- .../eu/dnetlib/common/oai/OaiResponse.java | 9 +++ 7 files changed, 123 insertions(+), 14 deletions(-) create mode 100644 dnet-app/frontends/is/src/app/oai-explorer/oai-explorer.component.html create mode 100644 dnet-app/frontends/is/src/app/oai-explorer/oai-explorer.component.ts diff --git a/dnet-app/frontends/is/src/app/app-routing.module.ts b/dnet-app/frontends/is/src/app/app-routing.module.ts index 4ac1b9e..b59e8a2 100644 --- a/dnet-app/frontends/is/src/app/app-routing.module.ts +++ b/dnet-app/frontends/is/src/app/app-routing.module.ts @@ -13,6 +13,7 @@ import { WfConfsComponent } from './wf-confs/wf-confs.component'; import { IndexComponent } from './index/index.component'; import { OaiComponent } from './oai/oai.component'; import { SwaggerUiComponent } from './swagger/swagger-ui.component'; +import { OaiExplorerComponent } from './oai-explorer/oai-explorer.component'; const routes: Routes = [ @@ -35,6 +36,7 @@ const routes: Routes = [ { path: "cleaner", component: CleanerTesterComponent }, { path: "index", component: IndexComponent }, { path: "oai", component: OaiComponent }, + { path: "oai-explorer", component: OaiExplorerComponent }, { path: "swagger-ui/:id", component: SwaggerUiComponent } ]; diff --git a/dnet-app/frontends/is/src/app/app.module.ts b/dnet-app/frontends/is/src/app/app.module.ts index 8e15380..6efad9f 100644 --- a/dnet-app/frontends/is/src/app/app.module.ts +++ b/dnet-app/frontends/is/src/app/app.module.ts @@ -48,6 +48,7 @@ import { WfTemplateDialog, WfConfDialog, WfConfLauncherDialog } from './wf-confs import { MatMenuModule } from '@angular/material/menu'; import { MatDatepickerModule } from '@angular/material/datepicker'; import { MatNativeDateModule } from '@angular/material/core'; +import { OaiExplorerComponent } from './oai-explorer/oai-explorer.component'; @NgModule({ declarations: [ @@ -90,6 +91,7 @@ import { MatNativeDateModule } from '@angular/material/core'; WfConfLauncherDialog, IndexComponent, OaiComponent, + OaiExplorerComponent, SwaggerUiComponent ], imports: [ diff --git a/dnet-app/frontends/is/src/app/main-menu-panels/main-menu-panels.component.html b/dnet-app/frontends/is/src/app/main-menu-panels/main-menu-panels.component.html index f06b074..3380997 100644 --- a/dnet-app/frontends/is/src/app/main-menu-panels/main-menu-panels.component.html +++ b/dnet-app/frontends/is/src/app/main-menu-panels/main-menu-panels.component.html @@ -18,6 +18,7 @@
Search + Oai Explorer
diff --git a/dnet-app/frontends/is/src/app/oai-explorer/oai-explorer.component.html b/dnet-app/frontends/is/src/app/oai-explorer/oai-explorer.component.html new file mode 100644 index 0000000..b82ab4a --- /dev/null +++ b/dnet-app/frontends/is/src/app/oai-explorer/oai-explorer.component.html @@ -0,0 +1,26 @@ +

Oai Explorer

+ + + OAI BaseUrl + + + + + + + + + +
+{{oaiResponse | json}}
+
diff --git a/dnet-app/frontends/is/src/app/oai-explorer/oai-explorer.component.ts b/dnet-app/frontends/is/src/app/oai-explorer/oai-explorer.component.ts new file mode 100644 index 0000000..802c678 --- /dev/null +++ b/dnet-app/frontends/is/src/app/oai-explorer/oai-explorer.component.ts @@ -0,0 +1,77 @@ +import { Component, Inject, Injectable, OnInit } from '@angular/core'; +import { ActivatedRoute, Params, Router } from '@angular/router'; +import { MatDialog, MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import { MDStore, MDStoreRecord, MDStoreVersion } from '../common/is.model'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { ISClient } from '../common/is.client'; +import { combineLatest } from 'rxjs'; + +@Component({ + selector: 'oai-explorer', + templateUrl: './oai-explorer.component.html', + styleUrls: [] +}) +export class OaiExplorerComponent implements OnInit { + + oaiBaseUrl: string = "" + page: number = 1; + oaiResponse = {}; + + constructor(public client: OaiExplorerClient, public router: Router, public route: ActivatedRoute, public dialog: MatDialog) { } + + ngOnInit() { + combineLatest([this.route.params, this.route.queryParams], + (params: Params, queryParams: Params) => ({ params, queryParams }) + ).subscribe((res: { params: Params; queryParams: Params }) => { + this.oaiBaseUrl = res.queryParams['baseUrl']; + + if (this.oaiBaseUrl) { + if (res.queryParams['page'] == 1) { + this.client.callIdentifyVerb(this.oaiBaseUrl, (res: any) => this.oaiResponse = res); + } else if (res.queryParams['page'] == 2) { + this.client.callListSetsVerb(this.oaiBaseUrl, (res: any) => this.oaiResponse = res); + } else if (res.queryParams['page'] == 3) { + this.client.callListMdFormatsVerb(this.oaiBaseUrl, (res: any) => this.oaiResponse = res); + } else if (res.queryParams['page'] == 4) { + this.client.callListRecordsVerb(this.oaiBaseUrl, (res: any) => this.oaiResponse = res); + } else if (res.queryParams['page'] == 5) { + this.client.callListIdentifiersVerb(this.oaiBaseUrl, (res: any) => this.oaiResponse = res); + } else { + this.client.callIdentifyVerb(this.oaiBaseUrl, (res: any) => this.oaiResponse = res); + } + } + }); + } + + changeUrl(baseUrl: string, page: number) { + this.router.navigate(['/oai-explorer'], { queryParams: { baseUrl: baseUrl, page: page } }); + } +} + +@Injectable({ + providedIn: 'root' +}) +export class OaiExplorerClient extends ISClient { + baseUrl = '/proxy/byType/datasource_manager/api'; + + callIdentifyVerb(oaiBaseUrl: string, onSuccess: Function) { + this.httpGet(this.baseUrl + '/oai-explorer/info?baseUrl=' + encodeURIComponent(oaiBaseUrl), onSuccess); + } + + callListSetsVerb(oaiBaseUrl: string, onSuccess: Function) { + this.httpGet(this.baseUrl + '/oai-explorer/sets?baseUrl=' + encodeURIComponent(oaiBaseUrl), onSuccess); + } + + callListMdFormatsVerb(oaiBaseUrl: string, onSuccess: Function) { + this.httpGet(this.baseUrl + '/oai-explorer/mdformats?baseUrl=' + encodeURIComponent(oaiBaseUrl), onSuccess); + } + + callListRecordsVerb(oaiBaseUrl: string, onSuccess: Function) { + this.httpGet(this.baseUrl + '/oai-explorer/records?baseUrl=' + encodeURIComponent(oaiBaseUrl), onSuccess); + } + + callListIdentifiersVerb(oaiBaseUrl: string, onSuccess: Function) { + this.httpGet(this.baseUrl + '/oai-explorer/identifiers?baseUrl=' + encodeURIComponent(oaiBaseUrl), onSuccess); + } + +} diff --git a/dnet-app/libs/dnet-oai-common/src/main/java/eu/dnetlib/common/oai/OaiClient.java b/dnet-app/libs/dnet-oai-common/src/main/java/eu/dnetlib/common/oai/OaiClient.java index 4d63dc1..b2db224 100644 --- a/dnet-app/libs/dnet-oai-common/src/main/java/eu/dnetlib/common/oai/OaiClient.java +++ b/dnet-app/libs/dnet-oai-common/src/main/java/eu/dnetlib/common/oai/OaiClient.java @@ -1,7 +1,6 @@ package eu.dnetlib.common.oai; import java.util.List; -import java.util.Map; import java.util.function.Function; import org.apache.commons.lang3.StringUtils; @@ -10,10 +9,6 @@ import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.Node; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -134,21 +129,18 @@ public class OaiClient { } private void callOaiVerb(final OaiRequest req, final OaiResponse res, final Function processBody) { - - res.setVerb(req.getVerb()); final long start = System.currentTimeMillis(); try { - final HttpHeaders headers = new HttpHeaders(); - headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_VALUE); - - final Map params = req.toQueryParams(); + res.setVerb(req.getVerb()); final UriComponentsBuilder urlBuilder = UriComponentsBuilder.fromHttpUrl(req.getBaseUrl()); - params.keySet().forEach(k -> urlBuilder.queryParam(k, "{" + k + "}")); + req.toQueryParams().forEach((k, v) -> urlBuilder.queryParam(k, v)); - final ResponseEntity httpResponse = - new RestTemplate().exchange(urlBuilder.encode().toUriString(), HttpMethod.GET, new HttpEntity<>(headers), String.class, params); + final String url = urlBuilder.encode().toUriString(); + res.setUrl(url); + + final ResponseEntity httpResponse = new RestTemplate().getForEntity(url, String.class); res.setHttpCode(httpResponse.getStatusCode().value()); diff --git a/dnet-app/libs/dnet-oai-common/src/main/java/eu/dnetlib/common/oai/OaiResponse.java b/dnet-app/libs/dnet-oai-common/src/main/java/eu/dnetlib/common/oai/OaiResponse.java index 4238c49..c60a32c 100644 --- a/dnet-app/libs/dnet-oai-common/src/main/java/eu/dnetlib/common/oai/OaiResponse.java +++ b/dnet-app/libs/dnet-oai-common/src/main/java/eu/dnetlib/common/oai/OaiResponse.java @@ -5,6 +5,7 @@ import java.io.Serializable; public class OaiResponse implements Serializable { private static final long serialVersionUID = -7841519266909952558L; + private String url; private String verb; private long time; private int httpCode; @@ -16,6 +17,14 @@ public class OaiResponse implements Serializable { private T body; private String resumptionToken; + public void setUrl(final String url) { + this.url = url; + } + + public String getUrl() { + return this.url; + } + public String getVerb() { return this.verb; }