Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/ccd-case-ui-toolkit",
"version": "7.2.59",
"version": "7.2.58-exui-3545-rc3",
"engines": {
"node": ">=18.19.0"
},
Expand Down
2 changes: 1 addition & 1 deletion projects/ccd-case-ui-toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/ccd-case-ui-toolkit",
"version": "7.2.59",
"version": "7.2.58-exui-3545-rc3",
"engines": {
"node": ">=18.19.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export class CaseEditComponent implements OnInit, OnDestroy {
const userId = userInfo.id ? userInfo.id : userInfo.uid;
const eventDetails: EventDetails = {eventId, caseId, userId, assignNeeded};
if (this.taskExistsForThisEvent(taskInSessionStorage, taskEventCompletionInfo, eventDetails)) {
this.abstractConfig.logMessage(`task exist for this event for caseId and eventId as ${caseId} ${eventId}`);
this.abstractConfig.logMessage(`task ${taskInSessionStorage.id} exist for this event for caseId and eventId as ${caseId} ${eventId}`);
// Show event completion component to perform event completion checks
this.eventCompletionParams = ({
caseId,
Expand All @@ -280,6 +280,7 @@ export class CaseEditComponent implements OnInit, OnDestroy {
this.sessionStorageService.setItem(CaseEditComponent.TASK_EVENT_COMPLETION_INFO, JSON.stringify(taskEventCompletionInfo));
this.isEventCompletionChecksRequired = true;
} else {
this.abstractConfig.logMessage(`task does not exist for caseId and eventId as ${caseId} ${eventId}`);
// Task not in session storage, proceed to submit
const caseEventData = this.generateCaseEventData({
eventTrigger,
Expand Down Expand Up @@ -461,11 +462,13 @@ export class CaseEditComponent implements OnInit, OnDestroy {
this.sessionStorageService.setItem('taskCompletionError', 'false');
submit(caseEventData).pipe(switchMap((response) => {
eventResponse = response;
this.abstractConfig.logMessage(`Event ${this.eventCompletionParams?.eventId} of case Id ${this.eventCompletionParams?.caseId} and taskId ${this.eventCompletionParams?.task?.id}`);
return this.postCompleteTaskIfRequired();
}),finalize(() => {
this.loadingService.unregister(loadingSpinnerToken);
// on event completion ensure the previous event clientContext/taskEventCompletionInfo removed
// Note - Not removeTaskFromClientContext because could interfere with other logic
this.abstractConfig.logMessage(`Clearing client context and task event completion info after event ${this.eventCompletionParams?.eventId} submission of case Id ${this.eventCompletionParams?.caseId} and task Id ${this.eventCompletionParams?.task?.id}`);
this.sessionStorageService.removeItem(CaseEditComponent.CLIENT_CONTEXT);
this.sessionStorageService.removeItem(CaseEditComponent.TASK_EVENT_COMPLETION_INFO)
this.isSubmitting = false;
Expand All @@ -475,6 +478,7 @@ export class CaseEditComponent implements OnInit, OnDestroy {
this.finishEventCompletionLogic(eventResponse);
},
error => {
this.abstractConfig.logMessage(`An error occurred while submission of event ${this.eventCompletionParams?.eventId} and case Id ${this.eventCompletionParams?.caseId} and taskId ${this.eventCompletionParams?.task?.id}`);
if (!eventResponse) {
// event submission error
this.error = error;
Expand Down Expand Up @@ -509,6 +513,7 @@ export class CaseEditComponent implements OnInit, OnDestroy {
this.abstractConfig.logMessage(`postCompleteTaskIfRequired: taskId ${task.id} and event name ${this.eventTrigger.name}`);
return this.workAllocationService.completeTask(task.id, this.eventTrigger.name);
}
this.abstractConfig.logMessage(`postCompleteTaskIfRequired: no task to complete for event name ${this.eventTrigger.name} and caseId ${this.caseDetails.case_id}`);
return of(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ describe('EventCompletionStateMachineService', () => {
component: eventCompletionComponentEmitter
};

let mockStateMachineConfig: any;

beforeEach(async () => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
Expand All @@ -143,7 +145,8 @@ describe('EventCompletionStateMachineService', () => {
{ provide: CaseNotifier, useValue: mockCaseNotifier }
]
});
service = new EventCompletionStateMachineService();
mockStateMachineConfig = { logMessage: jasmine.createSpy('logMessage') }; // added
service = new EventCompletionStateMachineService(mockStateMachineConfig); // pass config
});

it('should initialise state machine', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { State, StateMachine } from '@edium/fsm';
import { throwError } from 'rxjs';
import { AbstractAppConfig } from '../../../../app.config';
import { TaskState } from '../../../domain/work-allocation/Task';
import { FieldsUtils } from '../../../services';
import { EventCompletionStateMachineContext } from '../domain/event-completion-state-machine-context.model';
Expand All @@ -23,6 +24,8 @@ export class EventCompletionStateMachineService {
public stateTaskUnassigned: State;
public stateFinal: State;

constructor(private readonly abstractConfig: AbstractAppConfig) {}

public initialiseStateMachine(context: EventCompletionStateMachineContext): StateMachine {
return new StateMachine(EVENT_COMPLETION_STATE_MACHINE, context);
}
Expand Down Expand Up @@ -80,10 +83,11 @@ export class EventCompletionStateMachineService {
this.addTransitionsForStateTaskUnassigned();
}

public entryActionForStateCheckTasksCanBeCompleted(state: State, context: EventCompletionStateMachineContext): void {
public entryActionForStateCheckTasksCanBeCompleted = (state: State, context: EventCompletionStateMachineContext): void => {
const assignNeeded = context.sessionStorageService.getItem('assignNeeded');
context.workAllocationService.getTask(context.task.id).subscribe(
taskResponse => {
this.abstractConfig?.logMessage?.(`entryActionForStateCheckTasksCanBeCompleted: task_state ${taskResponse?.task?.task_state} for task id ${context.task.id}`);
if (taskResponse?.task?.task_state) {
switch (taskResponse.task.task_state.toUpperCase()) {
case TaskState.Unassigned:
Expand Down Expand Up @@ -119,9 +123,11 @@ export class EventCompletionStateMachineService {
} else if (!taskResponse?.task) {
context.alertService.setPreserveAlerts(true);
context.alertService.warning({ phrase: 'Task statecheck : no task available for completion', replacements: {} });
this.abstractConfig?.logMessage?.(`Task statecheck : no task available for completion`);
} else {
context.alertService.setPreserveAlerts(true);
context.alertService.warning({ phrase: 'Task statecheck : no task state available for completion', replacements: {} });
this.abstractConfig?.logMessage?.(`Task statecheck : no task state available for completion`);
}
},
error => {
Expand All @@ -137,11 +143,12 @@ export class EventCompletionStateMachineService {
context.component.setTaskState(EventCompletionTaskStates.TaskCancelled);
}

public entryActionForStateCompleteEventAndTask(state: State, context: EventCompletionStateMachineContext): void {
public entryActionForStateCompleteEventAndTask = (state: State, context: EventCompletionStateMachineContext): void => {
// Trigger final state to complete processing of state machine
state.trigger(EventCompletionStates.Final);
const clientContextStr = context.sessionStorageService.getItem(CaseEditComponent.CLIENT_CONTEXT);
const userTask = FieldsUtils.getUserTaskFromClientContext(clientContextStr);
this.abstractConfig?.logMessage?.(`entryActionForStateCompleteEventAndTask: userTask task_data ${JSON.stringify(userTask?.task_data?.id)}`);
if (userTask?.task_data) {
context.sessionStorageService.setItem('assignNeeded', 'false');
// just set event can be completed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class EventStartGuard implements CanActivate {
}

private checkForTasks(payload: TaskPayload, caseId: string, eventId: string, taskId: string, userId: string): Observable<boolean> {
this.abstractConfig.logMessage(`checkForTasks: for caseId ${caseId} and eventId ${eventId} and taskId ${taskId} and userId ${userId}`);
if (taskId && payload?.tasks?.length > 0) {
const task = payload.tasks.find((t) => t.id == taskId);
if (task) {
Expand Down Expand Up @@ -181,5 +182,6 @@ export class EventStartGuard implements CanActivate {
};
this.sessionStorageService.setItem(CaseEditComponent.TASK_EVENT_COMPLETION_INFO, JSON.stringify(taskEventCompletionInfo));
this.sessionStorageService.setItem(CaseEditComponent.CLIENT_CONTEXT, JSON.stringify(storeClientContext));
this.abstractConfig.logMessage(`EventStartGuard:setClientContextStorage: set task ${task.id} in client context for caseId ${caseId} and eventId ${eventId}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CUSTOM_ELEMENTS_SCHEMA, DebugElement } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ActivatedRoute, Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { AbstractAppConfig } from '../../../app.config';
import { Task } from '../../domain/work-allocation/Task';
import { SessionStorageService } from '../../services';
import { EventStartComponent } from './event-start.component';
Expand Down Expand Up @@ -76,6 +77,10 @@ describe('EventStartComponent', () => {
'addTransitions',
'startStateMachine',
]);
const mockAppConfig: Partial<AbstractAppConfig> = {
// add only the methods EventStartComponent uses
getCaseDataUrl: () => ''
};
TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [EventStartComponent],
Expand All @@ -85,6 +90,7 @@ describe('EventStartComponent', () => {
{ provide: Router, useValue: mockRouter },
{ provide: ActivatedRoute, useValue: mockRoute },
{ provide: EventStartStateMachineService, useValue: eventStartStateMachineService },
{ provide: AbstractAppConfig, useValue: mockAppConfig }
],
}).compileComponents();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { StateMachine } from '@edium/fsm';
import { AbstractAppConfig } from '../../../app.config';
import { Task } from '../../domain/work-allocation/Task';
import { ReadCookieService } from '../../services/cookie/read-cookie-service';
import { SessionStorageService } from '../../services/session/session-storage.service';
Expand All @@ -20,7 +21,8 @@ export class EventStartComponent implements OnInit {
private readonly router: Router,
private readonly route: ActivatedRoute,
private readonly sessionStorageService: SessionStorageService,
private readonly cookieService: ReadCookieService) {
private readonly cookieService: ReadCookieService,
private readonly abstractConfig: AbstractAppConfig) {
}

public ngOnInit(): void {
Expand All @@ -43,7 +45,7 @@ export class EventStartComponent implements OnInit {
};

// Initialise state machine
this.service = new EventStartStateMachineService();
this.service = new EventStartStateMachineService(this.abstractConfig);
this.stateMachine = this.service.initialiseStateMachine(this.context);
// Create states
this.service.createStates(this.stateMachine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,21 @@ describe('EventStartStateMachineService', () => {
cookieService: mockReadCookieService
};

let mockStateMachineConfig: any;

beforeEach(async () => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
providers: [
{ provide: Router, useValue: mockRouter }
{ provide: Router, useValue: mockRouter },
{
provide: EventStartStateMachineService,
useFactory: () => new EventStartStateMachineService(mockStateMachineConfig)
}
]
});
service = new EventStartStateMachineService();
mockStateMachineConfig = { logMessage: jasmine.createSpy('logMessage') }; // minimal stub
service = TestBed.inject(EventStartStateMachineService);
});

it('should initialise state machine', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { Params } from '@angular/router';
import { State, StateMachine } from '@edium/fsm';
import { AbstractAppConfig } from '../../../../app.config';
import { EventStartStateMachineContext, EventStartStates } from '../models';
import { TaskEventCompletionInfo } from '../../../domain/work-allocation/Task';
import { UserInfo } from '../../../domain/user/user-info.model';
Expand All @@ -20,6 +21,8 @@ export class EventStartStateMachineService {
public stateTaskUnassigned: State;
public stateFinal: State;

constructor(private readonly abstractConfig: AbstractAppConfig) {}

public initialiseStateMachine(context: EventStartStateMachineContext): StateMachine {
return new StateMachine(EVENT_STATE_MACHINE, context);
}
Expand Down Expand Up @@ -174,7 +177,7 @@ export class EventStartStateMachineService {
context.router.navigate([`${navigationURL}`], { queryParams: theQueryParams, relativeTo: context.route });
}

public entryActionForStateOneTaskAssignedToUser(state: State, context: EventStartStateMachineContext): void {
public entryActionForStateOneTaskAssignedToUser = (state: State, context: EventStartStateMachineContext): void => {
// Trigger final state to complete processing of state machine
state.trigger(EventStartStates.FINAL);

Expand All @@ -185,6 +188,7 @@ export class EventStartStateMachineService {
}

const taskStr = JSON.stringify(task);
this.abstractConfig?.logMessage?.(`entryActionForStateOneTaskAssignedToUser: task_state ${task?.task_state} for task id ${task.id}`);
console.log('entryActionForStateOneTaskAssignedToUser: setting client context task_data to ' + taskStr);
// Store task to session
const currentLanguage = context.cookieService.getCookie('exui-preferred-language');
Expand Down