mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 15:33:09 +00:00
Merge remote-tracking branch 'origin/master' into dspace-7-shibboleth
This commit is contained in:
6
.gitattributes
vendored
6
.gitattributes
vendored
@@ -1,6 +1,12 @@
|
|||||||
# Auto detect text files and perform LF normalization
|
# Auto detect text files and perform LF normalization
|
||||||
* text=auto
|
* text=auto
|
||||||
|
|
||||||
|
# Ensure Unix files always keep Unix line endings
|
||||||
|
*.sh text eol=lf
|
||||||
|
|
||||||
|
# Ensure Windows files always keep Windows line endings
|
||||||
|
*.bat text eol=crlf
|
||||||
|
|
||||||
# Standard to msysgit
|
# Standard to msysgit
|
||||||
*.doc diff=astextplain
|
*.doc diff=astextplain
|
||||||
*.DOC diff=astextplain
|
*.DOC diff=astextplain
|
||||||
|
@@ -32,11 +32,12 @@ script:
|
|||||||
# license:check => Validate all source code license headers
|
# license:check => Validate all source code license headers
|
||||||
# -Dmaven.test.skip=false => Enable DSpace Unit Tests
|
# -Dmaven.test.skip=false => Enable DSpace Unit Tests
|
||||||
# -DskipITs=false => Enable DSpace Integration Tests
|
# -DskipITs=false => Enable DSpace Integration Tests
|
||||||
|
# -Pdspace-rest => Enable optional dspace-rest module as part of build
|
||||||
# -P !assembly => Skip assembly of "dspace-installer" directory (as it can be memory intensive)
|
# -P !assembly => Skip assembly of "dspace-installer" directory (as it can be memory intensive)
|
||||||
# -B => Maven batch/non-interactive mode (recommended for CI)
|
# -B => Maven batch/non-interactive mode (recommended for CI)
|
||||||
# -V => Display Maven version info before build
|
# -V => Display Maven version info before build
|
||||||
# -Dsurefire.rerunFailingTestsCount=2 => try again for flakey tests, and keep track of/report on number of retries
|
# -Dsurefire.rerunFailingTestsCount=2 => try again for flakey tests, and keep track of/report on number of retries
|
||||||
- "mvn clean install license:check -Dmaven.test.skip=false -DskipITs=false -P !assembly -B -V -Dsurefire.rerunFailingTestsCount=2"
|
- "mvn clean install license:check -Dmaven.test.skip=false -DskipITs=false -Pdspace-rest -P !assembly -B -V -Dsurefire.rerunFailingTestsCount=2"
|
||||||
|
|
||||||
# After a successful build and test (see 'script'), send code coverage reports to coveralls.io
|
# After a successful build and test (see 'script'), send code coverage reports to coveralls.io
|
||||||
# These code coverage reports are generated by jacoco-maven-plugin (during test process above).
|
# These code coverage reports are generated by jacoco-maven-plugin (during test process above).
|
||||||
|
10
Dockerfile
10
Dockerfile
@@ -23,7 +23,8 @@ USER dspace
|
|||||||
ADD --chown=dspace . /app/
|
ADD --chown=dspace . /app/
|
||||||
COPY dspace/src/main/docker/local.cfg /app/local.cfg
|
COPY dspace/src/main/docker/local.cfg /app/local.cfg
|
||||||
|
|
||||||
# Build DSpace. Copy the dspace-install directory to /install. Clean up the build to keep the docker image small
|
# Build DSpace (note: this build doesn't include the optional, deprecated "dspace-rest" webapp)
|
||||||
|
# Copy the dspace-install directory to /install. Clean up the build to keep the docker image small
|
||||||
RUN mvn package && \
|
RUN mvn package && \
|
||||||
mv /app/dspace/target/${TARGET_DIR}/* /install && \
|
mv /app/dspace/target/${TARGET_DIR}/* /install && \
|
||||||
mvn clean
|
mvn clean
|
||||||
@@ -54,12 +55,9 @@ EXPOSE 8080 8009
|
|||||||
ENV JAVA_OPTS=-Xmx2000m
|
ENV JAVA_OPTS=-Xmx2000m
|
||||||
|
|
||||||
# Run the "server" webapp off the /server path (e.g. http://localhost:8080/server/)
|
# Run the "server" webapp off the /server path (e.g. http://localhost:8080/server/)
|
||||||
# and the v6.x (deprecated) REST API off the "/rest" path
|
RUN ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/server
|
||||||
RUN ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/server && \
|
|
||||||
ln -s $DSPACE_INSTALL/webapps/rest /usr/local/tomcat/webapps/rest
|
|
||||||
# If you wish to run "server" webapp off the ROOT path, then comment out the above RUN, and uncomment the below RUN.
|
# If you wish to run "server" webapp off the ROOT path, then comment out the above RUN, and uncomment the below RUN.
|
||||||
# You also MUST update the URL in dspace/src/main/docker/local.cfg
|
# You also MUST update the URL in dspace/src/main/docker/local.cfg
|
||||||
# Please note that server webapp should only run on one path at a time.
|
# Please note that server webapp should only run on one path at a time.
|
||||||
#RUN mv /usr/local/tomcat/webapps/ROOT /usr/local/tomcat/webapps/ROOT.bk && \
|
#RUN mv /usr/local/tomcat/webapps/ROOT /usr/local/tomcat/webapps/ROOT.bk && \
|
||||||
# ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/ROOT && \
|
# ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/ROOT
|
||||||
# ln -s $DSPACE_INSTALL/webapps/rest /usr/local/tomcat/webapps/rest
|
|
||||||
|
@@ -24,7 +24,7 @@ ADD --chown=dspace . /app/
|
|||||||
COPY dspace/src/main/docker/local.cfg /app/local.cfg
|
COPY dspace/src/main/docker/local.cfg /app/local.cfg
|
||||||
|
|
||||||
# Build DSpace. Copy the dspace-install directory to /install. Clean up the build to keep the docker image small
|
# Build DSpace. Copy the dspace-install directory to /install. Clean up the build to keep the docker image small
|
||||||
RUN mvn package -P'!dspace-rest' && \
|
RUN mvn package && \
|
||||||
mv /app/dspace/target/${TARGET_DIR}/* /install && \
|
mv /app/dspace/target/${TARGET_DIR}/* /install && \
|
||||||
mvn clean
|
mvn clean
|
||||||
|
|
||||||
|
@@ -25,8 +25,9 @@ USER dspace
|
|||||||
ADD --chown=dspace . /app/
|
ADD --chown=dspace . /app/
|
||||||
COPY dspace/src/main/docker/local.cfg /app/local.cfg
|
COPY dspace/src/main/docker/local.cfg /app/local.cfg
|
||||||
|
|
||||||
# Build DSpace. Copy the dspace-install directory to /install. Clean up the build to keep the docker image small
|
# Build DSpace (including the optional, deprecated "dspace-rest" webapp)
|
||||||
RUN mvn package && \
|
# Copy the dspace-install directory to /install. Clean up the build to keep the docker image small
|
||||||
|
RUN mvn package -Pdspace-rest && \
|
||||||
mv /app/dspace/target/${TARGET_DIR}/* /install && \
|
mv /app/dspace/target/${TARGET_DIR}/* /install && \
|
||||||
mvn clean
|
mvn clean
|
||||||
|
|
||||||
|
@@ -153,7 +153,7 @@ public class AuthorityValueServiceImpl implements AuthorityValueService {
|
|||||||
public List<AuthorityValue> findByValue(Context context, String schema, String element, String qualifier,
|
public List<AuthorityValue> findByValue(Context context, String schema, String element, String qualifier,
|
||||||
String value) {
|
String value) {
|
||||||
String field = fieldParameter(schema, element, qualifier);
|
String field = fieldParameter(schema, element, qualifier);
|
||||||
return findByValue(context, field, qualifier);
|
return findByValue(context, field, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -11,8 +11,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.solr.common.SolrDocument;
|
import org.apache.solr.common.SolrDocument;
|
||||||
import org.apache.solr.common.SolrInputDocument;
|
import org.apache.solr.common.SolrInputDocument;
|
||||||
@@ -140,8 +140,8 @@ public class PersonAuthorityValue extends AuthorityValue {
|
|||||||
@Override
|
@Override
|
||||||
public void setValues(SolrDocument document) {
|
public void setValues(SolrDocument document) {
|
||||||
super.setValues(document);
|
super.setValues(document);
|
||||||
this.firstName = ObjectUtils.toString(document.getFieldValue("first_name"));
|
this.firstName = Objects.toString(document.getFieldValue("first_name"), "");
|
||||||
this.lastName = ObjectUtils.toString(document.getFieldValue("last_name"));
|
this.lastName = Objects.toString(document.getFieldValue("last_name"), "");
|
||||||
nameVariants = new ArrayList<String>();
|
nameVariants = new ArrayList<String>();
|
||||||
Collection<Object> document_name_variant = document.getFieldValues("name_variant");
|
Collection<Object> document_name_variant = document.getFieldValues("name_variant");
|
||||||
if (document_name_variant != null) {
|
if (document_name_variant != null) {
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
package org.dspace.authorize;
|
package org.dspace.authorize;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
@@ -23,7 +24,6 @@ import javax.persistence.Table;
|
|||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.core.ReloadableEntity;
|
import org.dspace.core.ReloadableEntity;
|
||||||
@@ -123,16 +123,16 @@ public class ResourcePolicy implements ReloadableEntity<Integer> {
|
|||||||
if (getAction() != other.getAction()) {
|
if (getAction() != other.getAction()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!ObjectUtils.equals(getEPerson(), other.getEPerson())) {
|
if (!Objects.equals(getEPerson(), other.getEPerson())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!ObjectUtils.equals(getGroup(), other.getGroup())) {
|
if (!Objects.equals(getGroup(), other.getGroup())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!ObjectUtils.equals(getStartDate(), other.getStartDate())) {
|
if (!Objects.equals(getStartDate(), other.getStartDate())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!ObjectUtils.equals(getEndDate(), other.getEndDate())) {
|
if (!Objects.equals(getEndDate(), other.getEndDate())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -185,7 +185,7 @@ public class ResourcePolicy implements ReloadableEntity<Integer> {
|
|||||||
/**
|
/**
|
||||||
* set the action this policy authorizes
|
* set the action this policy authorizes
|
||||||
*
|
*
|
||||||
* @param myid action ID from {@link org.dspace.core.Constants#Constants Constants}
|
* @param myid action ID from {@link org.dspace.core.Constants Constants}
|
||||||
*/
|
*/
|
||||||
public void setAction(int myid) {
|
public void setAction(int myid) {
|
||||||
this.actionId = myid;
|
this.actionId = myid;
|
||||||
|
@@ -367,7 +367,7 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setWorkflowGroup(Context context, Collection collection, int step, Group group)
|
public void setWorkflowGroup(Context context, Collection collection, int step, Group group)
|
||||||
throws SQLException, AuthorizeException {
|
throws SQLException {
|
||||||
Workflow workflow = null;
|
Workflow workflow = null;
|
||||||
try {
|
try {
|
||||||
workflow = workflowFactory.getWorkflow(collection);
|
workflow = workflowFactory.getWorkflow(collection);
|
||||||
@@ -889,4 +889,4 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
|||||||
throws SQLException {
|
throws SQLException {
|
||||||
return collectionDAO.getCollectionsWithBitstreamSizesTotal(context);
|
return collectionDAO.getCollectionsWithBitstreamSizesTotal(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -361,20 +361,18 @@ public class Context implements AutoCloseable {
|
|||||||
// If Context is no longer open/valid, just note that it has already been closed
|
// If Context is no longer open/valid, just note that it has already been closed
|
||||||
if (!isValid()) {
|
if (!isValid()) {
|
||||||
log.info("complete() was called on a closed Context object. No changes to commit.");
|
log.info("complete() was called on a closed Context object. No changes to commit.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// As long as we have a valid, writeable database connection,
|
// As long as we have a valid, writeable database connection,
|
||||||
// rollback any changes if we are in read-only mode,
|
// commit changes. Otherwise, we'll just close the DB connection (see below)
|
||||||
// otherwise, commit any changes made as part of the transaction
|
if (!isReadOnly()) {
|
||||||
if (isReadOnly()) {
|
|
||||||
abort();
|
|
||||||
} else {
|
|
||||||
commit();
|
commit();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (dbConnection != null) {
|
if (dbConnection != null) {
|
||||||
// Free the DB connection
|
// Free the DB connection and invalidate the Context
|
||||||
dbConnection.closeDBConnection();
|
dbConnection.closeDBConnection();
|
||||||
dbConnection = null;
|
dbConnection = null;
|
||||||
}
|
}
|
||||||
@@ -395,29 +393,24 @@ public class Context implements AutoCloseable {
|
|||||||
// If Context is no longer open/valid, just note that it has already been closed
|
// If Context is no longer open/valid, just note that it has already been closed
|
||||||
if (!isValid()) {
|
if (!isValid()) {
|
||||||
log.info("commit() was called on a closed Context object. No changes to commit.");
|
log.info("commit() was called on a closed Context object. No changes to commit.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isReadOnly()) {
|
if (isReadOnly()) {
|
||||||
throw new UnsupportedOperationException("You cannot commit a read-only context");
|
throw new UnsupportedOperationException("You cannot commit a read-only context");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Our DB Connection (Hibernate) will decide if an actual commit is required or not
|
|
||||||
try {
|
try {
|
||||||
// As long as we have a valid, writeable database connection,
|
// Dispatch events before committing changes to the database,
|
||||||
// commit any changes made as part of the transaction
|
// as the consumers may change something too
|
||||||
if (isValid()) {
|
dispatchEvents();
|
||||||
// Dispatch events before committing changes to the database,
|
|
||||||
// as the consumers may change something too
|
|
||||||
dispatchEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Cache size on commit is " + getCacheSize());
|
log.debug("Cache size on commit is " + getCacheSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dbConnection != null) {
|
if (dbConnection != null) {
|
||||||
//Commit our changes
|
// Commit our changes (this closes the transaction but leaves database connection open)
|
||||||
dbConnection.commit();
|
dbConnection.commit();
|
||||||
reloadContextBoundEntities();
|
reloadContextBoundEntities();
|
||||||
}
|
}
|
||||||
@@ -425,8 +418,12 @@ public class Context implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatch any events (cached in current Context) to configured EventListeners (consumers)
|
||||||
|
* in the EventService. This should be called prior to any commit as some consumers may add
|
||||||
|
* to the current transaction. Once events are dispatched, the Context's event cache is cleared.
|
||||||
|
*/
|
||||||
public void dispatchEvents() {
|
public void dispatchEvents() {
|
||||||
// Commit any changes made as part of the transaction
|
|
||||||
Dispatcher dispatcher = null;
|
Dispatcher dispatcher = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -462,6 +459,7 @@ public class Context implements AutoCloseable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an event to be dispatched when this context is committed.
|
* Add an event to be dispatched when this context is committed.
|
||||||
|
* NOTE: Read-only Contexts cannot add events, as they cannot modify objects.
|
||||||
*
|
*
|
||||||
* @param event event to be dispatched
|
* @param event event to be dispatched
|
||||||
*/
|
*/
|
||||||
@@ -490,6 +488,10 @@ public class Context implements AutoCloseable {
|
|||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not the context has events cached.
|
||||||
|
* @return true or false
|
||||||
|
*/
|
||||||
public boolean hasEvents() {
|
public boolean hasEvents() {
|
||||||
return !CollectionUtils.isEmpty(events);
|
return !CollectionUtils.isEmpty(events);
|
||||||
}
|
}
|
||||||
@@ -521,22 +523,25 @@ public class Context implements AutoCloseable {
|
|||||||
// If Context is no longer open/valid, just note that it has already been closed
|
// If Context is no longer open/valid, just note that it has already been closed
|
||||||
if (!isValid()) {
|
if (!isValid()) {
|
||||||
log.info("abort() was called on a closed Context object. No changes to abort.");
|
log.info("abort() was called on a closed Context object. No changes to abort.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Rollback ONLY if we have a database connection, and it is NOT Read Only
|
// Rollback ONLY if we have a database transaction, and it is NOT Read Only
|
||||||
if (isValid() && !isReadOnly()) {
|
if (!isReadOnly() && isTransactionAlive()) {
|
||||||
dbConnection.rollback();
|
dbConnection.rollback();
|
||||||
}
|
}
|
||||||
} catch (SQLException se) {
|
} catch (SQLException se) {
|
||||||
log.error(se.getMessage(), se);
|
log.error("Error rolling back transaction during an abort()", se);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (!dbConnection.isSessionAlive()) {
|
if (dbConnection != null) {
|
||||||
|
// Free the DB connection & invalidate the Context
|
||||||
dbConnection.closeDBConnection();
|
dbConnection.closeDBConnection();
|
||||||
|
dbConnection = null;
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.error("Exception aborting context", ex);
|
log.error("Error closing the database connection", ex);
|
||||||
}
|
}
|
||||||
events = null;
|
events = null;
|
||||||
}
|
}
|
||||||
@@ -558,7 +563,22 @@ public class Context implements AutoCloseable {
|
|||||||
*/
|
*/
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
// Only return true if our DB connection is live
|
// Only return true if our DB connection is live
|
||||||
return dbConnection != null && dbConnection.isTransActionAlive();
|
// NOTE: A transaction need not exist for our Context to be valid, as a Context may use multiple transactions.
|
||||||
|
return dbConnection != null && dbConnection.isSessionAlive();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find out whether our context includes an open database transaction.
|
||||||
|
* Returns <code>true</code> if there is an open transaction. Returns
|
||||||
|
* <code>false</code> if the context is invalid (e.g. abort() or complete())
|
||||||
|
* was called OR no current transaction exists (e.g. commit() was just called
|
||||||
|
* and no new transaction has begun)
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected boolean isTransactionAlive() {
|
||||||
|
// Only return true if both Context is valid *and* transaction is alive
|
||||||
|
return isValid() && dbConnection.isTransActionAlive();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -571,21 +591,22 @@ public class Context implements AutoCloseable {
|
|||||||
return mode != null && mode == Mode.READ_ONLY;
|
return mode != null && mode == Mode.READ_ONLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a group's UUID to the list of special groups cached in Context
|
||||||
|
* @param groupID UUID of group
|
||||||
|
*/
|
||||||
public void setSpecialGroup(UUID groupID) {
|
public void setSpecialGroup(UUID groupID) {
|
||||||
specialGroups.add(groupID);
|
specialGroups.add(groupID);
|
||||||
|
|
||||||
// System.out.println("Added " + groupID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test if member of special group
|
* Test if a group is a special group
|
||||||
*
|
*
|
||||||
* @param groupID ID of special group to test
|
* @param groupID ID of special group to test
|
||||||
* @return true if member
|
* @return true if member
|
||||||
*/
|
*/
|
||||||
public boolean inSpecialGroup(UUID groupID) {
|
public boolean inSpecialGroup(UUID groupID) {
|
||||||
if (specialGroups.contains(groupID)) {
|
if (specialGroups.contains(groupID)) {
|
||||||
// System.out.println("Contains " + groupID);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,10 +614,9 @@ public class Context implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an array of all of the special groups that current user is a member
|
* Get an array of all of the special groups that current user is a member of.
|
||||||
* of.
|
|
||||||
*
|
*
|
||||||
* @return list of groups
|
* @return list of special groups
|
||||||
* @throws SQLException if database error
|
* @throws SQLException if database error
|
||||||
*/
|
*/
|
||||||
public List<Group> getSpecialGroups() throws SQLException {
|
public List<Group> getSpecialGroups() throws SQLException {
|
||||||
@@ -608,6 +628,10 @@ public class Context implements AutoCloseable {
|
|||||||
return myGroups;
|
return myGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the context, aborting any open transactions (if any).
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void finalize() throws Throwable {
|
protected void finalize() throws Throwable {
|
||||||
/*
|
/*
|
||||||
|
@@ -35,6 +35,23 @@ import org.springframework.orm.hibernate5.SessionFactoryUtils;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Hibernate implementation of the DBConnection.
|
* Hibernate implementation of the DBConnection.
|
||||||
|
* <P>
|
||||||
|
* NOTE: This class does NOT represent a single Hibernate database connection. Instead, it wraps
|
||||||
|
* Hibernate's Session object to obtain access to a database connection in order to execute one or more
|
||||||
|
* transactions.
|
||||||
|
* <P>
|
||||||
|
* Per DSpace's current Hibernate configuration ([dspace]/config/core-hibernate.xml), we use the one-session-per-thread
|
||||||
|
* approach (ThreadLocalSessionContext). This means that Hibernate creates a single Session per thread (request), at the
|
||||||
|
* time when getCurrentSession() is first called.
|
||||||
|
* <P>
|
||||||
|
* This Session may be reused for multiple Transactions, but if commit() is called, any objects (Entities) in
|
||||||
|
* the Session become disconnected and MUST be reloaded into the Session (see reloadEntity() method below).
|
||||||
|
* <P>
|
||||||
|
* If an Error occurs, the Session itself is invalidated. No further Transactions can be run on that Session.
|
||||||
|
* <P>
|
||||||
|
* DSpace generally follows the "Session-per-request" transactional pattern described here:
|
||||||
|
* https://docs.jboss.org/hibernate/orm/5.0/userguide/en-US/html/ch06.html#session-per-request
|
||||||
|
*
|
||||||
*
|
*
|
||||||
* @author kevinvandevelde at atmire.com
|
* @author kevinvandevelde at atmire.com
|
||||||
*/
|
*/
|
||||||
@@ -47,32 +64,61 @@ public class HibernateDBConnection implements DBConnection<Session> {
|
|||||||
private boolean batchModeEnabled = false;
|
private boolean batchModeEnabled = false;
|
||||||
private boolean readOnlyEnabled = false;
|
private boolean readOnlyEnabled = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the current Session from Hibernate (per our settings, Hibernate is configured to create one Session
|
||||||
|
* per thread). If Session doesn't yet exist, it is created. A Transaction is also initialized (or reinintialized)
|
||||||
|
* in the Session if one doesn't exist, or was previously closed (e.g. if commit() was previously called)
|
||||||
|
* @return Hibernate current Session object
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Session getSession() throws SQLException {
|
public Session getSession() throws SQLException {
|
||||||
|
// If we don't yet have a live transaction, start a new one
|
||||||
|
// NOTE: a Session cannot be used until a Transaction is started.
|
||||||
if (!isTransActionAlive()) {
|
if (!isTransActionAlive()) {
|
||||||
sessionFactory.getCurrentSession().beginTransaction();
|
sessionFactory.getCurrentSession().beginTransaction();
|
||||||
configureDatabaseMode();
|
configureDatabaseMode();
|
||||||
}
|
}
|
||||||
|
// Return the current Hibernate Session object (Hibernate will create one if it doesn't yet exist)
|
||||||
return sessionFactory.getCurrentSession();
|
return sessionFactory.getCurrentSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the connection has a currently active Transaction. A Transaction is active if it has not yet been
|
||||||
|
* either committed or rolled back.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isTransActionAlive() {
|
public boolean isTransActionAlive() {
|
||||||
Transaction transaction = getTransaction();
|
Transaction transaction = getTransaction();
|
||||||
return transaction != null && transaction.isActive();
|
return transaction != null && transaction.isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the current Hibernate Transaction object from our Hibernate Session.
|
||||||
|
* @return current Transaction (may be active or inactive) or null
|
||||||
|
*/
|
||||||
protected Transaction getTransaction() {
|
protected Transaction getTransaction() {
|
||||||
return sessionFactory.getCurrentSession().getTransaction();
|
return sessionFactory.getCurrentSession().getTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if Hibernate Session is still "alive" / open. An open Session may or may not have an open Transaction
|
||||||
|
* (so isTransactionAlive() may return false even if isSessionAlive() returns true). A Session may be reused for
|
||||||
|
* multiple transactions (e.g. if commit() is called, the Session remains alive while the Transaction is closed)
|
||||||
|
*
|
||||||
|
* @return true if Session is alive, false otherwise
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isSessionAlive() {
|
public boolean isSessionAlive() {
|
||||||
return sessionFactory.getCurrentSession() != null && sessionFactory.getCurrentSession()
|
return sessionFactory.getCurrentSession() != null && sessionFactory.getCurrentSession().isOpen();
|
||||||
.getTransaction() != null && sessionFactory
|
|
||||||
.getCurrentSession().getTransaction().getStatus().isOneOf(TransactionStatus.ACTIVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rollback any changes applied to the current Transaction. This also closes the Transaction. A new Transaction
|
||||||
|
* may be opened the next time getSession() is called.
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void rollback() throws SQLException {
|
public void rollback() throws SQLException {
|
||||||
if (isTransActionAlive()) {
|
if (isTransActionAlive()) {
|
||||||
@@ -80,6 +126,14 @@ public class HibernateDBConnection implements DBConnection<Session> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close our current Database connection. This also closes & unbinds the Hibernate Session from our thread.
|
||||||
|
* <P>
|
||||||
|
* NOTE: Because DSpace configures Hibernate to automatically create a Session per thread, a Session may still
|
||||||
|
* exist after this method is called (as Hibernate may automatically create a new Session for the current thread).
|
||||||
|
* However, Hibernate will automatically clean up any existing Session when the thread closes.
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void closeDBConnection() throws SQLException {
|
public void closeDBConnection() throws SQLException {
|
||||||
if (sessionFactory.getCurrentSession() != null && sessionFactory.getCurrentSession().isOpen()) {
|
if (sessionFactory.getCurrentSession() != null && sessionFactory.getCurrentSession().isOpen()) {
|
||||||
@@ -87,11 +141,23 @@ public class HibernateDBConnection implements DBConnection<Session> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commits any current changes cached in the Hibernate Session to the database & closes the Transaction.
|
||||||
|
* To open a new Transaction, you may call getSession().
|
||||||
|
* <P>
|
||||||
|
* WARNING: When commit() is called, while the Session is still "alive", all previously loaded objects (entities)
|
||||||
|
* become disconnected from the Session. Therefore, if you continue to use the Session, you MUST reload any needed
|
||||||
|
* objects (entities) using reloadEntity() method.
|
||||||
|
*
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void commit() throws SQLException {
|
public void commit() throws SQLException {
|
||||||
if (isTransActionAlive() && !getTransaction().getStatus().isOneOf(TransactionStatus.MARKED_ROLLBACK,
|
if (isTransActionAlive() && !getTransaction().getStatus().isOneOf(TransactionStatus.MARKED_ROLLBACK,
|
||||||
TransactionStatus.ROLLING_BACK)) {
|
TransactionStatus.ROLLING_BACK)) {
|
||||||
|
// Flush synchronizes the database with in-memory objects in Session (and frees up that memory)
|
||||||
getSession().flush();
|
getSession().flush();
|
||||||
|
// Commit those results to the database & ends the Transaction
|
||||||
getTransaction().commit();
|
getTransaction().commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,6 +198,16 @@ public class HibernateDBConnection implements DBConnection<Session> {
|
|||||||
return getSession().getStatistics().getEntityCount();
|
return getSession().getStatistics().getEntityCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload an entity into the Hibernate cache. This can be called after a call to commit() to re-cache an object
|
||||||
|
* in the Hibernate Session (see commit()). Failing to reload objects into the cache may result in a Hibernate
|
||||||
|
* throwing a "LazyInitializationException" if you attempt to use an object that has been disconnected from the
|
||||||
|
* Session cache.
|
||||||
|
* @param entity The DSpace object to reload
|
||||||
|
* @param <E> The class of the entity. The entity must implement the {@link ReloadableEntity} interface.
|
||||||
|
* @return the newly cached object.
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <E extends ReloadableEntity> E reloadEntity(final E entity) throws SQLException {
|
public <E extends ReloadableEntity> E reloadEntity(final E entity) throws SQLException {
|
||||||
@@ -167,10 +243,13 @@ public class HibernateDBConnection implements DBConnection<Session> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evict an entity from the hibernate cache. This is necessary when batch processing a large number of items.
|
* Evict an entity from the hibernate cache.
|
||||||
|
* <P>
|
||||||
|
* When an entity is evicted, it frees up the memory used by that entity in the cache. This is often
|
||||||
|
* necessary when batch processing a large number of objects (to avoid out-of-memory exceptions).
|
||||||
*
|
*
|
||||||
* @param entity The entity to reload
|
* @param entity The entity to evict
|
||||||
* @param <E> The class of the enity. The entity must implement the {@link ReloadableEntity} interface.
|
* @param <E> The class of the entity. The entity must implement the {@link ReloadableEntity} interface.
|
||||||
* @throws SQLException When reloading the entity from the database fails.
|
* @throws SQLException When reloading the entity from the database fails.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@@ -8,22 +8,59 @@
|
|||||||
package org.dspace.submit.model;
|
package org.dspace.submit.model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This class represents an option available in the submission upload section to
|
||||||
|
* set permission on a file. An option is defined by a name such as "open
|
||||||
|
* access", "embargo", "restricted access", etc. and some optional attributes to
|
||||||
|
* better clarify the constraints and input available to the user. For instance
|
||||||
|
* an embargo option could allow to set a start date not longer than 3 years,
|
||||||
|
* etc
|
||||||
|
*
|
||||||
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
|
||||||
*/
|
*/
|
||||||
public class AccessConditionOption {
|
public class AccessConditionOption {
|
||||||
|
/** An unique name identifying the access contion option **/
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the name of the group that will be bound to the resource policy created if
|
||||||
|
* such option is used
|
||||||
|
*/
|
||||||
private String groupName;
|
private String groupName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this is in alternative to the {@link #groupName}. The sub-groups listed in
|
||||||
|
* the DSpace group identified by the name here specified will be available to
|
||||||
|
* the user to personalize the access condition. They can be for instance
|
||||||
|
* University Staff, University Students, etc. so that a "restricted access"
|
||||||
|
* option can be further specified without the need to create separate access
|
||||||
|
* condition options for each group
|
||||||
|
*/
|
||||||
private String selectGroupName;
|
private String selectGroupName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set to <code>true</code> if this option requires a start date to be indicated
|
||||||
|
* for the underlying resource policy to create
|
||||||
|
*/
|
||||||
private Boolean hasStartDate;
|
private Boolean hasStartDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set to <code>true</code> if this option requires an end date to be indicated
|
||||||
|
* for the underlying resource policy to create
|
||||||
|
*/
|
||||||
private Boolean hasEndDate;
|
private Boolean hasEndDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It contains, if applicable, the maximum start date (i.e. when the "embargo
|
||||||
|
* expires") that can be selected. It accepts date math via joda library (such as
|
||||||
|
* +3years)
|
||||||
|
*/
|
||||||
private String startDateLimit;
|
private String startDateLimit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It contains, if applicable, the maximum end date (i.e. when the "lease
|
||||||
|
* expires") that can be selected. It accepts date math via joda library (such as
|
||||||
|
* +3years)
|
||||||
|
*/
|
||||||
private String endDateLimit;
|
private String endDateLimit;
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -81,6 +118,4 @@ public class AccessConditionOption {
|
|||||||
public void setSelectGroupName(String selectGroupName) {
|
public void setSelectGroupName(String selectGroupName) {
|
||||||
this.selectGroupName = selectGroupName;
|
this.selectGroupName = selectGroupName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -7,29 +7,53 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.xmlworkflow;
|
package org.dspace.xmlworkflow;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
|
import org.dspace.content.service.CollectionService;
|
||||||
|
import org.dspace.core.Context;
|
||||||
|
import org.dspace.handle.service.HandleService;
|
||||||
|
import org.dspace.utils.DSpace;
|
||||||
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||||
|
import org.dspace.xmlworkflow.state.Step;
|
||||||
import org.dspace.xmlworkflow.state.Workflow;
|
import org.dspace.xmlworkflow.state.Workflow;
|
||||||
|
import org.dspace.xmlworkflow.state.actions.WorkflowActionConfig;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Required;
|
import org.springframework.beans.factory.annotation.Required;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The workflowfactory is responsible for parsing the
|
* The workflowfactory is responsible for parsing the workflow xml file and is used to retrieve info about the workflow:
|
||||||
* workflow xml file and is used to retrieve the workflow for
|
* - the workflow for a certain collection
|
||||||
* a certain collection
|
* - collections mapped to a certain workflow
|
||||||
|
* - collections not mapped to any workflow
|
||||||
|
* - configured workflows and the default workflow
|
||||||
|
* - workflow action by name
|
||||||
*
|
*
|
||||||
* @author Bram De Schouwer (bram.deschouwer at dot com)
|
* @author Bram De Schouwer (bram.deschouwer at dot com)
|
||||||
* @author Kevin Van de Velde (kevin at atmire dot com)
|
* @author Kevin Van de Velde (kevin at atmire dot com)
|
||||||
* @author Ben Bosman (ben at atmire dot com)
|
* @author Ben Bosman (ben at atmire dot com)
|
||||||
* @author Mark Diggory (markd at atmire dot com)
|
* @author Mark Diggory (markd at atmire dot com)
|
||||||
|
* @author Maria Verdonck (Atmire) on 11/12/2019
|
||||||
*/
|
*/
|
||||||
public class XmlWorkflowFactoryImpl implements XmlWorkflowFactory {
|
public class XmlWorkflowFactoryImpl implements XmlWorkflowFactory {
|
||||||
|
|
||||||
public static final String LEGACY_WORKFLOW_NAME = "defaultWorkflow";
|
public static final String LEGACY_WORKFLOW_NAME = "defaultWorkflow";
|
||||||
|
|
||||||
|
private Logger log = org.apache.logging.log4j.LogManager.getLogger(XmlWorkflowFactoryImpl.class);
|
||||||
|
|
||||||
private Map<String, Workflow> workflowMapping;
|
private Map<String, Workflow> workflowMapping;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected CollectionService collectionService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected HandleService handleService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Workflow getWorkflow(Collection collection) throws WorkflowConfigurationException {
|
public Workflow getWorkflow(Collection collection) throws WorkflowConfigurationException {
|
||||||
// Attempt to retrieve our workflow object
|
// Attempt to retrieve our workflow object
|
||||||
@@ -50,4 +74,93 @@ public class XmlWorkflowFactoryImpl implements XmlWorkflowFactory {
|
|||||||
public void setWorkflowMapping(Map<String, Workflow> workflowMapping) {
|
public void setWorkflowMapping(Map<String, Workflow> workflowMapping) {
|
||||||
this.workflowMapping = workflowMapping;
|
this.workflowMapping = workflowMapping;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public Workflow getWorkflowByName(String workflowName) throws WorkflowConfigurationException {
|
||||||
|
for (Workflow workflow : workflowMapping.values()) {
|
||||||
|
if (workflow.getID().equals(workflowName)) {
|
||||||
|
return workflow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new WorkflowConfigurationException(
|
||||||
|
"Error while retrieving workflow by the following name: " + workflowName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Workflow getDefaultWorkflow() {
|
||||||
|
return this.workflowMapping.get(LEGACY_WORKFLOW_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Workflow> getAllConfiguredWorkflows() {
|
||||||
|
return new ArrayList<>(this.workflowMapping.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Collection> getCollectionHandlesMappedToWorklow(Context context, String workflowName) {
|
||||||
|
List<Collection> collectionsMapped = new ArrayList<>();
|
||||||
|
for (String handle : this.workflowMapping.keySet()) {
|
||||||
|
if (this.workflowMapping.get(handle).getID().equals(workflowName)) {
|
||||||
|
try {
|
||||||
|
Collection collection = (Collection) handleService.resolveToObject(context, handle);
|
||||||
|
if (collection != null) {
|
||||||
|
collectionsMapped.add(collection);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("SQLException in XmlWorkflowFactoryImpl.getCollectionHandlesMappedToWorklow trying to " +
|
||||||
|
"retrieve collection with handle: " + handle, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return collectionsMapped;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Collection> getAllNonMappedCollectionsHandles(Context context) {
|
||||||
|
List<Collection> nonMappedCollections = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
for (Collection collection : this.collectionService.findAll(context)) {
|
||||||
|
if (workflowMapping.get(collection.getHandle()) == null) {
|
||||||
|
nonMappedCollections.add(collection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("SQLException in XmlWorkflowFactoryImpl.getAllNonMappedCollectionsHandles trying to " +
|
||||||
|
"retrieve all collections", e);
|
||||||
|
}
|
||||||
|
return nonMappedCollections;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean workflowByThisNameExists(String workflowName) {
|
||||||
|
for (Workflow workflow : this.workflowMapping.values()) {
|
||||||
|
if (workflow.getID().equals(workflowName)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDefaultWorkflow(String workflowName) {
|
||||||
|
if (StringUtils.isNotBlank(workflowName)) {
|
||||||
|
Workflow defaultWorkflow = this.getDefaultWorkflow();
|
||||||
|
if (defaultWorkflow != null && StringUtils.isNotBlank(defaultWorkflow.getID())) {
|
||||||
|
return (defaultWorkflow.getID().equals(workflowName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorkflowActionConfig getActionByName(String workflowActionName) {
|
||||||
|
return new DSpace().getServiceManager().getServiceByName(workflowActionName, WorkflowActionConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Step getStepByName(String workflowStepName) {
|
||||||
|
return new DSpace().getServiceManager().getServiceByName(workflowStepName, Step.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@@ -309,7 +309,7 @@ public class XmlWorkflowServiceImpl implements XmlWorkflowService {
|
|||||||
@Override
|
@Override
|
||||||
public WorkflowActionConfig doState(Context c, EPerson user, HttpServletRequest request, int workflowItemId,
|
public WorkflowActionConfig doState(Context c, EPerson user, HttpServletRequest request, int workflowItemId,
|
||||||
Workflow workflow, WorkflowActionConfig currentActionConfig)
|
Workflow workflow, WorkflowActionConfig currentActionConfig)
|
||||||
throws SQLException, AuthorizeException, IOException, MessagingException, WorkflowException {
|
throws SQLException, AuthorizeException, IOException, WorkflowException {
|
||||||
try {
|
try {
|
||||||
XmlWorkflowItem wi = xmlWorkflowItemService.find(c, workflowItemId);
|
XmlWorkflowItem wi = xmlWorkflowItemService.find(c, workflowItemId);
|
||||||
Step currentStep = currentActionConfig.getStep();
|
Step currentStep = currentActionConfig.getStep();
|
||||||
|
@@ -7,23 +7,31 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.xmlworkflow.factory;
|
package org.dspace.xmlworkflow.factory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
|
import org.dspace.core.Context;
|
||||||
import org.dspace.xmlworkflow.WorkflowConfigurationException;
|
import org.dspace.xmlworkflow.WorkflowConfigurationException;
|
||||||
|
import org.dspace.xmlworkflow.state.Step;
|
||||||
import org.dspace.xmlworkflow.state.Workflow;
|
import org.dspace.xmlworkflow.state.Workflow;
|
||||||
|
import org.dspace.xmlworkflow.state.actions.WorkflowActionConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The xmlworkflowfactory is responsible for parsing the
|
* The workflowfactory is responsible for parsing the workflow xml file and is used to retrieve info about the workflow:
|
||||||
* workflow xml file and is used to retrieve the workflow for
|
* - the workflow for a certain collection
|
||||||
* a certain collection
|
* - collections mapped to a certain workflow
|
||||||
|
* - collections not mapped to any workflow
|
||||||
|
* - configured workflows and the default workflow
|
||||||
|
* - workflow action by name
|
||||||
*
|
*
|
||||||
* @author Bram De Schouwer (bram.deschouwer at dot com)
|
* @author Bram De Schouwer (bram.deschouwer at dot com)
|
||||||
* @author Kevin Van de Velde (kevin at atmire dot com)
|
* @author Kevin Van de Velde (kevin at atmire dot com)
|
||||||
* @author Ben Bosman (ben at atmire dot com)
|
* @author Ben Bosman (ben at atmire dot com)
|
||||||
* @author Mark Diggory (markd at atmire dot com)
|
* @author Mark Diggory (markd at atmire dot com)
|
||||||
|
* @author Maria Verdonck (Atmire) on 11/12/2019
|
||||||
*/
|
*/
|
||||||
public interface XmlWorkflowFactory {
|
public interface XmlWorkflowFactory {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the workflow configuration for a single collection
|
* Retrieve the workflow configuration for a single collection
|
||||||
*
|
*
|
||||||
@@ -32,4 +40,74 @@ public interface XmlWorkflowFactory {
|
|||||||
* @throws WorkflowConfigurationException occurs if there is a configuration error in the workflow
|
* @throws WorkflowConfigurationException occurs if there is a configuration error in the workflow
|
||||||
*/
|
*/
|
||||||
public Workflow getWorkflow(Collection collection) throws WorkflowConfigurationException;
|
public Workflow getWorkflow(Collection collection) throws WorkflowConfigurationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the workflow configuration by name
|
||||||
|
*
|
||||||
|
* @param workflowName the name for which we want our workflow
|
||||||
|
* @return the workflow configuration
|
||||||
|
* @throws WorkflowConfigurationException occurs if there is no workflow configured by that name
|
||||||
|
*/
|
||||||
|
public Workflow getWorkflowByName(String workflowName) throws WorkflowConfigurationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a list of all configured workflows, or returns the cache of this if it was already created
|
||||||
|
*
|
||||||
|
* @return List of all configured workflows
|
||||||
|
*/
|
||||||
|
public List<Workflow> getAllConfiguredWorkflows();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if there is a workflow configured by the given name
|
||||||
|
*
|
||||||
|
* @param workflowName Name of a possible configured workflow
|
||||||
|
* @return True if there is a workflow configured by this name, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean workflowByThisNameExists(String workflowName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if the given workflowName is the workflow configured to be default for collections
|
||||||
|
*
|
||||||
|
* @param workflowName Name of workflow to check if default
|
||||||
|
* @return True if given workflowName is the workflow mapped to default for collections, otherwise false
|
||||||
|
*/
|
||||||
|
public boolean isDefaultWorkflow(String workflowName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the default workflow, i.e. the workflow that is mapped to collection=default in workflow.xml
|
||||||
|
*/
|
||||||
|
public Workflow getDefaultWorkflow();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a list of collections that are mapped to the given workflow in the workflow configuration.
|
||||||
|
* * Makes use of a cache so it only retrieves the workflowName->List<collectionHandle> if it's not cached
|
||||||
|
*
|
||||||
|
* @param context Dspace context
|
||||||
|
* @param workflowName Name of workflow we want the collections of that are mapped to is
|
||||||
|
* @return List of collections mapped to the requested workflow
|
||||||
|
*/
|
||||||
|
public List<Collection> getCollectionHandlesMappedToWorklow(Context context, String workflowName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns list of collections that are not mapped to any configured workflow, and thus use the default workflow
|
||||||
|
*
|
||||||
|
* @return List of collections not mapped to any workflow
|
||||||
|
*/
|
||||||
|
public List<Collection> getAllNonMappedCollectionsHandles(Context context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a {@link WorkflowActionConfig} object based on its name, should correspond with bean id in workflow-actions.xml
|
||||||
|
*
|
||||||
|
* @param workflowActionName Name of workflow action we want to retrieve
|
||||||
|
* @return Workflow action object corresponding to the given workflowActionName
|
||||||
|
*/
|
||||||
|
public WorkflowActionConfig getActionByName(String workflowActionName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a {@link Step} object based on its name, should correspond with bean id in workflow.xml
|
||||||
|
*
|
||||||
|
* @param workflowStepName Name of workflow step we want to retrieve
|
||||||
|
* @return Workflow step object corresponding to the given workflowStepName
|
||||||
|
*/
|
||||||
|
public Step getStepByName(String workflowStepName);
|
||||||
}
|
}
|
||||||
|
@@ -36,8 +36,7 @@ import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
|||||||
public abstract class Action {
|
public abstract class Action {
|
||||||
|
|
||||||
private WorkflowActionConfig parent;
|
private WorkflowActionConfig parent;
|
||||||
private static String ERROR_FIELDS_ATTRIBUTE = "dspace.workflow.error_fields";
|
private static final String ERROR_FIELDS_ATTRIBUTE = "dspace.workflow.error_fields";
|
||||||
|
|
||||||
|
|
||||||
public abstract void activate(Context c, XmlWorkflowItem wf)
|
public abstract void activate(Context c, XmlWorkflowItem wf)
|
||||||
throws SQLException, IOException, AuthorizeException, WorkflowException;
|
throws SQLException, IOException, AuthorizeException, WorkflowException;
|
||||||
@@ -45,6 +44,26 @@ public abstract class Action {
|
|||||||
public abstract ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
public abstract ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
||||||
throws SQLException, AuthorizeException, IOException, WorkflowException;
|
throws SQLException, AuthorizeException, IOException, WorkflowException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of options that the user can select at this action which results in the next step in the workflow
|
||||||
|
* @return A list of options of this action, resulting in the next step of the workflow
|
||||||
|
*/
|
||||||
|
public abstract List<String> getOptions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if one of the options is a parameter of the request
|
||||||
|
* @param request Action request
|
||||||
|
* @return true if one of the options is a parameter of the request; false if none was found
|
||||||
|
*/
|
||||||
|
protected boolean isOptionInParam(HttpServletRequest request) {
|
||||||
|
for (String option: this.getOptions()) {
|
||||||
|
if (request.getParameter(option) != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public WorkflowActionConfig getParent() {
|
public WorkflowActionConfig getParent() {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.xmlworkflow.state.actions;
|
package org.dspace.xmlworkflow.state.actions;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.dspace.xmlworkflow.state.Step;
|
import org.dspace.xmlworkflow.state.Step;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,4 +61,12 @@ public class WorkflowActionConfig {
|
|||||||
return step;
|
return step;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of options the user has on this action, resulting in the next step of the workflow
|
||||||
|
* @return A list of options of this action, resulting in the next step of the workflow
|
||||||
|
*/
|
||||||
|
public List<String> getOptions() {
|
||||||
|
return this.processingAction.getOptions();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -9,8 +9,11 @@ package org.dspace.xmlworkflow.state.actions.processingaction;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.dspace.app.util.Util;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.DCDate;
|
import org.dspace.content.DCDate;
|
||||||
import org.dspace.content.MetadataSchemaEnum;
|
import org.dspace.content.MetadataSchemaEnum;
|
||||||
@@ -31,40 +34,51 @@ import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
|||||||
*/
|
*/
|
||||||
public class AcceptEditRejectAction extends ProcessingAction {
|
public class AcceptEditRejectAction extends ProcessingAction {
|
||||||
|
|
||||||
public static final int MAIN_PAGE = 0;
|
private static final String SUBMIT_APPROVE = "submit_approve";
|
||||||
public static final int REJECT_PAGE = 1;
|
private static final String SUBMIT_REJECT = "submit_reject";
|
||||||
|
|
||||||
//TODO: rename to AcceptAndEditMetadataAction
|
//TODO: rename to AcceptAndEditMetadataAction
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activate(Context c, XmlWorkflowItem wf) throws SQLException {
|
public void activate(Context c, XmlWorkflowItem wf) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
||||||
throws SQLException, AuthorizeException, IOException {
|
throws SQLException, AuthorizeException, IOException {
|
||||||
|
if (super.isOptionInParam(request)) {
|
||||||
if (request.getParameter("submit_approve") != null) {
|
switch (Util.getSubmitButton(request, SUBMIT_CANCEL)) {
|
||||||
return processAccept(c, wfi, step, request);
|
case SUBMIT_APPROVE:
|
||||||
} else {
|
return processAccept(c, wfi);
|
||||||
if (request.getParameter("submit_reject") != null) {
|
case SUBMIT_REJECT:
|
||||||
return processRejectPage(c, wfi, step, request);
|
return processRejectPage(c, wfi, request);
|
||||||
|
default:
|
||||||
|
return new ActionResult(ActionResult.TYPE.TYPE_CANCEL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ActionResult(ActionResult.TYPE.TYPE_CANCEL);
|
return new ActionResult(ActionResult.TYPE.TYPE_CANCEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult processAccept(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
@Override
|
||||||
throws SQLException, AuthorizeException {
|
public List<String> getOptions() {
|
||||||
|
List<String> options = new ArrayList<>();
|
||||||
|
options.add(SUBMIT_APPROVE);
|
||||||
|
options.add(SUBMIT_REJECT);
|
||||||
|
options.add(ProcessingAction.SUBMIT_EDIT_METADATA);
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionResult processAccept(Context c, XmlWorkflowItem wfi)
|
||||||
|
throws SQLException, AuthorizeException {
|
||||||
//Delete the tasks
|
//Delete the tasks
|
||||||
addApprovedProvenance(c, wfi);
|
addApprovedProvenance(c, wfi);
|
||||||
|
|
||||||
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult processRejectPage(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
public ActionResult processRejectPage(Context c, XmlWorkflowItem wfi, HttpServletRequest request)
|
||||||
throws SQLException, AuthorizeException, IOException {
|
throws SQLException, AuthorizeException, IOException {
|
||||||
String reason = request.getParameter("reason");
|
String reason = request.getParameter("reason");
|
||||||
if (reason == null || 0 == reason.trim().length()) {
|
if (reason == null || 0 == reason.trim().length()) {
|
||||||
addErrorField(request, "reason");
|
addErrorField(request, "reason");
|
||||||
@@ -85,14 +99,14 @@ public class AcceptEditRejectAction extends ProcessingAction {
|
|||||||
|
|
||||||
// Get user's name + email address
|
// Get user's name + email address
|
||||||
String usersName = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService()
|
String usersName = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService()
|
||||||
.getEPersonName(c.getCurrentUser());
|
.getEPersonName(c.getCurrentUser());
|
||||||
|
|
||||||
String provDescription = getProvenanceStartId() + " Approved for entry into archive by "
|
String provDescription = getProvenanceStartId() + " Approved for entry into archive by "
|
||||||
+ usersName + " on " + now + " (GMT) ";
|
+ usersName + " on " + now + " (GMT) ";
|
||||||
|
|
||||||
// Add to item as a DC field
|
// Add to item as a DC field
|
||||||
itemService.addMetadata(c, wfi.getItem(), MetadataSchemaEnum.DC.getName(), "description", "provenance", "en",
|
itemService.addMetadata(c, wfi.getItem(), MetadataSchemaEnum.DC.getName(), "description", "provenance", "en",
|
||||||
provDescription);
|
provDescription);
|
||||||
itemService.update(c, wfi.getItem());
|
itemService.update(c, wfi.getItem());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,10 +7,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.xmlworkflow.state.actions.processingaction;
|
package org.dspace.xmlworkflow.state.actions.processingaction;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.dspace.app.util.Util;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.DCDate;
|
import org.dspace.content.DCDate;
|
||||||
import org.dspace.content.MetadataSchemaEnum;
|
import org.dspace.content.MetadataSchemaEnum;
|
||||||
@@ -31,29 +33,41 @@ import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
|||||||
*/
|
*/
|
||||||
public class FinalEditAction extends ProcessingAction {
|
public class FinalEditAction extends ProcessingAction {
|
||||||
|
|
||||||
|
private static final String SUBMIT_APPROVE = "submit_approve";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activate(Context c, XmlWorkflowItem wf) throws SQLException {
|
public void activate(Context c, XmlWorkflowItem wf) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
||||||
throws SQLException, AuthorizeException, IOException {
|
throws SQLException, AuthorizeException {
|
||||||
return processMainPage(c, wfi, step, request);
|
return processMainPage(c, wfi, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult processMainPage(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
public ActionResult processMainPage(Context c, XmlWorkflowItem wfi, HttpServletRequest request)
|
||||||
throws SQLException, AuthorizeException {
|
throws SQLException, AuthorizeException {
|
||||||
if (request.getParameter("submit_approve") != null) {
|
if (super.isOptionInParam(request)) {
|
||||||
//Delete the tasks
|
switch (Util.getSubmitButton(request, SUBMIT_CANCEL)) {
|
||||||
addApprovedProvenance(c, wfi);
|
case SUBMIT_APPROVE:
|
||||||
|
//Delete the tasks
|
||||||
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
addApprovedProvenance(c, wfi);
|
||||||
} else {
|
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
||||||
//We pressed the leave button so return to our submissions page
|
default:
|
||||||
return new ActionResult(ActionResult.TYPE.TYPE_SUBMISSION_PAGE);
|
//We pressed the leave button so return to our submissions page
|
||||||
|
return new ActionResult(ActionResult.TYPE.TYPE_SUBMISSION_PAGE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return new ActionResult(ActionResult.TYPE.TYPE_CANCEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getOptions() {
|
||||||
|
List<String> options = new ArrayList<>();
|
||||||
|
options.add(SUBMIT_APPROVE);
|
||||||
|
options.add(ProcessingAction.SUBMIT_EDIT_METADATA);
|
||||||
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addApprovedProvenance(Context c, XmlWorkflowItem wfi) throws SQLException, AuthorizeException {
|
private void addApprovedProvenance(Context c, XmlWorkflowItem wfi) throws SQLException, AuthorizeException {
|
||||||
@@ -62,14 +76,14 @@ public class FinalEditAction extends ProcessingAction {
|
|||||||
|
|
||||||
// Get user's name + email address
|
// Get user's name + email address
|
||||||
String usersName = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService()
|
String usersName = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService()
|
||||||
.getEPersonName(c.getCurrentUser());
|
.getEPersonName(c.getCurrentUser());
|
||||||
|
|
||||||
String provDescription = getProvenanceStartId() + " Approved for entry into archive by "
|
String provDescription = getProvenanceStartId() + " Approved for entry into archive by "
|
||||||
+ usersName + " on " + now + " (GMT) ";
|
+ usersName + " on " + now + " (GMT) ";
|
||||||
|
|
||||||
// Add to item as a DC field
|
// Add to item as a DC field
|
||||||
itemService.addMetadata(c, wfi.getItem(), MetadataSchemaEnum.DC.getName(), "description", "provenance", "en",
|
itemService.addMetadata(c, wfi.getItem(), MetadataSchemaEnum.DC.getName(), "description", "provenance", "en",
|
||||||
provDescription);
|
provDescription);
|
||||||
itemService.update(c, wfi.getItem());
|
itemService.update(c, wfi.getItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,6 +34,8 @@ public abstract class ProcessingAction extends Action {
|
|||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
protected ItemService itemService;
|
protected ItemService itemService;
|
||||||
|
|
||||||
|
public static final String SUBMIT_EDIT_METADATA = "submit_edit_metadata";
|
||||||
|
public static final String SUBMIT_CANCEL = "submit_cancel";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAuthorized(Context context, HttpServletRequest request, XmlWorkflowItem wfi) throws SQLException {
|
public boolean isAuthorized(Context context, HttpServletRequest request, XmlWorkflowItem wfi) throws SQLException {
|
||||||
|
@@ -9,9 +9,12 @@ package org.dspace.xmlworkflow.state.actions.processingaction;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.dspace.app.util.Util;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.DCDate;
|
import org.dspace.content.DCDate;
|
||||||
import org.dspace.content.MetadataSchemaEnum;
|
import org.dspace.content.MetadataSchemaEnum;
|
||||||
@@ -34,6 +37,8 @@ public class ReviewAction extends ProcessingAction {
|
|||||||
public static final int MAIN_PAGE = 0;
|
public static final int MAIN_PAGE = 0;
|
||||||
public static final int REJECT_PAGE = 1;
|
public static final int REJECT_PAGE = 1;
|
||||||
|
|
||||||
|
private static final String SUBMIT_APPROVE = "submit_approve";
|
||||||
|
private static final String SUBMIT_REJECT = "submit_reject";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activate(Context c, XmlWorkflowItem wfItem) {
|
public void activate(Context c, XmlWorkflowItem wfItem) {
|
||||||
@@ -43,22 +48,30 @@ public class ReviewAction extends ProcessingAction {
|
|||||||
@Override
|
@Override
|
||||||
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
||||||
throws SQLException, AuthorizeException, IOException {
|
throws SQLException, AuthorizeException, IOException {
|
||||||
if (request.getParameter("submit_approve") != null) {
|
if (super.isOptionInParam(request)) {
|
||||||
return processAccept(c, wfi, step, request);
|
switch (Util.getSubmitButton(request, SUBMIT_CANCEL)) {
|
||||||
} else {
|
case SUBMIT_APPROVE:
|
||||||
if (request.getParameter("submit_reject") != null) {
|
return processAccept(c, wfi);
|
||||||
return processRejectPage(c, wfi, step, request);
|
case SUBMIT_REJECT:
|
||||||
|
return processRejectPage(c, wfi, step, request);
|
||||||
|
default:
|
||||||
|
return new ActionResult(ActionResult.TYPE.TYPE_CANCEL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ActionResult(ActionResult.TYPE.TYPE_CANCEL);
|
return new ActionResult(ActionResult.TYPE.TYPE_CANCEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult processAccept(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
@Override
|
||||||
throws SQLException, AuthorizeException {
|
public List<String> getOptions() {
|
||||||
|
List<String> options = new ArrayList<>();
|
||||||
|
options.add(SUBMIT_APPROVE);
|
||||||
|
options.add(SUBMIT_REJECT);
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionResult processAccept(Context c, XmlWorkflowItem wfi) throws SQLException, AuthorizeException {
|
||||||
//Delete the tasks
|
//Delete the tasks
|
||||||
addApprovedProvenance(c, wfi);
|
addApprovedProvenance(c, wfi);
|
||||||
|
|
||||||
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,14 +81,14 @@ public class ReviewAction extends ProcessingAction {
|
|||||||
|
|
||||||
// Get user's name + email address
|
// Get user's name + email address
|
||||||
String usersName = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService()
|
String usersName = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService()
|
||||||
.getEPersonName(c.getCurrentUser());
|
.getEPersonName(c.getCurrentUser());
|
||||||
|
|
||||||
String provDescription = getProvenanceStartId() + " Approved for entry into archive by "
|
String provDescription = getProvenanceStartId() + " Approved for entry into archive by "
|
||||||
+ usersName + " on " + now + " (GMT) ";
|
+ usersName + " on " + now + " (GMT) ";
|
||||||
|
|
||||||
// Add to item as a DC field
|
// Add to item as a DC field
|
||||||
itemService.addMetadata(c, wfi.getItem(), MetadataSchemaEnum.DC.getName(), "description", "provenance", "en",
|
itemService.addMetadata(c, wfi.getItem(), MetadataSchemaEnum.DC.getName(), "description", "provenance", "en",
|
||||||
provDescription);
|
provDescription);
|
||||||
itemService.update(c, wfi.getItem());
|
itemService.update(c, wfi.getItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,8 +103,8 @@ public class ReviewAction extends ProcessingAction {
|
|||||||
|
|
||||||
//We have pressed reject, so remove the task the user has & put it back to a workspace item
|
//We have pressed reject, so remove the task the user has & put it back to a workspace item
|
||||||
XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService()
|
XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService()
|
||||||
.sendWorkflowItemBackSubmission(c, wfi, c.getCurrentUser(),
|
.sendWorkflowItemBackSubmission(c, wfi, c.getCurrentUser(),
|
||||||
this.getProvenanceStartId(), reason);
|
this.getProvenanceStartId(), reason);
|
||||||
|
|
||||||
|
|
||||||
return new ActionResult(ActionResult.TYPE.TYPE_SUBMISSION_PAGE);
|
return new ActionResult(ActionResult.TYPE.TYPE_SUBMISSION_PAGE);
|
||||||
|
@@ -9,6 +9,7 @@ package org.dspace.xmlworkflow.state.actions.processingaction;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
@@ -17,7 +18,6 @@ import org.dspace.content.Item;
|
|||||||
import org.dspace.content.MetadataSchemaEnum;
|
import org.dspace.content.MetadataSchemaEnum;
|
||||||
import org.dspace.content.MetadataValue;
|
import org.dspace.content.MetadataValue;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.workflow.WorkflowException;
|
|
||||||
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
|
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
|
||||||
import org.dspace.xmlworkflow.service.WorkflowRequirementsService;
|
import org.dspace.xmlworkflow.service.WorkflowRequirementsService;
|
||||||
import org.dspace.xmlworkflow.state.Step;
|
import org.dspace.xmlworkflow.state.Step;
|
||||||
@@ -40,14 +40,13 @@ public class ScoreEvaluationAction extends ProcessingAction {
|
|||||||
private int minimumAcceptanceScore;
|
private int minimumAcceptanceScore;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activate(Context c, XmlWorkflowItem wf)
|
public void activate(Context c, XmlWorkflowItem wf) {
|
||||||
throws SQLException, IOException, AuthorizeException, WorkflowException {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
||||||
throws SQLException, AuthorizeException, IOException, WorkflowException {
|
throws SQLException, AuthorizeException, IOException {
|
||||||
boolean hasPassed = false;
|
boolean hasPassed = false;
|
||||||
//Retrieve all our scores from the metadata & add em up
|
//Retrieve all our scores from the metadata & add em up
|
||||||
List<MetadataValue> scores = itemService
|
List<MetadataValue> scores = itemService
|
||||||
@@ -82,6 +81,11 @@ public class ScoreEvaluationAction extends ProcessingAction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getOptions() {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
public int getMinimumAcceptanceScore() {
|
public int getMinimumAcceptanceScore() {
|
||||||
return minimumAcceptanceScore;
|
return minimumAcceptanceScore;
|
||||||
}
|
}
|
||||||
|
@@ -7,14 +7,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.xmlworkflow.state.actions.processingaction;
|
package org.dspace.xmlworkflow.state.actions.processingaction;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.dspace.app.util.Util;
|
import org.dspace.app.util.Util;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.workflow.WorkflowException;
|
|
||||||
import org.dspace.xmlworkflow.service.WorkflowRequirementsService;
|
import org.dspace.xmlworkflow.service.WorkflowRequirementsService;
|
||||||
import org.dspace.xmlworkflow.state.Step;
|
import org.dspace.xmlworkflow.state.Step;
|
||||||
import org.dspace.xmlworkflow.state.actions.ActionResult;
|
import org.dspace.xmlworkflow.state.actions.ActionResult;
|
||||||
@@ -32,20 +32,21 @@ import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
|||||||
*/
|
*/
|
||||||
public class ScoreReviewAction extends ProcessingAction {
|
public class ScoreReviewAction extends ProcessingAction {
|
||||||
|
|
||||||
|
private static final String SUBMIT_SCORE = "submit_score";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activate(Context c, XmlWorkflowItem wf)
|
public void activate(Context c, XmlWorkflowItem wf) {
|
||||||
throws SQLException, IOException, AuthorizeException, WorkflowException {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
||||||
throws SQLException, AuthorizeException, IOException, WorkflowException {
|
throws SQLException, AuthorizeException {
|
||||||
if (request.getParameter("submit_score") != null) {
|
if (request.getParameter(SUBMIT_SCORE) != null) {
|
||||||
int score = Util.getIntParameter(request, "score");
|
int score = Util.getIntParameter(request, "score");
|
||||||
//Add our score to the metadata
|
//Add our score to the metadata
|
||||||
itemService.addMetadata(c, wfi.getItem(), WorkflowRequirementsService.WORKFLOW_SCHEMA, "score", null, null,
|
itemService.addMetadata(c, wfi.getItem(), WorkflowRequirementsService.WORKFLOW_SCHEMA, "score", null, null,
|
||||||
String.valueOf(score));
|
String.valueOf(score));
|
||||||
itemService.update(c, wfi.getItem());
|
itemService.update(c, wfi.getItem());
|
||||||
|
|
||||||
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
||||||
@@ -54,4 +55,9 @@ public class ScoreReviewAction extends ProcessingAction {
|
|||||||
return new ActionResult(ActionResult.TYPE.TYPE_SUBMISSION_PAGE);
|
return new ActionResult(ActionResult.TYPE.TYPE_SUBMISSION_PAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getOptions() {
|
||||||
|
return Arrays.asList(SUBMIT_SCORE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,8 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.xmlworkflow.state.actions.processingaction;
|
package org.dspace.xmlworkflow.state.actions.processingaction;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -18,7 +18,6 @@ import org.dspace.authorize.AuthorizeException;
|
|||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.eperson.service.EPersonService;
|
import org.dspace.eperson.service.EPersonService;
|
||||||
import org.dspace.workflow.WorkflowException;
|
|
||||||
import org.dspace.xmlworkflow.Role;
|
import org.dspace.xmlworkflow.Role;
|
||||||
import org.dspace.xmlworkflow.state.Step;
|
import org.dspace.xmlworkflow.state.Step;
|
||||||
import org.dspace.xmlworkflow.state.actions.ActionResult;
|
import org.dspace.xmlworkflow.state.actions.ActionResult;
|
||||||
@@ -39,36 +38,38 @@ import org.springframework.beans.factory.annotation.Required;
|
|||||||
*/
|
*/
|
||||||
public class SelectReviewerAction extends ProcessingAction {
|
public class SelectReviewerAction extends ProcessingAction {
|
||||||
|
|
||||||
public static final int MAIN_PAGE = 0;
|
|
||||||
public static final int SEARCH_RESULTS_PAGE = 1;
|
public static final int SEARCH_RESULTS_PAGE = 1;
|
||||||
|
|
||||||
public static final int RESULTS_PER_PAGE = 5;
|
public static final int RESULTS_PER_PAGE = 5;
|
||||||
|
|
||||||
|
private static final String SUBMIT_CANCEL = "submit_cancel";
|
||||||
|
private static final String SUBMIT_SEARCH = "submit_search";
|
||||||
|
private static final String SUBMIT_SELECT_REVIEWER = "submit_select_reviewer_";
|
||||||
|
|
||||||
private Role role;
|
private Role role;
|
||||||
|
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
protected EPersonService ePersonService;
|
private EPersonService ePersonService;
|
||||||
|
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
protected WorkflowItemRoleService workflowItemRoleService;
|
private WorkflowItemRoleService workflowItemRoleService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activate(Context c, XmlWorkflowItem wf)
|
public void activate(Context c, XmlWorkflowItem wf) {
|
||||||
throws SQLException, IOException, AuthorizeException, WorkflowException {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
||||||
throws SQLException, AuthorizeException, IOException, WorkflowException {
|
throws SQLException, AuthorizeException {
|
||||||
String submitButton = Util.getSubmitButton(request, "submit_cancel");
|
String submitButton = Util.getSubmitButton(request, SUBMIT_CANCEL);
|
||||||
|
|
||||||
//Check if our user has pressed cancel
|
//Check if our user has pressed cancel
|
||||||
if (submitButton.equals("submit_cancel")) {
|
if (submitButton.equals(SUBMIT_CANCEL)) {
|
||||||
//Send us back to the submissions page
|
//Send us back to the submissions page
|
||||||
return new ActionResult(ActionResult.TYPE.TYPE_CANCEL);
|
return new ActionResult(ActionResult.TYPE.TYPE_CANCEL);
|
||||||
|
|
||||||
} else if (submitButton.equals("submit_search")) {
|
} else if (submitButton.equals(SUBMIT_SEARCH)) {
|
||||||
//Perform the search
|
//Perform the search
|
||||||
String query = request.getParameter("query");
|
String query = request.getParameter("query");
|
||||||
int page = Util.getIntParameter(request, "result-page");
|
int page = Util.getIntParameter(request, "result-page");
|
||||||
@@ -85,7 +86,7 @@ public class SelectReviewerAction extends ProcessingAction {
|
|||||||
request.setAttribute("result-page", page);
|
request.setAttribute("result-page", page);
|
||||||
request.setAttribute("page", SEARCH_RESULTS_PAGE);
|
request.setAttribute("page", SEARCH_RESULTS_PAGE);
|
||||||
return new ActionResult(ActionResult.TYPE.TYPE_PAGE, SEARCH_RESULTS_PAGE);
|
return new ActionResult(ActionResult.TYPE.TYPE_PAGE, SEARCH_RESULTS_PAGE);
|
||||||
} else if (submitButton.startsWith("submit_select_reviewer_")) {
|
} else if (submitButton.startsWith(SUBMIT_SELECT_REVIEWER)) {
|
||||||
//Retrieve the identifier of the eperson which will do the reviewing
|
//Retrieve the identifier of the eperson which will do the reviewing
|
||||||
UUID reviewerId = UUID.fromString(submitButton.substring(submitButton.lastIndexOf("_") + 1));
|
UUID reviewerId = UUID.fromString(submitButton.substring(submitButton.lastIndexOf("_") + 1));
|
||||||
EPerson reviewer = ePersonService.find(c, reviewerId);
|
EPerson reviewer = ePersonService.find(c, reviewerId);
|
||||||
@@ -102,6 +103,14 @@ public class SelectReviewerAction extends ProcessingAction {
|
|||||||
return new ActionResult(ActionResult.TYPE.TYPE_ERROR);
|
return new ActionResult(ActionResult.TYPE.TYPE_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getOptions() {
|
||||||
|
List<String> options = new ArrayList<>();
|
||||||
|
options.add(SUBMIT_SEARCH);
|
||||||
|
options.add(SUBMIT_SELECT_REVIEWER);
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
public Role getRole() {
|
public Role getRole() {
|
||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,8 @@ package org.dspace.xmlworkflow.state.actions.processingaction;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.dspace.app.util.Util;
|
import org.dspace.app.util.Util;
|
||||||
@@ -38,6 +40,10 @@ public class SingleUserReviewAction extends ProcessingAction {
|
|||||||
|
|
||||||
public static final int OUTCOME_REJECT = 1;
|
public static final int OUTCOME_REJECT = 1;
|
||||||
|
|
||||||
|
protected static final String SUBMIT_APPROVE = "submit_approve";
|
||||||
|
protected static final String SUBMIT_REJECT = "submit_reject";
|
||||||
|
protected static final String SUBMIT_DECLINE_TASK = "submit_decline_task";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activate(Context c, XmlWorkflowItem wfItem) {
|
public void activate(Context c, XmlWorkflowItem wfItem) {
|
||||||
|
|
||||||
@@ -58,19 +64,28 @@ public class SingleUserReviewAction extends ProcessingAction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getOptions() {
|
||||||
|
List<String> options = new ArrayList<>();
|
||||||
|
options.add(SUBMIT_APPROVE);
|
||||||
|
options.add(SUBMIT_REJECT);
|
||||||
|
options.add(SUBMIT_DECLINE_TASK);
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
public ActionResult processMainPage(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
public ActionResult processMainPage(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
||||||
throws SQLException, AuthorizeException {
|
throws SQLException, AuthorizeException {
|
||||||
if (request.getParameter("submit_approve") != null) {
|
if (request.getParameter(SUBMIT_APPROVE) != null) {
|
||||||
//Delete the tasks
|
//Delete the tasks
|
||||||
addApprovedProvenance(c, wfi);
|
addApprovedProvenance(c, wfi);
|
||||||
|
|
||||||
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
||||||
} else if (request.getParameter("submit_reject") != null) {
|
} else if (request.getParameter(SUBMIT_REJECT) != null) {
|
||||||
// Make sure we indicate which page we want to process
|
// Make sure we indicate which page we want to process
|
||||||
request.setAttribute("page", REJECT_PAGE);
|
request.setAttribute("page", REJECT_PAGE);
|
||||||
// We have pressed reject item, so take the user to a page where he can reject
|
// We have pressed reject item, so take the user to a page where he can reject
|
||||||
return new ActionResult(ActionResult.TYPE.TYPE_PAGE);
|
return new ActionResult(ActionResult.TYPE.TYPE_PAGE);
|
||||||
} else if (request.getParameter("submit_decline_task") != null) {
|
} else if (request.getParameter(SUBMIT_DECLINE_TASK) != null) {
|
||||||
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, OUTCOME_REJECT);
|
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, OUTCOME_REJECT);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@@ -8,6 +8,8 @@
|
|||||||
package org.dspace.xmlworkflow.state.actions.userassignment;
|
package org.dspace.xmlworkflow.state.actions.userassignment;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
@@ -34,6 +36,11 @@ public class AssignAction extends UserSelectionAction {
|
|||||||
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getOptions() {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
public void generateTasks() {
|
public void generateTasks() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,7 +9,9 @@ package org.dspace.xmlworkflow.state.actions.userassignment;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
@@ -112,6 +114,11 @@ public class AssignOriginalSubmitterAction extends UserSelectionAction {
|
|||||||
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getOptions() {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a claimed task for the user IF this user doesn't have a claimed action for this workflow item
|
* Create a claimed task for the user IF this user doesn't have a claimed action for this workflow item
|
||||||
*
|
*
|
||||||
|
@@ -9,6 +9,7 @@ package org.dspace.xmlworkflow.state.actions.userassignment;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
@@ -106,6 +107,11 @@ public class AutoAssignAction extends UserSelectionAction {
|
|||||||
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getOptions() {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a claimed task for the user IF this user doesn't have a claimed action for this workflow item
|
* Create a claimed task for the user IF this user doesn't have a claimed action for this workflow item
|
||||||
*
|
*
|
||||||
|
@@ -10,6 +10,7 @@ package org.dspace.xmlworkflow.state.actions.userassignment;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
@@ -67,6 +68,11 @@ public class ClaimAction extends UserSelectionAction {
|
|||||||
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getOptions() {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void alertUsersOnActivation(Context c, XmlWorkflowItem wfi, RoleMembers roleMembers)
|
public void alertUsersOnActivation(Context c, XmlWorkflowItem wfi, RoleMembers roleMembers)
|
||||||
throws IOException, SQLException {
|
throws IOException, SQLException {
|
||||||
|
@@ -8,6 +8,8 @@
|
|||||||
package org.dspace.xmlworkflow.state.actions.userassignment;
|
package org.dspace.xmlworkflow.state.actions.userassignment;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
@@ -37,6 +39,11 @@ public class InheritUsersAction extends UserSelectionAction {
|
|||||||
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getOptions() {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFinished(XmlWorkflowItem wfi) {
|
public boolean isFinished(XmlWorkflowItem wfi) {
|
||||||
return false;
|
return false;
|
||||||
|
@@ -7,14 +7,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.xmlworkflow.state.actions.userassignment;
|
package org.dspace.xmlworkflow.state.actions.userassignment;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.util.ArrayList;
|
||||||
import java.sql.SQLException;
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.dspace.authorize.AuthorizeException;
|
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.xmlworkflow.RoleMembers;
|
import org.dspace.xmlworkflow.RoleMembers;
|
||||||
import org.dspace.xmlworkflow.WorkflowConfigurationException;
|
|
||||||
import org.dspace.xmlworkflow.state.Step;
|
import org.dspace.xmlworkflow.state.Step;
|
||||||
import org.dspace.xmlworkflow.state.actions.ActionResult;
|
import org.dspace.xmlworkflow.state.actions.ActionResult;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
||||||
@@ -34,12 +32,11 @@ public class NoUserSelectionAction extends UserSelectionAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void regenerateTasks(Context c, XmlWorkflowItem wfi, RoleMembers roleMembers) throws SQLException {
|
public void regenerateTasks(Context c, XmlWorkflowItem wfi, RoleMembers roleMembers) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidUserSelection(Context context, XmlWorkflowItem wfi, boolean hasUI)
|
public boolean isValidUserSelection(Context context, XmlWorkflowItem wfi, boolean hasUI) {
|
||||||
throws WorkflowConfigurationException, SQLException {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,12 +46,16 @@ public class NoUserSelectionAction extends UserSelectionAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activate(Context c, XmlWorkflowItem wf) throws SQLException, IOException {
|
public void activate(Context c, XmlWorkflowItem wf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)
|
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request) {
|
||||||
throws SQLException, AuthorizeException, IOException {
|
|
||||||
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getOptions() {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,82 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||||
|
|
||||||
|
<bean id="uploadConfigurationDefault" class="org.dspace.submit.model.UploadConfiguration">
|
||||||
|
<property name="name" value="upload"></property>
|
||||||
|
<property name="configurationService" ref="org.dspace.services.ConfigurationService"/>
|
||||||
|
<property name="metadata" value="bitstream-metadata" />
|
||||||
|
<property name="options">
|
||||||
|
<list>
|
||||||
|
<ref bean="openAccess"/>
|
||||||
|
<ref bean="lease"/>
|
||||||
|
<ref bean="embargoed" />
|
||||||
|
<ref bean="embargoedWithGroupSelect" />
|
||||||
|
<ref bean="administrator"/>
|
||||||
|
<!-- <ref bean="networkAdministration"/> -->
|
||||||
|
</list>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="openAccess" class="org.dspace.submit.model.AccessConditionOption">
|
||||||
|
<property name="groupName" value="Anonymous"/>
|
||||||
|
<property name="name" value="openaccess"/>
|
||||||
|
<property name="hasStartDate" value="false"/>
|
||||||
|
<property name="hasEndDate" value="false"/>
|
||||||
|
</bean>
|
||||||
|
<bean id="lease" class="org.dspace.submit.model.AccessConditionOption">
|
||||||
|
<property name="groupName" value="Anonymous"/>
|
||||||
|
<!--
|
||||||
|
use the selectGroupName to specify the group containing the subgroups
|
||||||
|
that can be used for the policy
|
||||||
|
<property name="selectGroupName" value="Lease Groups"/>
|
||||||
|
-->
|
||||||
|
<property name="name" value="lease"/>
|
||||||
|
<property name="hasStartDate" value="false"/>
|
||||||
|
<property name="hasEndDate" value="true"/>
|
||||||
|
<property name="endDateLimit" value="+6MONTHS"/>
|
||||||
|
</bean>
|
||||||
|
<bean id="embargoed" class="org.dspace.submit.model.AccessConditionOption">
|
||||||
|
<property name="groupName" value="Anonymous"/>
|
||||||
|
<!--
|
||||||
|
use the selectGroupName to specify the group containing the subgroups
|
||||||
|
that can be used for the policy
|
||||||
|
<property name="selectGroupName" value="Embargoed Groups"/>
|
||||||
|
-->
|
||||||
|
<property name="name" value="embargo"/>
|
||||||
|
<property name="hasStartDate" value="true"/>
|
||||||
|
<property name="startDateLimit" value="+36MONTHS"/>
|
||||||
|
<property name="hasEndDate" value="false"/>
|
||||||
|
|
||||||
|
</bean>
|
||||||
|
<bean id="embargoedWithGroupSelect" class="org.dspace.submit.model.AccessConditionOption">
|
||||||
|
<property name="selectGroupName" value="Embargoed Groups"/>
|
||||||
|
<property name="name" value="embargo"/>
|
||||||
|
<property name="hasStartDate" value="true"/>
|
||||||
|
<property name="startDateLimit" value="+36MONTHS"/>
|
||||||
|
<property name="hasEndDate" value="false"/>
|
||||||
|
</bean>
|
||||||
|
<bean id="administrator" class="org.dspace.submit.model.AccessConditionOption">
|
||||||
|
<property name="groupName" value="Administrator"/>
|
||||||
|
<property name="name" value="administrator"/>
|
||||||
|
<property name="hasStartDate" value="false"/>
|
||||||
|
<property name="hasEndDate" value="false"/>
|
||||||
|
</bean>
|
||||||
|
<!-- <bean id="networkAdministration" class="org.dspace.submit.model.AccessConditionOption">
|
||||||
|
<property name="groupName" value="INSTITUTIONAL_NETWORK"/>
|
||||||
|
<property name="name" value="networkAdministration"/>
|
||||||
|
<property name="hasStartDate" value="false"/>
|
||||||
|
<property name="hasEndDate" value="false"/>
|
||||||
|
</bean> -->
|
||||||
|
|
||||||
|
<bean id="uploadConfigurationService" class="org.dspace.submit.model.UploadConfigurationService">
|
||||||
|
<property name="map">
|
||||||
|
<map>
|
||||||
|
<entry key="upload" value-ref="uploadConfigurationDefault" />
|
||||||
|
</map>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
</beans>
|
@@ -0,0 +1,99 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans
|
||||||
|
xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:util="http://www.springframework.org/schema/util"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
|
||||||
|
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd">
|
||||||
|
|
||||||
|
<bean id="claimactionAPI" class="org.dspace.xmlworkflow.state.actions.userassignment.ClaimAction" scope="prototype"/>
|
||||||
|
<bean id="reviewactionAPI" class="org.dspace.xmlworkflow.state.actions.processingaction.ReviewAction" scope="prototype"/>
|
||||||
|
<bean id="editactionAPI" class="org.dspace.xmlworkflow.state.actions.processingaction.AcceptEditRejectAction" scope="prototype"/>
|
||||||
|
<bean id="finaleditactionAPI" class="org.dspace.xmlworkflow.state.actions.processingaction.FinalEditAction" scope="prototype"/>
|
||||||
|
<bean id="singleuserreviewactionAPI" class="org.dspace.xmlworkflow.state.actions.processingaction.SingleUserReviewAction" scope="prototype"/>
|
||||||
|
|
||||||
|
<bean id="selectrevieweractionAPI" class="org.dspace.xmlworkflow.state.actions.processingaction.SelectReviewerAction" scope="prototype">
|
||||||
|
<property name="role" ref="scoreAssignedReviewer"/>
|
||||||
|
</bean>
|
||||||
|
<bean id="scorereviewactionAPI" class="org.dspace.xmlworkflow.state.actions.processingaction.ScoreReviewAction" scope="prototype"/>
|
||||||
|
<bean id="evaluationactionAPI" class="org.dspace.xmlworkflow.state.actions.processingaction.ScoreEvaluationAction" scope="prototype">
|
||||||
|
<property name="minimumAcceptanceScore" value="50" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
<bean id="autoassignactionAPI" class="org.dspace.xmlworkflow.state.actions.userassignment.AutoAssignAction" scope="prototype"/>
|
||||||
|
<bean id="noUserSelectionActionAPI" class="org.dspace.xmlworkflow.state.actions.userassignment.NoUserSelectionAction" scope="prototype"/>
|
||||||
|
<bean id="assignoriginalsubmitteractionAPI" class="org.dspace.xmlworkflow.state.actions.userassignment.AssignOriginalSubmitterAction" scope="prototype"/>
|
||||||
|
|
||||||
|
<bean id="reviewaction" class="org.dspace.xmlworkflow.state.actions.WorkflowActionConfig" scope="prototype">
|
||||||
|
<constructor-arg type="java.lang.String" value="reviewaction"/>
|
||||||
|
<property name="processingAction" ref="reviewactionAPI"/>
|
||||||
|
<property name="requiresUI" value="true"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="editaction" class="org.dspace.xmlworkflow.state.actions.WorkflowActionConfig" scope="prototype">
|
||||||
|
<constructor-arg type="java.lang.String" value="editaction"/>
|
||||||
|
<property name="processingAction" ref="editactionAPI"/>
|
||||||
|
<property name="requiresUI" value="true"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="finaleditaction" class="org.dspace.xmlworkflow.state.actions.WorkflowActionConfig" scope="prototype">
|
||||||
|
<constructor-arg type="java.lang.String" value="finaleditaction"/>
|
||||||
|
<property name="processingAction" ref="finaleditactionAPI"/>
|
||||||
|
<property name="requiresUI" value="true"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
<!--Action for the select single reviewer workflow -->
|
||||||
|
<bean id="selectrevieweraction" class="org.dspace.xmlworkflow.state.actions.WorkflowActionConfig" scope="prototype">
|
||||||
|
<constructor-arg type="java.lang.String" value="selectrevieweraction"/>
|
||||||
|
<property name="processingAction" ref="selectrevieweractionAPI"/>
|
||||||
|
<property name="requiresUI" value="true"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="singleuserreviewaction" class="org.dspace.xmlworkflow.state.actions.WorkflowActionConfig" scope="prototype">
|
||||||
|
<constructor-arg type="java.lang.String" value="singleuserreviewaction"/>
|
||||||
|
<property name="processingAction" ref="singleuserreviewactionAPI"/>
|
||||||
|
<property name="requiresUI" value="true"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="scorereviewaction" class="org.dspace.xmlworkflow.state.actions.WorkflowActionConfig" scope="prototype">
|
||||||
|
<constructor-arg type="java.lang.String" value="scorereviewaction"/>
|
||||||
|
<property name="processingAction" ref="scorereviewactionAPI" />
|
||||||
|
<property name="requiresUI" value="true"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<!--Autmatic step that evaluates scores (workflow.score) and checks if they match the configured minimum for archiving -->
|
||||||
|
<bean id="evaluationaction" class="org.dspace.xmlworkflow.state.actions.WorkflowActionConfig" scope="prototype">
|
||||||
|
<constructor-arg type="java.lang.String" value="evaluationaction"/>
|
||||||
|
<property name="processingAction" ref="evaluationactionAPI" />
|
||||||
|
<property name="requiresUI" value="false"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
<!--User selection actions-->
|
||||||
|
<bean id="claimaction" class="org.dspace.xmlworkflow.state.actions.UserSelectionActionConfig" scope="prototype">
|
||||||
|
<constructor-arg type="java.lang.String" value="claimaction"/>
|
||||||
|
<property name="processingAction" ref="claimactionAPI"/>
|
||||||
|
<property name="requiresUI" value="true"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="autoassignAction" class="org.dspace.xmlworkflow.state.actions.UserSelectionActionConfig" scope="prototype">
|
||||||
|
<constructor-arg type="java.lang.String" value="autoassignAction"/>
|
||||||
|
<property name="processingAction" ref="autoassignactionAPI"/>
|
||||||
|
<property name="requiresUI" value="false"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="noUserSelectionAction" class="org.dspace.xmlworkflow.state.actions.UserSelectionActionConfig" scope="prototype">
|
||||||
|
<constructor-arg type="java.lang.String" value="noUserSelectionAction"/>
|
||||||
|
<property name="processingAction" ref="noUserSelectionActionAPI"/>
|
||||||
|
<property name="requiresUI" value="false"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="originalSubmitterAssignAction" class="org.dspace.xmlworkflow.state.actions.UserSelectionActionConfig" scope="prototype">
|
||||||
|
<constructor-arg type="java.lang.String" value=""/>
|
||||||
|
<property name="processingAction" ref="assignoriginalsubmitteractionAPI"/>
|
||||||
|
<property name="requiresUI" value="false"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
</beans>
|
@@ -9,8 +9,8 @@
|
|||||||
<util:map>
|
<util:map>
|
||||||
<entry key="defaultWorkflow"
|
<entry key="defaultWorkflow"
|
||||||
value-ref="defaultWorkflow"/>
|
value-ref="defaultWorkflow"/>
|
||||||
<entry key="123456789/4" value-ref="selectSingleReviewer"/>
|
<entry key="123456789/workflow-test-1" value-ref="selectSingleReviewer"/>
|
||||||
<!-- <entry key="123456789/5" value-ref="scoreReview"/>-->
|
<!-- <entry key="123456789/5" value-ref="scoreReview"/>-->
|
||||||
</util:map>
|
</util:map>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
@@ -15,9 +15,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.transform.Source;
|
import javax.xml.transform.Source;
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
@@ -47,7 +45,6 @@ import org.xmlunit.diff.ComparisonFormatter;
|
|||||||
import org.xmlunit.diff.DefaultComparisonFormatter;
|
import org.xmlunit.diff.DefaultComparisonFormatter;
|
||||||
import org.xmlunit.diff.Diff;
|
import org.xmlunit.diff.Diff;
|
||||||
import org.xmlunit.diff.Difference;
|
import org.xmlunit.diff.Difference;
|
||||||
import org.xmlunit.util.Predicate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests of {@link StructBuilder}.
|
* Tests of {@link StructBuilder}.
|
||||||
@@ -314,9 +311,9 @@ public class StructBuilderIT
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reject uninteresting nodes.
|
* Reject uninteresting nodes. (currently commented out of tests above)
|
||||||
*/
|
*/
|
||||||
private static class MyNodeFilter implements Predicate<Node> {
|
/*private static class MyNodeFilter implements Predicate<Node> {
|
||||||
private static final List<String> dontCare = Arrays.asList(
|
private static final List<String> dontCare = Arrays.asList(
|
||||||
"description",
|
"description",
|
||||||
"intro",
|
"intro",
|
||||||
@@ -330,5 +327,5 @@ public class StructBuilderIT
|
|||||||
String type = node.getLocalName();
|
String type = node.getLocalName();
|
||||||
return ! dontCare.contains(type);
|
return ! dontCare.contains(type);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
package org.dspace.app.util;
|
package org.dspace.app.util;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@@ -14,7 +14,9 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.AbstractUnitTest;
|
import org.dspace.AbstractUnitTest;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
@@ -85,7 +87,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
|||||||
log.error("SQL Error in init", ex);
|
log.error("SQL Error in init", ex);
|
||||||
fail("SQL Error in init: " + ex.getMessage());
|
fail("SQL Error in init: " + ex.getMessage());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
log.error("IO Error in init", e);
|
||||||
|
fail("IO Error in init: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,8 +122,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
|||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
context.commit();
|
context.commit();
|
||||||
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
||||||
String[] urlSplitted = gm.getPDFURL().get(0).split("/");
|
List<String> urlSplitted = Splitter.on("/").splitToList(gm.getPDFURL().get(0));
|
||||||
assertEquals("Pdf", urlSplitted[urlSplitted.length - 1]);
|
assertEquals("Pdf", urlSplitted.get(urlSplitted.size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -154,8 +157,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
|||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
context.commit();
|
context.commit();
|
||||||
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
||||||
String[] urlSplitted = gm.getPDFURL().get(0).split("/");
|
List<String> urlSplitted = Splitter.on("/").splitToList(gm.getPDFURL().get(0));
|
||||||
assertEquals("size9", urlSplitted[urlSplitted.length - 1]);
|
assertEquals("size9", urlSplitted.get(urlSplitted.size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -189,8 +192,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
|||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
context.commit();
|
context.commit();
|
||||||
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
||||||
String[] urlSplitted = gm.getPDFURL().get(0).split("/");
|
List<String> urlSplitted = Splitter.on("/").splitToList(gm.getPDFURL().get(0));
|
||||||
assertEquals("first", urlSplitted[urlSplitted.length - 1]);
|
assertEquals("first", urlSplitted.get(urlSplitted.size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -225,8 +228,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
|||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
context.commit();
|
context.commit();
|
||||||
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
||||||
String[] urlSplitted = gm.getPDFURL().get(0).split("/");
|
List<String> urlSplitted = Splitter.on("/").splitToList(gm.getPDFURL().get(0));
|
||||||
assertEquals("primary", urlSplitted[urlSplitted.length - 1]);
|
assertEquals("primary", urlSplitted.get(urlSplitted.size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -261,8 +264,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
|||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
context.commit();
|
context.commit();
|
||||||
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
||||||
String[] urlSplitted = gm.getPDFURL().get(0).split("/");
|
List<String> urlSplitted = Splitter.on("/").splitToList(gm.getPDFURL().get(0));
|
||||||
assertEquals("large", urlSplitted[urlSplitted.length - 1]);
|
assertEquals("large", urlSplitted.get(urlSplitted.size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -285,7 +288,7 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetPDFURLWithNoBitstreams() throws Exception {
|
public void testGetPDFURLWithNoBitstreams() throws Exception {
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
Bundle bundle = ContentServiceFactory.getInstance().getBundleService().create(context, it, "ORIGINAL");
|
ContentServiceFactory.getInstance().getBundleService().create(context, it, "ORIGINAL");
|
||||||
|
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
context.commit();
|
context.commit();
|
||||||
@@ -319,8 +322,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
|||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
context.commit();
|
context.commit();
|
||||||
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
GoogleMetadata gm = new GoogleMetadata(this.context, it);
|
||||||
String[] urlSplitted = gm.getPDFURL().get(0).split("/");
|
List<String> urlSplitted = Splitter.on("/").splitToList(gm.getPDFURL().get(0));
|
||||||
assertEquals("small", urlSplitted[urlSplitted.length - 1]);
|
assertEquals("small", urlSplitted.get(urlSplitted.size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -334,12 +337,8 @@ public class GoogleMetadataTest extends AbstractUnitTest {
|
|||||||
community = context.reloadEntity(community);
|
community = context.reloadEntity(community);
|
||||||
ContentServiceFactory.getInstance().getCommunityService().delete(context, community);
|
ContentServiceFactory.getInstance().getCommunityService().delete(context, community);
|
||||||
community = null;
|
community = null;
|
||||||
} catch (SQLException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
throw new AssertionError("Error occurred in destroy()", e);
|
||||||
} catch (AuthorizeException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
it = null;
|
it = null;
|
||||||
super.destroy();
|
super.destroy();
|
||||||
|
@@ -264,8 +264,8 @@ public class IPMatcherTest {
|
|||||||
assertFalse(ipMatcher.match("192.1.2.2"));
|
assertFalse(ipMatcher.match("192.1.2.2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Commented out as this is currently not used in tests
|
||||||
private ArrayList<String> getAllIp4Except(ArrayList<String> exceptions) {
|
/*private ArrayList<String> getAllIp4Except(ArrayList<String> exceptions) {
|
||||||
int d1 = 0;
|
int d1 = 0;
|
||||||
int d2 = 0;
|
int d2 = 0;
|
||||||
int d3 = 0;
|
int d3 = 0;
|
||||||
@@ -284,7 +284,7 @@ public class IPMatcherTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ips;
|
return ips;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private void verifyAllIp4Except(ArrayList<String> exceptions, boolean asserted, IPMatcher ipMatcher)
|
private void verifyAllIp4Except(ArrayList<String> exceptions, boolean asserted, IPMatcher ipMatcher)
|
||||||
throws IPMatcherException {
|
throws IPMatcherException {
|
||||||
|
@@ -90,8 +90,7 @@ public class AuthorizeServiceTest extends AbstractUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testauthorizeMethodRespectSpecialGroups() {
|
public void testauthorizeMethodRespectSpecialGroups() {
|
||||||
|
|
||||||
EPerson eperson1;
|
EPerson eperson;
|
||||||
EPerson eperson2;
|
|
||||||
Group group1;
|
Group group1;
|
||||||
|
|
||||||
Community dso;
|
Community dso;
|
||||||
@@ -99,7 +98,7 @@ public class AuthorizeServiceTest extends AbstractUnitTest {
|
|||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
|
|
||||||
// create an eperson and a group
|
// create an eperson and a group
|
||||||
eperson1 = ePersonService.create(context);
|
eperson = ePersonService.create(context);
|
||||||
group1 = groupService.create(context);
|
group1 = groupService.create(context);
|
||||||
// A group has to have a name, otherwise there are queries that break
|
// A group has to have a name, otherwise there are queries that break
|
||||||
groupService.setName(group1, "My test group 2");
|
groupService.setName(group1, "My test group 2");
|
||||||
@@ -111,19 +110,19 @@ public class AuthorizeServiceTest extends AbstractUnitTest {
|
|||||||
// special group to the user. Then test if the action on the DSO
|
// special group to the user. Then test if the action on the DSO
|
||||||
// is allowed for the user
|
// is allowed for the user
|
||||||
authorizeService.addPolicy(context, dso, Constants.ADD, group1);
|
authorizeService.addPolicy(context, dso, Constants.ADD, group1);
|
||||||
context.setCurrentUser(eperson1);
|
context.setCurrentUser(eperson);
|
||||||
context.setSpecialGroup(group1.getID());
|
context.setSpecialGroup(group1.getID());
|
||||||
context.commit();
|
context.commit();
|
||||||
} catch (SQLException | AuthorizeException ex) {
|
} catch (SQLException | AuthorizeException ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new AssertionError(ex);
|
||||||
} finally {
|
} finally {
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Assert.assertTrue(authorizeService.authorizeActionBoolean(context, eperson1, dso, Constants.ADD, true));
|
Assert.assertTrue(authorizeService.authorizeActionBoolean(context, eperson, dso, Constants.ADD, true));
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new AssertionError(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -232,7 +232,7 @@ public class BitstreamFormatTest extends AbstractUnitTest {
|
|||||||
// Disalow full Admin perms
|
// Disalow full Admin perms
|
||||||
when(authorizeServiceSpy.isAdmin(context)).thenReturn(false);
|
when(authorizeServiceSpy.isAdmin(context)).thenReturn(false);
|
||||||
|
|
||||||
BitstreamFormat found = bitstreamFormatService.create(context);
|
bitstreamFormatService.create(context);
|
||||||
fail("Exception should have been thrown");
|
fail("Exception should have been thrown");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -363,7 +363,7 @@ public class BundleTest extends AbstractDSpaceObjectTest {
|
|||||||
doThrow(new AuthorizeException()).when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
|
doThrow(new AuthorizeException()).when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
|
||||||
|
|
||||||
File f = new File(testProps.get("test.bitstream").toString());
|
File f = new File(testProps.get("test.bitstream").toString());
|
||||||
Bitstream bs = bitstreamService.create(context, b, new FileInputStream(f));
|
bitstreamService.create(context, b, new FileInputStream(f));
|
||||||
fail("Exception should be thrown");
|
fail("Exception should be thrown");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,7 +399,7 @@ public class BundleTest extends AbstractDSpaceObjectTest {
|
|||||||
|
|
||||||
int assetstore = 0; //default assetstore
|
int assetstore = 0; //default assetstore
|
||||||
File f = new File(testProps.get("test.bitstream").toString());
|
File f = new File(testProps.get("test.bitstream").toString());
|
||||||
Bitstream bs = bitstreamService.register(context, b, assetstore, f.getAbsolutePath());
|
bitstreamService.register(context, b, assetstore, f.getAbsolutePath());
|
||||||
fail("Exception should be thrown");
|
fail("Exception should be thrown");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -196,7 +196,7 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
|
|||||||
|
|
||||||
// test creating collection with a specified handle which IS already in use
|
// test creating collection with a specified handle which IS already in use
|
||||||
// This should throw an exception
|
// This should throw an exception
|
||||||
Collection created = collectionService.create(context, owningCommunity, inUseHandle);
|
collectionService.create(context, owningCommunity, inUseHandle);
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,7 +291,6 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
|
|||||||
String itext = "introductory text";
|
String itext = "introductory text";
|
||||||
String copy = "copyright declaration";
|
String copy = "copyright declaration";
|
||||||
String sidebar = "side bar text";
|
String sidebar = "side bar text";
|
||||||
String tempItem = "3";
|
|
||||||
String provDesc = "provenance description";
|
String provDesc = "provenance description";
|
||||||
String license = "license text";
|
String license = "license text";
|
||||||
|
|
||||||
@@ -370,7 +369,7 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
|
|||||||
@Test(expected = AuthorizeException.class)
|
@Test(expected = AuthorizeException.class)
|
||||||
public void testSetLogoNoAuth() throws Exception {
|
public void testSetLogoNoAuth() throws Exception {
|
||||||
File f = new File(testProps.get("test.bitstream").toString());
|
File f = new File(testProps.get("test.bitstream").toString());
|
||||||
Bitstream logo = collectionService.setLogo(context, collection, new FileInputStream(f));
|
collectionService.setLogo(context, collection, new FileInputStream(f));
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,7 +392,7 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
|
|||||||
@Test(expected = AuthorizeException.class)
|
@Test(expected = AuthorizeException.class)
|
||||||
public void testCreateWorkflowGroupNoAuth() throws Exception {
|
public void testCreateWorkflowGroupNoAuth() throws Exception {
|
||||||
int step = 1;
|
int step = 1;
|
||||||
Group result = collectionService.createWorkflowGroup(context, collection, step);
|
collectionService.createWorkflowGroup(context, collection, step);
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,7 +460,7 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
|
|||||||
*/
|
*/
|
||||||
@Test(expected = AuthorizeException.class)
|
@Test(expected = AuthorizeException.class)
|
||||||
public void testCreateSubmittersNoAuth() throws Exception {
|
public void testCreateSubmittersNoAuth() throws Exception {
|
||||||
Group result = collectionService.createSubmitters(context, collection);
|
collectionService.createSubmitters(context, collection);
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,7 +510,7 @@ public class CollectionTest extends AbstractDSpaceObjectTest {
|
|||||||
*/
|
*/
|
||||||
@Test(expected = AuthorizeException.class)
|
@Test(expected = AuthorizeException.class)
|
||||||
public void testCreateAdministratorsNoAuth() throws Exception {
|
public void testCreateAdministratorsNoAuth() throws Exception {
|
||||||
Group result = collectionService.createAdministrators(context, collection);
|
collectionService.createAdministrators(context, collection);
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -195,7 +195,7 @@ public class CommunityTest extends AbstractDSpaceObjectTest {
|
|||||||
|
|
||||||
// test creating community with no parent (as a non-admin)
|
// test creating community with no parent (as a non-admin)
|
||||||
// this should throw an exception
|
// this should throw an exception
|
||||||
Community created = communityService.create(null, context);
|
communityService.create(null, context);
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ public class CommunityTest extends AbstractDSpaceObjectTest {
|
|||||||
|
|
||||||
// test creating community with a specified handle which IS already in use
|
// test creating community with a specified handle which IS already in use
|
||||||
// This should throw an exception
|
// This should throw an exception
|
||||||
Community created = communityService.create(null, context, inUseHandle);
|
communityService.create(null, context, inUseHandle);
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,7 +378,7 @@ public class CommunityTest extends AbstractDSpaceObjectTest {
|
|||||||
doThrow(new AuthorizeException()).when(authorizeServiceSpy).authorizeAction(context, c, Constants.WRITE);
|
doThrow(new AuthorizeException()).when(authorizeServiceSpy).authorizeAction(context, c, Constants.WRITE);
|
||||||
|
|
||||||
File f = new File(testProps.get("test.bitstream").toString());
|
File f = new File(testProps.get("test.bitstream").toString());
|
||||||
Bitstream logo = communityService.setLogo(context, c, new FileInputStream(f));
|
communityService.setLogo(context, c, new FileInputStream(f));
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,7 +425,7 @@ public class CommunityTest extends AbstractDSpaceObjectTest {
|
|||||||
*/
|
*/
|
||||||
@Test(expected = AuthorizeException.class)
|
@Test(expected = AuthorizeException.class)
|
||||||
public void testCreateAdministratorsNoAuth() throws Exception {
|
public void testCreateAdministratorsNoAuth() throws Exception {
|
||||||
Group result = communityService.createAdministrators(context, c);
|
communityService.createAdministrators(context, c);
|
||||||
fail("Exception should have been thrown");
|
fail("Exception should have been thrown");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -617,7 +617,7 @@ public class CommunityTest extends AbstractDSpaceObjectTest {
|
|||||||
// Disallow current Community ADD perms
|
// Disallow current Community ADD perms
|
||||||
doThrow(new AuthorizeException()).when(authorizeServiceSpy).authorizeAction(context, c, Constants.ADD);
|
doThrow(new AuthorizeException()).when(authorizeServiceSpy).authorizeAction(context, c, Constants.ADD);
|
||||||
|
|
||||||
Collection result = collectionService.create(context, c);
|
collectionService.create(context, c);
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -672,7 +672,7 @@ public class CommunityTest extends AbstractDSpaceObjectTest {
|
|||||||
// Disallow current Community ADD perms
|
// Disallow current Community ADD perms
|
||||||
doThrow(new AuthorizeException()).when(authorizeServiceSpy).authorizeAction(context, c, Constants.ADD);
|
doThrow(new AuthorizeException()).when(authorizeServiceSpy).authorizeAction(context, c, Constants.ADD);
|
||||||
|
|
||||||
Community result = communityService.createSubcommunity(context, c);
|
communityService.createSubcommunity(context, c);
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -872,8 +872,9 @@ public class CommunityTest extends AbstractDSpaceObjectTest {
|
|||||||
Collection grandchildCol = collectionService.create(context, grandchild);
|
Collection grandchildCol = collectionService.create(context, grandchild);
|
||||||
// Create two separate items
|
// Create two separate items
|
||||||
WorkspaceItem wsItem = workspaceItemService.create(context, childCol, false);
|
WorkspaceItem wsItem = workspaceItemService.create(context, childCol, false);
|
||||||
wsItem = workspaceItemService.create(context, childCol, false);
|
|
||||||
Item item = installItemService.installItem(context, wsItem);
|
Item item = installItemService.installItem(context, wsItem);
|
||||||
|
wsItem = workspaceItemService.create(context, grandchildCol, false);
|
||||||
|
Item item2 = installItemService.installItem(context, wsItem);
|
||||||
|
|
||||||
// Done creating the objects. Turn auth system back on
|
// Done creating the objects. Turn auth system back on
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
@@ -885,6 +886,7 @@ public class CommunityTest extends AbstractDSpaceObjectTest {
|
|||||||
UUID childColId = childCol.getID();
|
UUID childColId = childCol.getID();
|
||||||
UUID grandchildColId = grandchildCol.getID();
|
UUID grandchildColId = grandchildCol.getID();
|
||||||
UUID itemId = item.getID();
|
UUID itemId = item.getID();
|
||||||
|
UUID item2Id = item2.getID();
|
||||||
|
|
||||||
// Delete the parent of this entire hierarchy
|
// Delete the parent of this entire hierarchy
|
||||||
communityService.delete(context, parent);
|
communityService.delete(context, parent);
|
||||||
@@ -902,6 +904,8 @@ public class CommunityTest extends AbstractDSpaceObjectTest {
|
|||||||
collectionService.find(context, grandchildColId), nullValue());
|
collectionService.find(context, grandchildColId), nullValue());
|
||||||
assertThat("Item not deleted",
|
assertThat("Item not deleted",
|
||||||
itemService.find(context, itemId), nullValue());
|
itemService.find(context, itemId), nullValue());
|
||||||
|
assertThat("Item not deleted",
|
||||||
|
itemService.find(context, item2Id), nullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1030,7 +1034,7 @@ public class CommunityTest extends AbstractDSpaceObjectTest {
|
|||||||
assertThat("testGetParentObject 1", communityService.getParentObject(context, son), notNullValue());
|
assertThat("testGetParentObject 1", communityService.getParentObject(context, son), notNullValue());
|
||||||
assertThat("testGetParentObject 2", (Community) communityService.getParentObject(context, son), equalTo(c));
|
assertThat("testGetParentObject 2", (Community) communityService.getParentObject(context, son), equalTo(c));
|
||||||
} catch (AuthorizeException ex) {
|
} catch (AuthorizeException ex) {
|
||||||
fail("Authorize exception catched");
|
throw new AssertionError("AuthorizeException occurred", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -19,7 +19,6 @@ import java.util.Locale;
|
|||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.apache.commons.lang3.time.DateUtils;
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -28,11 +27,6 @@ import org.junit.Test;
|
|||||||
* @author pvillega
|
* @author pvillega
|
||||||
*/
|
*/
|
||||||
public class DCDateTest {
|
public class DCDateTest {
|
||||||
/**
|
|
||||||
* log4j category
|
|
||||||
*/
|
|
||||||
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(DCDateTest.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object to use in the tests
|
* Object to use in the tests
|
||||||
*/
|
*/
|
||||||
|
@@ -8,16 +8,14 @@
|
|||||||
package org.dspace.content;
|
package org.dspace.content;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.dspace.content.dao.RelationshipTypeDAO;
|
|
||||||
import org.dspace.content.service.EntityTypeService;
|
import org.dspace.content.service.EntityTypeService;
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
import org.dspace.content.service.RelationshipService;
|
import org.dspace.content.service.RelationshipService;
|
||||||
@@ -60,10 +58,8 @@ public class EntityServiceImplTest {
|
|||||||
public void testfindByItemId() throws Exception {
|
public void testfindByItemId() throws Exception {
|
||||||
// Declare objects utilized in unit test
|
// Declare objects utilized in unit test
|
||||||
Item item = mock(Item.class);
|
Item item = mock(Item.class);
|
||||||
List<Relationship> relationshipList = new ArrayList<>();
|
|
||||||
Relationship relationship = mock(Relationship.class);
|
Relationship relationship = mock(Relationship.class);
|
||||||
relationship.setId(9);
|
relationship.setId(9);
|
||||||
relationshipList.add(relationship);
|
|
||||||
|
|
||||||
// Mock the state of objects utilized in findByItemId() to meet the success criteria of an invocation
|
// Mock the state of objects utilized in findByItemId() to meet the success criteria of an invocation
|
||||||
when(itemService.find(any(), any())).thenReturn(item);
|
when(itemService.find(any(), any())).thenReturn(item);
|
||||||
@@ -79,10 +75,6 @@ public class EntityServiceImplTest {
|
|||||||
// Declare objects utilized in unit test
|
// Declare objects utilized in unit test
|
||||||
Entity entity = mock(Entity.class);
|
Entity entity = mock(Entity.class);
|
||||||
EntityTypeService entityTypeService = mock(EntityTypeService.class);
|
EntityTypeService entityTypeService = mock(EntityTypeService.class);
|
||||||
Item item = mock(Item.class);
|
|
||||||
List<MetadataValue> list = new ArrayList<>();
|
|
||||||
MetadataValue metadataValue = mock(MetadataValue.class);
|
|
||||||
list.add(metadataValue);
|
|
||||||
EntityType entityType = entityTypeService.findByEntityType(context, "testType");
|
EntityType entityType = entityTypeService.findByEntityType(context, "testType");
|
||||||
|
|
||||||
// The returned EntityType should equal our defined entityType case
|
// The returned EntityType should equal our defined entityType case
|
||||||
@@ -151,11 +143,7 @@ public class EntityServiceImplTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetAllRelationshipTypes() throws Exception {
|
public void testGetAllRelationshipTypes() throws Exception {
|
||||||
// Declare objects utilized for this test
|
// Declare objects utilized for this test
|
||||||
List<MetadataValue> list = new ArrayList<>();
|
|
||||||
MetadataValue metadataValue = mock(MetadataValue.class);
|
|
||||||
list.add(metadataValue);
|
|
||||||
Item item = mock(Item.class);
|
Item item = mock(Item.class);
|
||||||
RelationshipTypeDAO relationshipTypeDAO = mock(RelationshipTypeDAO.class);
|
|
||||||
Entity entity = mock(Entity.class);
|
Entity entity = mock(Entity.class);
|
||||||
RelationshipType relationshipType = mock(RelationshipType.class);
|
RelationshipType relationshipType = mock(RelationshipType.class);
|
||||||
relationshipType.setLeftType(leftType);
|
relationshipType.setLeftType(leftType);
|
||||||
@@ -185,7 +173,7 @@ public class EntityServiceImplTest {
|
|||||||
RelationshipType relationshipType = mock(RelationshipType.class);
|
RelationshipType relationshipType = mock(RelationshipType.class);
|
||||||
|
|
||||||
// Currently this unit test will only test one case with one relationshipType
|
// Currently this unit test will only test one case with one relationshipType
|
||||||
List<RelationshipType> relationshipTypeList = new LinkedList<>();
|
List<RelationshipType> relationshipTypeList = new ArrayList<>();
|
||||||
relationshipTypeList.add(relationshipType);
|
relationshipTypeList.add(relationshipType);
|
||||||
List<MetadataValue> metsList = new ArrayList<>();
|
List<MetadataValue> metsList = new ArrayList<>();
|
||||||
MetadataValue metadataValue = mock(MetadataValue.class);
|
MetadataValue metadataValue = mock(MetadataValue.class);
|
||||||
@@ -213,7 +201,7 @@ public class EntityServiceImplTest {
|
|||||||
RelationshipType relationshipType = mock(RelationshipType.class);
|
RelationshipType relationshipType = mock(RelationshipType.class);
|
||||||
|
|
||||||
// Currently this unit test will only test one case with one relationshipType
|
// Currently this unit test will only test one case with one relationshipType
|
||||||
List<RelationshipType> relationshipTypeList = new LinkedList<>();
|
List<RelationshipType> relationshipTypeList = new ArrayList<>();
|
||||||
relationshipTypeList.add(relationshipType);
|
relationshipTypeList.add(relationshipType);
|
||||||
List<MetadataValue> metsList = new ArrayList<>();
|
List<MetadataValue> metsList = new ArrayList<>();
|
||||||
MetadataValue metadataValue = mock(MetadataValue.class);
|
MetadataValue metadataValue = mock(MetadataValue.class);
|
||||||
@@ -236,7 +224,7 @@ public class EntityServiceImplTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetRelationshipTypesByTypeName() throws Exception {
|
public void testGetRelationshipTypesByTypeName() throws Exception {
|
||||||
// Declare objects utilized in unit test
|
// Declare objects utilized in unit test
|
||||||
List<RelationshipType> list = new LinkedList<>();
|
List<RelationshipType> list = new ArrayList<>();
|
||||||
RelationshipType relationshipType = mock(RelationshipType.class);
|
RelationshipType relationshipType = mock(RelationshipType.class);
|
||||||
list.add(relationshipType);
|
list.add(relationshipType);
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
package org.dspace.content;
|
package org.dspace.content;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@@ -14,7 +14,6 @@ import static org.junit.Assert.assertThat;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.dspace.AbstractUnitTest;
|
import org.dspace.AbstractUnitTest;
|
||||||
import org.dspace.content.factory.ContentServiceFactory;
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
import org.dspace.content.service.BitstreamFormatService;
|
import org.dspace.content.service.BitstreamFormatService;
|
||||||
@@ -30,11 +29,6 @@ import org.junit.Test;
|
|||||||
*/
|
*/
|
||||||
public class FormatIdentifierTest extends AbstractUnitTest {
|
public class FormatIdentifierTest extends AbstractUnitTest {
|
||||||
|
|
||||||
/**
|
|
||||||
* log4j category
|
|
||||||
*/
|
|
||||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(FormatIdentifierTest.class);
|
|
||||||
|
|
||||||
protected BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService();
|
protected BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService();
|
||||||
protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory.getInstance()
|
protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory.getInstance()
|
||||||
.getBitstreamFormatService();
|
.getBitstreamFormatService();
|
||||||
@@ -71,8 +65,8 @@ public class FormatIdentifierTest extends AbstractUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGuessFormat() throws Exception {
|
public void testGuessFormat() throws Exception {
|
||||||
File f = new File(testProps.get("test.bitstream").toString());
|
File f = new File(testProps.get("test.bitstream").toString());
|
||||||
Bitstream bs = null;
|
Bitstream bs;
|
||||||
BitstreamFormat result = null;
|
BitstreamFormat result;
|
||||||
BitstreamFormat pdf = bitstreamFormatService.findByShortDescription(context, "Adobe PDF");
|
BitstreamFormat pdf = bitstreamFormatService.findByShortDescription(context, "Adobe PDF");
|
||||||
|
|
||||||
//test null filename
|
//test null filename
|
||||||
|
@@ -19,7 +19,6 @@ import java.io.IOException;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.dspace.AbstractIntegrationTest;
|
import org.dspace.AbstractIntegrationTest;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.factory.ContentServiceFactory;
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
@@ -48,11 +47,6 @@ import org.junit.Test;
|
|||||||
* @author tdonohue
|
* @author tdonohue
|
||||||
*/
|
*/
|
||||||
public class ITCommunityCollection extends AbstractIntegrationTest {
|
public class ITCommunityCollection extends AbstractIntegrationTest {
|
||||||
/**
|
|
||||||
* log4j category
|
|
||||||
*/
|
|
||||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(ITCommunityCollection.class);
|
|
||||||
|
|
||||||
protected CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
|
protected CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
|
||||||
protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
||||||
protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
|
protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
|
||||||
@@ -107,8 +101,8 @@ public class ITCommunityCollection extends AbstractIntegrationTest {
|
|||||||
//verify it works as expected
|
//verify it works as expected
|
||||||
assertThat("testCreateTree 0", parent.getParentCommunities().size(), is(0));
|
assertThat("testCreateTree 0", parent.getParentCommunities().size(), is(0));
|
||||||
assertThat("testCreateTree 1", child1.getParentCommunities().get(0), equalTo(parent));
|
assertThat("testCreateTree 1", child1.getParentCommunities().get(0), equalTo(parent));
|
||||||
assertThat("testCreateTree 2", (Community) collectionService.getParentObject(context, col1), equalTo(child1));
|
assertThat("testCreateTree 2", collectionService.getParentObject(context, col1), equalTo(child1));
|
||||||
assertThat("testCreateTree 3", (Community) collectionService.getParentObject(context, col2), equalTo(child1));
|
assertThat("testCreateTree 3", collectionService.getParentObject(context, col2), equalTo(child1));
|
||||||
|
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
communityService.delete(context, parent);
|
communityService.delete(context, parent);
|
||||||
@@ -133,8 +127,8 @@ public class ITCommunityCollection extends AbstractIntegrationTest {
|
|||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
//verify it works as expected
|
//verify it works as expected
|
||||||
assertThat("testCreateItems 0", (Collection) itemService.getParentObject(context, item1), equalTo(col1));
|
assertThat("testCreateItems 0", itemService.getParentObject(context, item1), equalTo(col1));
|
||||||
assertThat("testCreateItems 1", (Collection) itemService.getParentObject(context, item2), equalTo(col2));
|
assertThat("testCreateItems 1", itemService.getParentObject(context, item2), equalTo(col2));
|
||||||
|
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
communityService.delete(context, parent);
|
communityService.delete(context, parent);
|
||||||
@@ -158,8 +152,8 @@ public class ITCommunityCollection extends AbstractIntegrationTest {
|
|||||||
|
|
||||||
// Add same number of items to each collection
|
// Add same number of items to each collection
|
||||||
for (int count = 0; count < items_per_collection; count++) {
|
for (int count = 0; count < items_per_collection; count++) {
|
||||||
Item item1 = installItemService.installItem(context, workspaceItemService.create(context, col1, false));
|
installItemService.installItem(context, workspaceItemService.create(context, col1, false));
|
||||||
Item item2 = installItemService.installItem(context, workspaceItemService.create(context, col2, false));
|
installItemService.installItem(context, workspaceItemService.create(context, col2, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, let's throw in a small wrench and add a mapped item
|
// Finally, let's throw in a small wrench and add a mapped item
|
||||||
@@ -229,7 +223,6 @@ public class ITCommunityCollection extends AbstractIntegrationTest {
|
|||||||
context.setCurrentUser(commAdmin);
|
context.setCurrentUser(commAdmin);
|
||||||
|
|
||||||
// Test deletion of single Bitstream as a Community Admin (delete just flags as deleted)
|
// Test deletion of single Bitstream as a Community Admin (delete just flags as deleted)
|
||||||
UUID bitstreamId = bitstream.getID();
|
|
||||||
bitstreamService.delete(context, bitstream);
|
bitstreamService.delete(context, bitstream);
|
||||||
assertTrue("Community Admin unable to flag Bitstream as deleted",
|
assertTrue("Community Admin unable to flag Bitstream as deleted",
|
||||||
bitstream.isDeleted());
|
bitstream.isDeleted());
|
||||||
@@ -312,7 +305,6 @@ public class ITCommunityCollection extends AbstractIntegrationTest {
|
|||||||
context.setCurrentUser(collAdmin);
|
context.setCurrentUser(collAdmin);
|
||||||
|
|
||||||
// Test deletion of single Bitstream as a Collection Admin (delete just flags as deleted)
|
// Test deletion of single Bitstream as a Collection Admin (delete just flags as deleted)
|
||||||
UUID bitstreamId = bitstream2.getID();
|
|
||||||
bitstreamService.delete(context, bitstream2);
|
bitstreamService.delete(context, bitstream2);
|
||||||
assertTrue("Collection Admin unable to flag Bitstream as deleted",
|
assertTrue("Collection Admin unable to flag Bitstream as deleted",
|
||||||
bitstream2.isDeleted());
|
bitstream2.isDeleted());
|
||||||
@@ -327,7 +319,6 @@ public class ITCommunityCollection extends AbstractIntegrationTest {
|
|||||||
// Test deletion of single Item as a Collection Admin
|
// Test deletion of single Item as a Collection Admin
|
||||||
UUID itemId = item.getID();
|
UUID itemId = item.getID();
|
||||||
bundleId = bundle.getID();
|
bundleId = bundle.getID();
|
||||||
bitstreamId = bitstream.getID();
|
|
||||||
itemService.delete(context, item);
|
itemService.delete(context, item);
|
||||||
assertThat("Collection Admin unable to delete sub-Item",
|
assertThat("Collection Admin unable to delete sub-Item",
|
||||||
itemService.find(context, itemId), nullValue());
|
itemService.find(context, itemId), nullValue());
|
||||||
|
@@ -16,7 +16,6 @@ import java.io.IOException;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.dspace.AbstractIntegrationTest;
|
import org.dspace.AbstractIntegrationTest;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.factory.ContentServiceFactory;
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
@@ -37,11 +36,6 @@ import org.junit.Test;
|
|||||||
* @author pvillega
|
* @author pvillega
|
||||||
*/
|
*/
|
||||||
public class ITMetadata extends AbstractIntegrationTest {
|
public class ITMetadata extends AbstractIntegrationTest {
|
||||||
/**
|
|
||||||
* log4j category
|
|
||||||
*/
|
|
||||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(ITMetadata.class);
|
|
||||||
|
|
||||||
|
|
||||||
protected CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
|
protected CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
|
||||||
protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
||||||
|
@@ -7,7 +7,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.content;
|
package org.dspace.content;
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.dspace.AbstractUnitTest;
|
import org.dspace.AbstractUnitTest;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -23,11 +22,6 @@ import org.junit.Test;
|
|||||||
*/
|
*/
|
||||||
public class InProgressSubmissionTest extends AbstractUnitTest {
|
public class InProgressSubmissionTest extends AbstractUnitTest {
|
||||||
|
|
||||||
/**
|
|
||||||
* log4j category
|
|
||||||
*/
|
|
||||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(InProgressSubmissionTest.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be run before every test as per @Before. It will
|
* This method will be run before every test as per @Before. It will
|
||||||
* initialize resources required for the tests.
|
* initialize resources required for the tests.
|
||||||
|
@@ -132,8 +132,8 @@ public class ItemComparatorTest extends AbstractUnitTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCompare() throws SQLException {
|
public void testCompare() throws SQLException {
|
||||||
int result = 0;
|
int result;
|
||||||
ItemComparator ic = null;
|
ItemComparator ic;
|
||||||
|
|
||||||
//one of the tiems has no value
|
//one of the tiems has no value
|
||||||
ic = new ItemComparator("test", "one", Item.ANY, true);
|
ic = new ItemComparator("test", "one", Item.ANY, true);
|
||||||
@@ -246,7 +246,7 @@ public class ItemComparatorTest extends AbstractUnitTest {
|
|||||||
@SuppressWarnings( {"ObjectEqualsNull", "IncompatibleEquals"})
|
@SuppressWarnings( {"ObjectEqualsNull", "IncompatibleEquals"})
|
||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
ItemComparator ic = new ItemComparator("test", "one", Item.ANY, true);
|
ItemComparator ic = new ItemComparator("test", "one", Item.ANY, true);
|
||||||
ItemComparator target = null;
|
ItemComparator target;
|
||||||
|
|
||||||
assertFalse("testEquals 0", ic.equals(null));
|
assertFalse("testEquals 0", ic.equals(null));
|
||||||
assertFalse("testEquals 1", ic.equals("test one"));
|
assertFalse("testEquals 1", ic.equals("test one"));
|
||||||
|
@@ -41,7 +41,6 @@ import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
|||||||
import org.dspace.authorize.service.AuthorizeService;
|
import org.dspace.authorize.service.AuthorizeService;
|
||||||
import org.dspace.content.factory.ContentServiceFactory;
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
import org.dspace.content.service.BitstreamFormatService;
|
import org.dspace.content.service.BitstreamFormatService;
|
||||||
import org.dspace.content.service.CollectionService;
|
|
||||||
import org.dspace.content.service.MetadataFieldService;
|
import org.dspace.content.service.MetadataFieldService;
|
||||||
import org.dspace.content.service.MetadataSchemaService;
|
import org.dspace.content.service.MetadataSchemaService;
|
||||||
import org.dspace.core.Constants;
|
import org.dspace.core.Constants;
|
||||||
@@ -76,8 +75,6 @@ public class ItemTest extends AbstractDSpaceObjectTest {
|
|||||||
.getBitstreamFormatService();
|
.getBitstreamFormatService();
|
||||||
private MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService();
|
private MetadataFieldService metadataFieldService = ContentServiceFactory.getInstance().getMetadataFieldService();
|
||||||
|
|
||||||
private CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
|
||||||
|
|
||||||
private Collection collection;
|
private Collection collection;
|
||||||
private Community owningCommunity;
|
private Community owningCommunity;
|
||||||
|
|
||||||
@@ -839,7 +836,7 @@ public class ItemTest extends AbstractDSpaceObjectTest {
|
|||||||
@Test(expected = AuthorizeException.class)
|
@Test(expected = AuthorizeException.class)
|
||||||
public void testCreateBundleNoAuth() throws Exception {
|
public void testCreateBundleNoAuth() throws Exception {
|
||||||
String name = "bundle";
|
String name = "bundle";
|
||||||
Bundle created = bundleService.create(context, it, name);
|
bundleService.create(context, it, name);
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -941,7 +938,7 @@ public class ItemTest extends AbstractDSpaceObjectTest {
|
|||||||
public void testCreateSingleBitstream_InputStream_StringNoAuth() throws Exception {
|
public void testCreateSingleBitstream_InputStream_StringNoAuth() throws Exception {
|
||||||
String name = "new bundle";
|
String name = "new bundle";
|
||||||
File f = new File(testProps.get("test.bitstream").toString());
|
File f = new File(testProps.get("test.bitstream").toString());
|
||||||
Bitstream result = itemService.createSingleBitstream(context, new FileInputStream(f), it, name);
|
itemService.createSingleBitstream(context, new FileInputStream(f), it, name);
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -972,7 +969,7 @@ public class ItemTest extends AbstractDSpaceObjectTest {
|
|||||||
@Test(expected = AuthorizeException.class)
|
@Test(expected = AuthorizeException.class)
|
||||||
public void testCreateSingleBitstream_InputStreamNoAuth() throws Exception {
|
public void testCreateSingleBitstream_InputStreamNoAuth() throws Exception {
|
||||||
File f = new File(testProps.get("test.bitstream").toString());
|
File f = new File(testProps.get("test.bitstream").toString());
|
||||||
Bitstream result = itemService.createSingleBitstream(context, new FileInputStream(f), it);
|
itemService.createSingleBitstream(context, new FileInputStream(f), it);
|
||||||
fail("Expected exception");
|
fail("Expected exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1624,7 +1621,7 @@ public class ItemTest extends AbstractDSpaceObjectTest {
|
|||||||
assertThat("testGetParentObject 1", itemService.getParentObject(context, it), notNullValue());
|
assertThat("testGetParentObject 1", itemService.getParentObject(context, it), notNullValue());
|
||||||
assertThat("testGetParentObject 2", (Collection) itemService.getParentObject(context, it), equalTo(parent));
|
assertThat("testGetParentObject 2", (Collection) itemService.getParentObject(context, it), equalTo(parent));
|
||||||
} catch (AuthorizeException ex) {
|
} catch (AuthorizeException ex) {
|
||||||
fail("Authorize exception catched");
|
throw new AssertionError("Authorize Exception occurred", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -104,11 +104,11 @@ public class LicenseUtilsTest extends AbstractUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetLicenseText_5args() throws SQLException, AuthorizeException, IOException {
|
public void testGetLicenseText_5args() throws SQLException, AuthorizeException, IOException {
|
||||||
//parameters for the test
|
//parameters for the test
|
||||||
Locale locale = null;
|
Locale locale;
|
||||||
Collection collection = null;
|
Collection collection;
|
||||||
Item item = null;
|
Item item;
|
||||||
EPerson person = null;
|
EPerson person;
|
||||||
Map<String, Object> additionalInfo = null;
|
Map<String, Object> additionalInfo;
|
||||||
|
|
||||||
// We don't test attribute 4 as this is the date, and the date often differs between when the test
|
// We don't test attribute 4 as this is the date, and the date often differs between when the test
|
||||||
// is executed, and when the LicenceUtils code gets the current date/time which causes the test to fail
|
// is executed, and when the LicenceUtils code gets the current date/time which causes the test to fail
|
||||||
@@ -195,10 +195,10 @@ public class LicenseUtilsTest extends AbstractUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetLicenseText_4args() throws SQLException, AuthorizeException, IOException {
|
public void testGetLicenseText_4args() throws SQLException, AuthorizeException, IOException {
|
||||||
//parameters for the test
|
//parameters for the test
|
||||||
Locale locale = null;
|
Locale locale;
|
||||||
Collection collection = null;
|
Collection collection;
|
||||||
Item item = null;
|
Item item;
|
||||||
EPerson person = null;
|
EPerson person;
|
||||||
|
|
||||||
String template = "Template license: %1$s %2$s %3$s %5$s %6$s";
|
String template = "Template license: %1$s %2$s %3$s %5$s %6$s";
|
||||||
String templateResult = "Template license: first name last name testgetlicensetext_4args@email.com ";
|
String templateResult = "Template license: first name last name testgetlicensetext_4args@email.com ";
|
||||||
|
@@ -9,8 +9,6 @@ package org.dspace.content;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,12 +19,6 @@ import org.junit.Test;
|
|||||||
*/
|
*/
|
||||||
public class NonUniqueMetadataExceptionTest {
|
public class NonUniqueMetadataExceptionTest {
|
||||||
|
|
||||||
/**
|
|
||||||
* log4j category
|
|
||||||
*/
|
|
||||||
private static final Logger log = LogManager
|
|
||||||
.getLogger(NonUniqueMetadataExceptionTest.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dummy test to avoid initialization errors
|
* Dummy test to avoid initialization errors
|
||||||
*/
|
*/
|
||||||
|
@@ -463,8 +463,8 @@ public class RelationshipMetadataServiceTest extends AbstractUnitTest {
|
|||||||
WorkspaceItem is = workspaceItemService.create(context, col, false);
|
WorkspaceItem is = workspaceItemService.create(context, col, false);
|
||||||
Item secondItem = installItemService.installItem(context, is);
|
Item secondItem = installItemService.installItem(context, is);
|
||||||
itemService.addMetadata(context, secondItem, "relationship", "type", null, null, "Publication");
|
itemService.addMetadata(context, secondItem, "relationship", "type", null, null, "Publication");
|
||||||
Relationship secondRelationship = relationshipService.create(context, secondItem, rightItem,
|
relationshipService.create(context, secondItem, rightItem,
|
||||||
isAuthorOfPublicationRelationshipType, 0, 0);
|
isAuthorOfPublicationRelationshipType, 0, 0);
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
assertThat(relationshipService.findNextRightPlaceByRightItem(context, rightItem), equalTo(2));
|
assertThat(relationshipService.findNextRightPlaceByRightItem(context, rightItem), equalTo(2));
|
||||||
@@ -489,8 +489,8 @@ public class RelationshipMetadataServiceTest extends AbstractUnitTest {
|
|||||||
itemService.addMetadata(context, secondAuthor, "relationship", "type", null, null, "Author");
|
itemService.addMetadata(context, secondAuthor, "relationship", "type", null, null, "Author");
|
||||||
itemService.addMetadata(context, secondAuthor, "person", "familyName", null, null, "familyName");
|
itemService.addMetadata(context, secondAuthor, "person", "familyName", null, null, "familyName");
|
||||||
itemService.addMetadata(context, secondAuthor, "person", "givenName", null, null, "firstName");
|
itemService.addMetadata(context, secondAuthor, "person", "givenName", null, null, "firstName");
|
||||||
Relationship secondRelationship = relationshipService.create(context, leftItem, secondAuthor,
|
relationshipService.create(context, leftItem, secondAuthor,
|
||||||
isAuthorOfPublicationRelationshipType, 0, 0);
|
isAuthorOfPublicationRelationshipType, 0, 0);
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
assertThat(relationshipService.findNextLeftPlaceByLeftItem(context, leftItem), equalTo(2));
|
assertThat(relationshipService.findNextLeftPlaceByLeftItem(context, leftItem), equalTo(2));
|
||||||
|
@@ -8,12 +8,11 @@
|
|||||||
package org.dspace.content;
|
package org.dspace.content;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.dspace.authorize.service.AuthorizeService;
|
import org.dspace.authorize.service.AuthorizeService;
|
||||||
@@ -137,7 +136,7 @@ public class RelationshipServiceImplTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testFindByItemAndRelationshipType() throws Exception {
|
public void testFindByItemAndRelationshipType() throws Exception {
|
||||||
// Declare objects utilized in unit test
|
// Declare objects utilized in unit test
|
||||||
List<Relationship> relList = new LinkedList<>();
|
List<Relationship> relList = new ArrayList<>();
|
||||||
Item item = mock(Item.class);
|
Item item = mock(Item.class);
|
||||||
RelationshipType testRel = new RelationshipType();
|
RelationshipType testRel = new RelationshipType();
|
||||||
|
|
||||||
@@ -152,7 +151,7 @@ public class RelationshipServiceImplTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testFindByRelationshipType() throws Exception {
|
public void testFindByRelationshipType() throws Exception {
|
||||||
// Declare objects utilized in unit test
|
// Declare objects utilized in unit test
|
||||||
List<Relationship> relList = new LinkedList<>();
|
List<Relationship> relList = new ArrayList<>();
|
||||||
RelationshipType testRel = new RelationshipType();
|
RelationshipType testRel = new RelationshipType();
|
||||||
|
|
||||||
// The Relationship(s) reported should match our our relList
|
// The Relationship(s) reported should match our our relList
|
||||||
@@ -231,8 +230,6 @@ public class RelationshipServiceImplTest {
|
|||||||
public void testDelete() throws Exception {
|
public void testDelete() throws Exception {
|
||||||
|
|
||||||
// Declare objects utilized in unit test
|
// Declare objects utilized in unit test
|
||||||
MetadataValue metVal = mock(MetadataValue.class);
|
|
||||||
List<MetadataValue> metsList = new ArrayList<>();
|
|
||||||
List<Relationship> leftTypelist = new ArrayList<>();
|
List<Relationship> leftTypelist = new ArrayList<>();
|
||||||
List<Relationship> rightTypelist = new ArrayList<>();
|
List<Relationship> rightTypelist = new ArrayList<>();
|
||||||
Item leftItem = mock(Item.class);
|
Item leftItem = mock(Item.class);
|
||||||
@@ -246,7 +243,6 @@ public class RelationshipServiceImplTest {
|
|||||||
testRel.setRightwardType("Entitylabel");
|
testRel.setRightwardType("Entitylabel");
|
||||||
testRel.setLeftMinCardinality(0);
|
testRel.setLeftMinCardinality(0);
|
||||||
testRel.setRightMinCardinality(0);
|
testRel.setRightMinCardinality(0);
|
||||||
metsList.add(metVal);
|
|
||||||
relationship = getRelationship(leftItem, rightItem, testRel, 0,0);
|
relationship = getRelationship(leftItem, rightItem, testRel, 0,0);
|
||||||
leftTypelist.add(relationship);
|
leftTypelist.add(relationship);
|
||||||
rightTypelist.add(relationship);
|
rightTypelist.add(relationship);
|
||||||
|
@@ -10,15 +10,14 @@ package org.dspace.content;
|
|||||||
import static org.hamcrest.core.IsEqual.equalTo;
|
import static org.hamcrest.core.IsEqual.equalTo;
|
||||||
import static org.hamcrest.core.IsNull.notNullValue;
|
import static org.hamcrest.core.IsNull.notNullValue;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.dspace.content.dao.RelationshipTypeDAO;
|
import org.dspace.content.dao.RelationshipTypeDAO;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -30,9 +29,6 @@ import org.mockito.junit.MockitoJUnitRunner;
|
|||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class RelationshipTypeTest {
|
public class RelationshipTypeTest {
|
||||||
|
|
||||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(RelationshipTypeTest.class);
|
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private RelationshipTypeServiceImpl relationshipTypeService;
|
private RelationshipTypeServiceImpl relationshipTypeService;
|
||||||
|
|
||||||
@@ -102,7 +98,7 @@ public class RelationshipTypeTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testRelationshipTypeFindAll() throws Exception {
|
public void testRelationshipTypeFindAll() throws Exception {
|
||||||
// Declare objects utilized for this test
|
// Declare objects utilized for this test
|
||||||
List<RelationshipType> mockedList = new LinkedList<>();
|
List<RelationshipType> mockedList = new ArrayList<>();
|
||||||
mockedList.add(firstRelationshipType);
|
mockedList.add(firstRelationshipType);
|
||||||
mockedList.add(secondRelationshipType);
|
mockedList.add(secondRelationshipType);
|
||||||
|
|
||||||
@@ -120,7 +116,7 @@ public class RelationshipTypeTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testRelationshipTypeFindByLeftOrRightwardType() throws Exception {
|
public void testRelationshipTypeFindByLeftOrRightwardType() throws Exception {
|
||||||
// Declare objects utilized for this test
|
// Declare objects utilized for this test
|
||||||
List<RelationshipType> mockedList = new LinkedList<>();
|
List<RelationshipType> mockedList = new ArrayList<>();
|
||||||
mockedList.add(firstRelationshipType);
|
mockedList.add(firstRelationshipType);
|
||||||
|
|
||||||
// Mock DAO to return our mockedList
|
// Mock DAO to return our mockedList
|
||||||
@@ -138,7 +134,7 @@ public class RelationshipTypeTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testRelationshipTypefindByEntityType() throws Exception {
|
public void testRelationshipTypefindByEntityType() throws Exception {
|
||||||
// Declare objects utilized for this test
|
// Declare objects utilized for this test
|
||||||
List<RelationshipType> mockedList = new LinkedList<>();
|
List<RelationshipType> mockedList = new ArrayList<>();
|
||||||
mockedList.add(firstRelationshipType);
|
mockedList.add(firstRelationshipType);
|
||||||
|
|
||||||
// Mock DAO to return our mockedList
|
// Mock DAO to return our mockedList
|
||||||
|
@@ -58,7 +58,7 @@ public class SiteTest extends AbstractUnitTest {
|
|||||||
try {
|
try {
|
||||||
//we have to create a new community in the database
|
//we have to create a new community in the database
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
this.s = (Site) siteService.findSite(context);
|
this.s = siteService.findSite(context);
|
||||||
//we need to commit the changes so we don't block the table for testing
|
//we need to commit the changes so we don't block the table for testing
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
@@ -120,8 +120,7 @@ public class SiteTest extends AbstractUnitTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSiteFind() throws Exception {
|
public void testSiteFind() throws Exception {
|
||||||
int id = 0;
|
Site found = siteService.findSite(context);
|
||||||
Site found = (Site) siteService.findSite(context);
|
|
||||||
assertThat("testSiteFind 0", found, notNullValue());
|
assertThat("testSiteFind 0", found, notNullValue());
|
||||||
assertThat("testSiteFind 1", found, equalTo(s));
|
assertThat("testSiteFind 1", found, equalTo(s));
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.content;
|
package org.dspace.content;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@@ -48,11 +49,6 @@ public class ThumbnailTest extends AbstractUnitTest {
|
|||||||
*/
|
*/
|
||||||
private Bitstream orig;
|
private Bitstream orig;
|
||||||
|
|
||||||
/**
|
|
||||||
* Thumbnail instance for the tests, original copy
|
|
||||||
*/
|
|
||||||
private Thumbnail t;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be run before every test as per @Before. It will
|
* This method will be run before every test as per @Before. It will
|
||||||
* initialize resources required for the tests.
|
* initialize resources required for the tests.
|
||||||
@@ -69,7 +65,9 @@ public class ThumbnailTest extends AbstractUnitTest {
|
|||||||
File f = new File(testProps.get("test.bitstream").toString());
|
File f = new File(testProps.get("test.bitstream").toString());
|
||||||
thumb = bitstreamService.create(context, new FileInputStream(f));
|
thumb = bitstreamService.create(context, new FileInputStream(f));
|
||||||
orig = bitstreamService.create(context, new FileInputStream(f));
|
orig = bitstreamService.create(context, new FileInputStream(f));
|
||||||
t = new Thumbnail(thumb, orig);
|
Thumbnail t = new Thumbnail(thumb, orig);
|
||||||
|
assertEquals(orig, t.getOriginal());
|
||||||
|
assertEquals(thumb, t.getThumb());
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
log.error("IO Error in init", ex);
|
log.error("IO Error in init", ex);
|
||||||
fail("SQL Error in init: " + ex.getMessage());
|
fail("SQL Error in init: " + ex.getMessage());
|
||||||
@@ -89,9 +87,16 @@ public class ThumbnailTest extends AbstractUnitTest {
|
|||||||
@After
|
@After
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
thumb = null;
|
try {
|
||||||
orig = null;
|
context.turnOffAuthorisationSystem();
|
||||||
t = null;
|
bitstreamService.delete(context, thumb);
|
||||||
|
bitstreamService.delete(context, orig);
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
thumb = null;
|
||||||
|
orig = null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new AssertionError("Error in destroy()", e);
|
||||||
|
}
|
||||||
super.destroy();
|
super.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,7 +25,6 @@ import org.dspace.content.service.CommunityService;
|
|||||||
import org.dspace.content.service.InstallItemService;
|
import org.dspace.content.service.InstallItemService;
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
import org.dspace.content.service.WorkspaceItemService;
|
import org.dspace.content.service.WorkspaceItemService;
|
||||||
import org.dspace.core.ConfigurationManager;
|
|
||||||
import org.dspace.handle.factory.HandleServiceFactory;
|
import org.dspace.handle.factory.HandleServiceFactory;
|
||||||
import org.dspace.handle.service.HandleService;
|
import org.dspace.handle.service.HandleService;
|
||||||
import org.dspace.versioning.Version;
|
import org.dspace.versioning.Version;
|
||||||
@@ -49,7 +48,6 @@ public class VersioningTest extends AbstractUnitTest {
|
|||||||
|
|
||||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(VersioningTest.class);
|
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(VersioningTest.class);
|
||||||
|
|
||||||
private String originalHandle;
|
|
||||||
private Item originalItem;
|
private Item originalItem;
|
||||||
private Item versionedItem;
|
private Item versionedItem;
|
||||||
private String summary = "Unit test version";
|
private String summary = "Unit test version";
|
||||||
@@ -65,7 +63,7 @@ public class VersioningTest extends AbstractUnitTest {
|
|||||||
|
|
||||||
//A regex that can be used to see if a handle contains the format of handle created by the org.dspace.identifier
|
//A regex that can be used to see if a handle contains the format of handle created by the org.dspace.identifier
|
||||||
// .VersionedHandleIdentifierProvider*
|
// .VersionedHandleIdentifierProvider*
|
||||||
protected String versionedHandleRegex = ConfigurationManager.getProperty("handle.prefix") + "\\/[0-9]*\\.[0-9]";
|
//protected String versionedHandleRegex = ConfigurationManager.getProperty("handle.prefix") + "\\/[0-9]*\\.[0-9]";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be run before every test as per @Before. It will
|
* This method will be run before every test as per @Before. It will
|
||||||
@@ -86,7 +84,6 @@ public class VersioningTest extends AbstractUnitTest {
|
|||||||
WorkspaceItem is = workspaceItemService.create(context, col, false);
|
WorkspaceItem is = workspaceItemService.create(context, col, false);
|
||||||
|
|
||||||
originalItem = installItemService.installItem(context, is);
|
originalItem = installItemService.installItem(context, is);
|
||||||
originalHandle = originalItem.getHandle();
|
|
||||||
|
|
||||||
Version version = versionService.createNewVersion(context, originalItem, summary);
|
Version version = versionService.createNewVersion(context, originalItem, summary);
|
||||||
WorkspaceItem wsi = workspaceItemService.findByItem(context, version.getItem());
|
WorkspaceItem wsi = workspaceItemService.findByItem(context, version.getItem());
|
||||||
|
@@ -160,8 +160,8 @@ public class WorkspaceItemTest extends AbstractUnitTest {
|
|||||||
// Allow Collection ADD perms
|
// Allow Collection ADD perms
|
||||||
doNothing().when(authorizeServiceSpy).authorizeAction(context, collection, Constants.ADD);
|
doNothing().when(authorizeServiceSpy).authorizeAction(context, collection, Constants.ADD);
|
||||||
|
|
||||||
boolean template = false;
|
boolean template;
|
||||||
WorkspaceItem created = null;
|
WorkspaceItem created;
|
||||||
|
|
||||||
template = false;
|
template = false;
|
||||||
created = workspaceItemService.create(context, collection, template);
|
created = workspaceItemService.create(context, collection, template);
|
||||||
|
@@ -22,6 +22,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.AbstractIntegrationTest;
|
import org.dspace.AbstractIntegrationTest;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
@@ -1194,9 +1195,9 @@ public class ITDSpaceAIP extends AbstractIntegrationTest {
|
|||||||
|
|
||||||
// Get the typeText & name of this object from the values
|
// Get the typeText & name of this object from the values
|
||||||
String info = infoMap.get(key);
|
String info = infoMap.get(key);
|
||||||
String[] values = info.split(valueseparator);
|
List<String> values = Splitter.on(valueseparator).splitToList(info);
|
||||||
String typeText = values[0];
|
String typeText = values.get(0);
|
||||||
String name = values[1];
|
String name = values.get(1);
|
||||||
|
|
||||||
// Also assert type and name are correct
|
// Also assert type and name are correct
|
||||||
assertEquals("assertObjectsExist object " + key + " type",
|
assertEquals("assertObjectsExist object " + key + " type",
|
||||||
|
@@ -14,6 +14,7 @@ import static org.mockito.Mockito.when;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
import org.dspace.content.MetadataValue;
|
import org.dspace.content.MetadataValue;
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
@@ -85,18 +86,15 @@ public class CollectedTest {
|
|||||||
metadataValueList.add(metadataValue);
|
metadataValueList.add(metadataValue);
|
||||||
String s = "dc.title";
|
String s = "dc.title";
|
||||||
list.add(s);
|
list.add(s);
|
||||||
String[] splittedString = s.split("\\.");
|
List<String> splittedString = Splitter.on('.').splitToList(s);
|
||||||
collected.setFields(list);
|
collected.setFields(list);
|
||||||
valueList.add("TestValue");
|
valueList.add("TestValue");
|
||||||
|
|
||||||
// Mock the state of objects utilized in getValues() to meet the success criteria of an invocation
|
// Mock the state of objects utilized in getValues() to meet the success criteria of an invocation
|
||||||
when(itemService.getMetadata(item, splittedString.length > 0 ? splittedString[0] :
|
when(itemService.getMetadata(item, splittedString.size() > 0 ? splittedString.get(0) : null,
|
||||||
null,
|
splittedString.size() > 1 ? splittedString.get(1) : null,
|
||||||
splittedString.length > 1 ? splittedString[1] :
|
splittedString.size() > 2 ? splittedString.get(2) : null,
|
||||||
null,
|
Item.ANY, false)).thenReturn(metadataValueList);
|
||||||
splittedString.length > 2 ? splittedString[2] :
|
|
||||||
null,
|
|
||||||
Item.ANY, false)).thenReturn(metadataValueList);
|
|
||||||
when(metadataValue.getValue()).thenReturn("TestValue");
|
when(metadataValue.getValue()).thenReturn("TestValue");
|
||||||
|
|
||||||
// The reported value(s) should match our valueList
|
// The reported value(s) should match our valueList
|
||||||
|
@@ -14,6 +14,7 @@ import static org.mockito.Mockito.when;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
import org.dspace.content.MetadataValue;
|
import org.dspace.content.MetadataValue;
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
@@ -107,18 +108,15 @@ public class ConcatenateTest {
|
|||||||
metadataValueList.add(metadataValue);
|
metadataValueList.add(metadataValue);
|
||||||
String s = "dc.title";
|
String s = "dc.title";
|
||||||
list.add(s);
|
list.add(s);
|
||||||
String[] splittedString = s.split("\\.");
|
List<String> splittedString = Splitter.on(".").splitToList(s);
|
||||||
concatenate.setFields(list);
|
concatenate.setFields(list);
|
||||||
valueList.add("TestValue");
|
valueList.add("TestValue");
|
||||||
|
|
||||||
// Mock the state of objects utilized in getValues() to meet the success criteria of an invocation
|
// Mock the state of objects utilized in getValues() to meet the success criteria of an invocation
|
||||||
when(itemService.getMetadata(item, splittedString.length > 0 ? splittedString[0] :
|
when(itemService.getMetadata(item, splittedString.size() > 0 ? splittedString.get(0) : null,
|
||||||
null,
|
splittedString.size() > 1 ? splittedString.get(1) : null,
|
||||||
splittedString.length > 1 ? splittedString[1] :
|
splittedString.size() > 2 ? splittedString.get(2) : null,
|
||||||
null,
|
Item.ANY, false)).thenReturn(metadataValueList);
|
||||||
splittedString.length > 2 ? splittedString[2] :
|
|
||||||
null,
|
|
||||||
Item.ANY, false)).thenReturn(metadataValueList);
|
|
||||||
when(metadataValue.getValue()).thenReturn("TestValue");
|
when(metadataValue.getValue()).thenReturn("TestValue");
|
||||||
|
|
||||||
|
|
||||||
|
@@ -13,7 +13,6 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -150,8 +149,8 @@ public class RelatedTest {
|
|||||||
assertEquals("TestGetValues 1", virtualMetadataConfiguration.getValues(context, item),
|
assertEquals("TestGetValues 1", virtualMetadataConfiguration.getValues(context, item),
|
||||||
related.getValues(context, item));
|
related.getValues(context, item));
|
||||||
related.setPlace(2);
|
related.setPlace(2);
|
||||||
// No match should return empty LinkedList
|
// No match should return empty List
|
||||||
assertEquals("TestGetValues 2", new LinkedList<>(), related.getValues(context, item));
|
assertEquals("TestGetValues 2", new ArrayList<>(), related.getValues(context, item));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -11,7 +11,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
|||||||
public class UUIDValueTest {
|
public class UUIDValueTest {
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private UUIDValue UUIDValue;
|
private UUIDValue uuidValue;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Context context;
|
private Context context;
|
||||||
@@ -36,32 +36,32 @@ public class UUIDValueTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetValues() throws Exception {
|
public void testGetValues() throws Exception {
|
||||||
// Setup objects utilized in unit test
|
// Setup objects utilized in unit test
|
||||||
List<String> list = new LinkedList<>();
|
List<String> list = new ArrayList<>();
|
||||||
Item item = mock(Item.class);
|
Item item = mock(Item.class);
|
||||||
UUID uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
when(item.getID()).thenReturn(uuid);
|
when(item.getID()).thenReturn(uuid);
|
||||||
list.add(String.valueOf(uuid));
|
list.add(String.valueOf(uuid));
|
||||||
|
|
||||||
// The reported value(s) should match our defined list
|
// The reported value(s) should match our defined list
|
||||||
assertEquals("TestGetValues 0", list, UUIDValue.getValues(context, item));
|
assertEquals("TestGetValues 0", list, uuidValue.getValues(context, item));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetUseForPlace() {
|
public void testSetUseForPlace() {
|
||||||
// Setup objects utilized in unit test
|
// Setup objects utilized in unit test
|
||||||
UUIDValue.setUseForPlace(true);
|
uuidValue.setUseForPlace(true);
|
||||||
|
|
||||||
// The reported boolean should return true
|
// The reported boolean should return true
|
||||||
assertEquals("TestSetUseForPlace 0", true, UUIDValue.getUseForPlace());
|
assertEquals("TestSetUseForPlace 0", true, uuidValue.getUseForPlace());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetUseForPlace() {
|
public void testGetUseForPlace() {
|
||||||
// Setup objects utilized in unit test
|
// Setup objects utilized in unit test
|
||||||
UUIDValue.setUseForPlace(true);
|
uuidValue.setUseForPlace(true);
|
||||||
|
|
||||||
// The reported boolean should return true
|
// The reported boolean should return true
|
||||||
assertEquals("TestGetUseForPlace 0", true, UUIDValue.getUseForPlace());
|
assertEquals("TestGetUseForPlace 0", true, uuidValue.getUseForPlace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,12 +10,15 @@ package org.dspace.core;
|
|||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||||
import static org.hamcrest.CoreMatchers.nullValue;
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -84,7 +87,7 @@ public class ContextTest extends AbstractUnitTest {
|
|||||||
* Test of setCurrentUser method, of class Context.
|
* Test of setCurrentUser method, of class Context.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetCurrentUser() throws SQLException, AuthorizeException {
|
public void testSetCurrentUser() throws SQLException, AuthorizeException, IOException {
|
||||||
// Allow full Admin perms
|
// Allow full Admin perms
|
||||||
when(authorizeServiceSpy.isAdmin(context)).thenReturn(true);
|
when(authorizeServiceSpy.isAdmin(context)).thenReturn(true);
|
||||||
|
|
||||||
@@ -105,6 +108,9 @@ public class ContextTest extends AbstractUnitTest {
|
|||||||
|
|
||||||
// Restore the previous current user
|
// Restore the previous current user
|
||||||
context.setCurrentUser(oldUser);
|
context.setCurrentUser(oldUser);
|
||||||
|
|
||||||
|
// Cleanup our new user
|
||||||
|
ePersonService.delete(context, newUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -255,6 +261,60 @@ public class ContextTest extends AbstractUnitTest {
|
|||||||
cleanupContext(instance);
|
cleanupContext(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of commit method, of class Context.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCommit() throws SQLException, AuthorizeException, IOException {
|
||||||
|
// To test commit() we need a new Context object
|
||||||
|
Context instance = new Context();
|
||||||
|
|
||||||
|
// By default, we should have a new DB connection, so let's make sure it is there
|
||||||
|
assertThat("HibernateDBConnection should exist", instance.getDBConnection(), notNullValue());
|
||||||
|
assertTrue("Context should be valid", instance.isValid());
|
||||||
|
assertTrue("Transaction should be open", instance.isTransactionAlive());
|
||||||
|
|
||||||
|
// Allow full Admin perms (in new context)
|
||||||
|
when(authorizeServiceSpy.isAdmin(instance)).thenReturn(true);
|
||||||
|
|
||||||
|
// Create a new EPerson (to be committed)
|
||||||
|
String createdEmail = "myfakeemail@example.com";
|
||||||
|
EPerson newUser = ePersonService.create(instance);
|
||||||
|
newUser.setFirstName(instance, "Tim");
|
||||||
|
newUser.setLastName(instance, "Smith");
|
||||||
|
newUser.setEmail(createdEmail);
|
||||||
|
newUser.setCanLogIn(true);
|
||||||
|
newUser.setLanguage(instance, I18nUtil.getDefaultLocale().getLanguage());
|
||||||
|
|
||||||
|
// Now, call commit()
|
||||||
|
instance.commit();
|
||||||
|
|
||||||
|
// We expect our DB connection to still exist
|
||||||
|
assertThat("HibernateDBConnection should still be open", instance.getDBConnection(), notNullValue());
|
||||||
|
// We expect the Context to be valid
|
||||||
|
assertTrue("Context should still be valid", instance.isValid());
|
||||||
|
// However, the transaction should now be closed
|
||||||
|
assertFalse("DB transaction should be closed", instance.isTransactionAlive());
|
||||||
|
|
||||||
|
// ReloadEntity and verify changes saved
|
||||||
|
// NOTE: reloadEntity() is required, see commit() method Javadocs
|
||||||
|
newUser = instance.reloadEntity(newUser);
|
||||||
|
assertEquals("New user should be created", newUser.getEmail(), createdEmail);
|
||||||
|
|
||||||
|
// Change the email and commit again (a Context should support multiple commit() calls)
|
||||||
|
String newEmail = "myrealemail@example.com";
|
||||||
|
newUser.setEmail(newEmail);
|
||||||
|
instance.commit();
|
||||||
|
|
||||||
|
// Reload entity and new value should be there.
|
||||||
|
newUser = instance.reloadEntity(newUser);
|
||||||
|
assertEquals("New email address should be saved", newUser.getEmail(), newEmail);
|
||||||
|
|
||||||
|
// Cleanup our new object & context
|
||||||
|
ePersonService.delete(instance, newUser);
|
||||||
|
cleanupContext(instance);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of abort method, of class Context.
|
* Test of abort method, of class Context.
|
||||||
*/
|
*/
|
||||||
@@ -269,11 +329,11 @@ public class ContextTest extends AbstractUnitTest {
|
|||||||
// Create a new EPerson (DO NOT COMMIT IT)
|
// Create a new EPerson (DO NOT COMMIT IT)
|
||||||
String createdEmail = "susie@email.com";
|
String createdEmail = "susie@email.com";
|
||||||
EPerson newUser = ePersonService.create(instance);
|
EPerson newUser = ePersonService.create(instance);
|
||||||
newUser.setFirstName(context, "Susan");
|
newUser.setFirstName(instance, "Susan");
|
||||||
newUser.setLastName(context, "Doe");
|
newUser.setLastName(instance, "Doe");
|
||||||
newUser.setEmail(createdEmail);
|
newUser.setEmail(createdEmail);
|
||||||
newUser.setCanLogIn(true);
|
newUser.setCanLogIn(true);
|
||||||
newUser.setLanguage(context, I18nUtil.getDefaultLocale().getLanguage());
|
newUser.setLanguage(instance, I18nUtil.getDefaultLocale().getLanguage());
|
||||||
|
|
||||||
// Abort our context
|
// Abort our context
|
||||||
instance.abort();
|
instance.abort();
|
||||||
@@ -304,12 +364,11 @@ public class ContextTest extends AbstractUnitTest {
|
|||||||
|
|
||||||
// Create a new EPerson (DO NOT COMMIT IT)
|
// Create a new EPerson (DO NOT COMMIT IT)
|
||||||
EPerson newUser = ePersonService.create(instance);
|
EPerson newUser = ePersonService.create(instance);
|
||||||
newUser.setFirstName(context, "Susan");
|
newUser.setFirstName(instance, "Susan");
|
||||||
newUser.setLastName(context, "Doe");
|
newUser.setLastName(instance, "Doe");
|
||||||
newUser.setEmail(createdEmail);
|
newUser.setEmail(createdEmail);
|
||||||
newUser.setCanLogIn(true);
|
newUser.setCanLogIn(true);
|
||||||
newUser.setLanguage(context, I18nUtil.getDefaultLocale().getLanguage());
|
newUser.setLanguage(instance, I18nUtil.getDefaultLocale().getLanguage());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open a new context, let's make sure that EPerson isn't there
|
// Open a new context, let's make sure that EPerson isn't there
|
||||||
@@ -433,7 +492,7 @@ public class ContextTest extends AbstractUnitTest {
|
|||||||
* Test of getSpecialGroups method, of class Context.
|
* Test of getSpecialGroups method, of class Context.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetSpecialGroups() throws SQLException, AuthorizeException {
|
public void testGetSpecialGroups() throws SQLException, AuthorizeException, IOException {
|
||||||
// To test special groups we need a new Context object
|
// To test special groups we need a new Context object
|
||||||
Context instance = new Context();
|
Context instance = new Context();
|
||||||
|
|
||||||
@@ -456,7 +515,8 @@ public class ContextTest extends AbstractUnitTest {
|
|||||||
assertThat("testGetSpecialGroup 1", specialGroups.get(0), equalTo(group));
|
assertThat("testGetSpecialGroup 1", specialGroups.get(0), equalTo(group));
|
||||||
assertThat("testGetSpecialGroup 1", specialGroups.get(1), equalTo(adminGroup));
|
assertThat("testGetSpecialGroup 1", specialGroups.get(1), equalTo(adminGroup));
|
||||||
|
|
||||||
// Cleanup our context
|
// Cleanup our context & group
|
||||||
|
groupService.delete(instance, group);
|
||||||
cleanupContext(instance);
|
cleanupContext(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,229 @@
|
|||||||
|
/**
|
||||||
|
* 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.core;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.dspace.AbstractUnitTest;
|
||||||
|
import org.dspace.eperson.EPerson;
|
||||||
|
import org.dspace.utils.DSpace;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform some basic unit tests for HibernateDBConnection
|
||||||
|
*
|
||||||
|
* @author tdonohue
|
||||||
|
*/
|
||||||
|
public class HibernateDBConnectionTest extends AbstractUnitTest {
|
||||||
|
|
||||||
|
private HibernateDBConnection connection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will be run before every test as per @Before. It will
|
||||||
|
* initialize resources required for the tests.
|
||||||
|
*
|
||||||
|
* Other methods can be annotated with @Before here or in subclasses
|
||||||
|
* but no execution order is guaranteed
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
super.init();
|
||||||
|
// Get a DB connection to test with
|
||||||
|
connection = new DSpace().getServiceManager()
|
||||||
|
.getServiceByName(null, HibernateDBConnection.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of getSession method
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetSession() throws SQLException {
|
||||||
|
assertNotNull("DB connection should not be null", connection);
|
||||||
|
// Connection should begin with an active transaction
|
||||||
|
assertTrue("A transaction should be open by default", connection.getTransaction().isActive());
|
||||||
|
|
||||||
|
// Rollback current transaction
|
||||||
|
connection.getTransaction().rollback();
|
||||||
|
|
||||||
|
// Transaction should be closed
|
||||||
|
assertFalse("Transaction should be closed after rollback", connection.getTransaction().isActive());
|
||||||
|
|
||||||
|
//Now call getSession(), saving a reference to the session
|
||||||
|
Session currentSession = connection.getSession();
|
||||||
|
|
||||||
|
// New transaction should be initialized
|
||||||
|
assertTrue("New transaction should be open after getSession() call",
|
||||||
|
connection.getTransaction().isActive());
|
||||||
|
|
||||||
|
// Call getSession again. The same Session should still be returned
|
||||||
|
assertEquals("Multiple calls to getSession should return same Session", currentSession,
|
||||||
|
connection.getSession());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of isTransactionAlive method
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testIsTransactionAlive() {
|
||||||
|
assertNotNull("DB connection should not be null", connection);
|
||||||
|
assertNotNull("Transaction should not be null", connection.getTransaction());
|
||||||
|
// Connection should begin with a transaction
|
||||||
|
assertTrue("A transaction should be open by default", connection.isTransActionAlive());
|
||||||
|
|
||||||
|
// Rollback current transaction
|
||||||
|
connection.getTransaction().rollback();
|
||||||
|
|
||||||
|
// Transaction should be closed
|
||||||
|
assertFalse("Transaction should be closed after rollback", connection.isTransActionAlive());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of isSessionAlive method
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testIsSessionAlive() throws SQLException {
|
||||||
|
assertNotNull("DB connection should not be null", connection);
|
||||||
|
assertNotNull("Session should not be null", connection.getSession());
|
||||||
|
assertTrue("A Session should be alive by default", connection.isSessionAlive());
|
||||||
|
|
||||||
|
// Rollback current transaction, closing it
|
||||||
|
connection.getTransaction().rollback();
|
||||||
|
|
||||||
|
// Session should still be alive even after transaction closes
|
||||||
|
assertTrue("A Session should still be alive if transaction closes", connection.isSessionAlive());
|
||||||
|
|
||||||
|
// NOTE: Because we configure Hibernate Session objects to be bound to a thread
|
||||||
|
// (see 'hibernate.current_session_context_class' in hibernate.cfg.xml), a Session is ALWAYS ALIVE until
|
||||||
|
// the thread closes (at which point Hibernate will clean it up automatically).
|
||||||
|
// This means that essentially isSessionAlive() will always return true, unless the connection is severed
|
||||||
|
// in some unexpected way. See also "testCloseDBConnection()"
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of closeDBConnection method
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCloseDBConnection() throws SQLException {
|
||||||
|
// Get a reference to the current Session
|
||||||
|
Session initialSession = connection.getSession();
|
||||||
|
|
||||||
|
// Close the DB connection / Session
|
||||||
|
// NOTE: Because of our Hibernate configuration, Hibernate automatically creates a new Session per thread.
|
||||||
|
// Even though we "close" the connection, Hibernate will reopen a new one immediately. So, all this actually
|
||||||
|
// does is create a *new* Session
|
||||||
|
connection.closeDBConnection();
|
||||||
|
|
||||||
|
Session newSession = connection.getSession();
|
||||||
|
assertNotEquals("New Session expected",initialSession, newSession);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of commit method
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCommit() throws SQLException {
|
||||||
|
// Ensure a transaction exists
|
||||||
|
connection.getSession();
|
||||||
|
assertTrue("Transaction should be active", connection.getTransaction().isActive());
|
||||||
|
|
||||||
|
connection.commit();
|
||||||
|
assertFalse("Commit should close transaction", connection.getTransaction().isActive());
|
||||||
|
|
||||||
|
// A second commit should be a no-op (no error thrown)
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of rollback method
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testRollback() throws SQLException {
|
||||||
|
// Ensure a transaction exists
|
||||||
|
connection.getSession();
|
||||||
|
assertTrue("Transaction should be active", connection.getTransaction().isActive());
|
||||||
|
|
||||||
|
connection.rollback();
|
||||||
|
assertFalse("Rollback should close transaction", connection.getTransaction().isActive());
|
||||||
|
|
||||||
|
// A second rollback should be a no-op (no error thrown)
|
||||||
|
connection.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of reloadEntity method
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testReloadEntityAfterRollback() throws SQLException {
|
||||||
|
// Get DBConnection associated with DSpace Context
|
||||||
|
HibernateDBConnection dbConnection = (HibernateDBConnection) context.getDBConnection();
|
||||||
|
EPerson person = context.getCurrentUser();
|
||||||
|
|
||||||
|
assertTrue("Current user should be cached in session", dbConnection.getSession()
|
||||||
|
.contains(person));
|
||||||
|
|
||||||
|
dbConnection.rollback();
|
||||||
|
assertFalse("Current user should be gone from cache", dbConnection.getSession()
|
||||||
|
.contains(person));
|
||||||
|
|
||||||
|
person = dbConnection.reloadEntity(person);
|
||||||
|
assertTrue("Current user should be cached back in session", dbConnection.getSession()
|
||||||
|
.contains(person));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of reloadEntity method
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testReloadEntityAfterCommit() throws SQLException {
|
||||||
|
// Get DBConnection associated with DSpace Context
|
||||||
|
HibernateDBConnection dbConnection = (HibernateDBConnection) context.getDBConnection();
|
||||||
|
EPerson person = context.getCurrentUser();
|
||||||
|
|
||||||
|
assertTrue("Current user should be cached in session", dbConnection.getSession()
|
||||||
|
.contains(person));
|
||||||
|
|
||||||
|
dbConnection.commit();
|
||||||
|
assertFalse("Current user should be gone from cache", dbConnection.getSession()
|
||||||
|
.contains(person));
|
||||||
|
|
||||||
|
person = dbConnection.reloadEntity(person);
|
||||||
|
assertTrue("Current user should be cached back in session", dbConnection.getSession()
|
||||||
|
.contains(person));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of uncacheEntity method
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testUncacheEntity() throws SQLException {
|
||||||
|
// Get DBConnection associated with DSpace Context
|
||||||
|
HibernateDBConnection dbConnection = (HibernateDBConnection) context.getDBConnection();
|
||||||
|
EPerson person = context.getCurrentUser();
|
||||||
|
|
||||||
|
assertTrue("Current user should be cached in session", dbConnection.getSession()
|
||||||
|
.contains(person));
|
||||||
|
|
||||||
|
dbConnection.uncacheEntity(person);
|
||||||
|
assertFalse("Current user should be gone from cache", dbConnection.getSession()
|
||||||
|
.contains(person));
|
||||||
|
|
||||||
|
// Test ability to reload an uncached entity
|
||||||
|
person = dbConnection.reloadEntity(person);
|
||||||
|
assertTrue("Current user should be cached back in session", dbConnection.getSession()
|
||||||
|
.contains(person));
|
||||||
|
}
|
||||||
|
}
|
@@ -8,7 +8,7 @@
|
|||||||
package org.dspace.core;
|
package org.dspace.core;
|
||||||
|
|
||||||
import static org.apache.bcel.Const.ACC_PUBLIC;
|
import static org.apache.bcel.Const.ACC_PUBLIC;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -136,12 +136,12 @@ public class PathsClassLoaderTest {
|
|||||||
jarFile.getCanonicalPath()};
|
jarFile.getCanonicalPath()};
|
||||||
PathsClassLoader instance = new PathsClassLoader(parentCL, classpath);
|
PathsClassLoader instance = new PathsClassLoader(parentCL, classpath);
|
||||||
Class result = instance.findClass(className);
|
Class result = instance.findClass(className);
|
||||||
assertTrue("Should return a Class from file", result instanceof Class);
|
assertNotNull("Should return a Class from file", result);
|
||||||
|
|
||||||
classpath[0] = jarFile.getCanonicalPath();
|
classpath[0] = jarFile.getCanonicalPath();
|
||||||
instance = new PathsClassLoader(parentCL, classpath);
|
instance = new PathsClassLoader(parentCL, classpath);
|
||||||
result = instance.findClass(jarClassName);
|
result = instance.findClass(jarClassName);
|
||||||
assertTrue("Should return a Class from JAR", result instanceof Class);
|
assertNotNull("Should return a Class from JAR", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -8,8 +8,8 @@
|
|||||||
package org.dspace.external.provider.impl;
|
package org.dspace.external.provider.impl;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -28,10 +28,12 @@ public class MockDataProvider implements ExternalDataProvider {
|
|||||||
* Generic getter for the sourceIdentifier
|
* Generic getter for the sourceIdentifier
|
||||||
* @return the sourceIdentifier value of this MockDataProvider
|
* @return the sourceIdentifier value of this MockDataProvider
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String getSourceIdentifier() {
|
public String getSourceIdentifier() {
|
||||||
return sourceIdentifier;
|
return sourceIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Optional<ExternalDataObject> getExternalDataObject(String id) {
|
public Optional<ExternalDataObject> getExternalDataObject(String id) {
|
||||||
ExternalDataObject externalDataObject = mockLookupMap.get(id);
|
ExternalDataObject externalDataObject = mockLookupMap.get(id);
|
||||||
if (externalDataObject == null) {
|
if (externalDataObject == null) {
|
||||||
@@ -41,8 +43,9 @@ public class MockDataProvider implements ExternalDataProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<ExternalDataObject> searchExternalDataObjects(String query, int start, int limit) {
|
public List<ExternalDataObject> searchExternalDataObjects(String query, int start, int limit) {
|
||||||
List<ExternalDataObject> listToReturn = new LinkedList<>();
|
List<ExternalDataObject> listToReturn = new ArrayList<>();
|
||||||
for (Map.Entry<String, ExternalDataObject> entry : mockLookupMap.entrySet()) {
|
for (Map.Entry<String, ExternalDataObject> entry : mockLookupMap.entrySet()) {
|
||||||
if (StringUtils.containsIgnoreCase(entry.getKey(), query)) {
|
if (StringUtils.containsIgnoreCase(entry.getKey(), query)) {
|
||||||
listToReturn.add(entry.getValue());
|
listToReturn.add(entry.getValue());
|
||||||
@@ -72,7 +75,7 @@ public class MockDataProvider implements ExternalDataProvider {
|
|||||||
|
|
||||||
public void init() throws IOException {
|
public void init() throws IOException {
|
||||||
mockLookupMap = new HashMap<>();
|
mockLookupMap = new HashMap<>();
|
||||||
List<String> externalDataObjectsToMake = new LinkedList<>();
|
List<String> externalDataObjectsToMake = new ArrayList<>();
|
||||||
externalDataObjectsToMake.add("one");
|
externalDataObjectsToMake.add("one");
|
||||||
externalDataObjectsToMake.add("two");
|
externalDataObjectsToMake.add("two");
|
||||||
externalDataObjectsToMake.add("three");
|
externalDataObjectsToMake.add("three");
|
||||||
@@ -83,7 +86,7 @@ public class MockDataProvider implements ExternalDataProvider {
|
|||||||
externalDataObject.setId(id);
|
externalDataObject.setId(id);
|
||||||
externalDataObject.setValue(id);
|
externalDataObject.setValue(id);
|
||||||
externalDataObject.setDisplayValue(id);
|
externalDataObject.setDisplayValue(id);
|
||||||
List<MetadataValueDTO> list = new LinkedList<>();
|
List<MetadataValueDTO> list = new ArrayList<>();
|
||||||
list.add(new MetadataValueDTO("dc", "contributor", "author", null, "Donald, Smith"));
|
list.add(new MetadataValueDTO("dc", "contributor", "author", null, "Donald, Smith"));
|
||||||
externalDataObject.setMetadata(list);
|
externalDataObject.setMetadata(list);
|
||||||
|
|
||||||
|
@@ -128,12 +128,8 @@ public class HandleDAOImplTest extends AbstractUnitTest {
|
|||||||
owningCommunity = context.reloadEntity(owningCommunity);
|
owningCommunity = context.reloadEntity(owningCommunity);
|
||||||
ContentServiceFactory.getInstance().getCommunityService().delete(context, owningCommunity);
|
ContentServiceFactory.getInstance().getCommunityService().delete(context, owningCommunity);
|
||||||
owningCommunity = null;
|
owningCommunity = null;
|
||||||
} catch (SQLException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
throw new AssertionError("Error occurred in destroy()", e);
|
||||||
} catch (AuthorizeException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
item1 = null;
|
item1 = null;
|
||||||
item2 = null;
|
item2 = null;
|
||||||
|
@@ -11,7 +11,7 @@ import static org.hamcrest.CoreMatchers.equalTo;
|
|||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.dspace.AbstractUnitTest;
|
import org.dspace.AbstractUnitTest;
|
||||||
@@ -121,7 +121,7 @@ public class DSpaceCommandLineParameterTest extends AbstractUnitTest {
|
|||||||
String value3 = null;
|
String value3 = null;
|
||||||
DSpaceCommandLineParameter dSpaceCommandLineParameter3 = new DSpaceCommandLineParameter(key3, value3);
|
DSpaceCommandLineParameter dSpaceCommandLineParameter3 = new DSpaceCommandLineParameter(key3, value3);
|
||||||
|
|
||||||
List<DSpaceCommandLineParameter> dSpaceCommandLineParameterList = new LinkedList<>();
|
List<DSpaceCommandLineParameter> dSpaceCommandLineParameterList = new ArrayList<>();
|
||||||
dSpaceCommandLineParameterList.add(dSpaceCommandLineParameter);
|
dSpaceCommandLineParameterList.add(dSpaceCommandLineParameter);
|
||||||
dSpaceCommandLineParameterList.add(dSpaceCommandLineParameter1);
|
dSpaceCommandLineParameterList.add(dSpaceCommandLineParameter1);
|
||||||
dSpaceCommandLineParameterList.add(dSpaceCommandLineParameter2);
|
dSpaceCommandLineParameterList.add(dSpaceCommandLineParameter2);
|
||||||
|
@@ -11,11 +11,11 @@ package org.dspace.statistics.util;
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -114,7 +114,7 @@ public class DummyHttpServletRequest implements HttpServletRequest {
|
|||||||
* @param headerValue The value of the header
|
* @param headerValue The value of the header
|
||||||
*/
|
*/
|
||||||
public void addHeader(String headerName, String headerValue) {
|
public void addHeader(String headerName, String headerValue) {
|
||||||
List<String> values = headers.computeIfAbsent(headerName, k -> new LinkedList<>());
|
List<String> values = headers.computeIfAbsent(headerName, k -> new ArrayList<>());
|
||||||
values.add(headerValue);
|
values.add(headerValue);
|
||||||
}
|
}
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -292,6 +292,7 @@ public class DummyHttpServletRequest implements HttpServletRequest {
|
|||||||
* @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl()
|
* @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public boolean isRequestedSessionIdFromUrl() {
|
public boolean isRequestedSessionIdFromUrl() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return false;
|
||||||
@@ -502,6 +503,7 @@ public class DummyHttpServletRequest implements HttpServletRequest {
|
|||||||
* @see javax.servlet.ServletRequest#getRealPath(java.lang.String)
|
* @see javax.servlet.ServletRequest#getRealPath(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public String getRealPath(String arg0) {
|
public String getRealPath(String arg0) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
|
@@ -271,7 +271,7 @@ public class BasicWorkflowAuthorizationIT
|
|||||||
Item item = wsi.getItem();
|
Item item = wsi.getItem();
|
||||||
Bundle bundle = bundleService.create(context, item, "ORIGINAL");
|
Bundle bundle = bundleService.create(context, item, "ORIGINAL");
|
||||||
File f = new File(AbstractDSpaceTest.testProps.get("test.bitstream").toString());
|
File f = new File(AbstractDSpaceTest.testProps.get("test.bitstream").toString());
|
||||||
Bitstream bs = bitstreamService.create(context, bundle, new FileInputStream(f));
|
bitstreamService.create(context, bundle, new FileInputStream(f));
|
||||||
bundleService.update(context, bundle);
|
bundleService.update(context, bundle);
|
||||||
itemService.update(context, item);
|
itemService.update(context, item);
|
||||||
workspaceItemService.update(context, wsi);
|
workspaceItemService.update(context, wsi);
|
||||||
@@ -323,7 +323,7 @@ public class BasicWorkflowAuthorizationIT
|
|||||||
Item item = wsi.getItem();
|
Item item = wsi.getItem();
|
||||||
Bundle bundle = bundleService.create(context, item, "ORIGINAL");
|
Bundle bundle = bundleService.create(context, item, "ORIGINAL");
|
||||||
File f = new File(AbstractDSpaceTest.testProps.get("test.bitstream").toString());
|
File f = new File(AbstractDSpaceTest.testProps.get("test.bitstream").toString());
|
||||||
Bitstream bs = bitstreamService.create(context, bundle, new FileInputStream(f));
|
bitstreamService.create(context, bundle, new FileInputStream(f));
|
||||||
bundleService.update(context, bundle);
|
bundleService.update(context, bundle);
|
||||||
itemService.update(context, item);
|
itemService.update(context, item);
|
||||||
workspaceItemService.update(context, wsi);
|
workspaceItemService.update(context, wsi);
|
||||||
@@ -365,7 +365,7 @@ public class BasicWorkflowAuthorizationIT
|
|||||||
item.setSubmitter(submitter);
|
item.setSubmitter(submitter);
|
||||||
Bundle bundle = bundleService.create(context, item, "ORIGINAL");
|
Bundle bundle = bundleService.create(context, item, "ORIGINAL");
|
||||||
File f = new File(AbstractDSpaceTest.testProps.get("test.bitstream").toString());
|
File f = new File(AbstractDSpaceTest.testProps.get("test.bitstream").toString());
|
||||||
Bitstream bs = bitstreamService.create(context, bundle, new FileInputStream(f));
|
bitstreamService.create(context, bundle, new FileInputStream(f));
|
||||||
bundleService.update(context, bundle);
|
bundleService.update(context, bundle);
|
||||||
itemService.update(context, item);
|
itemService.update(context, item);
|
||||||
workspaceItemService.update(context, wsi);
|
workspaceItemService.update(context, wsi);
|
||||||
|
@@ -31,49 +31,48 @@ public class RoleTest extends AbstractUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void defaultWorkflow_RoleReviewer() {
|
public void defaultWorkflow_RoleReviewer() {
|
||||||
Role role = defaultWorkflow.getRoles().get("Reviewer");
|
Role role = defaultWorkflow.getRoles().get("Reviewer");
|
||||||
assertEquals(role.getDescription(),
|
assertEquals("The people responsible for this step are able to edit the metadata of incoming submissions, " +
|
||||||
"The people responsible for this step are able to edit the metadata of incoming submissions, " +
|
"and then accept or reject them.", role.getDescription());
|
||||||
"and then accept or reject them.");
|
assertEquals("Reviewer", role.getName());
|
||||||
assertEquals(role.getName(), "Reviewer");
|
assertEquals(Role.Scope.COLLECTION, role.getScope());
|
||||||
assertEquals(role.getScope(), Role.Scope.COLLECTION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultWorkflow_RoleEditor() {
|
public void defaultWorkflow_RoleEditor() {
|
||||||
Role role = defaultWorkflow.getRoles().get("Editor");
|
Role role = defaultWorkflow.getRoles().get("Editor");
|
||||||
assertEquals(role.getDescription(), "The people responsible for this step are able to edit the " +
|
assertEquals("The people responsible for this step are able to edit the " +
|
||||||
"metadata of incoming submissions, and then accept or reject them.");
|
"metadata of incoming submissions, and then accept or reject them.", role.getDescription());
|
||||||
assertEquals(role.getName(), "Editor");
|
assertEquals("Editor", role.getName());
|
||||||
assertEquals(role.getScope(), Role.Scope.COLLECTION);
|
assertEquals(Role.Scope.COLLECTION, role.getScope());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultWorkflow_RoleFinalEditor() {
|
public void defaultWorkflow_RoleFinalEditor() {
|
||||||
Role role = defaultWorkflow.getRoles().get("Final Editor");
|
Role role = defaultWorkflow.getRoles().get("Final Editor");
|
||||||
assertEquals(role.getDescription(), "The people responsible for this step are able to edit the " +
|
assertEquals("The people responsible for this step are able to edit the " +
|
||||||
"metadata of incoming submissions, but will not be able to reject them.");
|
"metadata of incoming submissions, but will not be able to reject them.", role.getDescription());
|
||||||
assertEquals(role.getName(), "Final Editor");
|
assertEquals("Final Editor", role.getName());
|
||||||
assertEquals(role.getScope(), Role.Scope.COLLECTION);
|
assertEquals(Role.Scope.COLLECTION, role.getScope());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void selectSingleReviewer_RoleReviewManagers() {
|
public void selectSingleReviewer_RoleReviewManagers() {
|
||||||
Role role = selectSingleReviewer.getRoles().get("ReviewManagers");
|
Role role = selectSingleReviewer.getRoles().get("ReviewManagers");
|
||||||
assertEquals(role.getName(), "ReviewManagers");
|
assertEquals("ReviewManagers", role.getName());
|
||||||
assertEquals(role.getScope(), Role.Scope.REPOSITORY);
|
assertEquals(Role.Scope.REPOSITORY, role.getScope());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void selectSingleReviewer_RoleReviewer() {
|
public void selectSingleReviewer_RoleReviewer() {
|
||||||
Role role = selectSingleReviewer.getRoles().get("Reviewer");
|
Role role = selectSingleReviewer.getRoles().get("Reviewer");
|
||||||
assertEquals(role.getName(), "Reviewer");
|
assertEquals("Reviewer", role.getName());
|
||||||
assertEquals(role.getScope(), Role.Scope.ITEM);
|
assertEquals(Role.Scope.ITEM, role.getScope());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void scoreReview_RoleScoreReviewers() {
|
public void scoreReview_RoleScoreReviewers() {
|
||||||
Role role = scoreReview.getRoles().get("ScoreReviewers");
|
Role role = scoreReview.getRoles().get("ScoreReviewers");
|
||||||
assertEquals(role.getName(), "ScoreReviewers");
|
assertEquals("ScoreReviewers", role.getName());
|
||||||
assertEquals(role.getScope(), Role.Scope.COLLECTION);
|
assertEquals(Role.Scope.COLLECTION, role.getScope());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,7 @@ import org.dspace.utils.DSpace;
|
|||||||
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||||
import org.dspace.xmlworkflow.state.Workflow;
|
import org.dspace.xmlworkflow.state.Workflow;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -42,6 +43,8 @@ public class XmlWorkflowFactoryTest extends AbstractUnitTest {
|
|||||||
= new DSpace().getServiceManager().getServiceByName("xmlWorkflowFactory",
|
= new DSpace().getServiceManager().getServiceByName("xmlWorkflowFactory",
|
||||||
XmlWorkflowFactoryImpl.class);
|
XmlWorkflowFactoryImpl.class);
|
||||||
private Community owningCommunity;
|
private Community owningCommunity;
|
||||||
|
private Collection mappedCollection;
|
||||||
|
private Collection nonMappedCollection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* log4j category
|
* log4j category
|
||||||
@@ -63,6 +66,9 @@ public class XmlWorkflowFactoryTest extends AbstractUnitTest {
|
|||||||
//we have to create a new community in the database
|
//we have to create a new community in the database
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
this.owningCommunity = communityService.create(null, context);
|
this.owningCommunity = communityService.create(null, context);
|
||||||
|
this.mappedCollection =
|
||||||
|
this.collectionService.create(context, owningCommunity, "123456789/workflow-test-1");
|
||||||
|
this.nonMappedCollection = this.collectionService.create(context, owningCommunity, "123456789/999");
|
||||||
//we need to commit the changes so we don't block the table for testing
|
//we need to commit the changes so we don't block the table for testing
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -74,38 +80,46 @@ public class XmlWorkflowFactoryTest extends AbstractUnitTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will be run after every test as per @After. It will
|
||||||
|
* clean resources initialized by the @Before methods.
|
||||||
|
*
|
||||||
|
* Other methods can be annotated with @After here or in subclasses
|
||||||
|
* but no execution order is guaranteed
|
||||||
|
*/
|
||||||
|
@After
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.collectionService.delete(context, this.nonMappedCollection);
|
||||||
|
this.collectionService.delete(context, this.mappedCollection);
|
||||||
|
this.communityService.delete(context, this.owningCommunity);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error in destroy", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
this.owningCommunity = null;
|
||||||
|
this.nonMappedCollection = null;
|
||||||
|
this.mappedCollection = null;
|
||||||
|
try {
|
||||||
|
super.destroy();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error in destroy", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void workflowMapping_NonMappedCollection() throws WorkflowConfigurationException {
|
public void workflowMapping_NonMappedCollection() throws WorkflowConfigurationException {
|
||||||
Collection collection = this.findOrCreateCollectionWithHandle("123456789/6");
|
Workflow workflow = xmlWorkflowFactory.getWorkflow(this.nonMappedCollection);
|
||||||
Workflow workflow = xmlWorkflowFactory.getWorkflow(collection);
|
|
||||||
assertEquals(workflow.getID(), "defaultWorkflow");
|
assertEquals(workflow.getID(), "defaultWorkflow");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void workflowMapping_MappedCollection() throws WorkflowConfigurationException {
|
public void workflowMapping_MappedCollection() throws WorkflowConfigurationException {
|
||||||
Collection collection = this.findOrCreateCollectionWithHandle("123456789/4");
|
Workflow workflow = xmlWorkflowFactory.getWorkflow(this.mappedCollection);
|
||||||
Workflow workflow = xmlWorkflowFactory.getWorkflow(collection);
|
|
||||||
assertEquals(workflow.getID(), "selectSingleReviewer");
|
assertEquals(workflow.getID(), "selectSingleReviewer");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection findOrCreateCollectionWithHandle(String handle) {
|
|
||||||
try {
|
|
||||||
context.turnOffAuthorisationSystem();
|
|
||||||
for (Collection collection : this.collectionService.findAll(context)) {
|
|
||||||
if (collection.getHandle().equalsIgnoreCase(handle)) {
|
|
||||||
return collection;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Collection collection = this.collectionService.create(context, owningCommunity, handle);
|
|
||||||
context.restoreAuthSystemState();
|
|
||||||
return collection;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
log.error("SQL Error in findOrCreateCollectionWithHandle", e);
|
|
||||||
fail("SQL Error in findOrCreateCollectionWithHandle: " + e.getMessage());
|
|
||||||
} catch (AuthorizeException e) {
|
|
||||||
log.error("Authorization Error in findOrCreateCollectionWithHandle", e);
|
|
||||||
fail("Authorization Error in findOrCreateCollectionWithHandle: " + e.getMessage());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -7,8 +7,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.xmlworkflow.state;
|
package org.dspace.xmlworkflow.state;
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static junit.framework.TestCase.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -35,70 +36,70 @@ public class StepTest extends AbstractUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void defaultWorkflow_ReviewStep() throws WorkflowConfigurationException {
|
public void defaultWorkflow_ReviewStep() throws WorkflowConfigurationException {
|
||||||
Step step = defaultWorkflow.getStep("reviewstep");
|
Step step = defaultWorkflow.getStep("reviewstep");
|
||||||
assertEquals(step.getUserSelectionMethod().getId(), "claimaction");
|
assertEquals("claimaction", step.getUserSelectionMethod().getId());
|
||||||
assertEquals(step.getRole().getName(), "Reviewer");
|
assertEquals("Reviewer", step.getRole().getName());
|
||||||
List<WorkflowActionConfig> actions = step.getActions();
|
List<WorkflowActionConfig> actions = step.getActions();
|
||||||
assert (this.containsActionNamed(actions, "reviewaction"));
|
assertTrue(this.containsActionNamed(actions, "reviewaction"));
|
||||||
assertEquals(step.getNextStep(0).getId(), "editstep");
|
assertEquals("editstep", step.getNextStep(0).getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultWorkflow_EditStep() throws WorkflowConfigurationException {
|
public void defaultWorkflow_EditStep() throws WorkflowConfigurationException {
|
||||||
Step step = defaultWorkflow.getStep("editstep");
|
Step step = defaultWorkflow.getStep("editstep");
|
||||||
assertEquals(step.getUserSelectionMethod().getId(), "claimaction");
|
assertEquals("claimaction", step.getUserSelectionMethod().getId());
|
||||||
assertEquals(step.getRole().getName(), "Editor");
|
assertEquals("Editor", step.getRole().getName());
|
||||||
List<WorkflowActionConfig> actions = step.getActions();
|
List<WorkflowActionConfig> actions = step.getActions();
|
||||||
assert (this.containsActionNamed(actions, "editaction"));
|
assertTrue(this.containsActionNamed(actions, "editaction"));
|
||||||
assertEquals(step.getNextStep(0).getId(), "finaleditstep");
|
assertEquals("finaleditstep", step.getNextStep(0).getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultWorkflow_FinalEditStep() throws WorkflowConfigurationException {
|
public void defaultWorkflow_FinalEditStep() throws WorkflowConfigurationException {
|
||||||
Step step = defaultWorkflow.getStep("finaleditstep");
|
Step step = defaultWorkflow.getStep("finaleditstep");
|
||||||
assertEquals(step.getUserSelectionMethod().getId(), "claimaction");
|
assertEquals("claimaction", step.getUserSelectionMethod().getId());
|
||||||
assertEquals(step.getRole().getName(), "Final Editor");
|
assertEquals("Final Editor", step.getRole().getName());
|
||||||
List<WorkflowActionConfig> actions = step.getActions();
|
List<WorkflowActionConfig> actions = step.getActions();
|
||||||
assert (this.containsActionNamed(actions, "finaleditaction"));
|
assertTrue(this.containsActionNamed(actions, "finaleditaction"));
|
||||||
assertNull(step.getNextStep(0));
|
assertNull(step.getNextStep(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void selectSingleReviewer_SelectReviewerStep() throws WorkflowConfigurationException {
|
public void selectSingleReviewer_SelectReviewerStep() throws WorkflowConfigurationException {
|
||||||
Step step = selectSingleReviewer.getStep("selectReviewerStep");
|
Step step = selectSingleReviewer.getStep("selectReviewerStep");
|
||||||
assertEquals(step.getUserSelectionMethod().getId(), "claimaction");
|
assertEquals("claimaction", step.getUserSelectionMethod().getId());
|
||||||
assertEquals(step.getRole().getName(), "ReviewManagers");
|
assertEquals("ReviewManagers", step.getRole().getName());
|
||||||
List<WorkflowActionConfig> actions = step.getActions();
|
List<WorkflowActionConfig> actions = step.getActions();
|
||||||
assert (this.containsActionNamed(actions, "selectrevieweraction"));
|
assertTrue(this.containsActionNamed(actions, "selectrevieweraction"));
|
||||||
assertEquals(step.getNextStep(0).getId(), "singleUserReviewStep");
|
assertEquals("singleUserReviewStep", step.getNextStep(0).getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void selectSingleReviewer_SingleUserReviewStep() throws WorkflowConfigurationException {
|
public void selectSingleReviewer_SingleUserReviewStep() throws WorkflowConfigurationException {
|
||||||
Step step = selectSingleReviewer.getStep("singleUserReviewStep");
|
Step step = selectSingleReviewer.getStep("singleUserReviewStep");
|
||||||
assertEquals(step.getUserSelectionMethod().getId(), "autoassignAction");
|
assertEquals("autoassignAction", step.getUserSelectionMethod().getId());
|
||||||
assert (step.getRole().getName().equals("Reviewer"));
|
assertEquals("Reviewer", step.getRole().getName());
|
||||||
List<WorkflowActionConfig> actions = step.getActions();
|
List<WorkflowActionConfig> actions = step.getActions();
|
||||||
assert (this.containsActionNamed(actions, "singleuserreviewaction"));
|
assertTrue(this.containsActionNamed(actions, "singleuserreviewaction"));
|
||||||
assertEquals(step.getNextStep(1).getId(), "selectReviewerStep");
|
assertEquals("selectReviewerStep", step.getNextStep(1).getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void scoreReview_ScoreReviewStep() throws WorkflowConfigurationException {
|
public void scoreReview_ScoreReviewStep() throws WorkflowConfigurationException {
|
||||||
Step step = scoreReview.getStep("scoreReviewStep");
|
Step step = scoreReview.getStep("scoreReviewStep");
|
||||||
assertEquals(step.getUserSelectionMethod().getId(), "claimaction");
|
assertEquals("claimaction", step.getUserSelectionMethod().getId());
|
||||||
assertEquals(step.getRole().getName(), "ScoreReviewers");
|
assertEquals("ScoreReviewers", step.getRole().getName());
|
||||||
List<WorkflowActionConfig> actions = step.getActions();
|
List<WorkflowActionConfig> actions = step.getActions();
|
||||||
assert (this.containsActionNamed(actions, "scorereviewaction"));
|
assertTrue(this.containsActionNamed(actions, "scorereviewaction"));
|
||||||
assertEquals(step.getNextStep(0).getId(), "evaluationStep");
|
assertEquals("evaluationStep", step.getNextStep(0).getId());
|
||||||
assertEquals(step.getRequiredUsers(), 2);
|
assertEquals(2, step.getRequiredUsers());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void scoreReview_EvaluationStep() throws WorkflowConfigurationException {
|
public void scoreReview_EvaluationStep() throws WorkflowConfigurationException {
|
||||||
Step step = scoreReview.getStep("evaluationStep");
|
Step step = scoreReview.getStep("evaluationStep");
|
||||||
assertEquals(step.getUserSelectionMethod().getId(), "noUserSelectionAction");
|
assertEquals("noUserSelectionAction", step.getUserSelectionMethod().getId());
|
||||||
List<WorkflowActionConfig> actions = step.getActions();
|
List<WorkflowActionConfig> actions = step.getActions();
|
||||||
assert (this.containsActionNamed(actions, "evaluationaction"));
|
assertTrue(this.containsActionNamed(actions, "evaluationaction"));
|
||||||
assertNull(step.getNextStep(0));
|
assertNull(step.getNextStep(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,7 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.xmlworkflow.state;
|
package org.dspace.xmlworkflow.state;
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -31,30 +32,30 @@ public class WorkflowTest extends AbstractUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultWorkflow() {
|
public void defaultWorkflow() {
|
||||||
assertEquals(defaultWorkflow.getFirstStep().getId(), "reviewstep");
|
assertEquals("reviewstep", defaultWorkflow.getFirstStep().getId());
|
||||||
List<Step> steps = defaultWorkflow.getSteps();
|
List<Step> steps = defaultWorkflow.getSteps();
|
||||||
assertEquals(steps.size(), 3);
|
assertEquals(3, steps.size());
|
||||||
assert (this.containsStepNamed(steps, "reviewstep"));
|
assertTrue(this.containsStepNamed(steps, "reviewstep"));
|
||||||
assert (this.containsStepNamed(steps, "editstep"));
|
assertTrue(this.containsStepNamed(steps, "editstep"));
|
||||||
assert (this.containsStepNamed(steps, "finaleditstep"));
|
assertTrue(this.containsStepNamed(steps, "finaleditstep"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void selectSingleReviewer() {
|
public void selectSingleReviewer() {
|
||||||
assertEquals(selectSingleReviewer.getFirstStep().getId(), "selectReviewerStep");
|
assertEquals("selectReviewerStep", selectSingleReviewer.getFirstStep().getId());
|
||||||
List<Step> steps = selectSingleReviewer.getSteps();
|
List<Step> steps = selectSingleReviewer.getSteps();
|
||||||
assertEquals(steps.size(), 2);
|
assertEquals(2, steps.size());
|
||||||
assert (this.containsStepNamed(steps, "selectReviewerStep"));
|
assertTrue(this.containsStepNamed(steps, "selectReviewerStep"));
|
||||||
assert (this.containsStepNamed(steps, "singleUserReviewStep"));
|
assertTrue(this.containsStepNamed(steps, "singleUserReviewStep"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void scoreReview() {
|
public void scoreReview() {
|
||||||
assertEquals(scoreReview.getFirstStep().getId(), "scoreReviewStep");
|
assertEquals("scoreReviewStep", scoreReview.getFirstStep().getId());
|
||||||
List<Step> steps = scoreReview.getSteps();
|
List<Step> steps = scoreReview.getSteps();
|
||||||
assertEquals(steps.size(), 2);
|
assertEquals(2, steps.size());
|
||||||
assert (this.containsStepNamed(steps, "scoreReviewStep"));
|
assertTrue(this.containsStepNamed(steps, "scoreReviewStep"));
|
||||||
assert (this.containsStepNamed(steps, "evaluationStep"));
|
assertTrue(this.containsStepNamed(steps, "evaluationStep"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean containsStepNamed(List<Step> steps, String stepName) {
|
private boolean containsStepNamed(List<Step> steps, String stepName) {
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<!-- This is the path to the root [dspace-src] directory. -->
|
<!-- This is the path to the root [dspace-src] directory. -->
|
||||||
<root.basedir>${basedir}/..</root.basedir>
|
<root.basedir>${basedir}/..</root.basedir>
|
||||||
<xoai.version>3.2.11</xoai.version>
|
<xoai.version>3.3.0</xoai.version>
|
||||||
<jtwig.version>5.87.0.RELEASE</jtwig.version>
|
<jtwig.version>5.87.0.RELEASE</jtwig.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
@@ -103,6 +103,11 @@
|
|||||||
<groupId>org.codehaus.woodstox</groupId>
|
<groupId>org.codehaus.woodstox</groupId>
|
||||||
<artifactId>wstx-asl</artifactId>
|
<artifactId>wstx-asl</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
|
<!-- Later version provided by Hibernate -->
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.dom4j</groupId>
|
||||||
|
<artifactId>dom4j</artifactId>
|
||||||
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@@ -22,7 +22,7 @@ import org.dspace.core.ConfigurationManager;
|
|||||||
|
|
||||||
public class DSpaceResourceResolver implements ResourceResolver {
|
public class DSpaceResourceResolver implements ResourceResolver {
|
||||||
private static final TransformerFactory transformerFactory = TransformerFactory
|
private static final TransformerFactory transformerFactory = TransformerFactory
|
||||||
.newInstance();
|
.newInstance("net.sf.saxon.TransformerFactoryImpl", null);
|
||||||
|
|
||||||
private final String basePath = ConfigurationManager.getProperty("oai",
|
private final String basePath = ConfigurationManager.getProperty("oai",
|
||||||
"config.dir");
|
"config.dir");
|
||||||
|
@@ -26,11 +26,12 @@ public class DSpaceSolrServerResolver implements SolrServerResolver {
|
|||||||
@Override
|
@Override
|
||||||
public SolrClient getServer() throws SolrServerException {
|
public SolrClient getServer() throws SolrServerException {
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
|
String serverUrl = configurationService.getProperty("oai.solr.url");
|
||||||
try {
|
try {
|
||||||
server = new HttpSolrClient.Builder(configurationService.getProperty("oai", "solr.url")).build();
|
server = new HttpSolrClient.Builder(serverUrl).build();
|
||||||
log.debug("Solr Server Initialized");
|
log.debug("OAI Solr Server Initialized");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error("Could not initialize OAI Solr Server at " + serverUrl , e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return server;
|
return server;
|
||||||
|
@@ -30,12 +30,12 @@ public class DSpaceSolrServer {
|
|||||||
|
|
||||||
public static SolrClient getServer() throws SolrServerException {
|
public static SolrClient getServer() throws SolrServerException {
|
||||||
if (_server == null) {
|
if (_server == null) {
|
||||||
|
String serverUrl = ConfigurationManager.getProperty("oai.solr.url");
|
||||||
try {
|
try {
|
||||||
_server = new HttpSolrClient.Builder(
|
_server = new HttpSolrClient.Builder(serverUrl).build();
|
||||||
ConfigurationManager.getProperty("oai", "solr.url")).build();
|
log.debug("OAI Solr Server Initialized");
|
||||||
log.debug("Solr Server Initialized");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error("Could not initialize OAI Solr Server at " + serverUrl , e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _server;
|
return _server;
|
||||||
|
@@ -19,7 +19,8 @@ import javax.xml.transform.stream.StreamSource;
|
|||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
public abstract class AbstractXSLTest {
|
public abstract class AbstractXSLTest {
|
||||||
private static final TransformerFactory factory = TransformerFactory.newInstance();
|
private static final TransformerFactory factory = TransformerFactory
|
||||||
|
.newInstance("net.sf.saxon.TransformerFactoryImpl", null);
|
||||||
|
|
||||||
protected TransformBuilder apply(String xslLocation) throws Exception {
|
protected TransformBuilder apply(String xslLocation) throws Exception {
|
||||||
return new TransformBuilder(xslLocation);
|
return new TransformBuilder(xslLocation);
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
#DSpace REST API (Jersey)
|
#DSpace REST API (Jersey) - DEPRECATED
|
||||||
|
|
||||||
A RESTful web services API for DSpace, built using JAX-RS1 JERSEY.
|
A RESTful web services API for DSpace, built using JAX-RS1 JERSEY.
|
||||||
|
|
||||||
|
_This REST API has been deprecated and will be removed in v8. Please use the Server API (/server) webapp instead._
|
||||||
|
|
||||||
##Getting Started
|
##Getting Started
|
||||||
This REST API is integrated directly into the DSpace codebase.
|
This REST API is integrated directly into the DSpace codebase.
|
||||||
|
|
||||||
|
@@ -59,7 +59,9 @@ public class RestIndex {
|
|||||||
// TODO Better graphics, add arguments to all methods. (limit, offset, item and so on)
|
// TODO Better graphics, add arguments to all methods. (limit, offset, item and so on)
|
||||||
return "<html><title>DSpace REST - index</title>" +
|
return "<html><title>DSpace REST - index</title>" +
|
||||||
"<body>"
|
"<body>"
|
||||||
+ "<h1>DSpace REST API</h1>" +
|
+ "<h1>DSpace REST API (Deprecated)</h1>" +
|
||||||
|
"<em>This REST API is deprecated and will be removed in v8." +
|
||||||
|
" Please use the new Server API webapp instead.</em><br/>" +
|
||||||
"Server path: " + servletContext.getContextPath() +
|
"Server path: " + servletContext.getContextPath() +
|
||||||
"<h2>Index</h2>" +
|
"<h2>Index</h2>" +
|
||||||
"<ul>" +
|
"<ul>" +
|
||||||
|
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>DSpace REST API</servlet-name>
|
<servlet-name>DSpace REST API (Deprecated)</servlet-name>
|
||||||
<servlet-class>
|
<servlet-class>
|
||||||
org.glassfish.jersey.servlet.ServletContainer
|
org.glassfish.jersey.servlet.ServletContainer
|
||||||
</servlet-class>
|
</servlet-class>
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
</servlet>
|
</servlet>
|
||||||
|
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>DSpace REST API</servlet-name>
|
<servlet-name>DSpace REST API (Deprecated)</servlet-name>
|
||||||
<url-pattern>/*</url-pattern>
|
<url-pattern>/*</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
<!-- Security settings and mapping -->
|
<!-- Security settings and mapping -->
|
||||||
<security-constraint>
|
<security-constraint>
|
||||||
<web-resource-collection>
|
<web-resource-collection>
|
||||||
<web-resource-name>DSpace REST API</web-resource-name>
|
<web-resource-name>DSpace REST API (Deprecated)</web-resource-name>
|
||||||
<url-pattern>/*</url-pattern>
|
<url-pattern>/*</url-pattern>
|
||||||
</web-resource-collection>
|
</web-resource-collection>
|
||||||
<user-data-constraint>
|
<user-data-constraint>
|
||||||
|
@@ -27,7 +27,6 @@ import org.dspace.app.rest.converter.ConverterService;
|
|||||||
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||||
import org.dspace.app.rest.model.BitstreamRest;
|
import org.dspace.app.rest.model.BitstreamRest;
|
||||||
import org.dspace.app.rest.model.hateoas.BitstreamResource;
|
import org.dspace.app.rest.model.hateoas.BitstreamResource;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
|
||||||
import org.dspace.app.rest.utils.ContextUtil;
|
import org.dspace.app.rest.utils.ContextUtil;
|
||||||
import org.dspace.app.rest.utils.MultipartFileSender;
|
import org.dspace.app.rest.utils.MultipartFileSender;
|
||||||
import org.dspace.app.rest.utils.Utils;
|
import org.dspace.app.rest.utils.Utils;
|
||||||
@@ -243,7 +242,7 @@ public class BitstreamRestController {
|
|||||||
|
|
||||||
context.commit();
|
context.commit();
|
||||||
|
|
||||||
BitstreamRest bitstreamRest = converter.toRest(context.reloadEntity(bitstream), Projection.DEFAULT);
|
BitstreamRest bitstreamRest = converter.toRest(context.reloadEntity(bitstream), utils.obtainProjection());
|
||||||
return converter.toResource(bitstreamRest);
|
return converter.toResource(bitstreamRest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,311 @@
|
|||||||
|
/**
|
||||||
|
* 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 java.util.regex.Pattern.compile;
|
||||||
|
import static org.apache.http.HttpStatus.SC_NO_CONTENT;
|
||||||
|
import static org.apache.http.HttpStatus.SC_UNPROCESSABLE_ENTITY;
|
||||||
|
import static org.dspace.app.rest.utils.ContextUtil.obtainContext;
|
||||||
|
import static org.dspace.app.rest.utils.RegexUtils.REGEX_UUID;
|
||||||
|
import static org.dspace.app.util.AuthorizeUtil.authorizeManageAdminGroup;
|
||||||
|
import static org.dspace.app.util.AuthorizeUtil.authorizeManageSubmittersGroup;
|
||||||
|
import static org.dspace.app.util.AuthorizeUtil.authorizeManageWorkflowsGroup;
|
||||||
|
import static org.springframework.web.bind.annotation.RequestMethod.DELETE;
|
||||||
|
import static org.springframework.web.bind.annotation.RequestMethod.POST;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
|
import org.dspace.app.rest.model.GroupRest;
|
||||||
|
import org.dspace.app.rest.utils.GroupUtil;
|
||||||
|
import org.dspace.app.rest.utils.Utils;
|
||||||
|
import org.dspace.authorize.AuthorizeException;
|
||||||
|
import org.dspace.authorize.service.AuthorizeService;
|
||||||
|
import org.dspace.content.Collection;
|
||||||
|
import org.dspace.content.Community;
|
||||||
|
import org.dspace.core.Context;
|
||||||
|
import org.dspace.eperson.EPerson;
|
||||||
|
import org.dspace.eperson.Group;
|
||||||
|
import org.dspace.eperson.service.EPersonService;
|
||||||
|
import org.dspace.eperson.service.GroupService;
|
||||||
|
import org.dspace.xmlworkflow.storedcomponents.CollectionRole;
|
||||||
|
import org.dspace.xmlworkflow.storedcomponents.service.CollectionRoleService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will be the entry point for the api/eperson/groups endpoint with additional paths to it
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/" + GroupRest.CATEGORY + "/" + GroupRest.GROUPS)
|
||||||
|
public class GroupRestController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GroupService groupService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EPersonService ePersonService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AuthorizeService authorizeService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CollectionRoleService collectionRoleService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
Utils utils;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
GroupUtil groupUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to add one or more subgroups to a group.
|
||||||
|
* The subgroups to be added should be provided in the request body as a uri-list.
|
||||||
|
* Note that only the 'AUTHENTICATED' state will be checked in PreAuthorize, a more detailed check will be done by
|
||||||
|
* using the 'checkAuthorization' method.
|
||||||
|
*
|
||||||
|
* @param uuid the uuid of the group to add the subgroups to
|
||||||
|
*/
|
||||||
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
|
@RequestMapping(method = POST, path = "/{uuid}/subgroups", consumes = {"text/uri-list"})
|
||||||
|
public void addChildGroups(@PathVariable UUID uuid, HttpServletResponse response, HttpServletRequest request)
|
||||||
|
throws SQLException, AuthorizeException {
|
||||||
|
|
||||||
|
Context context = obtainContext(request);
|
||||||
|
|
||||||
|
Group parentGroup = groupService.find(context, uuid);
|
||||||
|
if (parentGroup == null) {
|
||||||
|
throw new ResourceNotFoundException("parent group is not found for uuid: " + uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkAuthorization(context, parentGroup);
|
||||||
|
|
||||||
|
List<String> groupLinks = utils.getStringListFromRequest(request);
|
||||||
|
|
||||||
|
List<Group> childGroups = new ArrayList<>();
|
||||||
|
for (String groupLink : groupLinks) {
|
||||||
|
Optional<Group> childGroup = findGroup(context, groupLink);
|
||||||
|
if (!childGroup.isPresent() || !canAddGroup(context, parentGroup, childGroup.get())) {
|
||||||
|
throw new UnprocessableEntityException("cannot add child group: " + groupLink);
|
||||||
|
}
|
||||||
|
childGroups.add(childGroup.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Group childGroup : childGroups) {
|
||||||
|
groupService.addMember(context, parentGroup, childGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.complete();
|
||||||
|
|
||||||
|
response.setStatus(SC_NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<Group> findGroup(Context context, String groupLink) throws SQLException {
|
||||||
|
|
||||||
|
Group group = null;
|
||||||
|
|
||||||
|
Pattern linkPattern = compile("^.*/(" + REGEX_UUID + ")/?$");
|
||||||
|
Matcher matcher = linkPattern.matcher(groupLink);
|
||||||
|
if (matcher.matches()) {
|
||||||
|
group = groupService.find(context, UUID.fromString(matcher.group(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.ofNullable(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canAddGroup(Context context, Group parentGroup, Group childGroup) throws SQLException {
|
||||||
|
|
||||||
|
return !groupService.isParentOf(context, childGroup, parentGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to add one or more members to a group.
|
||||||
|
* The members to be added should be provided in the request body as a uri-list.
|
||||||
|
* Note that only the 'AUTHENTICATED' state will be checked in PreAuthorize, a more detailed check will be done by
|
||||||
|
* using the 'checkAuthorization' method.
|
||||||
|
*
|
||||||
|
* @param uuid the uuid of the group to add the members to
|
||||||
|
*/
|
||||||
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
|
@RequestMapping(method = POST, path = "/{uuid}/epersons", consumes = {"text/uri-list"})
|
||||||
|
public void addMembers(@PathVariable UUID uuid, HttpServletResponse response, HttpServletRequest request)
|
||||||
|
throws SQLException, AuthorizeException {
|
||||||
|
|
||||||
|
Context context = obtainContext(request);
|
||||||
|
|
||||||
|
Group parentGroup = groupService.find(context, uuid);
|
||||||
|
if (parentGroup == null) {
|
||||||
|
throw new ResourceNotFoundException("parent group is not found for uuid: " + uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkAuthorization(context, parentGroup);
|
||||||
|
|
||||||
|
List<String> memberLinks = utils.getStringListFromRequest(request);
|
||||||
|
|
||||||
|
List<EPerson> members = new ArrayList<>();
|
||||||
|
for (String memberLink : memberLinks) {
|
||||||
|
Optional<EPerson> member = findEPerson(context, memberLink);
|
||||||
|
if (!member.isPresent()) {
|
||||||
|
throw new UnprocessableEntityException("cannot add child group: " + memberLink);
|
||||||
|
}
|
||||||
|
members.add(member.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (EPerson member : members) {
|
||||||
|
groupService.addMember(context, parentGroup, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.complete();
|
||||||
|
|
||||||
|
response.setStatus(SC_NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<EPerson> findEPerson(Context context, String groupLink) throws SQLException {
|
||||||
|
|
||||||
|
EPerson ePerson = null;
|
||||||
|
|
||||||
|
Pattern linkPattern = compile("^.*/(" + REGEX_UUID + ")/?$");
|
||||||
|
Matcher matcher = linkPattern.matcher(groupLink);
|
||||||
|
if (matcher.matches()) {
|
||||||
|
ePerson = ePersonService.find(context, UUID.fromString(matcher.group(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.ofNullable(ePerson);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to remove a subgroup from a group.
|
||||||
|
* Note that only the 'AUTHENTICATED' state will be checked in PreAuthorize, a more detailed check will be done by
|
||||||
|
* using the 'checkAuthorization' method.
|
||||||
|
*
|
||||||
|
* @param parentUUID the uuid of the parent group
|
||||||
|
* @param childUUID the uuid of the subgroup which has to be removed
|
||||||
|
*/
|
||||||
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
|
@RequestMapping(method = DELETE, path = "/{parentUUID}/subgroups/{childUUID}")
|
||||||
|
public void removeChildGroup(@PathVariable UUID parentUUID, @PathVariable UUID childUUID,
|
||||||
|
HttpServletResponse response, HttpServletRequest request)
|
||||||
|
throws IOException, SQLException, AuthorizeException {
|
||||||
|
|
||||||
|
Context context = obtainContext(request);
|
||||||
|
|
||||||
|
Group parentGroup = groupService.find(context, parentUUID);
|
||||||
|
if (parentGroup == null) {
|
||||||
|
throw new ResourceNotFoundException("parent group is not found for uuid: " + parentUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkAuthorization(context, parentGroup);
|
||||||
|
|
||||||
|
Group childGroup = groupService.find(context, childUUID);
|
||||||
|
if (childGroup == null) {
|
||||||
|
response.sendError(SC_UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
groupService.removeMember(context, parentGroup, childGroup);
|
||||||
|
|
||||||
|
context.complete();
|
||||||
|
|
||||||
|
response.setStatus(SC_NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to remove a member from a group.
|
||||||
|
* Note that only the 'AUTHENTICATED' state will be checked in PreAuthorize, a more detailed check will be done by
|
||||||
|
* using the 'checkAuthorization' method.
|
||||||
|
*
|
||||||
|
* @param parentUUID the uuid of the parent group
|
||||||
|
* @param memberUUID the uuid of the member which has to be removed
|
||||||
|
*/
|
||||||
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
|
@RequestMapping(method = DELETE, path = "/{parentUUID}/epersons/{memberUUID}")
|
||||||
|
public void removeMember(@PathVariable UUID parentUUID, @PathVariable UUID memberUUID,
|
||||||
|
HttpServletResponse response, HttpServletRequest request)
|
||||||
|
throws IOException, SQLException, AuthorizeException {
|
||||||
|
|
||||||
|
Context context = obtainContext(request);
|
||||||
|
|
||||||
|
Group parentGroup = groupService.find(context, parentUUID);
|
||||||
|
if (parentGroup == null) {
|
||||||
|
throw new ResourceNotFoundException("parent group is not found for uuid: " + parentUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkAuthorization(context, parentGroup);
|
||||||
|
|
||||||
|
EPerson childGroup = ePersonService.find(context, memberUUID);
|
||||||
|
if (childGroup == null) {
|
||||||
|
response.sendError(SC_UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
groupService.removeMember(context, parentGroup, childGroup);
|
||||||
|
|
||||||
|
context.complete();
|
||||||
|
|
||||||
|
response.setStatus(SC_NO_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method checks whether the current user has sufficient rights to modify the group.
|
||||||
|
* Depending on the kind of group and due to delegated administration, separate checks need to be done to verify
|
||||||
|
* whether the user is allowed to modify the group.
|
||||||
|
*
|
||||||
|
* @param context the context of which the user will be checked
|
||||||
|
* @param group the group to be checked
|
||||||
|
* @throws SQLException
|
||||||
|
* @throws AuthorizeException
|
||||||
|
*/
|
||||||
|
private void checkAuthorization(Context context, Group group) throws SQLException, AuthorizeException {
|
||||||
|
|
||||||
|
if (authorizeService.isAdmin(context)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Collection collection = groupUtil.getCollection(context, group);
|
||||||
|
if (collection != null) {
|
||||||
|
|
||||||
|
if (group.equals(collection.getSubmitters())) {
|
||||||
|
authorizeManageSubmittersGroup(context, collection);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
List<CollectionRole> collectionRoles = collectionRoleService.findByCollection(context, collection);
|
||||||
|
for (CollectionRole role : collectionRoles) {
|
||||||
|
if (group.equals(role.getGroup())) {
|
||||||
|
authorizeManageWorkflowsGroup(context, collection);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (group.equals(collection.getAdministrators())) {
|
||||||
|
authorizeManageAdminGroup(context, collection);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Community community = groupUtil.getCommunity(context, group);
|
||||||
|
if (community != null) {
|
||||||
|
authorizeManageAdminGroup(context, community);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new AuthorizeException("not authorized to manage this group");
|
||||||
|
}
|
||||||
|
}
|
@@ -22,7 +22,6 @@ import org.dspace.app.rest.exception.UnprocessableEntityException;
|
|||||||
import org.dspace.app.rest.model.BundleRest;
|
import org.dspace.app.rest.model.BundleRest;
|
||||||
import org.dspace.app.rest.model.ItemRest;
|
import org.dspace.app.rest.model.ItemRest;
|
||||||
import org.dspace.app.rest.model.hateoas.BundleResource;
|
import org.dspace.app.rest.model.hateoas.BundleResource;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
|
||||||
import org.dspace.app.rest.repository.ItemRestRepository;
|
import org.dspace.app.rest.repository.ItemRestRepository;
|
||||||
import org.dspace.app.rest.utils.ContextUtil;
|
import org.dspace.app.rest.utils.ContextUtil;
|
||||||
import org.dspace.app.rest.utils.Utils;
|
import org.dspace.app.rest.utils.Utils;
|
||||||
@@ -108,7 +107,7 @@ public class ItemAddBundleController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bundle bundle = itemRestRepository.addBundleToItem(context, item, bundleRest);
|
Bundle bundle = itemRestRepository.addBundleToItem(context, item, bundleRest);
|
||||||
BundleResource bundleResource = converter.toResource(converter.toRest(bundle, Projection.DEFAULT));
|
BundleResource bundleResource = converter.toResource(converter.toRest(bundle, utils.obtainProjection()));
|
||||||
return ControllerUtils.toResponseEntity(HttpStatus.CREATED, new HttpHeaders(), bundleResource);
|
return ControllerUtils.toResponseEntity(HttpStatus.CREATED, new HttpHeaders(), bundleResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,7 +21,6 @@ import org.dspace.app.rest.converter.ConverterService;
|
|||||||
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||||
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
import org.dspace.app.rest.model.CollectionRest;
|
import org.dspace.app.rest.model.CollectionRest;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
|
||||||
import org.dspace.app.rest.utils.ContextUtil;
|
import org.dspace.app.rest.utils.ContextUtil;
|
||||||
import org.dspace.app.rest.utils.Utils;
|
import org.dspace.app.rest.utils.Utils;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
@@ -97,7 +96,7 @@ public class ItemOwningCollectionUpdateRestController {
|
|||||||
if (targetCollection == null) {
|
if (targetCollection == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return converter.toRest(targetCollection, Projection.DEFAULT);
|
return converter.toRest(targetCollection, utils.obtainProjection());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -580,11 +580,10 @@ public class RestResourceController implements InitializingBean {
|
|||||||
MultipartFile uploadfile) {
|
MultipartFile uploadfile) {
|
||||||
checkModelPluralForm(apiCategory, model);
|
checkModelPluralForm(apiCategory, model);
|
||||||
DSpaceRestRepository<RestAddressableModel, ID> repository = utils.getResourceRepository(apiCategory, model);
|
DSpaceRestRepository<RestAddressableModel, ID> repository = utils.getResourceRepository(apiCategory, model);
|
||||||
|
|
||||||
RestAddressableModel modelObject = null;
|
RestAddressableModel modelObject = null;
|
||||||
try {
|
try {
|
||||||
modelObject = repository.upload(request, apiCategory, model, id, uploadfile);
|
modelObject = repository.upload(request, apiCategory, model, id, uploadfile);
|
||||||
} catch (Exception e) {
|
} catch (SQLException e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
return ControllerUtils.toEmptyResponse(HttpStatus.INTERNAL_SERVER_ERROR);
|
return ControllerUtils.toEmptyResponse(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
@@ -910,7 +909,6 @@ public class RestResourceController implements InitializingBean {
|
|||||||
Pageable page,
|
Pageable page,
|
||||||
PagedResourcesAssembler assembler,
|
PagedResourcesAssembler assembler,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
|
|
||||||
DSpaceRestRepository<T, ?> repository = utils.getResourceRepository(apiCategory, model);
|
DSpaceRestRepository<T, ?> repository = utils.getResourceRepository(apiCategory, model);
|
||||||
Link link = linkTo(methodOn(this.getClass(), apiCategory, model).findAll(apiCategory, model,
|
Link link = linkTo(methodOn(this.getClass(), apiCategory, model).findAll(apiCategory, model,
|
||||||
page, assembler, response))
|
page, assembler, response))
|
||||||
|
@@ -0,0 +1,82 @@
|
|||||||
|
/**
|
||||||
|
* 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 java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.converter.ConverterService;
|
||||||
|
import org.dspace.app.rest.model.CollectionRest;
|
||||||
|
import org.dspace.app.rest.model.WorkflowDefinitionRest;
|
||||||
|
import org.dspace.app.rest.projection.Projection;
|
||||||
|
import org.dspace.app.rest.repository.AbstractDSpaceRestRepository;
|
||||||
|
import org.dspace.app.rest.repository.LinkRestRepository;
|
||||||
|
import org.dspace.app.rest.utils.Utils;
|
||||||
|
import org.dspace.content.Collection;
|
||||||
|
import org.dspace.core.Context;
|
||||||
|
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link repository for "collections" subresource of an individual workflow definition.
|
||||||
|
*
|
||||||
|
* @author Maria Verdonck (Atmire) on 11/12/2019
|
||||||
|
*/
|
||||||
|
@Component(WorkflowDefinitionRest.CATEGORY + "." + WorkflowDefinitionRest.NAME + "."
|
||||||
|
+ WorkflowDefinitionRest.COLLECTIONS_MAPPED_TO)
|
||||||
|
public class WorkflowDefinitionCollectionsLinkRepository extends AbstractDSpaceRestRepository
|
||||||
|
implements LinkRestRepository {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected XmlWorkflowFactory xmlWorkflowFactory;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected ConverterService converter;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected Utils utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET endpoint that returns the list of collections that make an explicit use of the workflow-definition.
|
||||||
|
* If a collection doesn't specify the workflow-definition to be used, the default mapping applies,
|
||||||
|
* but this collection is not included in the list returned by this method.
|
||||||
|
*
|
||||||
|
* @param request The request object
|
||||||
|
* @param workflowName Name of workflow we want the collections of that are mapped to is
|
||||||
|
* @return List of collections mapped to the requested workflow
|
||||||
|
*/
|
||||||
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
|
public Page<CollectionRest> getCollections(@Nullable HttpServletRequest request,
|
||||||
|
String workflowName,
|
||||||
|
@Nullable Pageable optionalPageable,
|
||||||
|
Projection projection) {
|
||||||
|
if (xmlWorkflowFactory.workflowByThisNameExists(workflowName)) {
|
||||||
|
Context context = obtainContext();
|
||||||
|
List<Collection> collectionsMappedToWorkflow = new ArrayList<>();
|
||||||
|
if (xmlWorkflowFactory.isDefaultWorkflow(workflowName)) {
|
||||||
|
collectionsMappedToWorkflow.addAll(xmlWorkflowFactory.getAllNonMappedCollectionsHandles(context));
|
||||||
|
}
|
||||||
|
collectionsMappedToWorkflow.addAll(xmlWorkflowFactory.getCollectionHandlesMappedToWorklow(context,
|
||||||
|
workflowName));
|
||||||
|
Pageable pageable = optionalPageable != null ? optionalPageable : new PageRequest(0, 20);
|
||||||
|
return converter.toRestPage(utils.getPage(collectionsMappedToWorkflow, pageable),
|
||||||
|
projection);
|
||||||
|
} else {
|
||||||
|
throw new ResourceNotFoundException("No workflow with name " + workflowName + " is configured");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,63 @@
|
|||||||
|
/**
|
||||||
|
* 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 java.util.List;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.model.WorkflowDefinitionRest;
|
||||||
|
import org.dspace.app.rest.model.WorkflowStepRest;
|
||||||
|
import org.dspace.app.rest.projection.Projection;
|
||||||
|
import org.dspace.app.rest.repository.AbstractDSpaceRestRepository;
|
||||||
|
import org.dspace.app.rest.repository.LinkRestRepository;
|
||||||
|
import org.dspace.xmlworkflow.WorkflowConfigurationException;
|
||||||
|
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||||
|
import org.dspace.xmlworkflow.state.Step;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link repository for "steps" subresource of an individual workflow definition.
|
||||||
|
*
|
||||||
|
* @author Maria Verdonck (Atmire) on 24/02/2020
|
||||||
|
*/
|
||||||
|
@Component(WorkflowDefinitionRest.CATEGORY + "." + WorkflowDefinitionRest.NAME + "."
|
||||||
|
+ WorkflowDefinitionRest.STEPS)
|
||||||
|
public class WorkflowDefinitionStepsLinkRepository extends AbstractDSpaceRestRepository
|
||||||
|
implements LinkRestRepository {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected XmlWorkflowFactory xmlWorkflowFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET endpoint that returns the list of steps of a workflow-definition.
|
||||||
|
*
|
||||||
|
* @param request The request object
|
||||||
|
* @param workflowName Name of workflow we want the steps from
|
||||||
|
* @return List of steps of the requested workflow
|
||||||
|
*/
|
||||||
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
|
public Page<WorkflowStepRest> getSteps(@Nullable HttpServletRequest request,
|
||||||
|
String workflowName,
|
||||||
|
@Nullable Pageable optionalPageable,
|
||||||
|
Projection projection) {
|
||||||
|
try {
|
||||||
|
List<Step> steps = xmlWorkflowFactory.getWorkflowByName(workflowName).getSteps();
|
||||||
|
Pageable pageable = optionalPageable != null ? optionalPageable : new PageRequest(0, 20);
|
||||||
|
return converter.toRestPage(utils.getPage(steps, pageable), projection);
|
||||||
|
} catch (WorkflowConfigurationException e) {
|
||||||
|
throw new ResourceNotFoundException("No workflow with name " + workflowName + " is configured");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,57 @@
|
|||||||
|
/**
|
||||||
|
* 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 java.util.List;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.model.WorkflowActionRest;
|
||||||
|
import org.dspace.app.rest.model.WorkflowStepRest;
|
||||||
|
import org.dspace.app.rest.projection.Projection;
|
||||||
|
import org.dspace.app.rest.repository.AbstractDSpaceRestRepository;
|
||||||
|
import org.dspace.app.rest.repository.LinkRestRepository;
|
||||||
|
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||||
|
import org.dspace.xmlworkflow.state.actions.WorkflowActionConfig;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link repository for "actions" subresource of an individual workflow step.
|
||||||
|
*
|
||||||
|
* @author Maria Verdonck (Atmire) on 24/02/2020
|
||||||
|
*/
|
||||||
|
@Component(WorkflowStepRest.CATEGORY + "." + WorkflowStepRest.NAME + "."
|
||||||
|
+ WorkflowStepRest.ACTIONS)
|
||||||
|
public class WorkflowStepActionsLinkRepository extends AbstractDSpaceRestRepository
|
||||||
|
implements LinkRestRepository {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected XmlWorkflowFactory xmlWorkflowFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET endpoint that returns the list of actions of a workflow step.
|
||||||
|
*
|
||||||
|
* @param request The request object
|
||||||
|
* @param workflowStepName Name of workflow step we want the actions from
|
||||||
|
* @return List of actions of the requested workflow step
|
||||||
|
*/
|
||||||
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
|
public Page<WorkflowActionRest> getActions(@Nullable HttpServletRequest request,
|
||||||
|
String workflowStepName,
|
||||||
|
@Nullable Pageable optionalPageable,
|
||||||
|
Projection projection) {
|
||||||
|
List<WorkflowActionConfig> actions = xmlWorkflowFactory.getStepByName(workflowStepName).getActions();
|
||||||
|
Pageable pageable = optionalPageable != null ? optionalPageable : new PageRequest(0, 20);
|
||||||
|
return converter.toRestPage(utils.getPage(actions, pageable), projection);
|
||||||
|
}
|
||||||
|
}
|
@@ -10,6 +10,7 @@ package org.dspace.app.rest.converter;
|
|||||||
import org.dspace.app.rest.model.ClaimedTaskRest;
|
import org.dspace.app.rest.model.ClaimedTaskRest;
|
||||||
import org.dspace.app.rest.projection.Projection;
|
import org.dspace.app.rest.projection.Projection;
|
||||||
import org.dspace.discovery.IndexableObject;
|
import org.dspace.discovery.IndexableObject;
|
||||||
|
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.ClaimedTask;
|
import org.dspace.xmlworkflow.storedcomponents.ClaimedTask;
|
||||||
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -28,6 +29,9 @@ public class ClaimedTaskConverter
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ConverterService converter;
|
private ConverterService converter;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected XmlWorkflowFactory xmlWorkflowFactory;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClaimedTaskRest convert(ClaimedTask obj, Projection projection) {
|
public ClaimedTaskRest convert(ClaimedTask obj, Projection projection) {
|
||||||
ClaimedTaskRest taskRest = new ClaimedTaskRest();
|
ClaimedTaskRest taskRest = new ClaimedTaskRest();
|
||||||
@@ -35,8 +39,7 @@ public class ClaimedTaskConverter
|
|||||||
XmlWorkflowItem witem = obj.getWorkflowItem();
|
XmlWorkflowItem witem = obj.getWorkflowItem();
|
||||||
taskRest.setId(obj.getID());
|
taskRest.setId(obj.getID());
|
||||||
taskRest.setWorkflowitem(converter.toRest(witem, projection));
|
taskRest.setWorkflowitem(converter.toRest(witem, projection));
|
||||||
taskRest.setAction(obj.getActionID());
|
taskRest.setAction(converter.toRest(xmlWorkflowFactory.getActionByName(obj.getActionID()), projection));
|
||||||
taskRest.setStep(obj.getStepID());
|
|
||||||
taskRest.setOwner(converter.toRest(obj.getOwner(), projection));
|
taskRest.setOwner(converter.toRest(obj.getOwner(), projection));
|
||||||
return taskRest;
|
return taskRest;
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,7 @@ import org.springframework.core.type.filter.AssignableTypeFilter;
|
|||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
import org.springframework.data.domain.PageImpl;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.hateoas.Link;
|
||||||
import org.springframework.hateoas.Resource;
|
import org.springframework.hateoas.Resource;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -155,9 +156,30 @@ public class ConverterService {
|
|||||||
* @throws ClassCastException if the resource type is not compatible with the inferred return type.
|
* @throws ClassCastException if the resource type is not compatible with the inferred return type.
|
||||||
*/
|
*/
|
||||||
public <T extends HALResource> T toResource(RestModel restObject) {
|
public <T extends HALResource> T toResource(RestModel restObject) {
|
||||||
|
return toResource(restObject, new Link[] {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the given rest object to a {@link HALResource} object.
|
||||||
|
* <p>
|
||||||
|
* If the rest object is a {@link RestAddressableModel}, the projection returned by
|
||||||
|
* {@link RestAddressableModel#getProjection()} will be used to determine which optional
|
||||||
|
* embeds and links will be added, and {@link Projection#transformResource(HALResource)}
|
||||||
|
* will be automatically called before returning the final, fully converted resource.
|
||||||
|
* </p><p>
|
||||||
|
* In all cases, the {@link HalLinkService} will be used immediately after the resource is constructed,
|
||||||
|
* to ensure all {@link HalLinkFactory}s have had a chance to add links as needed.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param restObject the input rest object.
|
||||||
|
* @param oldLinks The old links fo the Resource Object
|
||||||
|
* @param <T> the return type, a subclass of {@link HALResource}.
|
||||||
|
* @return the fully converted resource, with all automatic links and embeds applied.
|
||||||
|
*/
|
||||||
|
public <T extends HALResource> T toResource(RestModel restObject, Link... oldLinks) {
|
||||||
T halResource = getResource(restObject);
|
T halResource = getResource(restObject);
|
||||||
if (restObject instanceof RestAddressableModel) {
|
if (restObject instanceof RestAddressableModel) {
|
||||||
utils.embedOrLinkClassLevelRels(halResource);
|
utils.embedOrLinkClassLevelRels(halResource, oldLinks);
|
||||||
halLinkService.addLinks(halResource);
|
halLinkService.addLinks(halResource);
|
||||||
Projection projection = ((RestAddressableModel) restObject).getProjection();
|
Projection projection = ((RestAddressableModel) restObject).getProjection();
|
||||||
return projection.transformResource(halResource);
|
return projection.transformResource(halResource);
|
||||||
|
@@ -43,7 +43,6 @@ public class PoolTaskConverter
|
|||||||
taskRest.setGroup(converter.toRest(obj.getGroup(), projection));
|
taskRest.setGroup(converter.toRest(obj.getGroup(), projection));
|
||||||
}
|
}
|
||||||
taskRest.setAction(obj.getActionID());
|
taskRest.setAction(obj.getActionID());
|
||||||
taskRest.setStep(obj.getStepID());
|
|
||||||
return taskRest;
|
return taskRest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,12 +26,6 @@ public class ResourcePolicyConverter implements DSpaceConverter<ResourcePolicy,
|
|||||||
@Autowired
|
@Autowired
|
||||||
ResourcePolicyService resourcePolicyService;
|
ResourcePolicyService resourcePolicyService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
EPersonConverter epersonConverter;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
GroupConverter groupConverter;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ConverterService converterService;
|
ConverterService converterService;
|
||||||
|
|
||||||
@@ -53,13 +47,11 @@ public class ResourcePolicyConverter implements DSpaceConverter<ResourcePolicy,
|
|||||||
model.setEndDate(obj.getEndDate());
|
model.setEndDate(obj.getEndDate());
|
||||||
|
|
||||||
if (obj.getGroup() != null) {
|
if (obj.getGroup() != null) {
|
||||||
model.setGroupUUID(obj.getGroup().getID());
|
model.setGroup(converterService.toRest(obj.getGroup(), projection));
|
||||||
model.setGroup(groupConverter.convert(obj.getGroup(), projection));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.getEPerson() != null) {
|
if (obj.getEPerson() != null) {
|
||||||
model.setEpersonUUID(obj.getEPerson().getID());
|
model.setEperson(converterService.toRest(obj.getEPerson(), projection));
|
||||||
model.setEperson(epersonConverter.convert(obj.getEPerson(), projection));
|
|
||||||
}
|
}
|
||||||
if (obj.getdSpaceObject() != null) {
|
if (obj.getdSpaceObject() != null) {
|
||||||
model.setResource(converterService.toRest(obj.getdSpaceObject(), projection));
|
model.setResource(converterService.toRest(obj.getdSpaceObject(), projection));
|
||||||
|
@@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* 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 org.dspace.app.rest.model.WorkflowActionRest;
|
||||||
|
import org.dspace.app.rest.projection.Projection;
|
||||||
|
import org.dspace.xmlworkflow.state.actions.WorkflowActionConfig;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converter to translate {@link WorkflowActionConfig} to a {@link WorkflowActionRest} object
|
||||||
|
*
|
||||||
|
* @author Maria Verdonck (Atmire) on 06/01/2020
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class WorkflowActionConverter implements DSpaceConverter<WorkflowActionConfig, WorkflowActionRest> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorkflowActionRest convert(WorkflowActionConfig modelObject, Projection projection) {
|
||||||
|
WorkflowActionRest restModel = new WorkflowActionRest();
|
||||||
|
restModel.setProjection(projection);
|
||||||
|
restModel.setId(modelObject.getId());
|
||||||
|
restModel.setOptions(modelObject.getOptions());
|
||||||
|
return restModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<WorkflowActionConfig> getModelClass() {
|
||||||
|
return WorkflowActionConfig.class;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* 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.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.dspace.app.rest.model.WorkflowDefinitionRest;
|
||||||
|
import org.dspace.app.rest.model.WorkflowStepRest;
|
||||||
|
import org.dspace.app.rest.projection.Projection;
|
||||||
|
import org.dspace.xmlworkflow.factory.XmlWorkflowFactory;
|
||||||
|
import org.dspace.xmlworkflow.state.Workflow;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converter to translate Workflow to a Workflow Definition
|
||||||
|
*
|
||||||
|
* @author Maria Verdonck (Atmire) on 11/12/2019
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class WorkflowDefinitionConverter implements DSpaceConverter<Workflow, WorkflowDefinitionRest> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected XmlWorkflowFactory xmlWorkflowFactory;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ConverterService converter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorkflowDefinitionRest convert(Workflow modelObject, Projection projection) {
|
||||||
|
WorkflowDefinitionRest restModel = new WorkflowDefinitionRest();
|
||||||
|
restModel.setName(modelObject.getID());
|
||||||
|
restModel.setIsDefault(xmlWorkflowFactory.isDefaultWorkflow(modelObject.getID()));
|
||||||
|
restModel.setProjection(projection);
|
||||||
|
restModel.setSteps(modelObject.getSteps().stream()
|
||||||
|
.map(x -> (WorkflowStepRest) converter.toRest(x, projection))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
return restModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<Workflow> getModelClass() {
|
||||||
|
return Workflow.class;
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user