From db08662cac3df3112c9e4a55a0e92d4bf414687c Mon Sep 17 00:00:00 2001 From: Aldo Mihasi Date: Thu, 21 Sep 2023 09:33:27 +0300 Subject: [PATCH] fix bug when creating new version or clone a dmp --- .../main/java/eu/eudat/controllers/DMPs.java | 2 +- .../managers/DataManagementPlanManager.java | 15 ++++- .../DataManagementPlanNewVersionModel.java | 2 +- .../ui/dashboard/drafts/drafts.component.ts | 57 +++++++++++++++++++ .../recent-edited-activity.component.ts | 57 +++++++++++++++++++ .../recent-edited-dmp-activity.component.ts | 57 +++++++++++++++++++ .../app/ui/dmp/clone/dmp-clone.component.ts | 56 ++++++++++++++++++ .../dmp-editor-blueprint.component.ts | 6 +- .../dmp-listing-item.component.ts | 56 ++++++++++++++++++ .../ui/dmp/overview/dmp-overview.component.ts | 56 ++++++++++++++++++ .../app/ui/dmp/wizard/dmp-wizard.component.ts | 55 ++++++++++++++++++ 11 files changed, 413 insertions(+), 6 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java index a2a1926f6..2427314d6 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java @@ -260,7 +260,7 @@ public class DMPs extends BaseController { @RequestMapping(method = RequestMethod.POST, value = {"/clone/{id}"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> clone(@PathVariable UUID id, @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception { - UUID cloneId = this.dataManagementPlanManager.clone(dataManagementPlan, principal); + UUID cloneId = this.dataManagementPlanManager.clone(id, dataManagementPlan, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).payload(cloneId)); } 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 b447f83b6..390e9fe57 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 @@ -687,6 +687,9 @@ public class DataManagementPlanManager { if (latestVersionDMP.get(0).getVersion().equals(oldDmp.getVersion())) { DMP newDmp = dataManagementPlan.toDataModel(); + newDmp.setProfile(oldDmp.getProfile()); + newDmp.setProperties(oldDmp.getProperties()); + newDmp.setDmpProperties(oldDmp.getDmpProperties()); UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build(); newDmp.setCreator(user); if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.ORGANIZATIONS, principal)) { @@ -735,6 +738,9 @@ public class DataManagementPlanManager { } DMP tempDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp); newDmp.setId(tempDmp.getId()); + for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){ + apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().createOrUpdate(dmpDatasetProfile); + } // Assign creator. //assignUser(newDmp, user); @@ -764,8 +770,12 @@ public class DataManagementPlanManager { } } - public UUID clone(DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception { + public UUID clone(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception { + DMP oldDmp = databaseRepository.getDmpDao().find(uuid); DMP newDmp = dataManagementPlan.toDataModel(); + newDmp.setProfile(oldDmp.getProfile()); + newDmp.setProperties(oldDmp.getProperties()); + newDmp.setDmpProperties(oldDmp.getDmpProperties()); UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build(); newDmp.setCreator(user); @@ -809,6 +819,9 @@ public class DataManagementPlanManager { } DMP tempDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp); newDmp.setId(tempDmp.getId()); + for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){ + apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().createOrUpdate(dmpDatasetProfile); + } assignUser(newDmp, user); copyDatasets(newDmp, databaseRepository.getDatasetDao()); diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanNewVersionModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanNewVersionModel.java index ba4a80a05..9c93e28da 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanNewVersionModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanNewVersionModel.java @@ -259,7 +259,7 @@ public class DataManagementPlanNewVersionModel implements DataModel dmpDatasetProfiles = new HashSet<>(); for (AssociatedProfile profile : this.profiles) { DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile(); - dmpDatasetProfile.setId(profile.getId()); + dmpDatasetProfile.setId(null); dmpDatasetProfile.setDmp(entity); dmpDatasetProfile.setDatasetprofile(profile.toData()); dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData())); diff --git a/dmp-frontend/src/app/ui/dashboard/drafts/drafts.component.ts b/dmp-frontend/src/app/ui/dashboard/drafts/drafts.component.ts index 81f04cb48..dae5b3da9 100644 --- a/dmp-frontend/src/app/ui/dashboard/drafts/drafts.component.ts +++ b/dmp-frontend/src/app/ui/dashboard/drafts/drafts.component.ts @@ -42,6 +42,9 @@ import {ProjectFormModel} from "@app/ui/dmp/editor/grant-tab/project-form-model" import {FunderFormModel} from "@app/ui/dmp/editor/grant-tab/funder-form-model"; import {ExtraPropertiesFormModel} from "@app/ui/dmp/editor/general-tab/extra-properties-form.model"; import {CloneDialogComponent} from "@app/ui/dmp/clone/clone-dialog/clone-dialog.component"; +import { isNullOrUndefined } from '@app/utilities/enhancers/utils'; +import { DmpBlueprintDefinition, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint'; +import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service'; @Component({ selector: 'app-drafts', @@ -82,6 +85,7 @@ export class DraftsComponent extends BaseComponent implements OnInit { public enumUtils: EnumUtils, private authentication: AuthService, private dmpService: DmpService, + private dmpProfileService: DmpProfileService, private dashboardService: DashboardService, private language: TranslateService, private dialog: MatDialog, @@ -233,6 +237,17 @@ export class DraftsComponent extends BaseComponent implements OnInit { this.dmpModel.fromModel(data); this.dmpModel.status = DmpStatus.Draft; this.dmpFormGroup = this.dmpModel.buildForm(); + + if (!isNullOrUndefined(this.formGroup.get('profile').value)) { + this.dmpProfileService.getSingleBlueprint(this.formGroup.get('profile').value.id) + .pipe(takeUntil(this._destroyed)) + .subscribe(result => { + this.checkForGrant(result.definition); + this.checkForFunder(result.definition); + this.checkForProject(result.definition); + }); + } + if (!isNewVersion) { this.dmpFormGroup.get('label').setValue(dmp.title + " New"); } @@ -240,6 +255,48 @@ export class DraftsComponent extends BaseComponent implements OnInit { }); } + private checkForGrant(blueprint: DmpBlueprintDefinition) { + let hasGrant = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) { + hasGrant = true; + } + } + )); + if (!hasGrant) { + this.formGroup.removeControl('grant'); + } + } + + private checkForFunder(blueprint: DmpBlueprintDefinition) { + let hasFunder = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) { + hasFunder = true; + } + } + )); + if (!hasFunder) { + this.formGroup.removeControl('funder'); + } + } + + private checkForProject(blueprint: DmpBlueprintDefinition) { + let hasProject = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) { + hasProject = true; + } + } + )); + if (!hasProject) { + this.formGroup.removeControl('project'); + } + } + openCloneDialog(isNewVersion: boolean) { const dialogRef = this.dialog.open(CloneDialogComponent, { maxWidth: '700px', diff --git a/dmp-frontend/src/app/ui/dashboard/recent-edited-activity/recent-edited-activity.component.ts b/dmp-frontend/src/app/ui/dashboard/recent-edited-activity/recent-edited-activity.component.ts index 0c9e41e52..3213b5af6 100644 --- a/dmp-frontend/src/app/ui/dashboard/recent-edited-activity/recent-edited-activity.component.ts +++ b/dmp-frontend/src/app/ui/dashboard/recent-edited-activity/recent-edited-activity.component.ts @@ -42,6 +42,9 @@ import { DmpModel } from '@app/core/model/dmp/dmp'; import { CloneDialogComponent } from '@app/ui/dmp/clone/clone-dialog/clone-dialog.component'; import { MatomoService } from '@app/core/services/matomo/matomo-service'; import { HttpClient } from '@angular/common/http'; +import { isNullOrUndefined } from '@app/utilities/enhancers/utils'; +import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service'; +import { DmpBlueprintDefinition, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint'; @Component({ selector: 'app-recent-edited-activity', @@ -82,6 +85,7 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn public enumUtils: EnumUtils, private authentication: AuthService, private dmpService: DmpService, + private dmpProfileService: DmpProfileService, private dashboardService: DashboardService, private language: TranslateService, private dialog: MatDialog, @@ -299,6 +303,17 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn this.dmpModel.fromModel(data); this.dmpModel.status = DmpStatus.Draft; this.dmpFormGroup = this.dmpModel.buildForm(); + + if (!isNullOrUndefined(this.formGroup.get('profile').value)) { + this.dmpProfileService.getSingleBlueprint(this.formGroup.get('profile').value.id) + .pipe(takeUntil(this._destroyed)) + .subscribe(result => { + this.checkForGrant(result.definition); + this.checkForFunder(result.definition); + this.checkForProject(result.definition); + }); + } + if (!isNewVersion) { this.dmpFormGroup.get('label').setValue(dmp.title + " New"); } @@ -306,6 +321,48 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn }); } + private checkForGrant(blueprint: DmpBlueprintDefinition) { + let hasGrant = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) { + hasGrant = true; + } + } + )); + if (!hasGrant) { + this.formGroup.removeControl('grant'); + } + } + + private checkForFunder(blueprint: DmpBlueprintDefinition) { + let hasFunder = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) { + hasFunder = true; + } + } + )); + if (!hasFunder) { + this.formGroup.removeControl('funder'); + } + } + + private checkForProject(blueprint: DmpBlueprintDefinition) { + let hasProject = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) { + hasProject = true; + } + } + )); + if (!hasProject) { + this.formGroup.removeControl('project'); + } + } + openCloneDialog(isNewVersion: boolean) { const dialogRef = this.dialog.open(CloneDialogComponent, { maxWidth: '700px', diff --git a/dmp-frontend/src/app/ui/dashboard/recent-edited-dmp-activity/recent-edited-dmp-activity.component.ts b/dmp-frontend/src/app/ui/dashboard/recent-edited-dmp-activity/recent-edited-dmp-activity.component.ts index 1e53f6b9a..925149b02 100644 --- a/dmp-frontend/src/app/ui/dashboard/recent-edited-dmp-activity/recent-edited-dmp-activity.component.ts +++ b/dmp-frontend/src/app/ui/dashboard/recent-edited-dmp-activity/recent-edited-dmp-activity.component.ts @@ -34,6 +34,9 @@ import { FunderFormModel } from '@app/ui/dmp/editor/grant-tab/funder-form-model' import { ProjectFormModel } from '@app/ui/dmp/editor/grant-tab/project-form-model'; import { MatomoService } from '@app/core/services/matomo/matomo-service'; import { HttpClient } from '@angular/common/http'; +import { isNullOrUndefined } from '@app/utilities/enhancers/utils'; +import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service'; +import { DmpBlueprintDefinition, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint'; @Component({ selector: 'app-recent-edited-dmp-activity', @@ -75,6 +78,7 @@ export class RecentEditedDmpActivityComponent extends BaseComponent implements O public enumUtils: EnumUtils, private authentication: AuthService, private dmpService: DmpService, + private dmpProfileService: DmpProfileService, private datasetService: DatasetService, private language: TranslateService, private dialog: MatDialog, @@ -252,6 +256,17 @@ export class RecentEditedDmpActivityComponent extends BaseComponent implements O this.dmpModel.fromModel(data); this.dmpModel.status = DmpStatus.Draft; this.dmpFormGroup = this.dmpModel.buildForm(); + + if (!isNullOrUndefined(this.formGroup.get('profile').value)) { + this.dmpProfileService.getSingleBlueprint(this.formGroup.get('profile').value.id) + .pipe(takeUntil(this._destroyed)) + .subscribe(result => { + this.checkForGrant(result.definition); + this.checkForFunder(result.definition); + this.checkForProject(result.definition); + }); + } + if (!isNewVersion) { this.dmpFormGroup.get('label').setValue(dmp.label + " New"); } @@ -259,6 +274,48 @@ export class RecentEditedDmpActivityComponent extends BaseComponent implements O }); } + private checkForGrant(blueprint: DmpBlueprintDefinition) { + let hasGrant = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) { + hasGrant = true; + } + } + )); + if (!hasGrant) { + this.formGroup.removeControl('grant'); + } + } + + private checkForFunder(blueprint: DmpBlueprintDefinition) { + let hasFunder = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) { + hasFunder = true; + } + } + )); + if (!hasFunder) { + this.formGroup.removeControl('funder'); + } + } + + private checkForProject(blueprint: DmpBlueprintDefinition) { + let hasProject = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) { + hasProject = true; + } + } + )); + if (!hasProject) { + this.formGroup.removeControl('project'); + } + } + openCloneDialog(isNewVersion: boolean) { const dialogRef = this.dialog.open(CloneDialogComponent, { maxWidth: '700px', diff --git a/dmp-frontend/src/app/ui/dmp/clone/dmp-clone.component.ts b/dmp-frontend/src/app/ui/dmp/clone/dmp-clone.component.ts index 20681c99e..6c84540a7 100644 --- a/dmp-frontend/src/app/ui/dmp/clone/dmp-clone.component.ts +++ b/dmp-frontend/src/app/ui/dmp/clone/dmp-clone.component.ts @@ -29,6 +29,9 @@ import { DmpEditorModel } from '../editor/dmp-editor.model'; import { DatasetWizardEditorModel } from '@app/ui/dataset/dataset-wizard/dataset-wizard-editor.model'; import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component'; import { MatDialog } from '@angular/material/dialog'; +import { isNullOrUndefined } from '@app/utilities/enhancers/utils'; +import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service'; +import { DmpBlueprintDefinition, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint'; @Component({ @@ -65,6 +68,7 @@ export class DmpCloneComponent extends BaseComponent implements OnInit { private router: Router, private language: TranslateService, private dmpService: DmpService, + private dmpProfileService: DmpProfileService, private authentication: AuthService, private uiNotificationService: UiNotificationService, private datasetService: DatasetService, @@ -90,6 +94,16 @@ export class DmpCloneComponent extends BaseComponent implements OnInit { this.dmp.status = DmpStatus.Draft; this.formGroup = this.dmp.buildForm(); + if (!isNullOrUndefined(this.formGroup.get('profile').value)) { + this.dmpProfileService.getSingleBlueprint(this.formGroup.get('profile').value.id) + .pipe(takeUntil(this._destroyed)) + .subscribe(result => { + this.checkForGrant(result.definition); + this.checkForFunder(result.definition); + this.checkForProject(result.definition); + }); + } + this.datasets = this.formGroup.get('datasets') as FormArray; this.parentDmpLabel = this.formGroup.get('label').value; @@ -128,6 +142,48 @@ export class DmpCloneComponent extends BaseComponent implements OnInit { } + private checkForGrant(blueprint: DmpBlueprintDefinition) { + let hasGrant = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) { + hasGrant = true; + } + } + )); + if (!hasGrant) { + this.formGroup.removeControl('grant'); + } + } + + private checkForFunder(blueprint: DmpBlueprintDefinition) { + let hasFunder = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) { + hasFunder = true; + } + } + )); + if (!hasFunder) { + this.formGroup.removeControl('funder'); + } + } + + private checkForProject(blueprint: DmpBlueprintDefinition) { + let hasProject = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) { + hasProject = true; + } + } + )); + if (!hasProject) { + this.formGroup.removeControl('project'); + } + } + public cancel(id: String): void { if (id != null) { this.router.navigate(['/plans/overview/' + id]); 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 1eea3c3a9..d4355e9e0 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 @@ -835,7 +835,7 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im let hasGrant = false; this.selectedDmpBlueprintDefinition.sections.forEach(section => section.fields.forEach( field => { - if (field.category === FieldCategory.SYSTEM && field.type === SystemFieldType.GRANT) { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) { hasGrant = true; } } @@ -849,7 +849,7 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im let hasFunder = false; this.selectedDmpBlueprintDefinition.sections.forEach(section => section.fields.forEach( field => { - if (field.category === FieldCategory.SYSTEM && field.type === SystemFieldType.FUNDER) { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) { hasFunder = true; } } @@ -863,7 +863,7 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im let hasProject = false; this.selectedDmpBlueprintDefinition.sections.forEach(section => section.fields.forEach( field => { - if (field.category === FieldCategory.SYSTEM && field.type === SystemFieldType.PROJECT) { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) { hasProject = true; } } diff --git a/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts b/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts index aa1830664..8332bb525 100644 --- a/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts +++ b/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts @@ -28,6 +28,9 @@ import { ExtraPropertiesFormModel } from '../../editor/general-tab/extra-propert import { GrantTabModel } from '../../editor/grant-tab/grant-tab-model'; import { MatomoService } from '@app/core/services/matomo/matomo-service'; import { HttpClient } from '@angular/common/http'; +import { isNullOrUndefined } from '@app/utilities/enhancers/utils'; +import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service'; +import { DmpBlueprintDefinition, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint'; @Component({ selector: 'app-dmp-listing-item-component', @@ -53,6 +56,7 @@ export class DmpListingItemComponent extends BaseComponent implements OnInit { private authentication: AuthService, public enumUtils: EnumUtils, private dmpService: DmpService, + private dmpProfileService: DmpProfileService, private language: TranslateService, private uiNotificationService: UiNotificationService, private lockService: LockService, @@ -173,6 +177,16 @@ export class DmpListingItemComponent extends BaseComponent implements OnInit { this.dmpModel.status = DmpStatus.Draft; this.dmpFormGroup = this.dmpModel.buildForm(); + if (!isNullOrUndefined(this.dmpFormGroup.get('profile').value)) { + this.dmpProfileService.getSingleBlueprint(this.dmpFormGroup.get('profile').value.id) + .pipe(takeUntil(this._destroyed)) + .subscribe(result => { + this.checkForGrant(result.definition); + this.checkForFunder(result.definition); + this.checkForProject(result.definition); + }); + } + if (!isNewVersion) { this.dmpFormGroup.get('label').setValue(dmp.label + " New"); } @@ -180,6 +194,48 @@ export class DmpListingItemComponent extends BaseComponent implements OnInit { }); } + private checkForGrant(blueprint: DmpBlueprintDefinition) { + let hasGrant = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) { + hasGrant = true; + } + } + )); + if (!hasGrant) { + this.dmpFormGroup.removeControl('grant'); + } + } + + private checkForFunder(blueprint: DmpBlueprintDefinition) { + let hasFunder = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) { + hasFunder = true; + } + } + )); + if (!hasFunder) { + this.dmpFormGroup.removeControl('funder'); + } + } + + private checkForProject(blueprint: DmpBlueprintDefinition) { + let hasProject = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) { + hasProject = true; + } + } + )); + if (!hasProject) { + this.dmpFormGroup.removeControl('project'); + } + } + openCloneDialog(isNewVersion: boolean) { const dialogRef = this.dialog.open(CloneDialogComponent, { maxWidth: '700px', diff --git a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts index d7978b1cb..9b14376ce 100644 --- a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts +++ b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts @@ -47,6 +47,8 @@ import {DepositRepositoriesService} from '@app/core/services/deposit-repositorie import {DepositConfigurationModel} from '@app/core/model/deposit/deposit-configuration'; import {DoiModel} from '@app/core/model/doi/doi'; import {isNullOrUndefined} from '@app/utilities/enhancers/utils'; +import { DmpBlueprintDefinition, FieldCategory, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint'; +import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service'; @Component({ selector: 'app-dmp-overview', @@ -81,6 +83,7 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { private route: ActivatedRoute, private router: Router, private dmpService: DmpService, + private dmpProfileService: DmpProfileService, private depositRepositoriesService: DepositRepositoriesService, private translate: TranslateService, private authentication: AuthService, @@ -207,6 +210,17 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { this.dmpModel.fromModel(data); this.dmpModel.status = DmpStatus.Draft; this.formGroup = this.dmpModel.buildForm(); + + if (!isNullOrUndefined(this.formGroup.get('profile').value)) { + this.dmpProfileService.getSingleBlueprint(this.formGroup.get('profile').value.id) + .pipe(takeUntil(this._destroyed)) + .subscribe(result => { + this.checkForGrant(result.definition); + this.checkForFunder(result.definition); + this.checkForProject(result.definition); + }); + } + if (!isNewVersion) { this.formGroup.get('label').setValue(this.dmp.label + " New"); } @@ -214,6 +228,48 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { }); } + private checkForGrant(blueprint: DmpBlueprintDefinition) { + let hasGrant = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) { + hasGrant = true; + } + } + )); + if (!hasGrant) { + this.formGroup.removeControl('grant'); + } + } + + private checkForFunder(blueprint: DmpBlueprintDefinition) { + let hasFunder = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) { + hasFunder = true; + } + } + )); + if (!hasFunder) { + this.formGroup.removeControl('funder'); + } + } + + private checkForProject(blueprint: DmpBlueprintDefinition) { + let hasProject = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) { + hasProject = true; + } + } + )); + if (!hasProject) { + this.formGroup.removeControl('project'); + } + } + openCloneDialog(isNewVersion: boolean) { const dialogRef = this.dialog.open(CloneDialogComponent, { maxWidth: '900px', diff --git a/dmp-frontend/src/app/ui/dmp/wizard/dmp-wizard.component.ts b/dmp-frontend/src/app/ui/dmp/wizard/dmp-wizard.component.ts index b25b10731..23b8833d1 100644 --- a/dmp-frontend/src/app/ui/dmp/wizard/dmp-wizard.component.ts +++ b/dmp-frontend/src/app/ui/dmp/wizard/dmp-wizard.component.ts @@ -5,6 +5,8 @@ import { FormGroup } from '@angular/forms'; import { MatSnackBar } from '@angular/material/snack-bar'; import { ActivatedRoute, Params, Router } from '@angular/router'; import { DmpModel } from '@app/core/model/dmp/dmp'; +import { DmpBlueprintDefinition, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint'; +import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service'; import { DmpService } from '@app/core/services/dmp/dmp.service'; import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; import { FunderFormModel } from '@app/ui/dmp/editor/grant-tab/funder-form-model'; @@ -13,6 +15,7 @@ import { ProjectFormModel } from '@app/ui/dmp/editor/grant-tab/project-form-mode import { DmpWizardEditorModel } from '@app/ui/dmp/wizard/dmp-wizard-editor.model'; import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item'; import { IBreadCrumbComponent } from '@app/ui/misc/breadcrumb/definition/IBreadCrumbComponent'; +import { isNullOrUndefined } from '@app/utilities/enhancers/utils'; import { BaseComponent } from '@common/base/base.component'; import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; import { TranslateService } from '@ngx-translate/core'; @@ -35,6 +38,7 @@ export class DmpWizardComponent extends BaseComponent implements OnInit, IBreadC constructor( private dmpService: DmpService, + private dmpProfileService: DmpProfileService, private language: TranslateService, private snackBar: MatSnackBar, private route: ActivatedRoute, @@ -58,6 +62,16 @@ export class DmpWizardComponent extends BaseComponent implements OnInit, IBreadC this.dmp.fromModel(data); this.formGroup = this.dmp.buildForm(); + if (!isNullOrUndefined(this.formGroup.get('profile').value)) { + this.dmpProfileService.getSingleBlueprint(this.formGroup.get('profile').value.id) + .pipe(takeUntil(this._destroyed)) + .subscribe(result => { + this.checkForGrant(result.definition); + this.checkForFunder(result.definition); + this.checkForProject(result.definition); + }); + } + if (this.route.routeConfig.path.startsWith('new_version/')) { this.formGroup.get('version').setValue(this.formGroup.get('version').value + 1); this.formGroup.controls['label'].disable(); @@ -75,6 +89,47 @@ export class DmpWizardComponent extends BaseComponent implements OnInit, IBreadC }); } + private checkForGrant(blueprint: DmpBlueprintDefinition) { + let hasGrant = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) { + hasGrant = true; + } + } + )); + if (!hasGrant) { + this.formGroup.removeControl('grant'); + } + } + + private checkForFunder(blueprint: DmpBlueprintDefinition) { + let hasFunder = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) { + hasFunder = true; + } + } + )); + if (!hasFunder) { + this.formGroup.removeControl('funder'); + } + } + + private checkForProject(blueprint: DmpBlueprintDefinition) { + let hasProject = false; + blueprint.sections.forEach(section => section.fields.forEach( + field => { + if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) { + hasProject = true; + } + } + )); + if (!hasProject) { + this.formGroup.removeControl('project'); + } + } submit() { this.saving = true;