2018-06-27 12:29:21 +02:00
|
|
|
package eu.eudat.logic.managers;
|
2018-03-28 15:24:47 +02:00
|
|
|
|
|
|
|
import eu.eudat.data.dao.entities.DMPProfileDao;
|
|
|
|
import eu.eudat.data.entities.DMPProfile;
|
|
|
|
import eu.eudat.data.query.items.item.dmpprofile.DataManagementPlanProfileCriteriaRequest;
|
|
|
|
import eu.eudat.data.query.items.table.dmpprofile.DataManagementPlanProfileTableRequest;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.models.data.helpers.common.DataTableData;
|
|
|
|
import eu.eudat.models.data.listingmodels.DataManagementPlanProfileListingModel;
|
|
|
|
import eu.eudat.models.data.security.Principal;
|
2018-03-28 15:24:47 +02:00
|
|
|
import eu.eudat.queryable.QueryableList;
|
2018-06-27 12:29:21 +02:00
|
|
|
import eu.eudat.logic.services.ApiContext;
|
2018-03-28 15:24:47 +02:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by ikalyvas on 3/21/2018.
|
|
|
|
*/
|
|
|
|
public class DataManagementProfileManager {
|
|
|
|
|
|
|
|
public DataTableData<DataManagementPlanProfileListingModel> getPaged(ApiContext apiContext, DataManagementPlanProfileTableRequest dataManagementPlanProfileTableRequest, Principal principal) throws Exception {
|
|
|
|
|
|
|
|
QueryableList<DMPProfile> items = apiContext.getOperationsContext().getDatabaseRepository().getDmpProfileDao().getWithCriteria(dataManagementPlanProfileTableRequest.getCriteria());
|
|
|
|
QueryableList<DMPProfile> pagedItems = PaginationManager.applyPaging(items, dataManagementPlanProfileTableRequest);
|
|
|
|
|
|
|
|
DataTableData<DataManagementPlanProfileListingModel> dataTable = new DataTableData<DataManagementPlanProfileListingModel>();
|
|
|
|
|
|
|
|
CompletableFuture itemsFuture = pagedItems
|
|
|
|
.selectAsync(item -> new DataManagementPlanProfileListingModel().fromDataModel(item)).whenComplete((resultList, throwable) -> {
|
|
|
|
dataTable.setData(resultList);
|
|
|
|
});
|
|
|
|
|
|
|
|
CompletableFuture countFuture = items.countAsync().whenComplete((count, throwable) -> {
|
|
|
|
dataTable.setTotalCount(count);
|
|
|
|
});
|
|
|
|
CompletableFuture.allOf(itemsFuture, countFuture).join();
|
|
|
|
return dataTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
public DataManagementPlanProfileListingModel getSingle(DMPProfileDao dmpProfileDao, String id, Principal principal) throws InstantiationException, IllegalAccessException {
|
|
|
|
DMPProfile dmpProfile = dmpProfileDao.find(UUID.fromString(id));
|
|
|
|
DataManagementPlanProfileListingModel dataManagementPlanProfileListingModel = new DataManagementPlanProfileListingModel();
|
|
|
|
dataManagementPlanProfileListingModel.fromDataModel(dmpProfile);
|
|
|
|
return dataManagementPlanProfileListingModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<DataManagementPlanProfileListingModel> getWithCriteria(DMPProfileDao dmpProfileDao, DataManagementPlanProfileCriteriaRequest dataManagementPlanProfileCriteriaRequest) throws IllegalAccessException, InstantiationException {
|
|
|
|
QueryableList<DMPProfile> items = dmpProfileDao.getWithCriteria(dataManagementPlanProfileCriteriaRequest.getCriteria());
|
|
|
|
List<DataManagementPlanProfileListingModel> datamanagementPlans = items.select(item -> new DataManagementPlanProfileListingModel().fromDataModel(item));
|
|
|
|
return datamanagementPlans;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void createOrUpdate(ApiContext apiContext, DataManagementPlanProfileListingModel dataManagementPlanProfileListingModel, Principal principal) throws Exception {
|
|
|
|
DMPProfile dmpProfile = dataManagementPlanProfileListingModel.toDataModel();
|
|
|
|
apiContext.getOperationsContext().getDatabaseRepository().getDmpProfileDao().createOrUpdate(dmpProfile);
|
|
|
|
}
|
|
|
|
}
|