When finalize DMP properly finalize it's datasets first

This commit is contained in:
George Kalampokis 2021-04-21 18:21:52 +03:00
parent ede8bbf48e
commit e5264780c3
3 changed files with 39 additions and 23 deletions

View File

@ -933,25 +933,37 @@ public class DataManagementPlanManager {
throw new Exception("User does not have the privilege to do this action.");
if (dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()))
throw new Exception("DMP is already finalized");
dmp.setStatus(DMP.DMPStatus.FINALISED.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
this.updateIndex(dmp);
MetricsManager.decreaseValue("argos_managed_dmps", 1, "draft");
MetricsManager.increaseValue("argos_managed_dmps", 1, "finalized");
List<Dataset> indexDatasets = new ArrayList<>();
if (datasetsToBeFinalized != null && datasetsToBeFinalized.getUuids() != null && !datasetsToBeFinalized.getUuids().isEmpty()) {
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
List<Dataset> finalizedDatasets = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
.asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeFinalized.getUuids()))
.update(root -> root.<Integer>get("status"), Dataset.Status.FINALISED.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
.toList();
for (Dataset dataset: finalizedDatasets) {
Dataset.Status status = Dataset.Status.fromInteger(dataset.getStatus());
Date finalizedDate = dataset.getFinalizedAt();
dataset.setStatus(Dataset.Status.FINALISED.getValue());
dataset.setFinalizedAt(new Date());
DatasetWizardModel wizardModel = new DatasetWizardModel();
wizardModel = wizardModel.fromDataModel(dataset);
wizardModel.setDatasetProfileDefinition(this.datasetManager.getPagedProfile(wizardModel, dataset));
try {
datasetManager.createOrUpdate(wizardModel, principal);
} catch (Exception e) {
dataset.setStatus(status.getValue());
dataset.setFinalizedAt(finalizedDate);
throw e;
}
dataset.setModified(new Date());
}
/*apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
.asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeFinalized.getUuids()))
.update(root -> root.<Date>get("finalizedAt"), new Date());
List<Dataset> finalizedDatasets = dmp.getDataset().stream().filter(dataset -> datasetsToBeFinalized.getUuids().contains(dataset.getId())).collect(Collectors.toList());
finalizedDatasets.forEach(dataset ->{
.update(root -> root.<Date>get("finalizedAt"), new Date());*/
//List<Dataset> finalizedDatasets = dmp.getDataset().stream().filter(dataset -> datasetsToBeFinalized.getUuids().contains(dataset.getId())).collect(Collectors.toList());
/* finalizedDatasets.forEach(dataset ->{
dataset.setStatus(Dataset.Status.FINALISED.getValue());
dataset.setFinalizedAt(new Date());
dataset.setModified(new Date());
} );
} );*/
indexDatasets.addAll(finalizedDatasets);
List<UUID> datasetsToBeCanceled = new LinkedList<>();
for (Dataset dataset : dmp.getDataset()) {
@ -982,10 +994,14 @@ public class DataManagementPlanManager {
cancelledDatasets.forEach(dataset -> dataset.setStatus(Dataset.Status.CANCELED.getValue()));
indexDatasets.addAll(cancelledDatasets);
}
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
sendNotification(dmp, user, NotificationType.DMP_FINALISED);
}
dmp.setStatus(DMP.DMPStatus.FINALISED.getValue());
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
this.updateIndex(dmp);
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
sendNotification(dmp, user, NotificationType.DMP_FINALISED);
MetricsManager.decreaseValue("argos_managed_dmps", 1, "draft");
MetricsManager.increaseValue("argos_managed_dmps", 1, "finalized");
this.updateDatasetsIndex(indexDatasets);
MetricsManager.decreaseValue("argos_managed_dataset_descriptions", indexDatasets.size(), "draft");
MetricsManager.increaseValue("argos_managed_dataset_descriptions", indexDatasets.size(), "finalized");
@ -1977,13 +1993,13 @@ public class DataManagementPlanManager {
if (unpublishedUrl == null) {
// Second step, add the file to the entry.
FileEnvelope file = getWordDocument(id.toString(), principal, configLoader);
String name = file.getFilename().substring(0, file.getFilename().length() - 5);
/*String name = file.getFilename().substring(0, file.getFilename().length() - 5);
File pdfFile = datasetManager.convertToPDF(file, environment);
String fileName = name + ".pdf";
FileSystemResource fileSystemResource = new FileSystemResource(pdfFile);
String fileName = name + ".pdf";*/
FileSystemResource fileSystemResource = new FileSystemResource(file.getFile());
HttpEntity<FileSystemResource> addFileMapRequest = new HttpEntity<>(fileSystemResource, null);
String addFileUrl = links.get("bucket") + "/" + fileName + "?access_token=" + zenodoToken;
String addFileUrl = links.get("bucket") + "/" + file.getFilename() + "?access_token=" + zenodoToken;
restTemplate.put(addFileUrl, addFileMapRequest);
Files.deleteIfExists(file.getFile().toPath());

View File

@ -1352,7 +1352,7 @@ ALTER TABLE ONLY public."Notification"
--
ALTER TABLE ONLY public."UserDatasetProfile"
ADD CONSTRAINT "UserDatasetProfile_datasetProfile_fkey" FOREIGN KEY (datasetProfile) REFERENCES public."DatasetProfile" ("ID");
ADD CONSTRAINT "UserDatasetProfile_datasetProfile_fkey" FOREIGN KEY ("datasetProfile") REFERENCES public."DatasetProfile" ("ID");
--
-- Name: UserDatasetProfile UserDatasetProfile_user_key; Type: FK CONSTRAINT; Schema: public; Owner: :POSTGRES_USER
@ -1360,7 +1360,7 @@ ALTER TABLE ONLY public."UserDatasetProfile"
ALTER TABLE ONLY public."UserDatasetProfile"
ADD CONSTRAINT "UserDatasetProfile_usr_fkey" FOREIGN KEY (usr) REFERENCES public."UserInfo" (id);
ADD CONSTRAINT "UserDatasetProfile_usr_fkey" FOREIGN KEY ("usr") REFERENCES public."UserInfo" (id);
--
-- Name: UserDMP UserDMP_dmp_fkey; Type: FK CONSTRAINT; Schema: public; Owner: :POSTGRES_USER

View File

@ -5,12 +5,12 @@ CREATE TABLE public."UserDatasetProfile"
"datasetProfile" uuid NOT NULL,
role integer,
CONSTRAINT "UserDatasetProfile_pkey" PRIMARY KEY (id),
CONSTRAINT "UserDatasetProfile_datasetProfile_fkey" FOREIGN KEY (datasetProfile)
CONSTRAINT "UserDatasetProfile_datasetProfile_fkey" FOREIGN KEY ("datasetProfile")
REFERENCES public."DatasetProfile" ("ID") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID,
CONSTRAINT "UserDatasetProfile_usr_fkey" FOREIGN KEY (usr)
CONSTRAINT "UserDatasetProfile_usr_fkey" FOREIGN KEY ("usr")
REFERENCES public."UserInfo" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION