DS-3851 community feedback: code cleanup

This commit is contained in:
Andrea Bollini
2019-03-14 23:49:35 +01:00
parent 3e22142aa7
commit 19606943b1
22 changed files with 290 additions and 549 deletions

View File

@@ -462,13 +462,6 @@ public class BitstreamServiceImpl extends DSpaceObjectServiceImpl<Bitstream> imp
return bitstreamDAO.getNotReferencedBitstreams(context);
}
@Override
public void addMetadata(Context context, Bitstream dso, MetadataField metadataField, String lang,
List<String> values, List<String> authorities, List<Integer> confidences)
throws SQLException {
addMetadata(context, dso, metadataField, lang, values, authorities, confidences, null);
}
public Long getLastModified(Bitstream bitstream) {
return bitstreamStorageService.getLastModified(bitstream);
}

View File

@@ -372,7 +372,7 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
log.error(LogManager.getHeader(context, "setWorkflowGroup",
"collection_id=" + collection.getID() + " " + e.getMessage()), e);
}
if (!StringUtils.equals("default", workflow.getID())) {
if (!StringUtils.equals(XmlWorkflowFactory.LEGACY_WORKFLOW_NAME, workflow.getID())) {
throw new IllegalArgumentException(
"setWorkflowGroup can be used only on collection with the default basic dspace workflow. "
+ "Instead, the collection: "

View File

@@ -231,7 +231,7 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
@Override
public void addMetadata(Context context, T dso, MetadataField metadataField, String lang, List<String> values,
List<String> authorities, List<Integer> confidences, List<Integer> places)
List<String> authorities, List<Integer> confidences)
throws SQLException {
boolean authorityControlled = metadataAuthorityService.isAuthorityControlled(metadataField);
boolean authorityRequired = metadataAuthorityService.isAuthorityRequired(metadataField);
@@ -703,15 +703,4 @@ public abstract class DSpaceObjectServiceImpl<T extends DSpaceObject> implements
}
}
@Override
public void addMetadata(Context context, T dso, MetadataField metadataField, String lang, List<String> values,
List<String> authorities, List<Integer> confidences) throws SQLException {
addMetadata(context, dso, metadataField, lang, values, authorities, confidences, null);
}
@Override
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, String value,
String authority, int confidence, int place) throws SQLException {
addMetadata(context, dso, metadataField, language, value, authority, confidence);
}
}

View File

@@ -10,7 +10,6 @@ package org.dspace.content;
import java.io.Serializable;
import java.sql.SQLException;
import org.dspace.authorize.AuthorizeException;
import org.dspace.browse.BrowsableObject;
import org.dspace.eperson.EPerson;
@@ -29,11 +28,6 @@ public interface InProgressSubmission<ID extends Serializable> extends Browsable
*/
ID getID();
/**
* Update the submission, including the unarchived item.
*/
void update() throws SQLException, AuthorizeException;
/**
* Get the incomplete item object
*

View File

@@ -27,9 +27,7 @@ import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.dspace.authorize.AuthorizeException;
import org.dspace.browse.BrowsableObject;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.ReloadableEntity;
@@ -245,20 +243,6 @@ public class WorkspaceItem
supervisorGroups.add(group);
}
@Override
public void update() throws SQLException, AuthorizeException {
Context context = null;
try {
context = new Context();
ContentServiceFactory.getInstance().getWorkspaceItemService().update(context, this);
} finally {
if (context != null && context.isValid()) {
context.abort();
}
}
}
@Override
public int getType() {
return Constants.WORKSPACEITEM;

View File

@@ -239,26 +239,6 @@ public interface DSpaceObjectService<T extends DSpaceObject> extends BrowsableOb
public void addMetadata(Context context, T dso, MetadataField metadataField, String lang, List<String> values,
List<String> authorities, List<Integer> confidences) throws SQLException;
/**
* Add metadata fields. These are appended to existing values.
* Use <code>clearDC</code> to remove values. The values are insert in the
* positions passed in the places argument.
*
* @param context DSpace context
* @param dso DSpaceObject
* @param metadataField the metadata field to which the value is to be set
* @param lang the ISO639 language code, optionally followed by an underscore
* and the ISO3166 country code. <code>null</code> means the
* value has no language (for example, a date).
* @param values the values to add.
* @param authorities the external authority key for this value (or null)
* @param confidences the authority confidence (default 0)
* @param places the places to use for the supplied values
* @throws SQLException if database error
*/
public void addMetadata(Context context, T dso, MetadataField metadataField, String lang, List<String> values,
List<String> authorities, List<Integer> confidences, List<Integer> places) throws SQLException;
/**
* Shortcut for {@link #addMetadata(Context, DSpaceObject, MetadataField, String, List, List, List)} when a single
* value need to be added
@@ -275,23 +255,6 @@ public interface DSpaceObjectService<T extends DSpaceObject> extends BrowsableOb
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, String value,
String authority, int confidence) throws SQLException;
/**
* Shortcut for {@link #addMetadata(Context, DSpaceObject, MetadataField, String, List, List, List, List)} when a
* single value need to be added
*
* @param context
* @param dso
* @param metadataField
* @param language
* @param value
* @param authority
* @param confidence
* @param place
* @throws SQLException
*/
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, String value,
String authority, int confidence, int place) throws SQLException;
public void addMetadata(Context context, T dso, MetadataField metadataField, String language, String value)
throws SQLException;

