DS-3851 partially remove legacy workflow to simplify testing

First tests for the workflow endpoint
This commit is contained in:
Andrea Bollini
2019-02-20 23:11:04 +01:00
parent d3d3b57133
commit 70091e59b8
27 changed files with 1057 additions and 244 deletions

View File

@@ -74,23 +74,6 @@ public class Collection extends DSpaceObject implements DSpaceObjectLegacySuppor
@JoinColumn(name = "template_item_id")
private Item template;
/**
* Groups corresponding to workflow steps - NOTE these start from one, so
* workflowGroups[0] corresponds to workflow_step_1.
*/
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "workflow_step_1")
private Group workflowStep1;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "workflow_step_2")
private Group workflowStep2;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "workflow_step_3")
private Group workflowStep3;
@OneToOne
@JoinColumn(name = "submitter")
/** The default group of administrators */
@@ -205,31 +188,16 @@ public class Collection extends DSpaceObject implements DSpaceObjectLegacySuppor
setModified();
}
public Group getWorkflowStep1() {
return workflowStep1;
public Group getWorkflowStep1(Context context) {
return getCollectionService().getWorkflowGroup(context, this, 1);
}
public Group getWorkflowStep2() {
return workflowStep2;
public Group getWorkflowStep2(Context context) {
return getCollectionService().getWorkflowGroup(context, this, 2);
}
public Group getWorkflowStep3() {
return workflowStep3;
}
void setWorkflowStep1(Group workflowStep1) {
this.workflowStep1 = workflowStep1;
setModified();
}
void setWorkflowStep2(Group workflowStep2) {
this.workflowStep2 = workflowStep2;
setModified();
}
void setWorkflowStep3(Group workflowStep3) {
this.workflowStep3 = workflowStep3;
setModified();
public Group getWorkflowStep3(Context context) {
return getCollectionService().getWorkflowGroup(context, this, 3);
}
/**

View File

@@ -47,6 +47,11 @@ import org.dspace.event.Event;
import org.dspace.harvest.HarvestedCollection;
import org.dspace.harvest.service.HarvestedCollectionService;
import org.dspace.workflow.factory.WorkflowServiceFactory;
import org.dspace.xmlworkflow.WorkflowConfigurationException;
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
import org.dspace.xmlworkflow.state.Workflow;
import org.dspace.xmlworkflow.storedcomponents.CollectionRole;
import org.dspace.xmlworkflow.storedcomponents.service.CollectionRoleService;
import org.springframework.beans.factory.annotation.Autowired;
/**
@@ -88,6 +93,11 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
@Autowired(required = true)
protected HarvestedCollectionService harvestedCollectionService;
@Autowired(required = true)
protected XmlWorkflowFactory workflowFactory;
@Autowired(required = true)
protected CollectionRoleService collectionRoleService;
protected CollectionServiceImpl() {
super();
@@ -338,91 +348,95 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
// Check authorisation - Must be an Admin to create Workflow Group
AuthorizeUtil.authorizeManageWorkflowsGroup(context, collection);
if (getWorkflowGroup(collection, step) == null) {
if (getWorkflowGroup(context, collection, step) == null) {
//turn off authorization so that Collection Admins can create Collection Workflow Groups
context.turnOffAuthorisationSystem();
Group g = groupService.create(context);
context.restoreAuthSystemState();
groupService.setName(g,
"COLLECTION_" + collection.getID() + "_WORKFLOW_STEP_" + step);
groupService.update(context, g);
context.restoreAuthSystemState();
setWorkflowGroup(context, collection, step, g);
}
return getWorkflowGroup(collection, step);
return getWorkflowGroup(context, collection, step);
}
@Override
public void setWorkflowGroup(Context context, Collection collection, int step, Group group)
throws SQLException, AuthorizeException {
// we need to store the old group to be able to revoke permissions if granted before
Group oldGroup = null;
int action;
Workflow workflow = null;
try {
workflow = workflowFactory.getWorkflow(collection);
} catch (IOException | WorkflowConfigurationException e) {
log.error(LogManager.getHeader(context, "setWorkflowGroup",
"collection_id=" + collection.getID() + " " + e.getMessage()), e);
}
if (!StringUtils.equals("default", workflow.getID())) {
throw new IllegalArgumentException(
"setWorkflowGroup can be used only on collection with the default basic dspace workflow. "
+ "Instead, the collection: "
+ collection.getID() + " has the workflow: " + workflow.getID());
}
String roleId;
switch (step) {
case 1:
oldGroup = collection.getWorkflowStep1();
action = Constants.WORKFLOW_STEP_1;
collection.setWorkflowStep1(group);
roleId = "reviewer";
break;
case 2:
oldGroup = collection.getWorkflowStep2();
action = Constants.WORKFLOW_STEP_2;
collection.setWorkflowStep2(group);
roleId = "editor";
break;
case 3:
oldGroup = collection.getWorkflowStep3();
action = Constants.WORKFLOW_STEP_3;
collection.setWorkflowStep3(group);
roleId = "finaleditor";
break;
default:
throw new IllegalArgumentException("Illegal step count: " + step);
}
// deal with permissions.
try {
context.turnOffAuthorisationSystem();
// remove the policies for the old group
if (oldGroup != null) {
Iterator<ResourcePolicy> oldPolicies =
resourcePolicyService.find(context, collection, oldGroup, action).iterator();
while (oldPolicies.hasNext()) {
resourcePolicyService.delete(context, oldPolicies.next());
}
oldPolicies = resourcePolicyService.find(context, collection, oldGroup, Constants.ADD).iterator();
while (oldPolicies.hasNext()) {
ResourcePolicy rp = oldPolicies.next();
if (rp.getRpType() == ResourcePolicy.TYPE_WORKFLOW) {
resourcePolicyService.delete(context, rp);
}
}
}
// group can be null to delete workflow step.
// we need to grant permissions if group is not null
CollectionRole colRole = collectionRoleService.find(context, collection, roleId);
if (colRole == null) {
if (group != null) {
authorizeService.addPolicy(context, collection, action, group, ResourcePolicy.TYPE_WORKFLOW);
authorizeService.addPolicy(context, collection, Constants.ADD, group, ResourcePolicy.TYPE_WORKFLOW);
colRole = collectionRoleService.create(context, collection, roleId, group);
}
} else {
if (group != null) {
colRole.setGroup(group);
collectionRoleService.update(context, colRole);
} else {
collectionRoleService.delete(context, colRole);
}
} finally {
context.restoreAuthSystemState();
}
collection.setModified();
}
@Override
public Group getWorkflowGroup(Collection collection, int step) {
public Group getWorkflowGroup(Context context, Collection collection, int step) {
String roleId;
switch (step) {
case 1:
return collection.getWorkflowStep1();
roleId = "reviewer";
break;
case 2:
return collection.getWorkflowStep2();
roleId = "editor";
break;
case 3:
return collection.getWorkflowStep3();
roleId = "finaleditor";
break;
default:
throw new IllegalStateException("Illegal step count: " + step);
throw new IllegalArgumentException("Illegal step count: " + step);
}
CollectionRole colRole;
try {
colRole = collectionRoleService.find(context, collection, roleId);
if (colRole != null) {
return colRole.getGroup();
}
return null;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
@@ -733,29 +747,11 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
// Remove any Handle
handleService.unbindHandle(context, collection);
// Remove any workflow groups - must happen after deleting collection
Group g = collection.getWorkflowStep1();
if (g != null) {
collection.setWorkflowStep1(null);
groupService.delete(context, g);
}
g = collection.getWorkflowStep2();
if (g != null) {
collection.setWorkflowStep2(null);
groupService.delete(context, g);
}
g = collection.getWorkflowStep3();
if (g != null) {
collection.setWorkflowStep3(null);
groupService.delete(context, g);
}
// Remove any workflow roles
collectionRoleService.deleteByCollection(context, collection);
// Remove default administrators group
g = collection.getAdministrators();
Group g = collection.getAdministrators();
if (g != null) {
collection.setAdmins(null);

View File

@@ -35,6 +35,13 @@ public interface CollectionDAO extends DSpaceObjectLegacySupportDAO<Collection>
public Collection findByTemplateItem(Context context, Item item) throws SQLException;
/**
*
* @param context DSpace Context
* @param group EPerson Group
* @return the collection, if any, that has the specified group as administrators or submitters
* @throws SQLException
*/
public Collection findByGroup(Context context, Group group) throws SQLException;
public List<Collection> findAuthorized(Context context, EPerson ePerson, List<Integer> actions) throws SQLException;

View File

@@ -97,10 +97,7 @@ public class CollectionDAOImpl extends AbstractHibernateDSODAO<Collection> imple
Root<Collection> collectionRoot = criteriaQuery.from(Collection.class);
criteriaQuery.select(collectionRoot);
criteriaQuery
.where(criteriaBuilder.or(criteriaBuilder.equal(collectionRoot.get(Collection_.workflowStep1), group),
criteriaBuilder.equal(collectionRoot.get(Collection_.workflowStep2), group),
criteriaBuilder.equal(collectionRoot.get(Collection_.workflowStep3), group),
criteriaBuilder.equal(collectionRoot.get(Collection_.submitters), group),
.where(criteriaBuilder.or(criteriaBuilder.equal(collectionRoot.get(Collection_.submitters), group),
criteriaBuilder.equal(collectionRoot.get(Collection_.admins), group)
)
);

View File

@@ -299,7 +299,7 @@ public class RoleDisseminator implements PackageDisseminator {
writer.writeAttribute(ID, String.valueOf(group.getID()));
writer.writeAttribute(NAME, exportGroupName);
String groupType = getGroupType(relatedObject, group);
String groupType = getGroupType(context, relatedObject, group);
if (groupType != null && !groupType.isEmpty()) {
writer.writeAttribute(TYPE, groupType);
}
@@ -349,7 +349,7 @@ public class RoleDisseminator implements PackageDisseminator {
* @param group the group
* @return a group type string or null
*/
protected String getGroupType(DSpaceObject dso, Group group) {
protected String getGroupType(Context context, DSpaceObject dso, Group group) {
if (dso == null || group == null) {
return null;
}
@@ -370,13 +370,13 @@ public class RoleDisseminator implements PackageDisseminator {
} else if (group.equals(collection.getSubmitters())) {
//Check if Submitters group
return GROUP_TYPE_SUBMIT;
} else if (group.equals(collection.getWorkflowStep1())) {
} else if (group.equals(collection.getWorkflowStep1(context))) {
//Check if workflow step 1 group
return GROUP_TYPE_WORKFLOW_STEP_1;
} else if (group.equals(collection.getWorkflowStep2())) {
} else if (group.equals(collection.getWorkflowStep2(context))) {
//check if workflow step 2 group
return GROUP_TYPE_WORKFLOW_STEP_2;
} else if (group.equals(collection.getWorkflowStep3())) {
} else if (group.equals(collection.getWorkflowStep3(context))) {
//check if workflow step 3 group
return GROUP_TYPE_WORKFLOW_STEP_3;
}
@@ -521,16 +521,16 @@ public class RoleDisseminator implements PackageDisseminator {
list.add(collection.getSubmitters());
}
//check for workflow step 1 group
if (collection.getWorkflowStep1() != null) {
list.add(collection.getWorkflowStep1());
if (collection.getWorkflowStep1(context) != null) {
list.add(collection.getWorkflowStep1(context));
}
//check for workflow step 2 group
if (collection.getWorkflowStep2() != null) {
list.add(collection.getWorkflowStep2());
if (collection.getWorkflowStep2(context) != null) {
list.add(collection.getWorkflowStep2(context));
}
//check for workflow step 3 group
if (collection.getWorkflowStep3() != null) {
list.add(collection.getWorkflowStep3());
if (collection.getWorkflowStep3(context) != null) {
list.add(collection.getWorkflowStep3(context));
}
// FINAL CATCH-ALL -> Find any other groups where name begins with "COLLECTION_<ID>_"

View File

@@ -159,11 +159,12 @@ public interface CollectionService
* This returns <code>null</code> if there is no group associated with
* this collection for the given step.
*
* @param context DSpace Context
* @param collection Collection
* @param step the workflow step (1-3)
* @return the group of reviewers or <code>null</code>
*/
public Group getWorkflowGroup(Collection collection, int step);
public Group getWorkflowGroup(Context context, Collection collection, int step);
/**
* Create a default submitters group if one does not already exist. Returns
@@ -317,6 +318,13 @@ public interface CollectionService
public List<Collection> findAuthorized(Context context, Community community, int actionID)
throws java.sql.SQLException;
/**
*
* @param context DSpace Context
* @param group EPerson Group
* @return the collection, if any, that has the specified group as administrators or submitters
* @throws SQLException
*/
public Collection findByGroup(Context context, Group group) throws SQLException;
List<Collection> findCollectionsWithSubscribers(Context context) throws SQLException;

View File

@@ -211,7 +211,7 @@ public class WorkflowCuratorServiceImpl implements WorkflowCuratorService {
int step = state2step(wfi.getState());
// make sure this step exists
if (step < 4) {
Group wfGroup = collectionService.getWorkflowGroup(wfi.getCollection(), step);
Group wfGroup = collectionService.getWorkflowGroup(c, wfi.getCollection(), step);
if (wfGroup != null) {
epList.addAll(groupService.allMembers(c, wfGroup));
}

View File

@@ -24,6 +24,7 @@ import org.apache.commons.lang3.tuple.Pair;
import org.dspace.authorize.AuthorizeConfiguration;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.content.Collection;
import org.dspace.content.DSpaceObject;
import org.dspace.content.DSpaceObjectServiceImpl;
import org.dspace.content.MetadataField;
@@ -39,6 +40,8 @@ import org.dspace.eperson.service.EPersonService;
import org.dspace.eperson.service.GroupService;
import org.dspace.event.Event;
import org.dspace.util.UUIDUtils;
import org.dspace.xmlworkflow.storedcomponents.CollectionRole;
import org.dspace.xmlworkflow.storedcomponents.service.CollectionRoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -62,6 +65,9 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
@Autowired(required = true)
protected CollectionService collectionService;
@Autowired(required = true)
protected CollectionRoleService collectionRoleService;
@Autowired(required = true)
protected EPersonService ePersonService;
@@ -615,15 +621,6 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
org.dspace.content.Collection collection = collectionService.findByGroup(context, group);
if (collection != null) {
if ((group.equals(collection.getWorkflowStep1()) ||
group.equals(collection.getWorkflowStep2()) ||
group.equals(collection.getWorkflowStep3()))) {
if (AuthorizeConfiguration.canCollectionAdminManageWorkflows()) {
return collection;
} else if (AuthorizeConfiguration.canCommunityAdminManageCollectionWorkflows()) {
return collectionService.getParentObject(context, collection);
}
}
if (group.equals(collection.getSubmitters())) {
if (AuthorizeConfiguration.canCollectionAdminManageSubmitters()) {
return collection;
@@ -638,12 +635,34 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
return collectionService.getParentObject(context, collection);
}
}
} else if (AuthorizeConfiguration.canCommunityAdminManageAdminGroup()) {
} else {
if (AuthorizeConfiguration.canCollectionAdminManageWorkflows()
|| AuthorizeConfiguration.canCommunityAdminManageCollectionWorkflows()) {
// if the group is used for one or more roles on a single collection,
// admins can eventually manage it
List<CollectionRole> collectionRoles = collectionRoleService.findByGroup(context, group);
if (collectionRoles != null && collectionRoles.size() > 0) {
Set<Collection> colls = new HashSet<Collection>();
for (CollectionRole cr : collectionRoles) {
colls.add(cr.getCollection());
}
if (colls.size() == 1) {
collection = colls.iterator().next();
if (AuthorizeConfiguration.canCollectionAdminManageWorkflows()) {
return collection;
} else {
return collectionService.getParentObject(context, collection);
}
}
}
}
if (AuthorizeConfiguration.canCommunityAdminManageAdminGroup()) {
// is the group related to a community and community administrator allowed
// to manage it?
return communityService.findByAdminGroup(context, group);
}
}
}
return null;
}

View File

@@ -356,7 +356,7 @@ public class BasicWorkflowServiceImpl implements BasicWorkflowService {
// advance(...) will call itself if no workflow step group exists
// so we need to check permissions only if a workflow step group is
// in place.
if (workflowItem.getCollection().getWorkflowStep1() != null && e != null) {
if (workflowItem.getCollection().getWorkflowStep1(context) != null && e != null) {
authorizeService
.authorizeAction(context, e, workflowItem.getCollection(), Constants.WORKFLOW_STEP_1, true);
}
@@ -372,7 +372,7 @@ public class BasicWorkflowServiceImpl implements BasicWorkflowService {
// advance(...) will call itself if no workflow step group exists
// so we need to check permissions only if a workflow step group is
// in place.
if (workflowItem.getCollection().getWorkflowStep2() != null && e != null) {
if (workflowItem.getCollection().getWorkflowStep2(context) != null && e != null) {
authorizeService
.authorizeAction(context, e, workflowItem.getCollection(), Constants.WORKFLOW_STEP_2, true);
}
@@ -388,7 +388,7 @@ public class BasicWorkflowServiceImpl implements BasicWorkflowService {
// advance(...) will call itself if no workflow step group exists
// so we need to check permissions only if a workflow step group is
// in place.
if (workflowItem.getCollection().getWorkflowStep3() != null && e != null) {
if (workflowItem.getCollection().getWorkflowStep3(context) != null && e != null) {
authorizeService
.authorizeAction(context, e, workflowItem.getCollection(), Constants.WORKFLOW_STEP_3, true);
}
@@ -575,8 +575,8 @@ public class BasicWorkflowServiceImpl implements BasicWorkflowService {
// if there is a workflow state group and it contains any members,
// then we have to check permissions first
if ((collectionService.getWorkflowGroup(collection, step) != null)
&& !(groupService.isEmpty(collectionService.getWorkflowGroup(collection, step)))
if ((collectionService.getWorkflowGroup(context, collection, step) != null)
&& !(groupService.isEmpty(collectionService.getWorkflowGroup(context, collection, step)))
&& newowner != null) {
authorizeService.authorizeAction(context, newowner, collection, correspondingAction, true);
}
@@ -655,7 +655,7 @@ public class BasicWorkflowServiceImpl implements BasicWorkflowService {
// any approvers?
// if so, add them to tasklist
// if not, skip to next state
Group workflowStepGroup = collectionService.getWorkflowGroup(collection, step);
Group workflowStepGroup = collectionService.getWorkflowGroup(context, collection, step);
if ((workflowStepGroup != null) && !(groupService.isEmpty(workflowStepGroup))) {
// set new item state
@@ -1196,18 +1196,18 @@ public class BasicWorkflowServiceImpl implements BasicWorkflowService {
public Group getWorkflowRoleGroup(Context context, Collection collection, String roleName, Group roleGroup)
throws SQLException, AuthorizeException {
if ("WF_STEP1".equals(roleName)) {
roleGroup = collection.getWorkflowStep1();
roleGroup = collection.getWorkflowStep1(context);
if (roleGroup == null) {
roleGroup = collectionService.createWorkflowGroup(context, collection, 1);
}
} else if ("WF_STEP2".equals(roleName)) {
roleGroup = collection.getWorkflowStep2();
roleGroup = collection.getWorkflowStep2(context);
if (roleGroup == null) {
roleGroup = collectionService.createWorkflowGroup(context, collection, 2);
}
} else if ("WF_STEP3".equals(roleName)) {
roleGroup = collection.getWorkflowStep3();
roleGroup = collection.getWorkflowStep3(context);
if (roleGroup == null) {
roleGroup = collectionService.createWorkflowGroup(context, collection, 3);
}

View File

@@ -49,6 +49,11 @@ public class CollectionRoleServiceImpl implements CollectionRoleService {
return collectionRoleDAO.findByCollection(context, collection);
}
@Override
public List<CollectionRole> findByGroup(Context context, Group group) throws SQLException {
return collectionRoleDAO.findByGroup(context, group);
}
@Override
public CollectionRole create(Context context, Collection collection, String roleId, Group group)
throws SQLException {

View File

@@ -160,11 +160,6 @@ public class XmlWorkflowItem implements WorkflowItem, ReloadableEntity<Integer>,
return 0;
}
@Override
public String getTypeText() {
return "workflowitem";
}
@Override
public int getType() {
return Constants.WORKFLOWITEM;
@@ -182,7 +177,7 @@ public class XmlWorkflowItem implements WorkflowItem, ReloadableEntity<Integer>,
@Override
public String getHandle() {
return getType() + "-" + getID();
return null;
}
}

View File

@@ -99,13 +99,17 @@ public class XmlWorkflowItemServiceImpl implements XmlWorkflowItemService {
}
@Override
public List<XmlWorkflowItem> findAll(Context context, Integer offset, Integer pagesize) throws SQLException {
return findAllInCollection(context, offset, pagesize, null);
public List<XmlWorkflowItem> findAll(Context context, Integer page, Integer pagesize) throws SQLException {
return findAllInCollection(context, page, pagesize, null);
}
@Override
public List<XmlWorkflowItem> findAllInCollection(Context context, Integer offset, Integer pagesize,
public List<XmlWorkflowItem> findAllInCollection(Context context, Integer page, Integer pagesize,
Collection collection) throws SQLException {
Integer offset = null;
if (page != null && pagesize != null) {
offset = page * pagesize;
}
return xmlWorkflowItemDAO.findAllInCollection(context, offset, pagesize, collection);
}

View File

@@ -13,6 +13,7 @@ import java.util.List;
import org.dspace.content.Collection;
import org.dspace.core.Context;
import org.dspace.core.GenericDAO;
import org.dspace.eperson.Group;
import org.dspace.xmlworkflow.storedcomponents.CollectionRole;
/**
@@ -27,6 +28,17 @@ public interface CollectionRoleDAO extends GenericDAO<CollectionRole> {
public List<CollectionRole> findByCollection(Context context, Collection collection) throws SQLException;
/**
*
* @param context
* DSpace context
* @param group
* EPerson Group
* @return the list of CollectionRole assigned to the specified group
* @throws SQLException
*/
public List<CollectionRole> findByGroup(Context context, Group group) throws SQLException;
public CollectionRole findByCollectionAndRole(Context context, Collection collection, String role)
throws SQLException;

View File

@@ -27,6 +27,20 @@ import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
*/
public interface XmlWorkflowItemDAO extends GenericDAO<XmlWorkflowItem> {
/**
* Find all the workflow items in a specific collection using the pagination parameters (offset, limit)
*
* @param context
* dspace context
* @param offset
* the first record to return
* @param limit
* the max number of records to return
* @param collection
* the collection where the workflowitem has been submitted
* @return all the workflow items respecting the parameters conditions
* @throws SQLException
*/
public List<XmlWorkflowItem> findAllInCollection(Context context, Integer offset, Integer limit,
Collection collection) throws SQLException;

View File

@@ -17,6 +17,7 @@ import javax.persistence.criteria.Root;
import org.dspace.content.Collection;
import org.dspace.core.AbstractHibernateDAO;
import org.dspace.core.Context;
import org.dspace.eperson.Group;
import org.dspace.xmlworkflow.storedcomponents.CollectionRole;
import org.dspace.xmlworkflow.storedcomponents.CollectionRole_;
import org.dspace.xmlworkflow.storedcomponents.dao.CollectionRoleDAO;
@@ -43,6 +44,16 @@ public class CollectionRoleDAOImpl extends AbstractHibernateDAO<CollectionRole>
return list(context, criteriaQuery, false, CollectionRole.class, -1, -1);
}
@Override
public List<CollectionRole> findByGroup(Context context, Group group) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, CollectionRole.class);
Root<CollectionRole> collectionRoleRoot = criteriaQuery.from(CollectionRole.class);
criteriaQuery.select(collectionRoleRoot);
criteriaQuery.where(criteriaBuilder.equal(collectionRoleRoot.get(CollectionRole_.group), group));
return list(context, criteriaQuery, false, CollectionRole.class, -1, -1);
}
@Override
public CollectionRole findByCollectionAndRole(Context context, Collection collection, String role)
throws SQLException {

View File

@@ -56,6 +56,7 @@ public class XmlWorkflowItemDAOImpl extends AbstractHibernateDAO<XmlWorkflowItem
if (limit == null) {
limit = -1;
}
criteriaQuery.orderBy(criteriaBuilder.asc(xmlWorkflowItemRoot.get(XmlWorkflowItem_.id)));
return list(context, criteriaQuery, false, XmlWorkflowItem.class, limit, offset);
}

View File

@@ -28,6 +28,17 @@ public interface CollectionRoleService {
public CollectionRole find(Context context, Collection collection, String role) throws SQLException;
/**
*
* @param context
* DSpace context
* @param group
* EPerson Group
* @return the list of CollectionRole assigned to the specified group
* @throws SQLException
*/
public List<CollectionRole> findByGroup(Context context, Group group) throws SQLException;
public List<CollectionRole> findByCollection(Context context, Collection collection) throws SQLException;
public CollectionRole create(Context context, Collection collection, String roleId, Group group)

View File

@@ -509,8 +509,9 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
Group g = groupService.create(context);
context.restoreAuthSystemState();
collection.setWorkflowGroup(context, step, g);
assertThat("testSetWorkflowGroup 0", collectionService.getWorkflowGroup(collection, step), notNullValue());
assertThat("testSetWorkflowGroup 1", collectionService.getWorkflowGroup(collection, step), equalTo(g));
assertThat("testSetWorkflowGroup 0", collectionService.getWorkflowGroup(context, collection, step),
notNullValue());
assertThat("testSetWorkflowGroup 1", collectionService.getWorkflowGroup(context, collection, step), equalTo(g));
}
/**
@@ -528,8 +529,10 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
context.restoreAuthSystemState();
collection.setWorkflowGroup(context, step, g1);
collection.setWorkflowGroup(context, step, g2);
assertThat("testSetWorkflowGroup 0", collectionService.getWorkflowGroup(collection, step), notNullValue());
assertThat("testSetWorkflowGroup 1", collectionService.getWorkflowGroup(collection, step), equalTo(g2));
assertThat("testSetWorkflowGroup 0", collectionService.getWorkflowGroup(context, collection, step),
notNullValue());
assertThat("testSetWorkflowGroup 1", collectionService.getWorkflowGroup(context, collection, step),
equalTo(g2));
}
/**
@@ -539,7 +542,8 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
public void testGetWorkflowGroup() {
//null by default
int step = 1;
assertThat("testGetWorkflowGroup 0", collectionService.getWorkflowGroup(collection, step), nullValue());
assertThat("testGetWorkflowGroup 0", collectionService.getWorkflowGroup(context, collection, step),
nullValue());
}
/**

View File

@@ -156,7 +156,7 @@ public class PackageUtilsTest extends AbstractUnitTest {
@Test
public void testCrosswalkGroupNameWithoutUnderscore() throws Exception {
Collection testCollection = (Collection) handleService.resolveToObject(context, testCollectionHandle);
Group originalFirstStepWorkflowGroup = testCollection.getWorkflowStep1();
Group originalFirstStepWorkflowGroup = testCollection.getWorkflowStep1(context);
GroupService groupService = EPersonServiceFactory.getInstance().getGroupService();
Group testGroup = groupService.create(context);
@@ -178,7 +178,7 @@ public class PackageUtilsTest extends AbstractUnitTest {
@Test
public void testCrosswalkGroupNameUnderscoresNoDSO() throws Exception {
Collection testCollection = (Collection) handleService.resolveToObject(context, testCollectionHandle);
Group originalFirstStepWorkflowGroup = testCollection.getWorkflowStep1();
Group originalFirstStepWorkflowGroup = testCollection.getWorkflowStep1(context);
GroupService groupService = EPersonServiceFactory.getInstance().getGroupService();
Group testGroup = groupService.create(context);
@@ -200,7 +200,7 @@ public class PackageUtilsTest extends AbstractUnitTest {
@Test
public void testCrosswalkGroupNameUnderscoresAndDSO() throws Exception {
Collection testCollection = (Collection) handleService.resolveToObject(context, testCollectionHandle);
Group originalFirstStepWorkflowGroup = testCollection.getWorkflowStep1();
Group originalFirstStepWorkflowGroup = testCollection.getWorkflowStep1(context);
Group group = collectionService.createWorkflowGroup(context, testCollection, 1);

View File

@@ -208,7 +208,8 @@ public class BasicWorkflowAuthorizationIT
} finally {
context.restoreAuthSystemState();
}
Assert.assertThat("testsetWorkflowGroupSetsPermission 0", collectionService.getWorkflowGroup(collection, step),
Assert.assertThat("testsetWorkflowGroupSetsPermission 0",
collectionService.getWorkflowGroup(context, collection, step),
CoreMatchers.equalTo(group));
Assert.assertTrue(groupService.isDirectMember(group, member));
Assert.assertTrue("testsetWorkflowGroupSetsPermission 1", authorizeService
@@ -230,7 +231,8 @@ public class BasicWorkflowAuthorizationIT
context.restoreAuthSystemState();
}
Assert
.assertThat("testsetWorkflowGroupRevokesPermission 0", collectionService.getWorkflowGroup(collection, step),
.assertThat("testsetWorkflowGroupRevokesPermission 0",
collectionService.getWorkflowGroup(context, collection, step),
CoreMatchers
.equalTo(group));
Assert.assertTrue("testsetWorkflowGroupRevokesPermission 1", authorizeService
@@ -243,7 +245,8 @@ public class BasicWorkflowAuthorizationIT
context.restoreAuthSystemState();
}
Assert
.assertThat("testsetWorkflowGroupRevokesPermission 2", collectionService.getWorkflowGroup(collection, step),
.assertThat("testsetWorkflowGroupRevokesPermission 2",
collectionService.getWorkflowGroup(context, collection, step),
CoreMatchers
.nullValue());
Assert.assertFalse("testsetWorkflowGroupRevokesPermission 3", authorizeService

View File

@@ -291,9 +291,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertEquals(collection.getWorkflowStep1(), roleGroups.get(ROLE.STEP1));
Assert.assertNull(collection.getWorkflowStep2());
Assert.assertNull(collection.getWorkflowStep3());
Assert.assertEquals(collection.getWorkflowStep1(context), roleGroups.get(ROLE.STEP1));
Assert.assertNull(collection.getWorkflowStep2(context));
Assert.assertNull(collection.getWorkflowStep3(context));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP1POOL, wfi.getState());
@@ -340,9 +340,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertEquals(collection.getWorkflowStep1(), roleGroups.get(ROLE.STEP1));
Assert.assertNull(collection.getWorkflowStep2());
Assert.assertNull(collection.getWorkflowStep3());
Assert.assertEquals(collection.getWorkflowStep1(context), roleGroups.get(ROLE.STEP1));
Assert.assertNull(collection.getWorkflowStep2(context));
Assert.assertNull(collection.getWorkflowStep3(context));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP1POOL, wfi.getState());
@@ -389,9 +389,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertEquals(collection.getWorkflowStep1(), roleGroups.get(ROLE.STEP1));
Assert.assertNull(collection.getWorkflowStep2());
Assert.assertNull(collection.getWorkflowStep3());
Assert.assertEquals(collection.getWorkflowStep1(context), roleGroups.get(ROLE.STEP1));
Assert.assertNull(collection.getWorkflowStep2(context));
Assert.assertNull(collection.getWorkflowStep3(context));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP1POOL, wfi.getState());
@@ -438,9 +438,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertEquals(collection.getWorkflowStep1(), roleGroups.get(ROLE.STEP1));
Assert.assertNull(collection.getWorkflowStep2());
Assert.assertNull(collection.getWorkflowStep3());
Assert.assertEquals(collection.getWorkflowStep1(context), roleGroups.get(ROLE.STEP1));
Assert.assertNull(collection.getWorkflowStep2(context));
Assert.assertNull(collection.getWorkflowStep3(context));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP1POOL, wfi.getState());
@@ -490,9 +490,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertNull(collection.getWorkflowStep1());
Assert.assertEquals(collection.getWorkflowStep2(), roleGroups.get(ROLE.STEP2));
Assert.assertNull(collection.getWorkflowStep3());
Assert.assertNull(collection.getWorkflowStep1(context));
Assert.assertEquals(collection.getWorkflowStep2(context), roleGroups.get(ROLE.STEP2));
Assert.assertNull(collection.getWorkflowStep3(context));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP2POOL, wfi.getState());
@@ -538,9 +538,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertNull(collection.getWorkflowStep1());
Assert.assertEquals(collection.getWorkflowStep2(), roleGroups.get(ROLE.STEP2));
Assert.assertNull(collection.getWorkflowStep3());
Assert.assertNull(collection.getWorkflowStep1(context));
Assert.assertEquals(collection.getWorkflowStep2(context), roleGroups.get(ROLE.STEP2));
Assert.assertNull(collection.getWorkflowStep3(context));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP2POOL, wfi.getState());
@@ -586,9 +586,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertNull(collection.getWorkflowStep1());
Assert.assertEquals(collection.getWorkflowStep2(), roleGroups.get(ROLE.STEP2));
Assert.assertNull(collection.getWorkflowStep3());
Assert.assertNull(collection.getWorkflowStep1(context));
Assert.assertEquals(collection.getWorkflowStep2(context), roleGroups.get(ROLE.STEP2));
Assert.assertNull(collection.getWorkflowStep3(context));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP2POOL, wfi.getState());
@@ -634,9 +634,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertNull(collection.getWorkflowStep1());
Assert.assertEquals(collection.getWorkflowStep2(), roleGroups.get(ROLE.STEP2));
Assert.assertNull(collection.getWorkflowStep3());
Assert.assertNull(collection.getWorkflowStep1(context));
Assert.assertEquals(collection.getWorkflowStep2(context), roleGroups.get(ROLE.STEP2));
Assert.assertNull(collection.getWorkflowStep3(context));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP2POOL, wfi.getState());
@@ -685,9 +685,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertNull(collection.getWorkflowStep1());
Assert.assertNull(collection.getWorkflowStep2());
Assert.assertEquals(collection.getWorkflowStep3(), roleGroups.get(ROLE.STEP3));
Assert.assertNull(collection.getWorkflowStep1(context));
Assert.assertNull(collection.getWorkflowStep2(context));
Assert.assertEquals(collection.getWorkflowStep3(context), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP3POOL, wfi.getState());
@@ -733,9 +733,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertNull(collection.getWorkflowStep1());
Assert.assertNull(collection.getWorkflowStep2());
Assert.assertEquals(collection.getWorkflowStep3(), roleGroups.get(ROLE.STEP3));
Assert.assertNull(collection.getWorkflowStep1(context));
Assert.assertNull(collection.getWorkflowStep2(context));
Assert.assertEquals(collection.getWorkflowStep3(context), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP3POOL, wfi.getState());
@@ -781,9 +781,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertNull(collection.getWorkflowStep1());
Assert.assertNull(collection.getWorkflowStep2());
Assert.assertEquals(collection.getWorkflowStep3(), roleGroups.get(ROLE.STEP3));
Assert.assertNull(collection.getWorkflowStep1(context));
Assert.assertNull(collection.getWorkflowStep2(context));
Assert.assertEquals(collection.getWorkflowStep3(context), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP3POOL, wfi.getState());
@@ -829,9 +829,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertNull(collection.getWorkflowStep1());
Assert.assertNull(collection.getWorkflowStep2());
Assert.assertEquals(collection.getWorkflowStep3(), roleGroups.get(ROLE.STEP3));
Assert.assertNull(collection.getWorkflowStep1(context));
Assert.assertNull(collection.getWorkflowStep2(context));
Assert.assertEquals(collection.getWorkflowStep3(context), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP3POOL, wfi.getState());
@@ -880,9 +880,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertEquals(collection.getWorkflowStep1(), roleGroups.get(ROLE.STEP1));
Assert.assertEquals(collection.getWorkflowStep2(), roleGroups.get(ROLE.STEP2));
Assert.assertNull(collection.getWorkflowStep3());
Assert.assertEquals(collection.getWorkflowStep1(context), roleGroups.get(ROLE.STEP1));
Assert.assertEquals(collection.getWorkflowStep2(context), roleGroups.get(ROLE.STEP2));
Assert.assertNull(collection.getWorkflowStep3(context));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP1POOL, wfi.getState());
@@ -928,9 +928,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertEquals(collection.getWorkflowStep1(), roleGroups.get(ROLE.STEP1));
Assert.assertEquals(collection.getWorkflowStep2(), roleGroups.get(ROLE.STEP2));
Assert.assertNull(collection.getWorkflowStep3());
Assert.assertEquals(collection.getWorkflowStep1(context), roleGroups.get(ROLE.STEP1));
Assert.assertEquals(collection.getWorkflowStep2(context), roleGroups.get(ROLE.STEP2));
Assert.assertNull(collection.getWorkflowStep3(context));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP1POOL, wfi.getState());
@@ -976,9 +976,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertEquals(collection.getWorkflowStep1(), roleGroups.get(ROLE.STEP1));
Assert.assertEquals(collection.getWorkflowStep2(), roleGroups.get(ROLE.STEP2));
Assert.assertNull(collection.getWorkflowStep3());
Assert.assertEquals(collection.getWorkflowStep1(context), roleGroups.get(ROLE.STEP1));
Assert.assertEquals(collection.getWorkflowStep2(context), roleGroups.get(ROLE.STEP2));
Assert.assertNull(collection.getWorkflowStep3(context));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP1POOL, wfi.getState());
@@ -1029,9 +1029,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertEquals(collection.getWorkflowStep1(), roleGroups.get(ROLE.STEP1));
Assert.assertNull(collection.getWorkflowStep2());
Assert.assertEquals(collection.getWorkflowStep3(), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(collection.getWorkflowStep1(context), roleGroups.get(ROLE.STEP1));
Assert.assertNull(collection.getWorkflowStep2(context));
Assert.assertEquals(collection.getWorkflowStep3(context), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP1POOL, wfi.getState());
@@ -1077,9 +1077,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertEquals(collection.getWorkflowStep1(), roleGroups.get(ROLE.STEP1));
Assert.assertNull(collection.getWorkflowStep2());
Assert.assertEquals(collection.getWorkflowStep3(), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(collection.getWorkflowStep1(context), roleGroups.get(ROLE.STEP1));
Assert.assertNull(collection.getWorkflowStep2(context));
Assert.assertEquals(collection.getWorkflowStep3(context), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP1POOL, wfi.getState());
@@ -1126,9 +1126,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertEquals(collection.getWorkflowStep1(), roleGroups.get(ROLE.STEP1));
Assert.assertNull(collection.getWorkflowStep2());
Assert.assertEquals(collection.getWorkflowStep3(), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(collection.getWorkflowStep1(context), roleGroups.get(ROLE.STEP1));
Assert.assertNull(collection.getWorkflowStep2(context));
Assert.assertEquals(collection.getWorkflowStep3(context), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP1POOL, wfi.getState());
@@ -1178,9 +1178,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertNull(collection.getWorkflowStep1());
Assert.assertEquals(collection.getWorkflowStep2(), roleGroups.get(ROLE.STEP2));
Assert.assertEquals(collection.getWorkflowStep3(), roleGroups.get(ROLE.STEP3));
Assert.assertNull(collection.getWorkflowStep1(context));
Assert.assertEquals(collection.getWorkflowStep2(context), roleGroups.get(ROLE.STEP2));
Assert.assertEquals(collection.getWorkflowStep3(context), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP2POOL, wfi.getState());
@@ -1226,9 +1226,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertNull(collection.getWorkflowStep1());
Assert.assertEquals(collection.getWorkflowStep2(), roleGroups.get(ROLE.STEP2));
Assert.assertEquals(collection.getWorkflowStep3(), roleGroups.get(ROLE.STEP3));
Assert.assertNull(collection.getWorkflowStep1(context));
Assert.assertEquals(collection.getWorkflowStep2(context), roleGroups.get(ROLE.STEP2));
Assert.assertEquals(collection.getWorkflowStep3(context), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP2POOL, wfi.getState());
@@ -1274,9 +1274,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertNull(collection.getWorkflowStep1());
Assert.assertEquals(collection.getWorkflowStep2(), roleGroups.get(ROLE.STEP2));
Assert.assertEquals(collection.getWorkflowStep3(), roleGroups.get(ROLE.STEP3));
Assert.assertNull(collection.getWorkflowStep1(context));
Assert.assertEquals(collection.getWorkflowStep2(context), roleGroups.get(ROLE.STEP2));
Assert.assertEquals(collection.getWorkflowStep3(context), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP2POOL, wfi.getState());
@@ -1326,9 +1326,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertEquals(collection.getWorkflowStep1(), roleGroups.get(ROLE.STEP1));
Assert.assertEquals(collection.getWorkflowStep2(), roleGroups.get(ROLE.STEP2));
Assert.assertEquals(collection.getWorkflowStep3(), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(collection.getWorkflowStep1(context), roleGroups.get(ROLE.STEP1));
Assert.assertEquals(collection.getWorkflowStep2(context), roleGroups.get(ROLE.STEP2));
Assert.assertEquals(collection.getWorkflowStep3(context), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP1POOL, wfi.getState());
@@ -1382,9 +1382,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertEquals(collection.getWorkflowStep1(), roleGroups.get(ROLE.STEP1));
Assert.assertEquals(collection.getWorkflowStep2(), roleGroups.get(ROLE.STEP2));
Assert.assertEquals(collection.getWorkflowStep3(), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(collection.getWorkflowStep1(context), roleGroups.get(ROLE.STEP1));
Assert.assertEquals(collection.getWorkflowStep2(context), roleGroups.get(ROLE.STEP2));
Assert.assertEquals(collection.getWorkflowStep3(context), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP1POOL, wfi.getState());
@@ -1438,9 +1438,9 @@ public class BasicWorkflowAuthorizationRolesIT
try {
contextReload();
Assert.assertEquals(collection.getWorkflowStep1(), roleGroups.get(ROLE.STEP1));
Assert.assertEquals(collection.getWorkflowStep2(), roleGroups.get(ROLE.STEP2));
Assert.assertEquals(collection.getWorkflowStep3(), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(collection.getWorkflowStep1(context), roleGroups.get(ROLE.STEP1));
Assert.assertEquals(collection.getWorkflowStep2(context), roleGroups.get(ROLE.STEP2));
Assert.assertEquals(collection.getWorkflowStep3(context), roleGroups.get(ROLE.STEP3));
Assert.assertEquals(BasicWorkflowService.WFSTATE_STEP1POOL, wfi.getState());

View File

@@ -15,6 +15,7 @@ import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.dspace.app.rest.Parameter;
import org.dspace.app.rest.SearchRestMethod;
import org.dspace.app.rest.converter.WorkflowItemConverter;
import org.dspace.app.rest.exception.PatchBadRequestException;
@@ -49,7 +50,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
@@ -123,7 +123,7 @@ public class WorkflowItemRestRepository extends DSpaceRestRepository<WorkflowIte
}
@SearchRestMethod(name = "findBySubmitter")
public Page<WorkflowItemRest> findBySubmitter(@Param(value = "uuid") UUID submitterID, Pageable pageable) {
public Page<WorkflowItemRest> findBySubmitter(@Parameter(value = "uuid") UUID submitterID, Pageable pageable) {
List<XmlWorkflowItem> witems = null;
try {
Context context = obtainContext();

View File

@@ -0,0 +1,422 @@
/**
* 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;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
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.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.io.InputStream;
import java.util.UUID;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.CharEncoding;
import org.dspace.app.rest.builder.BitstreamBuilder;
import org.dspace.app.rest.builder.CollectionBuilder;
import org.dspace.app.rest.builder.CommunityBuilder;
import org.dspace.app.rest.builder.EPersonBuilder;
import org.dspace.app.rest.builder.WorkflowItemBuilder;
import org.dspace.app.rest.matcher.CollectionMatcher;
import org.dspace.app.rest.matcher.ItemMatcher;
import org.dspace.app.rest.matcher.WorkflowItemMatcher;
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.content.Bitstream;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.Item;
import org.dspace.eperson.EPerson;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Test;
/**
* Test suite for the WorkflowItem endpoint
* @author Andrea Bollini (andrea.bollini at 4science.it)
*
*/
public class WorkflowItemRestRepositoryIT extends AbstractControllerIntegrationTest {
@Test
/**
* All the workflowitems should be returned regardless of the collection where they were created
*
* @throws Exception
*/
public void findAllTest() throws Exception {
context.setCurrentUser(admin);
//** GIVEN **
//1. A community-collection structure with one parent community with sub-community and two collections.
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")
.withWorkflowGroup(1, admin).build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2")
.withWorkflowGroup(1, admin).build();
//2. Three workflow items in two different collections
XmlWorkflowItem workflowItem1 = WorkflowItemBuilder.createWorkflowItem(context, col1)
.withTitle("Workflow Item 1")
.withIssueDate("2017-10-17")
.build();
XmlWorkflowItem workflowItem2 = WorkflowItemBuilder.createWorkflowItem(context, col2)
.withTitle("Workflow Item 2")
.withIssueDate("2016-02-13")
.build();
XmlWorkflowItem workflowItem3 = WorkflowItemBuilder.createWorkflowItem(context, col2)
.withTitle("Workflow Item 3")
.withIssueDate("2016-02-13")
.build();
String token = getAuthToken(admin.getEmail(), password);
getClient(token).perform(get("/api/workflow/workflowitems"))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.workflowitems", Matchers.containsInAnyOrder(
WorkflowItemMatcher.matchItemWithTitleAndDateIssued(workflowItem1, "Workflow Item 1",
"2017-10-17"),
WorkflowItemMatcher.matchItemWithTitleAndDateIssued(workflowItem2, "Workflow Item 2",
"2016-02-13"),
WorkflowItemMatcher.matchItemWithTitleAndDateIssued(workflowItem3, "Workflow Item 3",
"2016-02-13"))))
.andExpect(jsonPath("$._links.self.href", Matchers.containsString("/api/workflow/workflowitems")))
.andExpect(jsonPath("$.page.size", is(20)))
.andExpect(jsonPath("$.page.totalElements", is(3)));
}
@Test
/**
* The workflowitem endpoint must provide proper pagination
*
* @throws Exception
*/
public void findAllWithPaginationTest() throws Exception {
context.turnOffAuthorisationSystem();
//** GIVEN **
//1. A community-collection structure with one parent community with sub-community and two collections.
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")
.withWorkflowGroup(1, admin).build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2")
.withWorkflowGroup(1, admin).build();
//2. Three workflow items in two different collections
XmlWorkflowItem workflowItem1 = WorkflowItemBuilder.createWorkflowItem(context, col1)
.withTitle("Workflow Item 1")
.withIssueDate("2017-10-17")
.build();
XmlWorkflowItem workflowItem2 = WorkflowItemBuilder.createWorkflowItem(context, col2)
.withTitle("Workflow Item 2")
.withIssueDate("2016-02-13")
.build();
XmlWorkflowItem workflowItem3 = WorkflowItemBuilder.createWorkflowItem(context, col2)
.withTitle("Workflow Item 3")
.withIssueDate("2016-02-13")
.build();
String token = getAuthToken(admin.getEmail(), password);
getClient(token).perform(get("/api/workflow/workflowitems").param("size", "2"))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.workflowitems",
Matchers.containsInAnyOrder(
WorkflowItemMatcher.matchItemWithTitleAndDateIssued(workflowItem1, "Workflow Item 1",
"2017-10-17"),
WorkflowItemMatcher.matchItemWithTitleAndDateIssued(workflowItem2, "Workflow Item 2",
"2016-02-13"))))
.andExpect(jsonPath("$._embedded.workflowitems",
Matchers.not(Matchers.contains(WorkflowItemMatcher
.matchItemWithTitleAndDateIssued(workflowItem3, "Workflow Item 3", "2016-02-13")))));
getClient(token).perform(get("/api/workflow/workflowitems").param("size", "2").param("page", "1"))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.workflowitems",
Matchers.contains(WorkflowItemMatcher.matchItemWithTitleAndDateIssued(workflowItem3,
"Workflow Item 3", "2016-02-13"))))
.andExpect(jsonPath("$._embedded.workflowitems",
Matchers.not(Matchers.contains(
WorkflowItemMatcher.matchItemWithTitleAndDateIssued(workflowItem1, "Workflow Item 1",
"2017-10-17"),
WorkflowItemMatcher.matchItemWithTitleAndDateIssued(workflowItem2, "Workflow Item 2",
"2016-02-13")))))
.andExpect(jsonPath("$.page.size", is(2))).andExpect(jsonPath("$.page.totalElements", is(3)));
}
@Test
/**
* The workflowitem resource endpoint must expose the proper structure
*
* @throws Exception
*/
public void findOneTest() throws Exception {
context.turnOffAuthorisationSystem();
//** GIVEN **
//1. A community-collection structure with one parent community with sub-community and two collections.
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")
.withWorkflowGroup(1, admin).build();
//2. a workflow item
XmlWorkflowItem witem = WorkflowItemBuilder.createWorkflowItem(context, col1)
.withTitle("Workflow Item 1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald").withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
getClient().perform(get("/api/workflow/workflowitems/" + witem.getID())).andExpect(status().isOk())
.andExpect(jsonPath("$",
Matchers.is(WorkflowItemMatcher.matchItemWithTitleAndDateIssuedAndSubject(witem,
"Workflow Item 1", "2017-10-17", "ExtraEntry"))));
}
@Test
/**
* The workflowitem resource endpoint must expose the proper structure
*
* @throws Exception
*/
public void findOneRelsTest() throws Exception {
context.turnOffAuthorisationSystem();
//** GIVEN **
//1. A community-collection structure with one parent community with sub-community and two collections.
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")
.withWorkflowGroup(1, admin).build();
//2. a workflow item
XmlWorkflowItem witem = WorkflowItemBuilder.createWorkflowItem(context, col1)
.withTitle("Workflow Item 1")
.withIssueDate("2017-10-17")
.withAuthor("Smith, Donald").withAuthor("Doe, John")
.withSubject("ExtraEntry")
.build();
getClient().perform(get("/api/workflow/workflowitems/" + witem.getID() + "/collection"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", Matchers
.is(CollectionMatcher.matchCollectionEntry(col1.getName(), col1.getID(), col1.getHandle()))));
getClient().perform(get("/api/workflow/workflowitems/" + witem.getID() + "/item")).andExpect(status().isOk())
.andExpect(jsonPath("$", Matchers.is(ItemMatcher.matchItemWithTitleAndDateIssued(witem.getItem(),
"Workflow Item 1", "2017-10-17"))));
getClient().perform(get("/api/workflow/workflowitems/" + witem.getID() + "/submissionDefinition"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", Matchers.is(hasJsonPath("$.id", is("traditional")))));
}
@Test
/**
* Check the response code for unexistent workflowitem
*
* @throws Exception
*/
public void findOneWrongIDTest() throws Exception {
String token = getAuthToken(admin.getEmail(), password);
getClient(token).perform(get("/api/workflow/workflowitems/" + Integer.MAX_VALUE))
.andExpect(status().isNotFound());
getClient(token).perform(get("/api/workflow/workflowitems/" + UUID.randomUUID()))
.andExpect(status().isNotFound());
}
@Test
/**
* Removing a workflowitem should result in delete of all the underline resources (item and bitstreams)
*
* @throws Exception
*/
@Ignore
public void deleteOneTest() throws Exception {
context.turnOffAuthorisationSystem();
//** GIVEN **
//1. A community with one collection.
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1")
.withWorkflowGroup(1, admin).build();
//2. a workspace item
XmlWorkflowItem witem = WorkflowItemBuilder.createWorkflowItem(context, col1)
.withTitle("Workflow Item 1")
.withIssueDate("2017-10-17")
.build();
Item item = witem.getItem();
//Add a bitstream to the item
String bitstreamContent = "ThisIsSomeDummyText";
Bitstream bitstream = null;
try (InputStream is = IOUtils.toInputStream(bitstreamContent, CharEncoding.UTF_8)) {
bitstream = BitstreamBuilder
.createBitstream(context, item, is)
.withName("Bitstream1")
.withMimeType("text/plain").build();
}
String token = getAuthToken(admin.getEmail(), password);
//Delete the workflowitem
getClient(token).perform(delete("/api/workflow/workflowitems/" + witem.getID()))
.andExpect(status().is(204));
//Trying to get deleted item should fail with 404
getClient().perform(get("/api/workflow/workflowitems/" + witem.getID()))
.andExpect(status().is(404));
//Trying to get deleted workflowitem's item should fail with 404
getClient().perform(get("/api/core/items/" + item.getID()))
.andExpect(status().is(404));
//Trying to get deleted workflowitem's bitstream should fail with 404
getClient().perform(get("/api/core/biststreams/" + bitstream.getID()))
.andExpect(status().is(404));
}
@Test
/**
* Create three workflowitem with two different submitter and verify that the findBySubmitter return the proper
* list of workflowitem for each submitter also paginating
*
* @throws Exception
*/
public void findBySubmitterTest() throws Exception {
context.turnOffAuthorisationSystem();
//** GIVEN **
//1. A community-collection structure with one parent community with sub-community and two collections.
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")
.withWorkflowGroup(1, admin).build();
Collection col2 = CollectionBuilder.createCollection(context, child1).withName("Collection 2")
.withWorkflowGroup(1, admin).build();
//2. create two users to use as submitters
EPerson submitter1 = EPersonBuilder.createEPerson(context)
.withEmail("submitter1@example.com")
.build();
EPerson submitter2 = EPersonBuilder.createEPerson(context)
.withEmail("submitter2@example.com")
.build();
// create two workflowitems with the first submitter
context.setCurrentUser(submitter1);
//3. Two workflow items in two different collections
XmlWorkflowItem workspaceItem1 = WorkflowItemBuilder.createWorkflowItem(context, col1)
.withTitle("Workflow Item 1")
.withIssueDate("2017-10-17")
.build();
XmlWorkflowItem workspaceItem2 = WorkflowItemBuilder.createWorkflowItem(context, col2)
.withTitle("Workflow Item 2")
.withIssueDate("2016-02-13")
.build();
//4. A workflowitem for the second submitter
context.setCurrentUser(submitter2);
XmlWorkflowItem workspaceItem3 = WorkflowItemBuilder.createWorkflowItem(context, col2)
.withTitle("Workflow Item 3")
.withIssueDate("2016-02-13")
.build();
// use our admin to retrieve all the workspace by submitter
String token = getAuthToken(admin.getEmail(), password);
// the first submitter has two workspace
getClient(token).perform(get("/api/workflow/workflowitems/search/findBySubmitter")
.param("size", "20")
.param("uuid", submitter1.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.workflowitems",
Matchers.containsInAnyOrder(
WorkflowItemMatcher.matchItemWithTitleAndDateIssued(workspaceItem1, "Workflow Item 1",
"2017-10-17"),
WorkflowItemMatcher.matchItemWithTitleAndDateIssued(workspaceItem2, "Workflow Item 2",
"2016-02-13"))))
.andExpect(jsonPath("$._embedded.workflowitems",
Matchers.not(Matchers.contains(WorkflowItemMatcher
.matchItemWithTitleAndDateIssued(workspaceItem3, "Workflow Item 3", "2016-02-13")))))
.andExpect(jsonPath("$.page.size", is(20)))
.andExpect(jsonPath("$.page.totalElements", is(2)));
// the first submitter has two workspace so if we paginate with a 1-size windows the page 1 will contains the
// second workspace
getClient(token).perform(get("/api/workflow/workflowitems/search/findBySubmitter")
.param("size", "1")
.param("page", "1")
.param("uuid", submitter1.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.workflowitems",
Matchers.contains(WorkflowItemMatcher.matchItemWithTitleAndDateIssued(workspaceItem2,
"Workflow Item 2", "2016-02-13"))))
.andExpect(jsonPath("$._embedded.workflowitems",
Matchers.not(Matchers.contains(
WorkflowItemMatcher.matchItemWithTitleAndDateIssued(workspaceItem1, "Workflow Item 1",
"2017-10-17"),
WorkflowItemMatcher.matchItemWithTitleAndDateIssued(workspaceItem3, "Workflow Item 3",
"2016-02-13")))))
.andExpect(jsonPath("$.page.size", is(1)))
.andExpect(jsonPath("$.page.totalElements", is(2)));
// the second submitter has a single workspace
getClient(token).perform(get("/api/workflow/workflowitems/search/findBySubmitter")
.param("size", "20")
.param("uuid", submitter2.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.workflowitems",
Matchers.contains(
WorkflowItemMatcher.matchItemWithTitleAndDateIssued(workspaceItem3, "Workflow Item 3",
"2016-02-13"))))
.andExpect(jsonPath("$.page.size", is(20)))
.andExpect(jsonPath("$.page.totalElements", is(1)));
}
}

View File

@@ -38,10 +38,13 @@ import org.dspace.eperson.service.RegistrationDataService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.versioning.factory.VersionServiceFactory;
import org.dspace.versioning.service.VersionHistoryService;
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
import org.dspace.xmlworkflow.service.XmlWorkflowService;
import org.dspace.xmlworkflow.storedcomponents.service.ClaimedTaskService;
import org.dspace.xmlworkflow.storedcomponents.service.InProgressUserService;
import org.dspace.xmlworkflow.storedcomponents.service.PoolTaskService;
import org.dspace.xmlworkflow.storedcomponents.service.WorkflowItemRoleService;
import org.dspace.xmlworkflow.storedcomponents.service.XmlWorkflowItemService;
/**
* Abstract builder class that holds references to all available services
@@ -55,6 +58,8 @@ public abstract class AbstractBuilder<T, S> {
static ItemService itemService;
static InstallItemService installItemService;
static WorkspaceItemService workspaceItemService;
static XmlWorkflowItemService workflowItemService;
static XmlWorkflowService workflowService;
static EPersonService ePersonService;
static GroupService groupService;
static BundleService bundleService;
@@ -92,6 +97,8 @@ public abstract class AbstractBuilder<T, S> {
itemService = ContentServiceFactory.getInstance().getItemService();
installItemService = ContentServiceFactory.getInstance().getInstallItemService();
workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
workflowItemService = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowItemService();
workflowService = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService();
ePersonService = EPersonServiceFactory.getInstance().getEPersonService();
groupService = EPersonServiceFactory.getInstance().getGroupService();
bundleService = ContentServiceFactory.getInstance().getBundleService();
@@ -109,11 +116,10 @@ public abstract class AbstractBuilder<T, S> {
siteService = ContentServiceFactory.getInstance().getSiteService();
// Temporarily disabled
// TODO find a way to be able to test the XML and "default" workflow at the same time
//claimedTaskService = XmlWorkflowServiceFactoryImpl.getInstance().getClaimedTaskService();
//inProgressUserService = XmlWorkflowServiceFactoryImpl.getInstance().getInProgressUserService();
//poolTaskService = XmlWorkflowServiceFactoryImpl.getInstance().getPoolTaskService();
//workflowItemRoleService = XmlWorkflowServiceFactoryImpl.getInstance().getWorkflowItemRoleService();
claimedTaskService = XmlWorkflowServiceFactory.getInstance().getClaimedTaskService();
inProgressUserService = XmlWorkflowServiceFactory.getInstance().getInProgressUserService();
poolTaskService = XmlWorkflowServiceFactory.getInstance().getPoolTaskService();
workflowItemRoleService = XmlWorkflowServiceFactory.getInstance().getWorkflowItemRoleService();
}

View File

@@ -19,6 +19,8 @@ import org.dspace.content.Community;
import org.dspace.content.MetadataSchema;
import org.dspace.content.service.DSpaceObjectService;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group;
/**
* Builder to construct Collection objects
@@ -70,6 +72,15 @@ public class CollectionBuilder extends AbstractDSpaceObjectBuilder<Collection> {
return this;
}
public CollectionBuilder withWorkflowGroup(int step, EPerson... members) throws SQLException, AuthorizeException {
Group g = collectionService.createWorkflowGroup(context, collection, step);
for (EPerson e : members) {
groupService.addMember(context, g, e);
}
groupService.update(context, g);
return this;
}
@Override
public Collection build() {
try {
@@ -84,9 +95,30 @@ public class CollectionBuilder extends AbstractDSpaceObjectBuilder<Collection> {
}
protected void cleanup() throws Exception {
deleteWorkflowGroups(collection);
delete(collection);
}
public void deleteWorkflowGroups(Collection collection) throws Exception {
try (Context c = new Context()) {
c.turnOffAuthorisationSystem();
for (int i = 1; i <= 3; i++) {
Group g = collectionService.getWorkflowGroup(c, collection, i);
if (g != null) {
Group attachedDso = c.reloadEntity(g);
if (attachedDso != null) {
collectionService.setWorkflowGroup(c, collection, i, null);
groupService.delete(c, attachedDso);
}
}
}
c.complete();
}
indexingService.commit();
}
@Override
protected DSpaceObjectService<Collection> getService() {
return collectionService;

View File

@@ -0,0 +1,185 @@
/**
* 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.builder;
import java.io.InputStream;
import org.dspace.content.Bitstream;
import org.dspace.content.Collection;
import org.dspace.content.DCDate;
import org.dspace.content.Item;
import org.dspace.content.LicenseUtils;
import org.dspace.content.MetadataSchema;
import org.dspace.content.WorkspaceItem;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
import org.dspace.xmlworkflow.storedcomponents.service.XmlWorkflowItemService;
/**
* Builder to construct WorkflowItem objects
*
**/
public class WorkflowItemBuilder extends AbstractBuilder<XmlWorkflowItem, XmlWorkflowItemService> {
private WorkspaceItem workspaceItem;
private XmlWorkflowItem workflowItem;
protected WorkflowItemBuilder(Context context) {
super(context);
}
/**
* Create a WorkflowItemBuilder. Until the build is finalized the builder works on a workspaceitem to add metadata,
* files, grant license, etc. The builder could result in a null workflowItem if the selected collection doesn't
* have a workflow enabled
*
* @param context
* the dspace context
* @param col
* the collection where the submission will occur
* @return a WorkflowItemBuilder
*/
public static WorkflowItemBuilder createWorkflowItem(final Context context, final Collection col) {
WorkflowItemBuilder builder = new WorkflowItemBuilder(context);
return builder.create(context, col);
}
private WorkflowItemBuilder create(final Context context, final Collection col) {
this.context = context;
try {
workspaceItem = workspaceItemService.create(context, col, false);
} catch (Exception e) {
return handleException(e);
}
return this;
}
@Override
public XmlWorkflowItem build() {
try {
workflowItem = workflowService.start(context, workspaceItem);
workspaceItem = null;
return workflowItem;
} catch (Exception e) {
return handleException(e);
}
}
@Override
public void delete(XmlWorkflowItem dso) throws Exception {
try (Context c = new Context()) {
c.turnOffAuthorisationSystem();
XmlWorkflowItem attachedDso = c.reloadEntity(dso);
if (attachedDso != null) {
getService().delete(c, attachedDso);
}
c.complete();
}
indexingService.commit();
}
private void deleteWsi(WorkspaceItem dso) throws Exception {
try (Context c = new Context()) {
c.turnOffAuthorisationSystem();
WorkspaceItem attachedDso = c.reloadEntity(dso);
if (attachedDso != null) {
workspaceItemService.deleteAll(c, attachedDso);
}
c.complete();
}
indexingService.commit();
}
@Override
protected void cleanup() throws Exception {
if (workspaceItem != null) {
deleteWsi(workspaceItem);
}
if (workflowItem != null) {
delete(workflowItem);
}
}
@Override
protected XmlWorkflowItemService getService() {
return workflowItemService;
}
protected WorkflowItemBuilder addMetadataValue(final String schema,
final String element, final String qualifier, final String value) {
try {
itemService.addMetadata(context, workspaceItem.getItem(), schema, element, qualifier, Item.ANY, value);
} catch (Exception e) {
return handleException(e);
}
return this;
}
protected WorkflowItemBuilder setMetadataSingleValue(final String schema,
final String element, final String qualifier, final String value) {
try {
itemService.setMetadataSingleValue(context, workspaceItem.getItem(), schema, element, qualifier, Item.ANY,
value);
} catch (Exception e) {
return handleException(e);
}
return this;
}
public WorkflowItemBuilder withTitle(final String title) {
return setMetadataSingleValue(MetadataSchema.DC_SCHEMA, "title", null, title);
}
public WorkflowItemBuilder withIssueDate(final String issueDate) {
return addMetadataValue(MetadataSchema.DC_SCHEMA, "date", "issued", new DCDate(issueDate).toString());
}
public WorkflowItemBuilder withAuthor(final String authorName) {
return addMetadataValue(MetadataSchema.DC_SCHEMA, "contributor", "author", authorName);
}
public WorkflowItemBuilder withSubject(final String subject) {
return addMetadataValue(MetadataSchema.DC_SCHEMA, "subject", null, subject);
}
public WorkflowItemBuilder grantLicense() {
Item item = workspaceItem.getItem();
String license;
try {
EPerson submitter = workspaceItem.getSubmitter();
submitter = context.reloadEntity(submitter);
license = LicenseUtils.getLicenseText(context.getCurrentLocale(), workspaceItem.getCollection(), item,
submitter);
LicenseUtils.grantLicense(context, item, license, null);
} catch (Exception e) {
handleException(e);
}
return this;
}
public WorkflowItemBuilder withFulltext(String name, String source, InputStream is) {
try {
Item item = workspaceItem.getItem();
Bitstream b = itemService.createSingleBitstream(context, is, item);
b.setName(context, name);
b.setSource(context, source);
} catch (Exception e) {
handleException(e);
}
return this;
}
}

View File

@@ -0,0 +1,113 @@
/**
* 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.matcher;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasNoJsonPath;
import static org.dspace.app.rest.test.AbstractControllerIntegrationTest.REST_SERVER_URL;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
import org.hamcrest.Matcher;
/**
* Utility class to construct a Matcher for a Workflow item
*
* @author Andrea Bollini (andrea.bollini at 4science.it)
*/
public class WorkflowItemMatcher {
private WorkflowItemMatcher() { }
/**
* Check if the returned json expose all the required links and properties and the title and dateIssued are present
* in the traditionalpageone section as by the default configuration (form-submission.xml)
*
* @param witem
* the workflowitem
* @param title
* the dc.title
* @param dateIssued
* the dc.date.issued
* @return
*/
public static Matcher matchItemWithTitleAndDateIssued(XmlWorkflowItem witem, String title,
String dateIssued) {
return allOf(
// Check workflowitem properties
matchProperties(witem),
// Check core metadata all appear in the first describe panel "traditionalpageone"
hasJsonPath("$.sections.traditionalpageone['dc.title'][0].value", is(title)),
hasJsonPath("$.sections.traditionalpageone['dc.date.issued'][0].value", is(dateIssued)),
// Check links
matchLinks(witem));
}
/**
* Check if the returned json expose all the required links and properties and the title and dateIssued are present
* in the traditionalpageone section and the subject in the traditionalpagetwo section as by the default
* configuration (form-submission.xml)
*
* @param witem
* the workflowitem
* @param title
* the dc.title
* @param dateIssued
* the dc.date.issued * @param subject the dc.subject
*
* @return
*/
public static Matcher matchItemWithTitleAndDateIssuedAndSubject(XmlWorkflowItem witem, String title,
String dateIssued,
String subject) {
return allOf(
// Check workspaceitem properties
matchProperties(witem),
// Check core metadata all appear in the first describe panel "traditionalpageone"
title != null ?
hasJsonPath("$.sections.traditionalpageone['dc.title'][0].value", is(title)) :
hasNoJsonPath("$.sections.traditionalpageone['dc.title']"),
hasJsonPath("$.sections.traditionalpageone['dc.date.issued'][0].value", is(dateIssued)),
// Check keywords they appear in the second describe panel "traditionalpagetwo"
hasJsonPath("$.sections.traditionalpagetwo['dc.subject'][0].value", is(subject)),
// Check links
matchLinks(witem));
}
/**
* Check that the id and type are exposed
*
* @param witem
* the workflowitem
* @return
*/
public static Matcher<? super Object> matchProperties(XmlWorkflowItem witem) {
return allOf(
hasJsonPath("$.id", is(witem.getID())),
hasJsonPath("$.type", is("workflowitem"))
);
}
/**
* Check that the required links are present
*
* @param witem
* the workflowitem
* @return
*/
public static Matcher<? super Object> matchLinks(XmlWorkflowItem witem) {
return allOf(
hasJsonPath("$._links.self.href", is(REST_SERVER_URL + "workflow/workflowitems/" + witem.getID())),
hasJsonPath("$._links.item.href", startsWith(REST_SERVER_URL)),
hasJsonPath("$._links.collection.href", startsWith(REST_SERVER_URL)),
hasJsonPath("$._links.submitter.href", startsWith(REST_SERVER_URL)),
hasJsonPath("$._links.submissionDefinition.href", startsWith(REST_SERVER_URL)));
}
}