|
|
|
@ -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());
|
|
|
|
|
|
|
|
|
|