View File

@@ -21,14 +21,12 @@ import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.workflow.WorkflowItem;
import org.dspace.workflow.factory.WorkflowServiceFactory;
/**
* Class representing an item going through the workflow process in DSpace
@@ -188,20 +186,6 @@ public class BasicWorkflowItem implements WorkflowItem {
this.publishedBefore = b;
}
@Override
public void update() throws SQLException, AuthorizeException {
Context context = null;
try {
context = new Context();
WorkflowServiceFactory.getInstance().getWorkflowItemService().update(context, this);
} finally {
if (context != null && context.isValid()) {
context.abort();
}
}
}
@Override
public int getType() {
return Constants.WORKFLOWITEM;

View File

@@ -668,6 +668,8 @@ public class XmlWorkflowServiceImpl implements XmlWorkflowService {
removeUserItemPolicies(c, wi.getItem(), task.getOwner());
claimedTaskService.delete(c, task);
}
c.addEvent(new Event(Event.MODIFY, Constants.ITEM, wi.getItem().getID(), null,
itemService.getIdentifiers(c, wi.getItem())));
}
/*
@@ -1058,17 +1060,10 @@ public class XmlWorkflowServiceImpl implements XmlWorkflowService {
}
protected void revokeReviewerPolicies(Context context, Item item) throws SQLException, AuthorizeException {
// get bundle "ORIGINAL"
Bundle originalBundle;
try {
originalBundle = itemService.getBundles(item, "ORIGINAL").get(0);
} catch (IndexOutOfBoundsException ex) {
originalBundle = null;
}
List<Bundle> bundles = item.getBundles();
for (Bundle originalBundle : bundles) {
// remove bitstream and bundle level policies
if (originalBundle != null) {
// We added policies for Bitstreams of the bundle "original" only
for (Bitstream bitstream : originalBundle.getBitstreams()) {
authorizeService.removeAllPoliciesByDSOAndType(context, bitstream, ResourcePolicy.TYPE_WORKFLOW);
}

View File

@@ -28,6 +28,8 @@ import org.dspace.xmlworkflow.state.actions.WorkflowActionConfig;
*/
public interface XmlWorkflowFactory {
public final String LEGACY_WORKFLOW_NAME = "default";
public Workflow getWorkflow(Collection collection) throws IOException, WorkflowConfigurationException, SQLException;
public Step createStep(Workflow workflow, String stepID) throws WorkflowConfigurationException, IOException;

View File

@@ -7,9 +7,6 @@
*/
package org.dspace.xmlworkflow.storedcomponents;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@@ -20,7 +17,6 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.dspace.browse.BrowsableObject;
import org.dspace.core.Constants;
@@ -40,9 +36,6 @@ import org.dspace.eperson.EPerson;
@Table(name = "cwf_claimtask")
public class ClaimedTask implements ReloadableEntity<Integer>, BrowsableObject<Integer> {
@Transient
public transient Map<String, Object> extraInfo = new HashMap<String, Object>();
@Id
@Column(name = "claimtask_id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cwf_claimtask_seq")

View File

@@ -7,9 +7,6 @@
*/
package org.dspace.xmlworkflow.storedcomponents;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@@ -21,7 +18,6 @@ import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.dspace.browse.BrowsableObject;
import org.dspace.core.Constants;
@@ -42,9 +38,6 @@ import org.dspace.eperson.Group;
@Table(name = "cwf_pooltask")
public class PoolTask implements ReloadableEntity<Integer>, BrowsableObject<Integer> {
@Transient
public transient Map<String, Object> extraInfo = new HashMap<String, Object>();
@Id
@Column(name = "pooltask_id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cwf_pooltask_seq")

View File

@@ -21,7 +21,6 @@ import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.dspace.authorize.AuthorizeException;
import org.dspace.browse.BrowsableObject;
import org.dspace.content.Collection;
import org.dspace.content.Item;
@@ -30,7 +29,6 @@ import org.dspace.core.Context;
import org.dspace.core.ReloadableEntity;
import org.dspace.eperson.EPerson;
import org.dspace.workflow.WorkflowItem;
import org.dspace.workflow.factory.WorkflowServiceFactory;
/**
* Class representing an item going through the workflow process in DSpace
@@ -139,20 +137,6 @@ public class XmlWorkflowItem implements WorkflowItem, ReloadableEntity<Integer>,
this.publishedBefore = b;
}
@Override
public void update() throws SQLException, AuthorizeException {
Context context = null;
try {
context = new Context();
WorkflowServiceFactory.getInstance().getWorkflowItemService().update(context, this);
} finally {
if (context != null && context.isValid()) {
context.abort();
}
}
}
@Override
public int getState() {
// FIXME not used by the xml workflow, should be removed when the basic workflow is removed and the interfaces

View File

@@ -0,0 +1,153 @@
/**
* 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.converter;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.dspace.app.rest.model.AInprogressSubmissionRest;
import org.dspace.app.rest.model.ErrorRest;
import org.dspace.app.rest.model.SubmissionDefinitionRest;
import org.dspace.app.rest.model.SubmissionSectionRest;
import org.dspace.app.rest.submit.AbstractRestProcessingStep;
import org.dspace.app.rest.submit.SubmissionService;
import org.dspace.app.util.SubmissionConfigReader;
import org.dspace.app.util.SubmissionConfigReaderException;
import org.dspace.app.util.SubmissionStepConfig;
import org.dspace.content.Collection;
import org.dspace.content.InProgressSubmission;
import org.dspace.content.Item;
import org.dspace.eperson.EPerson;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Abstract implementation providing the common functionalities for all the inprogressSubmission Converter
*
* @author Andrea Bollini (andrea.bollini at 4science.it)
*
* @param <T>
* the DSpace API inprogressSubmission object
* @param <R>
* the DSpace REST inprogressSubmission representation
* @param <ID>
* the Serializable class used as primary key
*/
public abstract class AInprogressItemConverter<T extends InProgressSubmission<ID>,
R extends AInprogressSubmissionRest<ID>, ID extends Serializable>
extends BrowsableDSpaceObjectConverter<T, R> {
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(AInprogressItemConverter.class);
@Autowired
private EPersonConverter epersonConverter;
@Autowired
private ItemConverter itemConverter;
@Autowired
private CollectionConverter collectionConverter;
protected SubmissionConfigReader submissionConfigReader;
@Autowired
private SubmissionDefinitionConverter submissionDefinitionConverter;
@Autowired
private SubmissionSectionConverter submissionSectionConverter;
@Autowired
SubmissionService submissionService;
public AInprogressItemConverter() throws SubmissionConfigReaderException {
submissionConfigReader = new SubmissionConfigReader();
}
protected void fillFromModel(T obj, R witem) {
Collection collection = obj.getCollection();
Item item = obj.getItem();
EPerson submitter = null;
try {
submitter = obj.getSubmitter();
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
witem.setId(obj.getID());
witem.setCollection(collection != null ? collectionConverter.convert(collection) : null);
witem.setItem(itemConverter.convert(item));
witem.setSubmitter(epersonConverter.convert(submitter));
// 1. retrieve the submission definition
// 2. iterate over the submission section to allow to plugin additional
// info
if (collection != null) {
SubmissionDefinitionRest def = submissionDefinitionConverter
.convert(submissionConfigReader.getSubmissionConfigByCollection(collection.getHandle()));
witem.setSubmissionDefinition(def);
for (SubmissionSectionRest sections : def.getPanels()) {
SubmissionStepConfig stepConfig = submissionSectionConverter.toModel(sections);
/*
* First, load the step processing class (using the current
* class loader)
*/
ClassLoader loader = this.getClass().getClassLoader();
Class stepClass;
try {
stepClass = loader.loadClass(stepConfig.getProcessingClassName());
Object stepInstance = stepClass.newInstance();
if (stepInstance instanceof AbstractRestProcessingStep) {
// load the interface for this step
AbstractRestProcessingStep stepProcessing =
(AbstractRestProcessingStep) stepClass.newInstance();
for (ErrorRest error : stepProcessing.validate(submissionService, obj, stepConfig)) {
addError(witem.getErrors(), error);
}
witem.getSections()
.put(sections.getId(), stepProcessing.getData(submissionService, obj, stepConfig));
} else {
log.warn("The submission step class specified by '" + stepConfig.getProcessingClassName() +
"' does not extend the class org.dspace.app.rest.submit.AbstractRestProcessingStep!" +
" Therefore it cannot be used by the Configurable Submission as the " +
"<processing-class>!");
}
} catch (Exception e) {
log.error("An error occurred during the unmarshal of the data for the section " + sections.getId()
+ " - reported error: " + e.getMessage(), e);
}
}
}
}
private void addError(List<ErrorRest> errors, ErrorRest toAdd) {
boolean found = false;
String i18nKey = toAdd.getMessage();
if (StringUtils.isNotBlank(i18nKey)) {
for (ErrorRest error : errors) {
if (i18nKey.equals(error.getMessage())) {
error.getPaths().addAll(toAdd.getPaths());
found = true;
break;
}
}
}
if (!found) {
errors.add(toAdd);
}
}
}

View File

@@ -7,7 +7,6 @@
*/
package org.dspace.app.rest.converter;
import org.apache.log4j.Logger;
import org.dspace.app.rest.model.ClaimedTaskRest;
import org.dspace.browse.BrowsableObject;
import org.dspace.xmlworkflow.storedcomponents.ClaimedTask;
@@ -25,11 +24,12 @@ import org.springframework.stereotype.Component;
public class ClaimedTaskConverter
extends BrowsableDSpaceObjectConverter<ClaimedTask, org.dspace.app.rest.model.ClaimedTaskRest> {
private static final Logger log = Logger.getLogger(ClaimedTaskConverter.class);
@Autowired
private WorkflowItemConverter workflowItemConverter;
@Autowired
private EPersonConverter epersonConverter;
@Override
public ClaimedTaskRest fromModel(ClaimedTask obj) {
ClaimedTaskRest taskRest = new ClaimedTaskRest();
@@ -39,6 +39,7 @@ public class ClaimedTaskConverter
taskRest.setWorkflowitem(workflowItemConverter.convert(witem));
taskRest.setAction(obj.getActionID());
taskRest.setStep(obj.getStepID());
taskRest.setOwner(epersonConverter.convert(obj.getOwner()));
return taskRest;
}

View File

@@ -7,26 +7,10 @@
*/
package org.dspace.app.rest.converter;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.dspace.app.rest.model.ErrorRest;
import org.dspace.app.rest.model.SubmissionDefinitionRest;
import org.dspace.app.rest.model.SubmissionSectionRest;
import org.dspace.app.rest.model.WorkflowItemRest;
import org.dspace.app.rest.submit.AbstractRestProcessingStep;
import org.dspace.app.rest.submit.SubmissionService;
import org.dspace.app.util.SubmissionConfigReader;
import org.dspace.app.util.SubmissionConfigReaderException;
import org.dspace.app.util.SubmissionStepConfig;
import org.dspace.browse.BrowsableObject;
import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.eperson.EPerson;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
@@ -38,95 +22,16 @@ import org.springframework.stereotype.Component;
*/
@Component
public class WorkflowItemConverter
extends BrowsableDSpaceObjectConverter<XmlWorkflowItem, org.dspace.app.rest.model.WorkflowItemRest> {
private static final Logger log = Logger.getLogger(WorkflowItemConverter.class);
@Autowired
private EPersonConverter epersonConverter;
@Autowired
private ItemConverter itemConverter;
@Autowired
private CollectionConverter collectionConverter;
private SubmissionConfigReader submissionConfigReader;
@Autowired
private SubmissionDefinitionConverter submissionDefinitionConverter;
@Autowired
private SubmissionSectionConverter submissionSectionConverter;
@Autowired
SubmissionService submissionService;
extends AInprogressItemConverter<XmlWorkflowItem, org.dspace.app.rest.model.WorkflowItemRest, Integer> {
public WorkflowItemConverter() throws SubmissionConfigReaderException {
submissionConfigReader = new SubmissionConfigReader();
super();
}
@Override
public WorkflowItemRest fromModel(XmlWorkflowItem obj) {
WorkflowItemRest witem = new WorkflowItemRest();
Collection collection = obj.getCollection();
Item item = obj.getItem();
EPerson submitter = null;
try {
submitter = obj.getSubmitter();
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
witem.setId(obj.getID());
witem.setCollection(collection != null ? collectionConverter.convert(collection) : null);
witem.setItem(itemConverter.convert(item));
witem.setSubmitter(epersonConverter.convert(submitter));
// 1. retrieve the submission definition
// 2. iterate over the submission section to allow to plugin additional
// info
if (collection != null) {
SubmissionDefinitionRest def = submissionDefinitionConverter
.convert(submissionConfigReader.getSubmissionConfigByCollection(collection.getHandle()));
witem.setSubmissionDefinition(def);
for (SubmissionSectionRest sections : def.getPanels()) {
SubmissionStepConfig stepConfig = submissionSectionConverter.toModel(sections);
/*
* First, load the step processing class (using the current
* class loader)
*/
ClassLoader loader = this.getClass().getClassLoader();
Class stepClass;
try {
stepClass = loader.loadClass(stepConfig.getProcessingClassName());
Object stepInstance = stepClass.newInstance();
if (stepInstance instanceof AbstractRestProcessingStep) {
// load the interface for this step
AbstractRestProcessingStep stepProcessing =
(AbstractRestProcessingStep) stepClass.newInstance();
for (ErrorRest error : stepProcessing.validate(submissionService, obj, stepConfig)) {
addError(witem.getErrors(), error);
}
witem.getSections()
.put(sections.getId(), stepProcessing.getData(submissionService, obj, stepConfig));
} else {
log.warn("The submission step class specified by '" + stepConfig.getProcessingClassName() +
"' does not extend the class org.dspace.app.rest.submit.AbstractRestProcessingStep!" +
" Therefore it cannot be used by the Configurable Submission as the " +
"<processing-class>!");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
fillFromModel(obj, witem);
return witem;
}
@@ -135,25 +40,6 @@ public class WorkflowItemConverter
return null;
}
private void addError(List<ErrorRest> errors, ErrorRest toAdd) {
boolean found = false;
String i18nKey = toAdd.getMessage();
if (StringUtils.isNotBlank(i18nKey)) {
for (ErrorRest error : errors) {
if (i18nKey.equals(error.getMessage())) {
error.getPaths().addAll(toAdd.getPaths());
found = true;
break;
}
}
}
if (!found) {
errors.add(toAdd);
}
}
@Override
public boolean supportsModel(BrowsableObject object) {
return object instanceof XmlWorkflowItem;

View File

@@ -7,24 +7,10 @@
*/
package org.dspace.app.rest.converter;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.dspace.app.rest.model.ErrorRest;
import org.dspace.app.rest.model.SubmissionDefinitionRest;
import org.dspace.app.rest.model.SubmissionSectionRest;
import org.dspace.app.rest.model.WorkspaceItemRest;
import org.dspace.app.rest.submit.AbstractRestProcessingStep;
import org.dspace.app.rest.submit.SubmissionService;
import org.dspace.app.util.SubmissionConfigReader;
import org.dspace.app.util.SubmissionConfigReaderException;
import org.dspace.app.util.SubmissionStepConfig;
import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.eperson.EPerson;
import org.springframework.beans.factory.annotation.Autowired;
import org.dspace.browse.BrowsableObject;
import org.dspace.content.WorkspaceItem;
import org.springframework.stereotype.Component;
/**
@@ -35,95 +21,17 @@ import org.springframework.stereotype.Component;
*/
@Component
public class WorkspaceItemConverter
extends DSpaceConverter<org.dspace.content.WorkspaceItem, org.dspace.app.rest.model.WorkspaceItemRest> {
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(WorkspaceItemConverter.class);
@Autowired
private EPersonConverter epersonConverter;
@Autowired
private ItemConverter itemConverter;
@Autowired
private CollectionConverter collectionConverter;
private SubmissionConfigReader submissionConfigReader;
@Autowired
private SubmissionDefinitionConverter submissionDefinitionConverter;
@Autowired
private SubmissionSectionConverter submissionSectionConverter;
@Autowired
SubmissionService submissionService;
extends AInprogressItemConverter<WorkspaceItem, WorkspaceItemRest, Integer> {
public WorkspaceItemConverter() throws SubmissionConfigReaderException {
submissionConfigReader = new SubmissionConfigReader();
super();
}
@Override
public WorkspaceItemRest fromModel(org.dspace.content.WorkspaceItem obj) {
WorkspaceItemRest witem = new WorkspaceItemRest();
Collection collection = obj.getCollection();
Item item = obj.getItem();
EPerson submitter = null;
try {
submitter = obj.getSubmitter();
} catch (SQLException e) {
throw new RuntimeException(e.getMessage(), e);
}
witem.setId(obj.getID());
witem.setCollection(collection != null ? collectionConverter.convert(collection) : null);
witem.setItem(itemConverter.convert(item));
witem.setSubmitter(epersonConverter.convert(submitter));
// 1. retrieve the submission definition
// 2. iterate over the submission section to allow to plugin additional
// info
if (collection != null) {
SubmissionDefinitionRest def = submissionDefinitionConverter
.convert(submissionConfigReader.getSubmissionConfigByCollection(collection.getHandle()));
witem.setSubmissionDefinition(def);
for (SubmissionSectionRest sections : def.getPanels()) {
SubmissionStepConfig stepConfig = submissionSectionConverter.toModel(sections);
/*
* First, load the step processing class (using the current
* class loader)
*/
ClassLoader loader = this.getClass().getClassLoader();
Class stepClass;
try {
stepClass = loader.loadClass(stepConfig.getProcessingClassName());
Object stepInstance = stepClass.newInstance();
if (stepInstance instanceof AbstractRestProcessingStep) {
// load the interface for this step
AbstractRestProcessingStep stepProcessing =
(AbstractRestProcessingStep) stepClass.newInstance();
for (ErrorRest error : stepProcessing.validate(submissionService, obj, stepConfig)) {
addError(witem.getErrors(), error);
}
witem.getSections()
.put(sections.getId(), stepProcessing.getData(submissionService, obj, stepConfig));
} else {
log.warn("The submission step class specified by '" + stepConfig.getProcessingClassName() +
"' does not extend the class org.dspace.app.rest.submit.AbstractRestProcessingStep!" +
" Therefore it cannot be used by the Configurable Submission as the " +
"<processing-class>!");
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
fillFromModel(obj, witem);
return witem;
}
@@ -132,22 +40,8 @@ public class WorkspaceItemConverter
return null;
}
private void addError(List<ErrorRest> errors, ErrorRest toAdd) {
boolean found = false;
String i18nKey = toAdd.getMessage();
if (StringUtils.isNotBlank(i18nKey)) {
for (ErrorRest error : errors) {
if (i18nKey.equals(error.getMessage())) {
error.getPaths().addAll(toAdd.getPaths());
found = true;
break;
}
}
}
if (!found) {
errors.add(toAdd);
}
@Override
public boolean supportsModel(BrowsableObject object) {
return object instanceof WorkspaceItem;
}
}

View File

@@ -0,0 +1,93 @@
/**
* 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.model;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* Abstract class to share common aspects between the REST representation of inprogressSubmission
*
* @author Andrea Bollini (andrea.bollini at 4science.it)
*
* @param <T>
* the serializable class used as primary key
*/
public abstract class AInprogressSubmissionRest<T extends Serializable> extends BaseObjectRest<T> {
private Date lastModified = new Date();
private Map<String, Serializable> sections;
@JsonIgnore
private CollectionRest collection;
@JsonIgnore
private ItemRest item;
@JsonIgnore
private SubmissionDefinitionRest submissionDefinition;
@JsonIgnore
private EPersonRest submitter;
public AInprogressSubmissionRest() {
super();
}
public Date getLastModified() {
return lastModified;
}
public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}
public ItemRest getItem() {
return item;
}
public void setItem(ItemRest item) {
this.item = item;
}
public SubmissionDefinitionRest getSubmissionDefinition() {
return submissionDefinition;
}
public void setSubmissionDefinition(SubmissionDefinitionRest submissionDefinition) {
this.submissionDefinition = submissionDefinition;
}
public EPersonRest getSubmitter() {
return submitter;
}
public void setSubmitter(EPersonRest submitter) {
this.submitter = submitter;
}
public Map<String, Serializable> getSections() {
if (sections == null) {
sections = new HashMap<String, Serializable>();
}
return sections;
}
public void setSections(Map<String, Serializable> sections) {
this.sections = sections;
}
public CollectionRest getCollection() {
return collection;
}
public void setCollection(CollectionRest collection) {
this.collection = collection;
}
}

View File

@@ -24,6 +24,9 @@ public class ClaimedTaskRest extends BaseObjectRest<Integer> {
private String action;
@JsonIgnore
private EPersonRest owner;
@JsonIgnore
private WorkflowItemRest workflowitem;
@@ -66,6 +69,18 @@ public class ClaimedTaskRest extends BaseObjectRest<Integer> {
this.action = action;
}
/**
* @see ClaimedTaskRest#getOwner()
* @return the owner of the task
*/
public EPersonRest getOwner() {
return owner;
}
public void setOwner(EPersonRest owner) {
this.owner = owner;
}
/**
*
* @return the WorkflowItemRest that belong to this claimed task

View File

@@ -7,12 +7,6 @@
*/
package org.dspace.app.rest.model;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.dspace.app.rest.RestResourceController;
/**
@@ -20,26 +14,10 @@ import org.dspace.app.rest.RestResourceController;
*
* @author Andrea Bollini (andrea.bollini at 4science.it)
*/
public class WorkflowItemRest extends BaseObjectRest<Integer> {
public class WorkflowItemRest extends AInprogressSubmissionRest<Integer> {
public static final String NAME = "workflowitem";
public static final String CATEGORY = RestAddressableModel.WORKFLOW;
private Date lastModified = new Date();
private Map<String, Serializable> sections;
@JsonIgnore
private CollectionRest collection;
@JsonIgnore
private ItemRest item;
@JsonIgnore
private SubmissionDefinitionRest submissionDefinition;
@JsonIgnore
private EPersonRest submitter;
@Override
public String getCategory() {
return CATEGORY;
@@ -50,83 +28,8 @@ public class WorkflowItemRest extends BaseObjectRest<Integer> {
return NAME;
}
/**
*
* @return the timestamp of the last modification done to the workflowitem
*/
public Date getLastModified() {
return lastModified;
}
public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}
/**
*
* @return the item wrapped by the workflowitem
*/
public ItemRest getItem() {
return item;
}
public void setItem(ItemRest item) {
this.item = item;
}
/**
*
* @return the SubmissionDefinition used by the workflowitem
*/
public SubmissionDefinitionRest getSubmissionDefinition() {
return submissionDefinition;
}
public void setSubmissionDefinition(SubmissionDefinitionRest submissionDefinition) {
this.submissionDefinition = submissionDefinition;
}
/**
*
* @return the submitter
*/
public EPersonRest getSubmitter() {
return submitter;
}
public void setSubmitter(EPersonRest submitter) {
this.submitter = submitter;
}
@Override
public Class getController() {
return RestResourceController.class;
}
/**
*
* @return the data of the workflowitem organized according to the submission definition
*/
public Map<String, Serializable> getSections() {
if (sections == null) {
sections = new HashMap<String, Serializable>();
}
return sections;
}
public void setSections(Map<String, Serializable> sections) {
this.sections = sections;
}
/**
*
* @return the collection where the workflow is in progress
*/
public CollectionRest getCollection() {
return collection;
}
public void setCollection(CollectionRest collection) {
this.collection = collection;
}
}

View File

@@ -7,12 +7,6 @@
*/
package org.dspace.app.rest.model;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.dspace.app.rest.RestResourceController;
/**
@@ -20,26 +14,10 @@ import org.dspace.app.rest.RestResourceController;
*
* @author Andrea Bollini (andrea.bollini at 4science.it)
*/
public class WorkspaceItemRest extends BaseObjectRest<Integer> {
public class WorkspaceItemRest extends AInprogressSubmissionRest<Integer> {
public static final String NAME = "workspaceitem";
public static final String CATEGORY = RestAddressableModel.SUBMISSION;
private Date lastModified = new Date();
private Map<String, Serializable> sections;
@JsonIgnore
private CollectionRest collection;
@JsonIgnore
private ItemRest item;
@JsonIgnore
private SubmissionDefinitionRest submissionDefinition;
@JsonIgnore
private EPersonRest submitter;
@Override
public String getCategory() {
return CATEGORY;
@@ -50,59 +28,8 @@ public class WorkspaceItemRest extends BaseObjectRest<Integer> {
return NAME;
}
public Date getLastModified() {
return lastModified;
}
public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}
public ItemRest getItem() {
return item;
}
public void setItem(ItemRest item) {
this.item = item;
}
public SubmissionDefinitionRest getSubmissionDefinition() {
return submissionDefinition;
}
public void setSubmissionDefinition(SubmissionDefinitionRest submissionDefinition) {
this.submissionDefinition = submissionDefinition;
}
public EPersonRest getSubmitter() {
return submitter;
}
public void setSubmitter(EPersonRest submitter) {
this.submitter = submitter;
}
@Override
public Class getController() {
return RestResourceController.class;
}
public Map<String, Serializable> getSections() {
if (sections == null) {
sections = new HashMap<String, Serializable>();
}
return sections;
}
public void setSections(Map<String, Serializable> sections) {
this.sections = sections;
}
public CollectionRest getCollection() {
return collection;
}
public void setCollection(CollectionRest collection) {
this.collection = collection;
}
}

View File

@@ -28,11 +28,9 @@ import org.dspace.app.rest.model.PoolTaskRest;
import org.dspace.app.rest.model.hateoas.ClaimedTaskResource;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.service.ItemService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.service.EPersonService;
import org.dspace.event.Event;
import org.dspace.workflow.WorkflowException;
import org.dspace.xmlworkflow.WorkflowConfigurationException;
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
@@ -136,10 +134,6 @@ public class ClaimedTaskRestRepository extends DSpaceRestRepository<ClaimedTaskR
throw new UnprocessableEntityException(
"Missing required fields: " + StringUtils.join(Action.getErrorFields(request), ","));
}
// workflowRequirementsService.removeClaimedUser(context, task.getWorkflowItem(), task.getOwner(), task
// .getStepID());
context.addEvent(new Event(Event.MODIFY, Constants.ITEM, task.getWorkflowItem().getItem().getID(), null,
itemService.getIdentifiers(context, task.getWorkflowItem().getItem())));
} catch (AuthorizeException e) {
throw new RESTAuthorizationException(e);
} catch (WorkflowException e) {
@@ -164,8 +158,6 @@ public class ClaimedTaskRestRepository extends DSpaceRestRepository<ClaimedTaskR
XmlWorkflowItem workflowItem = task.getWorkflowItem();
workflowService.deleteClaimedTask(context, workflowItem, task);
workflowRequirementsService.removeClaimedUser(context, workflowItem, task.getOwner(), task.getStepID());
context.addEvent(new Event(Event.MODIFY, Constants.ITEM, workflowItem.getItem().getID(), null,
itemService.getIdentifiers(context, workflowItem.getItem())));
} catch (AuthorizeException e) {
throw new RESTAuthorizationException(e);
} catch (SQLException | IOException | WorkflowConfigurationException e) {

View File

@@ -24,6 +24,7 @@ import org.dspace.app.rest.builder.CommunityBuilder;
import org.dspace.app.rest.builder.EPersonBuilder;
import org.dspace.app.rest.builder.PoolTaskBuilder;
import org.dspace.app.rest.builder.WorkflowItemBuilder;
import org.dspace.app.rest.matcher.EPersonMatcher;
import org.dspace.app.rest.matcher.PoolTaskMatcher;
import org.dspace.app.rest.matcher.WorkflowItemMatcher;
import org.dspace.app.rest.matcher.WorkspaceItemMatcher;
@@ -344,6 +345,8 @@ public class TaskRestRepositoriesIT extends AbstractControllerIntegrationTest {
Matchers.allOf(
hasJsonPath("$._links.self.href", Matchers.containsString("/api/workflow/claimedtasks/")),
hasJsonPath("$.type", Matchers.is("claimedtask")),
hasJsonPath("$._embedded.owner",
Matchers.is(EPersonMatcher.matchEPersonOnEmail(reviewer.getEmail()))),
hasJsonPath("$._embedded.workflowitem",
Matchers.is(WorkflowItemMatcher.matchItemWithTitleAndDateIssuedAndSubject(
witem, "Workflow Item 1", "2017-10-17", "ExtraEntry")))