Skip to content

Commit

Permalink
10475-Cambios en back para cambiar de coleccion
Browse files Browse the repository at this point in the history
  • Loading branch information
GarrafaGalactica committed May 7, 2024
1 parent 190463f commit 7a4da89
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -821,13 +821,19 @@ public void createPoolTasks(Context context, XmlWorkflowItem wi, RoleMembers ass
@Override
public void createOwnedTask(Context context, XmlWorkflowItem wi, Step step, WorkflowActionConfig action, EPerson e)
throws SQLException, AuthorizeException {
ClaimedTask task = claimedTaskService.create(context);
task.setWorkflowItem(wi);
task.setStepID(step.getId());
task.setActionID(action.getId());
task.setOwner(e);
task.setWorkflowID(step.getWorkflow().getID());
claimedTaskService.update(context, task);
if (claimedTaskService.find(context, wi, step.getId()).size() > 0){
ClaimedTask ct = claimedTaskService.find(context, wi, step.getId()).get(0);
ct.setActionID(action.getId());
claimedTaskService.update(context, ct);
}else {
ClaimedTask task = claimedTaskService.create(context);
task.setWorkflowItem(wi);
task.setStepID(step.getId());
task.setActionID(action.getId());
task.setOwner(e);
task.setWorkflowID(step.getWorkflow().getID());
claimedTaskService.update(context, task);
}
//Make sure this user has a task
grantUserAllItemPolicies(context, wi.getItem(), e, ResourcePolicy.TYPE_WORKFLOW);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public List<String> getOptions() {
options.add(SUBMIT_REJECT);
options.add(ProcessingAction.SUBMIT_EDIT_METADATA);
options.add(RETURN_TO_POOL);
options.add("approve-and-select");
return options;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.dspace.xmlworkflow.state.actions.processingaction;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.UUID;



import javax.servlet.http.HttpServletRequest;

import org.apache.logging.log4j.Logger;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection;
import org.dspace.content.DSpaceObject;
import org.dspace.core.Context;
import org.dspace.workflow.WorkflowException;
import org.dspace.xmlworkflow.state.Step;
import org.dspace.xmlworkflow.state.actions.ActionResult;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService;
import org.dspace.content.service.CollectionService;
import org.dspace.content.factory.ContentServiceFactory;



/**
* Processing class of an action that allows users to
* select the collection to publish the item
*
*/

public class SelectCollection extends ProcessingAction {

private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(SelectCollection.class);


protected static CollectionService collectionService = ContentServiceFactory.getInstance()
.getCollectionService();


@Override
public void activate(Context c, XmlWorkflowItem wf)
throws SQLException, IOException, AuthorizeException, WorkflowException {
// TODO Auto-generated method stub

}

@Override
public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServletRequest request)throws SQLException, AuthorizeException, IOException, WorkflowException {
UUID uuid = UUID.fromString(request.getParameter("collection_id"));
collectionService = ContentServiceFactory.getInstance().getCollectionService();
if(request.getParameter("submit_selectCollection") != null){
Collection co = collectionService.find(c, uuid);
if (co != null) {
wfi.setCollection(co);
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
}
return new ActionResult(ActionResult.TYPE.TYPE_ERROR);
} else {
//We pressed the leave button so return to our submissions page
return new ActionResult(ActionResult.TYPE.TYPE_SUBMISSION_PAGE);
}
}

@Override
public List<String> getOptions() {
List<String> options = new ArrayList<>();
options.add("submit_selectCollection");
return options;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.dspace.xmlworkflow.state.Step;
import org.dspace.xmlworkflow.state.actions.ActionResult;
import org.dspace.xmlworkflow.state.actions.WorkflowActionConfig;
import org.dspace.xmlworkflow.storedcomponents.ClaimedTask;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
import org.springframework.beans.factory.annotation.Autowired;

Expand Down Expand Up @@ -110,7 +111,7 @@ public ActionResult execute(Context c, XmlWorkflowItem wfi, Step step, HttpServl
throw new IllegalStateException();
}
if (submitter != null) {
createTaskForEPerson(c, wfi, step, nextAction, submitter);
createOrUpdateTaskForEPerson(c, wfi, step, nextAction, submitter);
}
//It is important that we return to the submission page since we will continue our actions with the submitter
return new ActionResult(ActionResult.TYPE.TYPE_OUTCOME, ActionResult.OUTCOME_COMPLETE);
Expand Down Expand Up @@ -141,5 +142,17 @@ protected void createTaskForEPerson(Context c, XmlWorkflowItem wfi, Step step, W
.createOwnedTask(c, wfi, step, actionConfig, user);
}
}

protected void createOrUpdateTaskForEPerson(Context c, XmlWorkflowItem wfi, Step step, WorkflowActionConfig actionConfig,
EPerson user) throws SQLException, AuthorizeException, IOException {
List<ClaimedTask> ct = claimedTaskService.find(c, wfi, step.getId());
if (ct != null) {
ct.get(0).setActionID(actionConfig.getId());
} else {
workflowRequirementsService.addClaimedUser(c, wfi, step, user);
XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService()
.createOwnedTask(c, wfi, step, actionConfig, user);
}
}

}
8 changes: 8 additions & 0 deletions dspace/config/spring/api/workflow-actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
<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="collectionSelectionAPI" class="org.dspace.xmlworkflow.state.actions.processingaction.SelectCollection" scope="prototype"/>

<bean id="selectCollection" class="org.dspace.xmlworkflow.state.actions.WorkflowActionConfig" scope="prototype">
<constructor-arg type="java.lang.String" value="selectCollection"/>
<property name="processingAction" ref="collectionSelectionAPI"/>
<property name="requiresUI" value="true"/>
</bean>

<bean id="reviewaction" class="org.dspace.xmlworkflow.state.actions.WorkflowActionConfig" scope="prototype">
<constructor-arg type="java.lang.String" value="reviewaction"/>
Expand Down
20 changes: 19 additions & 1 deletion dspace/config/spring/api/workflow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,25 @@
</util:list>
</property>
</bean>

<bean class="org.dspace.xmlworkflow.state.Step" name="SEDICI-ADMIN_review_autoarchive">
<property name="userSelectionMethod" ref="claimaction"/>
<property name="role">
<bean class="org.dspace.xmlworkflow.Role" name="SeDiCIAdmin">
<property name="scope" value="#{ T(org.dspace.xmlworkflow.Role.Scope).REPOSITORY}"/>
<property name="name" value="SeDiCIAdmin"/>
<property name="description" value="Rol asigando para las personas encargadas de gestionar el repositorio, principalmente a partir de la carga."/>
</bean>
</property>
<property name="actions">
<util:list>
<ref bean="editaction"/>
<ref bean="selectCollection"/>
</util:list>
</property>
</bean>

<bean class="org.dspace.xmlworkflow.state.Step" name="SEDICI-ADMIN_select_collection_autoarchive">
<property name="userSelectionMethod" ref="claimaction"/>
<property name="role">
<bean class="org.dspace.xmlworkflow.Role" name="SeDiCIAdmin">
Expand All @@ -216,7 +234,7 @@
</property>
<property name="actions">
<list>
<ref bean="editaction"/>
<ref bean="selectCollection"/>
</list>
</property>
</bean>
Expand Down

0 comments on commit 7a4da89

Please sign in to comment.