Adds "Creation User" on Funder entity and fixes bug showing Funder created by user to other users. (Issue #167)

This commit is contained in:
gkolokythas 2019-09-24 17:40:53 +03:00
parent f93b6103e9
commit aaa1e9d1c7
7 changed files with 47 additions and 9 deletions

View File

@ -35,7 +35,8 @@ public class FunderDaoImpl extends DatabaseAccess<Funder> implements FunderDao {
@Override
public QueryableList<Funder> getAuthenticated(QueryableList<Funder> query, UserInfo principal) {
return null;
query.where((builder, root) -> builder.equal(root.get("creationUser"), principal));
return query;
}
@Override

View File

@ -94,6 +94,10 @@ public class Funder implements DataEntity<Funder, UUID> {
@Column(name = "\"Type\"")
private Integer type;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "\"CreationUser\"", nullable = true)
private UserInfo creationUser;
public UUID getId() {
return id;
@ -151,6 +155,13 @@ public class Funder implements DataEntity<Funder, UUID> {
this.type = type;
}
public UserInfo getCreationUser() {
return creationUser;
}
public void setCreationUser(UserInfo creationUser) {
this.creationUser = creationUser;
}
@Override
public void update(Funder entity) {
this.label = entity.getLabel();
@ -160,6 +171,7 @@ public class Funder implements DataEntity<Funder, UUID> {
this.created = entity.getCreated();
this.modified = new Date();
this.type = entity.getType();
this.creationUser = entity.getCreationUser();
}
@Override

View File

@ -459,7 +459,9 @@ public class DataManagementPlanManager {
}
checkIfUserCanEditGrant(newDmp, user);
checkIfGrandHasCreationUser(newDmp, user);
assignGrandUserIfInternal(newDmp, user);
assignFunderUserIfInternal(newDmp, user);
assignProjectUserIfInternal(newDmp, user);
apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant());
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
@ -540,7 +542,9 @@ public class DataManagementPlanManager {
newDmp.setId(null);
checkIfUserCanEditGrant(newDmp, user);
checkIfGrandHasCreationUser(newDmp, user);
assignGrandUserIfInternal(newDmp, user);
assignFunderUserIfInternal(newDmp, user);
assignProjectUserIfInternal(newDmp, user);
databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant());
newDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp);
@ -571,7 +575,9 @@ public class DataManagementPlanManager {
newDmp.setId(null);
checkIfUserCanEditGrant(newDmp, user);
checkIfGrandHasCreationUser(newDmp, user);
assignGrandUserIfInternal(newDmp, user);
assignFunderUserIfInternal(newDmp, user);
assignProjectUserIfInternal(newDmp, user);
databaseRepository.getGrantDao().createOrUpdate(newDmp.getGrant());
newDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp);
@ -637,7 +643,7 @@ public class DataManagementPlanManager {
eu.eudat.data.entities.Funder funderEntity = funderDao.getWithCritetia(criteria).getSingleOrDefault();
if (funderEntity != null) funder.setId(funderEntity.getId());
else {
funder.setType(Funder.FunderType.EXTERNAL.getValue());
// funder.setType(Funder.FunderType.EXTERNAL.getValue());
funderDao.createOrUpdate(funder);
}
}
@ -684,12 +690,24 @@ public class DataManagementPlanManager {
}
}
private void checkIfGrandHasCreationUser(DMP dmp, UserInfo user) {
if (dmp.getGrant().getCreationUser() == null) {
private void assignGrandUserIfInternal(DMP dmp, UserInfo user) {
if (dmp.getGrant().getCreationUser() == null && dmp.getGrant().getReference().startsWith("dmp:")) {
dmp.getGrant().setCreationUser(user);
}
}
private void assignFunderUserIfInternal(DMP dmp, UserInfo user) {
if (dmp.getGrant().getFunder().getCreationUser() == null && dmp.getGrant().getFunder().getReference().startsWith("dmp:")) {
dmp.getGrant().getFunder().setCreationUser(user);
}
}
private void assignProjectUserIfInternal(DMP dmp, UserInfo user) {
if (dmp.getProject().getCreationUser() == null && dmp.getProject().getReference().startsWith("dmp:")) {
dmp.getProject().setCreationUser(user);
}
}
private void copyDatasets(DMP newDmp, DatasetDao datasetDao) {
List<CompletableFuture<Dataset>> futures = new LinkedList<>();
for (Dataset dataset : newDmp.getDataset()) {

View File

@ -33,8 +33,8 @@ public class FunderManager {
userInfo.setId(principal.getId());
funderCriteria.getCriteria().setReference("dmp:");
QueryableList<eu.eudat.data.entities.Funder> items = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getWithCritetia(funderCriteria.getCriteria());
//QueryableList<eu.eudat.data.entities.Funder> authItems = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getAuthenticated(items, userInfo);
List<Funder> funders = items.select(item -> new eu.eudat.models.data.funder.Funder().fromDataModel(item));
QueryableList<eu.eudat.data.entities.Funder> authItems = apiContext.getOperationsContext().getDatabaseRepository().getFunderDao().getAuthenticated(items, userInfo);
List<Funder> funders = authItems.select(item -> new eu.eudat.models.data.funder.Funder().fromDataModel(item));
List<Map<String, String>> remoteRepos = remoteFetcher.getFunders(funderCriteria.getCriteria().getLike());
FundersExternalSourcesModel fundersExternalSourcesModel = new FundersExternalSourcesModel().fromExternalItem(remoteRepos);
for (ExternalSourcesItemModel externalListingItem : fundersExternalSourcesModel) {

View File

@ -314,6 +314,7 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
}
else if (this.funder.getExistFunder() != null && this.funder.getLabel() == null){
dataManagementPlanEntity.getGrant().setFunder(this.funder.getExistFunder().toDataModel());
dataManagementPlanEntity.getGrant().getFunder().setType(Funder.FunderType.EXTERNAL.getValue());
}
}

View File

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

View File

@ -0,0 +1,4 @@
Update "Funder" as funder
set "CreationUser" = grant1."CreationUser"
from "Grant" as grant1
where funder."ID" = grant1."Funder"