Fixes clone functionality not working on published DMPs.

This commit is contained in:
gkolokythas 2020-01-07 18:17:21 +02:00
parent 6eaff65ea8
commit fa22017d48
7 changed files with 50 additions and 28 deletions

View File

@ -95,7 +95,7 @@ public class DMPs extends BaseController {
if (contentType.equals("application/xml") || contentType.equals("application/msword")) { if (contentType.equals("application/xml") || contentType.equals("application/msword")) {
return this.dataManagementPlanManager.getDocument(id, contentType, principal, this.configLoader); return this.dataManagementPlanManager.getDocument(id, contentType, principal, this.configLoader);
} else { } else {
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal, this.dynamicGrantConfiguration); eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
} }
} }

View File

@ -339,30 +339,24 @@ public class DataManagementPlanManager {
return this.datasetManager.convertToPDF(file, environment, fileName); return this.datasetManager.convertToPDF(file, environment, fileName);
}*/ }*/
public eu.eudat.models.data.dmp.DataManagementPlan getSingle(String id, Principal principal, DynamicGrantConfiguration dynamicGrantConfiguration) throws InstantiationException, IllegalAccessException { public eu.eudat.models.data.dmp.DataManagementPlan getSingle(String id, Principal principal) {
DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (dataManagementPlanEntity.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0) if (dataManagementPlanEntity.getUsers().stream().noneMatch(userInfo -> userInfo.getUser().getId() == principal.getId())) {
if (!dataManagementPlanEntity.isPublic()) {
throw new UnauthorisedException(); throw new UnauthorisedException();
eu.eudat.models.data.dmp.DataManagementPlan datamanagementPlan = new eu.eudat.models.data.dmp.DataManagementPlan(); }
datamanagementPlan.fromDataModel(dataManagementPlanEntity); }
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = new eu.eudat.models.data.dmp.DataManagementPlan();
dataManagementPlan.fromDataModel(dataManagementPlanEntity);
Map dmpProperties = dataManagementPlanEntity.getDmpProperties() != null ? new org.json.JSONObject(dataManagementPlanEntity.getDmpProperties()).toMap() : null; Map dmpProperties = dataManagementPlanEntity.getDmpProperties() != null ? new org.json.JSONObject(dataManagementPlanEntity.getDmpProperties()).toMap() : null;
// datamanagementPlan.setDynamicFields(dynamicGrantConfiguration.getFields().stream().map(item -> {
// DynamicFieldWithValue fieldWithValue = new DynamicFieldWithValue();
// fieldWithValue.setId(item.getId());
// fieldWithValue.setDependencies(item.getDependencies());
// fieldWithValue.setName(item.getName());
// fieldWithValue.setQueryProperty(item.getQueryProperty());
// fieldWithValue.setRequired(item.getRequired());
// return fieldWithValue;
// }).collect(Collectors.toList()));
if (dmpProperties != null && datamanagementPlan.getDynamicFields() != null) if (dmpProperties != null && dataManagementPlan.getDynamicFields() != null)
datamanagementPlan.getDynamicFields().forEach(item -> { dataManagementPlan.getDynamicFields().forEach(item -> {
Map<String, String> properties = (Map<String, String>) dmpProperties.get(item.getId()); Map<String, String> properties = (Map<String, String>) dmpProperties.get(item.getId());
if (properties != null) if (properties != null)
item.setValue(new Tuple<>(properties.get("id"), properties.get("label"))); item.setValue(new Tuple<>(properties.get("id"), properties.get("label")));
}); });
return datamanagementPlan; return dataManagementPlan;
} }
public DataManagementPlanOverviewModel getOverviewSingle(String id, Principal principal) throws InstantiationException, IllegalAccessException { public DataManagementPlanOverviewModel getOverviewSingle(String id, Principal principal) throws InstantiationException, IllegalAccessException {

View File

@ -19,14 +19,14 @@
<i class="material-icons-outlined mr-2">view_agenda</i> <i class="material-icons-outlined mr-2">view_agenda</i>
{{ 'SIDE-BAR.GENERAL' | translate }} {{ 'SIDE-BAR.GENERAL' | translate }}
</ng-template> </ng-template>
<app-general-tab [formGroup]="formGroup" [isNewVersion]="isNewVersion"></app-general-tab> <app-general-tab [formGroup]="formGroup" [isNewVersion]="isNewVersion" [isClone]="isClone"></app-general-tab>
</mat-tab> </mat-tab>
<mat-tab> <mat-tab>
<ng-template mat-tab-label> <ng-template mat-tab-label>
<mat-icon class="mr-2">work_outline</mat-icon> <mat-icon class="mr-2">work_outline</mat-icon>
{{ 'DMP-LISTING.COLUMNS.GRANT' | translate }} {{ 'DMP-LISTING.COLUMNS.GRANT' | translate }}
</ng-template> </ng-template>
<app-grant-tab [grantformGroup]="formGroup.get('grant')" [projectFormGroup]="formGroup.get('project')" [funderFormGroup]="formGroup.get('funder')" [isFinalized]="isFinalized" [isNewVersion]="isNewVersion"></app-grant-tab> <app-grant-tab [grantformGroup]="formGroup.get('grant')" [projectFormGroup]="formGroup.get('project')" [funderFormGroup]="formGroup.get('funder')" [isFinalized]="isFinalized" [isNewVersion]="isNewVersion" [isClone]="isClone" [isNew]="isNew"></app-grant-tab>
</mat-tab> </mat-tab>
<mat-tab> <mat-tab>
<ng-template mat-tab-label> <ng-template mat-tab-label>

View File

@ -35,6 +35,8 @@ export class DmpCloneComponent extends BaseComponent implements OnInit {
selectedTab = 0; selectedTab = 0;
parentDmpLabel: string; parentDmpLabel: string;
isNewVersion: boolean = false; isNewVersion: boolean = false;
isClone: boolean = true;
isNew: boolean = false;
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,

View File

@ -31,6 +31,7 @@ export class GeneralTabComponent extends BaseComponent implements OnInit {
@Input() formGroup: FormGroup = null; @Input() formGroup: FormGroup = null;
@Input() isNewVersion: boolean; @Input() isNewVersion: boolean;
@Input() isUserOwner: boolean; @Input() isUserOwner: boolean;
@Input() isClone: boolean;
profilesAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = { profilesAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = {
filterFn: this.filterProfiles.bind(this), filterFn: this.filterProfiles.bind(this),
@ -82,7 +83,7 @@ export class GeneralTabComponent extends BaseComponent implements OnInit {
this.formGroup.get('label').disable(); this.formGroup.get('label').disable();
} }
if (!this.isUserOwner) { if (!this.isUserOwner && !this.isClone) {
this.formGroup.disable(); this.formGroup.disable();
} }
} }

View File

@ -24,7 +24,7 @@
<!-- Toggle Between Add Funder or Use Existing --> <!-- Toggle Between Add Funder or Use Existing -->
<div class="col d-flex"> <div class="col d-flex">
<div class="row" *ngIf="!isFinalized && isUserOwner"> <div class="row" *ngIf="showToggleButton()">
<div class="col-12 add-entity" *ngIf="isCreateNewFunder" (click)="createFunder()"> <div class="col-12 add-entity" *ngIf="isCreateNewFunder" (click)="createFunder()">
<mat-icon>settings_backup_restore</mat-icon> <mat-icon>settings_backup_restore</mat-icon>
<span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-FUNDER' | translate}}</span> <span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-FUNDER' | translate}}</span>
@ -63,7 +63,7 @@
<!-- Toggle Between Add Grant or Use Existing --> <!-- Toggle Between Add Grant or Use Existing -->
<div class="col d-flex"> <div class="col d-flex">
<div class="row" *ngIf="!isFinalized && isUserOwner"> <div class="row" *ngIf="showToggleButton()">
<div class="col-12 add-entity" *ngIf="isCreateNew" (click)="createGrant()"> <div class="col-12 add-entity" *ngIf="isCreateNew" (click)="createGrant()">
<mat-icon>settings_backup_restore</mat-icon> <mat-icon>settings_backup_restore</mat-icon>
<span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-GRANT' | translate}}</span> <span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-GRANT' | translate}}</span>
@ -104,7 +104,7 @@
<!-- Toggle Between Add Project or Use Existing --> <!-- Toggle Between Add Project or Use Existing -->
<div class="col d-flex"> <div class="col d-flex">
<div class="row" *ngIf="!isFinalized && isUserOwner"> <div class="row" *ngIf="showToggleButton()">
<div class="col-12 add-entity" *ngIf="isCreateNewProject" (click)="createProject()"> <div class="col-12 add-entity" *ngIf="isCreateNewProject" (click)="createProject()">
<mat-icon>settings_backup_restore</mat-icon> <mat-icon>settings_backup_restore</mat-icon>
<span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-PROJECT' | translate}}</span> <span>{{'QUICKWIZARD.CREATE-ADD.CREATE.QUICKWIZARD_CREATE.ACTIONS.EXIST-PROJECT' | translate}}</span>

