Attaches Funder on Grant model according to requirements. (Issue #145)

This commit is contained in:
gkolokythas 2019-08-23 12:15:41 +03:00
parent d635032224
commit dca2b7fe84
3 changed files with 51 additions and 32 deletions

View File

@ -86,7 +86,7 @@ public class Funder implements DataModel<eu.eudat.data.entities.Funder, Funder>
}
@Override
public eu.eudat.data.entities.Funder toDataModel() throws Exception {
public eu.eudat.data.entities.Funder toDataModel() {
eu.eudat.data.entities.Funder entity = new eu.eudat.data.entities.Funder();
entity.setId(this.id);
entity.setLabel(this.label);

View File

@ -0,0 +1,20 @@
package eu.eudat.models.data.funder;
public class FunderDMPEditorModel {
private Funder existFunder;
private String label;
public Funder getExistFunder() {
return existFunder;
}
public void setExistFunder(Funder existFunder) {
this.existFunder = existFunder;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}

View File

@ -1,9 +1,11 @@
package eu.eudat.models.data.grant;
import eu.eudat.data.entities.Funder;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.models.DataModel;
import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.files.ContentFile;
import eu.eudat.models.data.funder.FunderDMPEditorModel;
import java.util.Arrays;
import java.util.Date;
@ -14,42 +16,27 @@ import java.util.UUID;
public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
private UUID id;
private List<DataManagementPlan> dmps;
private String label;
private int type;
private String abbreviation;
private String reference;
private String uri;
private String definition;
private Date startDate;
private Date endDate;
private eu.eudat.data.entities.Grant.Status status;
private UserInfo creationUser;
private Date created;
private Date modified;
private String description;
private List<ContentFile> files;
private FunderDMPEditorModel funder;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
@ -57,7 +44,6 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
@ -65,7 +51,6 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
public List<DataManagementPlan> getDmps() {
return dmps;
}
public void setDmps(List<DataManagementPlan> dmps) {
this.dmps = dmps;
}
@ -73,7 +58,6 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
@ -81,7 +65,6 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
public String getAbbreviation() {
return abbreviation;
}
public void setAbbreviation(String abbreviation) {
this.abbreviation = abbreviation;
}
@ -89,7 +72,6 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
@ -97,7 +79,6 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
@ -105,7 +86,6 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
public String getDefinition() {
return definition;
}
public void setDefinition(String definition) {
this.definition = definition;
}
@ -113,7 +93,6 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
@ -121,7 +100,6 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
@ -129,7 +107,6 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
public short getStatus() {
return status.getValue();
}
public void setStatus(Short status) {
this.status = eu.eudat.data.entities.Grant.Status.fromInteger(status);
}
@ -137,7 +114,6 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
public UserInfo getCreationUser() {
return creationUser;
}
public void setCreationUser(UserInfo creationUser) {
this.creationUser = creationUser;
}
@ -145,7 +121,6 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
@ -153,7 +128,6 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
@ -161,7 +135,6 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@ -169,11 +142,17 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
public List<ContentFile> getFiles() {
return files;
}
public void setFiles(List<ContentFile> files) {
this.files = files;
}
public FunderDMPEditorModel getFunder() {
return funder;
}
public void setFunder(FunderDMPEditorModel funder) {
this.funder = funder;
}
@Override
public Grant fromDataModel(eu.eudat.data.entities.Grant entity) {
this.id = entity.getId();
@ -190,6 +169,10 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
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));
this.funder = new FunderDMPEditorModel();
if (entity.getFunder() != null)
this.funder.getExistFunder().fromDataModel(entity.getFunder());
return this;
}
@ -209,6 +192,22 @@ public class Grant implements DataModel<eu.eudat.data.entities.Grant, Grant> {
entity.setStatus(this.status != null ? this.getStatus() : eu.eudat.data.entities.Grant.Status.ACTIVE.getValue());
entity.setModified(new Date());
entity.setDescription(this.description);
if (this.funder != null) {
if (this.funder.getExistFunder() != null && this.funder.getLabel() == null)
entity.setFunder(this.funder.getExistFunder().toDataModel());
else {
Funder funder = new Funder();
funder.setLabel(this.funder.getLabel());
funder.setType(Funder.FunderType.INTERNAL.getValue());
funder.setReference("dmp:" + this.funder.getLabel());
funder.setDefinition("");
funder.setCreated(new Date());
funder.setStatus(Funder.Status.ACTIVE.getValue());
funder.setModified(new Date());
entity.setFunder(funder);
}
}
return entity;
}