Allow to create or update DMP and it's datasets with one endpoint (post full)

This commit is contained in:
George Kalampokis 2020-07-27 13:09:30 +03:00
parent ca4525238e
commit 22493569fa
6 changed files with 113 additions and 36 deletions

View File

@ -210,7 +210,15 @@ public class DMPs extends BaseController {
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<UUID>> createOrUpdate(@RequestBody eu.eudat.models.data.dmp.DataManagementPlanEditorModel dataManagementPlanEditorModel, Principal principal) throws Exception {
DMP dmp = this.dataManagementPlanManager.createOrUpdate(this.getApiContext(), dataManagementPlanEditorModel, principal);
DMP dmp = this.dataManagementPlanManager.createOrUpdate(dataManagementPlanEditorModel, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(dmp.getId()));
}
@Transactional
@RequestMapping(method = RequestMethod.POST, path = "full", consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<UUID>> createOrUpdateWithDatasets(@RequestBody eu.eudat.models.data.dmp.DataManagementPlanEditorModel dataManagementPlanEditorModel, Principal principal) throws Exception {
DMP dmp = this.dataManagementPlanManager.createOrUpdateWithDatasets(dataManagementPlanEditorModel, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(dmp.getId()));
}
@ -261,7 +269,8 @@ public class DMPs extends BaseController {
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."));
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(e.getMessage()));
logger.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to make Data Management Plan public."));
}
}
@ -272,7 +281,8 @@ public class DMPs extends BaseController {
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()));
logger.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to finalize Data Management Plan."));
}
}
@ -283,7 +293,8 @@ public class DMPs extends BaseController {
this.dataManagementPlanManager.undoFinalize(UUID.fromString(id), principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Data Datamanagement Plan made active."));
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message(e.getMessage()));
logger.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DMP>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to unfinalize the Data Management Plan."));
}
}
@ -312,7 +323,7 @@ public class DMPs extends BaseController {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully created DOI for Data Datamanagement Plan in question.").payload(zenodoDOI));
} catch (Exception e) {
logger.error(e.getMessage(), e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<String>().status(ApiMessageCode.ERROR_MESSAGE).message(e.getMessage()));
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<String>().status(ApiMessageCode.ERROR_MESSAGE).message("Failed to create DOI for the Data Management Plan."));
}
}

View File

