[angular-16-irish-monitor | DONE | CHANGED] update log Service, add log actions in claims and orcid links

This commit is contained in:
argirok 2023-12-14 14:01:06 +02:00
parent e4ae0ca35c
commit 5060151e09
5 changed files with 37 additions and 14 deletions

View File

@ -16,6 +16,7 @@ import {
import {UserManagementService} from "../../../services/user-management.service"; import {UserManagementService} from "../../../services/user-management.service";
import {Subscriber, timer} from "rxjs"; import {Subscriber, timer} from "rxjs";
import {map} from "rxjs/operators"; import {map} from "rxjs/operators";
import {LogService} from "../../../utils/log/log.service";
@Component({ @Component({
selector: 'claim-insert', selector: 'claim-insert',
@ -59,7 +60,7 @@ import {map} from "rxjs/operators";
}) })
export class ClaimInsertComponent { export class ClaimInsertComponent {
constructor(private claimService: ClaimsService, private _router: Router, private route: ActivatedRoute, constructor(private claimService: ClaimsService, private _router: Router, private route: ActivatedRoute,
private userManagementService: UserManagementService) { private userManagementService: UserManagementService, private _logService: LogService) {
} }
subscriptions = []; subscriptions = [];
ngOnDestroy() { ngOnDestroy() {
@ -127,6 +128,7 @@ export class ClaimInsertComponent {
public feedRecordsJob; public feedRecordsJob;
public claims2Insert; public claims2Insert;
public records2Insert public records2Insert
infoToLog = [];
public insert() { public insert() {
this.confirmOpen(); this.confirmOpen();
} }
@ -145,6 +147,7 @@ export class ClaimInsertComponent {
this.errorInClaims = []; this.errorInClaims = [];
this.insertedRecords = []; this.insertedRecords = [];
this.errorInRecords = []; this.errorInRecords = [];
this.infoToLog = [];
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => { this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
if (!user) { if (!user) {
this.saveAndNavigate(); this.saveAndNavigate();
@ -190,10 +193,11 @@ export class ClaimInsertComponent {
} else if (entity.project) { } else if (entity.project) {
claims.push(ClaimInsertComponent.createProjectClaim(result, entity, user.email, dashboard)); claims.push(ClaimInsertComponent.createProjectClaim(result, entity, user.email, dashboard));
} }
this.infoToLog.push([ result.title?result.title: result.id, entity.title?entity.title:entity.id]);
} }
if (this.inlineEntity) { if (this.inlineEntity) {
this.infoToLog.push([ this.inlineEntity.title?this.inlineEntity.title: this.inlineEntity.id, entity.title?entity.title:entity.id]);
if (this.inlineEntity.result) { if (this.inlineEntity.result) {
if (entity.result) { if (entity.result) {
@ -256,6 +260,12 @@ export class ClaimInsertComponent {
data => { data => {
this.claims2Insert = claims.length; this.claims2Insert = claims.length;
this.claimsJob = data.data; this.claimsJob = data.data;
if(this.properties.logServiceUrl) {
for(let info of this.infoToLog) {
this.subscriptions.push(this._logService.logLink(this.properties, info[0],info[1]).subscribe(res => {
}));
}
}
this.saveLocalStorage(); this.saveLocalStorage();
let timerSubscription = timer(0, 10000).pipe( let timerSubscription = timer(0, 10000).pipe(
map(() => { map(() => {
@ -375,7 +385,7 @@ export class ClaimInsertComponent {
localStorage.removeItem(this.localStoragePrefix + "claimsJob"); localStorage.removeItem(this.localStoragePrefix + "claimsJob");
localStorage.removeItem(this.localStoragePrefix + "feedRecordsJob"); localStorage.removeItem(this.localStoragePrefix + "feedRecordsJob");
this._router.navigate(['/myclaims'], {queryParams: this.params}); this._router.navigate([this.properties.myClaimsLink], {queryParams: this.params});
} }
} }

View File

@ -6,10 +6,11 @@ import {LoadingModalModule} from '../../../utils/modal/loadingModal.module';
import {ClaimInsertComponent} from './insertClaim.component'; import {ClaimInsertComponent} from './insertClaim.component';
import {ClaimServiceModule} from '../../claim-utils/service/claimsService.module'; import {ClaimServiceModule} from '../../claim-utils/service/claimsService.module';
import {IconsModule} from "../../../utils/icons/icons.module"; import {IconsModule} from "../../../utils/icons/icons.module";
import {LogServiceModule} from "../../../utils/log/LogService.module";
@NgModule({ @NgModule({
imports: [ imports: [
SharedModule, AlertModalModule, LoadingModalModule, ClaimServiceModule, IconsModule SharedModule, AlertModalModule, LoadingModalModule, ClaimServiceModule, IconsModule, LogServiceModule
], ],
declarations: [ClaimInsertComponent], declarations: [ClaimInsertComponent],
exports:[ ClaimInsertComponent] exports:[ ClaimInsertComponent]

View File

@ -12,6 +12,7 @@ import {EnvProperties} from "../utils/properties/env-properties";
import {UserManagementService} from "../services/user-management.service"; import {UserManagementService} from "../services/user-management.service";
import {OpenaireEntities} from "../utils/properties/searchFields"; import {OpenaireEntities} from "../utils/properties/searchFields";
import {FullScreenModalComponent} from "../utils/modal/full-screen-modal/full-screen-modal.component"; import {FullScreenModalComponent} from "../utils/modal/full-screen-modal/full-screen-modal.component";
import {LogService} from "../utils/log/log.service";
declare var UIkit: any; declare var UIkit: any;
@ -377,7 +378,7 @@ export class OrcidWorkComponent {
private _router: Router, private _router: Router,
private orcidService: OrcidService, private orcidService: OrcidService,
private resultLandingService: ResultLandingService, private resultLandingService: ResultLandingService,
private userManagementService: UserManagementService) { private userManagementService: UserManagementService, private _logService: LogService) {
if (typeof document !== 'undefined') { if (typeof document !== 'undefined') {
this.tokenUrl = properties.orcidTokenURL this.tokenUrl = properties.orcidTokenURL
+ "client_id=" + properties.orcidClientId + "client_id=" + properties.orcidClientId
@ -540,7 +541,9 @@ export class OrcidWorkComponent {
private saveWork() { private saveWork() {
this.subscriptions.push(this.orcidService.saveWork(this.resultLandingInfo, this.pids).subscribe( this.subscriptions.push(this.orcidService.saveWork(this.resultLandingInfo, this.pids).subscribe(
response => { response => {
if(this.properties.logServiceUrl) {
this.subscriptions.push(this._logService.logOrcidLink(this.properties, "added", this.resultLandingInfo.title, this.resultLandingInfo.identifiers.get('doi')[0]).subscribe(res => { }));
}
// for testing only // for testing only
// this.openGrantModal("Add work in your ORCID record"); // this.openGrantModal("Add work in your ORCID record");
// this.requestGrant = true; // this.requestGrant = true;
@ -722,6 +725,9 @@ export class OrcidWorkComponent {
if (deletedPutCodes) { if (deletedPutCodes) {
for (let i = 0; i < deletedPutCodes.length; i++) { for (let i = 0; i < deletedPutCodes.length; i++) {
let deletedPutCode = deletedPutCodes[i]; let deletedPutCode = deletedPutCodes[i];
if(this.properties.logServiceUrl) {
this.subscriptions.push(this._logService.logRemoveOrcidLink(this.properties, deletedPutCode).subscribe(res => { }));
}
if (deletedPutCode == null) { if (deletedPutCode == null) {
deletedAll = false; deletedAll = false;
} else { } else {

View File

@ -16,11 +16,12 @@ import {IconsModule} from '../utils/icons/icons.module';
import {IconsService} from "../utils/icons/icons.service"; import {IconsService} from "../utils/icons/icons.service";
import {orcid_add, orcid_bin} from "../utils/icons/icons"; import {orcid_add, orcid_bin} from "../utils/icons/icons";
import {FullScreenModalModule} from "../utils/modal/full-screen-modal/full-screen-modal.module"; import {FullScreenModalModule} from "../utils/modal/full-screen-modal/full-screen-modal.module";
import {LogServiceModule} from "../utils/log/LogService.module";
@NgModule({ @NgModule({
imports: [ imports: [
CommonModule, RouterModule, AlertModalModule, LoadingModule, ResultLandingUtilsModule, CommonModule, RouterModule, AlertModalModule, LoadingModule, ResultLandingUtilsModule,
IconsModule, FullScreenModalModule IconsModule, FullScreenModalModule, LogServiceModule
], ],
declarations: [ declarations: [
OrcidComponent, OrcidComponent,

View File

@ -4,7 +4,7 @@ import {Injectable} from "@angular/core";
import {Observable} from "rxjs"; import {Observable} from "rxjs";
export abstract class Log{ export abstract class Log{
action:string; action: "link" | "orcid-link" | "upload-dois";
message:string; message:string;
protected constructor(action, message){ protected constructor(action, message){
this.action =action; this.action =action;
@ -13,16 +13,18 @@ export abstract class Log{
} }
export class LinkLog extends Log{ export class LinkLog extends Log{
constructor() { constructor(sourceTitle,targetTitle) {
super("linking","a user linked"); super("link","a user linked the \"" +sourceTitle+"\" " + " to the \"" +targetTitle+"\" " );
} }
} }
export class OrcidLinkLog extends Log{ export class OrcidLinkLog extends Log{
constructor( action:'added'|'removed', title: string, doi: string) { constructor( action:'added'|'removed', title: string, id: string) {
super("orcid-claim","user with ORCID iD " + action + " research product \"" + title+ "\" (" + doi + ") " + (action == 'added'?'to':'from') super("orcid-link","user with ORCID ID " + action + " research product "+ (title?"\"" + title+ "\"":"") + " (" + id + ") " + (action == 'added'?'to':'from')
+ " their ORCID record."); + " their ORCID record.");
} }
} }
export class UploadLog extends Log{ export class UploadLog extends Log{
@ -39,12 +41,15 @@ export class LogService {
logUploadDOIs(properties: EnvProperties, dois:number){ logUploadDOIs(properties: EnvProperties, dois:number){
return this.http.post(properties.logServiceUrl+"logAction", new UploadLog(dois) ); return this.http.post(properties.logServiceUrl+"logAction", new UploadLog(dois) );
} }
logLink(properties: EnvProperties){ logLink(properties: EnvProperties, sourceTitle,targetTitle){
return this.http.post(properties.logServiceUrl+"logAction", new LinkLog() ); return this.http.post(properties.logServiceUrl+"logAction", new LinkLog(sourceTitle, targetTitle) );
} }
logOrcidLink(properties: EnvProperties, action:'added'|'removed', title: string, doi: string){ logOrcidLink(properties: EnvProperties, action:'added'|'removed', title: string, doi: string){
return this.http.post(properties.logServiceUrl+"logAction", new OrcidLinkLog(action, title, doi) ); return this.http.post(properties.logServiceUrl+"logAction", new OrcidLinkLog(action, title, doi) );
} }
logRemoveOrcidLink(properties: EnvProperties, code: string){
return this.http.post(properties.logServiceUrl+"logAction", new OrcidLinkLog('removed',null, code) );
}
getLogs(properties: EnvProperties):Observable<any>{ getLogs(properties: EnvProperties):Observable<any>{
return this.http.get(properties.logServiceUrl+"log"); return this.http.get(properties.logServiceUrl+"log");
} }