[CST-7756] refactoring

This commit is contained in:
Mykhaylo
2022-12-07 14:25:35 +01:00
parent 2c11f7c757
commit fd7016f14e
22 changed files with 788 additions and 858 deletions

View File

@@ -119,7 +119,6 @@ public abstract class ContentServiceFactory {
public <T extends DSpaceObject> DSpaceObjectService<T> getDSpaceObjectService(T dso) { public <T extends DSpaceObject> DSpaceObjectService<T> getDSpaceObjectService(T dso) {
// No need to worry when supressing, as long as our "getDSpaceObjectManager" method is properly implemented // No need to worry when supressing, as long as our "getDSpaceObjectManager" method is properly implemented
// no casting issues should occur // no casting issues should occur
@SuppressWarnings("unchecked")
DSpaceObjectService<T> manager = getDSpaceObjectService(dso.getType()); DSpaceObjectService<T> manager = getDSpaceObjectService(dso.getType());
return manager; return manager;
} }

View File

@@ -9,8 +9,8 @@ package org.dspace.eperson;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.eperson.dao.SubscriptionParameterDAO; import org.dspace.eperson.dao.SubscriptionParameterDAO;
import org.dspace.eperson.service.SubscriptionParameterService; import org.dspace.eperson.service.SubscriptionParameterService;
@@ -34,8 +34,8 @@ public class SubscribeParameterServiceImpl implements SubscriptionParameterServi
} }
@Override @Override
public SubscriptionParameter add(Context context, String name, String value, public SubscriptionParameter add(Context context, String name, String value, Subscription subscription)
Subscription subscription) throws SQLException, AuthorizeException { throws SQLException {
SubscriptionParameter subscriptionParameter = SubscriptionParameter subscriptionParameter =
subscriptionParameterDAO.create(context, new SubscriptionParameter()); subscriptionParameterDAO.create(context, new SubscriptionParameter());
subscriptionParameter.setName(name); subscriptionParameter.setName(name);
@@ -43,12 +43,12 @@ public class SubscribeParameterServiceImpl implements SubscriptionParameterServi
subscriptionParameter.setValue(value); subscriptionParameter.setValue(value);
return subscriptionParameter; return subscriptionParameter;
} }
@Override @Override
public SubscriptionParameter edit(Context context,Integer id,String value, public SubscriptionParameter edit(Context context, Integer id, String value, String name, Subscription subscription)
String name, Subscription subscription) throws SQLException, AuthorizeException { throws SQLException {
SubscriptionParameter subscriptionParameter = SubscriptionParameter subscriptionParameter =
subscriptionParameterDAO.findByID(context, SubscriptionParameter.class, id); subscriptionParameterDAO.findByID(context, SubscriptionParameter.class, id);
subscriptionParameter.setId(id);
subscriptionParameter.setName(name); subscriptionParameter.setName(name);
subscriptionParameter.setSubscription(subscription); subscriptionParameter.setSubscription(subscription);
subscriptionParameter.setValue(value); subscriptionParameter.setValue(value);
@@ -62,16 +62,15 @@ public class SubscribeParameterServiceImpl implements SubscriptionParameterServi
} }
@Override @Override
public void deleteSubscriptionParameter(Context context, Integer id) throws SQLException, AuthorizeException { public void delete(Context context, Integer id) throws SQLException {
SubscriptionParameter subscriptionParameter = SubscriptionParameter subscriptionParameter =
subscriptionParameterDAO.findByID(context, SubscriptionParameter.class, id); subscriptionParameterDAO.findByID(context, SubscriptionParameter.class, id);
if (subscriptionParameter != null) { if (Objects.nonNull(subscriptionParameter)) {
subscriptionParameter.setSubscription(null); subscriptionParameter.setSubscription(null);
subscriptionParameterDAO.delete(context, subscriptionParameter); subscriptionParameterDAO.delete(context, subscriptionParameter);
} else { } else {
throw new SQLException("Subscription parameter with id" + id + "do not exists"); throw new SQLException("Subscription parameter with id" + id + "do not exists");
} }
} }
} }

View File

