oai explorer

This commit is contained in:
Michele Artini 2024-01-31 16:02:40 +01:00
parent 196b89358e
commit d330b4442d
3 changed files with 248 additions and 35 deletions

View File

@ -3,24 +3,220 @@
<mat-form-field appearance="fill" floatLabel="always" style="width: 100%;">
<mat-label>OAI BaseUrl</mat-label>
<input matInput [(ngModel)]="oaiBaseUrl" />
<button mat-stroked-button matSuffix color="primary" (click)="changeUrl(oaiBaseUrl, 1)">
<button mat-stroked-button matSuffix color="primary" (click)="gotoPage(1, null, null, null, null)"
[disabled]="!oaiBaseUrl">
Info
</button>
<button mat-stroked-button matSuffix color="primary" (click)="changeUrl(oaiBaseUrl, 2)">
<button mat-stroked-button matSuffix color="primary" (click)="gotoPage(2, null, null, null, null)"
[disabled]="!oaiBaseUrl">
Sets
</button>
<button mat-stroked-button matSuffix color="primary" (click)="changeUrl(oaiBaseUrl, 3)">
<button mat-stroked-button matSuffix color="primary" (click)="gotoPage(3, null, null, null, null)"
[disabled]="!oaiBaseUrl">
MD Formats
</button>
<button mat-stroked-button matSuffix color="primary" (click)="changeUrl(oaiBaseUrl, 4)">
<button mat-stroked-button matSuffix color="primary" (click)="gotoPage(4, null, null, null, null)"
[disabled]="!oaiBaseUrl">
Records
</button>
<button mat-stroked-button matSuffix color="primary" (click)="changeUrl(oaiBaseUrl, 5)" style="margin-right: 0.5em;">
<button mat-stroked-button matSuffix color="primary" (click)="gotoPage(5, null, null, null, null)"
[disabled]="!oaiBaseUrl" style="margin-right: 0.5em;">
Identifiers
</button>
</mat-form-field>
<pre>
{{oaiResponse | json}}
</pre>
<p>
<span *ngIf="oaiResponse.url">
<b>OAI URL: </b>
<a href="{{oaiResponse.url}}" target="_blank" *ngIf="oaiResponse.url">{{oaiResponse.url}}</a>
<br />
</span>
<span *ngIf="oaiResponse.verb"><b>OAI Verb: </b> {{oaiResponse.verb}}<br /></span>
<span *ngIf="oaiResponse.httpCode"><b>Response Code: </b> {{oaiResponse.httpCode}}<br /></span>
<span *ngIf="oaiResponse.time"><b>Response Time: </b> {{oaiResponse.time}} ms<br /></span>
</p>
<mat-card *ngIf="!oaiResponse.valid">
<mat-card-content>
<pre>{{oaiResponse.error}}</pre>
</mat-card-content>
</mat-card>
<!-- INFO -->
<mat-card *ngIf="oaiResponse.valid && page == 1" style="margin-top: 2em;">
<mat-card-content>
<table>
<tr>
<th align="left" width="20%">Repository Name</th>
<td>{{oaiResponse.body.repositoryName}}</td>
</tr>
<tr>
<th align="left" width="20%">Base URL</th>
<td>{{oaiResponse.body.baseURL}}</td>
</tr>
<tr>
<th align="left" width="20%">Protocol Version</th>
<td>{{oaiResponse.body.protocolVersion}}</td>
</tr>
<tr>
<th align="left" width="20%">Earliest Datestamp</th>
<td>{{oaiResponse.body.earliestDatestamp}}</td>
</tr>
<tr>
<th align="left" width="20%">Deleted Record</th>
<td>{{oaiResponse.body.deletedRecord}}</td>
</tr>
<tr>
<th align="left" width="20%">Granularity</th>
<td>{{oaiResponse.body.granularity}}</td>
</tr>
<tr *ngFor="let email of oaiResponse.body.adminEmails">
<th align="left" width="20%">Admin Email</th>
<td>{{email}}</td>
</tr>
<tr *ngFor="let c of oaiResponse.body.compressions">
<th align="left" width="20%">Compression</th>
<td>{{c}}</td>
</tr>
<tr *ngFor="let desc of oaiResponse.body.descriptions">
<th align="left" width="20%">Description</th>
<td>{{desc}}</td>
</tr>
</table>
</mat-card-content>
</mat-card>
<!-- SETS -->
<ng-container *ngIf="oaiResponse.valid && page == 2 && oaiResponse.body && oaiResponse.body.length">
<mat-card *ngFor=" let s of oaiResponse.body" style="margin-top: 2em;">
<mat-card-content>
<table>
<tr>
<th align="left" width="20%">Set Spec</th>
<td>{{s.setSpec}}</td>
</tr>
<tr>
<th align="left" width="20%">Set Name</th>
<td>{{s.setName}}</td>
</tr>
<tr *ngIf="s.description">
<th align="left" width="20%">Description</th>
<td>{{s.description}}</td>
</tr>
</table>
</mat-card-content>
<mat-card-actions>
<button mat-stroked-button matSuffix color="primary" (click)="gotoPage(4, s.setSpec, null, null, null)">
Records
</button>
<button mat-stroked-button matSuffix color="primary" (click)="gotoPage(5, s.setSpec, null, null, null)">
Identifiers
</button>
</mat-card-actions>
</mat-card>
</ng-container>
<!-- SETS -->
<ng-container *ngIf="oaiResponse.valid && page == 3 && oaiResponse.body && oaiResponse.body.length">
<mat-card *ngFor=" let f of oaiResponse.body" style="margin-top: 2em;">
<mat-card-content>
<table>
<tr>
<th align="left" width="20%">Metadata Prefix</th>
<td>{{f.metadataPrefix}}</td>
</tr>
<tr>
<th align="left" width="20%">Metadata Namespace</th>
<td>{{f.metadataNamespace}}</td>
</tr>
<tr>
<th align="left" width="20%">Metadata Schema</th>
<td>{{f.metadataSchema}}</td>
</tr>
</table>
</mat-card-content>
<mat-card-actions>
<button mat-stroked-button matSuffix color="primary" (click)="gotoPage(4, null, f.metadataPrefix, null, null)">
Records
</button>
<button mat-stroked-button matSuffix color="primary" (click)="gotoPage(5, null, f.metadataPrefix, null, null)">
Identifiers
</button>
</mat-card-actions>
</mat-card>
</ng-container>
<!-- Records -->
<ng-container *ngIf="oaiResponse.valid && page == 4 && oaiResponse.body && oaiResponse.body.length">
<mat-card *ngFor=" let r of oaiResponse.body" style="margin-top: 2em;">
<mat-card-content>
<table>
<tr>
<th align="left" width="20%">ID</th>
<td>{{r.id}}</td>
</tr>
<tr>
<th align="left" width="20%">Date</th>
<td>{{r.date}}</td>
</tr>
<tr *ngFor="let s of r.sets">
<th align="left" width="20%">In Set</th>
<td>{{s}}</td>
</tr>
</table>
</mat-card-content>
<mat-card-content>
<pre>{{r.body}}</pre>
</mat-card-content>
</mat-card>
</ng-container>
<!-- Identifiers -->
<ng-container *ngIf="oaiResponse.valid && page == 5 && oaiResponse.body && oaiResponse.body.length">
<mat-card *ngFor=" let r of oaiResponse.body" style="margin-top: 2em;">
<mat-card-content>
<table>
<tr>
<th align="left" width="20%">ID</th>
<td>{{r.id}}</td>
</tr>
<tr>
<th align="left" width="20%">Date</th>
<td>{{r.date}}</td>
</tr>
<tr *ngFor="let s of r.sets">
<th align="left" width="20%">In Set</th>
<td>{{s}}</td>
</tr>
</table>
</mat-card-content>
<mat-card-actions>
<button mat-stroked-button matSuffix color="primary" (click)="gotoPage(4, null, null, null, r.id)">
Get Record (TODO)
</button>
</mat-card-actions>
</mat-card>
</ng-container>
<!-- Single Record -->
<mat-card *ngIf="oaiResponse.valid && page == 6 && oaiResponse.body">
<mat-card-content>
<table>
<tr>
<th align="left" width="20%">ID</th>
<td>{{oaiResponse.body.id}}</td>
</tr>
<tr>
<th align="left" width="20%">Date</th>
<td>{{oaiResponse.body.date}}</td>
</tr>
<tr *ngFor="let s of oaiResponse.body.sets">
<th align="left" width="20%">In Set</th>
<td>{{s}}</td>
</tr>
</table>
</mat-card-content>
<mat-card-content>
<pre>{{oaiResponse.body.body}}</pre>
</mat-card-content>
</mat-card>

