[DSC-183] Fix checkstyle and refactor

This commit is contained in:
Mykhaylo
2022-12-01 18:51:24 +01:00
parent bdb4bd53dc
commit 141cde9899
19 changed files with 295 additions and 406 deletions

View File

@@ -2,11 +2,14 @@
* The contents of this file are subject to the license and copyright * The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source * detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at * tree and available online at
* <p> *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
package org.dspace.eperson; package org.dspace.eperson;
import java.sql.SQLException;
import java.util.List;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context; import org.dspace.core.Context;
@@ -14,8 +17,6 @@ import org.dspace.eperson.dao.SubscriptionParameterDAO;
import org.dspace.eperson.service.SubscriptionParameterService; import org.dspace.eperson.service.SubscriptionParameterService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.sql.SQLException;
import java.util.List;
/** /**
* Class implemennting method for service layer of SubscriptionParameter entity * Class implemennting method for service layer of SubscriptionParameter entity
@@ -42,16 +43,20 @@ public class SubscribeParameterServiceImpl implements SubscriptionParameterServi
} }
@Override @Override
public SubscriptionParameter add(Context context, String name, String value, Subscription subscription) throws SQLException, AuthorizeException { public SubscriptionParameter add(Context context, String name, String value,
SubscriptionParameter subscriptionParameter = subscriptionParameterDAO.create(context, new SubscriptionParameter()); Subscription subscription) throws SQLException, AuthorizeException {
SubscriptionParameter subscriptionParameter =
subscriptionParameterDAO.create(context, new SubscriptionParameter());
subscriptionParameter.setName(name); subscriptionParameter.setName(name);
subscriptionParameter.setSubscription(subscription); subscriptionParameter.setSubscription(subscription);
subscriptionParameter.setValue(value); subscriptionParameter.setValue(value);
return subscriptionParameter; return subscriptionParameter;
} }
@Override @Override
public SubscriptionParameter edit(Context context,Integer id,String value, String name, Subscription subscription) throws SQLException, AuthorizeException { public SubscriptionParameter edit(Context context,Integer id,String value,
SubscriptionParameter subscriptionParameter = subscriptionParameterDAO.findByID(context, SubscriptionParameter.class, id); String name, Subscription subscription) throws SQLException, AuthorizeException {
SubscriptionParameter subscriptionParameter =
subscriptionParameterDAO.findByID(context, SubscriptionParameter.class, id);
subscriptionParameter.setId(id); subscriptionParameter.setId(id);
subscriptionParameter.setName(name); subscriptionParameter.setName(name);
subscriptionParameter.setSubscription(subscription); subscriptionParameter.setSubscription(subscription);
@@ -67,7 +72,8 @@ public class SubscribeParameterServiceImpl implements SubscriptionParameterServi
@Override @Override
public void deleteSubscriptionParameter(Context context, Integer id) throws SQLException, AuthorizeException { public void deleteSubscriptionParameter(Context context, Integer id) throws SQLException, AuthorizeException {
SubscriptionParameter subscriptionParameter = subscriptionParameterDAO.findByID(context, SubscriptionParameter.class, id); SubscriptionParameter subscriptionParameter =
subscriptionParameterDAO.findByID(context, SubscriptionParameter.class, id);
if (subscriptionParameter != null) { if (subscriptionParameter != null) {
subscriptionParameter.setSubscription(null); subscriptionParameter.setSubscription(null);
subscriptionParameterDAO.delete(context, subscriptionParameter); subscriptionParameterDAO.delete(context, subscriptionParameter);

View File

@@ -2,7 +2,6 @@
* The contents of this file are subject to the license and copyright * The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source * detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at * tree and available online at
* <p>
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
package org.dspace.eperson; package org.dspace.eperson;
@@ -61,8 +60,8 @@ public class SubscribeServiceImpl implements SubscribeService {
|| ((context.getCurrentUser() != null) && (context || ((context.getCurrentUser() != null) && (context
.getCurrentUser().getID().equals(eperson.getID())))) { .getCurrentUser().getID().equals(eperson.getID())))) {
Subscription new_subscription = subscriptionDAO.create(context, new Subscription()); Subscription new_subscription = subscriptionDAO.create(context, new Subscription());
subscriptionParameterList.forEach(subscriptionParameter -> new_subscription.addParameter(subscriptionParameter)); subscriptionParameterList.forEach(subscriptionParameter ->
// new_subscription.setSubscriptionParameterList(subscriptionParameterList); new_subscription.addParameter(subscriptionParameter));
new_subscription.setePerson(eperson); new_subscription.setePerson(eperson);
new_subscription.setdSpaceObject(dSpaceObject); new_subscription.setdSpaceObject(dSpaceObject);
new_subscription.setType(type); new_subscription.setType(type);
@@ -75,20 +74,20 @@ public class SubscribeServiceImpl implements SubscribeService {
@Override @Override
public void unsubscribe(Context context, EPerson eperson, public void unsubscribe(Context context, EPerson eperson,
Collection collection) throws SQLException, AuthorizeException { DSpaceObject dSpaceObject) throws SQLException, AuthorizeException {
// Check authorisation. Must be administrator, or the eperson. // Check authorisation. Must be administrator, or the eperson.
if (authorizeService.isAdmin(context) if (authorizeService.isAdmin(context)
|| ((context.getCurrentUser() != null) && (context || ((context.getCurrentUser() != null) && (context
.getCurrentUser().getID().equals(eperson.getID())))) { .getCurrentUser().getID().equals(eperson.getID())))) {
if (collection == null) { if (dSpaceObject == null) {
// Unsubscribe from all // Unsubscribe from all
subscriptionDAO.deleteByEPerson(context, eperson); subscriptionDAO.deleteByEPerson(context, eperson);
} else { } else {
subscriptionDAO.deleteByCollectionAndEPerson(context, collection, eperson); subscriptionDAO.deleteByDSOAndEPerson(context, dSpaceObject, eperson);
log.info(LogHelper.getHeader(context, "unsubscribe", log.info(LogManager.getHeader(context, "unsubscribe",
"eperson_id=" + eperson.getID() + ",collection_id=" "eperson_id=" + eperson.getID() + ",collection_id="
+ collection.getID())); + dSpaceObject.getID()));
} }
} else { } else {
throw new AuthorizeException( throw new AuthorizeException(
@@ -103,7 +102,8 @@ public class SubscribeServiceImpl implements SubscribeService {
} }
@Override @Override
public List<Subscription> getSubscriptionsByEPersonAndDso(Context context, EPerson eperson, DSpaceObject dSpaceObject) public List<Subscription> getSubscriptionsByEPersonAndDso(Context context,
EPerson eperson, DSpaceObject dSpaceObject)
throws SQLException { throws SQLException {
return subscriptionDAO.findByEPerson(context, eperson); return subscriptionDAO.findByEPerson(context, eperson);
} }
@@ -159,7 +159,8 @@ public class SubscribeServiceImpl implements SubscribeService {
subscriptionDB.removeParameterList(); subscriptionDB.removeParameterList();
subscriptionDB.setType(type); subscriptionDB.setType(type);
subscriptionDB.setdSpaceObject(dSpaceObject); subscriptionDB.setdSpaceObject(dSpaceObject);
subscriptionParameterList.forEach(subscriptionParameter -> subscriptionDB.addParameter(subscriptionParameter)); subscriptionParameterList.forEach(subscriptionParameter ->
subscriptionDB.addParameter(subscriptionParameter));
subscriptionDB.setePerson(eperson); subscriptionDB.setePerson(eperson);
subscriptionDAO.save(context, subscriptionDB); subscriptionDAO.save(context, subscriptionDB);
return subscriptionDB; return subscriptionDB;
@@ -169,10 +170,12 @@ public class SubscribeServiceImpl implements SubscribeService {
} }
@Override @Override
public Subscription addSubscriptionParameter(Context context, Integer id, SubscriptionParameter subscriptionParameter) throws SQLException, AuthorizeException { public Subscription addSubscriptionParameter(Context context, Integer id,
SubscriptionParameter subscriptionParameter) throws SQLException, AuthorizeException {
// must be admin or the subscriber of the subscription // 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.getePerson().equals(context.getCurrentUser())) { if (authorizeService.isAdmin(context, context.getCurrentUser())
|| subscriptionDB.getePerson().equals(context.getCurrentUser())) {
subscriptionDB.addParameter(subscriptionParameter); subscriptionDB.addParameter(subscriptionParameter);
subscriptionDAO.save(context, subscriptionDB); subscriptionDAO.save(context, subscriptionDB);
return subscriptionDB; return subscriptionDB;
@@ -182,10 +185,12 @@ public class SubscribeServiceImpl implements SubscribeService {
} }
@Override @Override
public Subscription removeSubscriptionParameter(Context context, Integer id, SubscriptionParameter subscriptionParameter) throws SQLException, AuthorizeException { public Subscription removeSubscriptionParameter(Context context, Integer id,
SubscriptionParameter subscriptionParameter) throws SQLException, AuthorizeException {
// must be admin or the subscriber of the subscription // 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.getePerson().equals(context.getCurrentUser())) { if (authorizeService.isAdmin(context, context.getCurrentUser())
|| subscriptionDB.getePerson().equals(context.getCurrentUser())) {
subscriptionDB.removeParameter(subscriptionParameter); subscriptionDB.removeParameter(subscriptionParameter);
subscriptionDAO.save(context, subscriptionDB); subscriptionDAO.save(context, subscriptionDB);
return subscriptionDB; return subscriptionDB;
@@ -200,8 +205,14 @@ public class SubscribeServiceImpl implements SubscribeService {
Subscription subscription = subscriptionDAO.findByID(context, Subscription.class, id); Subscription subscription = subscriptionDAO.findByID(context, Subscription.class, id);
if (subscription != null) { if (subscription != null) {
// must be admin or the subscriber of the subscription // must be admin or the subscriber of the subscription
if (authorizeService.isAdmin(context, context.getCurrentUser()) || subscription.getePerson().equals(context.getCurrentUser())) { if (authorizeService.isAdmin(context, context.getCurrentUser())
|| subscription.getePerson().equals(context.getCurrentUser())) {
try {
subscriptionDAO.delete(context, subscription); subscriptionDAO.delete(context, subscription);
} catch (SQLException sqlException) {
throw new SQLException(sqlException);
}
} else { } else {
throw new AuthorizeException("Only admin or e-person themselves can delete the subscription"); throw new AuthorizeException("Only admin or e-person themselves can delete the subscription");
} }

View File

@@ -7,6 +7,8 @@
*/ */
package org.dspace.eperson; package org.dspace.eperson;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
@@ -17,17 +19,14 @@ import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.SequenceGenerator; import javax.persistence.SequenceGenerator;
import javax.persistence.Table; import javax.persistence.Table;
import org.dspace.content.Collection;
import org.dspace.content.DSpaceObject; import org.dspace.content.DSpaceObject;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.ReloadableEntity; import org.dspace.core.ReloadableEntity;
import java.util.ArrayList;
import java.util.List;
/** /**
* Database entity representation of the subscription table * Database entity representation of the subscription table

View File

@@ -9,7 +9,6 @@ package org.dspace.eperson;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
@@ -31,8 +30,9 @@ import javax.persistence.Table;
public class SubscriptionParameter { public class SubscriptionParameter {
@Id @Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "subscription_parameter_seq") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "subscription_parameter_seq")
@SequenceGenerator(name = "subscription_parameter_seq", sequenceName = "subscription_parameter_seq", allocationSize = 1) @SequenceGenerator(name = "subscription_parameter_seq",
@Column(name = "subscription_parameter_id", unique = true, nullable = false, insertable = true) sequenceName = "subscription_parameter_seq", allocationSize = 1)
@Column(name = "subscription_parameter_id", unique = true)
private Integer id; private Integer id;
@ManyToOne @ManyToOne
@JoinColumn(name = "subscription_id") @JoinColumn(name = "subscription_id")

View File

@@ -2,7 +2,6 @@
* The contents of this file are subject to the license and copyright * The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source * detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at * tree and available online at
*
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
package org.dspace.eperson.dao; package org.dspace.eperson.dao;
@@ -10,7 +9,6 @@ package org.dspace.eperson.dao;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import org.dspace.content.Collection;
import org.dspace.content.DSpaceObject; import org.dspace.content.DSpaceObject;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.GenericDAO; import org.dspace.core.GenericDAO;
@@ -31,11 +29,12 @@ public interface SubscriptionDAO extends GenericDAO<Subscription> {
public List<Subscription> findByEPerson(Context context, EPerson eperson) throws SQLException; public List<Subscription> findByEPerson(Context context, EPerson eperson) throws SQLException;
public List<Subscription> findByEPersonAndDso(Context context, EPerson eperson, DSpaceObject dSpaceObject) throws SQLException; public List<Subscription> findByEPersonAndDso(Context context,
EPerson eperson, DSpaceObject dSpaceObject) throws SQLException;
public void deleteByEPerson(Context context, EPerson eperson) throws SQLException; public void deleteByEPerson(Context context, EPerson eperson) throws SQLException;
public void deleteByCollectionAndEPerson(Context context, Collection collection, EPerson eperson) public void deleteByDSOAndEPerson(Context context, DSpaceObject dSpaceObject, EPerson eperson)
throws SQLException; throws SQLException;
public List<Subscription> findAllOrderedByEPerson(Context context) throws SQLException; public List<Subscription> findAllOrderedByEPerson(Context context) throws SQLException;

View File

@@ -6,10 +6,10 @@
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
package org.dspace.eperson.dao; package org.dspace.eperson.dao;
import org.dspace.core.GenericDAO; import org.dspace.core.GenericDAO;
import org.dspace.eperson.SubscriptionParameter; import org.dspace.eperson.SubscriptionParameter;
/** /**
* Database Access Object interface class for the SubscriptionParamter object. * Database Access Object interface class for the SubscriptionParamter object.
* The implementation of this class is responsible for all database calls for the SubscriptionParameter object and is * The implementation of this class is responsible for all database calls for the SubscriptionParameter object and is

View File

@@ -15,7 +15,6 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import org.dspace.content.Collection;
import org.dspace.content.DSpaceObject; import org.dspace.content.DSpaceObject;
import org.dspace.core.AbstractHibernateDAO; import org.dspace.core.AbstractHibernateDAO;
import org.dspace.core.Context; import org.dspace.core.Context;
@@ -47,14 +46,17 @@ public class SubscriptionDAOImpl extends AbstractHibernateDAO<Subscription> impl
} }
@Override @Override
public List<Subscription> findByEPersonAndDso(Context context, EPerson eperson, DSpaceObject dSpaceObject) throws SQLException { public List<Subscription> findByEPersonAndDso(Context context, EPerson eperson,
DSpaceObject dSpaceObject) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context); CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
javax.persistence.criteria.CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Subscription.class); javax.persistence.criteria.CriteriaQuery criteriaQuery =
getCriteriaQuery(criteriaBuilder, Subscription.class);
Root<Subscription> subscriptionRoot = criteriaQuery.from(Subscription.class); Root<Subscription> subscriptionRoot = criteriaQuery.from(Subscription.class);
criteriaQuery.select(subscriptionRoot); criteriaQuery.select(subscriptionRoot);
criteriaQuery.where(criteriaBuilder.equal(subscriptionRoot.get(Subscription_.ePerson), eperson)); criteriaQuery.where(criteriaBuilder.equal(subscriptionRoot.get(Subscription_.ePerson), eperson));
criteriaQuery.where(criteriaBuilder.and(criteriaBuilder.equal(subscriptionRoot.get(Subscription_.ePerson), eperson), criteriaQuery.where(criteriaBuilder.and(criteriaBuilder.equal(
subscriptionRoot.get(Subscription_.ePerson), eperson),
criteriaBuilder.equal(subscriptionRoot.get(Subscription_.dSpaceObject), dSpaceObject) criteriaBuilder.equal(subscriptionRoot.get(Subscription_.dSpaceObject), dSpaceObject)
)); ));
return list(context, criteriaQuery, false, Subscription.class, -1, -1); return list(context, criteriaQuery, false, Subscription.class, -1, -1);
@@ -78,11 +80,11 @@ public class SubscriptionDAOImpl extends AbstractHibernateDAO<Subscription> impl
} }
@Override @Override
public void deleteByCollectionAndEPerson(Context context, Collection collection, EPerson eperson) public void deleteByDSOAndEPerson(Context context, DSpaceObject dSpaceObject, EPerson eperson)
throws SQLException { throws SQLException {
String hqlQuery = "delete from Subscription where collection=:collection AND ePerson=:ePerson"; String hqlQuery = "delete from Subscription where dSpaceObject=:dSpaceObject AND ePerson=:ePerson";
Query query = createQuery(context, hqlQuery); Query query = createQuery(context, hqlQuery);
query.setParameter("collection", collection); query.setParameter("dSpaceObject", dSpaceObject);
query.setParameter("ePerson", eperson); query.setParameter("ePerson", eperson);
query.executeUpdate(); query.executeUpdate();
} }

View File

@@ -18,7 +18,8 @@ import org.dspace.eperson.dao.SubscriptionParameterDAO;
* *
* @author Alba Aliu at atis.al * @author Alba Aliu at atis.al
*/ */
public class SubscriptionParameterDAOImpl extends AbstractHibernateDAO<SubscriptionParameter> implements SubscriptionParameterDAO { public class SubscriptionParameterDAOImpl extends AbstractHibernateDAO
<SubscriptionParameter> implements SubscriptionParameterDAO {
protected SubscriptionParameterDAOImpl() { protected SubscriptionParameterDAOImpl() {
super(); super();
} }

View File

@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright * The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source * detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at * tree and available online at
* <p> *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
package org.dspace.eperson.service; package org.dspace.eperson.service;
@@ -50,7 +50,7 @@ public interface SubscribeService {
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;
/** /**
* Unsubscribe an e-person to a collection. Passing in <code>null</code> * Unsubscribe an e-person to a collection. Passing in <code>null</code>
@@ -59,13 +59,13 @@ public interface SubscribeService {
* *
* @param context DSpace context * @param context DSpace context
* @param eperson EPerson to unsubscribe * @param eperson EPerson to unsubscribe
* @param collection Collection to unsubscribe from * @param dSpaceObject DSpaceObject to unsubscribe from
* @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.
* @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 void unsubscribe(Context context, EPerson eperson, public void unsubscribe(Context context, EPerson eperson,
Collection collection) throws SQLException, AuthorizeException; DSpaceObject dSpaceObject) throws SQLException, AuthorizeException;
/** /**
* Find out which collections an e-person is subscribed to * Find out which collections an e-person is subscribed to
@@ -86,7 +86,10 @@ 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, EPerson eperson, DSpaceObject dSpaceObject) throws SQLException; public List<Subscription> getSubscriptionsByEPersonAndDso(Context context,
EPerson eperson,
DSpaceObject dSpaceObject) 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
* *
@@ -171,7 +174,10 @@ public interface SubscribeService {
* @param subscriptionParameter SubscriptionParameter subscriptionParameter * @param subscriptionParameter 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 addSubscriptionParameter(Context context, Integer id, SubscriptionParameter subscriptionParameter) throws SQLException, AuthorizeException; public Subscription addSubscriptionParameter(Context context, Integer id,
SubscriptionParameter subscriptionParameter)
throws SQLException, AuthorizeException;
/** /**
* Deletes a parameter from subscription * Deletes a parameter from subscription
* *
@@ -180,7 +186,8 @@ public interface SubscribeService {
* @param subscriptionParameter SubscriptionParameter subscriptionParameter * @param subscriptionParameter 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, SubscriptionParameter subscriptionParameter) throws SQLException, AuthorizeException; public Subscription removeSubscriptionParameter(Context context, Integer id,
SubscriptionParameter subscriptionParameter) throws SQLException, AuthorizeException;
/** /**
* Deletes a subscription * Deletes a subscription

View File

@@ -7,18 +7,18 @@
*/ */
package org.dspace.eperson.service; package org.dspace.eperson.service;
import java.sql.SQLException;
import java.util.List;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.eperson.Subscription; import org.dspace.eperson.Subscription;
import org.dspace.eperson.SubscriptionParameter; import org.dspace.eperson.SubscriptionParameter;
import java.sql.SQLException;
import java.util.List;
/** /**
* Service interface class for the SubscriptionParameter object. * Service interface class for the SubscriptionParameter object.
* The implementation of this class is responsible for all business logic calls for the SubscriptionParameter object and is * The implementation of this class is responsible for all business logic calls for
* autowired by spring * the SubscriptionParameter object and is autowired by spring
* Class defining methods for sending new item e-mail alerts to users * Class defining methods for sending new item e-mail alerts to users
* *
* @author Alba Aliu @atis.al * @author Alba Aliu @atis.al

View File

@@ -7,6 +7,10 @@
*/ */
package org.dspace.app.rest.converter; package org.dspace.app.rest.converter;
import java.util.ArrayList;
import java.util.List;
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.projection.Projection; import org.dspace.app.rest.projection.Projection;
import org.dspace.app.rest.utils.Utils; import org.dspace.app.rest.utils.Utils;
@@ -24,12 +28,9 @@ import org.springframework.stereotype.Component;
public class SubscriptionConverter implements DSpaceConverter<Subscription, SubscriptionRest> { public class SubscriptionConverter implements DSpaceConverter<Subscription, SubscriptionRest> {
@Autowired @Autowired
protected Utils utils; protected Utils utils;
/* (non-Javadoc)
* @see org.dspace.app.rest.converter.DSpaceConverter#convert
* (java.lang.Object, org.dspace.app.rest.projection.Projection)
*/
@Autowired @Autowired
private ConverterService converter; private ConverterService converter;
@Override @Override
public SubscriptionRest convert(Subscription subscription, Projection projection) { public SubscriptionRest convert(Subscription subscription, Projection projection) {
SubscriptionRest rest = new SubscriptionRest(); SubscriptionRest rest = new SubscriptionRest();

View File

@@ -2,28 +2,23 @@
* The contents of this file are subject to the license and copyright * The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source * detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at * tree and available online at
* <p> *
* 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.app.rest.RestResourceController;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@LinksRest(links = { import org.dspace.app.rest.RestResourceController;
@LinkRest(
name = SubscriptionRest.DSPACE_OBJECT, @LinksRest(links = {@LinkRest(name = SubscriptionRest.DSPACE_OBJECT,
method = "getDSpaceObject" method = "getDSpaceObject"), @LinkRest(
),
@LinkRest(
name = SubscriptionRest.EPERSON, name = SubscriptionRest.EPERSON,
method = "getEPerson" method = "getEPerson")
)
}) })
public class SubscriptionRest extends BaseObjectRest<Integer>{ public class SubscriptionRest extends BaseObjectRest<Integer> {
public static final String NAME = "subscription"; public static final String NAME = "subscription";
public static final String NAME_PLURAL = "subscriptions"; public static final String NAME_PLURAL = "subscriptions";
public static final String CATEGORY = "core"; public static final String CATEGORY = "core";
@@ -60,6 +55,7 @@ public class SubscriptionRest extends BaseObjectRest<Integer>{
public void setSubscriptionParameterList(List<SubscriptionParameter> subscriptionParameterList) { public void setSubscriptionParameterList(List<SubscriptionParameter> subscriptionParameterList) {
this.subscriptionParameterList = subscriptionParameterList; this.subscriptionParameterList = subscriptionParameterList;
} }
public String getSubscriptionType() { public String getSubscriptionType() {
return this.type; return this.type;
} }

View File

@@ -2,15 +2,18 @@
* The contents of this file are subject to the license and copyright * The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source * detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at * tree and available online at
* <p> *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
package org.dspace.app.rest.repository; package org.dspace.app.rest.repository;
import java.sql.SQLException;
import javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest;
import org.dspace.app.rest.model.DSpaceObjectRest; import org.dspace.app.rest.model.DSpaceObjectRest;
import org.dspace.app.rest.model.SubscriptionRest; import org.dspace.app.rest.model.SubscriptionRest;
import org.dspace.app.rest.projection.Projection; import org.dspace.app.rest.projection.Projection;
import org.dspace.content.service.ItemService;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.eperson.Subscription; import org.dspace.eperson.Subscription;
import org.dspace.eperson.service.SubscribeService; import org.dspace.eperson.service.SubscribeService;
@@ -21,10 +24,6 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException; import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;
/** /**
* Link repository for "dataSpaceObject" of subscription * Link repository for "dataSpaceObject" of subscription
*/ */

View File

@@ -7,9 +7,10 @@
*/ */
package org.dspace.app.rest.repository; package org.dspace.app.rest.repository;
import java.sql.SQLException;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;
import org.dspace.app.rest.model.EPersonRest; import org.dspace.app.rest.model.EPersonRest;
import org.dspace.app.rest.model.SubscriptionRest; import org.dspace.app.rest.model.SubscriptionRest;
import org.dspace.app.rest.projection.Projection; import org.dspace.app.rest.projection.Projection;
@@ -21,8 +22,6 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.webmvc.ResourceNotFoundException; import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
* Link repository for "eperson" of subscription * Link repository for "eperson" of subscription
*/ */

View File

@@ -2,11 +2,20 @@
* The contents of this file are subject to the license and copyright * The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source * detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at * tree and available online at
* <p> *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
package org.dspace.app.rest.repository; package org.dspace.app.rest.repository;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
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.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@@ -15,6 +24,9 @@ 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.UnprocessableEntityException; import org.dspace.app.rest.exception.UnprocessableEntityException;
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.repository.patch.ResourcePatch;
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;
import org.dspace.content.DSpaceObject; import org.dspace.content.DSpaceObject;
@@ -43,7 +55,8 @@ import java.util.List;
*/ */
@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 {
private static final Logger log = LogManager.getLogger(); private static final Logger log = LogManager.getLogger();
@Autowired @Autowired
AuthorizeService authorizeService; AuthorizeService authorizeService;
@@ -60,7 +73,7 @@ public class SubscriptionRestRepository extends DSpaceRestRepository<Subscriptio
@Override @Override
@PreAuthorize("hasAuthority('ADMIN')") @PreAuthorize("isAuthenticated()")
public SubscriptionRest findOne(Context context, Integer id) { public SubscriptionRest findOne(Context context, Integer id) {
try { try {
Subscription subscription = subscribeService.findById(context, id); Subscription subscription = subscribeService.findById(context, id);
@@ -89,7 +102,8 @@ public class SubscriptionRestRepository extends DSpaceRestRepository<Subscriptio
try { try {
Context context = obtainContext(); Context context = obtainContext();
EPerson ePerson = personService.findByIdOrLegacyId(context, id); EPerson ePerson = personService.findByIdOrLegacyId(context, id);
if (context.getCurrentUser().equals(ePerson) || authorizeService.isAdmin(context, context.getCurrentUser())) { if (context.getCurrentUser().equals(ePerson)
|| authorizeService.isAdmin(context, context.getCurrentUser())) {
List<Subscription> subscriptionList = subscribeService.getSubscriptionsByEPerson(context, ePerson); List<Subscription> subscriptionList = subscribeService.getSubscriptionsByEPerson(context, ePerson);
return converter.toRestPage(subscriptionList, pageable, utils.obtainProjection()); return converter.toRestPage(subscriptionList, pageable, utils.obtainProjection());
} else { } else {
@@ -113,9 +127,12 @@ public class SubscriptionRestRepository extends DSpaceRestRepository<Subscriptio
if (dsoId == null || epersonId == null) { if (dsoId == null || epersonId == null) {
throw new UnprocessableEntityException("error parsing the body"); throw new UnprocessableEntityException("error parsing the body");
} }
if (context.getCurrentUser().equals(ePerson) || authorizeService.isAdmin(context, context.getCurrentUser())) { if (context.getCurrentUser().equals(ePerson)
List<Subscription> subscriptionList = subscribeService.getSubscriptionsByEPerson(context, ePerson); || authorizeService.isAdmin(context, context.getCurrentUser())) {
return converter.toRestPage(subscriptionList, pageable, utils.obtainProjection()); List<Subscription> subscriptionList =
subscribeService.getSubscriptionsByEPersonAndDso(context, ePerson, dSpaceObject);
return converter.toRestPage(subscriptionList, pageable, subscriptionList.size(),
utils.obtainProjection());
} else { } else {
throw new AuthorizeException("Only admin or e-person themselves can search for it's subscription"); throw new AuthorizeException("Only admin or e-person themselves can search for it's subscription");
} }
@@ -184,9 +201,18 @@ public class SubscriptionRestRepository extends DSpaceRestRepository<Subscriptio
} catch (SQLException e) { } catch (SQLException e) {
throw new ResourceNotFoundException(notFoundException); throw new ResourceNotFoundException(notFoundException);
} }
if (id.equals(subscriptionRest.getId())) { if (id.equals(subscription.getID())) {
subscription = subscribeService.updateSubscription(context, subscriptionRest.getId(), null, List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
null, subscriptionRest.getSubscriptionParameterList(), subscriptionRest.getType()); for (SubscriptionParameterRest subscriptionParameterRest :
subscriptionRest.getSubscriptionParameterList()) {
SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setSubscription(subscription);
subscriptionParameter.setValue(subscriptionParameterRest.getValue());
subscriptionParameter.setName(subscriptionParameterRest.getName());
subscriptionParameterList.add(subscriptionParameter);
}
subscription = subscribeService.updateSubscription(context, id, ePerson,
dSpaceObject, subscriptionParameterList, subscriptionRest.getSubscriptionType());
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: "
@@ -197,8 +223,9 @@ public class SubscriptionRestRepository extends DSpaceRestRepository<Subscriptio
@Override @Override
@PreAuthorize("isAuthenticated()") @PreAuthorize("isAuthenticated()")
public void patch(Context context, HttpServletRequest request, String apiCategory, String model, Integer id, Patch patch) public void patch(Context context, HttpServletRequest request, String apiCategory,
throws UnprocessableEntityException, DSpaceBadRequestException { String model, Integer id, Patch patch)
throws UnprocessableEntityException, DSpaceBadRequestException, AuthorizeException {
Subscription subscription = null; Subscription subscription = null;
try { try {
subscription = subscribeService.findById(context, id); subscription = subscribeService.findById(context, id);

View File

@@ -2,11 +2,13 @@
* The contents of this file are subject to the license and copyright * The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source * detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at * tree and available online at
* <p> *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
package org.dspace.app.rest.repository.patch.operation; package org.dspace.app.rest.repository.patch.operation;
import java.sql.SQLException;
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.exception.DSpaceBadRequestException; import org.dspace.app.rest.exception.DSpaceBadRequestException;
@@ -21,7 +23,7 @@ import org.dspace.eperson.service.SubscribeService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.sql.SQLException;
/** /**
* Implementation for SubscriptionParameterAddOperation patches. * Implementation for SubscriptionParameterAddOperation patches.
@@ -50,7 +52,8 @@ public class SubscriptionParameterAddOperation extends PatchOperation<Subscripti
} else { } else {
value = objectMapper.readTree((String) operation.getValue()); value = objectMapper.readTree((String) operation.getValue());
} }
SubscriptionParameterRest subscriptionParameterRest = objectMapper.readValue(value.toString(), SubscriptionParameterRest.class); SubscriptionParameterRest subscriptionParameterRest =
objectMapper.readValue(value.toString(), SubscriptionParameterRest.class);
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setSubscription(subscription); subscriptionParameter.setSubscription(subscription);
subscriptionParameter.setValue(subscriptionParameterRest.getValue()); subscriptionParameter.setValue(subscriptionParameterRest.getValue());

View File

@@ -2,11 +2,12 @@
* The contents of this file are subject to the license and copyright * The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source * detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at * tree and available online at
* <p> *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
package org.dspace.app.rest.repository.patch.operation; 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.DSpaceBadRequestException;
import org.dspace.app.rest.exception.RESTAuthorizationException; import org.dspace.app.rest.exception.RESTAuthorizationException;
@@ -20,8 +21,6 @@ import org.dspace.eperson.service.SubscriptionParameterService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.sql.SQLException;
/** /**
* Implementation for SubscriptionParameterRemoveOperation patches. * Implementation for SubscriptionParameterRemoveOperation patches.
* <p> * <p>

View File

@@ -2,11 +2,13 @@
* The contents of this file are subject to the license and copyright * The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source * detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at * tree and available online at
* <p> *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
package org.dspace.app.rest.repository.patch.operation; package org.dspace.app.rest.repository.patch.operation;
import java.sql.SQLException;
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.exception.DSpaceBadRequestException; import org.dspace.app.rest.exception.DSpaceBadRequestException;
@@ -22,9 +24,6 @@ import org.dspace.eperson.service.SubscriptionParameterService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.sql.SQLException;
/** /**
* Implementation for SubscriptionParameterReplaceOperation patches. * Implementation for SubscriptionParameterReplaceOperation patches.
* <p> * <p>
@@ -54,9 +53,11 @@ public class SubscriptionParameterReplaceOperation extends PatchOperation<Subscr
} else { } else {
value = objectMapper.readTree((String) operation.getValue()); value = objectMapper.readTree((String) operation.getValue());
} }
SubscriptionParameterRest subscriptionParameterRest = objectMapper.readValue(value.toString(), SubscriptionParameterRest.class); SubscriptionParameterRest subscriptionParameterRest = objectMapper.readValue(
value.toString(), SubscriptionParameterRest.class);
try { try {
SubscriptionParameter subscriptionParameter = subscriptionParameterService.edit(context, subscriptionParameterId, subscriptionParameterRest.getValue(), SubscriptionParameter subscriptionParameter = subscriptionParameterService.edit(context,
subscriptionParameterId, subscriptionParameterRest.getValue(),
subscriptionParameterRest.getName(), subscriptionParameterRest.getName(),
subscription); subscription);
} catch (SQLException | AuthorizeException exception) { } catch (SQLException | AuthorizeException exception) {

View File

@@ -2,7 +2,7 @@
* The contents of this file are subject to the license and copyright * The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source * detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at * tree and available online at
* <p> *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
package org.dspace.app.rest; package org.dspace.app.rest;
@@ -27,10 +27,10 @@ import org.dspace.content.service.SiteService;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import org.dspace.eperson.Subscription; import org.dspace.eperson.Subscription;
import org.dspace.eperson.SubscriptionParameter; import org.dspace.eperson.SubscriptionParameter;
import org.dspace.eperson.service.SubscribeService;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
@@ -41,7 +41,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
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.patch;
@@ -56,21 +55,29 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
* (Class has to start or end with IT to be picked up by the failsafe plugin) * (Class has to start or end with IT to be picked up by the failsafe plugin)
*/ */
public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationTest { public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationTest {
private Collection collection;
@Autowired private Item publicItem;
SubscribeService subscribeService;
@Override @Override
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
// We turn off the authorization system in order to create the structure as context.turnOffAuthorisationSystem();
// defined below parentCommunity = CommunityBuilder.createCommunity(context)
// context.turnOffAuthorisationSystem(); .withName("Parent Community")
// parentCommunity = CommunityBuilder.createCommunity(context).withName("Parent Community").build(); .build();
// colPeople = CollectionBuilder.createCollection(context, parentCommunity).withName("People") Community community = CommunityBuilder.createSubCommunity(context, parentCommunity)
// .withEntityType("Person").build(); .withName("Sub Community")
// context.restoreAuthSystemState(); .build();
collection = CollectionBuilder.createCollection(context, community).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
publicItem = ItemBuilder.createItem(context, collection)
.withTitle("Test")
.withIssueDate("2010-10-17")
.withAuthor("Smith, Donald")
.withSubject("ExtraEntry")
.build();
context.restoreAuthSystemState();
} }
@Test @Test
@@ -80,28 +87,13 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
getClient().perform(get("/api/core/subscriptions")) getClient().perform(get("/api/core/subscriptions"))
//The status has to be 401 Not Authorized //The status has to be 401 Not Authorized
.andExpect(status().isUnauthorized()); .andExpect(status().isUnauthorized());
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Test")
.withIssueDate("2010-10-17")
.withAuthor("Smith, Donald")
.withSubject("ExtraEntry")
.build();
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 = subscribeService.subscribe(context, admin, publicItem1, subscriptionParameterList, "TypeTest"); Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "TypeTest", publicItem, admin, subscriptionParameterList).build();
subscriptionParameter.setSubscription(subscription); subscriptionParameter.setSubscription(subscription);
//When we call the root endpoint //When we call the root endpoint
context.restoreAuthSystemState(); context.restoreAuthSystemState();
@@ -127,33 +119,18 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
@Test @Test
public void findByIdAsAdministrator() throws Exception { public void findByIdAsAdministrator() throws Exception {
context.turnOffAuthorisationSystem();
//When we call the root endpoint as anonymous user //When we call the root endpoint as anonymous user
getClient().perform(get("/api/core/subscriptions")) getClient().perform(get("/api/core/subscriptions"))
//The status has to be 403 Not Authorized //The status has to be 403 Not Authorized
.andExpect(status().isUnauthorized()); .andExpect(status().isUnauthorized());
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Item")
.withIssueDate("2020-10-17")
.withAuthor("John, Doe")
.withSubject("Test")
.build();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("Parameter"); subscriptionParameter.setName("Parameter");
subscriptionParameter.setValue("ValueParameter"); subscriptionParameter.setValue("ValueParameter");
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = subscribeService.subscribe(context, admin, publicItem1, subscriptionParameterList, "TestType"); Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "TestType", publicItem, admin, subscriptionParameterList).build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
//When we call the root endpoint //When we call the root endpoint
getClient(token).perform(get("/api/core/subscriptions/" + subscription.getID())) getClient(token).perform(get("/api/core/subscriptions/" + subscription.getID()))
@@ -175,34 +152,19 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
} }
@Test @Test
public void findByIdAsRandomUser() throws Exception { public void findByIdAsAnonymous() throws Exception {
String token = getAuthToken(admin.getEmail(), password);
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Item")
.withIssueDate("2020-10-17")
.withAuthor("John, Doe")
.withSubject("Test")
.build();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("Parameter"); subscriptionParameter.setName("Parameter");
subscriptionParameter.setValue("ValueParameter"); subscriptionParameter.setValue("ValueParameter");
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = subscribeService.subscribe(context, admin, publicItem1, subscriptionParameterList, "TestType"); Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "TestType", publicItem, admin, subscriptionParameterList).build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
//When we call the root endpoint //When we call the root endpoint
getClient(token).perform(get("/api/core/subscriptions/" + subscription.getID())) getClient().perform(get("/api/core/subscriptions/" + subscription.getID()))
//The status has to be 403 //The status has to be 401
.andExpect(status().isForbidden()); .andExpect(status().isUnauthorized());
} }
@Test @Test
@@ -213,26 +175,16 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
// .andExpect(status().isUnauthorized()); // .andExpect(status().isUnauthorized());
String token = getAuthToken(eperson.getEmail(), password); String token = getAuthToken(eperson.getEmail(), password);
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context) EPerson user = EPersonBuilder.createEPerson(context)
.withName("Parent Community") .withEmail("user@test.it")
.build(); .withPassword(password)
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Item")
.withIssueDate("2020-10-17")
.withAuthor("John, Doe")
.withSubject("Test")
.build(); .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 = subscribeService.subscribe(context, eperson, publicItem1, subscriptionParameterList, "TestType"); Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "TestType", publicItem, user, subscriptionParameterList).build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
//When we call the root endpoint //When we call the root endpoint
getClient(token).perform(get("/api/core/subscriptions/search/findByEPerson?id=" + eperson.getID())) getClient(token).perform(get("/api/core/subscriptions/search/findByEPerson?id=" + eperson.getID()))
@@ -242,14 +194,13 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
.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].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.startsWith(REST_SERVER_URL + "core/subscriptions")))
.andExpect(jsonPath("$._embedded.subscriptions[0]._links.dSpaceObject.href", Matchers.endsWith("dSpaceObject"))) .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.startsWith(REST_SERVER_URL + "core/subscriptions")))
.andExpect(jsonPath("$._embedded.subscriptions[0]._links.ePerson.href", Matchers.endsWith("ePerson"))) .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].name", is("Parameter1")))
.andExpect(jsonPath("$._embedded.subscriptions[0].subscriptionParameterList[0].value", is("ValueParameter1"))) .andExpect(jsonPath("$._embedded.subscriptions[0].subscriptionParameterList[0].value", is("ValueParameter1")));
.andExpect(jsonPath("$._links.self.href", Matchers.is(REST_SERVER_URL + "core/subscriptions")));
EPerson epersonIT = EPersonBuilder.createEPerson(context) EPerson epersonIT = EPersonBuilder.createEPerson(context)
@@ -257,30 +208,28 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
.withPassword(password) .withPassword(password)
.withLanguage("al") .withLanguage("al")
.build(); .build();
String epersonITtoken = getAuthToken(epersonIT.getEmail(), password); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
getClient(epersonITtoken).perform(get("/api/core/subscriptions/" + subscription.getID())) SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
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);
Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "TestType", collection, user, subscriptionParameterList).build();
Subscription subscription1 = SubscribeBuilder.subscribeBuilder(context, "Test", collection, user, subscriptionParameterList1).build();
context.restoreAuthSystemState();
//When we call the root endpoint
String token = getAuthToken(admin.getEmail(), password);
getClient(token).perform(get("/api/core/subscriptions/search/findByEPersonAndDso?dspace_object_id=" + collection.getID() + "&eperson_id=" + user.getID()))
//The status has to be 200 OK //The status has to be 200 OK
.andExpect(status().isUnauthorized()); .andExpect(status().isUnauthorized());
} }
@Test @Test
public void addSubscriptionNotLoggedIn() throws Exception { public void addSubscriptionNotLoggedIn() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Item")
.withIssueDate("2020-10-17")
.withAuthor("John, Doe")
.withSubject("Test")
.build();
context.restoreAuthSystemState();
SubscriptionParameterRest subscriptionParameterRest = new SubscriptionParameterRest(); SubscriptionParameterRest subscriptionParameterRest = new SubscriptionParameterRest();
subscriptionParameterRest.setValue("nameTest"); subscriptionParameterRest.setValue("nameTest");
subscriptionParameterRest.setName("valueTest"); subscriptionParameterRest.setName("valueTest");
@@ -289,10 +238,10 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
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", publicItem1.getID().toString()); params.add("dspace_object_id", publicItem.getID().toString());
params.add("eperson_id", eperson.getID().toString()); params.add("eperson_id", eperson.getID().toString());
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
getClient().perform(post("/api/core/subscriptions?dspace_object_id="+publicItem1.getID()+"&eperson_id="+eperson.getID()) getClient().perform(post("/api/core/subscriptions?dspace_object_id=" + publicItem.getID() + "&eperson_id=" + eperson.getID())
.content(objectMapper.writeValueAsString(subscriptionRest)) .content(objectMapper.writeValueAsString(subscriptionRest))
.contentType(contentType)) .contentType(contentType))
//The status has to be 401 Not Authorized //The status has to be 401 Not Authorized
@@ -301,22 +250,6 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
@Test @Test
public void addSubscriptionAsAdmin() throws Exception { public void addSubscriptionAsAdmin() throws Exception {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Item")
.withIssueDate("2020-10-17")
.withAuthor("John, Doe")
.withSubject("Test")
.build();
context.restoreAuthSystemState();
//When we call the root endpoint as anonymous user //When we call the root endpoint as anonymous user
SubscriptionParameterRest subscriptionParameterRest = new SubscriptionParameterRest(); SubscriptionParameterRest subscriptionParameterRest = new SubscriptionParameterRest();
subscriptionParameterRest.setValue("nameTest"); subscriptionParameterRest.setValue("nameTest");
@@ -328,9 +261,17 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
// subscriptionRest.setSubscriptionParameterList(subscriptionParameterRestList); // subscriptionRest.setSubscriptionParameterList(subscriptionParameterRestList);
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
getClient(token).perform(post("/api/core/subscriptions?dspace_object_id="+publicItem1.getID()+"&eperson_id="+admin.getID()) Map<String, Object> map = new HashMap<>();
.content(objectMapper.writeValueAsString(subscriptionRest)) map.put("type", "test");
.contentType(contentType)) 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);
getClient(token).perform(post("/api/core/subscriptions?dspace_object_id=" + publicItem.getID() + "&eperson_id=" + admin.getID())
.content(objectMapper.writeValueAsString(map))
.contentType(MediaType.APPLICATION_JSON_VALUE))
//The status has to be 200 OK //The status has to be 200 OK
.andExpect(status().isOk()) .andExpect(status().isOk())
//We expect the content type to be "application/hal+json;charset=UTF-8" //We expect the content type to be "application/hal+json;charset=UTF-8"
@@ -349,29 +290,27 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
@Test @Test
public void editSubscriptionAnonymous() throws Exception { public void editSubscriptionAnonymous() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Item")
.withIssueDate("2020-10-17")
.withAuthor("John, Doe")
.withSubject("Test")
.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 = subscribeService.subscribe(context, eperson, publicItem1, subscriptionParameterList, "TestType"); Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "TestType", publicItem, admin, subscriptionParameterList).build();
ObjectMapper objectMapper = new ObjectMapper();
String token = getAuthToken(admin.getEmail(), password);
Map<String, Object> newSubscription = new HashMap<>();
newSubscription.put("type", "test");
List<Map<String, Object>> list = new ArrayList<>();
Map<String, Object> sub_list = new HashMap<>();
sub_list.put("name", "frequency");
sub_list.put("value", "daily");
list.add(sub_list);
newSubscription.put("subscriptionParameterList", list);
context.restoreAuthSystemState(); context.restoreAuthSystemState();
//When we call the root endpoint as anonymous user //When we call the root endpoint as anonymous user
getClient().perform(put("/api/core/subscriptions")) getClient().perform(put("/api/core/subscriptions/" + subscription.getID() + "?dspace_object_id=" + publicItem.getID() + "&eperson_id=" + admin.getID())
.content(objectMapper.writeValueAsString(newSubscription))
.contentType(MediaType.APPLICATION_JSON_VALUE))
//The status has to be 403 Not Authorized //The status has to be 403 Not Authorized
.andExpect(status().isUnauthorized()); .andExpect(status().isUnauthorized());
} }
@@ -384,30 +323,17 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
.withPassword(password) .withPassword(password)
.withLanguage("al") .withLanguage("al")
.build(); .build();
String epersonITtoken = getAuthToken(epersonIT.getEmail(), password);
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Item")
.withIssueDate("2020-10-17")
.withAuthor("John, Doe")
.withSubject("Test")
.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 = subscribeService.subscribe(context, eperson, publicItem1, subscriptionParameterList, "TestType"); Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "TestType", publicItem, eperson, subscriptionParameterList).build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
//When we call the root endpoint as anonymous user //When we call the root endpoint as anonymous user
getClient(epersonITtoken).perform(put("/api/core/subscriptions")) getClient().perform(put("/api/core/subscriptions/" + subscription.getID() + "?dspace_object_id=" + publicItem.getID() + "&eperson_id=" + admin.getID())
.content(objectMapper.writeValueAsString(newSubscription))
.contentType(MediaType.APPLICATION_JSON_VALUE))
//The status has to be 403 Not Authorized //The status has to be 403 Not Authorized
.andExpect(status().isUnauthorized()); .andExpect(status().isUnauthorized());
} }
@@ -417,46 +343,39 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
String tokenAdmin = getAuthToken(admin.getEmail(), password); String tokenAdmin = getAuthToken(admin.getEmail(), password);
String tokenSubscriber = getAuthToken(eperson.getEmail(), password); String tokenSubscriber = getAuthToken(eperson.getEmail(), password);
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Item")
.withIssueDate("2020-10-17")
.withAuthor("John, Doe")
.withSubject("Test")
.build();
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 = subscribeService.subscribe(context, eperson, publicItem1, subscriptionParameterList, "Test"); Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "TestType", publicItem, eperson, subscriptionParameterList).build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
getClient(tokenSubscriber).perform(put("/api/core/subscriptions")) ObjectMapper objectMapper = new ObjectMapper();
//The status has to be 403 Not Authorized Map<String, Object> newSubscription = new HashMap<>();
.andExpect(status().isOk()); newSubscription.put("type", "test");
//When we call the root endpoint as anonymous user List<Map<String, Object>> list = new ArrayList<>();
getClient(tokenAdmin).perform(put("/api/core/subscriptions")) Map<String, Object> sub_list = new HashMap<>();
sub_list.put("name", "frequency");
sub_list.put("value", "daily");
list.add(sub_list);
newSubscription.put("subscriptionParameterList", list);
String tokenSubscriber = getAuthToken(eperson.getEmail(), password);
getClient(tokenSubscriber).perform(put("/api/core/subscriptions/" + subscription.getID() + "?dspace_object_id=" + publicItem.getID() + "&eperson_id=" + eperson.getID())
//The status has to be 403 Not Authorized //The status has to be 403 Not Authorized
.content(objectMapper.writeValueAsString(newSubscription))
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk()) .andExpect(status().isOk())
//We expect the content type to be "application/hal+json;charset=UTF-8" //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("$.type", is("Test"))) .andExpect(jsonPath("$.subscriptionType", is("test")))
.andExpect(jsonPath("$.id", Matchers.endsWith(REST_SERVER_URL + "/api/core/dSpaceObject"))) .andExpect(jsonPath("$.subscriptionParameterList[0].name", is("frequency")))
.andExpect(jsonPath("$.subscriptionParameterList[0].name", is("Frequency"))) .andExpect(jsonPath("$.subscriptionParameterList[0].value", is("daily")))
.andExpect(jsonPath("$.subscriptionParameterList[0].value", is("Daily"))) .andExpect(jsonPath("$._links.self.href", Matchers.startsWith(REST_SERVER_URL + "core/subscriptions")))
.andExpect(jsonPath("$._links.self.href", Matchers.startsWith(REST_SERVER_URL + "/api/core/subscriptions"))) .andExpect(jsonPath("$._links.dSpaceObject.href", Matchers.startsWith(REST_SERVER_URL + "core/subscriptions")))
.andExpect(jsonPath("$._links.dSpaceObject.href", Matchers.startsWith(REST_SERVER_URL + "/api/core/subscriptions"))) .andExpect(jsonPath("$._links.dSpaceObject.href", Matchers.endsWith("/dSpaceObject")))
.andExpect(jsonPath("$._links.dSpaceObject.href", Matchers.endsWith(REST_SERVER_URL + "/api/core/dSpaceObject"))) .andExpect(jsonPath("$._links.ePerson.href", Matchers.startsWith(REST_SERVER_URL + "core/subscriptions")))
.andExpect(jsonPath("$._links.ePerson.href", Matchers.startsWith(REST_SERVER_URL + "/api/core/subscriptions"))) .andExpect(jsonPath("$._links.ePerson.href", Matchers.endsWith("/ePerson")));
.andExpect(jsonPath("$._links.ePerson.href", Matchers.endsWith(REST_SERVER_URL + "/api/core/ePerson")));
} }
@Test @Test
@@ -468,26 +387,12 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
.withLanguage("al") .withLanguage("al")
.build(); .build();
String epersonITtoken = getAuthToken(epersonIT.getEmail(), password); String epersonITtoken = getAuthToken(epersonIT.getEmail(), password);
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Item")
.withIssueDate("2020-10-17")
.withAuthor("John, Doe")
.withSubject("Test")
.build();
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 = subscribeService.subscribe(context, eperson, publicItem1, subscriptionParameterList, "Test"); Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "Test", publicItem, eperson, subscriptionParameterList).build();
context.restoreAuthSystemState(); context.restoreAuthSystemState();
getClient(epersonITtoken).perform(put("/api/core/subscriptions")) getClient(epersonITtoken).perform(put("/api/core/subscriptions"))
//The status has to be 403 Not Authorized //The status has to be 403 Not Authorized
@@ -497,26 +402,13 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
@Test @Test
public void deleteSubscriptionAsAdmin() throws Exception { public void deleteSubscriptionAsAdmin() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Item")
.withIssueDate("2020-10-17")
.withAuthor("John, Doe")
.withSubject("Test")
.build();
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 = subscribeService.subscribe(context, eperson, publicItem1, subscriptionParameterList, "Test"); Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "Test", publicItem, eperson, subscriptionParameterList).build();
String token = getAuthToken(admin.getEmail(), password);
context.restoreAuthSystemState(); context.restoreAuthSystemState();
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
getClient(token).perform(put("/api/core/subscriptions")) getClient(token).perform(put("/api/core/subscriptions"))
@@ -526,26 +418,13 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
@Test @Test
public void patchReplaceSubscriptionParameterAsAdmin() throws Exception { public void patchReplaceSubscriptionParameterAsAdmin() throws Exception {
parentCommunity = CommunityBuilder.createCommunity(context) context.turnOffAuthorisationSystem();
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Item")
.withIssueDate("2020-10-17")
.withAuthor("John, Doe")
.withSubject("Test")
.build();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("TestName"); subscriptionParameter.setName("TestName");
subscriptionParameter.setValue("TestValue"); subscriptionParameter.setValue("TestValue");
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = subscribeService.subscribe(context, eperson, publicItem1, subscriptionParameterList, "Test"); Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "Test", publicItem, eperson, subscriptionParameterList).build();
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<Operation>();
Map<String, String> value = new HashMap<>(); Map<String, String> value = new HashMap<>();
@@ -575,26 +454,13 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
@Test @Test
public void patchSubscriptionParameterNotAsAdminNotAsSubscriber() throws Exception { public void patchSubscriptionParameterNotAsAdminNotAsSubscriber() throws Exception {
parentCommunity = CommunityBuilder.createCommunity(context) context.turnOffAuthorisationSystem();
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Item")
.withIssueDate("2020-10-17")
.withAuthor("John, Doe")
.withSubject("Test")
.build();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("TestName"); subscriptionParameter.setName("TestName");
subscriptionParameter.setValue("TestValue"); subscriptionParameter.setValue("TestValue");
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = subscribeService.subscribe(context, eperson, publicItem1, subscriptionParameterList, "Test"); Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "Test", publicItem, eperson, subscriptionParameterList).build();
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<Operation>();
Map<String, String> value = new HashMap<>(); Map<String, String> value = new HashMap<>();
value.put("name", "frequency"); value.put("name", "frequency");
@@ -611,32 +477,19 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
getClient(epersonITtoken).perform(patch("/api/core/subscriptions/" + subscription.getID()) getClient(epersonITtoken).perform(patch("/api/core/subscriptions/" + subscription.getID())
.content(patchBody) .content(patchBody)
) )
//The status has to be 200 OK //The status has to be 403 Forbidden
.andExpect(status().isUnauthorized()); .andExpect(status().isForbidden());
} }
@Test @Test
public void patchAddSubscriptionParameter() throws Exception { public void patchAddSubscriptionParameter() throws Exception {
parentCommunity = CommunityBuilder.createCommunity(context) context.turnOffAuthorisationSystem();
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Item")
.withIssueDate("2020-10-17")
.withAuthor("John, Doe")
.withSubject("Test")
.build();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("TestName"); subscriptionParameter.setName("TestName");
subscriptionParameter.setValue("TestValue"); subscriptionParameter.setValue("TestValue");
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = subscribeService.subscribe(context, eperson, publicItem1, subscriptionParameterList, "Test"); Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "Test", publicItem, eperson, subscriptionParameterList).build();
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<Operation>();
Map<String, String> value = new HashMap<>(); Map<String, String> value = new HashMap<>();
@@ -669,26 +522,12 @@ public class SubscriptionRestRepositoryIT extends AbstractControllerIntegrationT
@Test @Test
public void patchRemoveSubscriptionParameter() throws Exception { public void patchRemoveSubscriptionParameter() throws Exception {
context.turnOffAuthorisationSystem(); context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Community child1 = CommunityBuilder.createSubCommunity(context, parentCommunity)
.withName("Sub Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, child1).withName("Collection 1").build();
// creation of the item which will be the DSO related with a subscription
Item publicItem1 = ItemBuilder.createItem(context, col1)
.withTitle("Item")
.withIssueDate("2020-10-17")
.withAuthor("John, Doe")
.withSubject("Test")
.build();
List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>(); List<SubscriptionParameter> subscriptionParameterList = new ArrayList<>();
SubscriptionParameter subscriptionParameter = new SubscriptionParameter(); SubscriptionParameter subscriptionParameter = new SubscriptionParameter();
subscriptionParameter.setName("TestName"); subscriptionParameter.setName("TestName");
subscriptionParameter.setValue("TestValue"); subscriptionParameter.setValue("TestValue");
subscriptionParameterList.add(subscriptionParameter); subscriptionParameterList.add(subscriptionParameter);
Subscription subscription = subscribeService.subscribe(context, eperson, publicItem1, subscriptionParameterList, "Test"); Subscription subscription = SubscribeBuilder.subscribeBuilder(context, "Test", publicItem, eperson, subscriptionParameterList).build();
String token = getAuthToken(admin.getEmail(), password); String token = getAuthToken(admin.getEmail(), password);
List<Operation> ops = new ArrayList<Operation>(); List<Operation> ops = new ArrayList<Operation>();
Map<String, String> value = new HashMap<>(); Map<String, String> value = new HashMap<>();