diff --git a/modules/dataverse-parent/pom.xml b/modules/dataverse-parent/pom.xml
index 1d99c1cd3d8..db0fa46a952 100644
--- a/modules/dataverse-parent/pom.xml
+++ b/modules/dataverse-parent/pom.xml
@@ -200,9 +200,6 @@
0.43.4
-
-
- 5.0.0
diff --git a/pom.xml b/pom.xml
index bcca9884d50..5536bcccb05 100644
--- a/pom.xml
+++ b/pom.xml
@@ -252,20 +252,6 @@
expressly
provided
-
-
- com.querydsl
- querydsl-apt
- ${querydsl.version}
- jakarta
- provided
-
-
- com.querydsl
- querydsl-jpa
- ${querydsl.version}
- jakarta
-
commons-io
diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetVersionFilesServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/DatasetVersionFilesServiceBean.java
index fc662ee80bb..78fd896c897 100644
--- a/src/main/java/edu/harvard/iq/dataverse/DatasetVersionFilesServiceBean.java
+++ b/src/main/java/edu/harvard/iq/dataverse/DatasetVersionFilesServiceBean.java
@@ -1,37 +1,20 @@
package edu.harvard.iq.dataverse;
-import edu.harvard.iq.dataverse.QDataFileCategory;
-import edu.harvard.iq.dataverse.QDataFileTag;
-import edu.harvard.iq.dataverse.QDataTable;
-import edu.harvard.iq.dataverse.QDvObject;
-import edu.harvard.iq.dataverse.QEmbargo;
-import edu.harvard.iq.dataverse.QFileMetadata;
-
-import com.querydsl.core.Tuple;
-import com.querydsl.core.types.dsl.BooleanExpression;
-import com.querydsl.core.types.dsl.CaseBuilder;
-import com.querydsl.core.types.dsl.DateExpression;
-import com.querydsl.core.types.dsl.DateTimeExpression;
-
-import com.querydsl.jpa.impl.JPAQuery;
-import com.querydsl.jpa.impl.JPAQueryFactory;
-
+import edu.harvard.iq.dataverse.FileSearchCriteria.FileAccessStatus;
import jakarta.ejb.Stateless;
import jakarta.inject.Named;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
+import jakarta.persistence.Tuple;
+import jakarta.persistence.TypedQuery;
+import jakarta.persistence.criteria.*;
import java.io.Serializable;
import java.sql.Timestamp;
-import java.time.LocalDate;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import static edu.harvard.iq.dataverse.DataFileTag.TagLabelToTypes;
-import edu.harvard.iq.dataverse.FileSearchCriteria.FileAccessStatus;
-
@Stateless
@Named
public class DatasetVersionFilesServiceBean implements Serializable {
@@ -39,12 +22,6 @@ public class DatasetVersionFilesServiceBean implements Serializable {
@PersistenceContext(unitName = "VDCNet-ejbPU")
private EntityManager em;
- private final QFileMetadata fileMetadata = QFileMetadata.fileMetadata;
- private final QDvObject dvObject = QDvObject.dvObject;
- private final QDataFileCategory dataFileCategory = QDataFileCategory.dataFileCategory;
- private final QDataFileTag dataFileTag = QDataFileTag.dataFileTag;
- private final QDataTable dataTable = QDataTable.dataTable;
-
/**
* Different criteria to sort the results of FileMetadata queries used in {@link DatasetVersionFilesServiceBean#getFileMetadatas}
*/
@@ -73,10 +50,13 @@ public enum FileDownloadSizeMode {
* @return long value of total file metadata count
*/
public long getFileMetadataCount(DatasetVersion datasetVersion, FileSearchCriteria searchCriteria) {
- JPAQueryFactory queryFactory = new JPAQueryFactory(em);
- JPAQuery baseQuery = queryFactory.selectFrom(fileMetadata).where(fileMetadata.datasetVersion.id.eq(datasetVersion.getId()));
- applyFileSearchCriteriaToQuery(baseQuery, searchCriteria);
- return baseQuery.stream().count();
+ CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
+ CriteriaQuery criteriaQuery = criteriaBuilder.createQuery(Long.class);
+ Root fileMetadataRoot = criteriaQuery.from(FileMetadata.class);
+ criteriaQuery
+ .select(criteriaBuilder.count(fileMetadataRoot))
+ .where(createSearchCriteriaPredicate(datasetVersion, searchCriteria, criteriaBuilder, criteriaQuery, fileMetadataRoot));
+ return em.createQuery(criteriaQuery).getSingleResult();
}
/**
@@ -87,19 +67,15 @@ public long getFileMetadataCount(DatasetVersion datasetVersion, FileSearchCriter
* @return Map of file metadata counts per content type
*/
public Map getFileMetadataCountPerContentType(DatasetVersion datasetVersion, FileSearchCriteria searchCriteria) {
- JPAQueryFactory queryFactory = new JPAQueryFactory(em);
- JPAQuery baseQuery = queryFactory
- .select(fileMetadata.dataFile.contentType, fileMetadata.count())
- .from(fileMetadata)
- .where(fileMetadata.datasetVersion.id.eq(datasetVersion.getId()))
- .groupBy(fileMetadata.dataFile.contentType);
- applyFileSearchCriteriaToQuery(baseQuery, searchCriteria);
- List contentTypeOccurrences = baseQuery.fetch();
- Map result = new HashMap<>();
- for (Tuple occurrence : contentTypeOccurrences) {
- result.put(occurrence.get(fileMetadata.dataFile.contentType), occurrence.get(fileMetadata.count()));
- }
- return result;
+ CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
+ CriteriaQuery criteriaQuery = criteriaBuilder.createTupleQuery();
+ Root fileMetadataRoot = criteriaQuery.from(FileMetadata.class);
+ Path contentType = fileMetadataRoot.get("dataFile").get("contentType");
+ criteriaQuery
+ .multiselect(contentType, criteriaBuilder.count(contentType))
+ .where(createSearchCriteriaPredicate(datasetVersion, searchCriteria, criteriaBuilder, criteriaQuery, fileMetadataRoot))
+ .groupBy(contentType);
+ return getStringLongMapResultFromQuery(criteriaQuery);
}
/**
@@ -110,19 +86,18 @@ public Map getFileMetadataCountPerContentType(DatasetVersion datas
* @return Map of file metadata counts per category name
*/
public Map getFileMetadataCountPerCategoryName(DatasetVersion datasetVersion, FileSearchCriteria searchCriteria) {
- JPAQueryFactory queryFactory = new JPAQueryFactory(em);
- JPAQuery baseQuery = queryFactory
- .select(dataFileCategory.name, fileMetadata.count())
- .from(dataFileCategory, fileMetadata)
- .where(fileMetadata.datasetVersion.id.eq(datasetVersion.getId()).and(fileMetadata.fileCategories.contains(dataFileCategory)))
- .groupBy(dataFileCategory.name);
- applyFileSearchCriteriaToQuery(baseQuery, searchCriteria);
- List categoryNameOccurrences = baseQuery.fetch();
- Map result = new HashMap<>();
- for (Tuple occurrence : categoryNameOccurrences) {
- result.put(occurrence.get(dataFileCategory.name), occurrence.get(fileMetadata.count()));
- }
- return result;
+ CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
+ CriteriaQuery criteriaQuery = criteriaBuilder.createTupleQuery();
+ Root fileMetadataRoot = criteriaQuery.from(FileMetadata.class);
+ Root dataFileCategoryRoot = criteriaQuery.from(DataFileCategory.class);
+ Path categoryName = dataFileCategoryRoot.get("name");
+ criteriaQuery
+ .multiselect(categoryName, criteriaBuilder.count(fileMetadataRoot))
+ .where(criteriaBuilder.and(
+ createSearchCriteriaPredicate(datasetVersion, searchCriteria, criteriaBuilder, criteriaQuery, fileMetadataRoot),
+ dataFileCategoryRoot.in(fileMetadataRoot.get("fileCategories"))))
+ .groupBy(categoryName);
+ return getStringLongMapResultFromQuery(criteriaQuery);
}
/**
@@ -133,17 +108,21 @@ public Map getFileMetadataCountPerCategoryName(DatasetVersion data
* @return Map of file metadata counts per DataFileTag.TagType
*/
public Map getFileMetadataCountPerTabularTagName(DatasetVersion datasetVersion, FileSearchCriteria searchCriteria) {
- JPAQueryFactory queryFactory = new JPAQueryFactory(em);
- JPAQuery baseQuery = queryFactory
- .select(dataFileTag.type, fileMetadata.count())
- .from(dataFileTag, fileMetadata)
- .where(fileMetadata.datasetVersion.id.eq(datasetVersion.getId()).and(fileMetadata.dataFile.dataFileTags.contains(dataFileTag)))
- .groupBy(dataFileTag.type);
- applyFileSearchCriteriaToQuery(baseQuery, searchCriteria);
- List tagNameOccurrences = baseQuery.fetch();
+ CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
+ CriteriaQuery criteriaQuery = criteriaBuilder.createTupleQuery();
+ Root fileMetadataRoot = criteriaQuery.from(FileMetadata.class);
+ Root dataFileTagRoot = criteriaQuery.from(DataFileTag.class);
+ Path dataFileTagType = dataFileTagRoot.get("type");
+ criteriaQuery
+ .multiselect(dataFileTagType, criteriaBuilder.count(fileMetadataRoot))
+ .where(criteriaBuilder.and(
+ createSearchCriteriaPredicate(datasetVersion, searchCriteria, criteriaBuilder, criteriaQuery, fileMetadataRoot),
+ dataFileTagRoot.in(fileMetadataRoot.get("dataFile").get("dataFileTags"))))
+ .groupBy(dataFileTagType);
+ List tagNameOccurrences = em.createQuery(criteriaQuery).getResultList();
Map result = new HashMap<>();
for (Tuple occurrence : tagNameOccurrences) {
- result.put(occurrence.get(dataFileTag.type), occurrence.get(fileMetadata.count()));
+ result.put(occurrence.get(0, DataFileTag.TagType.class), occurrence.get(1, Long.class));
}
return result;
}
@@ -175,16 +154,21 @@ public Map getFileMetadataCountPerAccessStatus(DatasetVe
* @return a FileMetadata list from the specified DatasetVersion
*/
public List getFileMetadatas(DatasetVersion datasetVersion, Integer limit, Integer offset, FileSearchCriteria searchCriteria, FileOrderCriteria orderCriteria) {
- JPAQuery baseQuery = createGetFileMetadatasBaseQuery(datasetVersion, orderCriteria);
- applyFileSearchCriteriaToQuery(baseQuery, searchCriteria);
- applyOrderCriteriaToGetFileMetadatasQuery(baseQuery, orderCriteria);
+ CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
+ CriteriaQuery criteriaQuery = criteriaBuilder.createQuery(FileMetadata.class);
+ Root fileMetadataRoot = criteriaQuery.from(FileMetadata.class);
+ criteriaQuery
+ .select(fileMetadataRoot)
+ .where(createSearchCriteriaPredicate(datasetVersion, searchCriteria, criteriaBuilder, criteriaQuery, fileMetadataRoot))
+ .orderBy(createGetFileMetadatasOrder(criteriaBuilder, orderCriteria, fileMetadataRoot));
+ TypedQuery typedQuery = em.createQuery(criteriaQuery);
if (limit != null) {
- baseQuery.limit(limit);
+ typedQuery.setMaxResults(limit);
}
if (offset != null) {
- baseQuery.offset(offset);
+ typedQuery.setFirstResult(offset);
}
- return baseQuery.fetch();
+ return typedQuery.getResultList();
}
/**
@@ -213,119 +197,125 @@ private void addAccessStatusCountToTotal(DatasetVersion datasetVersion, Map baseQuery = queryFactory
- .selectFrom(fileMetadata)
- .where(fileMetadata.datasetVersion.id.eq(datasetVersion.getId()).and(createGetFileMetadatasAccessStatusExpression(accessStatus)));
- applyFileSearchCriteriaToQuery(baseQuery, searchCriteria);
- return baseQuery.stream().count();
+ CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
+ CriteriaQuery criteriaQuery = criteriaBuilder.createQuery(Long.class);
+ Root fileMetadataRoot = criteriaQuery.from(FileMetadata.class);
+ criteriaQuery
+ .select(criteriaBuilder.count(fileMetadataRoot))
+ .where(criteriaBuilder.and(
+ createSearchCriteriaAccessStatusPredicate(accessStatus, criteriaBuilder, fileMetadataRoot),
+ createSearchCriteriaPredicate(datasetVersion, searchCriteria, criteriaBuilder, criteriaQuery, fileMetadataRoot)));
+ return em.createQuery(criteriaQuery).getSingleResult();
}
- private JPAQuery createGetFileMetadatasBaseQuery(DatasetVersion datasetVersion, FileOrderCriteria orderCriteria) {
- JPAQueryFactory queryFactory = new JPAQueryFactory(em);
- JPAQuery baseQuery = queryFactory.selectFrom(fileMetadata).where(fileMetadata.datasetVersion.id.eq(datasetVersion.getId()));
- if (orderCriteria == FileOrderCriteria.Newest || orderCriteria == FileOrderCriteria.Oldest) {
- baseQuery.from(dvObject).where(dvObject.id.eq(fileMetadata.dataFile.id));
- }
- return baseQuery;
- }
-
- private BooleanExpression createGetFileMetadatasAccessStatusExpression(FileAccessStatus accessStatus) {
- QEmbargo embargo = fileMetadata.dataFile.embargo;
- BooleanExpression activelyEmbargoedExpression = embargo.dateAvailable.goe(DateExpression.currentDate(LocalDate.class));
- BooleanExpression inactivelyEmbargoedExpression = embargo.isNull();
- BooleanExpression accessStatusExpression;
- switch (accessStatus) {
- case EmbargoedThenRestricted:
- accessStatusExpression = activelyEmbargoedExpression.and(fileMetadata.dataFile.restricted.isTrue());
- break;
- case EmbargoedThenPublic:
- accessStatusExpression = activelyEmbargoedExpression.and(fileMetadata.dataFile.restricted.isFalse());
- break;
- case Restricted:
- accessStatusExpression = inactivelyEmbargoedExpression.and(fileMetadata.dataFile.restricted.isTrue());
- break;
- case Public:
- accessStatusExpression = inactivelyEmbargoedExpression.and(fileMetadata.dataFile.restricted.isFalse());
- break;
- default:
- throw new IllegalStateException("Unexpected value: " + accessStatus);
- }
- return accessStatusExpression;
+ private Predicate createSearchCriteriaAccessStatusPredicate(FileAccessStatus accessStatus, CriteriaBuilder criteriaBuilder, Root fileMetadataRoot) {
+ Path