no message

This commit is contained in:
Ioannis Kalyvas 2018-02-21 12:07:31 +02:00
parent 9fff5c25ae
commit 70db1b2894
30 changed files with 202 additions and 46 deletions

View File

@ -2,13 +2,20 @@ package eu.eudat.dao;
import eu.eudat.entities.DataEntity;
import eu.eudat.entities.Dataset;
import eu.eudat.queryable.QueryableList;
import java.util.concurrent.CompletableFuture;
public interface DatabaseAccessLayer<T extends DataEntity, I> {
T createOrUpdate(T item);
CompletableFuture<T> createOrUpdateAsync(T item);
T find(I id);
T find(I id, String hint);
void delete(T item);
QueryableList<T> asQueryable();

View File

@ -43,11 +43,6 @@ public class DatabaseContext<T extends DataEntity> {
return item;
}
public long count(Class<T> entityClass) {
EntityManager entityManager = this.entityManager;
return ((Number) entityManager.createQuery("select count(e) from " + entityClass.getSimpleName() + " e").getSingleResult()).longValue();
}
public void delete(T item) {
this.entityManager.remove(item);
}

View File

@ -32,10 +32,6 @@ public class DatabaseService<T extends DataEntity> {
return this.databaseCtx.createOrUpdate(item, tClass);
}
public Long count(Class<T> tClass) {
return this.databaseCtx.count(tClass);
}
public void delete(T item) {
this.databaseCtx.delete(item);
}

View File

@ -14,6 +14,7 @@ import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("dMPDao")
public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
@ -77,4 +78,13 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
return this.getDatabaseService().getQueryable(DMP.class);
}
@Override
public CompletableFuture<DMP> createOrUpdateAsync(DMP item) {
return CompletableFuture.supplyAsync(()->this.createOrUpdate(item));
}
@Override
public DMP find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("dataRepositoryDao")
public class DataRepositoryDaoImpl extends DatabaseAccess<DataRepository> implements DataRepositoryDao {
@ -36,6 +37,16 @@ public class DataRepositoryDaoImpl extends DatabaseAccess<DataRepository> implem
return getDatabaseService().createOrUpdate(item, DataRepository.class);
}
@Override
public CompletableFuture<DataRepository> createOrUpdateAsync(DataRepository item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public DataRepository find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(DataRepository item) {
this.getDatabaseService().delete(item);

View File

@ -15,8 +15,4 @@ public interface DatasetDao extends DatabaseAccessLayer<Dataset, UUID> {
QueryableList<Dataset> getAuthenticated(QueryableList<Dataset> query, UserInfo principal);
CompletableFuture<Dataset> createOrUpdateAsync(Dataset item);
Dataset find(UUID id, String hint);
}

View File

@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("datasetProfileDao")
public class DatasetProfileDaoImpl extends DatabaseAccess<DatasetProfile> implements DatasetProfileDao {
@ -50,4 +51,14 @@ public class DatasetProfileDaoImpl extends DatabaseAccess<DatasetProfile> implem
public QueryableList<DatasetProfile> asQueryable() {
return this.getDatabaseService().getQueryable(DatasetProfile.class);
}
@Override
public CompletableFuture<DatasetProfile> createOrUpdateAsync(DatasetProfile item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public DatasetProfile find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("externalDatasetDao")
@ -46,4 +47,14 @@ public class ExternalDatasetDaoImpl extends DatabaseAccess<ExternalDataset> impl
public QueryableList<ExternalDataset> asQueryable() {
return this.getDatabaseService().getQueryable(ExternalDataset.class);
}
@Override
public CompletableFuture<ExternalDataset> createOrUpdateAsync(ExternalDataset item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public ExternalDataset find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Service("invitationDao")
@ -43,4 +44,14 @@ public class InvitationDaoImpl extends DatabaseAccess<Invitation> implements Inv
public QueryableList<Invitation> asQueryable() {
return this.getDatabaseService().getQueryable(Invitation.class);
}
@Override
public CompletableFuture<Invitation> createOrUpdateAsync(Invitation item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public Invitation find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("organisationDao")
public class OrganisationDaoImpl extends DatabaseAccess<Organisation> implements OrganisationDao {
@ -45,4 +46,14 @@ public class OrganisationDaoImpl extends DatabaseAccess<Organisation> implements
public QueryableList<Organisation> asQueryable() {
return this.getDatabaseService().getQueryable(Organisation.class);
}
@Override
public CompletableFuture<Organisation> createOrUpdateAsync(Organisation item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public Organisation find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("projectDao")
public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDao {
@ -58,4 +59,14 @@ public class ProjectDaoImpl extends DatabaseAccess<Project> implements ProjectDa
query.where((builder, root) -> builder.equal(root.get("creator"), principal));
return query;
}
@Override
public CompletableFuture<Project> createOrUpdateAsync(Project item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public Project find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("registryDao")
public class RegistryDaoImpl extends DatabaseAccess<Registry> implements RegistryDao {
@ -45,4 +46,14 @@ public class RegistryDaoImpl extends DatabaseAccess<Registry> implements Registr
public QueryableList<Registry> asQueryable() {
return this.getDatabaseService().getQueryable(Registry.class);
}
@Override
public CompletableFuture<Registry> createOrUpdateAsync(Registry item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public Registry find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("researcherDao")
public class ResearcherDaoImpl extends DatabaseAccess<Researcher> implements ResearcherDao {
@ -45,4 +46,14 @@ public class ResearcherDaoImpl extends DatabaseAccess<Researcher> implements Res
public QueryableList<Researcher> asQueryable() {
return this.getDatabaseService().getQueryable(Researcher.class);
}
@Override
public CompletableFuture<Researcher> createOrUpdateAsync(Researcher item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public Researcher find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("serviceDao")
public class ServiceDaoImpl extends DatabaseAccess<Service> implements ServiceDao {
@ -45,4 +46,14 @@ public class ServiceDaoImpl extends DatabaseAccess<Service> implements ServiceDa
public QueryableList<Service> asQueryable() {
return this.getDatabaseService().getQueryable(Service.class);
}
@Override
public CompletableFuture<Service> createOrUpdateAsync(Service item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public Service find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
/**
* Created by ikalyvas on 2/8/2018.
@ -39,4 +40,14 @@ public class UserDmpDaoImpl extends DatabaseAccess<UserDMP> implements UserDmpDa
public QueryableList<UserDMP> asQueryable() {
return this.getDatabaseService().getQueryable(UserDMP.class);
}
@Override
public CompletableFuture<UserDMP> createOrUpdateAsync(UserDMP item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public UserDMP find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("userInfoDao")
public class UserInfoDaoImpl extends DatabaseAccess<UserInfo> implements UserInfoDao {
@ -49,4 +50,14 @@ public class UserInfoDaoImpl extends DatabaseAccess<UserInfo> implements UserInf
public QueryableList<UserInfo> asQueryable() {
return this.getDatabaseService().getQueryable(UserInfo.class);
}
@Override
public CompletableFuture<UserInfo> createOrUpdateAsync(UserInfo item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public UserInfo find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -11,6 +11,7 @@ import org.springframework.stereotype.Component;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("userRoleDao")
@ -55,4 +56,14 @@ public class UserRoleDaoImpl extends DatabaseAccess<UserRole> implements UserRol
public QueryableList<UserRole> asQueryable() {
return this.getDatabaseService().getQueryable(UserRole.class);
}
@Override
public CompletableFuture<UserRole> createOrUpdateAsync(UserRole item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public UserRole find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("credentialDao")
@ -49,4 +50,14 @@ public class CredentialDaoImpl extends DatabaseAccess<Credential> implements Cre
public QueryableList<Credential> asQueryable() {
return this.getDatabaseService().getQueryable(Credential.class);
}
@Override
public CompletableFuture<Credential> createOrUpdateAsync(Credential item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public Credential find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component("userTokenDao")
@ -37,4 +38,14 @@ public class UserTokenDaoImpl extends DatabaseAccess<UserToken> implements UserT
public QueryableList<UserToken> asQueryable() {
return this.getDatabaseService().getQueryable(UserToken.class);
}
@Override
public CompletableFuture<UserToken> createOrUpdateAsync(UserToken item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
public UserToken find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
}

View File

@ -39,10 +39,10 @@ public class DataManagementPlanManager {
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<DataManagementPlanListingModel>();
CompletableFuture itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)).toListAsync().whenComplete((resultList, throwable) -> {
List<DataManagementPlanListingModel> datamanagementPlans = resultList.stream().map(item -> new DataManagementPlanListingModel().fromDataModel(item)).collect(Collectors.toList());
dataTable.setData(datamanagementPlans);
});
CompletableFuture itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
.selectAsync(item -> new DataManagementPlanListingModel().fromDataModel(item)).whenComplete((resultList, throwable) -> {
dataTable.setData(resultList);
});
CompletableFuture countFuture = items.countAsync().whenComplete((count, throwable) -> {
dataTable.setTotalCount(count);
@ -62,7 +62,7 @@ public class DataManagementPlanManager {
public List<DataManagementPlan> getWithCriteria(DMPDao dmpsRepository, DataManagementPlanCriteriaRequest dataManagementPlanCriteria) throws IllegalAccessException, InstantiationException {
QueryableList<DMP> items = dmpsRepository.getWithCriteria(dataManagementPlanCriteria.getCriteria());
List<eu.eudat.models.dmp.DataManagementPlan> datamanagementPlans = items.toList().stream().map(item -> new DataManagementPlan().fromDataModel(item)).collect(Collectors.toList());
List<eu.eudat.models.dmp.DataManagementPlan> datamanagementPlans = items.select(item -> new DataManagementPlan().fromDataModel(item));
return datamanagementPlans;
}

View File

@ -2,7 +2,6 @@ package eu.eudat.managers;
import eu.eudat.builders.entity.UserInfoBuilder;
import eu.eudat.dao.entities.*;
import eu.eudat.entities.Dataset;
import eu.eudat.entities.UserInfo;
import eu.eudat.models.HintedModelFactory;
import eu.eudat.models.criteria.DataRepositoryCriteria;
@ -24,7 +23,6 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
public class DatasetManager {
@ -36,9 +34,9 @@ public class DatasetManager {
QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging(authItems, datasetTableRequest);
DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>();
CompletableFuture<List<Dataset>> itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DatasetListingModel.class)).toListAsync().whenComplete((resultList, throwable) -> {
List<DatasetListingModel> datasets = resultList.stream().map(item -> new DatasetListingModel().fromDataModel(item)).collect(Collectors.toList());
dataTable.setData(datasets);
CompletableFuture<List<DatasetListingModel>> itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DatasetListingModel.class)).
selectAsync(item -> new DatasetListingModel().fromDataModel(item)).whenComplete((resultList, throwable) -> {
dataTable.setData(resultList);
});
CompletableFuture countFuture = items.countAsync().whenComplete((count, throwable) -> {

View File

@ -19,20 +19,20 @@ public class DatasetProfileManager {
public static List<DatasetProfileAutocompleteItem> getWithCriteria(DatasetProfileDao datasetProfileRepository, DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) throws IllegalAccessException, InstantiationException {
QueryableList<DatasetProfile> items = datasetProfileRepository.getWithCriteria(datasetProfileAutocompleteRequest.getCriteria());
List<DatasetProfileAutocompleteItem> datasetProfiles = items.toList().stream().map(item -> new DatasetProfileAutocompleteItem().fromDataModel(item)).collect(Collectors.toList());
List<DatasetProfileAutocompleteItem> datasetProfiles = items.select(item -> new DatasetProfileAutocompleteItem().fromDataModel(item));
return datasetProfiles;
}
public static DataTableData<DatasetProfileListingModel> getPaged(ApiContext apiContext, DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws Exception {
QueryableList<DatasetProfile> items = apiContext.getDatabaseRepository().getDatasetProfileDao().getWithCriteria(datasetProfileTableRequestItem.getCriteria());
QueryableList<DatasetProfile> pagedItems = PaginationManager.applyPaging(items, datasetProfileTableRequestItem);
List<DatasetProfileListingModel> datasetProfiles = pagedItems.toList().stream().map(item -> new DatasetProfileListingModel().fromDataModel(item)).collect(Collectors.toList());
List<DatasetProfileListingModel> datasetProfiles = pagedItems.select(item -> new DatasetProfileListingModel().fromDataModel(item));
return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(datasetProfiles).totalCount(items.count()).build();
}
public static List<DatasetProfileListingModel> getAll(DatasetProfileDao datasetProfileRepository) throws IllegalAccessException, InstantiationException {
QueryableList<DatasetProfile> items = datasetProfileRepository.getAll();
List<DatasetProfileListingModel> datasetProfiles = items.toList().stream().map(item -> new DatasetProfileListingModel().fromDataModel(item)).collect(Collectors.toList());
List<DatasetProfileListingModel> datasetProfiles = items.select(item -> new DatasetProfileListingModel().fromDataModel(item));
return datasetProfiles;
}
}

View File

@ -22,7 +22,7 @@ public class DatasetWizardManager {
UserInfo userInfo = new UserInfo();
userInfo.setId(principal.getId());
QueryableList<DMP> items = dmpRepository.getUserDmps(datasetWizardAutocompleteRequest, userInfo);
List<DataManagentPlanListingModel> dataManagementPlans = items.toList().stream().map(item -> new DataManagentPlanListingModel().fromDataModel(item)).collect(Collectors.toList());
List<DataManagentPlanListingModel> dataManagementPlans = items.select(item -> new DataManagentPlanListingModel().fromDataModel(item));
return dataManagementPlans;
}

View File

@ -24,14 +24,14 @@ public class ExternalDatasetManager {
public DataTableData<ExternalDatasetListingModel> getPaged(ApiContext apiContext, ExternalDatasetTableRequest externalDatasetTableRequest) throws Exception {
QueryableList<ExternalDataset> items = apiContext.getDatabaseRepository().getExternalDatasetDao().getWithCriteria(externalDatasetTableRequest.getCriteria());
QueryableList<ExternalDataset> pagedItems = PaginationManager.applyPaging(items, externalDatasetTableRequest);
List<ExternalDatasetListingModel> externalDatasetListingmodels = pagedItems.toList().stream().map(item -> new ExternalDatasetListingModel().fromDataModel(item)).collect(Collectors.toList());
List<ExternalDatasetListingModel> externalDatasetListingmodels = pagedItems.select(item -> new ExternalDatasetListingModel().fromDataModel(item));
return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(externalDatasetListingmodels).totalCount(items.count()).build();
}
public List<ExternalDatasetListingModel> getWithExternal(ApiContext apiContext, String query, RemoteFetcher remoteFetcher) throws HugeResultSet, NoURLFound, InstantiationException, IllegalAccessException {
ExternalDatasetCriteria criteria = apiContext.getBuilderFactory().getBuilder(ExternalDatasetCriteriaBuilder.class).like(query).build();
QueryableList<eu.eudat.entities.ExternalDataset> items = apiContext.getDatabaseRepository().getExternalDatasetDao().getWithCriteria(criteria);
List<ExternalDatasetListingModel> externalDatasets = items.toList().stream().map(item -> new ExternalDatasetListingModel().fromDataModel(item)).collect(Collectors.toList());
List<ExternalDatasetListingModel> externalDatasets = items.select(item -> new ExternalDatasetListingModel().fromDataModel(item));
return externalDatasets;
}

View File

@ -29,7 +29,7 @@ public class InvitationsManager {
public static List<UserInfoInvitationModel> getUsers(ApiContext apiContext, UserInfoRequestItem userInfoRequestItem) throws InstantiationException, IllegalAccessException {
QueryableList<UserInfo> users = apiContext.getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoRequestItem.getCriteria());
List<UserInfoInvitationModel> userModels = users.toList().stream().map(item -> new UserInfoInvitationModel().fromDataModel(item)).collect(Collectors.toList());
List<UserInfoInvitationModel> userModels = users.select(item -> new UserInfoInvitationModel().fromDataModel(item));
return userModels;
}

View File

@ -32,9 +32,8 @@ public class ProjectManager {
QueryableList<eu.eudat.entities.Project> pagedItems = PaginationManager.applyPaging(items, projectTableRequest);
DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new DataTableData<eu.eudat.models.project.ProjectListingModel>();
CompletableFuture projectsFuture = pagedItems.withHint(HintedModelFactory.getHint(ProjectListingModel.class)).toListAsync().whenComplete((results, throwable) -> {
List<eu.eudat.models.project.ProjectListingModel> projects = results.stream().map(item -> new ProjectListingModel().fromDataModel(item)).collect(Collectors.toList());
dataTable.setData(projects);
CompletableFuture projectsFuture = pagedItems.withHint(HintedModelFactory.getHint(ProjectListingModel.class)).selectAsync(item -> new ProjectListingModel().fromDataModel(item)).whenComplete((results, throwable) -> {
dataTable.setData(results);
});
CompletableFuture countFuture = pagedItems.countAsync().whenComplete((count, throwable) -> dataTable.setTotalCount(count));
@ -58,7 +57,7 @@ public class ProjectManager {
public List<eu.eudat.models.project.Project> getCriteriaWithExternal(ApiContext apiContext, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound {
QueryableList<eu.eudat.entities.Project> items = apiContext.getDatabaseRepository().getProjectDao().getWithCriteria(projectCriteria.getCriteria());
List<eu.eudat.models.project.Project> projects = items.toList().stream().map(item -> new Project().fromDataModel(item)).collect(Collectors.toList());
List<eu.eudat.models.project.Project> projects = items.select(item -> new Project().fromDataModel(item));
List<Map<String, String>> remoteRepos = remoteFetcher.getProjects(projectCriteria.getCriteria().getLike());
ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos);
for (ExternalSourcesItemModel externalListingItem : projectsExternalSourcesModel) {
@ -76,7 +75,7 @@ public class ProjectManager {
public List<eu.eudat.models.project.Project> getCriteria(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound {
QueryableList<eu.eudat.entities.Project> items = projectRepository.getWithCriteria(projectCriteria.getCriteria());
List<eu.eudat.models.project.Project> projects = items.toList().stream().map(item -> new Project().fromDataModel(item)).collect(Collectors.toList());
List<eu.eudat.models.project.Project> projects = items.select(item -> new Project().fromDataModel(item));
return projects;
}

View File

@ -35,7 +35,7 @@ public class UserManager {
QueryableList<eu.eudat.entities.UserInfo> users = apiContext.getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoTableRequestItem.getCriteria());
QueryableList<eu.eudat.entities.UserInfo> pagedUsers = PaginationManager.applyPaging(users, userInfoTableRequestItem);
List<UserListingModel> modelUsers = pagedUsers.toList().stream().map(item -> new UserListingModel().fromDataModel(item)).collect(Collectors.toList());
List<UserListingModel> modelUsers = pagedUsers.select(item -> new UserListingModel().fromDataModel(item));
return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).totalCount(users.count()).data(modelUsers).build();
}

View File

@ -18,6 +18,8 @@ public interface QueryableList<T extends DataEntity> {
<R> List<R> select(SelectPredicate<T, R> predicate);
<R> CompletableFuture<List<R>> selectAsync(SelectPredicate<T, R> predicate);
List<T> toList();
CompletableFuture<List<T>> toListAsync();

View File

@ -24,9 +24,9 @@ import java.util.stream.Collectors;
public class QueryableHibernateList<T extends DataEntity> implements QueryableList<T> {
private EntityManager manager;
private CriteriaQuery query;
private CriteriaQuery<T> query;
private Class<T> tClass;
private Root root;
private Root<T> root;
private Root<T> nestedQueryRoot;
private Subquery<T> subquery;
private List<SinglePredicate<T>> singlePredicates = new LinkedList<>();
@ -61,7 +61,7 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
public QueryableHibernateList<T> setEntity(Class<T> type) {
CriteriaBuilder builder = this.manager.getCriteriaBuilder();
this.query = builder.createTupleQuery();
this.query = builder.createQuery(type);
this.root = this.query.from(this.tClass);
return this;
}
@ -94,12 +94,11 @@ public class QueryableHibernateList<T extends DataEntity> implements QueryableLi
}
public <R> List<R> select(SelectPredicate<T, R> predicate) {
List<T> list = this.toList();
List<R> newlist = new LinkedList<R>();
for (T item : list) {
newlist.add(predicate.applySelection(item));
}
return newlist;
return this.toList().stream().map(item -> predicate.applySelection(item)).collect(Collectors.toList());
}
public <R> CompletableFuture<List<R>> selectAsync(SelectPredicate<T, R> predicate) {
return this.toListAsync().thenApplyAsync(items-> items.stream().map(item -> predicate.applySelection(item)).collect(Collectors.toList()));
}
public QueryableList<T> distinct() {

View File

@ -5,6 +5,6 @@
export const environment = {
production: false,
Server: 'http://192.168.32.64:8080/api/',
Server: 'http://devel-21.local.cite.gr:8080/api/',
App: 'localhost:4200/'
};