Fixes bug on DMP not creating new Project when needed.
This commit is contained in:
parent
5aa87814de
commit
173ff16602
|
@ -74,7 +74,7 @@ public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDa
|
|||
}
|
||||
|
||||
public QueryableList<Project> getAuthenticated(QueryableList<Project> query, UserInfo principal) {
|
||||
query.where((builder, root) -> builder.or(builder.equal(root.get("creationUser"), principal), builder.equal(root.join("dmps").join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal.getId()))).distinct();
|
||||
query.where((builder, root) -> builder.or(builder.equal(root.get("creationUser"), principal), builder.equal(root.join("dmps", JoinType.LEFT).join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal.getId()))).distinct();
|
||||
return query;
|
||||
}
|
||||
|
||||
|
|
|
@ -142,8 +142,8 @@ public class DMPs extends BaseController {
|
|||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<DMP>> createOrUpdate(@RequestBody eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
|
||||
this.dataManagementPlanManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal);
|
||||
ResponseEntity<ResponseItem<DMP>> createOrUpdate(@RequestBody eu.eudat.models.data.dmp.DataManagementPlanEditorModel dataManagementPlanEditorModel, Principal principal) throws Exception {
|
||||
this.dataManagementPlanManager.createOrUpdate(this.getApiContext(), dataManagementPlanEditorModel, principal);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
|
||||
}
|
||||
|
||||
|
|
|
@ -417,11 +417,10 @@ public class DataManagementPlanManager {
|
|||
return result;
|
||||
}
|
||||
|
||||
public void createOrUpdate(ApiContext apiContext, DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
|
||||
public void createOrUpdate(ApiContext apiContext, DataManagementPlanEditorModel dataManagementPlan, Principal principal) throws Exception {
|
||||
|
||||
DMP newDmp = dataManagementPlan.toDataModel();
|
||||
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
|
||||
//newDmp.setCreator(user);
|
||||
|
||||
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
|
||||
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
|
||||
|
@ -878,7 +877,7 @@ public class DataManagementPlanManager {
|
|||
dm.setDynamicFields(dynamicFields); // Sets dynamicFields property.
|
||||
dm.setDefinition(dmpProfile);
|
||||
|
||||
createOrUpdate(apiContext, dm, principal);
|
||||
//createOrUpdate(apiContext, dm, principal);
|
||||
|
||||
System.out.println(dm);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,291 @@
|
|||
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.dynamicfields.DynamicFieldWithValue;
|
||||
import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.DataManagementPlanProfile;
|
||||
import eu.eudat.models.data.helpermodels.Tuple;
|
||||
import eu.eudat.models.data.listingmodels.DatasetListingModel;
|
||||
import eu.eudat.models.data.listingmodels.UserInfoListingModel;
|
||||
import eu.eudat.models.data.project.ProjectDMPEditorModel;
|
||||
import eu.eudat.models.data.userinfo.UserListingModel;
|
||||
import net.minidev.json.JSONObject;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagementPlanEditorModel> {
|
||||
private UUID id;
|
||||
private String label;
|
||||
private UUID groupId;
|
||||
private Tuple<UUID, String> profile;
|
||||
private int version;
|
||||
private int status;
|
||||
private boolean lockable;
|
||||
private String description;
|
||||
private List<DatasetListingModel> datasets;
|
||||
private List<AssociatedProfile> profiles;
|
||||
private eu.eudat.models.data.project.ProjectDMPEditorModel project;
|
||||
private List<Organisation> organisations;
|
||||
private List<Researcher> researchers;
|
||||
private List<UserListingModel> associatedUsers;
|
||||
private DataManagementPlanProfile definition;
|
||||
private eu.eudat.models.data.userinfo.UserInfo creator;
|
||||
private Date modified;
|
||||
private Date created;
|
||||
private List<DynamicFieldWithValue> dynamicFields;
|
||||
private Map<String, Object> properties;
|
||||
private List<UserInfoListingModel> users;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Tuple<UUID, String> getProfile() {
|
||||
return profile;
|
||||
}
|
||||
public void setProfile(Tuple<UUID, String> profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public UUID getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
public void setGroupId(UUID groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public List<UserListingModel> getAssociatedUsers() {
|
||||
return associatedUsers;
|
||||
}
|
||||
public void setAssociatedUsers(List<UserListingModel> associatedUsers) {
|
||||
this.associatedUsers = associatedUsers;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public List<Organisation> getOrganisations() {
|
||||
return organisations;
|
||||
}
|
||||
public void setOrganisations(List<Organisation> organizations) {
|
||||
this.organisations = organizations;
|
||||
}
|
||||
|
||||
public List<Researcher> getResearchers() {
|
||||
return researchers;
|
||||
}
|
||||
public void setResearchers(List<Researcher> researchers) {
|
||||
this.researchers = researchers;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public ProjectDMPEditorModel getProject() {
|
||||
return project;
|
||||
}
|
||||
public void setProject(ProjectDMPEditorModel project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public eu.eudat.models.data.userinfo.UserInfo getCreator() {
|
||||
return creator;
|
||||
}
|
||||
public void setCreator(eu.eudat.models.data.userinfo.UserInfo creator) {
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
public List<AssociatedProfile> getProfiles() {
|
||||
return profiles;
|
||||
}
|
||||
public void setProfiles(List<AssociatedProfile> profiles) {
|
||||
this.profiles = profiles;
|
||||
}
|
||||
|
||||
public Date getModified() {
|
||||
return modified;
|
||||
}
|
||||
public void setModified(Date modified) {
|
||||
this.modified = modified;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public DataManagementPlanProfile getDefinition() {
|
||||
return definition;
|
||||
}
|
||||
public void setDefinition(DataManagementPlanProfile definition) {
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
public Map<String, Object> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
public void setProperties(Map<String, Object> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public List<DynamicFieldWithValue> getDynamicFields() {
|
||||
return dynamicFields;
|
||||
}
|
||||
public void setDynamicFields(List<DynamicFieldWithValue> dynamicFields) {
|
||||
this.dynamicFields = dynamicFields;
|
||||
}
|
||||
|
||||
public boolean getLockable() {
|
||||
return lockable;
|
||||
}
|
||||
public void setLockable(boolean lockable) {
|
||||
this.lockable = lockable;
|
||||
}
|
||||
|
||||
public List<DatasetListingModel> getDatasets() {
|
||||
return datasets;
|
||||
}
|
||||
public void setDatasets(List<DatasetListingModel> datasets) {
|
||||
this.datasets = datasets;
|
||||
}
|
||||
|
||||
public List<UserInfoListingModel> getUsers() {
|
||||
return users;
|
||||
}
|
||||
public void setUsers(List<UserInfoListingModel> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataManagementPlanEditorModel 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.version = entity.getVersion();
|
||||
this.groupId = this.groupId == null ? null : this.groupId;
|
||||
this.label = entity.getLabel();
|
||||
this.project = new ProjectDMPEditorModel();
|
||||
this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null;
|
||||
this.project.getExistProject().fromDataModel(entity.getProject());
|
||||
this.creator = new eu.eudat.models.data.userinfo.UserInfo();
|
||||
this.groupId = entity.getGroupId();
|
||||
this.lockable = 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 -> {
|
||||
Optional<Map<String, Object>> fieldOptional = ((List<Map<String, Object>>) this.properties.get("fields")).stream().filter(field -> field.get("id").equals(item.getId().toString())).findFirst();
|
||||
if (fieldOptional.isPresent()) item.setValue(fieldOptional.get().get("value"));
|
||||
});
|
||||
}
|
||||
if (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()) {
|
||||
this.profiles = new LinkedList<>();
|
||||
for (DatasetProfile datasetProfile: entity.getAssociatedDmps()) {
|
||||
AssociatedProfile associatedProfile = new AssociatedProfile().fromData(datasetProfile);
|
||||
this.profiles.add(associatedProfile);
|
||||
}
|
||||
}
|
||||
this.datasets = entity.getDataset().stream().map(item -> new DatasetListingModel().fromDataModel(item)).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());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DMP toDataModel() throws Exception {
|
||||
DMP dataManagementPlanEntity = new DMP();
|
||||
if (this.profile != null) {
|
||||
DMPProfile dmpProfile = new DMPProfile();
|
||||
dmpProfile.setId(this.profile.getId());
|
||||
dataManagementPlanEntity.setProfile(dmpProfile);
|
||||
}
|
||||
dataManagementPlanEntity.setId(this.id);
|
||||
if (this.organisations != null && !this.organisations.isEmpty())
|
||||
dataManagementPlanEntity.setOrganisations(new HashSet<>(this.organisations.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
|
||||
if (this.researchers != null && !this.researchers.isEmpty())
|
||||
dataManagementPlanEntity.setResearchers(new HashSet<>(this.researchers.stream().map(item -> item.toDataModel()).collect(Collectors.toList())));
|
||||
dataManagementPlanEntity.setVersion(this.version);
|
||||
dataManagementPlanEntity.setLabel(this.label);
|
||||
if (this.project != null) {
|
||||
if (this.project.getExistProject() != null && this.project.getLabel() == null && this.project.getDescription() == null)
|
||||
dataManagementPlanEntity.setProject(this.project.getExistProject().toDataModel());
|
||||
else {
|
||||
Project project = new Project();
|
||||
project.setAbbreviation("");
|
||||
project.setLabel(this.project.getLabel());
|
||||
project.setReference("dmp:" + this.project.getLabel());
|
||||
project.setUri("");
|
||||
project.setDefinition("");
|
||||
project.setType(Project.ProjectType.INTERNAL.getValue());
|
||||
project.setDescription(this.project.getDescription());
|
||||
project.setStatus(Project.Status.ACTIVE.getValue());
|
||||
project.setCreated(new Date());
|
||||
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setId(this.users.stream().filter(userInfoListingModel -> ((Integer) userInfoListingModel.getRole()).equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getId());
|
||||
project.setCreationUser(userInfo);
|
||||
|
||||
dataManagementPlanEntity.setProject(project);
|
||||
}
|
||||
}
|
||||
|
||||
dataManagementPlanEntity.setStatus((short) this.status);
|
||||
dataManagementPlanEntity.setDescription(this.description);
|
||||
if (this.profiles != null) {
|
||||
Set<DatasetProfile> datasetProfiles = new HashSet<>();
|
||||
for (AssociatedProfile profile : this.profiles) {
|
||||
datasetProfiles.add(profile.toData());
|
||||
}
|
||||
dataManagementPlanEntity.setAssociatedDmps(datasetProfiles);
|
||||
}
|
||||
dataManagementPlanEntity.setProperties(this.properties != null ? JSONObject.toJSONString(this.properties) : null);
|
||||
dataManagementPlanEntity.setGroupId(this.groupId != null ? this.groupId : UUID.randomUUID());
|
||||
dataManagementPlanEntity.setModified(this.modified != null ? this.modified : new Date());
|
||||
dataManagementPlanEntity.setCreated(this.created != null ? this.created : new Date());
|
||||
if (this.dynamicFields != null)
|
||||
dataManagementPlanEntity.setDmpProperties(JSONObject.toJSONString(this.dynamicFields.stream().filter(item -> item.getValue() != null).collect(Collectors.toMap(DynamicFieldWithValue::getId, DynamicFieldWithValue::getValue))));
|
||||
|
||||
return dataManagementPlanEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHint() {
|
||||
return "fullyDetailed";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package eu.eudat.models.data.project;
|
||||
|
||||
public class ProjectDMPEditorModel {
|
||||
private Project existProject;
|
||||
private String label;
|
||||
private String description;
|
||||
|
||||
public Project getExistProject() {
|
||||
return existProject;
|
||||
}
|
||||
public void setExistProject(Project existProject) {
|
||||
this.existProject = existProject;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue