Adds logic and models for DMP's quick wizard Funder and Project, on backend.
This commit is contained in:
parent
6f6ee9876b
commit
5c1df31d88
|
@ -1,6 +1,8 @@
|
|||
package eu.eudat.controllers;
|
||||
|
||||
|
||||
import eu.eudat.data.entities.Funder;
|
||||
import eu.eudat.data.entities.Project;
|
||||
import eu.eudat.logic.managers.*;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
||||
|
@ -26,24 +28,28 @@ import java.util.UUID;
|
|||
public class QuickWizardController extends BaseController {
|
||||
|
||||
private QuickWizardManager quickWizardManager;
|
||||
private GrantManager grantManager;
|
||||
|
||||
|
||||
private DatasetManager datasetManager;
|
||||
|
||||
@Autowired
|
||||
public QuickWizardController(ApiContext apiContext, QuickWizardManager quickWizardManager, DatasetManager datasetManager, GrantManager grantManager) {
|
||||
public QuickWizardController(ApiContext apiContext, QuickWizardManager quickWizardManager, DatasetManager datasetManager) {
|
||||
super(apiContext);
|
||||
this.quickWizardManager = quickWizardManager;
|
||||
this.datasetManager = datasetManager;
|
||||
this.grantManager = grantManager;
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<QuickWizardModel>> addQuickWizardModel(@Valid @RequestBody QuickWizardModel quickWizard, Principal principal) throws Exception {
|
||||
|
||||
Funder funderEntity;
|
||||
//Create Funder
|
||||
if (quickWizard.getFunder().getExistFunder() == null) {
|
||||
funderEntity = this.quickWizardManager.createOrUpdate(quickWizard.getFunder().toDataFunder(), principal);
|
||||
} else {
|
||||
funderEntity = quickWizard.getFunder().getExistFunder().toDataModel();
|
||||
}
|
||||
|
||||
eu.eudat.data.entities.Grant grantEntity;
|
||||
//Create Grant
|
||||
if (quickWizard.getGrant().getExistGrant() == null) {
|
||||
|
@ -51,17 +57,26 @@ public class QuickWizardController extends BaseController {
|
|||
} else {
|
||||
grantEntity = quickWizard.getGrant().getExistGrant().toDataModel();
|
||||
}
|
||||
//grantEntity.setFunder(funderEntity);
|
||||
|
||||
Project projectEntity;
|
||||
//Create Project
|
||||
if (quickWizard.getProject().getExistProject() == null) {
|
||||
projectEntity = this.quickWizardManager.createOrUpdate(quickWizard.getProject().toDataProject(), principal);
|
||||
} else {
|
||||
projectEntity = quickWizard.getProject().getExistProject().toDataModel();
|
||||
}
|
||||
|
||||
//Create Dmp
|
||||
eu.eudat.data.entities.DMP dmpEntity = this.quickWizardManager.createOrUpdate(
|
||||
quickWizard.getDmp().toDataDmp(
|
||||
grantEntity,
|
||||
principal),
|
||||
quickWizard.getDmp().toDataDmp(grantEntity, projectEntity, principal),
|
||||
funderEntity,
|
||||
principal);
|
||||
|
||||
//Create Datasets
|
||||
quickWizard.getDmp().setId(dmpEntity.getId());
|
||||
for (DatasetDescriptionQuickWizardModel dataset : quickWizard.getDatasets().getDatasetsList()) {
|
||||
DataManagementPlan dmp = quickWizard.getDmp().toDataDmp( grantEntity, principal);
|
||||
DataManagementPlan dmp = quickWizard.getDmp().toDataDmp(grantEntity, projectEntity, principal);
|
||||
UUID uuid = quickWizard.getDmp().getDatasetProfile().getId();
|
||||
DatasetWizardModel datasetWizardModel = dataset.toDataModel(dmp, uuid);
|
||||
this.datasetManager.createOrUpdate(datasetWizardModel, principal);
|
||||
|
|
|
@ -114,7 +114,9 @@ public class GrantManager {
|
|||
FunderCriteria funderCriteria = new FunderCriteria();
|
||||
funderCriteria.setReference(grantCriteria.getCriteria().getFunderReference());
|
||||
Funder funder = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getWithCritetia(funderCriteria).getSingleOrDefault();
|
||||
grantCriteria.getCriteria().setFunderId(funder.getId().toString());
|
||||
if (funder != null) {
|
||||
grantCriteria.getCriteria().setFunderId(funder.getId().toString());
|
||||
}
|
||||
}
|
||||
grantCriteria.getCriteria().setReference("dmp:");
|
||||
QueryableList<eu.eudat.data.entities.Grant> items = apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().getWithCriteria(grantCriteria.getCriteria());
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package eu.eudat.logic.managers;
|
||||
|
||||
import eu.eudat.data.dao.criteria.FunderCriteria;
|
||||
import eu.eudat.data.dao.criteria.GrantCriteria;
|
||||
import eu.eudat.data.dao.criteria.ProjectCriteria;
|
||||
import eu.eudat.data.entities.*;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||
|
@ -24,20 +26,35 @@ public class QuickWizardManager {
|
|||
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
||||
}
|
||||
|
||||
public Funder createOrUpdate(eu.eudat.models.data.funder.Funder funder, Principal principal) {
|
||||
Funder funderEntity = funder.toDataModel();
|
||||
return databaseRepository.getFunderDao().createOrUpdate(funderEntity);
|
||||
}
|
||||
|
||||
public Grant createOrUpdate(eu.eudat.models.data.grant.Grant grant, Principal principal) throws ParseException, IOException {
|
||||
eu.eudat.data.entities.Grant grantEntity = grant.toDataModel();
|
||||
grantEntity.setType(eu.eudat.data.entities.Grant.GrantType.INTERNAL.getValue());
|
||||
grantEntity.setCreationUser(databaseRepository.getUserInfoDao().find(principal.getId()));
|
||||
Grant grantEntityRet = databaseRepository.getGrantDao().createOrUpdate(grantEntity);
|
||||
return grantEntityRet;
|
||||
return databaseRepository.getGrantDao().createOrUpdate(grantEntity);
|
||||
}
|
||||
|
||||
public DMP createOrUpdate(DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
|
||||
public Project createOrUpdate(eu.eudat.models.data.project.Project project, Principal principal) {
|
||||
Project projectEntity = project.toDataModel();
|
||||
projectEntity.setCreationUser(databaseRepository.getUserInfoDao().find(principal.getId()));
|
||||
return databaseRepository.getProjectDao().createOrUpdate(projectEntity);
|
||||
}
|
||||
|
||||
public DMP createOrUpdate(DataManagementPlan dataManagementPlan, Funder funderEntity, Principal principal) throws Exception {
|
||||
DMP newDmp = dataManagementPlan.toDataModel();
|
||||
if (funderEntity != null) {
|
||||
newDmp.getGrant().setFunder(funderEntity);
|
||||
}
|
||||
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
|
||||
createFunderIfItDoesntExist(newDmp, user);
|
||||
createGrantIfItDoesntExist(newDmp, user);
|
||||
//newDmp.setCreator(user);
|
||||
DMP dmpret = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
|
||||
createProjectIfItDoesntExist(newDmp, user);
|
||||
apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant());
|
||||
DMP dmpret = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
|
||||
if (dataManagementPlan.getAssociatedUsers().size() == 0)
|
||||
assignUser(newDmp, user, apiContext);
|
||||
return dmpret;
|
||||
|
@ -64,4 +81,32 @@ public class QuickWizardManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createFunderIfItDoesntExist(DMP newDmp, UserInfo userInfo) {
|
||||
if (newDmp.getGrant().getFunder() != null) {
|
||||
Funder funder = newDmp.getGrant().getFunder();
|
||||
FunderCriteria criteria = new FunderCriteria();
|
||||
criteria.setReference(funder.getReference());
|
||||
eu.eudat.data.entities.Funder funderEntity = databaseRepository.getFunderDao().getWithCritetia(criteria).getSingleOrDefault();
|
||||
if (funderEntity != null) funder.setId(funderEntity.getId());
|
||||
else {
|
||||
funder.setType(Funder.FunderType.EXTERNAL.getValue());
|
||||
databaseRepository.getFunderDao().createOrUpdate(funder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createProjectIfItDoesntExist(DMP newDmp, UserInfo userInfo) {
|
||||
if (newDmp.getProject() != null) {
|
||||
Project project = newDmp.getProject();
|
||||
ProjectCriteria criteria = new ProjectCriteria();
|
||||
criteria.setReference(project.getReference());
|
||||
eu.eudat.data.entities.Project projectEntity = databaseRepository.getProjectDao().getWithCritetia(criteria).getSingleOrDefault();
|
||||
if (projectEntity != null) project.setId(projectEntity.getId());
|
||||
else {
|
||||
project.setType(Project.ProjectType.EXTERNAL.getValue());
|
||||
databaseRepository.getProjectDao().createOrUpdate(project);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -283,6 +283,9 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
|
|||
if (this.grant != null) dataManagementPlanEntity.setGrant(this.grant.toDataModel());
|
||||
dataManagementPlanEntity.setStatus((short) this.status);
|
||||
dataManagementPlanEntity.setDescription(this.description);
|
||||
if (this.project != null) {
|
||||
dataManagementPlanEntity.setProject(this.project.toDataModel());
|
||||
}
|
||||
if (this.profiles != null) {
|
||||
Set<DatasetProfile> datasetProfiles = new HashSet<>();
|
||||
for (AssociatedProfile profile : this.profiles) {
|
||||
|
|
|
@ -161,7 +161,7 @@ public class Project implements DataModel<eu.eudat.data.entities.Project, Projec
|
|||
}
|
||||
|
||||
@Override
|
||||
public eu.eudat.data.entities.Project toDataModel() throws Exception {
|
||||
public eu.eudat.data.entities.Project toDataModel() {
|
||||
eu.eudat.data.entities.Project entity = new eu.eudat.data.entities.Project();
|
||||
entity.setId(this.id);
|
||||
entity.setAbbreviation(this.abbreviation);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.eudat.models.data.quickwizard;
|
||||
|
||||
import eu.eudat.data.entities.Grant;
|
||||
import eu.eudat.data.entities.Project;
|
||||
import eu.eudat.models.data.dmp.AssociatedProfile;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.models.data.userinfo.UserListingModel;
|
||||
|
@ -64,7 +65,7 @@ public class DmpQuickWizardModel {
|
|||
this.grant = grant;
|
||||
}
|
||||
|
||||
public eu.eudat.models.data.dmp.DataManagementPlan toDataDmp(Grant grant, Principal principal) {
|
||||
public eu.eudat.models.data.dmp.DataManagementPlan toDataDmp(Grant grant, Project project, Principal principal) {
|
||||
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlanEntity = new eu.eudat.models.data.dmp.DataManagementPlan();
|
||||
|
||||
dataManagementPlanEntity.setId(this.id);
|
||||
|
@ -75,6 +76,10 @@ public class DmpQuickWizardModel {
|
|||
eu.eudat.models.data.grant.Grant importGrant = new eu.eudat.models.data.grant.Grant();
|
||||
dataManagementPlanEntity.setGrant(importGrant.fromDataModel(grant));
|
||||
}
|
||||
if (project != null) {
|
||||
eu.eudat.models.data.project.Project importProject = new eu.eudat.models.data.project.Project();
|
||||
dataManagementPlanEntity.setProject(importProject.fromDataModel(project));
|
||||
}
|
||||
if (this.datasetProfile != null) {
|
||||
List<AssociatedProfile> assProfile = new LinkedList<>();
|
||||
assProfile.add(this.datasetProfile);
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package eu.eudat.models.data.quickwizard;
|
||||
|
||||
import eu.eudat.models.data.funder.Funder;
|
||||
|
||||
public class FunderQuickWizardModel {
|
||||
private String label;
|
||||
private Funder existFunder;
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public Funder getExistFunder() {
|
||||
return existFunder;
|
||||
}
|
||||
public void setExistFunder(Funder existFunder) {
|
||||
this.existFunder = existFunder;
|
||||
}
|
||||
|
||||
public Funder toDataFunder() {
|
||||
Funder toFunder = new Funder();
|
||||
toFunder.setLabel(this.label);
|
||||
toFunder.setReference("dmp:" + this.label);
|
||||
toFunder.setDefinition("");
|
||||
toFunder.setType(eu.eudat.data.entities.Funder.FunderType.INTERNAL.getValue());
|
||||
return toFunder;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package eu.eudat.models.data.quickwizard;
|
||||
|
||||
import eu.eudat.models.data.project.Project;
|
||||
|
||||
public class ProjectQuickWizardModel {
|
||||
private String label;
|
||||
private String description;
|
||||
private Project 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;
|
||||
}
|
||||
|
||||
public Project getExistProject() {
|
||||
return existProject;
|
||||
}
|
||||
public void setExistProject(Project existProject) {
|
||||
this.existProject = existProject;
|
||||
}
|
||||
|
||||
public Project toDataProject() {
|
||||
Project toProject = new Project();
|
||||
toProject.setAbbreviation("");
|
||||
toProject.setLabel(this.label);
|
||||
toProject.setReference("dmp:" + this.label);
|
||||
toProject.setUri("");
|
||||
toProject.setDefinition("");
|
||||
toProject.setDescription(this.description);
|
||||
return toProject;
|
||||
}
|
||||
}
|
|
@ -3,11 +3,20 @@ package eu.eudat.models.data.quickwizard;
|
|||
|
||||
public class QuickWizardModel {
|
||||
|
||||
private FunderQuickWizardModel funder;
|
||||
private GrantQuickWizardModel grant;
|
||||
private ProjectQuickWizardModel project;
|
||||
private DmpQuickWizardModel dmp;
|
||||
private DatasetQuickWizardModel datasets;
|
||||
private int status;
|
||||
|
||||
public FunderQuickWizardModel getFunder() {
|
||||
return funder;
|
||||
}
|
||||
public void setFunder(FunderQuickWizardModel funder) {
|
||||
this.funder = funder;
|
||||
}
|
||||
|
||||
public GrantQuickWizardModel getGrant() {
|
||||
return grant;
|
||||
}
|
||||
|
@ -15,6 +24,13 @@ public class QuickWizardModel {
|
|||
this.grant = grant;
|
||||
}
|
||||
|
||||
public ProjectQuickWizardModel getProject() {
|
||||
return project;
|
||||
}
|
||||
public void setProject(ProjectQuickWizardModel project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public DmpQuickWizardModel getDmp() {
|
||||
return dmp;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue