Skip to content

Commit

Permalink
Merge pull request #493 from MauroDataMapper/feature/gh-481_data_spec…
Browse files Browse the repository at this point in the history
…_turn_off_auto_submission

gh-481: Turn off Data Request auto submission
  • Loading branch information
NigelPalmer authored Dec 17, 2024
2 parents 0cefb0f + 6289cbb commit 7112b8c
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 993 deletions.
19 changes: 12 additions & 7 deletions src/app/core/sde-mauro-core.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ limitations under the License.
SPDX-License-Identifier: Apache-2.0
*/
import { Injectable } from '@angular/core';
import { IMauroCoreService, MauroDataSpecificationDTO } from '@maurodatamapper/sde-resources';
import {
IMauroCoreService,
MauroDataSpecificationDTO,
RequestResponse,
RequestType,
} from '@maurodatamapper/sde-resources';
import { SecurityService } from '../security/security.service';
import { DataSpecificationService } from '../data-explorer/data-specification.service';
import { DataSpecification } from '../data-explorer/data-explorer.types';
Expand Down Expand Up @@ -59,12 +64,12 @@ export class SdeMauroCoreService implements IMauroCoreService {

attachMauroDataSpecificationToRequest(
specificationId: Uuid,
requestId: Uuid
request: RequestResponse
): Observable<boolean> {
return this.specificationSubmissionService.submit(
specificationId,
SubmissionType.AttachPdfToRequest,
requestId
);
const submissionType =
request.type === RequestType.Data
? SubmissionType.AttachSqlAndPdfToRequest
: SubmissionType.AttachPdfToRequest;
return this.specificationSubmissionService.submit(specificationId, submissionType, request.id);
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
RequestResponse,
RequestService,
SdeRequest,
UserProjectDTO,
Uuid,
} from '@maurodatamapper/sde-resources';
import {
Expand All @@ -44,7 +43,6 @@ import { Observable } from 'rxjs/internal/Observable';
import { of } from 'rxjs/internal/observable/of';
import { switchMap } from 'rxjs/internal/operators/switchMap';
import { SubmissionStateService } from './submission-state.service';
import { CreateDataRequestStep } from '../submission-steps/create-data-request.step';
import {
ISubmissionStep,
StepName,
Expand All @@ -55,7 +53,6 @@ import { GenerateSqlStep } from '../submission-steps/generate-sql.step';
import { AttachSqlStep } from '../submission-steps/attach-sql.step';
import { GeneratePdfStep } from '../submission-steps/generate-pdf.step';
import { AttachPdfStep } from '../submission-steps/attach-pdf.step';
import { SubmitRequestStep } from '../submission-steps/submit-request.step';
import { BroadcastService } from 'src/app/core/broadcast.service';
import { DialogService } from '../../dialog.service';
import {
Expand All @@ -71,33 +68,29 @@ import {
providedIn: 'root',
})
export class SpecificationSubmissionService {
private dataRequestSubmissionSteps: ISubmissionStep[] = [];
private attachToRequestSubmissionSteps: ISubmissionStep[] = [];
private attachSqlAndPdfToRequestSubmissionSteps: ISubmissionStep[] = [];
private attachPdfToRequestSubmissionSteps: ISubmissionStep[] = [];

constructor(
private stateService: SubmissionStateService,
private dialogService: DialogService,
private broadcastService: BroadcastService,
private createDataRequestStep: CreateDataRequestStep,
private generateSqlStep: GenerateSqlStep,
private attachSqlStep: AttachSqlStep,
private generatePdfStep: GeneratePdfStep,
private attachPdfStep: AttachPdfStep,
private submitRequestStep: SubmitRequestStep,
private researcherRequestEndpoints: RequestEndpointsResearcher,
private membershipEndpoints: MembershipEndpointsResearcher,
private requestsService: RequestService
) {
this.dataRequestSubmissionSteps = [
this.createDataRequestStep,
this.attachSqlAndPdfToRequestSubmissionSteps = [
this.generateSqlStep,
this.attachSqlStep,
this.generatePdfStep,
this.attachPdfStep,
this.submitRequestStep,
];

this.attachToRequestSubmissionSteps = [this.generatePdfStep, this.attachPdfStep];
this.attachPdfToRequestSubmissionSteps = [this.generatePdfStep, this.attachPdfStep];
}

chooseRequestType(specificationId: Uuid): Observable<SubmissionWizardDialogResponse> {
Expand All @@ -106,12 +99,12 @@ export class SpecificationSubmissionService {
throw new Error('chooseRequestType: Specification ID is required.');
}

const projects$ = this.membershipEndpoints.listProjects().pipe(
map((projects: UserProjectDTO[]) =>
projects.map<IdNamePair>((proj) => {
const dataRequests$ = this.requestsService.listDraftDataRequests().pipe(
map((requests: SdeRequest[]) =>
requests.map<IdNamePair>((request) => {
return {
id: proj.projectId,
name: proj.projectName,
id: request.id,
name: request.title,
};
})
)
Expand Down Expand Up @@ -151,18 +144,14 @@ export class SpecificationSubmissionService {
} else {
// If `requestId` is undefined, use `forkJoin` to wait for both `projects$` and `newProjectRequests$`
return forkJoin({
projects: projects$,
dataRequests: dataRequests$,
newProjectRequests: newProjectRequests$,
projectChangeRequests: projectChangeRequests$,
}).pipe(
map(({ projects, newProjectRequests, projectChangeRequests }) => {
if (projects.length === 0 && newProjectRequests.length === 0) {
throw new NoProjectsFoundError();
}

map(({ dataRequests, newProjectRequests, projectChangeRequests }) => {
// Construct the dialog data with both projects and new project requests
const dialogData: SubmissionWizardDialogData = {
projects,
dataRequests,
newProjectRequests,
projectChangeRequests,
};
Expand Down Expand Up @@ -193,21 +182,20 @@ export class SpecificationSubmissionService {
submit(
specificationId: Uuid,
submissionType: SubmissionType,
requestId: Uuid | undefined = undefined,
projectId: Uuid | undefined = undefined
requestId: Uuid
): Observable<boolean> {
// Set initial state.
this.stateService.clear();

let submissionSteps: ISubmissionStep[] = [];

switch (submissionType) {
case SubmissionType.DataRequest:
submissionSteps = this.dataRequestSubmissionSteps;
this.stateService.set({ projectId });
case SubmissionType.AttachSqlAndPdfToRequest:
submissionSteps = this.attachSqlAndPdfToRequestSubmissionSteps;
this.stateService.set({ requestId });
break;
case SubmissionType.AttachPdfToRequest:
submissionSteps = this.attachToRequestSubmissionSteps;
submissionSteps = this.attachPdfToRequestSubmissionSteps;
this.stateService.set({ requestId });
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,21 @@ <h1 mat-dialog-title>Attach to Request</h1>

<!-- Page 2: Select Project form -->
<div *ngIf="currentPage === WizardPage.DataRequest">
<h1 mat-dialog-title>Create Data Request</h1>
<h1 mat-dialog-title>Attach to Data Request</h1>
<mat-dialog-content>
<form [formGroup]="selectProjectForm" role="form" name="selectProjectForm">
<form [formGroup]="selectDataRequestForm" role="form" name="selectDataRequestForm">
<div class="form-input">
<p>
Data Requests are automatically submitted. <br /><br />
Please select the project you would like to submit this data specification on behalf of.
</p>
<p>Please select the Data Request you would like to attach this data specification to.</p>
<mat-form-field appearance="outline">
<mat-label>Project</mat-label>
<mat-select formControlName="project" required>
<mat-option *ngFor="let project of projects" [value]="project">{{
project.name
<mat-label>Data Request</mat-label>
<mat-select formControlName="dataRequest" required>
<mat-option *ngFor="let dataRequest of dataRequests" [value]="dataRequest">{{
dataRequest.name
}}</mat-option>
</mat-select>
</mat-form-field>
<mat-error *ngIf="selectProjectForm.controls.project.errors?.['required']">
Please select a project
<mat-error *ngIf="selectDataRequestForm.controls.dataRequest.errors?.['required']">
Please select a Data Request
</mat-error>
</div>
</form>
Expand All @@ -75,7 +72,7 @@ <h1 mat-dialog-title>Create Data Request</h1>
<button
mat-flat-button
color="primary"
[disabled]="selectProjectForm.invalid"
[disabled]="selectDataRequestForm.invalid"
(click)="submitAttachToDataRequest()"
>
Attach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ import { Component, Inject, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { IdNamePair, RequestType, Uuid } from '@maurodatamapper/sde-resources';
import { SelectProjectDialogResponse } from '../select-project-dialog/select-project-dialog.component';

export interface SubmissionWizardDialogData {
projects: IdNamePair[];
dataRequests: IdNamePair[];
newProjectRequests: IdNamePair[];
projectChangeRequests: IdNamePair[];
}

export interface SubmissionWizardDialogResponse {
requestType: RequestType;
requestId: Uuid | undefined;
projectId: Uuid | undefined;
}

enum WizardPage {
Expand All @@ -51,13 +49,13 @@ export class SpecificationSubmissionWizardComponent implements OnInit {
currentPage = WizardPage.First; // Tracks the current page of the wizard
selectedOption: number | null = null; // Tracks the selected radio option

projects: IdNamePair[];
dataRequests: IdNamePair[];
newProjectRequests: IdNamePair[];
projectChangeRequests: IdNamePair[];

selectProjectForm = new FormGroup({
selectDataRequestForm = new FormGroup({
// eslint-disable-next-line @typescript-eslint/unbound-method
project: new FormControl<IdNamePair | null>(null, Validators.required),
dataRequest: new FormControl<IdNamePair | null>(null, Validators.required),
});

selectNewProjectRequestForm = new FormGroup({
Expand All @@ -74,7 +72,9 @@ export class SpecificationSubmissionWizardComponent implements OnInit {
private dialogRef: MatDialogRef<SpecificationSubmissionWizardComponent>,
@Inject(MAT_DIALOG_DATA) private data: SubmissionWizardDialogData
) {
this.projects = this.data.projects ?? [];
this.dataRequests = this.data.dataRequests ?? [];
const dataRequest: IdNamePair = { id: '', name: '<< Create Data Request >>' };
this.dataRequests.unshift(dataRequest);

this.newProjectRequests = this.data.newProjectRequests ?? [];
const newProject: IdNamePair = { id: '', name: '<< Create New Project Request >>' };
Expand All @@ -98,13 +98,8 @@ export class SpecificationSubmissionWizardComponent implements OnInit {
}

submitAttachToDataRequest() {
if (this.selectProjectForm.invalid || !this.selectProjectForm.controls.project.value) {
return;
}

const response: SubmissionWizardDialogResponse = {
requestId: undefined,
projectId: this.selectProjectForm.controls.project.value?.id,
requestId: this.selectDataRequestForm.controls.dataRequest.value?.id,
requestType: RequestType.Data,
};
this.dialogRef.close({ ...response });
Expand All @@ -113,7 +108,6 @@ export class SpecificationSubmissionWizardComponent implements OnInit {
submitAttachToNewProjectRequest() {
const response: SubmissionWizardDialogResponse = {
requestId: this.selectNewProjectRequestForm.controls.newProjectRequest.value?.id,
projectId: undefined,
requestType: RequestType.NewProject,
};
this.dialogRef.close({ ...response });
Expand All @@ -122,7 +116,6 @@ export class SpecificationSubmissionWizardComponent implements OnInit {
submitAttachToProjectChangeRequest() {
const response: SubmissionWizardDialogResponse = {
requestId: this.selectProjectChangeRequestForm.controls.projectChangeRequest.value?.id,
projectId: undefined,
requestType: RequestType.ProjectChange,
};
this.dialogRef.close({ ...response });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ import {
ExporterName,
ISubmissionState,
ISubmissionStep,
StepFunction,
StepName,
StepResult,
} from '../type-declarations/submission.resource';
import { AttachmentType } from '@maurodatamapper/sde-resources';
import { FileGenerationStepService } from '../services/fileGenerationStep.service';
import { BroadcastService } from 'src/app/core/broadcast.service';
import { ErrorService } from '../services/error.service';

@Injectable({
providedIn: 'root',
Expand Down
Loading

0 comments on commit 7112b8c

Please sign in to comment.