@@ -11,6 +11,7 @@ import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
@@ -43,9 +44,9 @@ public class SubscribeServiceImpl implements SubscribeService {
private CollectionService collectionService; private CollectionService collectionService;
@Override @Override
public List<Subscription> findAll(Context context, String resourceType, public List<Subscription> findAll(Context context, String resourceType, Integer limit, Integer offset)
Integer limit, Integer offset) throws Exception { throws Exception {
if (resourceType == null) { if (StringUtils.isBlank(resourceType)) {
return subscriptionDAO.findAllOrderedByDSO(context, limit, offset); return subscriptionDAO.findAllOrderedByDSO(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")) {
@@ -101,24 +102,25 @@ public class SubscribeServiceImpl implements SubscribeService {
} }
@Override @Override
public List<Subscription> getSubscriptionsByEPerson(Context context, EPerson eperson, Integer limit, Integer offset) public List<Subscription> findSubscriptionsByEPerson(Context context, EPerson eperson, Integer limit,Integer offset)
throws SQLException { throws SQLException {
return subscriptionDAO.findByEPerson(context, eperson, limit, offset); return subscriptionDAO.findByEPerson(context, eperson, limit, offset);
} }
@Override @Override
public List<Subscription> getSubscriptionsByEPersonAndDso(Context context,EPerson eperson,DSpaceObject dSpaceObject, public List<Subscription> findSubscriptionsByEPersonAndDso(Context context, EPerson eperson,
Integer limit, Integer offset) throws SQLException { DSpaceObject dSpaceObject,
Integer limit, Integer offset) throws SQLException {
return subscriptionDAO.findByEPersonAndDso(context, eperson, dSpaceObject, limit, offset); return subscriptionDAO.findByEPersonAndDso(context, eperson, dSpaceObject, limit, offset);
} }
@Override @Override
public List<Collection> getAvailableSubscriptions(Context context) throws SQLException { public List<Collection> findAvailableSubscriptions(Context context) throws SQLException {
return getAvailableSubscriptions(context, null); return findAvailableSubscriptions(context, null);
} }
@Override @Override
public List<Collection> getAvailableSubscriptions(Context context, EPerson eperson) throws SQLException { public List<Collection> findAvailableSubscriptions(Context context, EPerson eperson) throws SQLException {
if (Objects.nonNull(eperson)) { if (Objects.nonNull(eperson)) {
context.setCurrentUser(eperson); context.setCurrentUser(eperson);
} }
@@ -141,91 +143,50 @@ public class SubscribeServiceImpl implements SubscribeService {
} }
@Override @Override
public Subscription findById(Context context, int id) throws SQLException, AuthorizeException { public Subscription findById(Context context, int id) throws SQLException {
Subscription subscription = subscriptionDAO.findByID(context, Subscription.class, id); return 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
public Subscription updateSubscription(Context context, Integer id, public Subscription updateSubscription(Context context, Integer id, EPerson eperson, DSpaceObject dSpaceObject,
EPerson eperson, List<SubscriptionParameter> subscriptionParameterList, String type)
DSpaceObject dSpaceObject, throws SQLException {
List<SubscriptionParameter> subscriptionParameterList,
String type) throws SQLException, AuthorizeException {
// must be admin or the subscriber of the subscription
if (authorizeService.isAdmin(context, context.getCurrentUser()) || eperson.equals(context.getCurrentUser())) {
Subscription subscriptionDB = subscriptionDAO.findByID(context, Subscription.class, id);
subscriptionDB.removeParameterList();
subscriptionDB.setType(type);
subscriptionDB.setdSpaceObject(dSpaceObject);
subscriptionParameterList.forEach(subscriptionParameter ->
subscriptionDB.addParameter(subscriptionParameter));
subscriptionDB.setePerson(eperson);
subscriptionDAO.save(context, subscriptionDB);
return subscriptionDB;
} else {
throw new AuthorizeException("Only admin or e-person themselves can edit the subscription");
}
}
@Override
public Subscription addSubscriptionParameter(Context context, Integer id,
SubscriptionParameter subscriptionParameter) throws SQLException, AuthorizeException {
// must be admin or the subscriber of the subscription
Subscription subscriptionDB = subscriptionDAO.findByID(context, Subscription.class, id); Subscription subscriptionDB = subscriptionDAO.findByID(context, Subscription.class, id);
if (authorizeService.isAdmin(context, context.getCurrentUser()) subscriptionDB.removeParameterList();
|| subscriptionDB.getePerson().equals(context.getCurrentUser())) { subscriptionDB.setType(type);
subscriptionDB.addParameter(subscriptionParameter); subscriptionDB.setdSpaceObject(dSpaceObject);
subscriptionDAO.save(context, subscriptionDB); subscriptionParameterList.forEach(x -> subscriptionDB.addParameter(x));
return subscriptionDB; subscriptionDB.setePerson(eperson);
} else { subscriptionDAO.save(context, subscriptionDB);
throw new AuthorizeException("Only admin or e-person themselves can edit the subscription"); return subscriptionDB;
}
} }
@Override @Override
public Subscription removeSubscriptionParameter(Context context, Integer id, public Subscription addSubscriptionParameter(Context context, Integer id, SubscriptionParameter subscriptionParam)
SubscriptionParameter subscriptionParameter) throws SQLException, AuthorizeException { throws SQLException {
// must be admin or the subscriber of the subscription
Subscription subscriptionDB = subscriptionDAO.findByID(context, Subscription.class, id); Subscription subscriptionDB = subscriptionDAO.findByID(context, Subscription.class, id);
if (authorizeService.isAdmin(context, context.getCurrentUser()) subscriptionDB.addParameter(subscriptionParam);
|| subscriptionDB.getePerson().equals(context.getCurrentUser())) { subscriptionDAO.save(context, subscriptionDB);
subscriptionDB.removeParameter(subscriptionParameter); return subscriptionDB;
subscriptionDAO.save(context, subscriptionDB);
return subscriptionDB;
} else {
throw new AuthorizeException("Only admin or e-person themselves can edit the subscription");
}
} }
@Override @Override
public void deleteSubscription(Context context, Integer id) throws SQLException, AuthorizeException { public Subscription removeSubscriptionParameter(Context context,Integer id, SubscriptionParameter subscriptionParam)
// initially find the eperson associated with the subscription throws SQLException {
Subscription subscription = subscriptionDAO.findByID(context, Subscription.class, id); Subscription subscriptionDB = subscriptionDAO.findByID(context, Subscription.class, id);
if (subscription != null) { subscriptionDB.removeParameter(subscriptionParam);
// must be admin or the subscriber of the subscription subscriptionDAO.save(context, subscriptionDB);
if (authorizeService.isAdmin(context, context.getCurrentUser()) return subscriptionDB;
|| subscription.getePerson().equals(context.getCurrentUser())) {
try {
subscriptionDAO.delete(context, subscription);
} catch (SQLException sqlException) {
throw new SQLException(sqlException);
}
} else {
throw new AuthorizeException("Only admin or e-person themselves can delete the subscription");
}
} else {
throw new IllegalArgumentException("Subscription with id " + id + " is not found");
}
} }
@Override @Override
public List<Subscription> findAllSubscriptionsByTypeAndFrequency(Context context, public void deleteSubscription(Context context, Subscription subscription) throws SQLException {
String type, String frequencyValue) throws SQLException { subscriptionDAO.delete(context, subscription);
}
@Override
public List<Subscription> findAllSubscriptionsByTypeAndFrequency(Context context,String type, String frequencyValue)
throws SQLException {
return subscriptionDAO.findAllSubscriptionsByTypeAndFrequency(context, type, frequencyValue); return subscriptionDAO.findAllSubscriptionsByTypeAndFrequency(context, type, frequencyValue);
} }
@@ -235,12 +196,12 @@ public class SubscribeServiceImpl implements SubscribeService {
} }
@Override @Override
public Long countAllByEPerson(Context context, EPerson ePerson) throws SQLException { public Long countSubscriptionsByEPerson(Context context, EPerson ePerson) throws SQLException {
return subscriptionDAO.countAllByEPerson(context, ePerson); return subscriptionDAO.countAllByEPerson(context, ePerson);
} }
@Override @Override
public Long countAllByEPersonAndDSO(Context context, EPerson ePerson, DSpaceObject dSpaceObject) public Long countByEPersonAndDSO(Context context, EPerson ePerson, DSpaceObject dSpaceObject)
throws SQLException { throws SQLException {
return subscriptionDAO.countAllByEPersonAndDso(context, ePerson, dSpaceObject); return subscriptionDAO.countAllByEPersonAndDso(context, ePerson, dSpaceObject);
} }

View File

@@ -17,6 +17,8 @@ import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator; import javax.persistence.SequenceGenerator;
import javax.persistence.Table; import javax.persistence.Table;
import org.dspace.core.ReloadableEntity;
/** /**
* Database entity representation of the subscription_parameter table * Database entity representation of the subscription_parameter table
* *
@@ -24,7 +26,7 @@ import javax.persistence.Table;
*/ */
@Entity @Entity
@Table(name = "subscription_parameter") @Table(name = "subscription_parameter")
public class SubscriptionParameter { public class SubscriptionParameter implements ReloadableEntity<Integer> {
@Id @Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "subscription_parameter_seq") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "subscription_parameter_seq")
@@ -76,7 +78,8 @@ public class SubscriptionParameter {
this.value = value; this.value = value;
} }
public Integer getId() { @Override
public Integer getID() {
return id; return id;
} }

View File

@@ -41,8 +41,8 @@ public class SubscriptionDAOImpl extends AbstractHibernateDAO<Subscription> impl
} }
@Override @Override
public List<Subscription> findByEPerson(Context context, EPerson eperson, public List<Subscription> findByEPerson(Context context, EPerson eperson, Integer limit, Integer offset)
Integer limit, Integer offset) throws SQLException { 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);

View File

@@ -50,8 +50,7 @@ public interface SubscribeService {
* @throws AuthorizeException Exception indicating the current user of the context does not have permission * @throws AuthorizeException Exception indicating the current user of the context does not have permission
* to perform a particular action. * to perform a particular action.
*/ */
public Subscription subscribe(Context context, EPerson eperson, public Subscription subscribe(Context context, EPerson eperson, DSpaceObject dSpaceObject,
DSpaceObject dSpaceObject,
List<SubscriptionParameter> subscriptionParameterList, List<SubscriptionParameter> subscriptionParameterList,
String type) throws SQLException, AuthorizeException; String type) throws SQLException, AuthorizeException;
@@ -80,7 +79,7 @@ public interface SubscribeService {
* @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, Integer limit, Integer offset) public List<Subscription> findSubscriptionsByEPerson(Context context, EPerson eperson, Integer limit,Integer offset)
throws SQLException; throws SQLException;
/** /**
@@ -94,11 +93,9 @@ public interface SubscribeService {
* @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> findSubscriptionsByEPersonAndDso(Context context, EPerson eperson,
EPerson eperson,
DSpaceObject dSpaceObject, DSpaceObject dSpaceObject,
Integer limit, Integer limit, Integer offset) throws SQLException;
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
@@ -107,7 +104,7 @@ public interface SubscribeService {
* @return array of collections the currently logged in e-person can subscribe to * @return array of collections the currently logged in e-person can subscribe 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<Collection> getAvailableSubscriptions(Context context) throws SQLException; public List<Collection> findAvailableSubscriptions(Context context) throws SQLException;
/** /**
* Find out which collections an e-person can subscribe to * Find out which collections an e-person can subscribe to
@@ -117,7 +114,7 @@ public interface SubscribeService {
* @return array of collections e-person can subscribe to * @return array of collections e-person can subscribe 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<Collection> getAvailableSubscriptions(Context context, EPerson eperson) throws SQLException; public List<Collection> findAvailableSubscriptions(Context context, EPerson eperson) throws SQLException;
/** /**
* Is that e-person subscribed to that collection? * Is that e-person subscribed to that collection?
@@ -155,7 +152,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, AuthorizeException; public Subscription findById(Context context, int id) throws SQLException;
/** /**
* Updates a subscription by id * Updates a subscription by id
@@ -168,10 +165,8 @@ public interface SubscribeService {
* @param type String type * @param type String type
* @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 updateSubscription(Context context, Integer id, EPerson eperson, public Subscription updateSubscription(Context context, Integer id, EPerson eperson, DSpaceObject dSpaceObject,
DSpaceObject dSpaceObject, List<SubscriptionParameter> subscriptionParameterList, String type) throws SQLException;
List<SubscriptionParameter> subscriptionParameterList,
String type) throws SQLException, AuthorizeException;
/** /**
* Adds a parameter to a subscription * Adds a parameter to a subscription
@@ -182,18 +177,18 @@ 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 addSubscriptionParameter(Context context,Integer id,SubscriptionParameter subscriptionParameter) public Subscription addSubscriptionParameter(Context context,Integer id,SubscriptionParameter subscriptionParameter)
throws SQLException, AuthorizeException; throws SQLException;
/** /**
* Deletes a parameter from subscription * Deletes a parameter from subscription
* *
* @param context DSpace context * @param context DSpace context
* @param id Integer id * @param id Integer id
* @param subscriptionParameter SubscriptionParameter subscriptionParameter * @param subscriptionParam SubscriptionParameter subscriptionParameter
* @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 subscriptionParam)
SubscriptionParameter subscriptionParameter) throws SQLException, AuthorizeException; throws SQLException;
/** /**
* Deletes a subscription * Deletes a subscription
@@ -202,7 +197,7 @@ public interface SubscribeService {
* @param id Integer id of subscription * @param id Integer id of subscription
* @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 void deleteSubscription(Context context, Integer id) throws SQLException, AuthorizeException; public void deleteSubscription(Context context, Subscription subscription) throws SQLException;
/** /**
* Finds all subscriptions having given type and frequency * Finds all subscriptions having given type and frequency
@@ -220,7 +215,7 @@ public interface SubscribeService {
* *
* @param context DSpace context * @param context DSpace context
*/ */
public Long countAll(Context context) throws SQLException, AuthorizeException; public Long countAll(Context context) throws SQLException;
/** /**
* Counts all subscriptions by ePerson * Counts all subscriptions by ePerson
@@ -228,7 +223,7 @@ public interface SubscribeService {
* @param context DSpace context * @param context DSpace context
* @param ePerson EPerson ePerson * @param ePerson EPerson ePerson
*/ */
public Long countAllByEPerson(Context context, EPerson ePerson) throws SQLException, AuthorizeException; public Long countSubscriptionsByEPerson(Context context, EPerson ePerson) throws SQLException;
/** /**
* Counts all subscriptions by ePerson and DSO * Counts all subscriptions by ePerson and DSO
@@ -237,7 +232,6 @@ public interface SubscribeService {
* @param ePerson EPerson ePerson * @param ePerson EPerson ePerson
* @param dSpaceObject DSpaceObject dSpaceObject * @param dSpaceObject DSpaceObject dSpaceObject
*/ */
public Long countAllByEPersonAndDSO(Context context, EPerson ePerson, DSpaceObject dSpaceObject) public Long countByEPersonAndDSO(Context context, EPerson ePerson, DSpaceObject dSpaceObject) throws SQLException;
throws SQLException, AuthorizeException;
} }

View File

@@ -44,9 +44,8 @@ public interface SubscriptionParameterService {
* @throws AuthorizeException Exception indicating the current user of the context does not have permission * @throws AuthorizeException Exception indicating the current user of the context does not have permission
* to perform a particular action. * to perform a particular action.
*/ */
public SubscriptionParameter add(Context context, String value, public SubscriptionParameter add(Context context, String value, String name, Subscription subscription)
String name, throws SQLException;
Subscription subscription) throws SQLException, AuthorizeException;
/** /**
* Updates a subscription parameter with id * Updates a subscription parameter with id
@@ -60,9 +59,8 @@ public interface SubscriptionParameterService {
* @throws AuthorizeException Exception indicating the current user of the context does not have permission * @throws AuthorizeException Exception indicating the current user of the context does not have permission
* to perform a particular action. * to perform a particular action.
*/ */
public SubscriptionParameter edit(Context context, Integer id, String value, public SubscriptionParameter edit(Context context, Integer id, String value, String name, Subscription subscription)
String name, throws SQLException;
Subscription subscription) throws SQLException, AuthorizeException;
/** /**
* Finds a subscriptionParameter by id * Finds a subscriptionParameter by id
@@ -73,14 +71,12 @@ public interface SubscriptionParameterService {
*/ */
public SubscriptionParameter findById(Context context, int id) throws SQLException; public SubscriptionParameter findById(Context context, int id) throws SQLException;
/** /**
* Deletes a subscriptionParameter with id * Deletes a subscriptionParameter with id
* *
* @param context DSpace context * @param context DSpace context
* @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 void deleteSubscriptionParameter(Context context, Integer id) throws SQLException, AuthorizeException; public void delete(Context context, Integer id) throws SQLException;
} }

View File

@@ -20,7 +20,7 @@ CREATE TABLE subscription_parameter
( (
subscription_parameter_id INTEGER NOT NULL, subscription_parameter_id INTEGER NOT NULL,
name CHARACTER VARYING(255), name CHARACTER VARYING(255),
`value` CHARACTER VARYING(255), value CHARACTER VARYING(255),
subscription_id INTEGER NOT NULL, subscription_id INTEGER NOT NULL,
CONSTRAINT subscription_parameter_pkey PRIMARY KEY (subscription_parameter_id), CONSTRAINT subscription_parameter_pkey PRIMARY KEY (subscription_parameter_id),
CONSTRAINT subscription_parameter_subscription_fkey FOREIGN KEY (subscription_id) REFERENCES subscription (subscription_id) ON DELETE CASCADE CONSTRAINT subscription_parameter_subscription_fkey FOREIGN KEY (subscription_id) REFERENCES subscription (subscription_id) ON DELETE CASCADE

View File

@@ -43,7 +43,7 @@ dspace.server.url = http://localhost
db.driver = org.h2.Driver db.driver = org.h2.Driver
db.dialect=org.hibernate.dialect.H2Dialect db.dialect=org.hibernate.dialect.H2Dialect
# Use a 10 second database lock timeout to avoid occasional JDBC lock timeout errors # Use a 10 second database lock timeout to avoid occasional JDBC lock timeout errors
db.url = jdbc:h2:mem:test;LOCK_TIMEOUT=10000; db.url = jdbc:h2:mem:test;LOCK_TIMEOUT=10000;NON_KEYWORDS=VALUE
db.username = sa db.username = sa
db.password = db.password =
# H2's default schema is PUBLIC # H2's default schema is PUBLIC

View File

@@ -9,6 +9,7 @@ package org.dspace.builder;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@@ -44,18 +45,27 @@ public class SubscribeBuilder extends AbstractBuilder<Subscription, SubscribeSer
// Ensure object and any related objects are reloaded before checking to see what needs cleanup // Ensure object and any related objects are reloaded before checking to see what needs cleanup
subscription = c.reloadEntity(subscription); subscription = c.reloadEntity(subscription);
if (subscription != null) { if (subscription != null) {
delete(subscription); delete(c, subscription);
} }
c.complete(); c.complete();
indexingService.commit(); indexingService.commit();
} }
} }
@Override public static void deleteSubscription(int id) throws Exception {
public void delete(Context c, Subscription subscription) throws Exception { try (Context c = new Context()) {
if (subscription != null) { c.turnOffAuthorisationSystem();
getService().deleteSubscription(c, subscription.getID()); Subscription subscription = subscribeService.findById(c, id);
if (Objects.nonNull(subscription)) {
try {
subscribeService.deleteSubscription(c, subscription);
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
c.complete();
} }
indexingService.commit();
} }
@Override @Override
@@ -71,18 +81,6 @@ public class SubscribeBuilder extends AbstractBuilder<Subscription, SubscribeSer
return subscription; return subscription;
} }
public void delete(Subscription subscription) throws Exception {
try (Context c = new Context()) {
c.turnOffAuthorisationSystem();
Subscription subscription1 = c.reloadEntity(subscription);
if (subscription1 != null) {
getService().deleteSubscription(c, subscription1.getID());
}
c.complete();
}
indexingService.commit();
}
public static SubscribeBuilder subscribeBuilder(final Context context, String type, DSpaceObject dSpaceObject, public static SubscribeBuilder subscribeBuilder(final Context context, String type, DSpaceObject dSpaceObject,
EPerson ePerson, List<SubscriptionParameter> subscriptionParameterList) { EPerson ePerson, List<SubscriptionParameter> subscriptionParameterList) {
SubscribeBuilder builder = new SubscribeBuilder(context); SubscribeBuilder builder = new SubscribeBuilder(context);
@@ -103,4 +101,11 @@ public class SubscribeBuilder extends AbstractBuilder<Subscription, SubscribeSer
return this; return this;
} }
@Override
public void delete(Context c, Subscription dso) throws Exception {
if (Objects.nonNull(dso)) {
getService().deleteSubscription(c, dso);
}
}
} }

View File

@@ -41,7 +41,7 @@ public class SubscriptionConverter implements DSpaceConverter<Subscription, Subs
SubscriptionParameterRest subscriptionParameterRest = new SubscriptionParameterRest(); SubscriptionParameterRest subscriptionParameterRest = new SubscriptionParameterRest();
subscriptionParameterRest.setName(subscriptionParameter.getName()); subscriptionParameterRest.setName(subscriptionParameter.getName());
subscriptionParameterRest.setValue(subscriptionParameter.getValue()); subscriptionParameterRest.setValue(subscriptionParameter.getValue());
subscriptionParameterRest.setId(subscriptionParameter.getId()); subscriptionParameterRest.setId(subscriptionParameter.getID());
subscriptionParameterRestList.add(subscriptionParameterRest); subscriptionParameterRestList.add(subscriptionParameterRest);
} }
rest.setSubscriptionParameterList(subscriptionParameterRestList); rest.setSubscriptionParameterList(subscriptionParameterRestList);

View File

@@ -5,19 +5,20 @@
* *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
package org.dspace.app.rest.model; package org.dspace.app.rest.model;
import org.dspace.eperson.Subscription; import org.dspace.eperson.Subscription;
/**
* @author Mykhaylo Boychuk (mykhaylo.boychuk@4science.com)
*/
public class SubscriptionParameterRest { public class SubscriptionParameterRest {
private Integer id; private Integer id;
private String name; private String name;
private String value; private String value;
public SubscriptionParameterRest() { public SubscriptionParameterRest() {}
}
public SubscriptionParameterRest(Integer id, String name, String value, Subscription subscription) { public SubscriptionParameterRest(Integer id, String name, String value, Subscription subscription) {
this.id = id; this.id = id;

View File

@@ -56,8 +56,6 @@ public class SubscriptionDSpaceObjectLinkRepository extends AbstractDSpaceRestRe
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (AuthorizeException e) {
throw new AuthorizeException(e.getMessage());
} }
} }

View File

@@ -43,8 +43,6 @@ public class SubscriptionEPersonLinkRepository extends AbstractDSpaceRestReposit
return converter.toRest(subscription.getePerson(), projection); return converter.toRest(subscription.getePerson(), projection);
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (AuthorizeException e) {
throw new AuthorizeException(e.getMessage());
} }
} }

View File

@@ -7,6 +7,9 @@
*/ */
package org.dspace.app.rest.repository; package org.dspace.app.rest.repository;
import static org.dspace.app.rest.model.SubscriptionRest.CATEGORY;
import static org.dspace.app.rest.model.SubscriptionRest.NAME;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
@@ -19,14 +22,14 @@ import javax.ws.rs.BadRequestException;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.dspace.app.rest.Parameter;
import org.dspace.app.rest.SearchRestMethod; import org.dspace.app.rest.SearchRestMethod;
import org.dspace.app.rest.converter.ConverterService; import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.exception.DSpaceBadRequestException; import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
import org.dspace.app.rest.exception.UnprocessableEntityException; import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.SubscriptionParameterRest; import org.dspace.app.rest.model.SubscriptionParameterRest;
import org.dspace.app.rest.model.SubscriptionRest; import org.dspace.app.rest.model.SubscriptionRest;
import org.dspace.app.rest.model.patch.Patch; import org.dspace.app.rest.model.patch.Patch;
import org.dspace.app.rest.repository.patch.ResourcePatch;
import org.dspace.app.rest.utils.DSpaceObjectUtils; import org.dspace.app.rest.utils.DSpaceObjectUtils;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService; import org.dspace.authorize.service.AuthorizeService;
@@ -48,39 +51,32 @@ import org.springframework.stereotype.Component;
/** /**
* This is the repository responsible to manage SubscriptionRest object * This is the repository responsible to manage SubscriptionRest object
* *
* @author Alba Aliu at atis.al * @author Mykhaylo Boychuk (mykhaylo.boychuk at 4science.com)
*/ */
@Component(SubscriptionRest.CATEGORY + "." + SubscriptionRest.NAME) @Component(SubscriptionRest.CATEGORY + "." + SubscriptionRest.NAME)
public class SubscriptionRestRepository extends DSpaceRestRepository<SubscriptionRest, Integer> public class SubscriptionRestRepository extends DSpaceRestRepository<SubscriptionRest, Integer> {
implements LinkRestRepository {
@Autowired @Autowired
private ConverterService converter; private ConverterService converter;
@Autowired @Autowired
private EPersonService personService; private EPersonService ePersonService;
@Autowired @Autowired
private AuthorizeService authorizeService; private AuthorizeService authorizeService;
@Autowired @Autowired
private SubscribeService subscribeService; private SubscribeService subscribeService;
@Autowired @Autowired
private DSpaceObjectUtils dspaceObjectUtil; private DSpaceObjectUtils dspaceObjectUtil;
@Autowired
private ResourcePatch<Subscription> resourcePatch;
@Override @Override
@PreAuthorize("isAuthenticated()") @PreAuthorize("hasPermission(#id, 'subscription', 'READ')")
public SubscriptionRest findOne(Context context, Integer id) { public SubscriptionRest findOne(Context context, Integer id) {
Subscription subscription = null;
try { try {
Subscription subscription = subscribeService.findById(context, id); subscription = subscribeService.findById(context, id);
if (Objects.isNull(subscription)) { } catch (SQLException e) {
throw new ResourceNotFoundException("The subscription for ID: " + id + " could not be found"); throw new RuntimeException(e.getMessage(), e);
}
return converter.toRest(subscription, utils.obtainProjection());
} catch (SQLException sqlException) {
throw new RuntimeException(sqlException.getMessage(), sqlException);
} catch (AuthorizeException authorizeException) {
throw new RuntimeException(authorizeException.getMessage());
} }
return Objects.isNull(subscription) ? null : converter.toRest(subscription, utils.obtainProjection());
} }
@Override @Override
@@ -90,91 +86,77 @@ public class SubscriptionRestRepository extends DSpaceRestRepository<Subscriptio
HttpServletRequest req = getRequestService().getCurrentRequest().getHttpServletRequest(); HttpServletRequest req = getRequestService().getCurrentRequest().getHttpServletRequest();
String resourceType = req.getParameter("resourceType"); String resourceType = req.getParameter("resourceType");
List<Subscription> subscriptionList = subscribeService.findAll(context, resourceType, List<Subscription> subscriptionList = subscribeService.findAll(context, resourceType,
pageable.getPageSize(), Math.toIntExact(pageable.getOffset())); Math.toIntExact(pageable.getPageSize()),
Math.toIntExact(pageable.getOffset()));
Long total = subscribeService.countAll(context); Long total = subscribeService.countAll(context);
return converter.toRestPage(subscriptionList, pageable, total, utils.obtainProjection()); return converter.toRestPage(subscriptionList, pageable, total, utils.obtainProjection());
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(e.getMessage(), e);
} }
} }
@PreAuthorize("isAuthenticated()")
@SearchRestMethod(name = "findByEPerson") @SearchRestMethod(name = "findByEPerson")
public Page<SubscriptionRest> findAllSubscriptionsByEPerson(String id, Pageable pageable) throws Exception { @PreAuthorize("hasPermission(#epersonId, 'AdminOrOwner', 'READ')")
public Page<SubscriptionRest> findSubscriptionsByEPerson(@Parameter(value = "uuid", required = true) UUID epersonId,
Pageable pageable)throws Exception {
Long total = null;
List<Subscription> subscriptions = null;
try { try {
Context context = obtainContext(); Context context = obtainContext();
EPerson ePerson = personService.findByIdOrLegacyId(context, id); EPerson ePerson = ePersonService.find(context, epersonId);
if (context.getCurrentUser().equals(ePerson) subscriptions = subscribeService.findSubscriptionsByEPerson(context, ePerson,
|| authorizeService.isAdmin(context, context.getCurrentUser())) { Math.toIntExact(pageable.getPageSize()),
List<Subscription> subscriptionList = subscribeService.getSubscriptionsByEPerson(context, Math.toIntExact(pageable.getOffset()));
ePerson, pageable.getPageSize(), Math.toIntExact(pageable.getOffset())); total = subscribeService.countSubscriptionsByEPerson(context, ePerson);
Long total = subscribeService.countAllByEPerson(context, ePerson); } catch (SQLException e) {
return converter.toRestPage(subscriptionList, pageable, total, utils.obtainProjection()); throw new SQLException(e.getMessage(), e);
} else {
throw new AuthorizeException("Only admin or e-person themselves can search for it's subscription");
}
} catch (SQLException sqlException) {
throw new SQLException(sqlException.getMessage(), sqlException);
} catch (AuthorizeException authorizeException) {
throw new AuthorizeException(authorizeException.getMessage());
} }
return converter.toRestPage(subscriptions, pageable, total, utils.obtainProjection());
} }
@PreAuthorize("isAuthenticated()")
@SearchRestMethod(name = "findByEPersonAndDso") @SearchRestMethod(name = "findByEPersonAndDso")
public Page<SubscriptionRest> findByEPersonAndDso(Pageable pageable) throws Exception { @PreAuthorize("hasPermission(#epersonId, 'AdminOrOwner', 'READ')")
public Page<SubscriptionRest> findByEPersonAndDso(@Parameter(value = "eperson_id", required = true) UUID epersonId,
@Parameter(value = "dspace_object_id",required = true) UUID dsoId,
Pageable pageable) throws Exception {
Long total = null;
List<Subscription> subscriptions = null;
try { try {
Context context = obtainContext(); Context context = obtainContext();
HttpServletRequest req = getRequestService().getCurrentRequest().getHttpServletRequest(); DSpaceObject dSpaceObject = dspaceObjectUtil.findDSpaceObject(context, dsoId);
String epersonId = req.getParameter("eperson_id"); EPerson ePerson = ePersonService.find(context, epersonId);
String dsoId = req.getParameter("dspace_object_id"); subscriptions = subscribeService.findSubscriptionsByEPersonAndDso(context, ePerson, dSpaceObject,
DSpaceObject dSpaceObject = dspaceObjectUtil.findDSpaceObject(context, UUID.fromString(dsoId)); Math.toIntExact(pageable.getPageSize()),
EPerson ePerson = personService.findByIdOrLegacyId(context, epersonId); Math.toIntExact(pageable.getOffset()));
// dso must always be set total = subscribeService.countByEPersonAndDSO(context, ePerson, dSpaceObject);
if (dsoId == null || epersonId == null) { } catch (SQLException e) {
throw new UnprocessableEntityException("error parsing the body"); throw new SQLException(e.getMessage(), e);
}
if (context.getCurrentUser().equals(ePerson)
|| authorizeService.isAdmin(context, context.getCurrentUser())) {
List<Subscription> subscriptionList =
subscribeService.getSubscriptionsByEPersonAndDso(context, ePerson, dSpaceObject,
pageable.getPageSize(), Math.toIntExact(pageable.getOffset()));
Long total = subscribeService.countAllByEPersonAndDSO(context, ePerson, dSpaceObject);
return converter.toRestPage(subscriptionList, pageable, total,
utils.obtainProjection());
} else {
throw new AuthorizeException("Only admin or e-person themselves can search for it's subscription");
}
} catch (SQLException sqlException) {
throw new SQLException(sqlException.getMessage(), sqlException);
} catch (AuthorizeException authorizeException) {
throw new AuthorizeException(authorizeException.getMessage());
} }
return converter.toRestPage(subscriptions, pageable, total, utils.obtainProjection());
} }
@Override @Override
@PreAuthorize("isAuthenticated()")
protected SubscriptionRest createAndReturn(Context context) throws SQLException, AuthorizeException { protected SubscriptionRest createAndReturn(Context context) throws SQLException, AuthorizeException {
HttpServletRequest req = getRequestService().getCurrentRequest().getHttpServletRequest(); HttpServletRequest req = getRequestService().getCurrentRequest().getHttpServletRequest();
String epersonId = req.getParameter("eperson_id"); String epersonId = req.getParameter("eperson_id");
String dsoId = req.getParameter("dspace_object_id"); String dsoId = req.getParameter("dspace_object_id");
// dso must always be set
if (dsoId == null || epersonId == null) { if (Objects.isNull(dsoId) || Objects.isNull(epersonId)) {
throw new UnprocessableEntityException("error parsing the body"); throw new UnprocessableEntityException("Both eperson than DSpaceObject uuids must be provieded!");
} }
ObjectMapper mapper = new ObjectMapper();
try { try {
DSpaceObject dSpaceObject = dspaceObjectUtil.findDSpaceObject(context, UUID.fromString(dsoId)); DSpaceObject dSpaceObject = dspaceObjectUtil.findDSpaceObject(context, UUID.fromString(dsoId));
EPerson ePerson = personService.findByIdOrLegacyId(context, epersonId); EPerson ePerson = ePersonService.findByIdOrLegacyId(context, epersonId);
if (ePerson == null || dSpaceObject == null) { if (Objects.isNull(ePerson) || Objects.isNull(dSpaceObject)) {
throw new BadRequestException("Id of person or dspace object must represents reals ids"); throw new BadRequestException("Id of person or dspace object must represents reals ids");
} }
// user must have read permissions to dataspace object // user must have read permissions to dataspace object
if (!authorizeService.authorizeActionBoolean(context, ePerson, dSpaceObject, Constants.READ, true)) { if (!authorizeService.authorizeActionBoolean(context, ePerson, dSpaceObject, Constants.READ, true)) {
throw new AuthorizeException("The user has not READ rights on this DSO"); throw new AuthorizeException("The user has not READ rights on this DSO");
} }
// if user is admin do not make this control, // if user is admin do not make this control,
// otherwise make this control because normal user can only subscribe with their own ID of user. // otherwise make this control because normal user can only subscribe with their own ID of user.
if (!authorizeService.isAdmin(context)) { if (!authorizeService.isAdmin(context)) {
@@ -183,7 +165,7 @@ public class SubscriptionRestRepository extends DSpaceRestRepository<Subscriptio
} }
} }
ServletInputStream input = req.getInputStream(); ServletInputStream input = req.getInputStream();
SubscriptionRest subscriptionRest = mapper.readValue(input, SubscriptionRest.class); SubscriptionRest subscriptionRest = new ObjectMapper().readValue(input, SubscriptionRest.class);
Subscription subscription = null; Subscription subscription = null;
List<SubscriptionParameterRest> subscriptionParameterList = subscriptionRest.getSubscriptionParameterList(); List<SubscriptionParameterRest> subscriptionParameterList = subscriptionRest.getSubscriptionParameterList();
if (subscriptionParameterList != null) { if (subscriptionParameterList != null) {
@@ -212,91 +194,71 @@ public class SubscriptionRestRepository extends DSpaceRestRepository<Subscriptio
} }
@Override @Override
@PreAuthorize("isAuthenticated()") @PreAuthorize("hasPermission(#id, 'subscription', 'WRITE')")
protected SubscriptionRest put(Context context, HttpServletRequest request, String apiCategory, String model, protected SubscriptionRest put(Context context, HttpServletRequest request, String apiCategory, String model,
Integer id, JsonNode jsonNode) throws SQLException, AuthorizeException { Integer id, JsonNode jsonNode) throws SQLException, AuthorizeException {
HttpServletRequest req = getRequestService().getCurrentRequest().getHttpServletRequest(); HttpServletRequest req = getRequestService().getCurrentRequest().getHttpServletRequest();
String epersonId = req.getParameter("eperson_id"); String epersonId = req.getParameter("eperson_id");
String dsoId = req.getParameter("dspace_object_id"); String dsoId = req.getParameter("dspace_object_id");
SubscriptionRest subscriptionRest = null;
DSpaceObject dSpaceObject = null; SubscriptionRest subscriptionRest;
EPerson ePerson = null;
try { try {
subscriptionRest = new ObjectMapper().readValue(jsonNode.toString(), SubscriptionRest.class); subscriptionRest = new ObjectMapper().readValue(jsonNode.toString(), SubscriptionRest.class);
} catch (IOException e) { } catch (IOException e) {
throw new UnprocessableEntityException("Error parsing subscription json: " + e.getMessage()); throw new UnprocessableEntityException("Error parsing subscription json: " + e.getMessage(), e);
} }
String notFoundException = "ResourceNotFoundException:" + apiCategory + "." + model
+ " with id: " + id + " not found"; Subscription subscription = subscribeService.findById(context, id);
Subscription subscription; if (Objects.isNull(subscription)) {
try { throw new ResourceNotFoundException(apiCategory + "." + model + " with id: " + id + " not found");
subscription = subscribeService.findById(context, id);
if (subscription == null) {
throw new ResourceNotFoundException(notFoundException);
}
dSpaceObject = dspaceObjectUtil.findDSpaceObject(context, UUID.fromString(dsoId));
ePerson = personService.findByIdOrLegacyId(context, epersonId);
if (dSpaceObject == null || ePerson == null) {
throw new ResourceNotFoundException(notFoundException);
}
} catch (SQLException e) {
throw new ResourceNotFoundException(notFoundException);
} catch (AuthorizeException e) {
throw new AuthorizeException(e.getMessage());
} }
EPerson ePerson = ePersonService.findByIdOrLegacyId(context, epersonId);
if (Objects.isNull(ePerson)) {
throw new ResourceNotFoundException("There is not ePerson with uuid:" + epersonId);
}
DSpaceObject dSpaceObject = dspaceObjectUtil.findDSpaceObject(context, UUID.fromString(dsoId));
if (Objects.isNull(dSpaceObject)) {
throw new ResourceNotFoundException("There is not DSpaceObject with uuid:" + dsoId);
}
if (id.equals(subscription.getID())) { if (id.equals(subscription.getID())) {
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
for (SubscriptionParameterRest subscriptionParameterRest : for (SubscriptionParameterRest subscriptionParamRest : subscriptionRest.getSubscriptionParameterList()) {
subscriptionRest.getSubscriptionParameterList()) {
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setSubscription(subscription); subscriptionParameter.setSubscription(subscription);
subscriptionParameter.setValue(subscriptionParameterRest.getValue()); subscriptionParameter.setValue(subscriptionParamRest.getValue());
subscriptionParameter.setName(subscriptionParameterRest.getName()); subscriptionParameter.setName(subscriptionParamRest.getName());
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
} }
subscription = subscribeService.updateSubscription(context, id, ePerson, subscription = subscribeService.updateSubscription(context, id, ePerson, dSpaceObject,
dSpaceObject, subscriptionParameterList, subscriptionRest.getSubscriptionType()); subscriptionParameterList, subscriptionRest.getSubscriptionType());
context.commit(); 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: " + id + ", "
+ id + ", " + subscription.getID());
+ subscription.getID());
} }
} }
@Override @Override
@PreAuthorize("isAuthenticated()") @PreAuthorize("hasPermission(#id, 'subscription', 'DELETE')")
public void patch(Context context,HttpServletRequest request,String category, String model, Integer id, Patch patch) protected void delete(Context context, Integer id) throws AuthorizeException {
throws UnprocessableEntityException, DSpaceBadRequestException, AuthorizeException {
try { try {
Subscription subscription = subscribeService.findById(context, id); Subscription subscription = subscribeService.findById(context, id);
if (subscription == null) { if (Objects.isNull(subscription)) {
throw new ResourceNotFoundException(category + "." + model + " with id: " + id + " not found"); throw new ResourceNotFoundException(CATEGORY + "." + NAME + " with id: " + id + " not found");
} }
if (!authorizeService.isAdmin(context) || subscription.getePerson().equals(context.getCurrentUser())) { subscribeService.deleteSubscription(context, subscription);
throw new AuthorizeException("Only admin or e-person themselves can edit the subscription");
}
resourcePatch.patch(context, subscription, patch.getOperations());
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e); throw new RuntimeException("Unable to delete Subscription with id = " + id, e);
} catch (AuthorizeException authorizeException) {
throw new AuthorizeException(authorizeException.getMessage());
} catch (RuntimeException runtimeException) {
throw new RuntimeException(runtimeException.getMessage());
} }
} }
@Override @Override
@PreAuthorize("isAuthenticated()") protected void patch(Context c, HttpServletRequest req, String category, String model, Integer id, Patch patch) {
public void delete(Context context, Integer id) throws AuthorizeException { throw new RepositoryMethodNotImplementedException(SubscriptionRest.NAME, "patch");
try {
subscribeService.deleteSubscription(context, id);
} catch (SQLException sqlException) {
throw new RuntimeException(sqlException.getMessage(), sqlException);
} catch (AuthorizeException authorizeException) {
throw new AuthorizeException(authorizeException.getMessage());
}
} }
@Override @Override

