Refactos DMP update when set to "Finalized", now sets it's Datasets status of not "Finalized" to "Canceled".
This commit is contained in:
parent
590d85b355
commit
55407fd053
|
@ -94,7 +94,7 @@ public class DataManagementPlanManager {
|
|||
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<>();
|
||||
|
||||
CompletableFuture itemsFuture;
|
||||
if(fieldsGroup.equals("listing")){
|
||||
if (fieldsGroup.equals("listing")) {
|
||||
|
||||
itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
|
||||
.selectAsync(item -> {
|
||||
|
@ -102,17 +102,16 @@ public class DataManagementPlanManager {
|
|||
item.getDataset().stream()
|
||||
.filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED.getValue()) && !dataset.getStatus().equals(Dataset.Status.CANCELED.getValue())).collect(Collectors.toList()).stream()
|
||||
.filter(dataset -> dataset.getDmp().getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getId().equals(principalID)
|
||||
|| dataset.getDmp().getUsers().stream()
|
||||
.filter(x -> x.getUser().getId().equals(principalID))
|
||||
.collect(Collectors.toList()).size() > 0)
|
||||
|| dataset.getDmp().getUsers().stream()
|
||||
.filter(x -> x.getUser().getId().equals(principalID))
|
||||
.collect(Collectors.toList()).size() > 0)
|
||||
.collect(Collectors.toSet()));
|
||||
return new DataManagementPlanListingModel().fromDataModelDatasets(item);
|
||||
})
|
||||
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
itemsFuture = pagedItems
|
||||
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModel(item))
|
||||
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModel(item))
|
||||
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
|
||||
}
|
||||
|
||||
|
@ -131,7 +130,7 @@ public class DataManagementPlanManager {
|
|||
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<>();
|
||||
|
||||
CompletableFuture itemsFuture;
|
||||
if(fieldsGroup.equals("listing")){
|
||||
if (fieldsGroup.equals("listing")) {
|
||||
itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
|
||||
.selectAsync(item -> {
|
||||
item.setDataset(
|
||||
|
@ -140,8 +139,7 @@ public class DataManagementPlanManager {
|
|||
return new DataManagementPlanListingModel().fromDataModelDatasets(item);
|
||||
})
|
||||
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
itemsFuture = pagedItems
|
||||
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModel(item))
|
||||
.whenComplete((resultList, throwable) -> dataTable.setData(resultList));
|
||||
|
@ -301,30 +299,13 @@ public class DataManagementPlanManager {
|
|||
DataManagementPlanOverviewModel datamanagementPlan = new DataManagementPlanOverviewModel();
|
||||
datamanagementPlan.fromDataModelDatasets(dataManagementPlanEntity);
|
||||
|
||||
/*Map dmpProperties = dataManagementPlanEntity.getDmpProperties() != null ? new org.json.JSONObject(dataManagementPlanEntity.getDmpProperties()).toMap() : null;
|
||||
datamanagementPlan.setDynamicFields(dynamicProjectConfiguration.getFields().stream().map(item -> {
|
||||
DynamicFieldWithValue fieldWithValue = new DynamicFieldWithValue();
|
||||
fieldWithValue.setId(item.getId());
|
||||
fieldWithValue.setDependencies(item.getDependencies());
|
||||
fieldWithValue.setName(item.getName());
|
||||
fieldWithValue.setQueryProperty(item.getQueryProperty());
|
||||
fieldWithValue.setRequired(item.getRequired());
|
||||
return fieldWithValue;
|
||||
}).collect(Collectors.toList()));*/
|
||||
|
||||
/*if (dmpProperties != null && datamanagementPlan.getDynamicFields() != null)
|
||||
datamanagementPlan.getDynamicFields().forEach(item -> {
|
||||
Map<String, String> properties = (Map<String, String>) dmpProperties.get(item.getId());
|
||||
if (properties != null)
|
||||
item.setValue(new Tuple<>(properties.get("id"), properties.get("label")));
|
||||
});*/
|
||||
return datamanagementPlan;
|
||||
}
|
||||
|
||||
public eu.eudat.models.data.dmp.DataManagementPlan getSinglePublic(String id, DynamicProjectConfiguration dynamicProjectConfiguration) throws Exception {
|
||||
DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
|
||||
|
||||
if (dataManagementPlanEntity != null && dataManagementPlanEntity.getStatus() == 1){
|
||||
if (dataManagementPlanEntity != null && dataManagementPlanEntity.getStatus() == 1) {
|
||||
eu.eudat.models.data.dmp.DataManagementPlan datamanagementPlan = new eu.eudat.models.data.dmp.DataManagementPlan();
|
||||
datamanagementPlan.fromDataModel(dataManagementPlanEntity);
|
||||
datamanagementPlan.setDatasets(datamanagementPlan.getDatasets().stream().filter(dataset -> dataset.getStatus() == Dataset.Status.FINALISED.getValue()).collect(Collectors.toList()));
|
||||
|
@ -346,21 +327,19 @@ public class DataManagementPlanManager {
|
|||
item.setValue(new Tuple<>(properties.get("id"), properties.get("label")));
|
||||
});
|
||||
return datamanagementPlan;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new Exception("Selected DMP is not public");
|
||||
}
|
||||
}
|
||||
|
||||
public DataManagementPlanOverviewModel getOverviewSinglePublic(String id) throws Exception{
|
||||
public DataManagementPlanOverviewModel getOverviewSinglePublic(String id) throws Exception {
|
||||
DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id));
|
||||
if (dataManagementPlanEntity != null && dataManagementPlanEntity.getStatus() == 1) {
|
||||
DataManagementPlanOverviewModel datamanagementPlan = new DataManagementPlanOverviewModel();
|
||||
datamanagementPlan.fromDataModelDatasets(dataManagementPlanEntity);
|
||||
datamanagementPlan.setDatasets(datamanagementPlan.getDatasets().stream().filter(dataset -> dataset.getStatus() == Dataset.Status.FINALISED.getValue()).collect(Collectors.toList()));
|
||||
return datamanagementPlan;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new Exception("Selected DMP is not public");
|
||||
}
|
||||
}
|
||||
|
@ -428,14 +407,14 @@ public class DataManagementPlanManager {
|
|||
|
||||
if (dmp.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()))
|
||||
newDmp.setStatus(DMP.DMPStatus.FINALISED.getValue());
|
||||
|
||||
|
||||
try {
|
||||
newDmp.setCreated(dmp.getCreated());
|
||||
if (dmp.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId())
|
||||
.collect(Collectors.toList()).size() == 0) {
|
||||
List<UserDMP> userDMPList = dmp.getUsers().stream().collect(Collectors.toList());
|
||||
for (UserInfoListingModel userInfoListingModel : dataManagementPlan.getUsers()) {
|
||||
for(UserDMP userDMP : userDMPList) {
|
||||
for (UserDMP userDMP : userDMPList) {
|
||||
if (!(userDMP.getUser().getId().equals(userInfoListingModel.getId()))) {
|
||||
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().delete(userDMP);
|
||||
}
|
||||
|
@ -450,9 +429,18 @@ public class DataManagementPlanManager {
|
|||
|
||||
if (dataManagementPlan.getStatus() == DMP.DMPStatus.FINALISED.getValue()) {
|
||||
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
|
||||
.asQueryable().where((builder, root) -> root.get("id").in(dataManagementPlan.getDatasets()
|
||||
.stream().map(x -> UUID.fromString(x.getId())).collect(Collectors.toList())))
|
||||
.asQueryable().where((builder, root) -> root.get("id").in(dataManagementPlan.getDatasetsToBeFinalized()))
|
||||
.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()) && !dataManagementPlan.getDatasetsToBeFinalized().contains(dataset.getId())) {
|
||||
datasetsToBeCanceled.add(dataset.getId());
|
||||
}
|
||||
}
|
||||
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()
|
||||
.asQueryable().where((builder, root) -> root.get("id").in(datasetsToBeCanceled))
|
||||
.update(root -> root.<Integer>get("status"), Dataset.Status.CANCELED.getValue());
|
||||
}
|
||||
|
||||
if (dataManagementPlan.getAssociatedUsers().size() == 0)
|
||||
|
@ -478,7 +466,7 @@ public class DataManagementPlanManager {
|
|||
QueryableList<DMP> dataManagementPlanQueryableList = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(criteria);
|
||||
List<DMP> latestVersionDMP = dataManagementPlanQueryableList.toList();
|
||||
|
||||
if(latestVersionDMP.get(0).getVersion().equals(oldDmp.getVersion())){
|
||||
if (latestVersionDMP.get(0).getVersion().equals(oldDmp.getVersion())) {
|
||||
DMP newDmp = dataManagementPlan.toDataModel();
|
||||
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
|
||||
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
|
||||
|
@ -528,7 +516,7 @@ public class DataManagementPlanManager {
|
|||
DatasetCriteria criteria = new DatasetCriteria();
|
||||
List<UUID> dmpIds = Collections.singletonList(uuid);
|
||||
criteria.setDmpIds(dmpIds);
|
||||
if (apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).toList().size()>0)
|
||||
if (apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(criteria).toList().size() > 0)
|
||||
throw new DMPWithDatasetsDeleteException("You cannot Remove Datamanagement Plan with Datasets");
|
||||
DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid);
|
||||
oldDmp.setStatus(DMP.DMPStatus.DELETED.getValue());
|
||||
|
@ -654,7 +642,7 @@ public class DataManagementPlanManager {
|
|||
DMPProfile dmpProfile = dmp.getProfile();
|
||||
Element dmpProfileElement = xmlDoc.createElement("dmpProfile");
|
||||
Element dmpProfileName = xmlDoc.createElement("dmpProfileName");
|
||||
if (!(dmpProfile == null)){
|
||||
if (!(dmpProfile == null)) {
|
||||
dmpProfileName.setTextContent(dmpProfile.getLabel());
|
||||
dmpProfileElement.appendChild(dmpProfileName);
|
||||
Element dmpProfileId = xmlDoc.createElement("dmpProfileId");
|
||||
|
@ -742,7 +730,7 @@ public class DataManagementPlanManager {
|
|||
return fileEnvelope;
|
||||
}
|
||||
|
||||
public ResponseEntity<byte[]> getRDAJsonDocument(String id) throws IOException {
|
||||
public ResponseEntity<byte[]> getRDAJsonDocument(String id) throws IOException {
|
||||
eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id));
|
||||
DmpRDAExportModel dmpExport = new DmpRDAExportModel().fromDataModel(dmp);
|
||||
RDAExportModel rdaExportModel = new RDAExportModel();
|
||||
|
@ -754,8 +742,7 @@ public class DataManagementPlanManager {
|
|||
File file = new File(fileName);
|
||||
try {
|
||||
mapper.writeValue(file, rdaExportModel);
|
||||
}
|
||||
catch (IOException e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
@ -775,7 +762,7 @@ public class DataManagementPlanManager {
|
|||
|
||||
public ResponseEntity<byte[]> getDocument(String id, String contentType) throws InstantiationException, IllegalAccessException, IOException {
|
||||
File file;
|
||||
switch (contentType){
|
||||
switch (contentType) {
|
||||
case "application/xml":
|
||||
file = getXmlDocument(id).getFile();
|
||||
break;
|
||||
|
@ -804,20 +791,19 @@ public class DataManagementPlanManager {
|
|||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
public List<DmpImportModel> createDmpFromXml( ApiContext apiContext, MultipartFile[] files, Principal principal) throws IOException, JAXBException, Exception {
|
||||
public List<DmpImportModel> createDmpFromXml(ApiContext apiContext, MultipartFile[] files, Principal principal) throws IOException, JAXBException, Exception {
|
||||
List<DmpImportModel> dataManagementPlans = new ArrayList<>();
|
||||
// Jaxb approach.
|
||||
JAXBContext jaxbContext;
|
||||
|
||||
for (MultipartFile multipartFile : Arrays.asList(files)){ // Gets one item from the array.
|
||||
try{
|
||||
for (MultipartFile multipartFile : Arrays.asList(files)) { // Gets one item from the array.
|
||||
try {
|
||||
InputStream in = multipartFile.getInputStream(); // Transforms item to InputStream.
|
||||
jaxbContext = JAXBContext.newInstance(DmpImportModel.class);
|
||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||
DmpImportModel dmpImportModel = (DmpImportModel)jaxbUnmarshaller.unmarshal(in);
|
||||
DmpImportModel dmpImportModel = (DmpImportModel) jaxbUnmarshaller.unmarshal(in);
|
||||
dataManagementPlans.add(dmpImportModel);
|
||||
}
|
||||
catch (IOException | JAXBException ex){
|
||||
} catch (IOException | JAXBException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// TODO Iterate through the list of dataManagmentPlans.
|
||||
|
@ -844,21 +830,21 @@ public class DataManagementPlanManager {
|
|||
project.setAbbreviation(projectImport.getAbbreviation());
|
||||
project.setDescription(projectImport.getDescription());
|
||||
List<eu.eudat.models.data.dmp.AssociatedProfile> associatedProfiles = new LinkedList<>();
|
||||
for(AssociatedProfileImportModels a : dataManagementPlans.get(0).getProfilesImportModels()) {
|
||||
for (AssociatedProfileImportModels a : dataManagementPlans.get(0).getProfilesImportModels()) {
|
||||
AssociatedProfile associatedProfile = new AssociatedProfile();
|
||||
associatedProfile.setId(a.getId());
|
||||
associatedProfile.setLabel(a.getLabel());
|
||||
associatedProfiles.add(associatedProfile);
|
||||
}
|
||||
List< eu.eudat.models.data.dmp.Organisation > organisations = new ArrayList<>();
|
||||
for(OrganisationImportModel org : dataManagementPlans.get(0).getOrganisationImportModels()) {
|
||||
List<eu.eudat.models.data.dmp.Organisation> organisations = new ArrayList<>();
|
||||
for (OrganisationImportModel org : dataManagementPlans.get(0).getOrganisationImportModels()) {
|
||||
eu.eudat.models.data.dmp.Organisation organisation = new eu.eudat.models.data.dmp.Organisation();
|
||||
organisation.setLabel(org.getOrganaisationNameImport());
|
||||
organisation.setId(org.getOrganaisationReferenceImport());
|
||||
organisations.add(organisation);
|
||||
}
|
||||
List<eu.eudat.models.data.dmp.Researcher> researchers = new LinkedList<>();
|
||||
for(ResearcherImportModels res : dataManagementPlans.get(0).getResearchersImportModels()) {
|
||||
for (ResearcherImportModels res : dataManagementPlans.get(0).getResearchersImportModels()) {
|
||||
eu.eudat.models.data.dmp.Researcher researcher = new eu.eudat.models.data.dmp.Researcher();
|
||||
researcher.setLabel(res.getResearcherImportName());
|
||||
researcher.setId(res.getResearcherImportReference());
|
||||
|
|
|
@ -37,6 +37,7 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
|
|||
private List<DynamicFieldWithValue> dynamicFields;
|
||||
private Map<String, Object> properties;
|
||||
private List<UserInfoListingModel> users;
|
||||
private List<UUID> datasetsToBeFinalized;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
|
@ -185,6 +186,13 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
|
|||
this.users = users;
|
||||
}
|
||||
|
||||
public List<UUID> getDatasetsToBeFinalized() {
|
||||
return datasetsToBeFinalized;
|
||||
}
|
||||
public void setDatasetsToBeFinalized(List<UUID> datasetsToBeFinalized) {
|
||||
this.datasetsToBeFinalized = datasetsToBeFinalized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataManagementPlanEditorModel fromDataModel(DMP entity) {
|
||||
this.id = entity.getId();
|
||||
|
|
Loading…
Reference in New Issue