96 lines
3.2 KiB
TypeScript
96 lines
3.2 KiB
TypeScript
|
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
||
|
import {JSONP_PROVIDERS} from '@angular/http';
|
||
|
import {Observable} from 'rxjs/Observable';
|
||
|
import { RouteParams, RouteConfig, ROUTER_DIRECTIVES, Router } from '@angular/router-deprecated';
|
||
|
import {ClaimsService} from '../../services/claims.service';
|
||
|
import {PublicationTitleFormatter} from '../../common/publicationTitleFormatter.component';
|
||
|
|
||
|
|
||
|
@Component({
|
||
|
selector: 'claim-insert',
|
||
|
directives: [...ROUTER_DIRECTIVES],
|
||
|
template: `
|
||
|
|
||
|
<button *ngIf="claiming == false" (click)="insert()">Claim</button>
|
||
|
<div *ngIf="error == true"> {{errorMessage}}
|
||
|
</div>
|
||
|
|
||
|
`,
|
||
|
providers:[JSONP_PROVIDERS, ClaimsService]
|
||
|
})
|
||
|
export class ClaimInsertComponent {
|
||
|
constructor (private claimService: ClaimsService) {}
|
||
|
ngOnInit() {
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
@Input() contexts=[];
|
||
|
@Input() projects=[];
|
||
|
@Input() publications=[];
|
||
|
@Input() datasets=[];
|
||
|
|
||
|
claiming =false;
|
||
|
error = false;
|
||
|
errorMessage = "";
|
||
|
|
||
|
/*
|
||
|
|
||
|
curl -H "Content-Type: application/json" -X POST -d '{ "claimedBy" : "katerina@di.uoa.gr", "sourceId" : "corda_______::2c37878a0cede85dbbd1081bb9b4a2f8", "sourceType" : "project", "sourceCollectedFrom":"openaire", "targetId" : "dedup_wf_001::092c0354ef18384b6fb3e7224bd32b76", "targetType" : "publication", "targetCollectedFrom":"openaire"}'
|
||
|
*/
|
||
|
insert(){
|
||
|
this.claiming = true;
|
||
|
var user="argirok@di.uoa.gr"
|
||
|
if( this.datasets.length == 0 && this.publications.length == 0){
|
||
|
this.errorMessage = "There are no publications or datasets selected.";
|
||
|
this.error = true;
|
||
|
}else if(this.contexts.length == 0 && this.projects.length == 0){
|
||
|
this.errorMessage = "There are no projects or concepts to link.";
|
||
|
this.error = true;
|
||
|
}else{
|
||
|
|
||
|
for (var i = 0; i < this.publications.length; i++) {
|
||
|
|
||
|
var result=this.publications[i];
|
||
|
|
||
|
for (var j = 0; j < this.contexts.length; j++) {
|
||
|
var context=this.contexts[j];
|
||
|
|
||
|
var claim = { claimedBy : user, sourceId : context.concept.id, sourceType : "context", sourceCollectedFrom:"openaire", targetId : result.id , targetType : result.type,
|
||
|
targetCollectedFrom: result.source};
|
||
|
console.info("Trying to insert..... " + claim.targetId );
|
||
|
/*
|
||
|
'{ "claimedBy" : "katerina@di.uoa.gr", "sourceId" : "corda_______::2c37878a0cede85dbbd1081bb9b4a2f8", "sourceType" : "project", "sourceCollectedFrom":"openaire",
|
||
|
"targetId" : "dedup_wf_001::092c0354ef18384b6fb3e7224bd32b76", "targetType" : "publication", "targetCollectedFrom":"openaire"}'
|
||
|
*/
|
||
|
this.claimService.insertClaim(claim).subscribe(
|
||
|
data => {
|
||
|
},
|
||
|
err => console.error(err)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
for (var i = 0; i < this.datasets.length; i++) {
|
||
|
|
||
|
var result=this.datasets[i];
|
||
|
|
||
|
for (var j = 0; j < this.contexts.length; j++) {
|
||
|
var context=this.contexts[j];
|
||
|
|
||
|
var claim = { claimedBy : user, sourceId : context.concept.id, sourceType : "context", sourceCollectedFrom:"openaire", targetId : result.id , targetType : result.type, targetCollectedFrom: result.source};
|
||
|
this.claimService.insertClaim(claim).subscribe(
|
||
|
data => {
|
||
|
},
|
||
|
err => console.error(err)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
// claimService
|
||
|
}
|
||
|
}
|
||
|
}
|