418 lines
12 KiB
Java
418 lines
12 KiB
Java
package eu.eudat.migration.entities;
|
|
|
|
import eu.eudat.models.data.admin.composite.DatasetProfile;
|
|
import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel;
|
|
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
|
import eu.eudat.models.data.dmp.AssociatedProfile;
|
|
import eu.eudat.models.data.dmp.DataManagementPlan;
|
|
import eu.eudat.models.data.dmp.DataManagementPlanEditorModel;
|
|
import eu.eudat.models.data.dmp.Organisation;
|
|
import eu.eudat.models.data.funder.FunderDMPEditorModel;
|
|
import eu.eudat.models.data.grant.GrantDMPEditorModel;
|
|
import eu.eudat.models.data.project.ProjectDMPEditorModel;
|
|
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
|
import org.hibernate.annotations.LazyCollection;
|
|
import org.hibernate.annotations.LazyCollectionOption;
|
|
|
|
import javax.persistence.*;
|
|
import java.util.*;
|
|
|
|
@Entity
|
|
@Table(name = "plans")
|
|
public class Plan {
|
|
|
|
@Id
|
|
private Long id;
|
|
private String title;
|
|
@Column(name = "created_at")
|
|
@Temporal(TemporalType.TIMESTAMP)
|
|
private Date createdAt;
|
|
@Column(name = "updated_at")
|
|
@Temporal(TemporalType.TIMESTAMP)
|
|
private Date updatedAt;
|
|
private String identifier;
|
|
private String description;
|
|
private Visibility visibility;
|
|
@Column(name = "feedback_requested")
|
|
private Boolean feedbackRequested;
|
|
private Boolean complete;
|
|
@ManyToOne(fetch = FetchType.EAGER)
|
|
@JoinColumn(name = "org_id")
|
|
private Organization organization;
|
|
@ManyToOne(fetch = FetchType.EAGER)
|
|
@JoinColumn(name = "funder_id")
|
|
private Organization funder;
|
|
@Column(name = "start_date")
|
|
@Temporal(TemporalType.TIMESTAMP)
|
|
private Date startDate;
|
|
@Column(name = "end_date")
|
|
@Temporal(TemporalType.TIMESTAMP)
|
|
private Date endDate;
|
|
@Column(name = "grant_id")
|
|
private Long grantId;
|
|
@ManyToOne(fetch = FetchType.EAGER)
|
|
@JoinColumn(name = "api_client_id")
|
|
private ApiClient apiClient;
|
|
@ManyToOne(fetch = FetchType.EAGER)
|
|
@JoinColumn(name = "research_domain_id")
|
|
private ResearchDomain researchDomain;
|
|
@Column(name = "ethical_issues")
|
|
private Boolean ethicalIssues;
|
|
@Column(name = "ethical_issues_description")
|
|
private String ethicalIssuesDescription;
|
|
@Column(name = "ethical_issues_report")
|
|
private String ethicalIssuesReport;
|
|
@Column(name = "funding_status")
|
|
private FundingStatus fundingStatus;
|
|
@ManyToMany(cascade = CascadeType.ALL)
|
|
@JoinTable(name = "roles",
|
|
joinColumns = {@JoinColumn(name = "plan_id")},
|
|
inverseJoinColumns = {@JoinColumn(name = "user_id")}
|
|
)
|
|
@LazyCollection(LazyCollectionOption.FALSE)
|
|
private Set<User> users = new HashSet<>();
|
|
@OneToMany(cascade = CascadeType.ALL)
|
|
@JoinColumn(name = "plan_id")
|
|
@LazyCollection(LazyCollectionOption.FALSE)
|
|
private Set<Answer> answers = new HashSet<>();
|
|
|
|
public enum Visibility {
|
|
ORGANIZATION,
|
|
PUBLIC,
|
|
TEST,
|
|
PRIVATE
|
|
}
|
|
|
|
public enum FundingStatus {
|
|
PLANNED,
|
|
FUNDED,
|
|
DENIED
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "Plan{" +
|
|
"id=" + id +
|
|
", title='" + title + '\'' +
|
|
", createdAt=" + createdAt +
|
|
", updatedAt=" + updatedAt +
|
|
", identifier='" + identifier + '\'' +
|
|
", description='" + description + '\'' +
|
|
", visibility=" + visibility +
|
|
", feedbackRequested=" + feedbackRequested +
|
|
", complete=" + complete +
|
|
", organization=" + organization +
|
|
", funder=" + funder +
|
|
", startDate=" + startDate +
|
|
", endDate=" + endDate +
|
|
", grantId=" + grantId +
|
|
", apiClient=" + apiClient +
|
|
", researchDomain=" + researchDomain +
|
|
", ethicalIssues=" + ethicalIssues +
|
|
", ethicalIssuesDescription='" + ethicalIssuesDescription + '\'' +
|
|
", ethicalIssuesReport='" + ethicalIssuesReport + '\'' +
|
|
", fundingStatus=" + fundingStatus +
|
|
", users=" + users +
|
|
", answers=" + answers +
|
|
'}';
|
|
}
|
|
|
|
public Long getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(Long id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public String getTitle() {
|
|
return title;
|
|
}
|
|
|
|
public void setTitle(String title) {
|
|
this.title = title;
|
|
}
|
|
|
|
public Date getCreatedAt() {
|
|
return createdAt;
|
|
}
|
|
|
|
public void setCreatedAt(Date createdAt) {
|
|
this.createdAt = createdAt;
|
|
}
|
|
|
|
public Date getUpdatedAt() {
|
|
return updatedAt;
|
|
}
|
|
|
|
public void setUpdatedAt(Date updatedAt) {
|
|
this.updatedAt = updatedAt;
|
|
}
|
|
|
|
public String getIdentifier() {
|
|
return identifier;
|
|
}
|
|
|
|
public void setIdentifier(String identifier) {
|
|
this.identifier = identifier;
|
|
}
|
|
|
|
public String getDescription() {
|
|
return description;
|
|
}
|
|
|
|
public void setDescription(String description) {
|
|
this.description = description;
|
|
}
|
|
|
|
public Visibility getVisibility() {
|
|
return visibility;
|
|
}
|
|
|
|
public void setVisibility(Visibility visibility) {
|
|
this.visibility = visibility;
|
|
}
|
|
|
|
public Boolean getFeedbackRequested() {
|
|
return feedbackRequested;
|
|
}
|
|
|
|
public void setFeedbackRequested(Boolean feedbackRequested) {
|
|
this.feedbackRequested = feedbackRequested;
|
|
}
|
|
|
|
public Boolean getComplete() {
|
|
return complete;
|
|
}
|
|
|
|
public void setComplete(Boolean complete) {
|
|
this.complete = complete;
|
|
}
|
|
|
|
public Organization getOrganization() {
|
|
return organization;
|
|
}
|
|
|
|
public void setOrganization(Organization organization) {
|
|
this.organization = organization;
|
|
}
|
|
|
|
public Organization getFunder() {
|
|
return funder;
|
|
}
|
|
|
|
public void setFunder(Organization funder) {
|
|
this.funder = funder;
|
|
}
|
|
|
|
public Date getStartDate() {
|
|
return startDate;
|
|
}
|
|
|
|
public void setStartDate(Date startDate) {
|
|
this.startDate = startDate;
|
|
}
|
|
|
|
public Date getEndDate() {
|
|
return endDate;
|
|
}
|
|
|
|
public void setEndDate(Date endDate) {
|
|
this.endDate = endDate;
|
|
}
|
|
|
|
public Long getGrantId() {
|
|
return grantId;
|
|
}
|
|
|
|
public void setGrantId(Long grantId) {
|
|
this.grantId = grantId;
|
|
}
|
|
|
|
public ApiClient getApiClient() {
|
|
return apiClient;
|
|
}
|
|
|
|
public void setApiClient(ApiClient apiClient) {
|
|
this.apiClient = apiClient;
|
|
}
|
|
|
|
public ResearchDomain getResearchDomain() {
|
|
return researchDomain;
|
|
}
|
|
|
|
public void setResearchDomain(ResearchDomain researchDomain) {
|
|
this.researchDomain = researchDomain;
|
|
}
|
|
|
|
public Boolean getEthicalIssues() {
|
|
return ethicalIssues;
|
|
}
|
|
|
|
public void setEthicalIssues(Boolean ethicalIssues) {
|
|
this.ethicalIssues = ethicalIssues;
|
|
}
|
|
|
|
public String getEthicalIssuesDescription() {
|
|
return ethicalIssuesDescription;
|
|
}
|
|
|
|
public void setEthicalIssuesDescription(String ethicalIssuesDescription) {
|
|
this.ethicalIssuesDescription = ethicalIssuesDescription;
|
|
}
|
|
|
|
public String getEthicalIssuesReport() {
|
|
return ethicalIssuesReport;
|
|
}
|
|
|
|
public void setEthicalIssuesReport(String ethicalIssuesReport) {
|
|
this.ethicalIssuesReport = ethicalIssuesReport;
|
|
}
|
|
|
|
public FundingStatus getFundingStatus() {
|
|
return fundingStatus;
|
|
}
|
|
|
|
public void setFundingStatus(FundingStatus fundingStatus) {
|
|
this.fundingStatus = fundingStatus;
|
|
}
|
|
|
|
public Set<User> getUsers() {
|
|
return users;
|
|
}
|
|
|
|
public void setUsers(Set<User> users) {
|
|
this.users = users;
|
|
}
|
|
|
|
public Set<Answer> getAnswers() {
|
|
return answers;
|
|
}
|
|
|
|
public void setAnswers(Set<Answer> answers) {
|
|
this.answers = answers;
|
|
}
|
|
|
|
public DataManagementPlanEditorModel buildDMP(UUID profileId, String profileLabel,
|
|
eu.eudat.migration.properties.Entity funder,
|
|
eu.eudat.migration.properties.Entity grant) {
|
|
DataManagementPlanEditorModel dmpModel = new DataManagementPlanEditorModel();
|
|
dmpModel.setAssociatedUsers(new ArrayList<>());
|
|
dmpModel.setDatasets(new ArrayList<>());
|
|
dmpModel.setDatasetsToBeFinalized(new ArrayList<>());
|
|
dmpModel.setDescription(getDescription());
|
|
dmpModel.setDynamicFields(new ArrayList<>());
|
|
dmpModel.setExtraProperties(buildExtraProperties());
|
|
dmpModel.setFunder(buildFunder(funder));
|
|
dmpModel.setGrant(buildGrant(grant));
|
|
dmpModel.setLabel(getTitle());
|
|
dmpModel.setOrganisations(buildOrganizations());
|
|
dmpModel.setProfiles(buildProfiles(profileId, profileLabel));
|
|
dmpModel.setProject(buildProject());
|
|
dmpModel.setResearchers(new ArrayList<>());
|
|
dmpModel.setStatus(0);
|
|
return dmpModel;
|
|
}
|
|
|
|
public Map<String, Object> buildExtraProperties() {
|
|
Map<String, Object> properties = new HashMap<>();
|
|
properties.put("costs", new ArrayList<>());
|
|
properties.put("language", "en");
|
|
properties.put("publicDate", getCreatedAt());
|
|
properties.put("visible", getVisibility() == Visibility.PUBLIC);
|
|
return properties;
|
|
}
|
|
|
|
public FunderDMPEditorModel buildFunder(eu.eudat.migration.properties.Entity defaultFunder) {
|
|
FunderDMPEditorModel funder = new FunderDMPEditorModel();
|
|
if(getFunder() != null) {
|
|
funder.setLabel(getFunder().getName());
|
|
funder.setReference(getFunder().getAbbreviation());
|
|
} else {
|
|
funder.setLabel(defaultFunder.getLabel());
|
|
funder.setReference(defaultFunder.getReference());
|
|
}
|
|
return funder;
|
|
}
|
|
|
|
public GrantDMPEditorModel buildGrant(eu.eudat.migration.properties.Entity defaultGrant) {
|
|
GrantDMPEditorModel grant = new GrantDMPEditorModel();
|
|
if(getGrantId() != null) {
|
|
grant.setLabel(getGrantId().toString());
|
|
grant.setReference(getGrantId().toString());
|
|
grant.setDescription(getGrantId().toString());
|
|
} else {
|
|
grant.setLabel(defaultGrant.getLabel());
|
|
grant.setReference(defaultGrant.getReference());
|
|
grant.setDescription(defaultGrant.getDescription());
|
|
}
|
|
return grant;
|
|
}
|
|
|
|
public List<Organisation> buildOrganizations() {
|
|
if(getOrganization() != null) {
|
|
Organisation organisation = new Organisation();
|
|
organisation.setLabel(getOrganization().getName());
|
|
organisation.setReference("Internal:" + getOrganization().getAbbreviation());
|
|
organisation.setKey("Internal");
|
|
return Collections.singletonList(organisation);
|
|
} else {
|
|
return new ArrayList<>();
|
|
}
|
|
}
|
|
|
|
public List<AssociatedProfile> buildProfiles(UUID id, String label) {
|
|
AssociatedProfile profile = new AssociatedProfile();
|
|
profile.setId(id);
|
|
profile.setLabel(label);
|
|
return Collections.singletonList(profile);
|
|
}
|
|
|
|
public ProjectDMPEditorModel buildProject() {
|
|
return new ProjectDMPEditorModel();
|
|
}
|
|
|
|
public DatasetWizardModel buildDataset(UUID profileId, String profileLabel, DataManagementPlan dmp, PagedDatasetProfile pagedDatasetProfile) {
|
|
DatasetWizardModel datasetModel = new DatasetWizardModel();
|
|
datasetModel.setDataRepositories(new ArrayList<>());
|
|
buildPagedDatasetProfile(pagedDatasetProfile);
|
|
datasetModel.setDatasetProfileDefinition(pagedDatasetProfile);
|
|
datasetModel.setDescription(this.getDescription());
|
|
datasetModel.setDmp(dmp);
|
|
datasetModel.setExternalDatasets(new ArrayList<>());
|
|
datasetModel.setLabel(this.getTitle());
|
|
DatasetProfileOverviewModel profile = new DatasetProfileOverviewModel();
|
|
profile.setId(profileId);
|
|
profile.setLabel(profileLabel);
|
|
datasetModel.setProfile(profile);
|
|
datasetModel.setRegistries(new ArrayList<>());
|
|
datasetModel.setServices(new ArrayList<>());
|
|
datasetModel.setTags(new ArrayList<>());
|
|
return datasetModel;
|
|
}
|
|
|
|
public void buildPagedDatasetProfile(PagedDatasetProfile pagedDatasetProfile) {
|
|
pagedDatasetProfile.getPages().forEach(page -> {
|
|
page.getSections().forEach(section -> {
|
|
section.getCompositeFields().forEach(compositeField -> {
|
|
compositeField.getFields().forEach(field -> {
|
|
Long questionId = Question.fieldsQuestionsMap.get(field.getId());
|
|
if( questionId != null) {
|
|
Optional<Answer> optionalAnswer = answers.stream().filter(answer -> answer.getQuestion().getId().equals(questionId)).findFirst();
|
|
optionalAnswer.ifPresent(answer -> {
|
|
if(answer.getQuestion().getQuestionFormat().getOptionBased()) {
|
|
/* TODO check with real data */
|
|
field.setValue(answer.getText());
|
|
} else {
|
|
field.setValue(answer.getText());
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
}
|