Fixes Dmp Versioning functionality letting user editing and saving over an old version.
This commit is contained in:
parent
1f643cda9a
commit
02a42d22ba
|
@ -8,6 +8,7 @@ import eu.eudat.data.dao.entities.DMPDao;
|
|||
import eu.eudat.data.entities.DMP;
|
||||
import eu.eudat.data.query.items.item.dmp.DataManagementPlanCriteriaRequest;
|
||||
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
|
||||
import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException;
|
||||
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
|
||||
import eu.eudat.logic.managers.DataManagementPlanManager;
|
||||
import eu.eudat.logic.managers.DatasetManager;
|
||||
|
@ -105,8 +106,12 @@ public class DMPs extends BaseController {
|
|||
@RequestMapping(method = RequestMethod.POST, value = {"/new/{id}"}, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<DMP>> newVersion(@PathVariable UUID id, @Valid @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||
this.dataManagementPlanManager.newVersion(id, dataManagementPlan, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.NO_MESSAGE));
|
||||
try {
|
||||
this.dataManagementPlanManager.newVersion(id, dataManagementPlan, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.NO_MESSAGE));
|
||||
} catch (DMPNewVersionException exception) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/clone/{id}"}, consumes = "application/json", produces = "application/json")
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package eu.eudat.exceptions.datamanagementplan;
|
||||
|
||||
public class DMPNewVersionException extends RuntimeException {
|
||||
|
||||
public DMPNewVersionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ import eu.eudat.data.entities.Organisation;
|
|||
import eu.eudat.data.entities.Researcher;
|
||||
import eu.eudat.data.query.items.item.dmp.DataManagementPlanCriteriaRequest;
|
||||
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
|
||||
import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException;
|
||||
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
|
||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
||||
|
@ -25,6 +26,8 @@ import eu.eudat.models.HintedModelFactory;
|
|||
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
||||
import eu.eudat.models.data.dmp.*;
|
||||
import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue;
|
||||
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.DataManagementPlanProfile;
|
||||
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.Field;
|
||||
import eu.eudat.models.data.helpermodels.Tuple;
|
||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
|
||||
|
@ -283,17 +286,30 @@ public class DataManagementPlanManager {
|
|||
|
||||
public void newVersion(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||
DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid);
|
||||
DMP newDmp = dataManagementPlan.toDataModel();
|
||||
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
|
||||
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
|
||||
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
||||
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao(), user);
|
||||
newDmp.setCreator(user);
|
||||
newDmp.setGroupId(oldDmp.getGroupId());
|
||||
newDmp.setVersion(oldDmp.getVersion() + 1);
|
||||
newDmp.setId(null);
|
||||
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
|
||||
copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao());
|
||||
|
||||
DataManagementPlanCriteria criteria = new DataManagementPlanCriteria();
|
||||
LinkedList<UUID> list = new LinkedList<>();
|
||||
list.push(oldDmp.getGroupId());
|
||||
criteria.setGroupIds(list);
|
||||
criteria.setAllVersions(false);
|
||||
QueryableList<DMP> dataManagementPlanQueryableList = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria);
|
||||
List<DMP> latestVersionDMP = dataManagementPlanQueryableList.toList();
|
||||
|
||||
if(latestVersionDMP.get(0).getVersion().equals(oldDmp.getVersion())){
|
||||
DMP newDmp = dataManagementPlan.toDataModel();
|
||||
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
|
||||
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
|
||||
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
|
||||
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao(), user);
|
||||
newDmp.setCreator(user);
|
||||
newDmp.setGroupId(oldDmp.getGroupId());
|
||||
newDmp.setVersion(oldDmp.getVersion() + 1);
|
||||
newDmp.setId(null);
|
||||
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
|
||||
copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao());
|
||||
} else {
|
||||
throw new DMPNewVersionException("Version to update not the latest.");
|
||||
}
|
||||
}
|
||||
|
||||
public void clone(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||
|
@ -446,6 +462,9 @@ public class DataManagementPlanManager {
|
|||
Element dmpProfileId = xmlDoc.createElement("dmpProfileId");
|
||||
dmpProfileId.setTextContent(dmpProfile.getId().toString());
|
||||
dmpProfileElement.appendChild(dmpProfileId);
|
||||
Element values = xmlDoc.createElement("values");
|
||||
values.setTextContent(dmpProfile.getDefinition());
|
||||
dmpProfileElement.appendChild(values);
|
||||
}
|
||||
dmpElement.appendChild(dmpProfileElement);
|
||||
|
||||
|
@ -589,9 +608,19 @@ public class DataManagementPlanManager {
|
|||
// Creates new dataManagmentPlan to fill it with the data model that was parsed from the xml.
|
||||
// Creates properties.
|
||||
DataManagementPlan dm = new DataManagementPlan();
|
||||
Tuple tuple = new Tuple();
|
||||
DataManagementPlanProfile dmpProfile = new DataManagementPlanProfile();
|
||||
|
||||
List<Field> fieldList = new LinkedList<>();
|
||||
Field field = new Field();
|
||||
field.setLabel(dataManagementPlans.get(0).getDmpProfile().getDmpProfileName());
|
||||
field.setId(dataManagementPlans.get(0).getDmpProfile().getDmpProfileId());
|
||||
|
||||
fieldList.add(field);
|
||||
dmpProfile.setFields(fieldList);
|
||||
|
||||
/*Tuple tuple = new Tuple();
|
||||
tuple.setId(dataManagementPlans.get(0).getDmpProfile().getDmpProfileId());
|
||||
tuple.setLabel(dataManagementPlans.get(0).getDmpProfile().getDmpProfileName());
|
||||
tuple.setLabel(dataManagementPlans.get(0).getDmpProfile().getDmpProfileName());*/
|
||||
eu.eudat.models.data.project.Project project = new eu.eudat.models.data.project.Project();
|
||||
ProjectImportModels projectImport = dataManagementPlans.get(0).getProjectImport();
|
||||
project.setId(projectImport.getId());
|
||||
|
@ -632,7 +661,7 @@ public class DataManagementPlanManager {
|
|||
dm.setResearchers(researchers); // Sets researchers property.
|
||||
dm.setAssociatedUsers(associatedUsers); // Sets associatedUsers property.
|
||||
dm.setDynamicFields(dynamicFields); // Sets dynamicFields property.
|
||||
dm.setProfile(tuple);
|
||||
dm.setDefinition(dmpProfile);
|
||||
|
||||
createOrUpdate(apiContext, dm, principal);
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import { BreadcrumbItem } from '../../misc/breadcrumb/definition/breadcrumb-item
|
|||
import { IBreadCrumbComponent } from '../../misc/breadcrumb/definition/IBreadCrumbComponent';
|
||||
import { DmpWizardEditorModel } from './dmp-wizard-editor.model';
|
||||
import { SnackBarNotificationLevel, UiNotificationService } from '../../../core/services/notification/ui-notification-service';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dmp-wizard-component',
|
||||
|
@ -75,7 +76,7 @@ export class DmpWizardComponent extends BaseComponent implements OnInit, IBreadC
|
|||
.pipe(takeUntil(this._destroyed))
|
||||
.subscribe(
|
||||
complete => this.onCallbackSuccess(),
|
||||
error => this.onCallbackError(error)
|
||||
error => this.onCallbackErrorNewVersion(error)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -96,5 +97,9 @@ export class DmpWizardComponent extends BaseComponent implements OnInit, IBreadC
|
|||
});
|
||||
}
|
||||
|
||||
onCallbackErrorNewVersion(errorResponse: HttpErrorResponse) {
|
||||
this.uiNotificationService.snackBarNotification(errorResponse.error.message, SnackBarNotificationLevel.Error);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue