From cbd4dd39ea3497f629e9c1c433d4596b9492d237 Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Tue, 25 Apr 2017 12:09:11 +0000 Subject: [PATCH] Adding login token parameter in claim API requests | check for user session expiration before every API call| redirect to login page if needed | keep the current state and current url if needed git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@46951 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../claimContextSearchForm.component.ts | 138 +++++++++++------- .../claimContextSearchForm.module.ts | 3 +- .../claimResultSearchForm.component.html | 21 ++- .../claimResultSearchForm.component.ts | 2 +- .../displayClaims.component.html | 6 +- .../displayClaims/displayClaims.component.ts | 31 +++- .../claim-utils/service/claims.service.ts | 44 +++--- .../claim-utils/service/contexts.service.ts | 12 +- .../service/directIndexClaim.service.ts | 39 +++++ .../claimsAdmin/claimsAdmin.component.ts | 2 +- .../directLinking/directLinking.component.ts | 25 +++- .../insertClaim/insertClaim.component.ts | 53 ++++++- .../linking/insertClaim/insertClaim.module.ts | 7 +- .../linking/linkingGeneric.component.ts | 20 ++- .../selected/selectedContexts.component.ts | 25 +--- .../selected/selectedResults.component.ts | 11 +- .../app/claims/myClaims/myClaims.component.ts | 2 +- .../src/app/login/adminLoginGuard.guard.ts | 11 +- portal-2/src/app/login/freeGuard.guard.ts | 8 +- portal-2/src/app/login/loginGuard.guard.ts | 8 +- portal-2/src/app/login/utils/helper.class.ts | 9 +- .../navigationBar.component.ts | 41 +++++- 22 files changed, 365 insertions(+), 153 deletions(-) create mode 100644 portal-2/src/app/claims/claim-utils/service/directIndexClaim.service.ts diff --git a/portal-2/src/app/claims/claim-utils/claimContextSearchForm.component.ts b/portal-2/src/app/claims/claim-utils/claimContextSearchForm.component.ts index b4f793bb..13c7675e 100644 --- a/portal-2/src/app/claims/claim-utils/claimContextSearchForm.component.ts +++ b/portal-2/src/app/claims/claim-utils/claimContextSearchForm.component.ts @@ -1,9 +1,12 @@ import {Component, Input,Output, EventEmitter, ViewChild} from '@angular/core'; import {Observable} from 'rxjs/Observable'; +import { Router} from '@angular/router'; import {ContextsService} from './service/contexts.service'; import {ClaimContext} from './claimEntities.class'; import { StaticAutoCompleteComponent } from '../../utils/staticAutoComplete/staticAutoComplete.component'; declare var UIkit:any; +import {Session} from '../../login/utils/helper.class'; +import {ErrorCodes} from '../../login/utils/guardHelper.class'; @Component({ // moduleId: module.id, @@ -40,10 +43,14 @@ declare var UIkit:any; export class ClaimContextSearchFormComponent { // @Input() public inline:boolean = false ; // for claimed started from landing pages public showComponent:boolean = true ; // for claimed started from landing pages -@Input() public selectedList = []; +@Input() public selectedList; +//The following need to be kept in case we have to save the current state +@Input() public projects; +@Input() public results; +@Input() public inlineEntity; public selectedCommunityId:string = "0"; public selectedCategoryId:string ="0"; -@Output() contextSelected = new EventEmitter(); +// @Output() contextSelected = new EventEmitter(); @ViewChild (StaticAutoCompleteComponent) autocomplete : StaticAutoCompleteComponent ; @@ -61,7 +68,7 @@ public loading:boolean = false; ngOnInit() { this.getCommunities(); } -constructor(private _contextService: ContextsService) { +constructor(private _contextService: ContextsService,private router: Router) { } @@ -78,11 +85,8 @@ select($event){ // this.warningMessage = "Concept already in selected list"; } } - // var UIkit:any; if (!found) { - this.contextSelected.emit({ - value: true - }); + this.selectedList.push(context); UIkit.notify({ message : 'A context is selected.', @@ -102,63 +106,80 @@ select($event){ } getCommunities () { - this.loading = true; - this._contextService.getCommunities().subscribe( - data => { - this.communities = data.communities; - this.loading = false; - }, - err => { - console.log(err); - this.loading = false; - } - ); + if(!Session.isValidAndRemove()){ + this.saveStateAndRedirectLogin(); + + }else{ + this.loading = true; + var token=Session.getUserJwt(); + this._contextService.getCommunities(token).subscribe( + data => { + this.communities = data.communities; + this.loading = false; + }, + err => { + console.log(err); + this.loading = false; + } + ); + } } getCategories () { console.log(" Getting Categories... "); this.loading = true; this.categories=[]; if(this.selectedCommunityId != '0'){ - this._contextService.getCategories(this.selectedCommunityId).subscribe( - data => { - this.categories = data.category; - this.concepts = []; - this.addCommunityInConcepts(); - this.filteredList = []; - if (this.query !== ""){ - var event = {value: ""}; - event.value = this.query; + if(!Session.isValidAndRemove()){ + this.saveStateAndRedirectLogin(); + + }else{ + var token=Session.getUserJwt(); + this._contextService.getCategories(this.selectedCommunityId, token).subscribe( + data => { + this.categories = data.category; + this.concepts = []; + this.addCommunityInConcepts(); + this.filteredList = []; + if (this.query !== ""){ + var event = {value: ""}; + event.value = this.query; + } + this.loading = false; + }, + err => { + console.log(err); + this.loading = false; } - this.loading = false; - }, - err => { - console.log(err); - this.loading = false; - } - ); + ); + } } } getConcepts () { this.loading = true; if(this.selectedCategoryId != '0'){ - this.concepts = []; - this.addCommunityInConcepts(); - this._contextService.getConcepts(this.selectedCategoryId, "").subscribe( - data => { - this.concepts = data; - this.addCommunityInConcepts(); - if (this.query !== ""){ - var event = {value: ""}; - event.value = this.query; - // this.filter(event); - } - this.loading = false; - }, - err => { - console.log(err); - this.loading = false; - } - ); + if(!Session.isValidAndRemove()){ + this.saveStateAndRedirectLogin(); + }else{ + this.concepts = []; + this.addCommunityInConcepts(); + var token=Session.getUserJwt(); + this._contextService.getConcepts(this.selectedCategoryId, "",token).subscribe( + data => { + this.concepts = data; + this.addCommunityInConcepts(); + if (this.query !== ""){ + var event = {value: ""}; + event.value = this.query; + // this.filter(event); + } + this.loading = false; + }, + err => { + console.log(err); + this.loading = false; + } + ); + } }else{ this.concepts=[]; this.loading = false; @@ -190,5 +211,18 @@ addCommunityInConcepts(){ this.concepts.push({"id":this.selectedCommunityId, "label":this.selectedCommunityLabel}); this.autocomplete.updateList(this.concepts); } +saveStateAndRedirectLogin(){ + if(this.projects != null){ + localStorage.setItem("projects", JSON.stringify(this.projects)); + } + localStorage.setItem("contexts", JSON.stringify(this.selectedList)); + if(this.results != null){ + localStorage.setItem("results", JSON.stringify(this.results)); + } + if(this.inlineEntity != null){ + localStorage.setItem("inlineEntity", JSON.stringify(this.inlineEntity)); + } + this.router.navigate(['/user-info'], { queryParams: { "errorCode": ErrorCodes.NOT_VALID, "redirectUrl": this.router.url } }); +} } diff --git a/portal-2/src/app/claims/claim-utils/claimContextSearchForm.module.ts b/portal-2/src/app/claims/claim-utils/claimContextSearchForm.module.ts index ae3a5d8e..345d2c93 100644 --- a/portal-2/src/app/claims/claim-utils/claimContextSearchForm.module.ts +++ b/portal-2/src/app/claims/claim-utils/claimContextSearchForm.module.ts @@ -4,10 +4,11 @@ import { SharedModule } from '../../shared/shared.module'; import { ClaimContextSearchFormComponent } from './claimContextSearchForm.component'; import{ContextsServiceModule} from './service/contextsService.module'; import {StaticAutocompleteModule} from '../../utils/staticAutoComplete/staticAutoComplete.module'; + import { RouterModule } from '@angular/router'; @NgModule({ imports: [ - SharedModule, + SharedModule,RouterModule, ContextsServiceModule, StaticAutocompleteModule diff --git a/portal-2/src/app/claims/claim-utils/claimResultSearchForm.component.html b/portal-2/src/app/claims/claim-utils/claimResultSearchForm.component.html index ae5fc80d..eb6de00c 100644 --- a/portal-2/src/app/claims/claim-utils/claimResultSearchForm.component.html +++ b/portal-2/src/app/claims/claim-utils/claimResultSearchForm.component.html @@ -11,10 +11,10 @@
Publisher: {{item.publisher}}({{(item['published-print']['date-parts'][0][0])?item['published-print']['date-parts'][0][0]:item['published-print']['date-parts'][0]}}) -
Authors: {{author.family}} {{author.given}}{{(i < (item.author.length-1))?"; ":""}}
-
Editors: {{author.family}} {{author.given}}{{(i < (item.editor.length-1))?"; ":""}}
- +
Authors: {{author.family}} {{author.given}}{{(i < (item.author.slice(0,10).length-1))?"; ":""}}{{(i == item.author.slice(0,10).length-1 && item.author.length > 10)?"...":""}}
+
Editors: {{author.family}} {{author.given}}{{(i < (item.editor.slice(0,10).length-1))?"; ":""}}{{(i == item.editor.slice(0,10).length-1 && item.editor.length > 10)?"...":""}}
@@ -65,7 +64,8 @@ Publisher: {{result.publisher}}({{result.year}}) -
Authors: {{author.name}}{{(i < (result.authors.length-1))?"; ":""}}
+
Authors: {{author.name}}{{(i < (result.authors.slice(0,10).length-1))?"; ":""}}{{(i == result.authors.slice(0,10).length-1 && result.authors.length > 10)?"...":""}}
+ @@ -109,7 +109,7 @@ Journal: {{item['journal-title'].value}} ({{item['publication-date'].year.value}}) -
Authors: {{author}}{{(i < (item.contributors.length-1))?"; ":""}}
+
Authors: {{author}}{{(i < (item.contributors.slice(0,10).length-1))?"; ":""}}{{(i == item.contributors.slice(0,10).length-1 && item.contributors.length > 10)?"...":""}}
@@ -129,7 +129,6 @@ -
Publisher: {{item.publisher}} -
Authors: {{author}}{{(i < (item.creator.length-1))?"; ":""}}
+
Authors: {{author}}{{(i < (item.creator.slice(0,10).length-1))?"; ":""}}{{(i == item.creator.slice(0,10).length-1 && item.creator.length > 10)?"...":""}}
@@ -171,11 +170,11 @@ (click)="add(result, result.id, 'openaire','dataset', result['title'].url, result['title'].name, result.year, result['title'].accessMode)"> Publisher: {{result.publisher}}({{result.year}}) -
Authors: {{author.name}}{{(i < (result.authors.length-1))?"; ":""}}
+
Authors: {{author.name}}{{(i < (result.authors.slice(0,10).length-1))?"; ":""}}{{(i == result.authors.slice(0,10).length-1 && result.authors.length > 10)?"...":""}}
+ - diff --git a/portal-2/src/app/claims/claim-utils/claimResultSearchForm.component.ts b/portal-2/src/app/claims/claim-utils/claimResultSearchForm.component.ts index b5b60c68..4ef71519 100644 --- a/portal-2/src/app/claims/claim-utils/claimResultSearchForm.component.ts +++ b/portal-2/src/app/claims/claim-utils/claimResultSearchForm.component.ts @@ -513,7 +513,7 @@ openaireDataPageChange($event) { result.type = itemType; result.source = itemSource; - result.title = Array.isArray(itemTitle && itemTitle.length > 0 )?itemTitle[0]:itemTitle; + result.title = (Array.isArray(itemTitle) && itemTitle.length > 0 )?itemTitle[0]:itemTitle; result.url = itemUrl; result.accessRights = 'OPEN'; result.embargoEndDate = this.nextDate; diff --git a/portal-2/src/app/claims/claim-utils/displayClaims/displayClaims.component.html b/portal-2/src/app/claims/claim-utils/displayClaims/displayClaims.component.html index 77e13ef9..c5a6af85 100644 --- a/portal-2/src/app/claims/claim-utils/displayClaims/displayClaims.component.html +++ b/portal-2/src/app/claims/claim-utils/displayClaims/displayClaims.component.html @@ -34,7 +34,9 @@
An Error occured.
- +
+ User session is not valid. Please login again. +
@@ -44,7 +46,7 @@ You have selected {{selected.length}} claim(s) -
+
diff --git a/portal-2/src/app/claims/claim-utils/displayClaims/displayClaims.component.ts b/portal-2/src/app/claims/claim-utils/displayClaims/displayClaims.component.ts index e1ccb100..5a607c17 100644 --- a/portal-2/src/app/claims/claim-utils/displayClaims/displayClaims.component.ts +++ b/portal-2/src/app/claims/claim-utils/displayClaims/displayClaims.component.ts @@ -84,6 +84,7 @@ export class DisplayClaimsComponent { selected=[]; deleteMessage:string = ""; showErrorMessage:boolean = false; + userValidMessage:string = ""; //params for pagingFormatter to use when navigate to page params; @@ -92,6 +93,11 @@ export class DisplayClaimsComponent { claimsDeleted:number = 0; getClaims () { + if(!Session.isValidAndRemove()){ + this.userValidMessage = "User session has expired. Please login again."; + + }else{ + var token=Session.getUserJwt(); this.selected=[]; var types = ''; this.showErrorMessage = false; @@ -99,7 +105,7 @@ export class DisplayClaimsComponent { types+=(types.length>0?'&':'')+"types="+type; } if(this.fetchBy =="Project" ){ - this._claimService.getClaimsByProject(this.size,this.page,this.fetchId,this.keyword,this.sortby,this.descending, types).subscribe( + this._claimService.getClaimsByProject(this.size,this.page,this.fetchId,this.keyword,this.sortby,this.descending, types,token).subscribe( data => { this.claims = data.data; this.resultsNum= data.total; @@ -110,7 +116,7 @@ export class DisplayClaimsComponent { } ); }else if(this.fetchBy =="User"){ - this._claimService.getClaimsByUser(this.size,this.page,this.fetchId,this.keyword,this.sortby,this.descending, types).subscribe( + this._claimService.getClaimsByUser(this.size,this.page,this.fetchId,this.keyword,this.sortby,this.descending, types,token).subscribe( data => { this.claims = data.data; this.resultsNum= data.total; @@ -121,7 +127,7 @@ export class DisplayClaimsComponent { } ); }else if(this.fetchBy =="Result"){ - this._claimService.getClaimsByResult(this.size,this.page,this.fetchId,this.keyword,this.sortby,this.descending, types).subscribe( + this._claimService.getClaimsByResult(this.size,this.page,this.fetchId,this.keyword,this.sortby,this.descending, types,token).subscribe( data => { this.claims = data.data; this.resultsNum= data.total; @@ -132,7 +138,7 @@ export class DisplayClaimsComponent { } ); }else if(this.fetchBy =="Context"){ - this._claimService.getClaimsBycontext(this.size,this.page,this.fetchId,this.keyword,this.sortby,this.descending, types).subscribe( + this._claimService.getClaimsBycontext(this.size,this.page,this.fetchId,this.keyword,this.sortby,this.descending, types,token).subscribe( data => { this.claims = data.data; this.resultsNum= null; @@ -144,7 +150,7 @@ export class DisplayClaimsComponent { } ); }else{ - this._claimService.getClaims(this.size,this.page,this.keyword,this.sortby,this.descending, types).subscribe( + this._claimService.getClaims(this.size,this.page,this.keyword,this.sortby,this.descending, types,token).subscribe( data => { this.claims = data.data; this.resultsNum = null; @@ -157,6 +163,7 @@ export class DisplayClaimsComponent { ); } } +} goToClaim(claimId: number){ this._router.navigate( ['Claim', { id: claimId}] ); @@ -381,10 +388,14 @@ export class DisplayClaimsComponent { } deleteById(id:string){ + if(!Session.isValidAndRemove()){ + this.userValidMessage = "User session has expired. Please login again."; + }else{ + var token=Session.getUserJwt(); console.log("Deleting claim with id:"+id); // this._claimService.deleteClaimById(id); - this._claimService.deleteClaimById(id).subscribe( + this._claimService.deleteClaimById(id,token).subscribe( res => { console.log('Delete response'+res.code ); console.log("Deleted claim with id:"+ id); @@ -407,11 +418,16 @@ export class DisplayClaimsComponent { }); + } } batchDeleteById(ids:string[]){ + if(!Session.isValidAndRemove()){ + this.userValidMessage = "User session has expired. Please login again."; + }else{ + var token=Session.getUserJwt(); console.warn("Deleting claim with ids:"+ids); - this._claimService.deleteBulk(ids).subscribe( + this._claimService.deleteBulk(ids,token).subscribe( res => { console.info('Delete response'+res.code ); console.warn("Deleted ids:"+ res.deletedIds); @@ -442,6 +458,7 @@ export class DisplayClaimsComponent { this.deleteMessage=this.deleteMessage+'
'+res.notFoundIds.length+' claim(s) couldn\'t be deleted.
'; } }); + } } pageChange($event) { var page:number = +$event.value diff --git a/portal-2/src/app/claims/claim-utils/service/claims.service.ts b/portal-2/src/app/claims/claim-utils/service/claims.service.ts index 699ddf04..91d17f28 100644 --- a/portal-2/src/app/claims/claim-utils/service/claims.service.ts +++ b/portal-2/src/app/claims/claim-utils/service/claims.service.ts @@ -16,13 +16,13 @@ export class ClaimsService { this.baseUrl = OpenaireProperties.getClaimsAPIURL(); } - private getClaimRequest(size : number, page : number, url :string, fromCache:boolean):any { + private getClaimRequest(size : number, page : number, url :string, fromCache:boolean,token:string):any { console.info('ClaimsService: Claims request: '+url); let key = url; if (fromCache && this._cache.has(key)) { return Observable.of(this._cache.get(key)); } - return this.http.get( url) + return this.http.get( url+"&token="+token) .map(request => request.json()) .do(request => console.info("Get claims: offset = "+(size*(page-1)) + " limit ="+size )) .catch(this.handleError) @@ -30,40 +30,40 @@ export class ClaimsService { this._cache.set(key, res); }); } - getClaims( size : number, page : number, keyword:string, sortby: string, descending: boolean, types: string):any { + getClaims( size : number, page : number, keyword:string, sortby: string, descending: boolean, types: string,token:string):any { console.info('ClaimsService: getClaims ' ); console.info('ClaimsService: Types : '+types ); let url = this.baseUrl +"claims"+"?offset="+(size*(page-1) + "&limit="+size)+"&keyword="+keyword+"&sortby="+sortby+"&descending="+descending+"&"+types; - return this.getClaimRequest(size,page,url,true); + return this.getClaimRequest(size,page,url,true,token); } - getClaimsByUser( size : number, page : number, user:string, keyword:string, sortby: string, descending: boolean, types: string):any { + getClaimsByUser( size : number, page : number, user:string, keyword:string, sortby: string, descending: boolean, types: string,token:string):any { console.info('ClaimsService: getClaims for user : '+user); let url = this.baseUrl +"users/"+user+"/claims"+"?offset="+(size*(page-1) + "&limit="+size)+"&keyword="+keyword+"&sortby="+sortby+"&descending="+descending+"&"+types; - return this.getClaimRequest(size,page,url,false); + return this.getClaimRequest(size,page,url,false,token); } - getClaimsBycontext( size : number, page : number, contextId:string, keyword:string, sortby: string, descending: boolean, types: string):any { + getClaimsBycontext( size : number, page : number, contextId:string, keyword:string, sortby: string, descending: boolean, types: string,token:string):any { console.info('ClaimsService: getClaims for context : '+contextId); let url = this.baseUrl +"contexts/"+contextId+"/claims"+"?offset="+(size*(page-1) + "&limit="+size)+"&keyword="+keyword+"&sortby="+sortby+"&descending="+descending+"&"+types; - return this.getClaimRequest(size,page,url,true); + return this.getClaimRequest(size,page,url,true,token); } - getClaimsByResult( size : number, page : number, resultId:string, keyword:string, sortby: string, descending: boolean, types: string):any { + getClaimsByResult( size : number, page : number, resultId:string, keyword:string, sortby: string, descending: boolean, types: string,token:string):any { console.info('ClaimsService: getClaims for result : '+resultId); let url = this.baseUrl +"results/"+resultId+"/claims"+"?offset="+(size*(page-1) + "&limit="+size)+"&keyword="+keyword+"&sortby="+sortby+"&descending="+descending+"&"+types; - return this.getClaimRequest(size,page,url,true); + return this.getClaimRequest(size,page,url,true,token); } - getClaimsByProject( size : number, page : number, projectId:string, keyword:string, sortby: string, descending: boolean, types: string):any { + getClaimsByProject( size : number, page : number, projectId:string, keyword:string, sortby: string, descending: boolean, types: string,token:string):any { console.info('ClaimsService: getClaims for project : '+projectId); let url = this.baseUrl +"projects/"+projectId+"/claims"+"?offset="+(size*(page-1) + "&limit="+size)+"&keyword="+keyword+"&sortby="+sortby+"&descending="+descending+"&"+types; - return this.getClaimRequest(size,page,url,true); + return this.getClaimRequest(size,page,url,true,token); } - deleteClaimById(claimId:string):any{ + deleteClaimById(claimId:string,token:string):any{ console.warn('Trying to delete claim with id : '+claimId); - let url = this.baseUrl +"claims/"+claimId; + let url = this.baseUrl +"claims/"+claimId+"?token="+token; let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }); return this.http.delete( url, options).map(request => request.json()) @@ -71,7 +71,7 @@ export class ClaimsService { .catch(this.handleError); } - deleteBulk(claimIds:string[]):any{ + deleteBulk(claimIds:string[],token:string):any{ console.warn('Trying to delete claims with ids : '+claimIds); var url = ""; @@ -79,7 +79,7 @@ export class ClaimsService { for(var claimId of claimIds){ url=url+(url.length >0 ?"&":"")+"claimId="+claimId; } - url= this.baseUrl +"claims/bulk?"+url; + url= this.baseUrl +"claims/bulk?"+url+"&token="+token; let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }); return this.http.delete( url, options).map(request => request.json()) @@ -87,9 +87,9 @@ export class ClaimsService { .catch(this.handleError); } - insertBulkClaims(claims):any{ + insertBulkClaims(claims,token:string):any{ console.warn('Trying toinsert claims : '+claims); - let url = this.baseUrl +"claims/bulk"; + let url = this.baseUrl +"claims/bulk"+"?token="+token; let body = JSON.stringify( claims ); console.warn('Json body: : '+body); let headers = new Headers({ 'Content-Type': 'application/json' }); @@ -100,9 +100,9 @@ export class ClaimsService { .catch(this.handleError); } - insertClaim(claim):any{ + insertClaim(claim,token:string):any{ console.warn('Trying toinsert claim : '+claim); - let url = this.baseUrl +"claims"; + let url = this.baseUrl +"claims"+"?token="+token; let body = JSON.stringify( claim ); let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }); @@ -120,8 +120,8 @@ export class ClaimsService { return Observable.throw(error || 'Server error'); } - getClaim(id:string):any { - let url = this.baseUrl+"claims/"+id; + getClaim(id:string,token:string):any { + let url = this.baseUrl+"claims/"+id+"?token="+token; return new Promise((resolve, reject) => { this.http.get(url) .map(res => res.json()) diff --git a/portal-2/src/app/claims/claim-utils/service/contexts.service.ts b/portal-2/src/app/claims/claim-utils/service/contexts.service.ts index a8107fd6..c580cf2b 100644 --- a/portal-2/src/app/claims/claim-utils/service/contexts.service.ts +++ b/portal-2/src/app/claims/claim-utils/service/contexts.service.ts @@ -17,7 +17,7 @@ export class ContextsService { this.baseUrl = OpenaireProperties.getClaimsAPIURL(); } - public getCommunities():any { + public getCommunities(token:string):any { let url = this.baseUrl + 'communities'; let key = url; if (this._cache.has(key)) { @@ -25,7 +25,7 @@ export class ContextsService { } console.info('ContextsService: request communities '+url); - return this.http.get( url) + return this.http.get( url+"?token="+token) .map(request => request.json().data) // .do(request => console.info("Get claims: offset = ")) .catch(this.handleError) @@ -33,7 +33,7 @@ export class ContextsService { this._cache.set(key, res); }); } - public getCategories(communityId :string):any { + public getCategories(communityId :string,token:string):any { console.info('ContextsService: request categories for community with id '+communityId); let url= this.baseUrl + 'communities/' + communityId + '/categories'; let key = url; @@ -41,7 +41,7 @@ export class ContextsService { return Observable.of(this._cache.get(key)); } - return this.http.get( url) + return this.http.get( url+"?token="+token) .map(request => request.json().data) // .do(request => console.info("Get claims: offset = " )) .catch(this.handleError) @@ -49,7 +49,7 @@ export class ContextsService { this._cache.set(key, res); }); } - public getConcepts(categoryId :string, keyword: string):any { + public getConcepts(categoryId :string, keyword: string,token:string):any { console.info('ContextsService: request concept for category with id '+categoryId + ' and keyword '+ keyword); let url= this.baseUrl + 'categories/' + categoryId+ "/concepts"; let key = url; @@ -57,7 +57,7 @@ export class ContextsService { return Observable.of(this._cache.get(key)); } - return this.http.get( url) + return this.http.get( url+"?token="+token) .map(request => request.json().data) .map(res => this.parse(res.concept)) // .do(res => console.info(res )) diff --git a/portal-2/src/app/claims/claim-utils/service/directIndexClaim.service.ts b/portal-2/src/app/claims/claim-utils/service/directIndexClaim.service.ts new file mode 100644 index 00000000..7a4ec1ea --- /dev/null +++ b/portal-2/src/app/claims/claim-utils/service/directIndexClaim.service.ts @@ -0,0 +1,39 @@ +import {Injectable} from '@angular/core'; +import {Jsonp, URLSearchParams,ResponseOptions, RequestOptions, Headers} from '@angular/http'; +import {Http, Response} from '@angular/http'; +import {Observable} from 'rxjs/Observable'; +import {OpenaireProperties} from '../../../utils/properties/openaireProperties'; +import 'rxjs/add/observable/of'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/share'; + +@Injectable() +export class DirectIndexClaimService { + private baseUrl; + constructor(private jsonp: Jsonp, private http: Http) { + this.baseUrl = OpenaireProperties.getClaimsAPIURL(); + } + + public directClaim(record:any):any { + console.log("in direct claim service"); + let url = "http://beta.services.openaire.eu:8280/is/mvc/api/publications/feedObject"; + // let body = JSON.stringify( record ); + // console.warn('Direct Json body: : '+body); + console.warn('Direct Json record: : '+record); + let headers = new Headers({ 'Content-Type': 'application/json' }); + let options = new RequestOptions({ headers: headers }); + return this.http.post(url, record, options) + .map(res => res.json()) + .do(request => console.info("DirectClaim Response:"+request) ) + .catch(this.handleError); + + + } + private handleError (error: Response) { + // in a real world app, we may send the error to some remote logging infrastructure + // instead of just logging it to the console + console.log(error); + return Observable.throw(error || 'Server error'); + } + +} diff --git a/portal-2/src/app/claims/claimsAdmin/claimsAdmin.component.ts b/portal-2/src/app/claims/claimsAdmin/claimsAdmin.component.ts index 9420cf44..3eec3b19 100644 --- a/portal-2/src/app/claims/claimsAdmin/claimsAdmin.component.ts +++ b/portal-2/src/app/claims/claimsAdmin/claimsAdmin.component.ts @@ -11,7 +11,7 @@ import {Observable} from 'rxjs/Observable';
- +
`, diff --git a/portal-2/src/app/claims/directLinking/directLinking.component.ts b/portal-2/src/app/claims/directLinking/directLinking.component.ts index 7c48572e..b8c2d80e 100644 --- a/portal-2/src/app/claims/directLinking/directLinking.component.ts +++ b/portal-2/src/app/claims/directLinking/directLinking.component.ts @@ -28,7 +28,7 @@ import {SearchDatasetsService} from '../../services/searchDatasets.service'; {{displayedResult.title}} {{displayedResult.title}} -
Authors: {{author.name}}{{(i < (displayedResult.result.authors.length-1))?"; ":""}}
+
Authors: {{author.name}}{{(i < (displayedResult.result.authors.slice(0,10).length-1))?"; ":""}}{{(i == displayedResult.result.authors.slice(0,10).length-1 && displayedResult.result.authors.length > 10)?"...":""}}
@@ -43,7 +43,7 @@ import {SearchDatasetsService} from '../../services/searchDatasets.service';
-
@@ -93,6 +93,27 @@ export class DirectLinkingComponent { } ngOnInit() { + if(localStorage.getItem("projects")){ + this.projects = JSON.parse(localStorage.getItem("projects")); + } + if(localStorage.getItem("contexts")){ + this.contexts = JSON.parse(localStorage.getItem("contexts")); + } + if(localStorage.getItem("results")){ + this.results = JSON.parse(localStorage.getItem("results")); + } + if(localStorage.getItem("results")){ + this.results = JSON.parse(localStorage.getItem("results")); + } + if(localStorage.getItem("inlineEntity")){ + this.inlineResult = JSON.parse(localStorage.getItem("inlineEntity")); + } + + localStorage.removeItem("projects"); + localStorage.removeItem("contexts"); + localStorage.removeItem("results"); + localStorage.removeItem("inlineEntity"); + this.sub = this.route.queryParams.subscribe(params => { this.id = params['id']; this.type = params['type']; diff --git a/portal-2/src/app/claims/linking/insertClaim/insertClaim.component.ts b/portal-2/src/app/claims/linking/insertClaim/insertClaim.component.ts index 37b4a319..200aa5ab 100644 --- a/portal-2/src/app/claims/linking/insertClaim/insertClaim.component.ts +++ b/portal-2/src/app/claims/linking/insertClaim/insertClaim.component.ts @@ -2,10 +2,14 @@ import {Component, Input, Output, EventEmitter, ViewChild} from '@angular/core'; import {Observable} from 'rxjs/Observable'; import {Router} from '@angular/router'; import {ClaimsService} from '../../claim-utils/service/claims.service'; +import {DirectIndexClaimService} from '../../claim-utils/service/directIndexClaim.service'; + import {ModalLoading} from '../../../utils/modal/loading.component'; import {AlertModal} from '../../../utils/modal/alert'; import {Md5} from 'ts-md5/dist/md5'; import {Session} from '../../../login/utils/helper.class'; +import {ErrorCodes} from '../../../login/utils/guardHelper.class'; + @Component({ selector: 'claim-insert', template: ` @@ -16,6 +20,8 @@ import {Session} from '../../../login/utils/helper.class';
+ + @@ -23,7 +29,7 @@ import {Session} from '../../../login/utils/helper.class'; ` }) export class ClaimInsertComponent { - constructor (private claimService: ClaimsService, private _router:Router) {} + constructor (private claimService: ClaimsService,private directIndexClaimService:DirectIndexClaimService, private _router:Router) {} ngOnInit() { // console.info("Inlineentity:" +(this.inlineEntity)?this.inlineEntity+(this.inlineEntity.id)?this.inlineEntity.id:"no id":"null"+ + " show "+ (!this.claiming && this.showButton) ); } @@ -59,9 +65,21 @@ public validateInsertions(){ return } private insert(){ + if(!Session.isValidAndRemove()){ + this.showButton = false; + localStorage.setItem("projects", JSON.stringify(this.projects)); + localStorage.setItem("contexts", JSON.stringify(this.contexts)); + localStorage.setItem("results", JSON.stringify(this.results)); + if(this.inlineEntity != null){ + localStorage.setItem("inlineEntity", JSON.stringify(this.inlineEntity)); + } + + this._router.navigate(['/user-info'], { queryParams: { "errorCode": ErrorCodes.NOT_VALID, "redirectUrl": this._router.url} }); + + }else{ this.claiming = true; var user=Session.getUserEmail(); - var jwt=Session.getUserJwt(); + var token=Session.getUserJwt(); this.loading.open(); var claims = []; var directclaims = []; @@ -70,7 +88,7 @@ private insert(){ for (var i = 0; i < this.results.length; i++) { var result=this.results[i]; - if(["crosreff","datacite","orcid"].indexOf(result.source) != -1){ + if(["crossref","datacite","orcid"].indexOf(result.source) != -1){ directclaims.push(this.createDirectClaim(result,this.projects,this.contexts)); } if(this.contexts){ @@ -94,9 +112,30 @@ private insert(){ } } + var created =[]; + var failed =[]; + console.info("\n\ndirectclaims: "+directclaims.length+"\n\n"); + for(var i = 0; i { + console.log("AAA" + data); + created.push(directclaims[i].originalId) + }, + err => { + console.log(err); + failed.push(directclaims[i].originalId) + if(failed.length + created.length == directclaims.length){ + console.log("failed:"+failed); + console.log("created:"+created); + + } + } + ); + } console.info("try to insert "+claims.length+" claims"); - this.claimService.insertBulkClaims(claims).subscribe( + this.claimService.insertBulkClaims(claims,token).subscribe( data => { var inserted = data.insertedIds.length; @@ -108,6 +147,8 @@ private insert(){ this.errorsInClaimsInsertion(err.insertedIds,err.errorInClaims); } ); + } + } private validate(){ this.warningMessage = ""; @@ -212,6 +253,8 @@ createDirectClaim(result, projects, contexts){ var md5_id = Md5.hashStr(result.id); entity["originalId"]="user:claim__"+md5_id; entity["title"]=result.title; + entity["title"] =(Array.isArray(result.title) && result.title.length > 0 )?result.title[0]:result.title; + if(result.authors && result.authors.length > 0){ entity["authors"]=result.authors; } @@ -225,7 +268,7 @@ createDirectClaim(result, projects, contexts){ entity["type"]=result.type; if(result.source == "crossref" || result.source == "datacite"){ entity["pids"]= [];//{type:string, value:string}[]; - entity["pids"].push({type:"DOI",value:result.id}) + entity["pids"].push({type:"doi",value:result.id}) } entity["licenseCode"]=result.accessRights; if(result.accessRights == "EMBARGO"){ diff --git a/portal-2/src/app/claims/linking/insertClaim/insertClaim.module.ts b/portal-2/src/app/claims/linking/insertClaim/insertClaim.module.ts index dc0067b3..61781664 100644 --- a/portal-2/src/app/claims/linking/insertClaim/insertClaim.module.ts +++ b/portal-2/src/app/claims/linking/insertClaim/insertClaim.module.ts @@ -5,13 +5,14 @@ import {AlertModalModule} from '../../../utils/modal/alertModal.module'; import {LoadingModalModule} from '../../../utils/modal/loadingModal.module'; import {ClaimInsertComponent} from './insertClaim.component'; import {ClaimServiceModule} from '../../claim-utils/service/claimsService.module'; +import {DirectIndexClaimService} from '../../claim-utils/service/directIndexClaim.service'; @NgModule({ imports: [ SharedModule, AlertModalModule, LoadingModalModule, ClaimServiceModule ], - declarations: [ -ClaimInsertComponent - ], exports:[ ClaimInsertComponent] + declarations: [ClaimInsertComponent], + providers:[DirectIndexClaimService], + exports:[ ClaimInsertComponent] }) export class InsertClaimsModule { } diff --git a/portal-2/src/app/claims/linking/linkingGeneric.component.ts b/portal-2/src/app/claims/linking/linkingGeneric.component.ts index 823495cf..0fb474e9 100644 --- a/portal-2/src/app/claims/linking/linkingGeneric.component.ts +++ b/portal-2/src/app/claims/linking/linkingGeneric.component.ts @@ -26,7 +26,7 @@ import {SearchDatasetsService} from '../../services/searchDatasets.service';
-
@@ -83,6 +83,22 @@ export class LinkingGenericComponent { } ngOnInit() { + if( typeof localStorage !== 'undefined') { + if(localStorage.getItem("projects")){ + this.projects = JSON.parse(localStorage.getItem("projects")); + + } + if(localStorage.getItem("contexts")){ + this.contexts = JSON.parse(localStorage.getItem("contexts")); + } + if(localStorage.getItem("results")){ + this.results = JSON.parse(localStorage.getItem("results")); + + } + localStorage.removeItem("projects"); + localStorage.removeItem("contexts"); + localStorage.removeItem("results"); + } } next(){ @@ -120,7 +136,7 @@ export class LinkingGenericComponent { this.show=$event.value; this.showChangedType($event.value); } - + showChangedType(type:string) { this.show=type; if(this.show == 'project' || this.show == 'context' || this.show == 'software'){ diff --git a/portal-2/src/app/claims/linking/selected/selectedContexts.component.ts b/portal-2/src/app/claims/linking/selected/selectedContexts.component.ts index a1130095..4a95ff69 100644 --- a/portal-2/src/app/claims/linking/selected/selectedContexts.component.ts +++ b/portal-2/src/app/claims/linking/selected/selectedContexts.component.ts @@ -1,5 +1,6 @@ import {Component, Input,Output, EventEmitter} from '@angular/core'; import {ClaimContext} from '../../claim-utils/claimEntities.class'; + @Component({ selector: 'claim-selected-contexts', template: ` @@ -8,9 +9,9 @@ import {ClaimContext} from '../../claim-utils/claimEntities.class';

{{title}} ({{(contexts.length)}})

-
+
- +
  • {{context.community }} > {{context.category}} > {{context.concept.label}} @@ -21,21 +22,6 @@ import {ClaimContext} from '../../claim-utils/claimEntities.class';
    There are no communities
- ` @@ -55,6 +41,10 @@ export class ClaimSelectedContextsComponent { @Input() contexts:ClaimContext[]; + //The following need to be kept in case we have to save the current state + @Input() public projects; + @Input() public results; + @Input() public inlineEntity; @Input() componentClass:string = ""; //"" or "col-sm-6" for horizontal display (besides projects) @Input() show='home'; @Input() title='Communities'; @@ -63,6 +53,7 @@ export class ClaimSelectedContextsComponent { @Input() hideType; @Input() bulkMode:boolean = false; @Output() showChange = new EventEmitter(); + showsearch:boolean = false; todayDate = ''; diff --git a/portal-2/src/app/claims/linking/selected/selectedResults.component.ts b/portal-2/src/app/claims/linking/selected/selectedResults.component.ts index 3a563795..1b776133 100644 --- a/portal-2/src/app/claims/linking/selected/selectedResults.component.ts +++ b/portal-2/src/app/claims/linking/selected/selectedResults.component.ts @@ -39,18 +39,17 @@ import {Dates} from '../../../utils/string-utils.class';
- - + + - + - + - -
****sliced***
+
diff --git a/portal-2/src/app/claims/myClaims/myClaims.component.ts b/portal-2/src/app/claims/myClaims/myClaims.component.ts index d4d1177a..c7bc727a 100644 --- a/portal-2/src/app/claims/myClaims/myClaims.component.ts +++ b/portal-2/src/app/claims/myClaims/myClaims.component.ts @@ -12,7 +12,7 @@ import {Observable} from 'rxjs/Observable';
diff --git a/portal-2/src/app/login/adminLoginGuard.guard.ts b/portal-2/src/app/login/adminLoginGuard.guard.ts index eb08b95e..c35d8eb0 100644 --- a/portal-2/src/app/login/adminLoginGuard.guard.ts +++ b/portal-2/src/app/login/adminLoginGuard.guard.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import { Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router'; import {Observable} from 'rxjs/Observable'; import {Session} from './utils/helper.class'; +import {ErrorCodes} from './utils/guardHelper.class'; @Injectable() export class AdminLoginGuard implements CanActivate { @@ -11,28 +12,30 @@ export class AdminLoginGuard implements CanActivate { var user; var loggedIn = false; var isAdmin = false; - var errorCode = 1; + var errorCode = ErrorCodes.NOT_LOGGIN; if(Session.isLoggedIn()){ loggedIn = true; if(!Session.isValidAndRemove()){ loggedIn = false; - errorCode = 3; + errorCode = ErrorCodes.NOT_VALID; }else { isAdmin = Session.isAdminUser(); if(!isAdmin){ - errorCode = 2; + errorCode = ErrorCodes.NOT_ADMIN; } } }else{ - errorCode =1; + errorCode =ErrorCodes.NOT_LOGGIN; } if(!loggedIn){ + // this.guardHelper.redirect("/user-info",errorCode,state.url); this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }); return false; }else if(!isAdmin){ + // this.guardHelper.redirect("/user-info",errorCode,state.url); this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }); return false; }else{ diff --git a/portal-2/src/app/login/freeGuard.guard.ts b/portal-2/src/app/login/freeGuard.guard.ts index 4d455706..316ff266 100644 --- a/portal-2/src/app/login/freeGuard.guard.ts +++ b/portal-2/src/app/login/freeGuard.guard.ts @@ -2,6 +2,8 @@ import { Injectable } from '@angular/core'; import { Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router'; import {Observable} from 'rxjs/Observable'; import {Session} from './utils/helper.class'; +import {ErrorCodes} from './utils/guardHelper.class'; + @Injectable() export class FreeGuard implements CanActivate { @@ -11,18 +13,20 @@ export class FreeGuard implements CanActivate { var user; var valid = true; var loggedIn = false; - var errorCode = 1; + var errorCode = ErrorCodes.NOT_LOGGIN; if(Session.isLoggedIn()){ loggedIn = true; if(!Session.isValidAndRemove()){ loggedIn = false; valid = false; - errorCode = 3; + errorCode = ErrorCodes.NOT_VALID; } } if(!valid){ + // this.guardHelper.redirect("/user-info",errorCode,state.url); + this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }); return false; } diff --git a/portal-2/src/app/login/loginGuard.guard.ts b/portal-2/src/app/login/loginGuard.guard.ts index 17c63c81..6e960fd3 100644 --- a/portal-2/src/app/login/loginGuard.guard.ts +++ b/portal-2/src/app/login/loginGuard.guard.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import { Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router'; import {Observable} from 'rxjs/Observable'; import {Session} from './utils/helper.class'; +import {ErrorCodes} from './utils/guardHelper.class'; @Injectable() export class LoginGuard implements CanActivate { @@ -11,18 +12,19 @@ export class LoginGuard implements CanActivate { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | boolean { var user; var loggedIn = false; - var errorCode = 1; + var errorCode = ErrorCodes.NOT_LOGGIN; if(Session.isLoggedIn()){ loggedIn = true; if(!Session.isValidAndRemove()){ loggedIn = false; - errorCode = 3; + errorCode = ErrorCodes.NOT_VALID; } }else{ - errorCode = 1; + errorCode = ErrorCodes.NOT_LOGGIN; } if(!loggedIn){ + // this.guardHelper.redirect("/user-info",errorCode,state.url); this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } }); return false; }else{ diff --git a/portal-2/src/app/login/utils/helper.class.ts b/portal-2/src/app/login/utils/helper.class.ts index a00a9b47..337b49d4 100644 --- a/portal-2/src/app/login/utils/helper.class.ts +++ b/portal-2/src/app/login/utils/helper.class.ts @@ -74,8 +74,8 @@ export class Session{ if(Session.isLoggedIn()){ var expires = Session.getUser().expirationDate; var now = new Date().getTime() / 1000; - console.log(" is still valid ? "+(now < expires) + " now is:"+now + "expires at:"+expires); - return now < expires; + console.log(" is still valid ? "+(now +0 < expires) +" Remaining:"+ (expires - (now+0))+ " now is:"+now + "expires at:"+expires); + return now +0 < expires; } return false; } @@ -84,9 +84,12 @@ export class Session{ if(!Session.isUserValid()){ Session.removeUser(); return false; + }else{ + return true; } + }else{ + return false; } - return true; } } diff --git a/portal-2/src/app/sharedComponents/navigationBar.component.ts b/portal-2/src/app/sharedComponents/navigationBar.component.ts index 8ddbecfd..49f8ffca 100644 --- a/portal-2/src/app/sharedComponents/navigationBar.component.ts +++ b/portal-2/src/app/sharedComponents/navigationBar.component.ts @@ -1,5 +1,8 @@ import { Component } from '@angular/core'; import 'rxjs/Rx'; +import {ActivatedRoute, Router} from '@angular/router'; + +import {Session} from '../login/utils/helper.class'; @Component({ selector: 'navbar', @@ -80,7 +83,8 @@ import 'rxjs/Rx'; @@ -146,7 +150,7 @@ import 'rxjs/Rx'; + @@ -169,5 +184,27 @@ import 'rxjs/Rx'; ` }) export class NavigationBarComponent { + public isAuthorized: boolean = false; + sub:any; + constructor( private router: Router, private route: ActivatedRoute) {} + + ngOnInit() { + + this.initialize(); + this.sub = this.route.queryParams.subscribe(params => { + this.initialize(); + }); + } + ngOnDestroy(){ + this.sub.unsubscribe(); + } + initialize(){ + if(Session.isLoggedIn() && Session.isUserValid() && Session.isAdminUser()){ + this.isAuthorized = true; + }else { + this.isAuthorized = false; + } + + } }