Skip to content

Commit

Permalink
[VAS] Bug 11702: pastis 500 on check and show id (#1438)
Browse files Browse the repository at this point in the history
  • Loading branch information
laedanrex authored Aug 23, 2023
1 parent 7117de0 commit 9675924
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ public ResponseEntity<JsonNode> importArchivalProfiles(@RequestParam("fileName")
public ResponseEntity<Void> check(@RequestBody ProfileDto profileDto,
@RequestHeader(value = CommonConstants.X_TENANT_ID_HEADER) Integer tenant)
throws InvalidParseOperationException, PreconditionFailedException {
ApiUtils.checkValidity(profileDto);
SanityChecker.sanitizeCriteria(profileDto);
final boolean exist = profileExternalService.check(profileDto);
LOGGER.debug("check exist accessContract={}", profileDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ knowledge of the CeCILL-C license and that you accept its terms.
*/
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { ApplicationService } from 'ui-frontend-common';

@Injectable({
providedIn: 'root'
Expand All @@ -47,24 +48,36 @@ export class PopupService {
popUpDataAfterOpen = new BehaviorSubject<any>(null);
btnYesShoudBeDisabled = new BehaviorSubject<boolean>(false);

externalIdentifierEnabled: boolean;

constructor() { }
constructor(private applicationService: ApplicationService,) {
this.updateSlaveMode()
}

private updateSlaveMode() {
this.applicationService.isApplicationExternalIdentifierEnabled('PASTIS').subscribe((value) => {
this.externalIdentifierEnabled = value;
});
}

getPopUpDataOnOpen() {
return this.popUpDataAfterOpen.getValue();
}

getPopUpDataOnClose() {
return this.popUpDataBeforeClose;
}

setPopUpDataOnOpen(incomingData: any) {
this.popUpDataAfterOpen.next(incomingData);
}

setPopUpDataOnClose(incomingData: any) {
this.popUpDataBeforeClose.next(incomingData);
}

disableYesButton(condition: boolean) {
condition ? this.btnYesShoudBeDisabled.next(true) : this.btnYesShoudBeDisabled.next(false);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import { Subscription } from 'rxjs';
import { NoticeService } from '../../core/services/notice.service';
import { NotificationService } from '../../core/services/notification.service';
import { ProfileService } from '../../core/services/profile.service';
import { ArchivalProfileUnit } from '../../models/archival-profile-unit';
import { FileNode } from '../../models/file-node';
import { Profile } from '../../models/profile';
import { ProfileDescription } from '../../models/profile-description.model';
import { CreateNoticeChoiceComponent } from '../../profile/create-notice-choice/create-notice-choice.component';
import { CreateNoticeComponent } from '../../user-actions/create-notice/create-notice.component';
import { PastisDialogDataCreate } from '../../user-actions/save-profile/save-profile.component';
Expand Down Expand Up @@ -42,7 +40,7 @@ function constantToTranslate(edit: boolean) {
@Component({
selector: 'pastis-popup-option',
templateUrl: './pastis-popup-option.component.html',
styleUrls: [ './pastis-popup-option.component.scss' ]
styleUrls: ['./pastis-popup-option.component.scss']
})
export class PastisPopupOptionComponent implements OnInit, OnDestroy {

Expand All @@ -57,25 +55,17 @@ export class PastisPopupOptionComponent implements OnInit, OnDestroy {
popupSaveCreateNoticeOkLabel: string;
editProfile: boolean;

subscription1$: Subscription;
subscription2$: Subscription;
uploadProfileSub: Subscription;
subscriptions: Subscription[] = [];
subscriptions: Subscription = new Subscription();

isStandalone: boolean = environment.standalone;
popupCreationCancelLabel: string;
popupCreationTitleDialog: string;
popupCreationSubTitleDialog: string;
popupCreationOkLabel: string;

donnees: string[];

data: FileNode[] = [];

archivalProfileUnit: ArchivalProfileUnit;
profile: Profile;

profileDescription: ProfileDescription;

@Input()
sedaUrl: string;
@Input()
Expand All @@ -85,11 +75,14 @@ export class PastisPopupOptionComponent implements OnInit, OnDestroy {

expanded = false;


constructor(private router: Router, private profileService: ProfileService,
public dialog: MatDialog, private noticeService: NoticeService,
private translateService: TranslateService, private loaderService: NgxUiLoaderService,
private notificationService: NotificationService, private route: ActivatedRoute) {
constructor(private router: Router,
public dialog: MatDialog,
private profileService: ProfileService,
private noticeService: NoticeService,
private translateService: TranslateService,
private loaderService: NgxUiLoaderService,
private notificationService: NotificationService,
private route: ActivatedRoute) {
}

ngOnInit(): void {
Expand All @@ -101,7 +94,6 @@ export class PastisPopupOptionComponent implements OnInit, OnDestroy {
this.translateService.onLangChange
.subscribe((_: LangChangeEvent) => {
constantToTranslate.call(this);
// console.log(event.lang);
});
}

Expand All @@ -120,10 +112,9 @@ export class PastisPopupOptionComponent implements OnInit, OnDestroy {
if (fileToUpload) {
const formData = new FormData();
formData.append('file', fileToUpload, fileToUpload.name);
this.uploadProfileSub = this.profileService.uploadProfile(formData).subscribe((response: any) => {
this.profileService.uploadProfile(formData).subscribe((response: any) => {
if (response) {
// console.log('File submited! Reponse is : ', response);
this.router.navigate([ this.newProfileUrl ], { state: response, relativeTo: this.route });
this.router.navigate([this.newProfileUrl], { state: response, relativeTo: this.route });
}
});
}
Expand All @@ -135,55 +126,49 @@ export class PastisPopupOptionComponent implements OnInit, OnDestroy {

async createNotice() {
this.loaderService.start();
const dataToSendToPopUp = {} as PastisDialogData;
dataToSendToPopUp.titleDialog = this.popupCreationTitleDialog;
dataToSendToPopUp.subTitleDialog = this.popupCreationSubTitleDialog;
dataToSendToPopUp.width = '800px';
dataToSendToPopUp.height = '800px';
dataToSendToPopUp.okLabel = this.popupCreationOkLabel;
dataToSendToPopUp.cancelLabel = this.popupCreationCancelLabel;
const dialogRef = this.dialog.open(CreateNoticeChoiceComponent, {
const createNoticeChoiceData = {} as PastisDialogData;
createNoticeChoiceData.titleDialog = this.popupCreationTitleDialog;
createNoticeChoiceData.subTitleDialog = this.popupCreationSubTitleDialog;
createNoticeChoiceData.width = '800px';
createNoticeChoiceData.height = '800px';
createNoticeChoiceData.okLabel = this.popupCreationOkLabel;
createNoticeChoiceData.cancelLabel = this.popupCreationCancelLabel;
const createNoticeChoiceDialogRef = this.dialog.open(CreateNoticeChoiceComponent, {
width: '800px',
panelClass: 'pastis-popup-modal-box',
data: dataToSendToPopUp
data: createNoticeChoiceData
}
);
this.subscription2$ = dialogRef.afterClosed().subscribe((result) => {
const subscription1 = createNoticeChoiceDialogRef.afterClosed().subscribe((result) => {
if (result.success) {
// console.log(result.action + ' PA ou PUA ?');
if (result.action === 'PA' || result.action === 'PUA') {
const dataToSendToPopUp = {} as PastisDialogDataCreate;
dataToSendToPopUp.titleDialog = this.popupSaveCreateNoticeTitleDialog;
dataToSendToPopUp.subTitleDialog = this.popupSaveCreateNoticeSubTitleDialog;
dataToSendToPopUp.okLabel = this.popupSaveCreateNoticeOkLabel;
dataToSendToPopUp.cancelLabel = this.popupSaveCreateNoticeCancelLabel;
dataToSendToPopUp.modeProfile = result.action;
const dialogRef = this.dialog.open(CreateNoticeComponent, {
const createNoticeData = {} as PastisDialogDataCreate;
createNoticeData.titleDialog = this.popupSaveCreateNoticeTitleDialog;
createNoticeData.subTitleDialog = this.popupSaveCreateNoticeSubTitleDialog;
createNoticeData.okLabel = this.popupSaveCreateNoticeOkLabel;
createNoticeData.cancelLabel = this.popupSaveCreateNoticeCancelLabel;
createNoticeData.modeProfile = result.action;
const createNoticeDialogRef = this.dialog.open(CreateNoticeComponent, {
width: '800px',
panelClass: 'pastis-popup-modal-box',
data: dataToSendToPopUp
data: createNoticeData
}
);
dialogRef.afterClosed().subscribe((result) => {
const subscription2 = createNoticeDialogRef.afterClosed().subscribe((result) => {
let retour;
if (result.success) {
retour = result.data;
// console.log(retour.identifier + "identifier")
if (result.mode === 'PUA') {
// console.log('je suis sur un enregistrement d\'un PUA');
const profileDescription = this.noticeService.puaNotice(retour);
this.profileService.createArchivalUnitProfile(profileDescription).subscribe(() => {
this.changeExpand();
this.notificationService.showSuccess('La création de notice a bien été effectué');
this.profileService.refreshListProfiles();
// console.log('ok create');
});
} else if (result.mode === 'PA') {
// console.log(retour.identifier);
const profile: Profile = this.noticeService.paNotice(retour, true);
// STEP 1 : Create Notice
this.profileService.createProfilePa(profile).subscribe(() => {
// console.log("ok create" + createdProfile)
this.changeExpand();
this.notificationService.showSuccess('La création de notice a bien été effectué');
this.profileService.refreshListProfiles();
Expand All @@ -192,17 +177,17 @@ export class PastisPopupOptionComponent implements OnInit, OnDestroy {
}
}
});

this.subscriptions.add(subscription2);
}
}
});
this.subscriptions.add(subscription1);
this.loaderService.stop();
this.subscriptions.push(this.subscription2$);
}

ngOnDestroy(): void {
if (this.uploadProfileSub) {
this.uploadProfileSub.unsubscribe();
}
this.subscriptions.unsubscribe();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h2 class="pastis-dialog-config-title" matDialogTitle>
<form class="pastis-form" [formGroup]="form" (ngSubmit)="onSubmit()">

<div class="row">
<div class="col-10 form-control">
<div class="col-10 form-control" *ngIf="externalIdentifierEnabled">
<vitamui-common-input [disabled]="editNotice" (change)="checkIdentifier(modePUA)" [(ngModel)]="notice.identifier" class="col-9 px-0"
placeholder="{{ 'PROFILE.POP_UP_CREATION_NOTICE.IDENTIFIER' | translate }}" formControlName="identifier">
</vitamui-common-input>
Expand Down Expand Up @@ -76,4 +76,3 @@ <h2 class="pastis-dialog-config-title" matDialogTitle>
</div>

</form>

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { LangChangeEvent, TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';
Expand Down Expand Up @@ -30,14 +30,13 @@ function constantToTranslate() {
@Component({
selector: 'create-notice',
templateUrl: './create-notice.component.html',
styleUrls: [ './create-notice.component.scss' ]
styleUrls: ['./create-notice.component.scss']
})
export class CreateNoticeComponent implements OnInit, OnDestroy {
form: FormGroup;
stepIndex = 0;
btnIsDisabled: boolean;
dialogData: PastisDialogData;
isDisabledButton = false;
notice: Notice;
// edit or new notice
editNotice: boolean;
Expand All @@ -58,25 +57,25 @@ export class CreateNoticeComponent implements OnInit, OnDestroy {
isStandalone: boolean = environment.standalone;

subscriptions = new Subscription();
externalIdentifierEnabled: boolean;

constructor(public dialogRef: MatDialogRef<CreateNoticeComponent>,
@Inject(MAT_DIALOG_DATA) public data: PastisDialogDataCreate,
private formBuilder: FormBuilder,
private translateService: TranslateService,
private popUpService: PopupService,
private popupService: PopupService,
private fileService: FileService,
private router: Router,
private profileService: ProfileService) {

}

ngOnInit() {

this.externalIdentifierEnabled = this.popupService.externalIdentifierEnabled
this.editNotice = this.router.url.substring(this.router.url.lastIndexOf('/') - 4, this.router.url.lastIndexOf('/')) === 'edit';
if (this.editNotice) {
this.validate = true;
// Subscribe observer to notice

this.subscriptions.add(
this.fileService.noticeEditable.subscribe((value: Notice) => {
this.notice = value;
Expand Down Expand Up @@ -107,10 +106,10 @@ export class CreateNoticeComponent implements OnInit, OnDestroy {
}
this.information = 'texte d\'information';
this.form = this.formBuilder.group({
identifier: [ null, Validators.required ],
intitule: [ null, Validators.required ],
selectedStatus: [ null ],
description: [ null ],
identifier: [null, Validators.required],
intitule: [null, Validators.required],
selectedStatus: [null],
description: [null],
autoriserPresenceMetadonnees: false
});

Expand All @@ -125,7 +124,7 @@ export class CreateNoticeComponent implements OnInit, OnDestroy {
// set the inital state of the ok button to disabled

this.subscriptions.add(
this.popUpService.btnYesShoudBeDisabled.subscribe(status => {
this.popupService.btnYesShoudBeDisabled.subscribe(status => {
this.btnIsDisabled = status;
}));
}
Expand All @@ -135,7 +134,6 @@ export class CreateNoticeComponent implements OnInit, OnDestroy {
this.translateService.onLangChange
.subscribe((_: LangChangeEvent) => {
constantToTranslate.call(this);
// console.log(event.lang);
}));
}

Expand All @@ -149,8 +147,8 @@ export class CreateNoticeComponent implements OnInit, OnDestroy {


upateButtonStatusAndDataToSend() {
this.popUpService.setPopUpDataOnClose('test');
this.popUpService.disableYesButton(true);
this.popupService.setPopUpDataOnClose('test');
this.popupService.disableYesButton(true);
}


Expand All @@ -164,7 +162,6 @@ export class CreateNoticeComponent implements OnInit, OnDestroy {
}

checkIdentifier(modePUA: boolean) {

if (this.notice.identifier.length < 1) {
this.validate = false;
return;
Expand Down Expand Up @@ -207,12 +204,12 @@ export class CreateNoticeComponent implements OnInit, OnDestroy {
}

onSubmit() {
if (!this.externalIdentifierEnabled) {
this.form.controls.identifier.setValue(this.form.controls.intitule.value);
}
if (this.form.invalid) {
this.isDisabledButton = true;
return;
}
this.isDisabledButton = true;
// console.log(this.form.value);
if (this.editNotice) {
this.fileService.noticeEditable.next(this.notice);
this.fileService.setNotice(true);
Expand Down
Loading

0 comments on commit 9675924

Please sign in to comment.