argos/dmp-backend/web/src/main/java/eu/eudat/managers/DataManagementProfileManage...

61 lines
3.4 KiB
Java
Raw Normal View History

2018-03-28 15:24:47 +02:00
package eu.eudat.managers;
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;
import eu.eudat.models.HintedModelFactory;
import eu.eudat.models.helpers.common.DataTableData;
import eu.eudat.models.listingmodels.DataManagementPlanListingModel;
import eu.eudat.models.listingmodels.DataManagementPlanProfileListingModel;
import eu.eudat.models.security.Principal;
import eu.eudat.queryable.QueryableList;
import eu.eudat.services.ApiContext;
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);
}
}