View File

@@ -1,79 +0,0 @@
/**
* 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
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.repository.patch.operation;
import java.sql.SQLException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.dspace.app.rest.exception.DSpaceBadRequestException;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.SubscriptionParameterRest;
import org.dspace.app.rest.model.patch.JsonValueEvaluator;
import org.dspace.app.rest.model.patch.Operation;
import org.dspace.core.Context;
import org.dspace.eperson.Subscription;
import org.dspace.eperson.SubscriptionParameter;
import org.dspace.eperson.service.SubscribeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Implementation for SubscriptionParameterAddOperation patches.
* <p>
* Example:
* <code> curl -X PATCH http://${dspace.server.url}api/core/subscriptions/<:id-subscription> -H "
* Content-Type: application/json" -d '[{ "op": "replace", "path": "
* </code>
*/
@Component
public class SubscriptionParameterAddOperation extends PatchOperation<Subscription> {
@Autowired
private SubscribeService subscribeService;
@Override
public Subscription perform(Context context, Subscription subscription, Operation operation)
throws SQLException {
if (supports(subscription, operation)) {
JsonNode value = null;
ObjectMapper objectMapper = new ObjectMapper();
try {
if (operation.getValue() instanceof JsonValueEvaluator) {
value = ((JsonValueEvaluator) operation.getValue()).getValueNode();
} else {
value = objectMapper.readTree((String) operation.getValue());
}
SubscriptionParameterRest subscriptionParameterRest =
objectMapper.readValue(value.toString(), SubscriptionParameterRest.class);
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setSubscription(subscription);
subscriptionParameter.setValue(subscriptionParameterRest.getValue());
subscriptionParameter.setName(subscriptionParameterRest.getName());
subscribeService.addSubscriptionParameter(context, subscription.getID(), subscriptionParameter);
} catch (UnprocessableEntityException e) {
throw new UnprocessableEntityException(e.getMessage(), e);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
} else {
throw new DSpaceBadRequestException("Subscription does not support this operation");
}
return subscription;
}
@Override
public boolean supports(Object objectToMatch, Operation operation) {
return (objectToMatch instanceof Subscription
&& operation.getOp().trim().equalsIgnoreCase(OPERATION_ADD));
}
}

View File

@@ -1,65 +0,0 @@
/**
* 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
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.repository.patch.operation;
import java.sql.SQLException;
import org.dspace.app.rest.exception.DSpaceBadRequestException;
import org.dspace.app.rest.exception.RESTAuthorizationException;
import org.dspace.app.rest.model.patch.Operation;
import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context;
import org.dspace.eperson.Subscription;
import org.dspace.eperson.SubscriptionParameter;
import org.dspace.eperson.service.SubscribeService;
import org.dspace.eperson.service.SubscriptionParameterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Implementation for SubscriptionParameterRemoveOperation patches.
* <p>
* Example:
* <code> curl -X PATCH http://${dspace.server.url}api/core/subscriptions/<:id-subscription> -H "
* Content-Type: application/json" -d '[{ "op": "replace", "path": "
* </code>
*/
@Component
public class SubscriptionParameterRemoveOperation extends PatchOperation<Subscription> {
@Autowired
private SubscriptionParameterService subscriptionParameterService;
@Autowired
private SubscribeService subscribeService;
@Override
public Subscription perform(Context context, Subscription subscription, Operation operation)
throws SQLException {
if (supports(subscription, operation)) {
Integer path = Integer.parseInt(operation.getPath().split("/")[2]);
try {
SubscriptionParameter subscriptionParameter = subscriptionParameterService.findById(context, path);
subscribeService.removeSubscriptionParameter(context, subscription.getID(), subscriptionParameter);
} catch (AuthorizeException e) {
throw new RESTAuthorizationException("Unauthorized user for removing subscription parameter");
}
} else {
throw new DSpaceBadRequestException("Subscription does not support this operation");
}
return subscription;
}
@Override
public boolean supports(Object objectToMatch, Operation operation) {
return (objectToMatch instanceof Subscription
&& operation.getOp().trim().equalsIgnoreCase(OPERATION_REMOVE));
}
}

View File

@@ -1,83 +0,0 @@
/**
* 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
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.repository.patch.operation;
import java.sql.SQLException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.dspace.app.rest.exception.DSpaceBadRequestException;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.SubscriptionParameterRest;
import org.dspace.app.rest.model.patch.JsonValueEvaluator;
import org.dspace.app.rest.model.patch.Operation;
import org.dspace.core.Context;
import org.dspace.eperson.Subscription;
import org.dspace.eperson.service.SubscriptionParameterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Implementation for SubscriptionParameterReplaceOperation patches.
* <p>
* Example:
* <code> curl -X PATCH http://${dspace.server.url}api/core/subscriptions/<:id-subscription> -H "
* Content-Type: application/json" -d '[{ "op": "replace", "path": "
* </code>
*/
@Component
public class SubscriptionParameterReplaceOperation extends PatchOperation<Subscription> {
@Autowired
private SubscriptionParameterService subscriptionParameterService;
@Override
public Subscription perform(Context context, Subscription subscription, Operation operation)
throws SQLException {
if (supports(subscription, operation)) {
Integer subscriptionParameterId = Integer.parseInt(operation.getPath().split("/", 3)[2]);
checkModelForExistingValue(subscription, subscriptionParameterId);
JsonNode value = null;
ObjectMapper objectMapper = new ObjectMapper();
try {
if (operation.getValue() instanceof JsonValueEvaluator) {
value = ((JsonValueEvaluator) operation.getValue()).getValueNode();
} else {
value = objectMapper.readTree((String) operation.getValue());
}
SubscriptionParameterRest subscriptionParameterRest = objectMapper.readValue(
value.toString(), SubscriptionParameterRest.class);
subscriptionParameterService.edit(context, subscriptionParameterId,subscriptionParameterRest.getValue(),
subscriptionParameterRest.getName(), subscription);
} catch (UnprocessableEntityException e) {
throw new UnprocessableEntityException(e.getMessage(), e);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
return subscription;
} else {
throw new DSpaceBadRequestException("Subscription does not support this operation");
}
}
@Override
public boolean supports(Object objectToMatch, Operation operation) {
return (objectToMatch instanceof Subscription && operation.getOp().trim().equalsIgnoreCase(OPERATION_REPLACE));
}
/**
* Checks whether the subscription
*/
@SuppressWarnings("ReturnValueIgnored")
private void checkModelForExistingValue(Subscription subscription, Integer id) {
subscription.getSubscriptionParameterList().stream().filter(subscriptionParameter -> {
return subscriptionParameter.getId().equals(id);
}).findFirst().orElseThrow();
}
}

View File

@@ -0,0 +1,73 @@
/**
* 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
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.security;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.Objects;
import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.utils.ContextUtil;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.services.RequestService;
import org.dspace.services.model.Request;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;
/**
* @author Mykhaylo Boychuk (mykhaylo.boychuk@4science.com)
*/
@Component
public class SubscriptionAdminAndOwnerPermissionEvaluatorPlugin extends RestObjectPermissionEvaluatorPlugin {
private static final Logger log = LoggerFactory.getLogger(SubscriptionAdminAndOwnerPermissionEvaluatorPlugin.class);
@Autowired
private RequestService requestService;
@Autowired
private AuthorizeService authorizeService;
@Override
public boolean hasDSpacePermission(Authentication authentication, Serializable targetId,
String targetType, DSpaceRestPermission permission) {
DSpaceRestPermission restPermission = DSpaceRestPermission.convert(permission);
if (!DSpaceRestPermission.READ.equals(restPermission) &&
!DSpaceRestPermission.WRITE.equals(restPermission) &&
!DSpaceRestPermission.DELETE.equals(restPermission) ||
!StringUtils.equals(targetType, "AdminOrOwner")) {
return false;
}
Request request = requestService.getCurrentRequest();
Context context = ContextUtil.obtainContext(request.getHttpServletRequest());
UUID dsoId = UUID.fromString(targetId.toString());
EPerson currentUser = context.getCurrentUser();
// anonymous user
if (Objects.isNull(currentUser)) {
return false;
}
try {
return dsoId.equals(currentUser.getID()) || authorizeService.isAdmin(context, currentUser);
} catch (SQLException e) {
log.error(e.getMessage(), e);
}
return false;
}
}

View File

@@ -0,0 +1,84 @@
/**
* 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
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.security;
import static org.dspace.app.rest.model.SubscriptionRest.NAME;
import static org.dspace.app.rest.security.DSpaceRestPermission.DELETE;
import static org.dspace.app.rest.security.DSpaceRestPermission.READ;
import static org.dspace.app.rest.security.DSpaceRestPermission.WRITE;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.utils.ContextUtil;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.Subscription;
import org.dspace.eperson.service.SubscribeService;
import org.dspace.services.RequestService;
import org.dspace.services.model.Request;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;
/**
* {@link RestPermissionEvaluatorPlugin}
*
* @author Mykhaylo Boychuk (mykhaylo.boychuk at 4science.com)
*/
@Component
public class SubscriptionRestPermissionEvaluatorPlugin extends RestObjectPermissionEvaluatorPlugin {
private static final Logger log = LoggerFactory.getLogger(SubscriptionRestPermissionEvaluatorPlugin.class);
@Autowired
private RequestService requestService;
@Autowired
private SubscribeService subscribeService;
@Autowired
private AuthorizeService authorizeService;
@Override
public boolean hasDSpacePermission(Authentication authentication, Serializable targetId, String targetType,
DSpaceRestPermission permission) {
DSpaceRestPermission restPermission = DSpaceRestPermission.convert(permission);
if (!READ.equals(restPermission) && !WRITE.equals(restPermission) && !DELETE.equals(restPermission)
|| !StringUtils.equalsIgnoreCase(targetType, NAME)) {
return false;
}
Request request = requestService.getCurrentRequest();
Context context = ContextUtil.obtainContext(request.getHttpServletRequest());
try {
EPerson currentUser = context.getCurrentUser();
// anonymous user
if (Objects.isNull(currentUser)) {
return false;
}
// Admin user
if (authorizeService.isAdmin(context, currentUser)) {
return true;
}
Subscription subscription = subscribeService.findById(context, Integer.parseInt(targetId.toString()));
return Objects.nonNull(subscription) ? currentUser.equals(subscription.getePerson()) : true;
} catch (SQLException e) {
log.error(e.getMessage(), e);
}
return false;
}
}

View File

@@ -7,10 +7,11 @@
*/ */
package org.dspace.app.rest; package org.dspace.app.rest;
import static com.jayway.jsonpath.JsonPath.read;
import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
@@ -21,14 +22,12 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.dspace.app.rest.matcher.SubscriptionMatcher;
import org.dspace.app.rest.model.SubscriptionParameterRest; import org.dspace.app.rest.model.SubscriptionParameterRest;
import org.dspace.app.rest.model.SubscriptionRest; import org.dspace.app.rest.model.SubscriptionRest;
import org.dspace.app.rest.model.patch.AddOperation;
import org.dspace.app.rest.model.patch.Operation;
import org.dspace.app.rest.model.patch.RemoveOperation;
import org.dspace.app.rest.model.patch.ReplaceOperation;
import org.dspace.app.rest.test.AbstractControllerIntegrationTest; import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.builder.CollectionBuilder; import org.dspace.builder.CollectionBuilder;
import org.dspace.builder.CommunityBuilder; import org.dspace.builder.CommunityBuilder;
@@ -84,39 +83,34 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
@Test @Test
public void findAll() throws Exception { public void findAll() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("Frequency"); subscriptionParameter.setName("Frequency");
subscriptionParameter.setValue("Daily"); subscriptionParameter.setValue("Daily");
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context, Subscription subscription1 = SubscribeBuilder.subscribeBuilder(context,
"TypeTest", publicItem, admin, subscriptionParameterList).build(); "TestType", publicItem, eperson, subscriptionParameterList).build();
subscriptionParameter.setSubscription(subscription); List<SubscriptionParameter> subscriptionParameterList2 = new ArrayList<>();
SubscriptionParameter subscriptionParameter2 = new SubscriptionParameter();
subscriptionParameter2.setName("Frequency");
subscriptionParameter2.setValue("WEEKLY");
subscriptionParameterList2.add(subscriptionParameter2);
Subscription subscription2 = SubscribeBuilder.subscribeBuilder(context,
"TestType 2", collection, admin, subscriptionParameterList2).build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
String tokenAdmin = getAuthToken(admin.getEmail(), password); String tokenAdmin = getAuthToken(admin.getEmail(), password);
getClient(tokenAdmin).perform(get("/api/core/subscriptions")) getClient(tokenAdmin).perform(get("/api/core/subscriptions"))
.andExpect(status().isOk()) .andExpect(status().isOk())
//We expect the content type to be "application/hal+json;charset=UTF-8" .andExpect(jsonPath("$._embedded.subscriptions", Matchers.containsInAnyOrder(
.andExpect(content().contentType(contentType)) SubscriptionMatcher.matchSubscription(subscription1),
//By default we expect at least 1 submission forms so this to be reflected in the page object SubscriptionMatcher.matchSubscription(subscription2)
.andExpect(jsonPath("$.page.size", is(20))) )))
.andExpect(jsonPath("$.page.totalElements", greaterThanOrEqualTo(1))) .andExpect(jsonPath("$.page.size", is(20)))
.andExpect(jsonPath("$.page.totalPages", greaterThanOrEqualTo(1))) .andExpect(jsonPath("$.page.totalElements", greaterThanOrEqualTo(2)))
.andExpect(jsonPath("$.page.number", is(0))) .andExpect(jsonPath("$.page.totalPages", greaterThanOrEqualTo(1)))
.andExpect(jsonPath("$._embedded.subscriptions[0].subscriptionType", is("TypeTest"))) .andExpect(jsonPath("$.page.number", is(0)));
.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")));
} }
@Test @Test
@@ -141,39 +135,26 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
subscriptionParameter.setName("Frequency"); subscriptionParameter.setName("Frequency");
subscriptionParameter.setValue("Daily"); subscriptionParameter.setValue("Daily");
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context, Subscription subscription = SubscribeBuilder.subscribeBuilder(context,
"TypeTest", publicItem, admin, subscriptionParameterList).build(); "TypeTest", publicItem, admin, subscriptionParameterList).build();
subscriptionParameter.setSubscription(subscription);
context.restoreAuthSystemState(); context.restoreAuthSystemState();
String tokenAdmin = getAuthToken(admin.getEmail(), password); String tokenAdmin = getAuthToken(admin.getEmail(), password);
getClient(tokenAdmin).perform(get("/api/core/subscriptions?resourceType=Item")) getClient(tokenAdmin).perform(get("/api/core/subscriptions?resourceType=Item"))
.andExpect(status().isOk()) .andExpect(status().isOk())
//We expect the content type to be "application/hal+json;charset=UTF-8" .andExpect(jsonPath("$._embedded.subscriptions", Matchers.contains(
.andExpect(content().contentType(contentType)) SubscriptionMatcher.matchSubscription(subscription)
//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.size", is(20)))
.andExpect(jsonPath("$.page.totalElements", greaterThanOrEqualTo(1))) .andExpect(jsonPath("$.page.totalElements", greaterThanOrEqualTo(1)))
.andExpect(jsonPath("$.page.totalPages", greaterThanOrEqualTo(1))) .andExpect(jsonPath("$.page.totalPages", greaterThanOrEqualTo(1)))
.andExpect(jsonPath("$.page.number", is(0))) .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 // search for subscriptions related with collections
getClient(tokenAdmin).perform(get("/api/core/subscriptions?resourceType=Collection")) getClient(tokenAdmin).perform(get("/api/core/subscriptions?resourceType=Collection"))
.andExpect(status().isOk()) .andExpect(status().isOk())
//We expect the content type to be "application/hal+json;charset=UTF-8"
.andExpect(content().contentType(contentType)) .andExpect(content().contentType(contentType))
//By default we expect at least 1 submission forms so this to be reflected in the page object //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.size", is(20)))
@@ -185,7 +166,7 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
} }
@Test @Test
public void findByIdAsAdministrator() throws Exception { public void findOneWithOwnerTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
@@ -193,7 +174,39 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
subscriptionParameter.setValue("ValueParameter"); subscriptionParameter.setValue("ValueParameter");
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context, Subscription subscription = SubscribeBuilder.subscribeBuilder(context,
"TestType", publicItem, admin, subscriptionParameterList).build(); "TestType", publicItem, eperson, subscriptionParameterList).build();
context.restoreAuthSystemState();
String tokenEPerson = getAuthToken(eperson.getEmail(), password);
getClient(tokenEPerson).perform(get("/api/core/subscriptions/" + subscription.getID()))
.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("$.subscriptionType", is("TestType")))
.andExpect(jsonPath("$.subscriptionParameterList[0].name", is("Parameter")))
.andExpect(jsonPath("$.subscriptionParameterList[0].value", is("ValueParameter")))
.andExpect(jsonPath("$._links.ePerson.href", Matchers.endsWith("/ePerson")))
.andExpect(jsonPath("$._links.dSpaceObject.href", Matchers.endsWith("/dSpaceObject")))
.andExpect(jsonPath("$._links.self.href",
Matchers.startsWith(REST_SERVER_URL + "core/subscriptions/" + subscription.getID())))
.andExpect(jsonPath("$._links.dSpaceObject.href",
Matchers.startsWith(REST_SERVER_URL + "core/subscriptions")))
.andExpect(jsonPath("$._links.ePerson.href",
Matchers.startsWith(REST_SERVER_URL + "core/subscriptions")));
}
@Test
public void findOneAdminTest() throws Exception {
context.turnOffAuthorisationSystem();
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(); context.restoreAuthSystemState();
String tokenAdmin = getAuthToken(admin.getEmail(), password); String tokenAdmin = getAuthToken(admin.getEmail(), password);
@@ -216,7 +229,7 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
} }
@Test @Test
public void findByIdAsAnonymous() throws Exception { public void findOneAnonymousTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
@@ -224,7 +237,7 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
subscriptionParameter.setValue("ValueParameter"); subscriptionParameter.setValue("ValueParameter");
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context, Subscription subscription = SubscribeBuilder.subscribeBuilder(context,
"TestType", publicItem, admin, subscriptionParameterList).build(); "TestType", publicItem, admin, subscriptionParameterList).build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
getClient().perform(get("/api/core/subscriptions/" + subscription.getID())) getClient().perform(get("/api/core/subscriptions/" + subscription.getID()))
@@ -232,8 +245,7 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
} }
@Test @Test
//TODO public void findOneForbiddenTest() throws Exception {
public void findByIdNotAsSubscriberNotAsAdmin() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
@@ -241,90 +253,148 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
subscriptionParameter.setValue("ValueParameter"); subscriptionParameter.setValue("ValueParameter");
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context, Subscription subscription = SubscribeBuilder.subscribeBuilder(context,
"TestType", publicItem, admin, subscriptionParameterList).build(); "TestType", publicItem, admin, subscriptionParameterList).build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
String tokenEPerson = getAuthToken(eperson.getEmail(), password); String tokenEPerson = getAuthToken(eperson.getEmail(), password);
getClient(tokenEPerson).perform(get("/api/core/subscriptions/" + subscription.getID())) getClient(tokenEPerson).perform(get("/api/core/subscriptions/" + subscription.getID()))
.andExpect(status().isInternalServerError()); .andExpect(status().isForbidden());
} }
@Test @Test
public void findAllSubscriptionsByEPerson() throws Exception { public void findOneNotFoundTest() throws Exception {
String tokenAdmin = getAuthToken(admin.getEmail(), password);
getClient(tokenAdmin).perform(get("/api/core/subscriptions/" + Integer.MAX_VALUE))
.andExpect(status().isNotFound());
}
@Test
public void findSubscriptionsByEPersonAdminTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
EPerson user = EPersonBuilder.createEPerson(context)
.withEmail("user@test.it")
.withPassword(password)
.build();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("Parameter1"); subscriptionParameter.setName("Parameter 1");
subscriptionParameter.setValue("ValueParameter1"); subscriptionParameter.setValue("ValueParameter 1");
subscriptionParameterList.add(subscriptionParameter);
Subscription subscription1 = SubscribeBuilder.subscribeBuilder(context,
"TestType", publicItem, eperson, subscriptionParameterList).build();
List<SubscriptionParameter> subscriptionParameterList2 = new ArrayList<>();
SubscriptionParameter subscriptionParameter2 = new SubscriptionParameter();
subscriptionParameter2.setName("Parameter 2");
subscriptionParameter2.setValue("ValueParameter 2");
subscriptionParameterList2.add(subscriptionParameter2);
Subscription subscription2 = SubscribeBuilder.subscribeBuilder(context,
"TestType 2", collection, eperson, subscriptionParameterList2).build();
context.restoreAuthSystemState();
String tokenAdmin = getAuthToken(admin.getEmail(), password);
getClient(tokenAdmin).perform(get("/api/core/subscriptions/search/findByEPerson")
.param("uuid", eperson.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.subscriptions", Matchers.containsInAnyOrder(
SubscriptionMatcher.matchSubscription(subscription1),
SubscriptionMatcher.matchSubscription(subscription2)
)))
.andExpect(jsonPath("$.page.size", is(20)))
.andExpect(jsonPath("$.page.totalElements", greaterThanOrEqualTo(2)))
.andExpect(jsonPath("$.page.totalPages", greaterThanOrEqualTo(1)))
.andExpect(jsonPath("$.page.number", is(0)));
}
@Test
public void findSubscriptionsByEPersonOwnerTest() throws Exception {
context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("Parameter 1");
subscriptionParameter.setValue("ValueParameter 1");
subscriptionParameterList.add(subscriptionParameter);
Subscription subscription1 = SubscribeBuilder.subscribeBuilder(context,
"TestType", publicItem, eperson, subscriptionParameterList).build();
List<SubscriptionParameter> subscriptionParameterList2 = new ArrayList<>();
SubscriptionParameter subscriptionParameter2 = new SubscriptionParameter();
subscriptionParameter2.setName("Parameter 2");
subscriptionParameter2.setValue("ValueParameter 2");
subscriptionParameterList2.add(subscriptionParameter2);
Subscription subscription2 = SubscribeBuilder.subscribeBuilder(context,
"TestType 2", collection, eperson, subscriptionParameterList2).build();
context.restoreAuthSystemState();
String tokenAdmin = getAuthToken(eperson.getEmail(), password);
getClient(tokenAdmin).perform(get("/api/core/subscriptions/search/findByEPerson")
.param("uuid", eperson.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.subscriptions", Matchers.containsInAnyOrder(
SubscriptionMatcher.matchSubscription(subscription1),
SubscriptionMatcher.matchSubscription(subscription2)
)))
.andExpect(jsonPath("$.page.size", is(20)))
.andExpect(jsonPath("$.page.totalElements", greaterThanOrEqualTo(2)))
.andExpect(jsonPath("$.page.totalPages", greaterThanOrEqualTo(1)))
.andExpect(jsonPath("$.page.number", is(0)));
}
@Test
public void findSubscriptionsByEPersonUnauthorizedTest() throws Exception {
context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("Parameter 1");
subscriptionParameter.setValue("ValueParameter 1");
subscriptionParameterList.add(subscriptionParameter);
SubscribeBuilder.subscribeBuilder(context, "TestType", publicItem, eperson, subscriptionParameterList).build();
context.restoreAuthSystemState();
getClient().perform(get("/api/core/subscriptions/search/findByEPerson")
.param("uuid", eperson.getID().toString()))
.andExpect(status().isUnauthorized());
}
@Test
public void findSubscriptionsByEPersonForbiddenTest() throws Exception {
context.turnOffAuthorisationSystem();
EPerson user = EPersonBuilder.createEPerson(context)
.withEmail("user1@mail.com")
.withPassword(password)
.build();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("Parameter 1");
subscriptionParameter.setValue("ValueParameter 1");
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
SubscribeBuilder.subscribeBuilder(context, "TestType", publicItem, user, subscriptionParameterList).build(); SubscribeBuilder.subscribeBuilder(context, "TestType", publicItem, user, subscriptionParameterList).build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
String tokenEPerson = getAuthToken(eperson.getEmail(), password); String tokenEPerson = getAuthToken(eperson.getEmail(), password);
getClient(tokenEPerson).perform(get("/api/core/subscriptions/search/findByEPerson?id=" + eperson.getID())) getClient(tokenEPerson).perform(get("/api/core/subscriptions/search/findByEPerson")
.andExpect(status().isOk()) .param("uuid", user.getID().toString()))
.andExpect(jsonPath("$.page.size", is(20))) .andExpect(status().isForbidden());
.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("TestType")))
.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("Parameter1")))
.andExpect(jsonPath("$._embedded.subscriptions[0].subscriptionParameterList[0].value",
is("ValueParameter1")));
context.turnOffAuthorisationSystem();
EPersonBuilder.createEPerson(context)
.withEmail("epersonIT@example.com")
.withPassword(password)
.withLanguage("al")
.build();
subscriptionParameter.setName("Parameter1");
subscriptionParameter.setValue("ValueParameter1");
subscriptionParameterList.add(subscriptionParameter);
List<SubscriptionParameter> subscriptionParameterList1 = new ArrayList<>();
SubscriptionParameter subscriptionParameter1 = new SubscriptionParameter();
subscriptionParameter1.setName("Parameter1");
subscriptionParameter1.setValue("ValueParameter1");
subscriptionParameterList1.add(subscriptionParameter1);
SubscribeBuilder.subscribeBuilder(context, "TestType", collection, user, subscriptionParameterList).build();
SubscribeBuilder.subscribeBuilder(context, "Test", collection, user, subscriptionParameterList1).build();
context.restoreAuthSystemState();
String tokenAdmin = getAuthToken(admin.getEmail(), password);
getClient(tokenAdmin).perform(get("/api/core/subscriptions/search/findByEPersonAndDso")
.param("dspace_object_id", collection.getID().toString())
.param("eperson_id", user.getID().toString()))
.andExpect(status().isUnauthorized());
} }
@Test @Test
public void addSubscriptionNotLoggedIn() throws Exception { public void createSubscriptionUnauthorizedTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
SubscriptionParameterRest subscriptionParameterRest = new SubscriptionParameterRest(); SubscriptionParameterRest subscriptionParameterRest = new SubscriptionParameterRest();
subscriptionParameterRest.setValue("nameTest"); subscriptionParameterRest.setValue("Frequency");
subscriptionParameterRest.setName("valueTest"); subscriptionParameterRest.setName("Daily");
List<SubscriptionParameterRest> subscriptionParameterRestList = new ArrayList<>(); List<SubscriptionParameterRest> subscriptionParameterRestList = new ArrayList<>();
subscriptionParameterRestList.add(subscriptionParameterRest); subscriptionParameterRestList.add(subscriptionParameterRest);
SubscriptionRest subscriptionRest = new SubscriptionRest(); SubscriptionRest subscriptionRest = new SubscriptionRest();
subscriptionRest.setType("testType"); subscriptionRest.setType("testType");
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(); MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
params.add("dspace_object_id", publicItem.getID().toString()); params.add("dspace_object_id", publicItem.getID().toString());
params.add("eperson_id", eperson.getID().toString()); params.add("eperson_id", eperson.getID().toString());
context.restoreAuthSystemState(); context.restoreAuthSystemState();
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
getClient().perform(post("/api/core/subscriptions") getClient().perform(post("/api/core/subscriptions")
.param("dspace_object_id", publicItem.getID().toString()) .param("dspace_object_id", publicItem.getID().toString())
.param("eperson_id", eperson.getID().toString()) .param("eperson_id", eperson.getID().toString())
@@ -334,48 +404,165 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
} }
@Test @Test
public void addSubscriptionAsAdmin() throws Exception { public void createSubscriptionAdminForOtherPersonTest() throws Exception {
SubscriptionParameterRest subscriptionParameterRest = new SubscriptionParameterRest(); context.turnOffAuthorisationSystem();
subscriptionParameterRest.setValue("nameTest");
subscriptionParameterRest.setName("valueTest");
List<SubscriptionParameterRest> subscriptionParameterRestList = new ArrayList<>();
subscriptionParameterRestList.add(subscriptionParameterRest);
SubscriptionRest subscriptionRest = new SubscriptionRest();
subscriptionRest.setType("testType");
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("type", "test"); map.put("type", "testType");
List<Map<String, Object>> list = new ArrayList<>(); List<Map<String, Object>> list = new ArrayList<>();
Map<String, Object> sub_list = new HashMap<>(); Map<String, Object> sub_list = new HashMap<>();
sub_list.put("name", "frequency"); sub_list.put("name", "Frequency");
sub_list.put("value", "daily"); sub_list.put("value", "daily");
list.add(sub_list); list.add(sub_list);
map.put("subscriptionParameterList", list); map.put("subscriptionParameterList", list);
String tokenAdmin = getAuthToken(admin.getEmail(), password); context.restoreAuthSystemState();
getClient(tokenAdmin).perform(post("/api/core/subscriptions")
.param("dspace_object_id", publicItem.getID().toString()) AtomicReference<Integer> idRef = new AtomicReference<Integer>();
.param("eperson_id", admin.getID().toString())
.content(objectMapper.writeValueAsString(map)) try {
.contentType(MediaType.APPLICATION_JSON_VALUE)) String tokenAdmin = getAuthToken(admin.getEmail(), password);
.andExpect(status().isOk()) getClient(tokenAdmin).perform(post("/api/core/subscriptions")
//We expect the content type to be "application/hal+json;charset=UTF-8" .param("dspace_object_id", publicItem.getID().toString())
//By default we expect at least 1 submission forms so this to be reflected in the page object .param("eperson_id", eperson.getID().toString())
.andExpect(jsonPath("$.subscriptionType", is("testType"))) .content(new ObjectMapper().writeValueAsString(map))
.andExpect(jsonPath("$.id", Matchers.endsWith(REST_SERVER_URL + "core/dSpaceObject"))) .contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.subscriptionParameterList[0].name", is("nameTest"))) .andExpect(status().isCreated())
.andExpect(jsonPath("$.subscriptionParameterList[0].value", is("valueTest"))) .andExpect(jsonPath("$.subscriptionType", is("testType")))
.andExpect(jsonPath("$._links.self.href", Matchers.startsWith(REST_SERVER_URL + "core/subscriptions"))) .andExpect(jsonPath("$.subscriptionParameterList[0].name", is("Frequency")))
.andExpect(jsonPath("$._links.dSpaceObject.href", .andExpect(jsonPath("$.subscriptionParameterList[0].value", is("daily")))
Matchers.startsWith(REST_SERVER_URL + "core/subscriptions"))) .andExpect(jsonPath("$._links.ePerson.href", Matchers.endsWith("ePerson")))
.andExpect(jsonPath("$._links.dSpaceObject.href", Matchers.endsWith("dSpaceObject"))) .andExpect(jsonPath("$._links.dSpaceObject.href", Matchers.endsWith("dSpaceObject")))
.andExpect(jsonPath("$._links.ePerson.href", .andDo(result -> idRef.set(read(result.getResponse().getContentAsString(), "$.id")));
Matchers.startsWith(REST_SERVER_URL + "core/subscriptions"))) } finally {
.andExpect(jsonPath("$._links.ePerson.href", Matchers.endsWith("ePerson"))); SubscribeBuilder.deleteSubscription(idRef.get());
}
} }
@Test @Test
public void editSubscriptionAnonymous() throws Exception { public void createSubscriptionByEPersonTest() throws Exception {
context.turnOffAuthorisationSystem();
Map<String, Object> map = new HashMap<>();
map.put("type", "testType");
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);
map.put("subscriptionParameterList", list);
context.restoreAuthSystemState();
AtomicReference<Integer> idRef = new AtomicReference<Integer>();
try {
String tokenEPerson = getAuthToken(eperson.getEmail(), password);
getClient(tokenEPerson).perform(post("/api/core/subscriptions")
.param("dspace_object_id", publicItem.getID().toString())
.param("eperson_id", eperson.getID().toString())
.content(new ObjectMapper().writeValueAsString(map))
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.subscriptionType", is("testType")))
.andExpect(jsonPath("$.subscriptionParameterList[0].name", is("Frequency")))
.andExpect(jsonPath("$.subscriptionParameterList[0].value", is("daily")))
.andExpect(jsonPath("$._links.ePerson.href", Matchers.endsWith("ePerson")))
.andExpect(jsonPath("$._links.dSpaceObject.href", Matchers.endsWith("dSpaceObject")))
.andDo(result -> idRef.set(read(result.getResponse().getContentAsString(), "$.id")));
} finally {
SubscribeBuilder.deleteSubscription(idRef.get());
}
}
@Test
public void createSubscriptionPersonForAnotherPersonTest() throws Exception {
context.turnOffAuthorisationSystem();
EPerson user = EPersonBuilder.createEPerson(context)
.withEmail("user1@mail.com")
.withPassword(password)
.build();
Map<String, Object> map = new HashMap<>();
map.put("type", "testType");
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);
map.put("subscriptionParameterList", list);
context.restoreAuthSystemState();
String tokenEPerson = getAuthToken(eperson.getEmail(), password);
getClient(tokenEPerson).perform(post("/api/core/subscriptions")
.param("dspace_object_id", publicItem.getID().toString())
.param("eperson_id", user.getID().toString())
.content(new ObjectMapper().writeValueAsString(map))
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isForbidden());
}
@Test
public void deleteSubscriptionUnauthorizedTest() throws Exception {
context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("Frequency");
subscriptionParameter.setValue("Daily");
subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context,
"Test", publicItem, eperson, subscriptionParameterList).build();
context.restoreAuthSystemState();
getClient().perform(delete("/api/core/subscriptions/" + subscription.getID()))
.andExpect(status().isUnauthorized());
}
@Test
public void deleteSubscriptionAdminTest() throws Exception {
context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("Frequency");
subscriptionParameter.setValue("Daily");
subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context,
"Test", publicItem, eperson, subscriptionParameterList).build();
context.restoreAuthSystemState();
String tokenAdmin = getAuthToken(admin.getEmail(), password);
getClient(tokenAdmin).perform(delete("/api/core/subscriptions/" + subscription.getID()))
.andExpect(status().isNoContent());
}
@Test
public void deleteSubscriptionForbiddenTest() throws Exception {
context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("Frequency");
subscriptionParameter.setValue("Daily");
subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context,
"Test", publicItem, admin, subscriptionParameterList).build();
context.restoreAuthSystemState();
String tokenEPerson = getAuthToken(eperson.getEmail(), password);
getClient(tokenEPerson).perform(delete("/api/core/subscriptions/" + subscription.getID()))
.andExpect(status().isForbidden());
}
@Test
public void deleteSubscriptionNotFoundTest() throws Exception {
String tokenAdmin = getAuthToken(admin.getEmail(), password);
getClient(tokenAdmin).perform(delete("/api/core/subscriptions/" + Integer.MAX_VALUE))
.andExpect(status().isNotFound());
}
@Test
public void putSubscriptionUnauthorizedTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
@@ -384,6 +571,8 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context, Subscription subscription = SubscribeBuilder.subscribeBuilder(context,
"TestType", publicItem, admin, subscriptionParameterList).build(); "TestType", publicItem, admin, subscriptionParameterList).build();
context.restoreAuthSystemState();
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> newSubscription = new HashMap<>(); Map<String, Object> newSubscription = new HashMap<>();
newSubscription.put("type", "test"); newSubscription.put("type", "test");
@@ -393,7 +582,6 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
sub_list.put("value", "daily"); sub_list.put("value", "daily");
list.add(sub_list); list.add(sub_list);
newSubscription.put("subscriptionParameterList", list); newSubscription.put("subscriptionParameterList", list);
context.restoreAuthSystemState();
getClient().perform(put("/api/core/subscriptions/" + subscription.getID()) getClient().perform(put("/api/core/subscriptions/" + subscription.getID())
.param("dspace_object_id", publicItem.getID().toString()) .param("dspace_object_id", publicItem.getID().toString())
@@ -404,44 +592,38 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
} }
@Test @Test
//TODO public void putSubscriptionForbiddenTest() throws Exception {
public void editSubscriptionNotAsSubscriberNotAsAdmin() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
EPerson epersonIT = EPersonBuilder.createEPerson(context)
.withEmail("epersonIT@example.com")
.withPassword(password)
.withLanguage("al")
.build();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("Parameter1"); subscriptionParameter.setName("Parameter1");
subscriptionParameter.setValue("ValueParameter1"); subscriptionParameter.setValue("ValueParameter1");
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context, Subscription subscription = SubscribeBuilder.subscribeBuilder(context,
"TestType", publicItem, eperson, subscriptionParameterList).build(); "TestType", publicItem, admin, subscriptionParameterList).build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> newSubscription = new HashMap<>(); Map<String, Object> newSubscription = new HashMap<>();
newSubscription.put("type", "test"); newSubscription.put("type", "test");
List<Map<String, Object>> list = new ArrayList<>(); List<Map<String, Object>> list = new ArrayList<>();
Map<String, Object> sub_list = new HashMap<>(); Map<String, Object> sub_list = new HashMap<>();
sub_list.put("name", "frequency"); sub_list.put("name", "Frequency");
sub_list.put("value", "daily"); sub_list.put("value", "Daily");
list.add(sub_list); list.add(sub_list);
newSubscription.put("subscriptionParameterList", list); newSubscription.put("subscriptionParameterList", list);
String token = getAuthToken(epersonIT.getEmail(), password); String token = getAuthToken(eperson.getEmail(), password);
getClient(token).perform(put("/api/core/subscriptions/" + subscription.getID()) getClient(token).perform(put("/api/core/subscriptions/" + subscription.getID())
.param("dspace_object_id", publicItem.getID().toString())
.param("eperson_id", admin.getID().toString()) .param("eperson_id", admin.getID().toString())
.param("dspace_object_id", publicItem.getID().toString())
.content(objectMapper.writeValueAsString(newSubscription)) .content(objectMapper.writeValueAsString(newSubscription))
.contentType(MediaType.APPLICATION_JSON_VALUE)) .contentType(MediaType.APPLICATION_JSON_VALUE))
//The status has to be 500 Error .andExpect(status().isForbidden());
.andExpect(status().isInternalServerError());
} }
@Test @Test
public void editSubscriptionAsAdministratorOrSubscriber() throws Exception { public void putSubscriptionTest() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
@@ -449,15 +631,16 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
subscriptionParameter.setValue("Daily"); subscriptionParameter.setValue("Daily");
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context, Subscription subscription = SubscribeBuilder.subscribeBuilder(context,
"TestType", publicItem, eperson, subscriptionParameterList).build(); "TestType", publicItem, eperson, subscriptionParameterList).build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> newSubscription = new HashMap<>(); Map<String, Object> newSubscription = new HashMap<>();
newSubscription.put("type", "test"); newSubscription.put("type", "test");
List<Map<String, Object>> list = new ArrayList<>(); List<Map<String, Object>> list = new ArrayList<>();
Map<String, Object> sub_list = new HashMap<>(); Map<String, Object> sub_list = new HashMap<>();
sub_list.put("name", "frequency"); sub_list.put("name", "Frequency");
sub_list.put("value", "daily"); sub_list.put("value", "WEEKLY");
list.add(sub_list); list.add(sub_list);
newSubscription.put("subscriptionParameterList", list); newSubscription.put("subscriptionParameterList", list);
@@ -467,206 +650,50 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
.param("eperson_id", eperson.getID().toString()) .param("eperson_id", eperson.getID().toString())
.content(objectMapper.writeValueAsString(newSubscription)) .content(objectMapper.writeValueAsString(newSubscription))
.contentType(MediaType.APPLICATION_JSON_VALUE)) .contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk()) .andExpect(status().isOk())
//We expect the content type to be "application/hal+json;charset=UTF-8" .andExpect(content().contentType(contentType))
.andExpect(content().contentType(contentType)) .andExpect(jsonPath("$.subscriptionType", is("test")))
//By default we expect at least 1 submission forms so this to be reflected in the page object .andExpect(jsonPath("$.subscriptionParameterList[0].name", is("Frequency")))
.andExpect(jsonPath("$.subscriptionType", is("test"))) .andExpect(jsonPath("$.subscriptionParameterList[0].value", is("WEEKLY")))
.andExpect(jsonPath("$.subscriptionParameterList[0].name", is("frequency"))) .andExpect(jsonPath("$._links.ePerson.href", Matchers.endsWith("/ePerson")))
.andExpect(jsonPath("$.subscriptionParameterList[0].value", is("daily"))) .andExpect(jsonPath("$._links.dSpaceObject.href",Matchers.endsWith("/dSpaceObject")));
.andExpect(jsonPath("$._links.self.href", Matchers.startsWith(REST_SERVER_URL + "core/subscriptions")))
.andExpect(jsonPath("$._links.dSpaceObject.href",
Matchers.startsWith(REST_SERVER_URL + "core/subscriptions")))
.andExpect(jsonPath("$._links.dSpaceObject.href", Matchers.endsWith("/dSpaceObject")))
.andExpect(jsonPath("$._links.ePerson.href",
Matchers.startsWith(REST_SERVER_URL + "core/subscriptions")))
.andExpect(jsonPath("$._links.ePerson.href", Matchers.endsWith("/ePerson")));
} }
@Test @Test
public void deleteSubscriptionNotAsSubscriberNotAsAdmin() throws Exception { public void putSubscriptionAdminTest() throws Exception {
context.turnOffAuthorisationSystem();
EPerson epersonIT = EPersonBuilder.createEPerson(context)
.withEmail("epersonIT@example.com")
.withPassword(password)
.withLanguage("al")
.build();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("Frequency");
subscriptionParameter.setValue("Daily");
subscriptionParameterList.add(subscriptionParameter);
SubscribeBuilder.subscribeBuilder(context, "Test", publicItem, eperson, subscriptionParameterList).build();
context.restoreAuthSystemState();
String epersonITtoken = getAuthToken(epersonIT.getEmail(), password);
getClient(epersonITtoken).perform(put("/api/core/subscriptions"))
.andExpect(status().isUnauthorized());
}
@Test
public void deleteSubscriptionAsAdmin() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("Frequency"); subscriptionParameter.setName("Frequency");
subscriptionParameter.setValue("Daily"); subscriptionParameter.setValue("Daily");
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
SubscribeBuilder.subscribeBuilder(context, "Test", publicItem, eperson, subscriptionParameterList).build(); Subscription subscription = SubscribeBuilder.subscribeBuilder(context,
"TestType", publicItem, eperson, subscriptionParameterList).build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
ObjectMapper objectMapper = new ObjectMapper();
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", "WEEKLY");
list.add(sub_list);
newSubscription.put("subscriptionParameterList", list);
String tokenAdmin = getAuthToken(admin.getEmail(), password); String tokenAdmin = getAuthToken(admin.getEmail(), password);
getClient(tokenAdmin).perform(put("/api/core/subscriptions")) getClient(tokenAdmin).perform(put("/api/core/subscriptions/" + subscription.getID())
.andExpect(status().isOk()); .param("dspace_object_id", publicItem.getID().toString())
.param("eperson_id", eperson.getID().toString())
.content(objectMapper.writeValueAsString(newSubscription))
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$.subscriptionType", is("test")))
.andExpect(jsonPath("$.subscriptionParameterList[0].name", is("Frequency")))
.andExpect(jsonPath("$.subscriptionParameterList[0].value", is("WEEKLY")))
.andExpect(jsonPath("$._links.ePerson.href", Matchers.endsWith("/ePerson")))
.andExpect(jsonPath("$._links.dSpaceObject.href", Matchers.endsWith("/dSpaceObject")));
} }
@Test }
public void patchReplaceSubscriptionParameterAsAdmin() throws Exception {
context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("TestName");
subscriptionParameter.setValue("TestValue");
subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context,
"Test", publicItem, eperson, subscriptionParameterList).build();
List<Operation> ops = new ArrayList<Operation>();
Map<String, String> value = new HashMap<>();
value.put("name", "frequency");
value.put("value", "monthly");
ReplaceOperation replaceOperation = new ReplaceOperation("/subscriptionsParameter/"
+ subscription.getSubscriptionParameterList().get(0).getId(), value);
ops.add(replaceOperation);
String patchBody = getPatchContent(ops);
context.restoreAuthSystemState();
String tokenAdmin = getAuthToken(admin.getEmail(), password);
getClient(tokenAdmin).perform(patch("/api/core/subscriptions/" + subscription.getID())
.content(patchBody))
.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("$.type", is("Test")))
.andExpect(jsonPath("$.id", Matchers.endsWith(REST_SERVER_URL + "/api/core/dSpaceObject")))
.andExpect(jsonPath("$.subscriptionParameterList[0].name", is("frequency")))
.andExpect(jsonPath("$.subscriptionParameterList[0].value", is("monthly")))
.andExpect(jsonPath("$._links.self.href",
Matchers.startsWith(REST_SERVER_URL + "/api/core/subscriptions")))
.andExpect(jsonPath("$._links.dSpaceObject.href",
Matchers.startsWith(REST_SERVER_URL + "/api/core/subscriptions")))
.andExpect(jsonPath("$._links.dSpaceObject.href",
Matchers.endsWith(REST_SERVER_URL + "/api/core/dSpaceObject")))
.andExpect(jsonPath("$._links.ePerson.href",
Matchers.startsWith(REST_SERVER_URL + "/api/core/subscriptions")))
.andExpect(jsonPath("$._links.ePerson.href", Matchers.endsWith(REST_SERVER_URL + "/api/core/ePerson")));
}
@Test
public void patchSubscriptionParameterNotAsAdminNotAsSubscriber() throws Exception {
context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("TestName");
subscriptionParameter.setValue("TestValue");
subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context,
"Test", publicItem, eperson, subscriptionParameterList).build();
List<Operation> ops = new ArrayList<Operation>();
Map<String, String> value = new HashMap<>();
value.put("name", "frequency");
value.put("value", "monthly");
ReplaceOperation replaceOperation = new ReplaceOperation("/subscriptionsParameter/"
+ subscription.getSubscriptionParameterList().get(0).getId(), value);
ops.add(replaceOperation);
String patchBody = getPatchContent(ops);
EPerson epersonIT = EPersonBuilder.createEPerson(context)
.withEmail("epersonIT@example.com")
.withPassword(password)
.withLanguage("al")
.build();
context.restoreAuthSystemState();
String epersonITtoken = getAuthToken(epersonIT.getEmail(), password);
getClient(epersonITtoken).perform(patch("/api/core/subscriptions/" + subscription.getID())
.content(patchBody))
.andExpect(status().isForbidden());
}
@Test
public void patchAddSubscriptionParameter() throws Exception {
context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("TestName");
subscriptionParameter.setValue("TestValue");
subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context,
"Test", publicItem, eperson, subscriptionParameterList).build();
String token = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>();
Map<String, String> value = new HashMap<>();
value.put("name", "frequency");
value.put("value", "monthly");
AddOperation addOperation = new AddOperation("/subscriptionsParameter/"
+ subscription.getSubscriptionParameterList().get(0).getId(), value);
ops.add(addOperation);
String patchBody = getPatchContent(ops);
getClient(token).perform(patch("/api/core/subscriptions/" + subscription.getID())
.content(patchBody))
.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("$.type", is("Test")))
.andExpect(jsonPath("$.id", Matchers.endsWith(REST_SERVER_URL + "/api/core/dSpaceObject")))
.andExpect(jsonPath("$.subscriptionParameterList[0].name", is("TestName")))
.andExpect(jsonPath("$.subscriptionParameterList[0].value", is("TestValue")))
.andExpect(jsonPath("$.subscriptionParameterList[1].name", is("frequency")))
.andExpect(jsonPath("$.subscriptionParameterList[1].value", is("monthly")))
.andExpect(jsonPath("$._links.self.href",
Matchers.startsWith(REST_SERVER_URL + "/api/core/subscriptions")))
.andExpect(jsonPath("$._links.dSpaceObject.href",
Matchers.startsWith(REST_SERVER_URL + "/api/core/subscriptions")))
.andExpect(jsonPath("$._links.dSpaceObject.href",
Matchers.endsWith(REST_SERVER_URL + "/api/core/dSpaceObject")))
.andExpect(jsonPath("$._links.ePerson.href",
Matchers.startsWith(REST_SERVER_URL + "/api/core/subscriptions")))
.andExpect(jsonPath("$._links.ePerson.href", Matchers.endsWith(REST_SERVER_URL + "/api/core/ePerson")));
}
@Test
public void patchRemoveSubscriptionParameter() throws Exception {
context.turnOffAuthorisationSystem();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("TestName");
subscriptionParameter.setValue("TestValue");
subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context,
"Test", publicItem, eperson, subscriptionParameterList).build();
List<Operation> ops = new ArrayList<Operation>();
Map<String, String> value = new HashMap<>();
value.put("name", "frequency");
value.put("value", "monthly");
RemoveOperation removeOperation = new RemoveOperation("/subscriptionsParameter/"
+ subscription.getSubscriptionParameterList().get(0).getId());
ops.add(removeOperation);
String patchBody = getPatchContent(ops);
context.restoreAuthSystemState();
String token = getAuthToken(admin.getEmail(), password);
getClient(token).perform(patch("/api/core/subscriptions/" + subscription.getID())
.content(patchBody))
.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("$.type", is("Test")))
.andExpect(jsonPath("$.id", Matchers.endsWith(REST_SERVER_URL + "/api/core/dSpaceObject")))
.andExpect(jsonPath("$.subscriptionParameterList", Matchers.arrayWithSize(0)))
.andExpect(jsonPath("$._links.self.href",
Matchers.startsWith(REST_SERVER_URL + "/api/core/subscriptions")));
}
}

