Updates Colaborators fetch algorithm
This commit is contained in:
parent
2775841d84
commit
ea66da7cff
|
@ -11,4 +11,5 @@ public interface UserInfoDao extends DatabaseAccessLayer<UserInfo, UUID> {
|
||||||
|
|
||||||
QueryableList<UserInfo> getWithCriteria(UserInfoCriteria criteria);
|
QueryableList<UserInfo> getWithCriteria(UserInfoCriteria criteria);
|
||||||
|
|
||||||
|
QueryableList<UserInfo> getAuthenticated(QueryableList<UserInfo> users, UUID principalId);
|
||||||
}
|
}
|
|
@ -5,10 +5,13 @@ import eu.eudat.data.dao.criteria.UserInfoCriteria;
|
||||||
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
import eu.eudat.data.dao.databaselayer.service.DatabaseService;
|
||||||
import eu.eudat.data.entities.UserInfo;
|
import eu.eudat.data.entities.UserInfo;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
import eu.eudat.queryable.types.FieldSelectionType;
|
||||||
|
import eu.eudat.queryable.types.SelectionField;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@ -32,6 +35,17 @@ public class UserInfoDaoImpl extends DatabaseAccess<UserInfo> implements UserInf
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueryableList<UserInfo> getAuthenticated(QueryableList<UserInfo> users, UUID principalId) {
|
||||||
|
users.initSubQuery(UUID.class).where((builder, root) ->
|
||||||
|
builder.and(builder.equal(root.join("dmps").get("id"),
|
||||||
|
users.subQuery((builder1, root1) -> builder1.equal(root1.join("dmps").get("id"), principalId),
|
||||||
|
Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmps:id")))),
|
||||||
|
builder.notEqual(root.get("id"), principalId)));
|
||||||
|
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserInfo createOrUpdate(UserInfo item) {
|
public UserInfo createOrUpdate(UserInfo item) {
|
||||||
return this.getDatabaseService().createOrUpdate(item, UserInfo.class);
|
return this.getDatabaseService().createOrUpdate(item, UserInfo.class);
|
||||||
|
|
|
@ -14,7 +14,7 @@ import java.util.*;
|
||||||
@NamedEntityGraphs({
|
@NamedEntityGraphs({
|
||||||
@NamedEntityGraph(
|
@NamedEntityGraph(
|
||||||
name = "userInfo",
|
name = "userInfo",
|
||||||
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials")})
|
attributeNodes = {@NamedAttributeNode("userRoles"), @NamedAttributeNode("credentials"),@NamedAttributeNode("dmps")}),
|
||||||
})
|
})
|
||||||
public class UserInfo implements DataEntity<UserInfo, UUID> {
|
public class UserInfo implements DataEntity<UserInfo, UUID> {
|
||||||
|
|
||||||
|
|
|
@ -343,7 +343,11 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
|
||||||
Subquery<T> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(this.tClass);
|
Subquery<T> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(this.tClass);
|
||||||
this.nestedQueryRoot = subquery.from(this.tClass);
|
this.nestedQueryRoot = subquery.from(this.tClass);
|
||||||
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.nestedQueryRoot));
|
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.nestedQueryRoot));
|
||||||
|
if (fields.get(0).getType() == FieldSelectionType.FIELD)
|
||||||
subquery.select(this.nestedQueryRoot.get(fields.get(0).getField()));
|
subquery.select(this.nestedQueryRoot.get(fields.get(0).getField()));
|
||||||
|
else if (fields.get(0).getType() == FieldSelectionType.COMPOSITE_FIELD) {
|
||||||
|
subquery.select(this.nestedQueryRoot.join(fields.get(0).getField().split(":")[0]).get(fields.get(0).getField().split(":")[1]));
|
||||||
|
}
|
||||||
return subquery;
|
return subquery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,7 +356,11 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
|
||||||
Subquery<T> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(this.tClass);
|
Subquery<T> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(this.tClass);
|
||||||
this.nestedQueryRoot = subquery.from(this.tClass);
|
this.nestedQueryRoot = subquery.from(this.tClass);
|
||||||
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.root, this.nestedQueryRoot));
|
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.root, this.nestedQueryRoot));
|
||||||
|
if (fields.get(0).getType() == FieldSelectionType.FIELD)
|
||||||
subquery.select(this.nestedQueryRoot.get(fields.get(0).getField()));
|
subquery.select(this.nestedQueryRoot.get(fields.get(0).getField()));
|
||||||
|
else if (fields.get(0).getType() == FieldSelectionType.COMPOSITE_FIELD) {
|
||||||
|
subquery.select(this.nestedQueryRoot.get(fields.get(0).getField().split(":")[0]).get(fields.get(0).getField().split(":")[1]));
|
||||||
|
}
|
||||||
return subquery;
|
return subquery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,7 +383,8 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <U extends Comparable> Subquery<U> subQueryMax(SinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass) {
|
public <U extends
|
||||||
|
Comparable> Subquery<U> subQueryMax(SinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass) {
|
||||||
Subquery<U> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(uClass);
|
Subquery<U> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(uClass);
|
||||||
this.nestedQueryRoot = subquery.from(this.tClass);
|
this.nestedQueryRoot = subquery.from(this.tClass);
|
||||||
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.nestedQueryRoot));
|
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.nestedQueryRoot));
|
||||||
|
@ -388,7 +397,8 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <U extends Comparable> Subquery<U> subQueryMax(NestedQuerySinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass) {
|
public <U extends
|
||||||
|
Comparable> Subquery<U> subQueryMax(NestedQuerySinglePredicate<T> predicate, List<SelectionField> fields, Class<U> uClass) {
|
||||||
//Subquery<U> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(uClass);
|
//Subquery<U> subquery = this.manager.getCriteriaBuilder().createQuery().subquery(uClass);
|
||||||
//this.nestedQueryRoot = subquery.from(this.tClass);
|
//this.nestedQueryRoot = subquery.from(this.tClass);
|
||||||
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.root, this.nestedQueryRoot));
|
subquery.where(predicate.applyPredicate(this.manager.getCriteriaBuilder(), this.root, this.nestedQueryRoot));
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class Users extends BaseController {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/getCollaboratorsPaged"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/getCollaboratorsPaged"}, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DataTableData<UserListingModel>>> getCollaboratorsPaged(@Valid @RequestBody UserInfoTableRequestItem userInfoTableRequestItem, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<DataTableData<UserListingModel>>> getCollaboratorsPaged(@Valid @RequestBody UserInfoTableRequestItem userInfoTableRequestItem, Principal principal) throws Exception {
|
||||||
DataTableData<UserListingModel> dataTable = userManager.getCollaboratorsPaged(userInfoTableRequestItem, principal);
|
DataTableData<UserListingModel> dataTable = userManager.getCollaboratorsPaged(userInfoTableRequestItem, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<UserListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<UserListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package eu.eudat.logic.managers;
|
package eu.eudat.logic.managers;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
|
|
||||||
import eu.eudat.data.dao.entities.DMPDao;
|
|
||||||
import eu.eudat.data.dao.entities.UserInfoDao;
|
import eu.eudat.data.dao.entities.UserInfoDao;
|
||||||
import eu.eudat.data.entities.DMP;
|
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.entities.UserRole;
|
||||||
import eu.eudat.data.query.items.table.userinfo.UserInfoTableRequestItem;
|
import eu.eudat.data.query.items.table.userinfo.UserInfoTableRequestItem;
|
||||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||||
|
@ -19,7 +17,6 @@ import eu.eudat.models.data.dmp.DataManagementPlan;
|
||||||
import eu.eudat.models.data.helpers.common.DataTableData;
|
import eu.eudat.models.data.helpers.common.DataTableData;
|
||||||
import eu.eudat.models.data.login.Credentials;
|
import eu.eudat.models.data.login.Credentials;
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
import eu.eudat.models.data.userinfo.UserInfo;
|
|
||||||
import eu.eudat.models.data.userinfo.UserListingModel;
|
import eu.eudat.models.data.userinfo.UserListingModel;
|
||||||
import eu.eudat.models.data.userinfo.UserProfile;
|
import eu.eudat.models.data.userinfo.UserProfile;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
@ -30,7 +27,10 @@ import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@ -97,47 +97,17 @@ public class UserManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataTableData<UserListingModel> getCollaboratorsPaged(UserInfoTableRequestItem userInfoTableRequestItem, Principal principal) throws Exception {
|
public DataTableData<UserListingModel> getCollaboratorsPaged(UserInfoTableRequestItem userInfoTableRequestItem, Principal principal) throws Exception {
|
||||||
//UserInfoDao userInfoDao = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao();
|
UserInfoDao userInfoDao = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao();
|
||||||
DMPDao dmpDao = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao();
|
|
||||||
|
|
||||||
// Gets all the DMPs the user is associated.
|
QueryableList<UserInfo> users = userInfoDao.asQueryable();
|
||||||
DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria();
|
|
||||||
QueryableList<DMP> dmpItmes = dmpDao.getWithCriteria(dataManagementPlanCriteria);
|
|
||||||
QueryableList<DMP> dmpAuthItems = dmpDao.getAuthenticated(dmpItmes, principal.getId());
|
|
||||||
List<DMP> dmpList = dmpAuthItems.toList();
|
|
||||||
|
|
||||||
// List to place the associated users.
|
List<UserListingModel> colaborators = userInfoDao.getAuthenticated(users, principal.getId())
|
||||||
List<UserListingModel> associatedUsersList = new LinkedList<>();
|
.withHint(HintedModelFactory.getHint(UserListingModel.class))
|
||||||
|
.select(colaborator -> new UserListingModel().fromDataModel(colaborator));
|
||||||
// Iterate through the DMP list and get the users associated.
|
|
||||||
for (DMP dmp : dmpList) {
|
|
||||||
for (UserDMP userDMP : dmp.getUsers()) {
|
|
||||||
if (userDMP.getUser().getId() != principal.getId()) {
|
|
||||||
associatedUsersList.add(new UserListingModel().fromDataModel(userDMP.getUser()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove duplicates from the associated users list.
|
|
||||||
associatedUsersList = associatedUsersList.stream().distinct().collect(Collectors.toList());
|
|
||||||
|
|
||||||
// Filter using the criteria.
|
|
||||||
List<UserListingModel> associatedUsersListFiltered = new LinkedList<>();
|
|
||||||
associatedUsersList.stream()
|
|
||||||
.filter(item -> item.getName().toLowerCase().contains(userInfoTableRequestItem.getCriteria().getCollaboratorLike().toLowerCase())).forEach(
|
|
||||||
o -> {
|
|
||||||
associatedUsersListFiltered.add(o);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
/*QueryableList<eu.eudat.data.entities.UserInfo> users = userInfoDao.getWithCriteria(userInfoTableRequestItem.getCriteria()).withHint(HintedModelFactory.getHint(UserListingModel.class));
|
|
||||||
QueryableList<eu.eudat.data.entities.UserInfo> pagedUsers = PaginationManager.applyPaging(users, userInfoTableRequestItem);*/
|
|
||||||
|
|
||||||
//List<UserListingModel> modelUsers = pagedUsers.select(item -> new listing model().fromDataModel(item));
|
|
||||||
|
|
||||||
DataTableData<UserListingModel> dataTableData = new DataTableData<>();
|
DataTableData<UserListingModel> dataTableData = new DataTableData<>();
|
||||||
dataTableData.setData(associatedUsersListFiltered);
|
dataTableData.setData(colaborators);
|
||||||
dataTableData.setTotalCount((long)associatedUsersListFiltered.size());
|
dataTableData.setTotalCount((long) colaborators.size());
|
||||||
return dataTableData;
|
return dataTableData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue