Adds "Creation User" on Funder entity and fixes bug showing Funder created by user to other users. (Issue #167)
This commit is contained in:
parent
f93b6103e9
commit
aaa1e9d1c7
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE "Funder"
|
||||
ADD COLUMN "CreationUser" uuid
|
|
@ -0,0 +1,4 @@
|
|||
Update "Funder" as funder
|
||||
set "CreationUser" = grant1."CreationUser"
|
||||
from "Grant" as grant1
|
||||
where funder."ID" = grant1."Funder"
|
Loading…
Reference in New Issue