Make workflow curation tasks actually work.

When curation runs, there was no "current user" and no claimed task,
so the code broke when trying to find people to notify about curation
failures.
This commit is contained in:
Mark H. Wood
2023-08-01 17:13:07 -04:00
parent 7f9ec2eb1e
commit a76af35a0c
3 changed files with 52 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection; import org.dspace.content.Collection;
@@ -47,14 +48,17 @@ import org.springframework.stereotype.Service;
* Manage interactions between curation and workflow. A curation task can be * Manage interactions between curation and workflow. A curation task can be
* attached to a workflow step, to be executed during the step. * attached to a workflow step, to be executed during the step.
* *
* <p>
* <strong>NOTE:</strong> when run in workflow, curation tasks <em>run with
* authorization disabled</em>.
*
* @see CurationTaskConfig * @see CurationTaskConfig
* @author mwood * @author mwood
*/ */
@Service @Service
public class XmlWorkflowCuratorServiceImpl public class XmlWorkflowCuratorServiceImpl
implements XmlWorkflowCuratorService { implements XmlWorkflowCuratorService {
private static final Logger LOG private static final Logger LOG = LogManager.getLogger();
= org.apache.logging.log4j.LogManager.getLogger();
@Autowired(required = true) @Autowired(required = true)
protected XmlWorkflowFactory workflowFactory; protected XmlWorkflowFactory workflowFactory;
@@ -97,7 +101,13 @@ public class XmlWorkflowCuratorServiceImpl
throws AuthorizeException, IOException, SQLException { throws AuthorizeException, IOException, SQLException {
Curator curator = new Curator(); Curator curator = new Curator();
curator.setReporter(reporter); curator.setReporter(reporter);
return curate(curator, c, wfi); c.turnOffAuthorisationSystem();
if (null == c.getCurrentUser()) { // We need someone to email
c.setCurrentUser(ePersonService.findAnAdministrator(c));
}
boolean failedP = curate(curator, c, wfi);
c.restoreAuthSystemState();
return failedP;
} }
@Override @Override
@@ -123,7 +133,7 @@ public class XmlWorkflowCuratorServiceImpl
item.setOwningCollection(wfi.getCollection()); item.setOwningCollection(wfi.getCollection());
for (Task task : step.tasks) { for (Task task : step.tasks) {
curator.addTask(task.name); curator.addTask(task.name);
curator.curate(item); curator.curate(c, item);
int status = curator.getStatus(task.name); int status = curator.getStatus(task.name);
String result = curator.getResult(task.name); String result = curator.getResult(task.name);
String action = "none"; String action = "none";
@@ -223,8 +233,12 @@ public class XmlWorkflowCuratorServiceImpl
String status, String action, String message) String status, String action, String message)
throws AuthorizeException, IOException, SQLException { throws AuthorizeException, IOException, SQLException {
List<EPerson> epa = resolveContacts(c, task.getContacts(status), wfi); List<EPerson> epa = resolveContacts(c, task.getContacts(status), wfi);
if (epa.size() > 0) { if (!epa.isEmpty()) {
workflowService.notifyOfCuration(c, wfi, epa, task.name, action, message); workflowService.notifyOfCuration(c, wfi, epa, task.name, action, message);
} else {
LOG.warn("No contacts were found for workflow item {}: "
+ "task {} returned action {} with message {}",
wfi.getID(), task.name, action, message);
} }
} }
@@ -247,8 +261,7 @@ public class XmlWorkflowCuratorServiceImpl
// decode contacts // decode contacts
if ("$flowgroup".equals(contact)) { if ("$flowgroup".equals(contact)) {
// special literal for current flowgoup // special literal for current flowgoup
ClaimedTask claimedTask = claimedTaskService.findByWorkflowIdAndEPerson(c, wfi, c.getCurrentUser()); String stepID = getFlowStep(c, wfi).step;
String stepID = claimedTask.getStepID();
Step step; Step step;
try { try {
Workflow workflow = workflowFactory.getWorkflow(wfi.getCollection()); Workflow workflow = workflowFactory.getWorkflow(wfi.getCollection());
@@ -266,11 +279,13 @@ public class XmlWorkflowCuratorServiceImpl
epList.addAll(group.getMembers()); epList.addAll(group.getMembers());
} }
} else if ("$colladmin".equals(contact)) { } else if ("$colladmin".equals(contact)) {
// special literal for collection administrators
Group adGroup = wfi.getCollection().getAdministrators(); Group adGroup = wfi.getCollection().getAdministrators();
if (adGroup != null) { if (adGroup != null) {
epList.addAll(groupService.allMembers(c, adGroup)); epList.addAll(groupService.allMembers(c, adGroup));
} }
} else if ("$siteadmin".equals(contact)) { } else if ("$siteadmin".equals(contact)) {
// special literal for site administrator
EPerson siteEp = ePersonService.findByEmail(c, EPerson siteEp = ePersonService.findByEmail(c,
configurationService.getProperty("mail.admin")); configurationService.getProperty("mail.admin"));
if (siteEp != null) { if (siteEp != null) {

View File

@@ -47,6 +47,7 @@ import org.dspace.eperson.service.GroupService;
import org.dspace.eperson.service.SubscribeService; import org.dspace.eperson.service.SubscribeService;
import org.dspace.event.Event; import org.dspace.event.Event;
import org.dspace.orcid.service.OrcidTokenService; import org.dspace.orcid.service.OrcidTokenService;
import org.dspace.services.ConfigurationService;
import org.dspace.util.UUIDUtils; import org.dspace.util.UUIDUtils;
import org.dspace.versioning.Version; import org.dspace.versioning.Version;
import org.dspace.versioning.VersionHistory; import org.dspace.versioning.VersionHistory;
@@ -101,6 +102,8 @@ public class EPersonServiceImpl extends DSpaceObjectServiceImpl<EPerson> impleme
protected VersionDAO versionDAO; protected VersionDAO versionDAO;
@Autowired(required = true) @Autowired(required = true)
protected ClaimedTaskService claimedTaskService; protected ClaimedTaskService claimedTaskService;
@Autowired(required = true)
protected ConfigurationService configurationService;
@Autowired @Autowired
protected OrcidTokenService orcidTokenService; protected OrcidTokenService orcidTokenService;
@@ -113,6 +116,21 @@ public class EPersonServiceImpl extends DSpaceObjectServiceImpl<EPerson> impleme
return ePersonDAO.findByID(context, EPerson.class, id); return ePersonDAO.findByID(context, EPerson.class, id);
} }
@Override
public EPerson findAnAdministrator(Context c)
throws SQLException {
List<EPerson> contacts = groupService.findByName(c, Group.ADMIN).getMembers();
EPerson currentUser;
if (contacts.isEmpty()) {
log.warn("Administrators group is empty");
currentUser = findByEmail(c, configurationService.getProperty("mail.admin"));
// Null if no such EPerson
} else {
currentUser = contacts.get(0);
}
return currentUser;
}
@Override @Override
public EPerson findByIdOrLegacyId(Context context, String id) throws SQLException { public EPerson findByIdOrLegacyId(Context context, String id) throws SQLException {
if (StringUtils.isNumeric(id)) { if (StringUtils.isNumeric(id)) {

View File

@@ -157,6 +157,18 @@ public interface EPersonService extends DSpaceObjectService<EPerson>, DSpaceObje
public List<EPerson> findAll(Context context, int sortField, int pageSize, int offset) public List<EPerson> findAll(Context context, int sortField, int pageSize, int offset)
throws SQLException; throws SQLException;
/**
* Try very hard to find an administrator's account. Might return a member
* of the Administrators group, or an account with a configured email
* address.
*
* @param context current DSpace session.
* @return a presumed administrator account, or null if none could be found.
* @throws SQLException
*/
public EPerson findAnAdministrator(Context context)
throws SQLException;
/** /**
* Create a new eperson * Create a new eperson
* *