diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java index 819fefa91..f2d4037ea 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java @@ -528,7 +528,7 @@ public class DataManagementPlanManager { } if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.GRANT, principal)) { - if (newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { + if (newDmp.getGrant() != null && newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { checkIfUserCanEditGrant(newDmp, user); } assignGrandUserIfInternal(newDmp, user); @@ -547,7 +547,9 @@ public class DataManagementPlanManager { } if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.GRANT, principal)) { - apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant()); + if (newDmp.getGrant() != null) { + apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant()); + } } newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp); @@ -717,7 +719,7 @@ public class DataManagementPlanManager { newDmp.setId(null); if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.GRANT, principal)) { - if (newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { + if (newDmp.getGrant() != null && newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { checkIfUserCanEditGrant(newDmp, user); } assignGrandUserIfInternal(newDmp, user); @@ -729,13 +731,15 @@ public class DataManagementPlanManager { assignProjectUserIfInternal(newDmp, user); } if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.GRANT, principal)) { - if (newDmp.getGrant().getStartdate() == null) { - newDmp.getGrant().setStartdate(new Date()); + if (newDmp.getGrant() != null) { + if (newDmp.getGrant().getStartdate() == null) { + newDmp.getGrant().setStartdate(new Date()); + } + if (newDmp.getGrant().getEnddate() == null) { + newDmp.getGrant().setEnddate(Date.from(Instant.now().plus(365, ChronoUnit.DAYS))); + } + databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant()); } - if (newDmp.getGrant().getEnddate() == null) { - newDmp.getGrant().setEnddate(Date.from(Instant.now().plus(365, ChronoUnit.DAYS))); - } - databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant()); } DMP tempDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp); newDmp.setId(tempDmp.getId()); @@ -804,7 +808,7 @@ public class DataManagementPlanManager { newDmp.setId(null); if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.GRANT, principal)) { - if (newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { + if (newDmp.getGrant() != null && newDmp.getGrant().getType().equals(Grant.GrantType.INTERNAL.getValue())) { checkIfUserCanEditGrant(newDmp, user); } assignGrandUserIfInternal(newDmp, user); @@ -816,7 +820,9 @@ public class DataManagementPlanManager { assignProjectUserIfInternal(newDmp, user); } if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.GRANT, principal)) { - databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant()); + if (newDmp.getGrant() != null) { + databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant()); + } } DMP tempDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp); newDmp.setId(tempDmp.getId()); @@ -2306,19 +2312,19 @@ public class DataManagementPlanManager { } private void assignGrandUserIfInternal(DMP dmp, UserInfo user) { - if (dmp.getGrant().getCreationUser() == null && (dmp.getGrant().getReference() != null && dmp.getGrant().getReference().startsWith("dmp:"))) { + if (dmp.getGrant() != null && dmp.getGrant().getCreationUser() == null && (dmp.getGrant().getReference() != null && dmp.getGrant().getReference().startsWith("dmp:"))) { dmp.getGrant().setCreationUser(user); } } private void assignFunderUserIfInternal(DMP dmp, UserInfo user) { - if (dmp.getGrant().getFunder().getCreationUser() == null && ( dmp.getGrant().getFunder().getReference() != null && dmp.getGrant().getFunder().getReference().startsWith("dmp:"))) { + if (dmp.getGrant() != null && dmp.getGrant().getFunder() != null && dmp.getGrant().getFunder().getCreationUser() == null && ( dmp.getGrant().getFunder().getReference() != null && dmp.getGrant().getFunder().getReference().startsWith("dmp:"))) { dmp.getGrant().getFunder().setCreationUser(user); } } private void assignProjectUserIfInternal(DMP dmp, UserInfo user) { - if (dmp.getProject().getCreationUser() == null && (dmp.getProject().getReference() != null && dmp.getProject().getReference().startsWith("dmp:"))) { + if (dmp.getProject() != null && dmp.getProject().getCreationUser() == null && (dmp.getProject().getReference() != null && dmp.getProject().getReference().startsWith("dmp:"))) { dmp.getProject().setCreationUser(user); } } @@ -2398,7 +2404,7 @@ public class DataManagementPlanManager { * */ private void checkIfUserCanEditGrant(DMP dmp, UserInfo user) throws Exception{ - if (dmp.getGrant().getId() != null) { + if (dmp.getGrant() != null && dmp.getGrant().getId() != null) { Grant grant = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().find(dmp.getGrant().getId()); if (grant.getFunder() != null && dmp.getGrant().getFunder() != null && !grant.getFunder().getId().equals(dmp.getGrant().getFunder().getId())) { diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/AssociatedProfileImportModels.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/AssociatedProfileImportModels.java index d68a4e391..89f7c833d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/AssociatedProfileImportModels.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/AssociatedProfileImportModels.java @@ -16,7 +16,7 @@ public class AssociatedProfileImportModels { public UUID getId() { return id; } public void setId(UUID id) { this.id = id; } - @XmlElement(name = "profilelabel") + @XmlElement(name = "profileLabel") public String getLabel() { return label; } public void setLabel(String label) { this.label = label; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanEditorModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanEditorModel.java index fa1862322..c23ad1f14 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanEditorModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanEditorModel.java @@ -302,7 +302,7 @@ public class DataManagementPlanEditorModel implements DataModel { + section.get('ordinal').setValue(index + 1); + }); } fieldsArray(sectionIndex: number): FormArray { diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts index 3199b526c..f8a91057a 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts @@ -199,6 +199,7 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme this.lockService.checkLockStatus(data.id).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => { this.lockStatus = lockStatus; this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data); + this.dmpSectionIndex = this.datasetWizardModel.dmpSectionIndex; this.needsUpdate(); this.breadCrumbs = observableOf([ { @@ -337,6 +338,7 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme this.lockService.checkLockStatus(data.id).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => { this.lockStatus = lockStatus; this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data); + this.dmpSectionIndex = this.datasetWizardModel.dmpSectionIndex; this.datasetWizardModel.status = 0; this.formGroup = this.datasetWizardModel.buildForm(); this.formGroup.get('id').setValue(null); diff --git a/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor-blueprint.component.ts b/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor-blueprint.component.ts index 6ae617058..0da9ee5a8 100644 --- a/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor-blueprint.component.ts +++ b/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor-blueprint.component.ts @@ -56,6 +56,7 @@ import { PopupNotificationDialogComponent } from '@app/library/notification/popu import { GrantEditorModel } from '@app/ui/grant/editor/grant-editor.model'; import { CheckDeactivateBaseComponent } from '@app/library/deactivate/deactivate.component'; import { DmpProfileStatus } from '@app/core/common/enum/dmp-profile-status'; +import { DatasetService } from '@app/core/services/dataset/dataset.service'; interface Visible { value: boolean; @@ -132,6 +133,7 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im constructor( private dmpProfileService: DmpProfileService, + private datasetService: DatasetService, private authService: AuthService, private route: ActivatedRoute, private router: Router, @@ -658,6 +660,44 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im } + public removeDataset(datasetId: string, index: number) { + const dialogRef = this.dialog.open(ConfirmationDialogComponent, { + maxWidth: '300px', + restoreFocus: false, + data: { + message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'), + confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.DELETE'), + cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'), + isDeleteConfirmation: true + } + }); + dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => { + if (result) { + if (datasetId) { + this.datasetService.delete(datasetId) + .pipe(takeUntil(this._destroyed)) + .subscribe( + complete => { + this.onDeleteCallbackSuccess(); + }, + error => this.onDeleteCallbackError(error) + ); + } + this.formGroup.get('datasets')['controls'].splice(index, 1); + this.step = 0; + } + }); + } + + onDeleteCallbackSuccess(): void { + this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-DELETE'), SnackBarNotificationLevel.Success); + this.dmp.id != null ? this.router.navigate(['/reload']).then(() => this.router.navigate(['/plans', 'edit', this.dmp.id])) : this.router.navigate(['/plans']); + } + + onDeleteCallbackError(error) { + this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error); + } + //checks if the dpm is valid not taking into account the datasets validity private _isDMPDescriptionValid():boolean{ @@ -933,6 +973,7 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im let fields: Array = new Array(); var request = new DataTableRequest(0, 20, { fields: fields }); request.criteria = new DmpBlueprintCriteria(); + request.criteria.like = query; request.criteria.status = DmpProfileStatus.Finalized; return this.dmpProfileService.getPagedBlueprint(request).pipe(map(x => x.data)); }