Allow to return DMP with no Datasets for the Dataset Editor

This commit is contained in:
George Kalampokis 2022-03-15 17:58:01 +02:00
parent 4e0402df95
commit dc06ba9201
4 changed files with 36 additions and 18 deletions

View File

@ -102,11 +102,21 @@ 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, false); eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal, false, true);
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));
} }
} }
@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<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
}
@RequestMapping(method = RequestMethod.POST, value = {"/datasetProfilesUsedByDmps/paged"}, produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/datasetProfilesUsedByDmps/paged"}, produces = "application/json")
public @ResponseBody public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<DatasetProfileListingModel>>> getUsingDatasetProfilesPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem, Principal principal) { ResponseEntity<ResponseItem<DataTableData<DatasetProfileListingModel>>> getUsingDatasetProfilesPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem, Principal principal) {
@ -133,7 +143,7 @@ public class DMPs extends BaseController {
public @ResponseBody public @ResponseBody
ResponseEntity getSinglePublic(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception { ResponseEntity getSinglePublic(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception {
// try { // 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<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
// } catch (Exception ex) { // } catch (Exception ex) {
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).message(ex.getMessage())); // return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).message(ex.getMessage()));

View File

@ -274,7 +274,7 @@ public class DataManagementPlanManager {
return datasetsSet; 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(); eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = new eu.eudat.models.data.dmp.DataManagementPlan();
DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
if (!isPublic && principal == null) { if (!isPublic && principal == null) {
@ -286,8 +286,9 @@ public class DataManagementPlanManager {
} else if (isPublic && !dataManagementPlanEntity.isPublic()) { } else if (isPublic && !dataManagementPlanEntity.isPublic()) {
throw new ForbiddenException("Selected DMP is not public"); throw new ForbiddenException("Selected DMP is not public");
} }
dataManagementPlan.fromDataModel(dataManagementPlanEntity); if (includeDatasets) {
List<Dataset> datasetEnities = new ArrayList<>(dataManagementPlanEntity.getDataset()); dataManagementPlan.fromDataModel(dataManagementPlanEntity);
List<Dataset> datasetEnities = new ArrayList<>(dataManagementPlanEntity.getDataset());
/*for (int i = 0; i < datasetEnities.size(); i++) { /*for (int i = 0; i < datasetEnities.size(); i++) {
for (int j = i; j < dataManagementPlan.getDatasets().size(); j++) { for (int j = i; j < dataManagementPlan.getDatasets().size(); j++) {
if (dataManagementPlan.getDatasets().get(j).getId().equals(datasetEnities.get(i).getId())) { if (dataManagementPlan.getDatasets().get(j).getId().equals(datasetEnities.get(i).getId())) {
@ -296,17 +297,20 @@ public class DataManagementPlanManager {
} }
} }
}*/ }*/
datasetEnities.stream() datasetEnities.stream()
.filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED) && !dataset.getStatus().equals(Dataset.Status.CANCELED)) .filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED) && !dataset.getStatus().equals(Dataset.Status.CANCELED))
.forEach(dataset -> { .forEach(dataset -> {
dataManagementPlan.getDatasets().stream().filter(datasetWizardModel -> datasetWizardModel.getId().equals(dataset.getId())).forEach(datasetWizardModel -> { dataManagementPlan.getDatasets().stream().filter(datasetWizardModel -> datasetWizardModel.getId().equals(dataset.getId())).forEach(datasetWizardModel -> {
DatasetWizardModel wizardModel = datasetManager.getSingle(datasetWizardModel.getId().toString(), principal); DatasetWizardModel wizardModel = datasetManager.getSingle(datasetWizardModel.getId().toString(), principal);
datasetWizardModel.setDatasetProfileDefinition(wizardModel.getDatasetProfileDefinition()); datasetWizardModel.setDatasetProfileDefinition(wizardModel.getDatasetProfileDefinition());
datasetWizardModel.setTags(wizardModel.getTags()); datasetWizardModel.setTags(wizardModel.getTags());
}); });
}); });
if (isPublic) { if (isPublic) {
dataManagementPlan.setDatasets(dataManagementPlan.getDatasets().stream().filter(dataset -> dataset.getStatus() == Dataset.Status.FINALISED.getValue()).collect(Collectors.toList())); 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; Map dmpProperties = dataManagementPlanEntity.getDmpProperties() != null ? new org.json.JSONObject(dataManagementPlanEntity.getDmpProperties()).toMap() : null;

View File

@ -46,6 +46,10 @@ export class DmpService {
return this.http.get<DmpModel>(this.actionUrl + id, { headers: this.headers }); //'getSingle/' + return this.http.get<DmpModel>(this.actionUrl + id, { headers: this.headers }); //'getSingle/' +
} }
getSingleNoDatasets(id: String): Observable<DmpModel> {
return this.http.get<DmpModel>(this.actionUrl + 'plain/' + id, { headers: this.headers }); //'getSingle/' +
}
getSinglePublic(id: String): Observable<DmpModel> { getSinglePublic(id: String): Observable<DmpModel> {
return this.http.get<DmpModel>(this.actionUrl + 'public/' + id, { headers: this.headers }); return this.http.get<DmpModel>(this.actionUrl + 'public/' + id, { headers: this.headers });
} }

View File

@ -233,7 +233,7 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme
}); });
} else if (dmpId != null) { } else if (dmpId != null) {
this.isNew = true; 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)) .pipe(takeUntil(this._destroyed))
.subscribe(data => { .subscribe(data => {
this.datasetWizardModel = new DatasetWizardEditorModel(); this.datasetWizardModel = new DatasetWizardEditorModel();
@ -299,7 +299,7 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme
this.datasetWizardModel.status = 0; this.datasetWizardModel.status = 0;
this.formGroup = this.datasetWizardModel.buildForm(); this.formGroup = this.datasetWizardModel.buildForm();
this.formGroup.get('id').setValue(null); 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)) .pipe(takeUntil(this._destroyed))
.subscribe(data => { .subscribe(data => {
setTimeout(() => { setTimeout(() => {