@ -208,6 +208,15 @@ public class DataManagementPlanManager {
throw new ForbiddenException("Selected DMP is not public");
}
dataManagementPlan.fromDataModel(dataManagementPlanEntity);
List<Dataset> datasetEnities = new ArrayList<>(dataManagementPlanEntity.getDataset());
for (int i = 0; i < datasetEnities.size(); i++) {
for (int j = i; j < dataManagementPlan.getDatasets().size(); j++) {
if (dataManagementPlan.getDatasets().get(j).getId().equals(datasetEnities.get(i).getId())) {
dataManagementPlan.getDatasets().get(j).setDatasetProfileDefinition(datasetManager.getPagedProfile(dataManagementPlan.getDatasets().get(j), datasetEnities.get(i)));
break;
}
}
}
if (isPublic) {
dataManagementPlan.setDatasets(dataManagementPlan.getDatasets().stream().filter(dataset -> dataset.getStatus() == Dataset.Status.FINALISED.getValue()).collect(Collectors.toList()));
}
@ -333,7 +342,7 @@ public class DataManagementPlanManager {
* Data Management
* */
public DMP createOrUpdate(ApiContext apiContext, DataManagementPlanEditorModel dataManagementPlan, Principal principal) throws Exception {
public DMP createOrUpdate(DataManagementPlanEditorModel dataManagementPlan, Principal principal) throws Exception {
boolean setNotification = false;
if (dataManagementPlan.getId() != null) {
DMP dmp1 = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId());
@ -412,9 +421,9 @@ public class DataManagementPlanManager {
.update(root -> root.<Integer>get("status"), Dataset.Status.FINALISED.getValue());
List<UUID> datasetsToBeCanceled = new LinkedList<>();
for (DatasetListingModel dataset : dataManagementPlan.getDatasets()) {
if (!(dataset.getStatus() == (int) Dataset.Status.FINALISED.getValue()) && !dataManagementPlan.getDatasetsToBeFinalized().contains(UUID.fromString(dataset.getId()))) {
datasetsToBeCanceled.add(UUID.fromString(dataset.getId()));
for (DatasetWizardModel dataset : dataManagementPlan.getDatasets()) {
if (!(dataset.getStatus() == (int) Dataset.Status.FINALISED.getValue()) && !dataManagementPlan.getDatasetsToBeFinalized().contains(dataset.getId())) {
datasetsToBeCanceled.add(UUID.fromString(dataset.getId().toString()));
}
}
if (!datasetsToBeCanceled.isEmpty())
@ -423,9 +432,9 @@ public class DataManagementPlanManager {
.update(root -> root.<Integer>get("status"), Dataset.Status.CANCELED.getValue());
} else {
List<UUID> datasetsToBeCanceled = new LinkedList<>();
for (DatasetListingModel dataset : dataManagementPlan.getDatasets()) {
for (DatasetWizardModel dataset : dataManagementPlan.getDatasets()) {
if (!(dataset.getStatus() == (int) Dataset.Status.FINALISED.getValue())) {
datasetsToBeCanceled.add(UUID.fromString(dataset.getId()));
datasetsToBeCanceled.add(dataset.getId());
}
}
if (!datasetsToBeCanceled.isEmpty())
@ -451,6 +460,20 @@ public class DataManagementPlanManager {
return newDmp;
}
public DMP createOrUpdateWithDatasets(DataManagementPlanEditorModel dataManagementPlan, Principal principal) throws Exception {
List<Dataset> datasets = new ArrayList<>();
DMP tempDMP = dataManagementPlan.toDataModel();
for (DatasetWizardModel datasetWizardModel: dataManagementPlan.getDatasets()) {
datasetWizardModel.setDmp(new DataManagementPlan().fromDataModel(tempDMP));
Dataset dataset = datasetManager.createOrUpdate(datasetWizardModel, principal);
datasets.add(dataset);
}
DMP result = createOrUpdate(dataManagementPlan, principal);
return result;
}
public void newVersion(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
DMP oldDmp = databaseRepository.getDmpDao().find(uuid);
if (!isUserOwnerOfDmp(oldDmp, principal)) {
@ -1381,7 +1404,7 @@ public class DataManagementPlanManager {
dm.setDefinition(dmpProfile);
//createOrUpdate(apiContext, dm, principal);
DMP dmp = this.createOrUpdate(apiContext, dm, principal);
DMP dmp = this.createOrUpdate(dm, principal);
if (dmp.getOrganisations() == null) {
dmp.setOrganisations(new HashSet<>());
}

View File

@ -6,7 +6,6 @@ import eu.eudat.models.DataModel;
import eu.eudat.models.data.dataset.DataRepository;
import eu.eudat.models.data.dataset.Registry;
import eu.eudat.models.data.dataset.Service;
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.externaldataset.ExternalDatasetListingModel;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
@ -191,6 +190,40 @@ public class DatasetWizardModel implements DataModel<Dataset, DatasetWizardModel
return this;
}
public DatasetWizardModel fromDataModelNoDmp(Dataset entity) {
this.id = entity.getId();
this.label = entity.getLabel();
this.status = entity.getStatus();
this.reference = entity.getReference();
this.description = entity.getDescription();
this.profile = entity.getProfile().getId();
this.uri = entity.getUri();
this.registries = entity.getRegistries() != null ? entity.getRegistries().stream().map(item -> new Registry().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
this.dataRepositories = entity.getDatasetDataRepositories() != null ? entity.getDatasetDataRepositories().stream().map(item -> {
DataRepository dataRepository = new DataRepository().fromDataModel(item.getDataRepository());
if (item.getData() != null) {
Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData());
Map<String, String> values = data.get("data");
dataRepository.setInfo(values.get("info"));
}
return dataRepository;
}).collect(Collectors.toList()) : new ArrayList<>();
this.services = entity.getServices() != null ? entity.getServices().stream().map(item -> new Service().fromDataModel(item.getService())).collect(Collectors.toList()) : new ArrayList<>();
this.created = entity.getCreated();
this.externalDatasets = entity.getDatasetExternalDatasets() != null ? entity.getDatasetExternalDatasets().stream().map(item -> {
ExternalDatasetListingModel externalDatasetListingModel = new ExternalDatasetListingModel().fromDataModel(item.getExternalDataset());
if (item.getData() != null) {
Map<String, Map<String, String>> data = (Map<String, Map<String, String>>) JSONValue.parse(item.getData());
Map<String, String> values = data.get("data");
externalDatasetListingModel.setInfo(values.get("info"));
externalDatasetListingModel.setType(Integer.parseInt(values.get("type")));
}
return externalDatasetListingModel;
}).collect(Collectors.toList()) : new ArrayList<>();
this.modified = entity.getModified();
return this;
}
@Override
public Dataset toDataModel() throws Exception {
eu.eudat.data.entities.Dataset entity = new eu.eudat.data.entities.Dataset();

View File

@ -3,6 +3,7 @@ package eu.eudat.models.data.dmp;
import eu.eudat.data.entities.*;
import eu.eudat.logic.utilities.builders.XmlBuilder;
import eu.eudat.models.DataModel;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue;
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.DataManagementPlanProfile;
import eu.eudat.models.data.funder.Funder;
@ -26,7 +27,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
private int status;
private boolean lockable;
private String description;
private List<DatasetListingModel> datasets;
private List<DatasetWizardModel> datasets;
private List<AssociatedProfile> profiles;
private Grant grant;
private List<Organisation> organisations;
@ -178,10 +179,11 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.lockable = lockable;
}
public List<DatasetListingModel> getDatasets() {
public List<DatasetWizardModel> getDatasets() {
return datasets;
}
public void setDatasets(List<DatasetListingModel> datasets) {
public void setDatasets(List<DatasetWizardModel> datasets) {
this.datasets = datasets;
}
@ -233,8 +235,8 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
public DataManagementPlan fromDataModel(DMP entity) {
this.id = entity.getId();
this.profile = entity.getProfile() != null ? new Tuple<UUID, String>(entity.getProfile().getId(), entity.getProfile().getLabel()) : null;
this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList());
this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList());
this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
this.researchers = entity.getOrganisations() != null ? entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>();
this.version = entity.getVersion();
this.groupId = this.groupId == null ? null : entity.getGroupId();
this.label = entity.getLabel();
@ -243,7 +245,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.grant.fromDataModel(entity.getGrant());
this.creator = new eu.eudat.models.data.userinfo.UserInfo();
this.groupId = entity.getGroupId();
this.lockable = entity.getDataset().stream().findAny().isPresent();
this.lockable = entity.getDataset() != null && entity.getDataset().stream().findAny().isPresent();
this.definition = entity.getProfile() == null ? null : new DataManagementPlanProfile().fromXml(XmlBuilder.fromXml(entity.getProfile().getDefinition()).getDocumentElement());
if (this.definition != null && this.definition.getFields() != null && !this.definition.getFields().isEmpty() && this.properties != null) {
this.definition.getFields().forEach(item -> {
@ -251,7 +253,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
if (fieldOptional.isPresent()) item.setValue(fieldOptional.get().get("value"));
});
}
if (entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())))
if (entity.getUsers() != null && entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())))
this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser());
if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) {
@ -261,21 +263,23 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.profiles.add(associatedProfile);
}
}
if (entity.getDataset() != null) {
if (entity.isPublic()) {
this.datasets = entity.getDataset().stream()
.filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED.getValue()) && !dataset.getStatus().equals(Dataset.Status.CANCELED.getValue()) && !dataset.getStatus().equals(Dataset.Status.SAVED.getValue()))
.map(x-> new DatasetListingModel().fromDataModel(x)).collect(Collectors.toList());
.map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList());
} else {
this.datasets = entity.getDataset().stream()
.filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED.getValue()) && !dataset.getStatus().equals(Dataset.Status.CANCELED.getValue()))
.map(x-> new DatasetListingModel().fromDataModel(x)).collect(Collectors.toList());
.map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList());
}
}
this.modified = entity.getModified();
this.created = entity.getCreated();
this.description = entity.getDescription();
this.status = entity.getStatus();
this.associatedUsers = entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList());
this.users = entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList());
this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>();
this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
this.doi = entity.getDoi();
if (entity.getProject() != null) {

View File

@ -3,6 +3,7 @@ package eu.eudat.models.data.dmp;
import eu.eudat.data.entities.*;
import eu.eudat.logic.utilities.builders.XmlBuilder;
import eu.eudat.models.DataModel;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue;
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.DataManagementPlanProfile;
import eu.eudat.models.data.funder.FunderDMPEditorModel;
@ -26,7 +27,7 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
private int status;
private boolean lockable;
private String description;
private List<DatasetListingModel> datasets;
private List<DatasetWizardModel> datasets;
private List<AssociatedProfile> profiles;
private eu.eudat.models.data.grant.GrantDMPEditorModel grant;
private List<Organisation> organisations;
@ -177,10 +178,11 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
this.lockable = lockable;
}
public List<DatasetListingModel> getDatasets() {
public List<DatasetWizardModel> getDatasets() {
return datasets;
}
public void setDatasets(List<DatasetListingModel> datasets) {
public void setDatasets(List<DatasetWizardModel> datasets) {
this.datasets = datasets;
}
@ -253,7 +255,7 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
this.profiles.add(associatedProfile);
}
}
this.datasets = entity.getDataset().stream().map(item -> new DatasetListingModel().fromDataModel(item)).collect(Collectors.toList());
this.datasets = entity.getDataset().stream().map(item -> new DatasetWizardModel().fromDataModelNoDmp(item)).collect(Collectors.toList());
this.modified = entity.getModified();
this.created = entity.getCreated();
this.description = entity.getDescription();