View File

@ -14,8 +14,8 @@ import { combineLatest } from 'rxjs';
export class OaiExplorerComponent implements OnInit {
oaiBaseUrl: string = ""
page: number = 1;
oaiResponse = {};
page: number = 0;
oaiResponse: any = {};
constructor(public client: OaiExplorerClient, public router: Router, public route: ActivatedRoute, public dialog: MatDialog) { }
@ -24,27 +24,26 @@ export class OaiExplorerComponent implements OnInit {
(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);
}
}
this.gotoPage(1, null, null, null, null);
});
}
changeUrl(baseUrl: string, page: number) {
this.router.navigate(['/oai-explorer'], { queryParams: { baseUrl: baseUrl, page: page } });
gotoPage(page: number, set: string | null, format: string | null, token: string | null, id: string | null) {
this.page = page;
if (this.oaiBaseUrl) {
if (this.page == 1) {
this.client.callIdentifyVerb(this.oaiBaseUrl, (res: any) => this.oaiResponse = res);
} else if (this.page == 2) {
this.client.callListSetsVerb(this.oaiBaseUrl, token, (res: any) => this.oaiResponse = res);
} else if (this.page == 3) {
this.client.callListMdFormatsVerb(this.oaiBaseUrl, (res: any) => this.oaiResponse = res);
} else if (this.page == 4) {
this.client.callListRecordsVerb(this.oaiBaseUrl, set, format, token, (res: any) => this.oaiResponse = res);
} else if (this.page == 5) {
this.client.callListIdentifiersVerb(this.oaiBaseUrl, set, format, token, (res: any) => this.oaiResponse = res);
}
}
}
}
@ -58,20 +57,36 @@ export class OaiExplorerClient extends ISClient {
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);
callListSetsVerb(oaiBaseUrl: string, token: string | null, onSuccess: Function) {
let url = this.baseUrl + '/oai-explorer/sets?baseUrl=' + encodeURIComponent(oaiBaseUrl);
if (token) { url += "&token=" + encodeURIComponent(token); }
this.httpGet(url, 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);
callListRecordsVerb(oaiBaseUrl: string, set: string | null, format: string | null, token: string | null, onSuccess: Function) {
let url = this.baseUrl + '/oai-explorer/records?baseUrl=' + encodeURIComponent(oaiBaseUrl);
if (token) {
url += "&token=" + encodeURIComponent(token);
} else {
if (set) { url += '&set=' + encodeURIComponent(set); }
if (format) { url += '&format=' + encodeURIComponent(format); }
}
this.httpGet(url, onSuccess);
}
callListIdentifiersVerb(oaiBaseUrl: string, onSuccess: Function) {
this.httpGet(this.baseUrl + '/oai-explorer/identifiers?baseUrl=' + encodeURIComponent(oaiBaseUrl), onSuccess);
callListIdentifiersVerb(oaiBaseUrl: string, set: string | null, format: string | null, token: string | null, onSuccess: Function) {
let url = this.baseUrl + '/oai-explorer/identifiers?baseUrl=' + encodeURIComponent(oaiBaseUrl);
if (token) {
url += "&token=" + encodeURIComponent(token);
} else {
if (set) { url += '&set=' + encodeURIComponent(set); }
if (format) { url += '&format=' + encodeURIComponent(format); }
}
this.httpGet(url, onSuccess);
}
}

View File

@ -9,6 +9,7 @@ import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Node;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
@ -162,6 +163,7 @@ public class OaiClient {
}
} catch (final Throwable e) {
res.setValid(false);
res.setHttpCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
res.setError(e.getMessage());
} finally {
res.setTime(System.currentTimeMillis() - start);