View File

@@ -0,0 +1,57 @@
package org.dspace.app.rest.matcher;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static org.dspace.app.rest.test.AbstractControllerIntegrationTest.REST_SERVER_URL;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.is;
import java.util.stream.Collectors;
import org.dspace.eperson.Subscription;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
/**
* Provide convenient org.hamcrest.Matcher to verify a SubscriptionRest json response
*
* @author Mykhaylo Boychuk (mykhaylo.boychuk at 4science.it)
*/
public class SubscriptionMatcher {
private SubscriptionMatcher() {}
public static Matcher<? super Object> matchSubscription(Subscription subscription) {
return allOf(
hasJsonPath("$.id", is(subscription.getID())),
hasJsonPath("$.type", is("subscription")),
hasJsonPath("$.subscriptionType", is(subscription.getType())),
hasJsonPath("$.subscriptionParameterList", Matchers.containsInAnyOrder(
subscription.getSubscriptionParameterList().stream()
.map(x -> SubscriptionMatcher.matchSubscriptionParameter(x.getID(), x.getName(), x.getValue()))
.collect(Collectors.toList())
)),
//Check links
matchLinks(subscription.getID())
);
}
public static Matcher<? super Object> matchSubscriptionParameter(int id, String name, String value) {
return allOf(
hasJsonPath("$.id", is(id)),
hasJsonPath("$.name", is(name)),
hasJsonPath("$.value", is(value))
);
}
/**
* Gets a matcher for all expected links.
*/
public static Matcher<? super Object> matchLinks(Integer id) {
return HalMatcher.matchLinks(REST_SERVER_URL + "core/subscriptions/" + id,
"dSpaceObject",
"ePerson",
"self"
);
}
}