explore-services/src/app/linking/insertClaim/insertClaim.component.ts

92 lines
3.1 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"> <div class="alert alert-warning" role="alert">{{errorMessage}}</div>
</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 = "";
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];
this.insertClaim(result,user);
}
for (var i = 0; i < this.datasets.length; i++) {
var result=this.datasets[i];
this.insertClaim(result,user);
}
}
}
insertClaim(result:any, user:any){
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", sourceAccessRights:"OPEN", sourceEmbargoEndDate:"", targetId : result.id , targetType : result.type,
targetCollectedFrom: result.source, targetAccessRights:result.accessRights, targetEmbargoEndDate:result.embargoEndDate};
console.info("Trying to insert context - result relation: contextId: "+claim.sourceId +" resultId : " + claim.targetId );
this.claimService.insertClaim(claim).subscribe(
data => {
},
err => console.error(err)
);
}
for (var j = 0; j < this.projects.length; j++) {
var project=this.projects[j];
var claim = { claimedBy : user, sourceId : project.projectId, sourceType : "project", sourceCollectedFrom:"openaire", sourceAccessRights:"OPEN", sourceEmbargoEndDate:"", targetId : result.id , targetType : result.type,
targetCollectedFrom: result.source, targetAccessRights:result.accessRights, targetEmbargoEndDate:result.embargoEndDate};
console.info("Trying to insert project - result relation: projectId: "+claim.sourceId +" resultId : " + claim.targetId );
this.claimService.insertClaim(claim).subscribe(
data => {
},
err => console.error(err)
);
}
}
}