[WIP] Initial commit for new page to upload dois and get research results

This commit is contained in:
argirok 2023-10-25 17:42:38 +03:00
parent ab63ca457b
commit a41e994626
7 changed files with 332 additions and 3 deletions

View File

@ -5,6 +5,10 @@ const routes: Routes = [
{
path: 'researcher',
loadChildren: () => import('./researcher/researcher-routing.module').then(m => m.ResearcherRoutingModule)
},
{
path: 'upload-dois',
loadChildren: () => import('./upload-dois/upload-dois.module').then(m => m.UploadDoisModule)
}
];

View File

@ -2,7 +2,6 @@ import { Component } from '@angular/core';
import {properties} from "../environments/environment";
import {ActivatedRoute, Router} from "@angular/router";
import {MenuItem} from "./openaireLibrary/sharedComponents/menu";
import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component";
@Component({
selector: 'app-root',
@ -35,7 +34,7 @@ export class AppComponent {
view: boolean = false;
hasHeader: boolean = true;
properties = properties;
header: Header = {
header = {
route: "/",
title: "Noami",
logoUrl: "",
@ -58,6 +57,9 @@ export class AppComponent {
, null, null, null, null),
new MenuItem("repository", "Repository Monitors",
"", "/", false, [], null, {}
, null, null, null, null),
new MenuItem("upload-dois", "Upload DOIs",
"", "/upload-dois", false, [], null, {}
, null, null, null, null)
];
constructor(private route: ActivatedRoute,

View File

@ -0,0 +1,16 @@
import {NgModule} from "@angular/core";
import {RouterModule} from "@angular/router";
import {UploadDoisComponent} from "./upload-dois.component";
@NgModule({
imports: [
RouterModule.forChild([
{
path: '',
component: UploadDoisComponent
}
])
]
})
export class UploadDoisRoutingModule {
}

View File

@ -0,0 +1,42 @@
<div class="uk-float-left">
<span class="js-upload" uk-form-custom>
<input id="exampleInputFile" class="uk-width-medium" type="file" (change)="fileChangeEvent($event)"/>
<span class="uk-link " style="text-decoration: underline;">Upload a DOI's CSV file </span>
</span>
<!--button class="uk-button portal-button" type="button" tabindex="-1" [class.disabled]="!enableUpload" ><span class="uk-margin-small-right uk-icon" >
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> <polyline fill="none" stroke="#000" points="5 8 9.5 3.5 14 8 "></polyline> <rect x="3" y="17" width="13" height="1"></rect>
<line fill="none" stroke="#000" x1="9.5" y1="15" x2="9.5" y2="4"></line></svg></span> Select</button-->
<!--helper div="link-result-bulk" tooltip=true ></helper-->
<span class=" " uk-tooltip><span class="uk-icon" uk-icon="icon: info; ratio: 0.8">&nbsp; </span> </span>
</div>
<div class="uk-width-1-1">
All valid DOIs: {{allIds.length}} <br>
invalid DOIs: {{noValidIds.length}} <br>
duplicate: {{duplicateIds.length}} <br>
found in Openaire: {{foundIds.length}} <br>
not found in Openaire: {{notFoundIds.length}} <br>
</div>
<div *ngIf="foundIds.length + notFoundIds.length <allIds.length"> Fetching {{foundIds.length + notFoundIds.length}}/{{allIds.length}}... </div>
{{results.length}}
<div>
<div>
<paging-no-load [totalResults]="foundIds.length" [size]="size" [currentPage]="page" (pageChange)="updatePage($event)"></paging-no-load>
<table class="uk-table uk-table-responsive uk-table-striped">
<tr *ngFor="let result of results.slice((page-1)*size,page*size)">
<td>{{result.doi}}</td>
<ng-container *ngIf="result.found">
<td>{{result.title}}</td>
<td>{{result.accessMode}}</td>
<td>{{result.accessRoute}}</td>
</ng-container>
<ng-container *ngIf="!result.found">
<td> not found </td>
</ng-container>
</tr>
</table>
</div>
</div>
<modal-loading
[message]="'Uploading, reading your document and fetching results. Please give us a moment..'"></modal-loading>

View File

@ -0,0 +1,245 @@
import {Component, Input, OnInit, ViewChild} from '@angular/core';
import {Dates, DOI, Identifier, StringUtils} from "../openaireLibrary/utils/string-utils.class";
import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties";
import {ErrorCodes} from "../openaireLibrary/utils/properties/errorCodes";
import {Subscriber, timer} from "rxjs";
import {properties} from "../../environments/environment";
import {ClaimEntity} from "../openaireLibrary/claims/claim-utils/claimHelper.class";
import {ModalLoading} from "../openaireLibrary/utils/modal/loading.component";
import {SearchResearchResultsService} from "../openaireLibrary/services/searchResearchResults.service";
import {map} from "rxjs/operators";
@Component({
selector: 'upload-dois',
templateUrl: './upload-dois.component.html',
})
export class UploadDoisComponent implements OnInit {
page: number = 1;
size: number = 20;
public keyword: string = "";//"paolo manghi";//'0000-0001-7291-3210';
properties: EnvProperties = properties;
public errorCodes: ErrorCodes = new ErrorCodes();
public warningMessage = "";
public infoMessage = "";
subscriptions = [];
filesToUpload: Array<File>;
public select: boolean = true;
public results =[];
allIds: string[] = [];
foundIds: string[] = [];
existedIds: string[] = [];
duplicateIds: string[] = [];
duplicateIdsRow: number[] = [];
notFoundIds: string[] = [];
notFoundIdsRow: number[] = [];
noValidIds: string[] = [];
noValidIdsRow: number[] = [];
showReport: boolean = false;
@ViewChild(ModalLoading) loading: ModalLoading;
errorMessage = "";
enableUpload: boolean = true;
exceedsLimit = false;
fileLimit = 5;
constructor(private _searchResearchResultsService: SearchResearchResultsService) {
}
ngOnInit() {
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => {
if (subscription instanceof Subscriber) {
subscription.unsubscribe();
}
});
}
upload() {
this.enableUpload = false;
this.showReport = false;
this.errorMessage = "";
console.log(this.filesToUpload);
if (this.filesToUpload.length == 0) {
this.errorMessage = "There is no selected file to upload.";
return;
} else {
if (this.filesToUpload[0].name.indexOf(".csv") == -1 ||
(this.filesToUpload[0].type != "text/csv" && this.filesToUpload[0].type != "application/vnd.ms-excel")) {
this.errorMessage = "No valid file type. The required type is CSV";
return;
}
}
// this.loading.open();
console.log("here!");
this.makeFileRequest(this.properties.utilsService + '/upload', [], this.filesToUpload).then((result) => {
const rows = (result as any).split('\n'); // I have used space, you can use any thing.
this.exceedsLimit = false;
let invalid_rows = 0;
this.duplicateIds = [];
this.existedIds = [];
this.allIds = [];
this.foundIds = [];
this.noValidIds = [];
// this.results.slice(0, this.results.length);
this.notFoundIds = [];
if(rows.length > this.fileLimit){
this.exceedsLimit = true;
}
for (let i = 0; i < ( rows.length); i++) {23
if (rows[i] && rows[i] != null && rows[i]!="") {
const values = rows[i].split(',');
let id = this.removeDoubleQuotes(values[0]);
if (DOI.isValidDOI(id)) {
id = Identifier.getRawDOIValue(id);
console.log(id, id.split("\r")[0]);
id=id.split("\r")[0]
if (this.allIds.indexOf(id) > -1) {
this.duplicateIds.push(id);
this.duplicateIdsRow.push(i + 1);
} else {
this.allIds.push(id);
}
} else {
this.noValidIds.push(id);
this.noValidIdsRow.push(i + 1);
}
} else {
invalid_rows++;
}
}
this.fetchAllResults();
}, (error) => {
this.enableUpload = true;
this.loading.close();
this.errorMessage = "An error occured.";
this.handleError("Error uploading file", error);
});
}
private removeDoubleQuotes(value) {
if (value.indexOf('"') == 0) {
value = value.substring(1, value.length);
}
const index = +value.indexOf('"');
if (index == (value.length - 1) || index == (value.length - 2)) {
value = value.substring(0, index);
}
return value;
}
private validateAccessMode(value) {
const accessModes = ["OPEN", "CLOSED", "EMBARGO"];
return accessModes.indexOf(value) > -1;
}
fileChangeEvent(fileInput: any) {
this.filesToUpload = <Array<File>>fileInput.target.files;
this.upload();
}
makeFileRequest(url: string, params: Array<string>, files: Array<File>) {
return new Promise<void>((resolve, reject) => {
const formData: any = new FormData();
const xhr = new XMLHttpRequest();
for (let i = 0; i < files.length; i++) {
formData.append("uploads[]", files[i], files[i].name);
}
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
resolve(xhr.response);
} else {
reject(xhr.response);
}
}
}
xhr.open("POST", url, true);
xhr.send(formData);
});
}
fetchAllResults() {
let page = 1;
let timerSubscription = timer(0, 1000).pipe(
map(() => {
if((page-1)*this.size <= this.allIds.length) {
this.fetchResultsByPage(page); // load data contains the http request
page += 1;
}else{
this.stopFetching(timerSubscription);
}
})
).subscribe();
this.subscriptions.push(timerSubscription);
}
stopFetching(timerSubscription){
timerSubscription.unsubscribe();
}
fetchResultsByPage(page) {
let dois = this.allIds.slice((page-1)*this.size,page*this.size);
if(dois.length == 0){
return;
}
let query = ""
for (let i = 0; i < dois.length; i++) {
query += (query.length > 0 ? " or " : "") + '(pidclassid exact "doi" and pid="' + StringUtils.URIEncode(dois[i]) + '")';
}
// this.subscriptions.push(this._searchResearchResultsService.advancedSearchResults("publications",query ,1,this.size,null,properties,"&type=results").subscribe(data=>{
this.subscriptions.push(this._searchResearchResultsService.fetchByDOIs(dois).subscribe( data => {
for(let result of data[1]){
let matchingDOI =this.findMatchingDoi(result.DOIs,dois)
this.foundIds.push(matchingDOI);
this.results.push({ doi:matchingDOI, title: result.title.name, accessMode:result.title.accessMode, accessRoute:null, found: true})
}
if(data[0]<dois.length){
for(let doi of dois){
if(this.foundIds.indexOf(doi) ==-1){
this.notFoundIds.push(doi);
// this.results.push({ doi:doi, title: null, accessMode:null, accessRoute:null, found: false})
}
}
}
}));
}
findMatchingDoi(resultDois,requestedDois){
for(let doi of resultDois){
if(requestedDois.indexOf(doi)!=-1){
return doi;
}
}
return null;
}
private handleError(message: string, error) {
console.error("Bulk Claim (component): " + message, error);
}
private isSelected(result: ClaimEntity) {
let found: boolean = false;
const id = result.id;
for (let _i = 0; _i < this.results.length; _i++) {
let item = this.results[_i];
if (item.id && item.id == id) {
found = true;
break;
}
}
return found;
// indexOf doesn't work when results came from
// return this.selectedResults.indexOf(entity)!=-1;
}
updatePage($event) {
this.page = $event.value;
}
}

View File

@ -0,0 +1,18 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {UploadDoisComponent} from "./upload-dois.component";
import {UploadDoisRoutingModule} from "./upload-dois-routing.module";
import {LoadingModalModule} from "../openaireLibrary/utils/modal/loadingModal.module";
import {SearchResearchResultsServiceModule} from "../openaireLibrary/services/searchResearchResultsService.module";
import {PagingModule} from "../openaireLibrary/utils/paging.module";
@NgModule({
declarations: [UploadDoisComponent],
imports: [
CommonModule, UploadDoisRoutingModule, LoadingModalModule, SearchResearchResultsServiceModule, PagingModule
],
// exports: [UploadDoisComponent]
})
export class UploadDoisModule { }

View File

@ -15,7 +15,9 @@ let props: EnvProperties = {
searchOrcidURL: "https://pub.orcid.org/v3.0/",
piwikSiteId: "407",
enablePiwikTrack:false,
piwikBaseUrl: 'https://beta.analytics.openaire.eu/piwik.php?idsite='
piwikBaseUrl: 'https://beta.analytics.openaire.eu/piwik.php?idsite=',
utilsService: 'http://mpagasas.di.uoa.gr:8000'
}
export let properties: EnvProperties = {
...props, ...common, ...commonDev