2023-11-28 17:42:21 +01:00
import { HttpClient } from "@angular/common/http" ;
import { EnvProperties } from '../properties/env-properties' ;
import { Injectable } from "@angular/core" ;
2023-12-13 16:38:25 +01:00
import { Observable } from "rxjs" ;
2023-11-28 17:42:21 +01:00
export abstract class Log {
2023-12-14 13:01:06 +01:00
action : "link" | "orcid-link" | "upload-dois" ;
2023-11-28 17:42:21 +01:00
message :string ;
protected constructor ( action , message ) {
this . action = action ;
this . message = message ;
}
}
export class LinkLog extends Log {
2023-12-14 13:01:06 +01:00
constructor ( sourceTitle , targetTitle ) {
super ( "link" , "a user linked the \"" + sourceTitle + "\" " + " to the \"" + targetTitle + "\" " ) ;
2023-11-28 17:42:21 +01:00
}
}
export class OrcidLinkLog extends Log {
2023-12-14 13:01:06 +01:00
constructor ( action : 'added' | 'removed' , title : string , id : string ) {
super ( "orcid-link" , "user with ORCID ID " + action + " research product " + ( title ? "\"" + title + "\"" : "" ) + " (" + id + ") " + ( action == 'added' ? 'to' : 'from' )
2023-11-28 17:42:21 +01:00
+ " their ORCID record." ) ;
}
2023-12-14 13:01:06 +01:00
2023-11-28 17:42:21 +01:00
}
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 ) {
2023-12-12 15:39:59 +01:00
return this . http . post ( properties . logServiceUrl + "logAction" , new UploadLog ( dois ) ) ;
2023-11-28 17:42:21 +01:00
}
2023-12-14 13:01:06 +01:00
logLink ( properties : EnvProperties , sourceTitle , targetTitle ) {
return this . http . post ( properties . logServiceUrl + "logAction" , new LinkLog ( sourceTitle , targetTitle ) ) ;
2023-11-28 17:42:21 +01:00
}
logOrcidLink ( properties : EnvProperties , action : 'added' | 'removed' , title : string , doi : string ) {
2023-12-12 15:39:59 +01:00
return this . http . post ( properties . logServiceUrl + "logAction" , new OrcidLinkLog ( action , title , doi ) ) ;
2023-11-28 17:42:21 +01:00
}
2023-12-14 13:01:06 +01:00
logRemoveOrcidLink ( properties : EnvProperties , code : string ) {
return this . http . post ( properties . logServiceUrl + "logAction" , new OrcidLinkLog ( 'removed' , null , code ) ) ;
}
2023-12-13 16:38:25 +01:00
getLogs ( properties : EnvProperties ) : Observable < any > {
return this . http . get ( properties . logServiceUrl + "log" ) ;
}
2023-11-28 17:42:21 +01:00
}