min multiplicity check for descriptions in dmp finalization

This commit is contained in:
Bernaldo Mihasi 2023-09-22 11:10:08 +03:00
parent 0c9601d6f0
commit 56a70636c3
1 changed files with 52 additions and 50 deletions

View File

@ -608,33 +608,34 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
}); });
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe((result: DmpFinalizeDialogOutput) => { dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe((result: DmpFinalizeDialogOutput) => {
if (result && !result.cancelled) { if (result && !result.cancelled) {
if(!this.checkIfAnyProfileIsUsedLessThanMin(data)) { this.checkIfAnyProfileIsUsedLessThanMin(data).subscribe(checked => {
if (!checked) {
var datasetsToBeFinalized: DatasetsToBeFinalized = { var datasetsToBeFinalized: DatasetsToBeFinalized = {
uuids: result.datasetsToBeFinalized uuids: result.datasetsToBeFinalized
}; };
this.dmpService.finalize(datasetsToBeFinalized, this.dmp.id) this.dmpService.finalize(datasetsToBeFinalized, this.dmp.id)
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe( .subscribe(
complete => { complete => {
if(extraProperties.visible){ if(extraProperties.visible){
//this.publish(this.dmp.id); //this.publish(this.dmp.id);
this.dmpService.publish(this.dmp.id) this.dmpService.publish(this.dmp.id)
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(() => { .subscribe(() => {
//this.hasPublishButton = false; //this.hasPublishButton = false;
this.dmp.status = DmpStatus.Finalized;
this.onUpdateCallbackSuccess();
});
}
else{
this.dmp.status = DmpStatus.Finalized; this.dmp.status = DmpStatus.Finalized;
this.onUpdateCallbackSuccess(); this.onUpdateCallbackSuccess();
}); }
} },
else{ error => this.onUpdateCallbackError(error)
this.dmp.status = DmpStatus.Finalized; );
this.onUpdateCallbackSuccess(); }
} })
},
error => this.onUpdateCallbackError(error)
);
}
} }
}); });
@ -642,35 +643,36 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
} }
private checkIfAnyProfileIsUsedLessThanMin(dmpModel: DmpModel): boolean { private checkIfAnyProfileIsUsedLessThanMin(dmpModel: DmpModel): Observable<boolean> {
const blueprintId = dmpModel.profile.id; const blueprintId = dmpModel.profile.id;
this.dmpProfileService.getSingleBlueprint(blueprintId) return this.dmpProfileService.getSingleBlueprint(blueprintId)
.pipe(takeUntil(this._destroyed)) .pipe(map(result => {
.subscribe(result => { return result.definition.sections.some(section => {
result.definition.sections.forEach(section => { if(!section.hasTemplates)
if(section.hasTemplates){ return false;
section.descriptionTemplates.forEach(template => { return section.descriptionTemplates.some(template => {
if(template.minMultiplicity > 0) { if(!(template.minMultiplicity > 0))
let count = 0; return false;
dmpModel.datasets.filter(dataset => dataset.dmpSectionIndex === (section.ordinal - 1)).forEach(dataset => { let count = 0;
if(dataset.profile.id === template.descriptionTemplateId){ dmpModel.datasets.filter(dataset => dataset.dmpSectionIndex === (section.ordinal - 1)).forEach(dataset => {
count++; if(dataset.profile.id === template.descriptionTemplateId){
} count++;
})
if(count < template.minMultiplicity){
this.dialog.open(PopupNotificationDialogComponent, {
data: {
title: 'Min(' + template.minMultiplicity + ') datasets needed using this template.',
message: 'Add dataset.'
}, maxWidth: '30em'
});
}
} }
}) })
} if(count < template.minMultiplicity){
this.dialog.open(PopupNotificationDialogComponent, {
data: {
title: 'Min(' + template.minMultiplicity + ') datasets needed using this template.',
message: 'Add dataset.'
}, maxWidth: '30em'
});
return true;
}
else
return false;
})
}) })
}); }), takeUntil(this._destroyed));
return true;
} }
// newVersion(id: String, label: String) { // newVersion(id: String, label: String) {