View File

@ -70,6 +70,10 @@ export class DmpService {
return this.http.post<String>(this.actionUrl, dataManagementPlanModel, { headers: this.headers });
}
createDmpWithDatasets(dataManagementPlanModel: DmpModel): Observable<String> {
return this.http.post<String>(this.actionUrl + 'full', dataManagementPlanModel, { headers: this.headers });
}
inactivate(id: String): Observable<DmpModel> {
return this.http.delete<DmpModel>(this.actionUrl + 'inactivate/' + id, { headers: this.headers });
}
@ -98,12 +102,12 @@ export class DmpService {
return this.http.post<DmpModel>(this.actionUrl + 'finalize/' + id, datasetsToBeFinalized, { headers: this.headers });
}
unfinalize( id: String): Observable<DmpModel> {
unfinalize(id: String): Observable<DmpModel> {
return this.http.post<DmpModel>(this.actionUrl + 'unfinalize/' + id, { headers: this.headers });
}
updateUsers(id: string, users: UserInfoListingModel[]): Observable<DmpModel> {
return this.http.post<DmpModel>(`${this.actionUrl}updateusers/${id}`, users, {headers: this.headers});
return this.http.post<DmpModel>(`${this.actionUrl}updateusers/${id}`, users, { headers: this.headers });
}
getDoi(id: string): Observable<string> {