View File

@ -27,6 +27,7 @@ export class GrantTabComponent extends BaseComponent implements OnInit {
@Input() isNewVersion: boolean; @Input() isNewVersion: boolean;
@Input() isNew: boolean; @Input() isNew: boolean;
@Input() isUserOwner: boolean; @Input() isUserOwner: boolean;
@Input() isClone: boolean;
isCreateNew = false; isCreateNew = false;
isCreateNewProject = false; isCreateNewProject = false;
@ -64,7 +65,7 @@ export class GrantTabComponent extends BaseComponent implements OnInit {
initialItems: () => this.searchFunder(''), initialItems: () => this.searchFunder(''),
displayFn: (item) => item['label'], displayFn: (item) => item['label'],
titleFn: (item) => item['label'], titleFn: (item) => item['label'],
subtitleFn: (item) => item['source'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['source'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE') subtitleFn: (item) => item['source'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['source'] : (item['key'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['key'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE'))
} }
this.grantAutoCompleteConfiguration = { this.grantAutoCompleteConfiguration = {
@ -72,7 +73,7 @@ export class GrantTabComponent extends BaseComponent implements OnInit {
initialItems: () => this.searchGrant(''), initialItems: () => this.searchGrant(''),
displayFn: (item) => item['label'] + this.getGrantIdText(item), displayFn: (item) => item['label'] + this.getGrantIdText(item),
titleFn: (item) => item['label'] + this.getGrantIdText(item), titleFn: (item) => item['label'] + this.getGrantIdText(item),
subtitleFn: (item) => item['source'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['source'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE') subtitleFn: (item) => item['source'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['source'] : (item['key'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['key'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE'))
}; };
this.projectAutoCompleteConfiguration = { this.projectAutoCompleteConfiguration = {
@ -80,7 +81,7 @@ export class GrantTabComponent extends BaseComponent implements OnInit {
initialItems: () => this.searchProject(''), initialItems: () => this.searchProject(''),
displayFn: (item) => item['label'], displayFn: (item) => item['label'],
titleFn: (item) => item['label'], titleFn: (item) => item['label'],
subtitleFn: (item) => item['source'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['source'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE') subtitleFn: (item) => item['source'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['source'] : (item['key'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['key'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE'))
} }
this.isCreateNew = (this.grantformGroup.get('label').value != null && this.grantformGroup.get('label').value.length > 0); this.isCreateNew = (this.grantformGroup.get('label').value != null && this.grantformGroup.get('label').value.length > 0);
@ -90,7 +91,7 @@ export class GrantTabComponent extends BaseComponent implements OnInit {
this.setProjectValidators(); this.setProjectValidators();
this.setFunderValidators(); this.setFunderValidators();
this.registerFormListeners(); this.registerFormListeners();
if (this.isNew) { if (this.isNew && !this.isClone) {
this.grantformGroup.reset(); this.grantformGroup.reset();
this.grantformGroup.disable(); this.grantformGroup.disable();
} }
@ -144,6 +145,12 @@ export class GrantTabComponent extends BaseComponent implements OnInit {
this.grantformGroup.get('existGrant').disable(); this.grantformGroup.get('existGrant').disable();
this.grantformGroup.get('label').enable(); this.grantformGroup.get('label').enable();
this.grantformGroup.get('description').enable(); this.grantformGroup.get('description').enable();
} else if (this.isClone) {
this.grantformGroup.get('existGrant').enable();
this.grantformGroup.get('label').disable();
this.grantformGroup.get('label').reset();
this.grantformGroup.get('description').disable();
this.grantformGroup.get('description').reset();
} else if (this.isFinalized || this.isNewVersion || !this.isUserOwner) { } else if (this.isFinalized || this.isNewVersion || !this.isUserOwner) {
this.grantformGroup.get('existGrant').disable(); this.grantformGroup.get('existGrant').disable();
this.grantformGroup.get('label').disable(); this.grantformGroup.get('label').disable();
@ -162,6 +169,12 @@ export class GrantTabComponent extends BaseComponent implements OnInit {
this.projectFormGroup.get('existProject').disable(); this.projectFormGroup.get('existProject').disable();
this.projectFormGroup.get('label').enable(); this.projectFormGroup.get('label').enable();
this.projectFormGroup.get('description').enable(); this.projectFormGroup.get('description').enable();
} else if (this.isClone) {
this.projectFormGroup.get('existProject').enable();
this.projectFormGroup.get('label').disable()
this.projectFormGroup.get('label').reset();
this.projectFormGroup.get('description').disable();
this.projectFormGroup.get('description').reset();
} else if (this.isFinalized || this.isNewVersion || !this.isUserOwner) { } else if (this.isFinalized || this.isNewVersion || !this.isUserOwner) {
this.projectFormGroup.get('existProject').disable(); this.projectFormGroup.get('existProject').disable();
this.projectFormGroup.get('label').disable(); this.projectFormGroup.get('label').disable();
@ -179,6 +192,14 @@ export class GrantTabComponent extends BaseComponent implements OnInit {
if (this.isCreateNewFunder) { if (this.isCreateNewFunder) {
this.funderFormGroup.get('existFunder').disable(); this.funderFormGroup.get('existFunder').disable();
this.funderFormGroup.get('label').enable(); this.funderFormGroup.get('label').enable();
} else if (this.isClone) {
if (this.funderFormGroup.get('existFunder')) {
this.funderFormGroup.get('existFunder').enable();
this.funderFormGroup.get('label').disable();
this.funderFormGroup.get('label').reset();
} else {
this.funderFormGroup.get('label').enable();
}
} else if (this.isFinalized || this.isNewVersion || !this.isUserOwner) { } else if (this.isFinalized || this.isNewVersion || !this.isUserOwner) {
this.funderFormGroup.get('existFunder').disable(); this.funderFormGroup.get('existFunder').disable();
this.funderFormGroup.get('label').disable(); this.funderFormGroup.get('label').disable();
@ -213,4 +234,8 @@ export class GrantTabComponent extends BaseComponent implements OnInit {
isGrantDisabled() { isGrantDisabled() {
return this.grantformGroup.disabled; return this.grantformGroup.disabled;
} }
showToggleButton() {
return (!this.isFinalized && this.isUserOwner) || this.isClone;
}
} }