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 73b596822..174848582 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 @@ -102,11 +102,21 @@ public class DMPs extends BaseController { if (contentType.equals("application/xml") || contentType.equals("application/msword")) { return this.dataManagementPlanManager.getDocument(id, contentType, principal, this.configLoader); } else { - eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal, false); + eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal, false, true); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); } } + @RequestMapping(method = RequestMethod.GET, value = {"/plain/{id}"}) + public @ResponseBody + ResponseEntity getSingleNoDatasets(@PathVariable String id, @RequestHeader("Content-Type") String contentType, + @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception { + + eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal, false, false); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); + + } + @RequestMapping(method = RequestMethod.POST, value = {"/datasetProfilesUsedByDmps/paged"}, produces = "application/json") public @ResponseBody ResponseEntity>> getUsingDatasetProfilesPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem, Principal principal) { @@ -133,7 +143,7 @@ public class DMPs extends BaseController { public @ResponseBody ResponseEntity getSinglePublic(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception { // try { - eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal, true); + eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal, true, true); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); // } catch (Exception ex) { // return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).message(ex.getMessage())); 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 ec49822c5..997766bec 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 @@ -274,7 +274,7 @@ public class DataManagementPlanManager { return datasetsSet; } - public eu.eudat.models.data.dmp.DataManagementPlan getSingle(String id, Principal principal, boolean isPublic) throws Exception { + public eu.eudat.models.data.dmp.DataManagementPlan getSingle(String id, Principal principal, boolean isPublic, boolean includeDatasets) throws Exception { eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = new eu.eudat.models.data.dmp.DataManagementPlan(); DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); if (!isPublic && principal == null) { @@ -286,8 +286,9 @@ public class DataManagementPlanManager { } else if (isPublic && !dataManagementPlanEntity.isPublic()) { throw new ForbiddenException("Selected DMP is not public"); } - dataManagementPlan.fromDataModel(dataManagementPlanEntity); - List datasetEnities = new ArrayList<>(dataManagementPlanEntity.getDataset()); + if (includeDatasets) { + dataManagementPlan.fromDataModel(dataManagementPlanEntity); + List datasetEnities = new ArrayList<>(dataManagementPlanEntity.getDataset()); /*for (int i = 0; i < datasetEnities.size(); i++) { for (int j = i; j < dataManagementPlan.getDatasets().size(); j++) { if (dataManagementPlan.getDatasets().get(j).getId().equals(datasetEnities.get(i).getId())) { @@ -296,17 +297,20 @@ public class DataManagementPlanManager { } } }*/ - datasetEnities.stream() - .filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED) && !dataset.getStatus().equals(Dataset.Status.CANCELED)) - .forEach(dataset -> { - dataManagementPlan.getDatasets().stream().filter(datasetWizardModel -> datasetWizardModel.getId().equals(dataset.getId())).forEach(datasetWizardModel -> { - DatasetWizardModel wizardModel = datasetManager.getSingle(datasetWizardModel.getId().toString(), principal); - datasetWizardModel.setDatasetProfileDefinition(wizardModel.getDatasetProfileDefinition()); - datasetWizardModel.setTags(wizardModel.getTags()); - }); - }); - if (isPublic) { - dataManagementPlan.setDatasets(dataManagementPlan.getDatasets().stream().filter(dataset -> dataset.getStatus() == Dataset.Status.FINALISED.getValue()).collect(Collectors.toList())); + datasetEnities.stream() + .filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED) && !dataset.getStatus().equals(Dataset.Status.CANCELED)) + .forEach(dataset -> { + dataManagementPlan.getDatasets().stream().filter(datasetWizardModel -> datasetWizardModel.getId().equals(dataset.getId())).forEach(datasetWizardModel -> { + DatasetWizardModel wizardModel = datasetManager.getSingle(datasetWizardModel.getId().toString(), principal); + datasetWizardModel.setDatasetProfileDefinition(wizardModel.getDatasetProfileDefinition()); + datasetWizardModel.setTags(wizardModel.getTags()); + }); + }); + if (isPublic) { + dataManagementPlan.setDatasets(dataManagementPlan.getDatasets().stream().filter(dataset -> dataset.getStatus() == Dataset.Status.FINALISED.getValue()).collect(Collectors.toList())); + } + } else { + dataManagementPlan.fromDataModelNoDatasets(dataManagementPlanEntity); } Map dmpProperties = dataManagementPlanEntity.getDmpProperties() != null ? new org.json.JSONObject(dataManagementPlanEntity.getDmpProperties()).toMap() : null; diff --git a/dmp-frontend/src/app/core/services/dmp/dmp.service.ts b/dmp-frontend/src/app/core/services/dmp/dmp.service.ts index 52888b3c1..ce1bc9d0d 100644 --- a/dmp-frontend/src/app/core/services/dmp/dmp.service.ts +++ b/dmp-frontend/src/app/core/services/dmp/dmp.service.ts @@ -46,6 +46,10 @@ export class DmpService { return this.http.get(this.actionUrl + id, { headers: this.headers }); //'getSingle/' + } + getSingleNoDatasets(id: String): Observable { + return this.http.get(this.actionUrl + 'plain/' + id, { headers: this.headers }); //'getSingle/' + + } + getSinglePublic(id: String): Observable { return this.http.get(this.actionUrl + 'public/' + id, { headers: this.headers }); } 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 166fe8862..899f868ed 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 @@ -233,7 +233,7 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme }); } else if (dmpId != null) { this.isNew = true; - this.dmpService.getSingle(dmpId).pipe(map(data => data as DmpModel)) + this.dmpService.getSingleNoDatasets(dmpId).pipe(map(data => data as DmpModel)) .pipe(takeUntil(this._destroyed)) .subscribe(data => { this.datasetWizardModel = new DatasetWizardEditorModel(); @@ -299,7 +299,7 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme this.datasetWizardModel.status = 0; this.formGroup = this.datasetWizardModel.buildForm(); this.formGroup.get('id').setValue(null); - this.dmpService.getSingle(newDmpId).pipe(map(data => data as DmpModel)) + this.dmpService.getSingleNoDatasets(newDmpId).pipe(map(data => data as DmpModel)) .pipe(takeUntil(this._destroyed)) .subscribe(data => { setTimeout(() => {