Adds "creationUser" on Researcher entity. (Issue #168)

This commit is contained in:
gkolokythas 2019-09-30 17:42:01 +03:00
parent 09d4241df5
commit 47c2940517
6 changed files with 32 additions and 29 deletions

View File

@ -62,41 +62,34 @@ public class Researcher implements DataEntity<Researcher, UUID> {
@Convert(converter = DateToUTCConverter.class)
private Date modified = new Date();
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"CreationUser\"", nullable = true)
private UserInfo creationUser;
public Short getStatus() {
return status;
}
public void setStatus(Short status) {
this.status = status;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
@ -104,7 +97,6 @@ public class Researcher implements DataEntity<Researcher, UUID> {
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
@ -112,7 +104,6 @@ public class Researcher implements DataEntity<Researcher, UUID> {
public String getPrimaryEmail() {
return primaryEmail;
}
public void setPrimaryEmail(String primaryEmail) {
this.primaryEmail = primaryEmail;
}
@ -120,7 +111,6 @@ public class Researcher implements DataEntity<Researcher, UUID> {
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
@ -128,7 +118,6 @@ public class Researcher implements DataEntity<Researcher, UUID> {
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
@ -136,7 +125,6 @@ public class Researcher implements DataEntity<Researcher, UUID> {
public String getDefinition() {
return definition;
}
public void setDefinition(String definition) {
this.definition = definition;
}
@ -144,11 +132,16 @@ public class Researcher implements DataEntity<Researcher, UUID> {
public Set<DMP> getdMPs() {
return dMPs;
}
public void setdMPs(Set<DMP> dMPs) {
this.dMPs = dMPs;
}
public UserInfo getCreationUser() {
return creationUser;
}
public void setCreationUser(UserInfo creationUser) {
this.creationUser = creationUser;
}
@Override
public void update(Researcher entity) {

View File

@ -36,7 +36,7 @@ public class Researchers extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/getWithExternal"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<List<eu.eudat.models.data.dmp.Researcher>>> getWithExternal(@RequestBody ResearcherCriteriaRequest researcherCriteriaRequest, Principal principal) throws HugeResultSet, NoURLFound {
List<eu.eudat.models.data.dmp.Researcher> dataTable = this.researcherManager.getCriteriaWithExternal(researcherCriteriaRequest);
List<eu.eudat.models.data.dmp.Researcher> dataTable = this.researcherManager.getCriteriaWithExternal(researcherCriteriaRequest, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.data.dmp.Researcher>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
}
@ -44,7 +44,7 @@ public class Researchers extends BaseController {
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<Researcher>> create(@RequestBody eu.eudat.models.data.researcher.Researcher researcher, Principal principal) throws Exception {
this.researcherManager.create(researcher);
this.researcherManager.create(researcher, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Researcher>().status(ApiMessageCode.SUCCESS_MESSAGE));
}

View File

@ -444,7 +444,7 @@ public class DataManagementPlanManager {
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao(), user);
createFunderIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getFunderDao());
createGrantIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getGrantDao());
if (newDmp.getProject().getLabel() == null || newDmp.getProject().getLabel().trim().isEmpty()) {
@ -538,9 +538,9 @@ public class DataManagementPlanManager {
if (latestVersionDMP.get(0).getVersion().equals(oldDmp.getVersion())) {
DMP newDmp = dataManagementPlan.toDataModel();
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao());
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user);
createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao());
createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao());
@ -571,9 +571,10 @@ public class DataManagementPlanManager {
public void clone(DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
DMP newDmp = dataManagementPlan.toDataModel();
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao());
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
createOrganisationsIfTheyDontExist(newDmp, databaseRepository.getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, databaseRepository.getResearcherDao(), user);
createFunderIfItDoesntExist(newDmp, databaseRepository.getFunderDao());
createGrantIfItDoesntExist(newDmp, databaseRepository.getGrantDao());
@ -609,14 +610,17 @@ public class DataManagementPlanManager {
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(oldDmp);
}
private void createResearchersIfTheyDontExist(DMP newDmp, ResearcherDao researcherRepository) {
private void createResearchersIfTheyDontExist(DMP newDmp, ResearcherDao researcherRepository, UserInfo user) {
if (newDmp.getResearchers() != null && !newDmp.getResearchers().isEmpty()) {
for (eu.eudat.data.entities.Researcher researcher : newDmp.getResearchers()) {
ResearcherCriteria criteria = new ResearcherCriteria();
criteria.setLike(researcher.getReference());
List<eu.eudat.data.entities.Researcher> entries = researcherRepository.getWithCriteria(criteria).toList();
if (entries != null && !entries.isEmpty()) researcher.setId(entries.get(0).getId());
else researcherRepository.createOrUpdate(researcher);
else {
researcher.setCreationUser(user);
researcherRepository.createOrUpdate(researcher);
}
}
}
}

View File

@ -8,6 +8,7 @@ import eu.eudat.data.query.items.item.researcher.ResearcherCriteriaRequest;
import eu.eudat.logic.proxy.config.exceptions.HugeResultSet;
import eu.eudat.logic.proxy.config.exceptions.NoURLFound;
import eu.eudat.logic.proxy.fetching.RemoteFetcher;
import eu.eudat.models.data.security.Principal;
import eu.eudat.queryable.QueryableList;
import eu.eudat.logic.services.ApiContext;
import org.springframework.beans.factory.annotation.Autowired;
@ -15,6 +16,7 @@ import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
/**
@ -32,14 +34,16 @@ public class ResearcherManager {
this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher();
}
public Researcher create(eu.eudat.models.data.researcher.Researcher researcher) throws Exception {
public Researcher create(eu.eudat.models.data.researcher.Researcher researcher, Principal principal) throws Exception {
Researcher researcherEntity = researcher.toDataModel();
researcherEntity.setCreationUser(apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId()));
return apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().createOrUpdate(researcherEntity);
}
public List<eu.eudat.models.data.dmp.Researcher> getCriteriaWithExternal(ResearcherCriteriaRequest researcherCriteriaRequest) throws HugeResultSet, NoURLFound {
public List<eu.eudat.models.data.dmp.Researcher> getCriteriaWithExternal(ResearcherCriteriaRequest researcherCriteriaRequest, Principal principal) throws HugeResultSet, NoURLFound {
QueryableList<eu.eudat.data.entities.Researcher> items = apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().getWithCriteria(researcherCriteriaRequest.getCriteria());
items.where((builder, root) -> builder.equal(root.get("creationUser").get("id"), principal.getId()));
List<eu.eudat.models.data.dmp.Researcher> researchers = items.select(item -> new eu.eudat.models.data.dmp.Researcher().fromDataModel(item));
List<Map<String, String>> remoteRepos = remoteFetcher.getResearchers(researcherCriteriaRequest.getCriteria().getName(),null);
ResearchersExternalSourcesModel researchersExternalSourcesModel = new ResearchersExternalSourcesModel().fromExternalItem(remoteRepos);

View File

@ -268,9 +268,9 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
}
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())));
dataManagementPlanEntity.setOrganisations(new HashSet<>(this.organisations.stream().map(Organisation::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.setResearchers(new HashSet<>(this.researchers.stream().map(Researcher::toDataModel).collect(Collectors.toList())));
dataManagementPlanEntity.setVersion(this.version);
dataManagementPlanEntity.setLabel(this.label);
if (this.grant != null) {

View File

@ -0,0 +1,2 @@
ALTER TABLE "Researcher"
ADD COLUMN "CreationUser" uuid