openaire-library/utils/log/log.service.ts

52 lines
1.6 KiB
TypeScript

import {HttpClient} from "@angular/common/http";
import {EnvProperties} from '../properties/env-properties';
import {Injectable} from "@angular/core";
import {Observable} from "rxjs";
export abstract class Log{
action:string;
message:string;
protected constructor(action, message){
this.action =action;
this.message = message;
}
}
export class LinkLog extends Log{
constructor() {
super("linking","a user linked");
}
}
export class OrcidLinkLog extends Log{
constructor( action:'added'|'removed', title: string, doi: string) {
super("orcid-claim","user with ORCID iD " + action + " research product \"" + title+ "\" (" + doi + ") " + (action == 'added'?'to':'from')
+ " their ORCID record.");
}
}
export class UploadLog extends Log{
constructor(dois:number) {
super("upload-dois","a user uploaded a list of " + dois +" DOIs to the Irish Monitor to check their presence and retrieve the Open Access types and additional key metadata");
}
}
@Injectable()
export class LogService {
constructor(private http: HttpClient) {
}
logUploadDOIs(properties: EnvProperties, dois:number){
return this.http.post(properties.logServiceUrl+"logAction", new UploadLog(dois) );
}
logLink(properties: EnvProperties){
return this.http.post(properties.logServiceUrl+"logAction", new LinkLog() );
}
logOrcidLink(properties: EnvProperties, action:'added'|'removed', title: string, doi: string){
return this.http.post(properties.logServiceUrl+"logAction", new OrcidLinkLog(action, title, doi) );
}
getLogs(properties: EnvProperties):Observable<any>{
return this.http.get(properties.logServiceUrl+"log");
}
}