Fixes bug on DMP's filter Role.
This commit is contained in:
parent
ebd53e9513
commit
ccb96aeb13
|
@ -8,6 +8,7 @@ import eu.eudat.data.entities.UserDMP;
|
|||
import eu.eudat.data.entities.UserInfo;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface DMPDao extends DatabaseAccessLayer<DMP, UUID> {
|
||||
|
@ -16,6 +17,6 @@ public interface DMPDao extends DatabaseAccessLayer<DMP, UUID> {
|
|||
|
||||
QueryableList<DMP> getUserDmps(DatasetWizardUserDmpCriteria datasetWizardAutocompleteRequest, UserInfo userInfo);
|
||||
|
||||
QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UUID principalId);
|
||||
QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UUID principalId, List<Integer> roles);
|
||||
|
||||
}
|
|
@ -5,7 +5,6 @@ import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
|
|||
import eu.eudat.data.dao.criteria.DatasetWizardUserDmpCriteria;
|
||||
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
||||
import eu.eudat.data.entities.DMP;
|
||||
import eu.eudat.data.entities.UserDMP;
|
||||
import eu.eudat.data.entities.UserInfo;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import eu.eudat.queryable.types.FieldSelectionType;
|
||||
|
@ -14,15 +13,16 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.JoinType;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component("dMPDao")
|
||||
public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
|
||||
|
||||
|
||||
@Autowired
|
||||
public DMPDaoImpl(DatabaseService<DMP> databaseService) {
|
||||
super(databaseService);
|
||||
|
@ -56,13 +56,13 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
|
|||
}
|
||||
if (criteria.getIsPublic())
|
||||
query.where(((builder, root) -> builder.equal(root.get("isPublic"), true)));
|
||||
if (criteria.getRole() != null) {
|
||||
/*if (criteria.getRole() != null) {
|
||||
if (criteria.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())) {
|
||||
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).get("role"), UserDMP.UserDMPRoles.OWNER.getValue()));
|
||||
} else if (criteria.getRole().equals(UserDMP.UserDMPRoles.USER.getValue())) {
|
||||
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).get("role"), UserDMP.UserDMPRoles.USER.getValue()));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
if (criteria.getOrganisations() != null && !criteria.getOrganisations().isEmpty()) {
|
||||
query.where((builder, root) -> root.join("organisations").get("reference").in(criteria.getOrganisations()));
|
||||
}
|
||||
|
@ -76,8 +76,16 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
|
|||
return query;
|
||||
}
|
||||
|
||||
public QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UUID principal) {
|
||||
public QueryableList<DMP> getAuthenticated(QueryableList<DMP> query, UUID principal, List<Integer> roles) {
|
||||
if (roles != null && !roles.isEmpty()) {
|
||||
query.where((builder, root) -> {
|
||||
Join userJoin = root.join("users", JoinType.LEFT);
|
||||
return builder.and(builder.equal(userJoin.join("user", JoinType.LEFT).get("id"), principal), userJoin.get("role").in(roles));
|
||||
});
|
||||
} else {
|
||||
query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).join("user", JoinType.LEFT).get("id"), principal));
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,7 @@ import eu.eudat.data.dao.entities.DMPDao;
|
|||
import eu.eudat.data.dao.entities.DatasetDao;
|
||||
import eu.eudat.data.dao.entities.OrganisationDao;
|
||||
import eu.eudat.data.dao.entities.GrantDao;
|
||||
import eu.eudat.data.entities.DMP;
|
||||
import eu.eudat.data.entities.Dataset;
|
||||
import eu.eudat.data.entities.Grant;
|
||||
import eu.eudat.data.entities.UserInfo;
|
||||
import eu.eudat.data.entities.*;
|
||||
import eu.eudat.logic.builders.model.models.RecentActivityDataBuilder;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.operations.DatabaseRepository;
|
||||
|
@ -79,9 +76,9 @@ public class DashBoardManager {
|
|||
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
||||
dataManagementPlanCriteria.setAllVersions(false);
|
||||
GrantCriteria grantCriteria = new GrantCriteria();
|
||||
OrganisationCriteria organisationCriteria = new OrganisationCriteria();
|
||||
|
||||
CompletableFuture dmpFuture = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId()).countAsync()
|
||||
List<Integer> roles = new LinkedList<>();
|
||||
CompletableFuture dmpFuture = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles).countAsync()
|
||||
.whenComplete((dmpsStats, throwable) -> statistics.setTotalDataManagementPlanCount(dmpsStats));
|
||||
CompletableFuture datasetFuture = datasetRepository.getAuthenticated(datasetRepository.getWithCriteria(datasetCriteria), user).countAsync()
|
||||
.whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats));
|
||||
|
@ -108,7 +105,8 @@ public class DashBoardManager {
|
|||
GrantCriteria grantCriteria = new GrantCriteria();
|
||||
RecentActivityDataBuilder recentActivityDataBuilder = apiContext.getOperationsContext().getBuilderFactory().getBuilder(RecentActivityDataBuilder.class);
|
||||
|
||||
CompletableFuture<List<RecentActivityData>> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId())
|
||||
List<Integer> roles = new LinkedList<>();
|
||||
CompletableFuture<List<RecentActivityData>> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria), principal.getId(), roles)
|
||||
.withHint("dmpRecentActivity")
|
||||
.orderBy((builder, root) -> builder.desc(root.get("modified")))
|
||||
.take(numberofactivities)
|
||||
|
@ -141,8 +139,9 @@ public class DashBoardManager {
|
|||
DatasetDao datasetRepository = databaseRepository.getDatasetDao();
|
||||
GrantDao grantRepository = databaseRepository.getGrantDao();
|
||||
|
||||
List<Integer> roles = new LinkedList<>();
|
||||
List<SearchBarItem> searchBarItems = new LinkedList<>();
|
||||
CompletableFuture<List<SearchBarItem>> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.asQueryable(), principal.getId())
|
||||
CompletableFuture<List<SearchBarItem>> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.asQueryable(), principal.getId(), roles)
|
||||
.withHint("dmpRecentActivity")
|
||||
.where((builder, root) -> builder.like(builder.upper(root.get("label")), "%" + like.toUpperCase() + "%"))
|
||||
.orderBy((builder, root) -> builder.desc(root.get("modified")))
|
||||
|
|
|
@ -92,7 +92,9 @@ public class DataManagementPlanManager {
|
|||
public DataTableData<DataManagementPlanListingModel> getPaged(DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal, String fieldsGroup) throws Exception {
|
||||
UUID principalID = principal.getId();
|
||||
QueryableList<DMP> items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria());
|
||||
QueryableList<DMP> authItems = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(items, principalID);
|
||||
List<Integer> roles = new LinkedList<>();
|
||||
if (dataManagementPlanTableRequest.getCriteria().getRole() != null) roles.add(dataManagementPlanTableRequest.getCriteria().getRole());
|
||||
QueryableList<DMP> authItems = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(items, principalID, roles);
|
||||
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(authItems, dataManagementPlanTableRequest);
|
||||
|
||||
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<>();
|
||||
|
@ -363,7 +365,8 @@ public class DataManagementPlanManager {
|
|||
public List<DataManagementPlan> getWithCriteria(DMPDao dmpsRepository, DataManagementPlanCriteriaRequest dataManagementPlanCriteria, Principal principal) throws IllegalAccessException, InstantiationException {
|
||||
UUID principalID = principal.getId();
|
||||
QueryableList<DMP> items = dmpsRepository.getWithCriteria(dataManagementPlanCriteria.getCriteria()).withHint(HintedModelFactory.getHint(DataManagementPlan.class));
|
||||
QueryableList<DMP> authenticatedItems = dmpsRepository.getAuthenticated(items, principalID);
|
||||
List<Integer> roles = new LinkedList<>();
|
||||
QueryableList<DMP> authenticatedItems = dmpsRepository.getAuthenticated(items, principalID, roles);
|
||||
List<eu.eudat.models.data.dmp.DataManagementPlan> datamanagementPlans = authenticatedItems.select(item -> new DataManagementPlan().fromDataModel(item));
|
||||
return datamanagementPlans;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package eu.eudat.logic.managers;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.data.dao.entities.UserInfoDao;
|
||||
import eu.eudat.data.entities.DMP;
|
||||
import eu.eudat.data.entities.UserDMP;
|
||||
import eu.eudat.data.entities.UserInfo;
|
||||
import eu.eudat.data.entities.UserRole;
|
||||
import eu.eudat.data.query.items.table.userinfo.UserInfoTableRequestItem;
|
||||
|
@ -28,10 +29,7 @@ import org.w3c.dom.Document;
|
|||
import org.w3c.dom.Element;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
|
@ -66,7 +64,8 @@ public class UserManager {
|
|||
public UserProfile getSingle(UUID userId) throws Exception {
|
||||
eu.eudat.data.entities.UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userId);
|
||||
UserProfile profile = new UserProfile().fromDataModel(user);
|
||||
List<DMP> dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable(), userId).take(5).toList();
|
||||
List<Integer> roles = new LinkedList<>();
|
||||
List<DMP> dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable(), userId, roles).take(5).toList();
|
||||
profile.setAssociatedDmps(dmps.stream().map(x -> new DataManagementPlan().fromDataModel(x)).collect(Collectors.toList()));
|
||||
return profile;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue