mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 14:03:17 +00:00
[DSC-193] tests added, code review fixes, other fixes in pagination and ordering
This commit is contained in:
@@ -219,15 +219,15 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl<Community> imp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Bitstream setLogo(Context context, Community community, InputStream is)
|
public Bitstream setLogo(Context context, Community community, InputStream is)
|
||||||
throws AuthorizeException, IOException, SQLException {
|
throws AuthorizeException, IOException, SQLException {
|
||||||
// Check authorisation
|
// Check authorisation
|
||||||
// authorized to remove the logo when DELETE rights
|
// authorized to remove the logo when DELETE rights
|
||||||
// authorized when canEdit
|
// authorized when canEdit
|
||||||
if (!((is == null) && authorizeService.authorizeActionBoolean(
|
if (!((is == null) && authorizeService.authorizeActionBoolean(
|
||||||
context, community, Constants.DELETE))) {
|
context, community, Constants.DELETE))) {
|
||||||
canEdit(context, community);
|
canEdit(context, community);
|
||||||
}
|
}
|
||||||
subscribeService.deleteByDspaceObject(context, community);
|
|
||||||
// First, delete any existing logo
|
// First, delete any existing logo
|
||||||
Bitstream oldLogo = community.getLogo();
|
Bitstream oldLogo = community.getLogo();
|
||||||
if (oldLogo != null) {
|
if (oldLogo != null) {
|
||||||
@@ -244,7 +244,7 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl<Community> imp
|
|||||||
// now create policy for logo bitstream
|
// now create policy for logo bitstream
|
||||||
// to match our READ policy
|
// to match our READ policy
|
||||||
List<ResourcePolicy> policies = authorizeService
|
List<ResourcePolicy> policies = authorizeService
|
||||||
.getPoliciesActionFilter(context, community, Constants.READ);
|
.getPoliciesActionFilter(context, community, Constants.READ);
|
||||||
authorizeService.addPolicies(context, policies, newLogo);
|
authorizeService.addPolicies(context, policies, newLogo);
|
||||||
|
|
||||||
log.info(LogHelper.getHeader(context, "set_logo",
|
log.info(LogHelper.getHeader(context, "set_logo",
|
||||||
|
@@ -104,6 +104,9 @@ public class SubscribeCLITool {
|
|||||||
|
|
||||||
// Go through the list collating subscriptions for each e-person
|
// Go through the list collating subscriptions for each e-person
|
||||||
for (Subscription subscription : subscriptions) {
|
for (Subscription subscription : subscriptions) {
|
||||||
|
if (!(subscription.getdSpaceObject() != null && subscription.getdSpaceObject() instanceof Collection)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// Does this row relate to the same e-person as the last?
|
// Does this row relate to the same e-person as the last?
|
||||||
if ((currentEPerson == null)
|
if ((currentEPerson == null)
|
||||||
|| (!subscription.getePerson().getID().equals(currentEPerson
|
|| (!subscription.getePerson().getID().equals(currentEPerson
|
||||||
|
@@ -49,10 +49,10 @@ public class SubscribeServiceImpl implements SubscribeService {
|
|||||||
public List<Subscription> findAll(Context context, String resourceType,
|
public List<Subscription> findAll(Context context, String resourceType,
|
||||||
Integer limit, Integer offset) throws Exception {
|
Integer limit, Integer offset) throws Exception {
|
||||||
if (resourceType == null) {
|
if (resourceType == null) {
|
||||||
return subscriptionDAO.findAllOrderedByEPerson(context);
|
return subscriptionDAO.findAllOrderedById(context, limit, offset);
|
||||||
} else {
|
} else {
|
||||||
if (resourceType.equals("Item") || resourceType.equals("Collection") || resourceType.equals("Community")) {
|
if (resourceType.equals("Item") || resourceType.equals("Collection") || resourceType.equals("Community")) {
|
||||||
return subscriptionDAO.findAllOrderedByEPersonAndResourceType(context, resourceType, limit, offset);
|
return subscriptionDAO.findAllOrderedByIDAndResourceType(context, resourceType, limit, offset);
|
||||||
} else {
|
} else {
|
||||||
log.error("Resource type must be Item, Collection or Community");
|
log.error("Resource type must be Item, Collection or Community");
|
||||||
throw new Exception("Resource type must be Item, Collection or Community");
|
throw new Exception("Resource type must be Item, Collection or Community");
|
||||||
@@ -69,13 +69,13 @@ public class SubscribeServiceImpl implements SubscribeService {
|
|||||||
if (authorizeService.isAdmin(context)
|
if (authorizeService.isAdmin(context)
|
||||||
|| ((context.getCurrentUser() != null) && (context
|
|| ((context.getCurrentUser() != null) && (context
|
||||||
.getCurrentUser().getID().equals(eperson.getID())))) {
|
.getCurrentUser().getID().equals(eperson.getID())))) {
|
||||||
Subscription new_subscription = subscriptionDAO.create(context, new Subscription());
|
Subscription newSubscription = subscriptionDAO.create(context, new Subscription());
|
||||||
subscriptionParameterList.forEach(subscriptionParameter ->
|
subscriptionParameterList.forEach(subscriptionParameter ->
|
||||||
new_subscription.addParameter(subscriptionParameter));
|
newSubscription.addParameter(subscriptionParameter));
|
||||||
new_subscription.setePerson(eperson);
|
newSubscription.setePerson(eperson);
|
||||||
new_subscription.setdSpaceObject(dSpaceObject);
|
newSubscription.setdSpaceObject(dSpaceObject);
|
||||||
new_subscription.setType(type);
|
newSubscription.setType(type);
|
||||||
return new_subscription;
|
return newSubscription;
|
||||||
} else {
|
} else {
|
||||||
throw new AuthorizeException(
|
throw new AuthorizeException(
|
||||||
"Only admin or e-person themselves can subscribe");
|
"Only admin or e-person themselves can subscribe");
|
||||||
@@ -153,8 +153,13 @@ public class SubscribeServiceImpl implements SubscribeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Subscription findById(Context context, int id) throws SQLException {
|
public Subscription findById(Context context, int id) throws SQLException, AuthorizeException {
|
||||||
return subscriptionDAO.findByID(context, Subscription.class, id);
|
Subscription subscription = subscriptionDAO.findByID(context, Subscription.class, id);
|
||||||
|
if (context.getCurrentUser().equals(subscription.getePerson()) ||
|
||||||
|
authorizeService.isAdmin(context, context.getCurrentUser())) {
|
||||||
|
return subscription;
|
||||||
|
}
|
||||||
|
throw new AuthorizeException("Only admin or e-person themselves can edit the subscription");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -39,8 +39,8 @@ public interface SubscriptionDAO extends GenericDAO<Subscription> {
|
|||||||
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,
|
public List<Subscription> findAllOrderedByIDAndResourceType(Context context, String resourceType,
|
||||||
Integer limit, Integer offset) throws SQLException;
|
Integer limit, Integer offset) throws SQLException;
|
||||||
|
|
||||||
public List<Subscription> findAllOrderedByEPerson(Context context) throws SQLException;
|
public List<Subscription> findAllOrderedById(Context context, Integer limit, Integer offset) throws SQLException;
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,9 @@ public class SubscriptionDAOImpl extends AbstractHibernateDAO<Subscription> impl
|
|||||||
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));
|
||||||
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
|
orderList.add(criteriaBuilder.asc(subscriptionRoot.get(Subscription_.id)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
return list(context, criteriaQuery, false, Subscription.class, limit, offset);
|
return list(context, criteriaQuery, false, Subscription.class, limit, offset);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -61,6 +64,9 @@ public class SubscriptionDAOImpl extends AbstractHibernateDAO<Subscription> impl
|
|||||||
subscriptionRoot.get(Subscription_.ePerson), eperson),
|
subscriptionRoot.get(Subscription_.ePerson), eperson),
|
||||||
criteriaBuilder.equal(subscriptionRoot.get(Subscription_.dSpaceObject), dSpaceObject)
|
criteriaBuilder.equal(subscriptionRoot.get(Subscription_.dSpaceObject), dSpaceObject)
|
||||||
));
|
));
|
||||||
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
|
orderList.add(criteriaBuilder.asc(subscriptionRoot.get(Subscription_.id)));
|
||||||
|
criteriaQuery.orderBy(orderList);
|
||||||
return list(context, criteriaQuery, false, Subscription.class, limit, offset);
|
return list(context, criteriaQuery, false, Subscription.class, limit, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,9 +98,10 @@ public class SubscriptionDAOImpl extends AbstractHibernateDAO<Subscription> impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Subscription> findAllOrderedByEPersonAndResourceType(Context context, String resourceType,
|
public List<Subscription> findAllOrderedByIDAndResourceType(Context context, String resourceType,
|
||||||
Integer limit, Integer offset) throws SQLException {
|
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";
|
String hqlQuery = "select s from Subscription s join %s dso " +
|
||||||
|
"ON dso.id = s.dSpaceObject ORDER BY subscription_id";
|
||||||
if (resourceType != null) {
|
if (resourceType != null) {
|
||||||
hqlQuery = String.format(hqlQuery, resourceType);
|
hqlQuery = String.format(hqlQuery, resourceType);
|
||||||
}
|
}
|
||||||
@@ -109,14 +116,14 @@ public class SubscriptionDAOImpl extends AbstractHibernateDAO<Subscription> impl
|
|||||||
return query.getResultList();
|
return query.getResultList();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public List<Subscription> findAllOrderedByEPerson(Context context) throws SQLException {
|
public List<Subscription> findAllOrderedById(Context context, Integer limit, Integer offset) throws SQLException {
|
||||||
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Subscription.class);
|
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);
|
||||||
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
List<javax.persistence.criteria.Order> orderList = new LinkedList<>();
|
||||||
orderList.add(criteriaBuilder.asc(subscriptionRoot.get(Subscription_.ePerson)));
|
orderList.add(criteriaBuilder.asc(subscriptionRoot.get(Subscription_.id)));
|
||||||
criteriaQuery.orderBy(orderList);
|
criteriaQuery.orderBy(orderList);
|
||||||
return list(context, criteriaQuery, false, Subscription.class, -1, -1);
|
return list(context, criteriaQuery, false, Subscription.class, limit, offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -157,7 +157,7 @@ public interface SubscribeService {
|
|||||||
* @param id the id of subscription to be searched
|
* @param id the id of subscription to be searched
|
||||||
* @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 findById(Context context, int id) throws SQLException;
|
public Subscription findById(Context context, int id) throws SQLException, AuthorizeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a subscription by id
|
* Updates a subscription by id
|
||||||
|
@@ -14,6 +14,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import org.dspace.app.rest.model.DSpaceObjectRest;
|
import org.dspace.app.rest.model.DSpaceObjectRest;
|
||||||
import org.dspace.app.rest.model.SubscriptionRest;
|
import org.dspace.app.rest.model.SubscriptionRest;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
import org.dspace.app.rest.projection.Projection;
|
||||||
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.Subscription;
|
import org.dspace.eperson.Subscription;
|
||||||
import org.dspace.eperson.service.SubscribeService;
|
import org.dspace.eperson.service.SubscribeService;
|
||||||
@@ -38,7 +39,7 @@ public class SubscriptionDSpaceObjectLinkRepository extends AbstractDSpaceRestRe
|
|||||||
public DSpaceObjectRest getDSpaceObject(@Nullable HttpServletRequest request,
|
public DSpaceObjectRest getDSpaceObject(@Nullable HttpServletRequest request,
|
||||||
Integer subscriptionId,
|
Integer subscriptionId,
|
||||||
@Nullable Pageable optionalPageable,
|
@Nullable Pageable optionalPageable,
|
||||||
Projection projection) {
|
Projection projection) throws AuthorizeException {
|
||||||
try {
|
try {
|
||||||
Context context = obtainContext();
|
Context context = obtainContext();
|
||||||
Subscription subscription = subscribeService.findById(context, subscriptionId);
|
Subscription subscription = subscribeService.findById(context, subscriptionId);
|
||||||
@@ -51,6 +52,8 @@ public class SubscriptionDSpaceObjectLinkRepository extends AbstractDSpaceRestRe
|
|||||||
return converter.toRest(initializer.getImplementation(), projection);
|
return converter.toRest(initializer.getImplementation(), projection);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
} catch (AuthorizeException e) {
|
||||||
|
throw new AuthorizeException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import org.dspace.app.rest.model.EPersonRest;
|
import org.dspace.app.rest.model.EPersonRest;
|
||||||
import org.dspace.app.rest.model.SubscriptionRest;
|
import org.dspace.app.rest.model.SubscriptionRest;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
import org.dspace.app.rest.projection.Projection;
|
||||||
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.Subscription;
|
import org.dspace.eperson.Subscription;
|
||||||
import org.dspace.eperson.service.SubscribeService;
|
import org.dspace.eperson.service.SubscribeService;
|
||||||
@@ -34,7 +35,7 @@ public class SubscriptionEPersonLinkRepository extends AbstractDSpaceRestReposit
|
|||||||
public EPersonRest getEPerson(@Nullable HttpServletRequest request,
|
public EPersonRest getEPerson(@Nullable HttpServletRequest request,
|
||||||
Integer subscriptionId,
|
Integer subscriptionId,
|
||||||
@Nullable Pageable optionalPageable,
|
@Nullable Pageable optionalPageable,
|
||||||
Projection projection) {
|
Projection projection) throws AuthorizeException {
|
||||||
try {
|
try {
|
||||||
Context context = obtainContext();
|
Context context = obtainContext();
|
||||||
Subscription subscription = subscribeService.findById(context, subscriptionId);
|
Subscription subscription = subscribeService.findById(context, subscriptionId);
|
||||||
@@ -46,5 +47,8 @@ public class SubscriptionEPersonLinkRepository extends AbstractDSpaceRestReposit
|
|||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
catch (AuthorizeException e) {
|
||||||
|
throw new AuthorizeException(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -83,6 +83,8 @@ public class SubscriptionRestRepository extends DSpaceRestRepository
|
|||||||
return converter.toRest(subscription, utils.obtainProjection());
|
return converter.toRest(subscription, utils.obtainProjection());
|
||||||
} catch (SQLException sqlException) {
|
} catch (SQLException sqlException) {
|
||||||
throw new RuntimeException(sqlException.getMessage(), sqlException);
|
throw new RuntimeException(sqlException.getMessage(), sqlException);
|
||||||
|
} catch (AuthorizeException authorizeException) {
|
||||||
|
throw new RuntimeException(authorizeException.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +98,7 @@ public class SubscriptionRestRepository extends DSpaceRestRepository
|
|||||||
pageable.getPageSize(), Math.toIntExact(pageable.getOffset()));
|
pageable.getPageSize(), Math.toIntExact(pageable.getOffset()));
|
||||||
return converter.toRestPage(subscriptionList, pageable, utils.obtainProjection());
|
return converter.toRestPage(subscriptionList, pageable, utils.obtainProjection());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,6 +207,8 @@ public class SubscriptionRestRepository extends DSpaceRestRepository
|
|||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new ResourceNotFoundException(notFoundException);
|
throw new ResourceNotFoundException(notFoundException);
|
||||||
|
} catch (AuthorizeException e) {
|
||||||
|
throw new AuthorizeException(e.getMessage());
|
||||||
}
|
}
|
||||||
if (id.equals(subscription.getID())) {
|
if (id.equals(subscription.getID())) {
|
||||||
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
|
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
|
||||||
@@ -218,6 +222,7 @@ public class SubscriptionRestRepository extends DSpaceRestRepository
|
|||||||
}
|
}
|
||||||
subscription = subscribeService.updateSubscription(context, id, ePerson,
|
subscription = subscribeService.updateSubscription(context, id, ePerson,
|
||||||
dSpaceObject, subscriptionParameterList, subscriptionRest.getSubscriptionType());
|
dSpaceObject, subscriptionParameterList, subscriptionRest.getSubscriptionType());
|
||||||
|
context.commit();
|
||||||
return converter.toRest(subscription, utils.obtainProjection());
|
return converter.toRest(subscription, utils.obtainProjection());
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("The id in the Json and the id in the url do not match: "
|
throw new IllegalArgumentException("The id in the Json and the id in the url do not match: "
|
||||||
@@ -240,6 +245,10 @@ public class SubscriptionRestRepository extends DSpaceRestRepository
|
|||||||
resourcePatch.patch(context, subscription, patch.getOperations());
|
resourcePatch.patch(context, subscription, patch.getOperations());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
|
} catch (AuthorizeException authorizeException) {
|
||||||
|
throw new AuthorizeException(authorizeException.getMessage());
|
||||||
|
} catch (RuntimeException runtimeException) {
|
||||||
|
throw new RuntimeException(runtimeException.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation for ResearcherProfile visibility patches.
|
* Implementation for ResearcherProfile visibility patches.
|
||||||
*SubscriptionParameterAddOperationpatches
|
*
|
||||||
* Example:
|
* Example:
|
||||||
* <code> curl -X PATCH http://${dspace.server.url}/api/eperson/profiles/<:id-eperson> -H "
|
* <code> curl -X PATCH http://${dspace.server.url}/api/eperson/profiles/<:id-eperson> -H "
|
||||||
* Content-Type: application/json" -d '[{ "op": "replace", "path": "
|
* Content-Type: application/json" -d '[{ "op": "replace", "path": "
|
||||||
|
@@ -80,13 +80,10 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
|
|||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIND ALL
|
||||||
@Test
|
@Test
|
||||||
public void findAll() throws Exception {
|
public void findAll() throws Exception {
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
//When we call the root endpoint as anonymous user
|
|
||||||
getClient().perform(get("/api/core/subscriptions"))
|
|
||||||
//The status has to be 401 Not Authorized
|
|
||||||
.andExpect(status().isUnauthorized());
|
|
||||||
String token = getAuthToken(admin.getEmail(), password);
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
|
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
|
||||||
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
|
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
|
||||||
@@ -118,15 +115,80 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findByIdAsAdministrator() throws Exception {
|
public void findAllAnonymous() throws Exception {
|
||||||
|
//When we call the root endpoint as anonymous user
|
||||||
|
getClient().perform(get("/api/core/subscriptions"))
|
||||||
|
//The status has to be 401 Not Authorized
|
||||||
|
.andExpect(status().isUnauthorized());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAllAsUser() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
String token = getAuthToken(eperson.getEmail(), password);
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
//When we call the root endpoint as simple user
|
||||||
|
getClient(token).perform(get("/api/core/subscriptions"))
|
||||||
|
//The status has to be 403 Forbidden
|
||||||
|
.andExpect(status().isForbidden());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findAllWithResourceType() throws Exception {
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
//When we call the root endpoint as anonymous user
|
//When we call the root endpoint as anonymous user
|
||||||
getClient().perform(get("/api/core/subscriptions"))
|
getClient().perform(get("/api/core/subscriptions"))
|
||||||
//The status has to be 403 Not Authorized
|
//The status has to be 401 Not Authorized
|
||||||
.andExpect(status().isUnauthorized());
|
.andExpect(status().isUnauthorized());
|
||||||
String token = getAuthToken(admin.getEmail(), password);
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
|
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
|
||||||
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
|
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
|
||||||
|
subscriptionParameter.setName("Frequency");
|
||||||
|
subscriptionParameter.setValue("Daily");
|
||||||
|
subscriptionParameterList.add(subscriptionParameter);
|
||||||
|
Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "TypeTest", publicItem, admin, subscriptionParameterList).build();
|
||||||
|
subscriptionParameter.setSubscription(subscription);
|
||||||
|
//When we call the root endpoint
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
getClient(token).perform(get("/api/core/subscriptions?resourceType=Item"))
|
||||||
|
//The status has to be 200 OK
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
//We expect the content type to be "application/hal+json;charset=UTF-8"
|
||||||
|
.andExpect(content().contentType(contentType))
|
||||||
|
//By default we expect at least 1 submission forms so this to be reflected in the page object
|
||||||
|
.andExpect(jsonPath("$.page.size", is(20)))
|
||||||
|
.andExpect(jsonPath("$.page.totalElements", greaterThanOrEqualTo(1)))
|
||||||
|
.andExpect(jsonPath("$.page.totalPages", greaterThanOrEqualTo(1)))
|
||||||
|
.andExpect(jsonPath("$.page.number", is(0)))
|
||||||
|
.andExpect(jsonPath("$._embedded.subscriptions[0].subscriptionType", is("TypeTest")))
|
||||||
|
.andExpect(jsonPath("$._embedded.subscriptions[0]._links.dSpaceObject.href", Matchers.startsWith(REST_SERVER_URL + "core/subscriptions")))
|
||||||
|
.andExpect(jsonPath("$._embedded.subscriptions[0]._links.dSpaceObject.href", Matchers.endsWith("dSpaceObject")))
|
||||||
|
.andExpect(jsonPath("$._embedded.subscriptions[0]._links.ePerson.href", Matchers.startsWith(REST_SERVER_URL + "core/subscriptions")))
|
||||||
|
.andExpect(jsonPath("$._embedded.subscriptions[0]._links.ePerson.href", Matchers.endsWith("ePerson")))
|
||||||
|
.andExpect(jsonPath("$._embedded.subscriptions[0].subscriptionParameterList[0].name", is("Frequency")))
|
||||||
|
.andExpect(jsonPath("$._embedded.subscriptions[0].subscriptionParameterList[0].value", is("Daily")))
|
||||||
|
.andExpect(jsonPath("$._links.self.href", Matchers.is(REST_SERVER_URL + "core/subscriptions?resourceType=Item")));
|
||||||
|
// search for subscriptions related with collections
|
||||||
|
getClient(token).perform(get("/api/core/subscriptions?resourceType=Collection"))
|
||||||
|
//The status has to be 200 OK
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
//We expect the content type to be "application/hal+json;charset=UTF-8"
|
||||||
|
.andExpect(content().contentType(contentType))
|
||||||
|
//By default we expect at least 1 submission forms so this to be reflected in the page object
|
||||||
|
.andExpect(jsonPath("$.page.size", is(20)))
|
||||||
|
.andExpect(jsonPath("$.page.totalElements", greaterThanOrEqualTo(0)))
|
||||||
|
.andExpect(jsonPath("$.page.totalPages", greaterThanOrEqualTo(0)))
|
||||||
|
.andExpect(jsonPath("$.page.number", is(0)))
|
||||||
|
.andExpect(jsonPath("$._links.self.href", Matchers.is(REST_SERVER_URL + "core/subscriptions?resourceType=Collection")));
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIND BY ID
|
||||||
|
@Test
|
||||||
|
public void findByIdAsAdministrator() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
|
||||||
|
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
|
||||||
subscriptionParameter.setName("Parameter");
|
subscriptionParameter.setName("Parameter");
|
||||||
subscriptionParameter.setValue("ValueParameter");
|
subscriptionParameter.setValue("ValueParameter");
|
||||||
subscriptionParameterList.add(subscriptionParameter);
|
subscriptionParameterList.add(subscriptionParameter);
|
||||||
@@ -167,6 +229,24 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
|
|||||||
.andExpect(status().isUnauthorized());
|
.andExpect(status().isUnauthorized());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findByIdNotAsSubscriberNotAsAdmin() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
String token = getAuthToken(eperson.getEmail(), password);
|
||||||
|
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
|
||||||
|
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
|
||||||
|
subscriptionParameter.setName("Parameter");
|
||||||
|
subscriptionParameter.setValue("ValueParameter");
|
||||||
|
subscriptionParameterList.add(subscriptionParameter);
|
||||||
|
Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "TestType", publicItem, admin, subscriptionParameterList).build();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
//When we call the root endpoint
|
||||||
|
getClient(token).perform(get("/api/core/subscriptions/" + subscription.getID()))
|
||||||
|
//The status has to be 500
|
||||||
|
.andExpect(status().isInternalServerError());
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIND ALL BY EPERSON/DSO
|
||||||
@Test
|
@Test
|
||||||
public void findAllSubscriptionsByEPerson() throws Exception {
|
public void findAllSubscriptionsByEPerson() throws Exception {
|
||||||
//When we call the root endpoint as anonymous user
|
//When we call the root endpoint as anonymous user
|
||||||
@@ -228,6 +308,7 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
|
|||||||
.andExpect(status().isUnauthorized());
|
.andExpect(status().isUnauthorized());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ADD
|
||||||
@Test
|
@Test
|
||||||
public void addSubscriptionNotLoggedIn() throws Exception {
|
public void addSubscriptionNotLoggedIn() throws Exception {
|
||||||
SubscriptionParameterRest subscriptionParameterRest = new SubscriptionParameterRest();
|
SubscriptionParameterRest subscriptionParameterRest = new SubscriptionParameterRest();
|
||||||
@@ -287,6 +368,7 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
|
|||||||
.andExpect(jsonPath("$._links.ePerson.href", Matchers.endsWith("ePerson")));
|
.andExpect(jsonPath("$._links.ePerson.href", Matchers.endsWith("ePerson")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PUT
|
||||||
@Test
|
@Test
|
||||||
public void editSubscriptionAnonymous() throws Exception {
|
public void editSubscriptionAnonymous() throws Exception {
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
@@ -330,12 +412,22 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
|
|||||||
subscriptionParameterList.add(subscriptionParameter);
|
subscriptionParameterList.add(subscriptionParameter);
|
||||||
Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "TestType", publicItem, eperson, subscriptionParameterList).build();
|
Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "TestType", publicItem, eperson, subscriptionParameterList).build();
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
String token = getAuthToken(epersonIT.getEmail(), password);
|
||||||
|
Map<String, Object> newSubscription = new HashMap<>();
|
||||||
|
newSubscription.put("type", "test");
|
||||||
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
|
Map<String, Object> sub_list = new HashMap<>();
|
||||||
|
sub_list.put("name", "frequency");
|
||||||
|
sub_list.put("value", "daily");
|
||||||
|
list.add(sub_list);
|
||||||
|
newSubscription.put("subscriptionParameterList", list);
|
||||||
//When we call the root endpoint as anonymous user
|
//When we call the root endpoint as anonymous user
|
||||||
getClient().perform(put("/api/core/subscriptions/" + subscription.getID() + "?dspace_object_id=" + publicItem.getID() + "&eperson_id=" + admin.getID())
|
getClient(token).perform(put("/api/core/subscriptions/" + subscription.getID() + "?dspace_object_id=" + publicItem.getID() + "&eperson_id=" + admin.getID())
|
||||||
.content(objectMapper.writeValueAsString(newSubscription))
|
.content(objectMapper.writeValueAsString(newSubscription))
|
||||||
.contentType(MediaType.APPLICATION_JSON_VALUE))
|
.contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||||
//The status has to be 403 Not Authorized
|
//The status has to be 500 Error
|
||||||
.andExpect(status().isUnauthorized());
|
.andExpect(status().isInternalServerError());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -378,6 +470,7 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
|
|||||||
.andExpect(jsonPath("$._links.ePerson.href", Matchers.endsWith("/ePerson")));
|
.andExpect(jsonPath("$._links.ePerson.href", Matchers.endsWith("/ePerson")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DELETE
|
||||||
@Test
|
@Test
|
||||||
public void deleteSubscriptionNotAsSubscriberNotAsAdmin() throws Exception {
|
public void deleteSubscriptionNotAsSubscriberNotAsAdmin() throws Exception {
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
@@ -416,6 +509,7 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
|
|||||||
.andExpect(status().isOk());
|
.andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PATCH
|
||||||
@Test
|
@Test
|
||||||
public void patchReplaceSubscriptionParameterAsAdmin() throws Exception {
|
public void patchReplaceSubscriptionParameterAsAdmin() throws Exception {
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
|
Reference in New Issue
Block a user