Creates new back end service that finalizes a DMP.
This commit is contained in:
parent
326757f2c3
commit
92486b9363
|
@ -17,6 +17,7 @@ import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
|||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
|
||||
import eu.eudat.models.data.datasetwizard.DatasetsToBeFinalized;
|
||||
import eu.eudat.models.data.dmp.DataManagementPlan;
|
||||
import eu.eudat.models.data.helpermodels.Tuple;
|
||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||
|
@ -39,7 +40,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
|
||||
import javax.activation.MimetypesFileTypeMap;
|
||||
import javax.validation.Valid;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -187,7 +187,6 @@ public class DMPs extends BaseController {
|
|||
@RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"})
|
||||
public @ResponseBody
|
||||
ResponseEntity<byte[]> getPDFDocument(@PathVariable String id, @RequestHeader("Content-Type") String contentType) throws IllegalAccessException, IOException, InstantiationException, InterruptedException {
|
||||
System.out.println(contentType);
|
||||
File file = this.dataManagementPlanManager.getWordDocument(id);
|
||||
String name = file.getName().substring(0, file.getName().length() - 5);
|
||||
File pdffile = datasetManager.convertToPDF(file, environment, name);
|
||||
|
@ -242,7 +241,18 @@ public class DMPs extends BaseController {
|
|||
public ResponseEntity<ResponseItem<DMP>> makePublic(@PathVariable String id, Principal principal) {
|
||||
try {
|
||||
this.dataManagementPlanManager.makePublic(UUID.fromString(id), principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made public"));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made public."));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, value = {"/finalize/{id}"})
|
||||
public ResponseEntity<ResponseItem<DMP>> makeFinalize(@PathVariable String id, Principal principal, @RequestBody DatasetsToBeFinalized datasetsToBeFinalized) {
|
||||
try {
|
||||
this.dataManagementPlanManager.makeFinalize(UUID.fromString(id), principal, datasetsToBeFinalized);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made finalized."));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(e.getMessage()));
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import eu.eudat.logic.utilities.documents.xml.ExportXmlBuilder;
|
|||
import eu.eudat.models.HintedModelFactory;
|
||||
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
|
||||
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
||||
import eu.eudat.models.data.datasetwizard.DatasetsToBeFinalized;
|
||||
import eu.eudat.models.data.dmp.*;
|
||||
import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue;
|
||||
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.DataManagementPlanProfile;
|
||||
|
@ -936,11 +937,51 @@ public class DataManagementPlanManager {
|
|||
public void makePublic(UUID id, Principal principal) throws Exception {
|
||||
DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id);
|
||||
// Check if dmp is finalized and if user is owner.
|
||||
if (!dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getId().equals(principal.getId()))
|
||||
if (!isUserOwnerOfDmp(dmp, principal))
|
||||
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 not finalized");
|
||||
dmp.setPublic(true);
|
||||
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
|
||||
}
|
||||
|
||||
public void makeFinalize(UUID id, Principal principal, DatasetsToBeFinalized datasetsToBeFinalized) throws Exception {
|
||||
DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id);
|
||||
if (!isUserOwnerOfDmp(dmp, principal))
|
||||
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);
|
||||
if (datasetsToBeFinalized != null && datasetsToBeFinalized.getUuids() != null && !datasetsToBeFinalized.getUuids().isEmpty()) {
|
||||
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
|
||||
.asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeFinalized.getUuids()))
|
||||
.update(root -> root.<Integer>get("status"), Dataset.Status.FINALISED.getValue());
|
||||
List<UUID> datasetsToBeCanceled = new LinkedList<>();
|
||||
for (Dataset dataset : dmp.getDataset()) {
|
||||
if (!dataset.getStatus().equals(Dataset.Status.FINALISED.getValue()) && !datasetsToBeFinalized.getUuids().contains(dataset.getId())) {
|
||||
datasetsToBeCanceled.add(dataset.getId());
|
||||
}
|
||||
}
|
||||
if (!datasetsToBeCanceled.isEmpty())
|
||||
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
|
||||
.asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeCanceled))
|
||||
.update(root -> root.<Integer>get("status"), Dataset.Status.CANCELED.getValue());
|
||||
} else {
|
||||
List<UUID> datasetsToBeCanceled = new LinkedList<>();
|
||||
for (Dataset dataset : dmp.getDataset()) {
|
||||
if (!dataset.getStatus().equals(Dataset.Status.FINALISED.getValue())) {
|
||||
datasetsToBeCanceled.add(dataset.getId());
|
||||
}
|
||||
}
|
||||
if (!datasetsToBeCanceled.isEmpty())
|
||||
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
|
||||
.asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeCanceled))
|
||||
.update(root -> root.<Integer>get("status"), Dataset.Status.CANCELED.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isUserOwnerOfDmp(DMP dmp, Principal principal) {
|
||||
return (dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getId()).equals(principal.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package eu.eudat.models.data.datasetwizard;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DatasetsToBeFinalized {
|
||||
private List<UUID> uuids;
|
||||
|
||||
public List<UUID> getUuids() {
|
||||
return uuids;
|
||||
}
|
||||
public void setUuids(List<UUID> uuids) {
|
||||
this.uuids = uuids;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue