mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 23:13:10 +00:00
[DSC-183] new paramater of type of dso in findall and pagination usage in query
This commit is contained in:
@@ -93,8 +93,12 @@ public class SubscribeCLITool {
|
|||||||
IOException {
|
IOException {
|
||||||
// Grab the subscriptions
|
// Grab the subscriptions
|
||||||
|
|
||||||
List<Subscription> subscriptions = subscribeService.findAll(context);
|
List<Subscription> subscriptions = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
subscriptions = subscribeService.findAll(context, null, -1, -1);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
EPerson currentEPerson = null;
|
EPerson currentEPerson = null;
|
||||||
List<Collection> collections = null; // List of Collections
|
List<Collection> collections = null; // List of Collections
|
||||||
|
|
||||||
|
@@ -46,8 +46,18 @@ public class SubscribeServiceImpl implements SubscribeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Subscription> findAll(Context context) throws SQLException {
|
public List<Subscription> findAll(Context context, String resourceType,
|
||||||
return subscriptionDAO.findAllOrderedByEPerson(context);
|
Integer limit, Integer offset) throws Exception {
|
||||||
|
if (resourceType == null) {
|
||||||
|
return subscriptionDAO.findAllOrderedByEPerson(context);
|
||||||
|
} else {
|
||||||
|
if (resourceType.equals("Item") || resourceType.equals("Collection") || resourceType.equals("Community")) {
|
||||||
|
return subscriptionDAO.findAllOrderedByEPersonAndResourceType(context, resourceType, limit, offset);
|
||||||
|
} else {
|
||||||
|
log.error("Resource type must be Item, Collection or Community");
|
||||||
|
throw new Exception("Resource type must be Item, Collection or Community");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -96,16 +106,17 @@ public class SubscribeServiceImpl implements SubscribeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Subscription> getSubscriptionsByEPerson(Context context, EPerson eperson)
|
public List<Subscription> getSubscriptionsByEPerson(Context context, EPerson eperson, Integer limit, Integer offset)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
return subscriptionDAO.findByEPerson(context, eperson);
|
return subscriptionDAO.findByEPerson(context, eperson, limit, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Subscription> getSubscriptionsByEPersonAndDso(Context context,
|
public List<Subscription> getSubscriptionsByEPersonAndDso(Context context,
|
||||||
EPerson eperson, DSpaceObject dSpaceObject)
|
EPerson eperson, DSpaceObject dSpaceObject,
|
||||||
|
Integer limit, Integer offset)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
return subscriptionDAO.findByEPerson(context, eperson);
|
return subscriptionDAO.findByEPersonAndDso(context, eperson, dSpaceObject, limit, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -122,14 +133,13 @@ public class SubscribeServiceImpl implements SubscribeService {
|
|||||||
context.setCurrentUser(eperson);
|
context.setCurrentUser(eperson);
|
||||||
}
|
}
|
||||||
collections = collectionService.findAuthorized(context, null, Constants.ADD);
|
collections = collectionService.findAuthorized(context, null, Constants.ADD);
|
||||||
|
|
||||||
return collections;
|
return collections;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSubscribed(Context context, EPerson eperson,
|
public boolean isSubscribed(Context context, EPerson eperson,
|
||||||
DSpaceObject dSpaceObject) throws SQLException {
|
DSpaceObject dSpaceObject) throws SQLException {
|
||||||
return subscriptionDAO.findByEPersonAndDso(context, eperson, dSpaceObject) != null;
|
return subscriptionDAO.findByEPersonAndDso(context, eperson, dSpaceObject, -1, -1) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
* The contents of this file are subject to the license and copyright
|
* The contents of this file are subject to the license and copyright
|
||||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
* tree and available online at
|
* tree and available online at
|
||||||
*
|
|
||||||
* http://www.dspace.org/license/
|
* http://www.dspace.org/license/
|
||||||
*/
|
*/
|
||||||
package org.dspace.eperson;
|
package org.dspace.eperson;
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
* The contents of this file are subject to the license and copyright
|
* The contents of this file are subject to the license and copyright
|
||||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
* tree and available online at
|
* tree and available online at
|
||||||
*
|
|
||||||
* http://www.dspace.org/license/
|
* http://www.dspace.org/license/
|
||||||
*/
|
*/
|
||||||
package org.dspace.eperson;
|
package org.dspace.eperson;
|
||||||
|
@@ -27,15 +27,20 @@ public interface SubscriptionDAO extends GenericDAO<Subscription> {
|
|||||||
|
|
||||||
public void deleteByDspaceObject(Context context, DSpaceObject dSpaceObject) throws SQLException;
|
public void deleteByDspaceObject(Context context, DSpaceObject dSpaceObject) throws SQLException;
|
||||||
|
|
||||||
public List<Subscription> findByEPerson(Context context, EPerson eperson) throws SQLException;
|
public List<Subscription> findByEPerson(Context context,
|
||||||
|
EPerson eperson, Integer limit, Integer offset) throws SQLException;
|
||||||
|
|
||||||
public List<Subscription> findByEPersonAndDso(Context context,
|
public List<Subscription> findByEPersonAndDso(Context context,
|
||||||
EPerson eperson, DSpaceObject dSpaceObject) throws SQLException;
|
EPerson eperson, DSpaceObject dSpaceObject,
|
||||||
|
Integer limit, Integer offset) throws SQLException;
|
||||||
|
|
||||||
public void deleteByEPerson(Context context, EPerson eperson) throws SQLException;
|
public void deleteByEPerson(Context context, EPerson eperson) throws SQLException;
|
||||||
|
|
||||||
public void deleteByDSOAndEPerson(Context context, DSpaceObject dSpaceObject, EPerson eperson)
|
public void deleteByDSOAndEPerson(Context context, DSpaceObject dSpaceObject, EPerson eperson)
|
||||||
throws SQLException;
|
throws SQLException;
|
||||||
|
|
||||||
|
public List<Subscription> findAllOrderedByEPersonAndResourceType(Context context, String resourceType,
|
||||||
|
Integer limit, Integer offset) throws SQLException;
|
||||||
|
|
||||||
public List<Subscription> findAllOrderedByEPerson(Context context) throws SQLException;
|
public List<Subscription> findAllOrderedByEPerson(Context context) throws SQLException;
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
* The contents of this file are subject to the license and copyright
|
* The contents of this file are subject to the license and copyright
|
||||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
* tree and available online at
|
* tree and available online at
|
||||||
*
|
|
||||||
* http://www.dspace.org/license/
|
* http://www.dspace.org/license/
|
||||||
*/
|
*/
|
||||||
package org.dspace.eperson.dao.impl;
|
package org.dspace.eperson.dao.impl;
|
||||||
@@ -36,18 +35,21 @@ public class SubscriptionDAOImpl extends AbstractHibernateDAO<Subscription> impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Subscription> findByEPerson(Context context, EPerson eperson) throws SQLException {
|
public List<Subscription> findByEPerson(Context context, EPerson eperson,
|
||||||
|
Integer limit, Integer offset) throws SQLException {
|
||||||
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
javax.persistence.criteria.CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Subscription.class);
|
javax.persistence.criteria.CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Subscription.class);
|
||||||
Root<Subscription> subscriptionRoot = criteriaQuery.from(Subscription.class);
|
Root<Subscription> subscriptionRoot = criteriaQuery.from(Subscription.class);
|
||||||
criteriaQuery.select(subscriptionRoot);
|
criteriaQuery.select(subscriptionRoot);
|
||||||
criteriaQuery.where(criteriaBuilder.equal(subscriptionRoot.get(Subscription_.ePerson), eperson));
|
criteriaQuery.where(criteriaBuilder.equal(subscriptionRoot.get(Subscription_.ePerson), eperson));
|
||||||
return list(context, criteriaQuery, false, Subscription.class, -1, -1);
|
return list(context, criteriaQuery, false, Subscription.class, limit, offset);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Subscription> findByEPersonAndDso(Context context, EPerson eperson,
|
public List<Subscription> findByEPersonAndDso(Context context, EPerson eperson,
|
||||||
DSpaceObject dSpaceObject) throws SQLException {
|
DSpaceObject dSpaceObject,
|
||||||
|
Integer limit, Integer offset) throws SQLException {
|
||||||
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
javax.persistence.criteria.CriteriaQuery criteriaQuery =
|
javax.persistence.criteria.CriteriaQuery criteriaQuery =
|
||||||
getCriteriaQuery(criteriaBuilder, Subscription.class);
|
getCriteriaQuery(criteriaBuilder, Subscription.class);
|
||||||
@@ -56,10 +58,10 @@ public class SubscriptionDAOImpl extends AbstractHibernateDAO<Subscription> impl
|
|||||||
criteriaQuery.where(criteriaBuilder.equal(subscriptionRoot.get(Subscription_.ePerson), eperson));
|
criteriaQuery.where(criteriaBuilder.equal(subscriptionRoot.get(Subscription_.ePerson), eperson));
|
||||||
|
|
||||||
criteriaQuery.where(criteriaBuilder.and(criteriaBuilder.equal(
|
criteriaQuery.where(criteriaBuilder.and(criteriaBuilder.equal(
|
||||||
subscriptionRoot.get(Subscription_.ePerson), eperson),
|
subscriptionRoot.get(Subscription_.ePerson), eperson),
|
||||||
criteriaBuilder.equal(subscriptionRoot.get(Subscription_.dSpaceObject), dSpaceObject)
|
criteriaBuilder.equal(subscriptionRoot.get(Subscription_.dSpaceObject), dSpaceObject)
|
||||||
));
|
));
|
||||||
return list(context, criteriaQuery, false, Subscription.class, -1, -1);
|
return list(context, criteriaQuery, false, Subscription.class, limit, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -89,6 +91,23 @@ public class SubscriptionDAOImpl extends AbstractHibernateDAO<Subscription> impl
|
|||||||
query.executeUpdate();
|
query.executeUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Subscription> findAllOrderedByEPersonAndResourceType(Context context, String resourceType,
|
||||||
|
Integer limit, Integer offset) throws SQLException {
|
||||||
|
String hqlQuery = "select s from Subscription s join %s dso ON dso.id = s.dSpaceObject ORDER BY eperson_id";
|
||||||
|
if (resourceType != null) {
|
||||||
|
hqlQuery = String.format(hqlQuery, resourceType);
|
||||||
|
}
|
||||||
|
Query query = createQuery(context, hqlQuery);
|
||||||
|
if (limit != -1) {
|
||||||
|
query.setMaxResults(limit);
|
||||||
|
}
|
||||||
|
if (offset != -1) {
|
||||||
|
query.setFirstResult(offset);
|
||||||
|
}
|
||||||
|
query.setHint("org.hibernate.cacheable", false);
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public List<Subscription> findAllOrderedByEPerson(Context context) throws SQLException {
|
public List<Subscription> findAllOrderedByEPerson(Context context) throws SQLException {
|
||||||
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
* The contents of this file are subject to the license and copyright
|
* The contents of this file are subject to the license and copyright
|
||||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
* tree and available online at
|
* tree and available online at
|
||||||
*
|
|
||||||
* http://www.dspace.org/license/
|
* http://www.dspace.org/license/
|
||||||
*/
|
*/
|
||||||
package org.dspace.eperson.service;
|
package org.dspace.eperson.service;
|
||||||
@@ -33,10 +32,13 @@ public interface SubscribeService {
|
|||||||
* new item appears in the collection.
|
* new item appears in the collection.
|
||||||
*
|
*
|
||||||
* @param context DSpace context
|
* @param context DSpace context
|
||||||
|
* @param limit Number of subscriptions to return
|
||||||
|
* @param offset Offset number
|
||||||
* @return list of Subscription objects
|
* @return list of Subscription objects
|
||||||
* @throws SQLException An exception that provides information on a database access error or other errors.
|
* @throws SQLException An exception that provides information on a database access error or other errors.
|
||||||
*/
|
*/
|
||||||
public List<Subscription> findAll(Context context) throws SQLException;
|
public List<Subscription> findAll(Context context, String resourceType,
|
||||||
|
Integer limit, Integer offset) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribe an e-person to a collection. An e-mail will be sent every day a
|
* Subscribe an e-person to a collection. An e-mail will be sent every day a
|
||||||
@@ -72,10 +74,13 @@ public interface SubscribeService {
|
|||||||
*
|
*
|
||||||
* @param context DSpace context
|
* @param context DSpace context
|
||||||
* @param eperson EPerson
|
* @param eperson EPerson
|
||||||
|
* @param limit Number of subscriptions to return
|
||||||
|
* @param offset Offset number
|
||||||
* @return array of collections e-person is subscribed to
|
* @return array of collections e-person is subscribed to
|
||||||
* @throws SQLException An exception that provides information on a database access error or other errors.
|
* @throws SQLException An exception that provides information on a database access error or other errors.
|
||||||
*/
|
*/
|
||||||
public List<Subscription> getSubscriptionsByEPerson(Context context, EPerson eperson) throws SQLException;
|
public List<Subscription> getSubscriptionsByEPerson(Context context, EPerson eperson,
|
||||||
|
Integer limit, Integer offset) throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find out which collections an e-person is subscribed to and related with dso
|
* Find out which collections an e-person is subscribed to and related with dso
|
||||||
@@ -83,12 +88,16 @@ public interface SubscribeService {
|
|||||||
* @param context DSpace context
|
* @param context DSpace context
|
||||||
* @param eperson EPerson
|
* @param eperson EPerson
|
||||||
* @param dSpaceObject DSpaceObject
|
* @param dSpaceObject DSpaceObject
|
||||||
|
* @param limit Number of subscriptions to return
|
||||||
|
* @param offset Offset number
|
||||||
* @return array of collections e-person is subscribed to and related with dso
|
* @return array of collections e-person is subscribed to and related with dso
|
||||||
* @throws SQLException An exception that provides information on a database access error or other errors.
|
* @throws SQLException An exception that provides information on a database access error or other errors.
|
||||||
*/
|
*/
|
||||||
public List<Subscription> getSubscriptionsByEPersonAndDso(Context context,
|
public List<Subscription> getSubscriptionsByEPersonAndDso(Context context,
|
||||||
EPerson eperson,
|
EPerson eperson,
|
||||||
DSpaceObject dSpaceObject) throws SQLException;
|
DSpaceObject dSpaceObject,
|
||||||
|
Integer limit,
|
||||||
|
Integer offset) throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find out which collections the currently logged in e-person can subscribe to
|
* Find out which collections the currently logged in e-person can subscribe to
|
||||||
@@ -187,7 +196,7 @@ public interface SubscribeService {
|
|||||||
* @throws SQLException An exception that provides information on a database access error or other errors.
|
* @throws SQLException An exception that provides information on a database access error or other errors.
|
||||||
*/
|
*/
|
||||||
public Subscription removeSubscriptionParameter(Context context, Integer id,
|
public Subscription removeSubscriptionParameter(Context context, Integer id,
|
||||||
SubscriptionParameter subscriptionParameter) throws SQLException, AuthorizeException;
|
SubscriptionParameter subscriptionParameter) throws SQLException, AuthorizeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a subscription
|
* Deletes a subscription
|
||||||
|
@@ -90,10 +90,13 @@ public class SubscriptionRestRepository extends DSpaceRestRepository
|
|||||||
@PreAuthorize("hasAuthority('ADMIN')")
|
@PreAuthorize("hasAuthority('ADMIN')")
|
||||||
public Page<SubscriptionRest> findAll(Context context, Pageable pageable) {
|
public Page<SubscriptionRest> findAll(Context context, Pageable pageable) {
|
||||||
try {
|
try {
|
||||||
List<Subscription> subscriptionList = subscribeService.findAll(context);
|
HttpServletRequest req = getRequestService().getCurrentRequest().getHttpServletRequest();
|
||||||
|
String resourceType = req.getParameter("resourceType");
|
||||||
|
List<Subscription> subscriptionList = subscribeService.findAll(context, resourceType,
|
||||||
|
pageable.getPageSize(), Math.toIntExact(pageable.getOffset()));
|
||||||
return converter.toRestPage(subscriptionList, pageable, utils.obtainProjection());
|
return converter.toRestPage(subscriptionList, pageable, utils.obtainProjection());
|
||||||
} catch (SQLException sqlException) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(sqlException.getMessage(), sqlException);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +107,8 @@ public class SubscriptionRestRepository extends DSpaceRestRepository
|
|||||||
EPerson ePerson = personService.findByIdOrLegacyId(context, id);
|
EPerson ePerson = personService.findByIdOrLegacyId(context, id);
|
||||||
if (context.getCurrentUser().equals(ePerson)
|
if (context.getCurrentUser().equals(ePerson)
|
||||||
|| authorizeService.isAdmin(context, context.getCurrentUser())) {
|
|| authorizeService.isAdmin(context, context.getCurrentUser())) {
|
||||||
List<Subscription> subscriptionList = subscribeService.getSubscriptionsByEPerson(context, ePerson);
|
List<Subscription> subscriptionList = subscribeService.getSubscriptionsByEPerson(context,
|
||||||
|
ePerson, pageable.getPageSize(), Math.toIntExact(pageable.getOffset()));
|
||||||
return converter.toRestPage(subscriptionList, pageable, utils.obtainProjection());
|
return converter.toRestPage(subscriptionList, pageable, utils.obtainProjection());
|
||||||
} else {
|
} else {
|
||||||
throw new AuthorizeException("Only admin or e-person themselves can search for it's subscription");
|
throw new AuthorizeException("Only admin or e-person themselves can search for it's subscription");
|
||||||
@@ -130,7 +134,8 @@ public class SubscriptionRestRepository extends DSpaceRestRepository
|
|||||||
if (context.getCurrentUser().equals(ePerson)
|
if (context.getCurrentUser().equals(ePerson)
|
||||||
|| authorizeService.isAdmin(context, context.getCurrentUser())) {
|
|| authorizeService.isAdmin(context, context.getCurrentUser())) {
|
||||||
List<Subscription> subscriptionList =
|
List<Subscription> subscriptionList =
|
||||||
subscribeService.getSubscriptionsByEPersonAndDso(context, ePerson, dSpaceObject);
|
subscribeService.getSubscriptionsByEPersonAndDso(context, ePerson, dSpaceObject,
|
||||||
|
pageable.getPageSize(), Math.toIntExact(pageable.getOffset()));
|
||||||
return converter.toRestPage(subscriptionList, pageable, subscriptionList.size(),
|
return converter.toRestPage(subscriptionList, pageable, subscriptionList.size(),
|
||||||
utils.obtainProjection());
|
utils.obtainProjection());
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user