When finalize DMP properly finalize it's datasets first

spring-update
George Kalampokis 3 years ago
parent ede8bbf48e
commit e5264780c3

@ -933,25 +933,37 @@ public class DataManagementPlanManager {
throw new Exception("User does not have the privilege to do this action."); throw new Exception("User does not have the privilege to do this action.");
if (dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue())) if (dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()))
throw new Exception("DMP is already finalized"); 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<>(); List<Dataset> indexDatasets = new ArrayList<>();
if (datasetsToBeFinalized != null && datasetsToBeFinalized.getUuids() != null && !datasetsToBeFinalized.getUuids().isEmpty()) { 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())) .asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeFinalized.getUuids()))
.update(root -> root.<Integer>get("status"), Dataset.Status.FINALISED.getValue()); .toList();
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao() 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())) .asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeFinalized.getUuids()))
.update(root -> root.<Date>get("finalizedAt"), new Date()); .update(root -> root.<Date>get("finalizedAt"), new Date());*/
List<Dataset> finalizedDatasets = dmp.getDataset().stream().filter(dataset -> datasetsToBeFinalized.getUuids().contains(dataset.getId())).collect(Collectors.toList()); //List<Dataset> finalizedDatasets = dmp.getDataset().stream().filter(dataset -> datasetsToBeFinalized.getUuids().contains(dataset.getId())).collect(Collectors.toList());
finalizedDatasets.forEach(dataset ->{ /* finalizedDatasets.forEach(dataset ->{
dataset.setStatus(Dataset.Status.FINALISED.getValue()); dataset.setStatus(Dataset.Status.FINALISED.getValue());
dataset.setFinalizedAt(new Date()); dataset.setFinalizedAt(new Date());
dataset.setModified(new Date()); dataset.setModified(new Date());
} ); } );*/
indexDatasets.addAll(finalizedDatasets); indexDatasets.addAll(finalizedDatasets);
List<UUID> datasetsToBeCanceled = new LinkedList<>(); List<UUID> datasetsToBeCanceled = new LinkedList<>();
for (Dataset dataset : dmp.getDataset()) { for (Dataset dataset : dmp.getDataset()) {
@ -982,10 +994,14 @@ public class DataManagementPlanManager {
cancelledDatasets.forEach(dataset -> dataset.setStatus(Dataset.Status.CANCELED.getValue())); cancelledDatasets.forEach(dataset -> dataset.setStatus(Dataset.Status.CANCELED.getValue()));
indexDatasets.addAll(cancelledDatasets); 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); this.updateDatasetsIndex(indexDatasets);
MetricsManager.decreaseValue("argos_managed_dataset_descriptions", indexDatasets.size(), "draft"); MetricsManager.decreaseValue("argos_managed_dataset_descriptions", indexDatasets.size(), "draft");
MetricsManager.increaseValue("argos_managed_dataset_descriptions", indexDatasets.size(), "finalized"); MetricsManager.increaseValue("argos_managed_dataset_descriptions", indexDatasets.size(), "finalized");
@ -1977,13 +1993,13 @@ public class DataManagementPlanManager {
if (unpublishedUrl == null) { if (unpublishedUrl == null) {
// Second step, add the file to the entry. // Second step, add the file to the entry.
FileEnvelope file = getWordDocument(id.toString(), principal, configLoader); 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); File pdfFile = datasetManager.convertToPDF(file, environment);
String fileName = name + ".pdf"; String fileName = name + ".pdf";*/
FileSystemResource fileSystemResource = new FileSystemResource(pdfFile); FileSystemResource fileSystemResource = new FileSystemResource(file.getFile());
HttpEntity<FileSystemResource> addFileMapRequest = new HttpEntity<>(fileSystemResource, null); 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); restTemplate.put(addFileUrl, addFileMapRequest);
Files.deleteIfExists(file.getFile().toPath()); Files.deleteIfExists(file.getFile().toPath());

@ -1352,7 +1352,7 @@ ALTER TABLE ONLY public."Notification"
-- --
ALTER TABLE ONLY public."UserDatasetProfile" 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 -- 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" 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 -- Name: UserDMP UserDMP_dmp_fkey; Type: FK CONSTRAINT; Schema: public; Owner: :POSTGRES_USER

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

Loading…
Cancel
Save