Fixes bug at DMP Wizard on creating new Grant, Funder and Project.

This commit is contained in:
gkolokythas 2019-12-12 14:02:52 +02:00
parent 7d6790b225
commit 9dbf57be03
8 changed files with 68 additions and 38 deletions

View File

@ -3,11 +3,13 @@ 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.managers.DatasetManager;
import eu.eudat.logic.managers.QuickWizardManager;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.quickwizard.DatasetCreateWizardModel;
import eu.eudat.models.data.quickwizard.DatasetDescriptionQuickWizardModel;
import eu.eudat.models.data.quickwizard.QuickWizardModel;
import eu.eudat.models.data.security.Principal;
@ -16,7 +18,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import eu.eudat.models.data.quickwizard.DatasetCreateWizardModel;
import javax.transaction.Transactional;
import javax.validation.Valid;
@ -47,7 +48,6 @@ public class QuickWizardController extends BaseController {
if (quickWizard.getFunder() == null) {
throw new Exception("Funder is a mandatory entity");
} else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() == null) {
// funderEntity = null;
throw new Exception("Funder is a mandatory entity");
} else if (quickWizard.getFunder().getExistFunder() == null && quickWizard.getFunder().getLabel() != null) {
funderEntity = this.quickWizardManager.createOrUpdate(quickWizard.getFunder().toDataFunder(), principal);
@ -57,7 +57,11 @@ public class QuickWizardController extends BaseController {
eu.eudat.data.entities.Grant grantEntity;
//Create Grant
if (quickWizard.getGrant().getExistGrant() == null) {
if (quickWizard.getGrant() == null) {
throw new Exception("Grant is a mandatory entity");
} else if (quickWizard.getGrant().getExistGrant() == null && quickWizard.getGrant().getLabel() == null) {
throw new Exception("Grant is a mandatory entity");
} else if (quickWizard.getGrant().getExistGrant() == null) {
grantEntity = this.quickWizardManager.createOrUpdate(quickWizard.getGrant().toDataGrant(), principal);
} else {
grantEntity = quickWizard.getGrant().getExistGrant().toDataModel();
@ -68,17 +72,15 @@ public class QuickWizardController extends BaseController {
if (quickWizard.getProject().getExistProject() == null
&& quickWizard.getProject().getLabel() == null) {
projectEntity = null;
} else if (quickWizard.getProject().getExistProject() == null && quickWizard.getProject().getLabel() != null){
} else if (quickWizard.getProject().getExistProject() == null && quickWizard.getProject().getLabel() != 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, projectEntity, principal),
funderEntity,
principal);
DataManagementPlan dataManagementPlan = quickWizard.getDmp().toDataDmp(grantEntity, projectEntity, principal);
eu.eudat.data.entities.DMP dmpEntity = this.quickWizardManager.createOrUpdate(dataManagementPlan, funderEntity, principal);
//Create Datasets
quickWizard.getDmp().setId(dmpEntity.getId());

View File

@ -13,6 +13,7 @@ import org.springframework.stereotype.Component;
import java.io.IOException;
import java.text.ParseException;
import java.util.UUID;
@Component
public class QuickWizardManager {
@ -109,6 +110,7 @@ public class QuickWizardManager {
eu.eudat.data.entities.Project projectEntity = databaseRepository.getProjectDao().getWithCritetia(criteria).getSingleOrDefault();
if (projectEntity != null) project.setId(projectEntity.getId());
else {
if (project.getId() == null) project.setId(UUID.randomUUID());
project.setType(Project.ProjectType.EXTERNAL.getValue());
databaseRepository.getProjectDao().createOrUpdate(project);
}

View File

@ -90,22 +90,28 @@ public class Funder implements DataModel<eu.eudat.data.entities.Funder, Funder>
this.status = entity.getStatus();
this.created = entity.getCreated();
this.modified = entity.getModified();
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source.equals("dmp")) {
this.source = "Internal";
} else {
this.source = source;
if (entity.getReference() != null) {
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source.equals("dmp")) {
this.source = "Internal";
} else {
this.source = source;
}
}
return this;
}
@Override
public eu.eudat.data.entities.Funder toDataModel() {
eu.eudat.data.entities.Funder entity = new eu.eudat.data.entities.Funder();
entity.setId(this.id);
entity.setId(UUID.randomUUID());
entity.setLabel(this.label);
entity.setType(this.type);
if (this.source != null && this.source.equals("Internal")) this.source = "dmp";
if (this.source == null && this.reference != null && this.reference.startsWith("dmp:")) {
entity.setReference(this.reference);
}
if (this.reference != null && !this.reference.trim().isEmpty()
&& this.source != null && !this.source.trim().isEmpty()) {
if (this.source.equals(this.reference.substring(0, this.source.length()))) {

View File

@ -177,11 +177,13 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
this.files = entity.getContent() != null ? Arrays.asList(new ContentFile(entity.getContent().getLabel(), UUID.fromString(entity.getContent().getUri().split(":")[1]), "final", entity.getContent().getExtension())) : Arrays.asList(new ContentFile("default.png", null, null, null));
if (entity.getFunder() != null)
this.funderId = entity.getFunder().getId();
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source.equals("dmp")) {
this.source = "Internal";
} else {
this.source = source;
if (entity.getReference() != null) {
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source.equals("dmp")) {
this.source = "Internal";
} else {
this.source = source;
}
}
return this;
@ -190,11 +192,14 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
@Override
public eu.eudat.data.entities.Grant toDataModel() {
eu.eudat.data.entities.Grant entity = new eu.eudat.data.entities.Grant();
entity.setId(this.id);
entity.setId(UUID.randomUUID());
entity.setAbbreviation(this.abbreviation);
entity.setLabel(this.label);
entity.setType(this.type);
if (this.source != null && this.source.equals("Internal")) this.source = "dmp";
if (this.source == null && this.reference != null && this.reference.startsWith("dmp:")) {
entity.setReference(this.reference);
}
if (this.reference != null && !this.reference.trim().isEmpty()
&& this.source != null && !this.source.trim().isEmpty()) {
if (this.source.equals(this.reference.substring(0, this.source.length()))) {

View File

@ -165,23 +165,29 @@ public class Project implements DataModel<eu.eudat.data.entities.Project, Projec
this.modified = entity.getModified();
this.description = entity.getDescription();
this.files = entity.getContent() != null ? Arrays.asList(new ContentFile(entity.getContent().getLabel(), UUID.fromString(entity.getContent().getUri().split(":")[1]), "final", entity.getContent().getExtension())) : Arrays.asList(new ContentFile("default.png", null, null, null));
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source.equals("dmp")) {
this.source = "Internal";
} else {
this.source = source;
if (entity.getReference() != null) {
String source = entity.getReference().substring(0, entity.getReference().indexOf(":"));
if (source.equals("dmp")) {
this.source = "Internal";
} else {
this.source = source;
}
}
return this;
}
@Override
public eu.eudat.data.entities.Project toDataModel() {
eu.eudat.data.entities.Project entity = new eu.eudat.data.entities.Project();
entity.setId(this.id);
entity.setId(UUID.randomUUID());
entity.setAbbreviation(this.abbreviation);
entity.setLabel(this.label);
entity.setType(this.type);
if (this.source != null && this.source.equals("Internal")) this.source = "dmp";
if (this.source == null && this.reference != null && this.reference.startsWith("dmp:")) {
entity.setReference(this.reference);
}
if (this.reference != null && !this.reference.trim().isEmpty()
&& this.source != null && !this.source.trim().isEmpty()) {
if (this.source.equals(this.reference.substring(0, this.source.length()))) {

View File

@ -2,6 +2,8 @@ package eu.eudat.models.data.quickwizard;
import eu.eudat.models.data.funder.Funder;
import java.util.UUID;
public class FunderQuickWizardModel {
private String label;
private Funder existFunder;
@ -22,8 +24,9 @@ public class FunderQuickWizardModel {
public Funder toDataFunder() {
Funder toFunder = new Funder();
toFunder.setId(UUID.randomUUID());
toFunder.setLabel(this.label);
toFunder.setReference("dmp:" + this.label);
toFunder.setReference("dmp:" + toFunder.getId());
toFunder.setDefinition("");
toFunder.setType(eu.eudat.data.entities.Funder.FunderType.INTERNAL.getValue());
return toFunder;

View File

@ -3,6 +3,8 @@ package eu.eudat.models.data.quickwizard;
import eu.eudat.models.data.grant.Grant;
import java.util.UUID;
public class GrantQuickWizardModel {
private String label;
private String description;
@ -33,14 +35,15 @@ public class GrantQuickWizardModel {
this.existGrant = existGrant;
}
public eu.eudat.models.data.grant.Grant toDataGrant(){
eu.eudat.models.data.grant.Grant toGrant = new eu.eudat.models.data.grant.Grant();
toGrant.setAbbreviation("");
toGrant.setLabel(this.label);
toGrant.setReference("dmp:" + this.label);
toGrant.setUri("");
toGrant.setDefinition("");
toGrant.setDescription(this.description);
return toGrant;
public eu.eudat.models.data.grant.Grant toDataGrant() {
eu.eudat.models.data.grant.Grant toGrant = new eu.eudat.models.data.grant.Grant();
toGrant.setId(UUID.randomUUID());
toGrant.setAbbreviation("");
toGrant.setLabel(this.label);
toGrant.setReference("dmp:" + toGrant.getId());
toGrant.setUri("");
toGrant.setDefinition("");
toGrant.setDescription(this.description);
return toGrant;
}
}

View File

@ -2,6 +2,8 @@ package eu.eudat.models.data.quickwizard;
import eu.eudat.models.data.project.Project;
import java.util.UUID;
public class ProjectQuickWizardModel {
private String label;
private String description;
@ -30,9 +32,10 @@ public class ProjectQuickWizardModel {
public Project toDataProject() {
Project toProject = new Project();
toProject.setId(UUID.randomUUID());
toProject.setAbbreviation("");
toProject.setLabel(this.label);
toProject.setReference("dmp:" + this.label);
toProject.setReference("dmp:" + toProject.getId());
toProject.setUri("");
toProject.setDefinition("");
toProject.setDescription(this.description);