Commit dec9fba2 authored by Florent Poittevin's avatar Florent Poittevin Committed by Alicia.DeDiosFuente
Browse files

feat: [DLCM-1985] improve sequential and parallel dispatch actions to manage intention and timeout

parent 0d70859c
......@@ -27,8 +27,15 @@ import {
} from "@shared/enums/routes.enum";
import {StateEnum} from "@shared/enums/state.enum";
import {SharedOrgUnitAction} from "@shared/stores/organizational-unit/shared-organizational-unit.action";
import {Observable} from "rxjs";
import {tap} from "rxjs/operators";
import {
Observable,
of,
switchMap,
} from "rxjs";
import {
map,
tap,
} from "rxjs/operators";
import {
ApiService,
defaultAssociationStateInitValue,
......@@ -110,7 +117,7 @@ export class AdminFundingAgenciesState extends ResourceState<AdminFundingAgencie
}
@Action(AdminFundingAgenciesAction.LoadResource)
loadResource(ctx: StateContext<AdminFundingAgenciesStateModel>, action: AdminFundingAgenciesAction.LoadResource): Observable<any> {
loadResource(ctx: StateContext<AdminFundingAgenciesStateModel>, action: AdminFundingAgenciesAction.LoadResource): Observable<boolean> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
......@@ -124,12 +131,13 @@ export class AdminFundingAgenciesState extends ResourceState<AdminFundingAgencie
],
},
]).pipe(
tap(success => {
if (success) {
map(result => {
if (result.success) {
ctx.dispatch(new AdminFundingAgenciesAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminFundingAgenciesAction.LoadResourceFail(action));
}
return result.success;
}),
);
}
......@@ -180,12 +188,14 @@ export class AdminFundingAgenciesState extends ResourceState<AdminFundingAgencie
this.actions$.pipe(ofSolidifyActionCompleted(AdminFundingAgenciesOrgUnitAction.UpdateSuccess)),
this.actions$.pipe(ofSolidifyActionCompleted(AdminFundingAgenciesOrgUnitAction.UpdateFail)),
],
}]);
}]).pipe(
map(result => result.success),
);
}
@OverrideDefaultAction()
@Action(AdminFundingAgenciesAction.Delete)
delete(ctx: StateContext<AdminFundingAgenciesStateModel>, action: AdminFundingAgenciesAction.Delete): Observable<any> {
delete(ctx: StateContext<AdminFundingAgenciesStateModel>, action: AdminFundingAgenciesAction.Delete): Observable<FundingAgency> {
const oldOrgUnit = ctx.getState().admin_fundingAgencies_organizationalUnit.selected.map(o => o.resId);
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(
......@@ -200,11 +210,13 @@ export class AdminFundingAgenciesState extends ResourceState<AdminFundingAgencie
},
],
).pipe(
tap(deleteSubResourceWithSuccess => {
if (deleteSubResourceWithSuccess) {
this.subscribe(super.delete(ctx, action));
map(result => result.success),
switchMap(success => {
if (success) {
return super.delete(ctx, action);
} else {
super.deleteFail(ctx, action as any);
return of(null);
}
}),
);
......
......@@ -9,9 +9,7 @@ import {
} from "@admin/institution/stores/organizational-unit/admin-institution-organizational-unit.state";
import {HttpClient} from "@angular/common/http";
import {Injectable} from "@angular/core";
import {
Institution,
} from "@models";
import {Institution} from "@models";
import {
Action,
Actions,
......@@ -33,7 +31,10 @@ import {
ResourceLogoStateModeEnum,
} from "@shared/stores/resource-logo/resource-logo.state";
import {Observable} from "rxjs";
import {tap} from "rxjs/operators";
import {
map,
tap,
} from "rxjs/operators";
import {
ApiService,
defaultAssociationStateInitValue,
......@@ -53,14 +54,15 @@ export interface AdminInstitutionStateModel extends ResourceLogoStateModel<Insti
@Injectable()
@State<AdminInstitutionStateModel>({
name: StateEnum.admin_institution,
defaults: {
...defaultResourceLogoStateInitValue(),
admin_institution_organizationalUnit: {...defaultAssociationStateInitValue()},
name: StateEnum.admin_institution,
defaults: {
...defaultResourceLogoStateInitValue(),
admin_institution_organizationalUnit: {...defaultAssociationStateInitValue()},
},
children: [
AdminInstitutionOrganizationalUnitState,
],
},
children: [
AdminInstitutionOrganizationalUnitState,
]},
)
export class AdminInstitutionState extends ResourceLogoState<AdminInstitutionStateModel, Institution> {
constructor(protected apiService: ApiService,
......@@ -127,7 +129,6 @@ export class AdminInstitutionState extends ResourceLogoState<AdminInstitutionSta
}
}
@OverrideDefaultAction()
@Action(AdminInstitutionAction.Create)
create(ctx: StateContext<AdminInstitutionStateModel>, action: AdminInstitutionAction.Create): Observable<Institution> {
......@@ -152,14 +153,16 @@ export class AdminInstitutionState extends ResourceLogoState<AdminInstitutionSta
return super.internalUpdate(ctx, action)
.pipe(
tap(model => {
this.updateSubResource(model, action, ctx)
.subscribe(success => {
if (success) {
ctx.dispatch(new AdminInstitutionAction.UpdateSuccess(action, model));
} else {
ctx.dispatch(new AdminInstitutionAction.UpdateFail(action));
}
});
this.subscribe(
this.updateSubResource(model, action, ctx).pipe(
tap(success => {
if (success) {
ctx.dispatch(new AdminInstitutionAction.UpdateSuccess(action, model));
} else {
ctx.dispatch(new AdminInstitutionAction.UpdateFail(action));
}
}),
));
}),
);
}
......@@ -177,7 +180,9 @@ export class AdminInstitutionState extends ResourceLogoState<AdminInstitutionSta
this.actions$.pipe(ofSolidifyActionCompleted(AdminInstitutionOrganizationalUnitAction.UpdateFail)),
],
},
]);
]).pipe(
map(result => result.success),
);
}
}
......@@ -18,7 +18,7 @@ import {RoutesEnum} from "@shared/enums/routes.enum";
import {StateEnum} from "@shared/enums/state.enum";
import {SharedLanguageAction} from "@shared/stores/language/shared-language.action";
import {Observable} from "rxjs";
import {tap} from "rxjs/operators";
import {map} from "rxjs/operators";
import {
ApiService,
defaultResourceStateInitValue,
......@@ -90,7 +90,7 @@ export class AdminLanguageState extends ResourceState<AdminLanguageStateModel, L
}
@Action(AdminLanguageAction.LoadResource)
loadResource(ctx: StateContext<DepositStateModel>, action: AdminLanguageAction.LoadResource): Observable<any> {
loadResource(ctx: StateContext<DepositStateModel>, action: AdminLanguageAction.LoadResource): Observable<boolean> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
......@@ -104,12 +104,13 @@ export class AdminLanguageState extends ResourceState<AdminLanguageStateModel, L
],
},
]).pipe(
tap(success => {
if (success) {
map(result => {
if (result.success) {
ctx.dispatch(new AdminLanguageAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminLanguageAction.LoadResourceFail(action));
}
return result.success;
}),
);
}
......
......@@ -25,7 +25,10 @@ import {StateEnum} from "@shared/enums/state.enum";
import {SharedRoleAction} from "@shared/stores/role/shared-role.action";
import {defaultStatusHistoryInitValue} from "@shared/stores/status-history/status-history.state";
import {Observable} from "rxjs";
import {tap} from "rxjs/operators";
import {
map,
tap,
} from "rxjs/operators";
import {
ApiService,
defaultResourceStateInitValue,
......@@ -105,7 +108,7 @@ export class AdminNotificationState extends ResourceState<AdminNotificationState
@OverrideDefaultAction()
@Action(AdminNotificationAction.LoadResource)
loadResource(ctx: StateContext<AdminNotificationStateModel>, action: AdminNotificationAction.LoadResource): Observable<any> {
loadResource(ctx: StateContext<AdminNotificationStateModel>, action: AdminNotificationAction.LoadResource): Observable<boolean> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
......@@ -119,12 +122,13 @@ export class AdminNotificationState extends ResourceState<AdminNotificationState
],
},
]).pipe(
tap(success => {
if (success) {
map(result => {
if (result.success) {
ctx.dispatch(new AdminNotificationAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminNotificationAction.LoadResourceFail(action));
}
return result.success;
}),
);
}
......
......@@ -20,7 +20,10 @@ import {
import {StateEnum} from "@shared/enums/state.enum";
import {SharedOrgUnitAction} from "@shared/stores/organizational-unit/shared-organizational-unit.action";
import {Observable} from "rxjs";
import {tap} from "rxjs/operators";
import {
map,
tap,
} from "rxjs/operators";
import {
ApiService,
defaultResourceStateInitValue,
......@@ -95,7 +98,7 @@ export class AdminOaiSetState extends ResourceState<AdminOaiSetStateModel, OaiSe
}
@Action(AdminOaiSetAction.LoadResource)
loadResource(ctx: StateContext<AdminOaiSetStateModel>, action: AdminOaiSetAction.LoadResource): Observable<any> {
loadResource(ctx: StateContext<AdminOaiSetStateModel>, action: AdminOaiSetAction.LoadResource): Observable<boolean> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
......@@ -109,12 +112,13 @@ export class AdminOaiSetState extends ResourceState<AdminOaiSetStateModel, OaiSe
],
},
]).pipe(
tap(success => {
if (success) {
map(result => {
if (result.success) {
ctx.dispatch(new AdminOaiSetAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminOaiSetAction.LoadResourceFail(action));
}
return result.success;
}),
);
}
......@@ -146,13 +150,13 @@ export class AdminOaiSetState extends ResourceState<AdminOaiSetStateModel, OaiSe
],
});
});
StoreUtil.dispatchSequentialActionAndWaitForSubActionsCompletion(ctx, listActionSubActionCompletionsWrapper).subscribe(success => {
if (success) {
this.subscribe(StoreUtil.dispatchSequentialActionAndWaitForSubActionsCompletion(ctx, listActionSubActionCompletionsWrapper).pipe(tap(result => {
if (result.success) {
ctx.dispatch(new AdminOaiSetAction.BulkCreateSuccess(action));
} else {
ctx.dispatch(new AdminOaiSetAction.BulkCreateFail(action));
}
});
})));
}
@Action(AdminOaiSetAction.BulkCreateSuccess)
......
......@@ -69,7 +69,10 @@ import {
import {SharedRoleAction} from "@shared/stores/role/shared-role.action";
import {SharedSubmissionPolicyAction} from "@shared/stores/submission-policy/shared-submission-policy.action";
import {Observable} from "rxjs";
import {tap} from "rxjs/operators";
import {
map,
tap,
} from "rxjs/operators";
import {
ApiService,
defaultAssociationStateInitValue,
......@@ -188,7 +191,7 @@ export class AdminOrganizationalUnitState extends ResourceLogoState<AdminOrganiz
}
@Action(AdminOrganizationalUnitAction.LoadResource)
loadResource(ctx: StateContext<DepositStateModel>, action: AdminOrganizationalUnitAction.LoadResource): Observable<any> {
loadResource(ctx: StateContext<DepositStateModel>, action: AdminOrganizationalUnitAction.LoadResource): Observable<boolean> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
......@@ -223,12 +226,13 @@ export class AdminOrganizationalUnitState extends ResourceLogoState<AdminOrganiz
],
},
]).pipe(
tap(success => {
if (success) {
map(result => {
if (result.success) {
ctx.dispatch(new AdminOrganizationalUnitAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminOrganizationalUnitAction.LoadResourceFail(action));
}
return result.success;
}));
}
......@@ -349,7 +353,9 @@ export class AdminOrganizationalUnitState extends ResourceLogoState<AdminOrganiz
this.actions$.pipe(ofSolidifyActionCompleted(AdminOrganizationalUnitInstitutionAction.UpdateFail)),
],
},
]);
]).pipe(
map(result => result.success),
);
}
@OverrideDefaultAction()
......
......@@ -21,7 +21,10 @@ import {
Observable,
of,
} from "rxjs";
import {tap} from "rxjs/operators";
import {
map,
tap,
} from "rxjs/operators";
import {
ActionSubActionCompletionsWrapper,
ApiService,
......@@ -107,7 +110,9 @@ export class AdminOrganizationalUnitDisseminationPolicyState extends Relation2Ti
if (isEmptyArray(listActionSubActionCompletionsWrapper)) {
return of(true);
}
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, listActionSubActionCompletionsWrapper);
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, listActionSubActionCompletionsWrapper).pipe(
map(result => result.success),
);
}
private getSubActionCompletions(): Observable<ActionCompletion<BaseSubAction<AdminOrganizationalUnitDisseminationPolicyAction.UpdateRelation>, Error>>[] | undefined {
......
......@@ -21,7 +21,10 @@ import {
Observable,
of,
} from "rxjs";
import {tap} from "rxjs/operators";
import {
map,
tap,
} from "rxjs/operators";
import {
ActionSubActionCompletionsWrapper,
ApiService,
......@@ -107,7 +110,9 @@ export class AdminOrganizationalUnitPreservationPolicyState extends Relation2Tie
if (isEmptyArray(listActionSubActionCompletionsWrapper)) {
return of(true);
}
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, listActionSubActionCompletionsWrapper);
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, listActionSubActionCompletionsWrapper).pipe(
map(result => result.success),
);
}
private getSubActionCompletions(): Observable<ActionCompletion<BaseSubAction<AdminOrganizationalUnitPreservationPolicyAction.UpdateRelation>, Error>>[] | undefined {
......
......@@ -21,7 +21,10 @@ import {
Observable,
of,
} from "rxjs";
import {tap} from "rxjs/operators";
import {
map,
tap,
} from "rxjs/operators";
import {
ActionSubActionCompletionsWrapper,
ApiService,
......@@ -107,7 +110,9 @@ export class AdminOrganizationalUnitSubmissionPolicyState extends Relation2Tiers
if (isEmptyArray(listActionSubActionCompletionsWrapper)) {
return of(true);
}
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, listActionSubActionCompletionsWrapper);
return StoreUtil.dispatchParallelActionAndWaitForSubActionsCompletion(ctx, listActionSubActionCompletionsWrapper).pipe(
map(result => result.success),
);
}
private getSubActionCompletions(): Observable<ActionCompletion<BaseSubAction<AdminOrganizationalUnitSubmissionPolicyAction.UpdateRelation>, Error>>[] | undefined {
......
......@@ -32,7 +32,10 @@ import {
import {StateEnum} from "@shared/enums/state.enum";
import {SharedRoleAction} from "@shared/stores/role/shared-role.action";
import {Observable} from "rxjs";
import {tap} from "rxjs/operators";
import {
map,
tap,
} from "rxjs/operators";
import {
ApiService,
defaultAssociationStateInitValue,
......@@ -121,7 +124,7 @@ export class AdminPersonState extends ResourceState<AdminPersonStateModel, Perso
}
@Action(AdminPersonAction.LoadResource)
loadResource(ctx: StateContext<DepositStateModel>, action: AdminPersonAction.LoadResource): Observable<any> {
loadResource(ctx: StateContext<DepositStateModel>, action: AdminPersonAction.LoadResource): Observable<boolean> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
......@@ -135,12 +138,13 @@ export class AdminPersonState extends ResourceState<AdminPersonStateModel, Perso
],
},
]).pipe(
tap(success => {
if (success) {
map(result => {
if (result.success) {
ctx.dispatch(new AdminPersonAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminPersonAction.LoadResourceFail(action));
}
return result.success;
}),
);
}
......@@ -206,6 +210,8 @@ export class AdminPersonState extends ResourceState<AdminPersonStateModel, Perso
this.actions$.pipe(ofSolidifyActionCompleted(AdminPersonInstitutionsAction.UpdateFail)),
],
},
]);
]).pipe(
map(result => result.success),
);
}
}
......@@ -18,7 +18,10 @@ import {RoutesEnum} from "@shared/enums/routes.enum";
import {StateEnum} from "@shared/enums/state.enum";
import {SharedLanguageAction} from "@shared/stores/language/shared-language.action";
import {Observable} from "rxjs";
import {tap} from "rxjs/operators";
import {
map,
tap,
} from "rxjs/operators";
import {
ApiService,
defaultResourceStateInitValue,
......@@ -90,7 +93,7 @@ export class AdminResearchDomainState extends ResourceState<AdminResearchDomainS
}
@Action(AdminResearchDomainAction.LoadResource)
loadResource(ctx: StateContext<DepositStateModel>, action: AdminResearchDomainAction.LoadResource): Observable<any> {
loadResource(ctx: StateContext<DepositStateModel>, action: AdminResearchDomainAction.LoadResource): Observable<boolean> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
......@@ -104,12 +107,13 @@ export class AdminResearchDomainState extends ResourceState<AdminResearchDomainS
],
},
]).pipe(
tap(success => {
if (success) {
map(result => {
if (result.success) {
ctx.dispatch(new AdminResearchDomainAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminResearchDomainAction.LoadResourceFail(action));
}
return result.success;
}),
);
}
......
......@@ -30,6 +30,7 @@ import {
import {Observable} from "rxjs";
import {
catchError,
map,
tap,
} from "rxjs/operators";
import {
......@@ -112,7 +113,7 @@ export class AdminUserState extends ResourceLogoState<AdminUserStateModel, User>
}
@Action(AdminUserAction.LoadResource)
loadResource(ctx: StateContext<AdminUserStateModel>, action: AdminUserAction.LoadResource): Observable<any> {
loadResource(ctx: StateContext<AdminUserStateModel>, action: AdminUserAction.LoadResource): Observable<boolean> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
......@@ -126,12 +127,13 @@ export class AdminUserState extends ResourceLogoState<AdminUserStateModel, User>
],
},
]).pipe(
tap(success => {
if (success) {
map(result => {
if (result.success) {
ctx.dispatch(new AdminUserAction.LoadResourceSuccess(action));
} else {
ctx.dispatch(new AdminUserAction.LoadResourceFail(action));
}
return result.success;
}),
);
}
......
......@@ -19,6 +19,7 @@ import {UserPreferencesUtil} from "@shared/utils/user-preferences.util";
import {tap} from "rxjs/operators";
import {
isEmptyArray,
isFalse,
isNullOrUndefined,
MARK_AS_TRANSLATABLE,
MemoizedUtil,
......@@ -51,8 +52,8 @@ export class DepositRootRoutable extends SharedAbstractRoutable implements OnIni
],
},
]).pipe(
tap(success => {
if (!success) {
tap(result => {
if (isFalse(result.success)) {
return;
}
......
......@@ -29,6 +29,7 @@ import {defaultStatusHistoryInitValue} from "@shared/stores/status-history/statu
import {Observable} from "rxjs";
import {
catchError,
map,
tap,
} from "rxjs/operators";
import {
......@@ -91,7 +92,7 @@ export class DepositCollectionState extends AssociationRemoteState<DepositCollec
}
@Action(DepositCollectionAction.Refresh)
refresh(ctx: StateContext<DepositCollectionStateModel>, action: DepositCollectionAction.Refresh): Observable<any> {
refresh(ctx: StateContext<DepositCollectionStateModel>, action: DepositCollectionAction.Refresh): Observable<boolean> {
ctx.patchState({
isLoadingCounter: ctx.getState().isLoadingCounter + 1,
});
......@@ -112,12 +113,13 @@ export class DepositCollectionState extends AssociationRemoteState<DepositCollec
],
},
]).pipe(
tap(success => {
if (success) {
map(result => {
if (result.success) {
ctx.dispatch(new DepositCollectionAction.RefreshSuccess(action));
} else {
ctx.dispatch(new DepositCollectionAction.RefreshFail(action));
}
return result.success;
}),
);
}
......