Minor refactoring

This commit is contained in:
George Kalampokis 2020-10-06 11:50:14 +03:00
parent a1b067071a
commit e2326e1070
1 changed files with 8 additions and 2 deletions

View File

@ -357,10 +357,13 @@ public class DataManagementPlanManager {
if (dataManagementPlan.getId() != null) {
DMP dmp1 = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId());
Instant dbTime = Instant.ofEpochMilli(dmp1.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS);
Instant modelTime = Instant.ofEpochMilli(dataManagementPlan.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS);
if (!isUserOwnerOfDmp(dmp1, principal)) {
throw new Exception("User not being the creator is not authorized to edit this DMP.");
}
if (Instant.ofEpochMilli(dmp1.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS).toEpochMilli() != Instant.ofEpochMilli(dataManagementPlan.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS).toEpochMilli()) {
if (dbTime.toEpochMilli() != modelTime.toEpochMilli()) {
throw new Exception("Another user have already edit that DMP.");
}
List<Dataset> datasetList = new ArrayList<>(dmp1.getDataset());
@ -479,10 +482,13 @@ public class DataManagementPlanManager {
if (dataManagementPlan.getId() != null) {
DMP dmp1 = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId());
Instant dbTime = Instant.ofEpochMilli(dmp1.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS);
Instant modelTime = Instant.ofEpochMilli(dataManagementPlan.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS);
if (!isUserOwnerOfDmp(dmp1, principal)) {
throw new Exception("User not being the creator is not authorized to edit this DMP.");
}
if (Instant.ofEpochMilli(dmp1.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS).toEpochMilli() != Instant.ofEpochMilli(dataManagementPlan.getModified().getTime()).truncatedTo(ChronoUnit.SECONDS).toEpochMilli()) {
if (dbTime.toEpochMilli() != modelTime.toEpochMilli()) {
throw new Exception("Another user have already edit that DMP.");
}
for (DatasetWizardModel dataset : dataManagementPlan.getDatasets()) {