Skip to content

Commit cfd36e8

Browse files
committed
changes from IQSS#11996 to enable workflows
1 parent faad3b1 commit cfd36e8

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ public enum Key {
177177
*/
178178
WorkflowsAdminIpWhitelist,
179179

180+
/**
181+
* Represents the workflow identifier for the "pre-publish dataset" operation.
182+
* This identifier is used to manage and define the specific workflow
183+
* triggered before a dataset is published within the application.
184+
*/
185+
PrePublishDatasetWorkflowId,
186+
/**
187+
* Represents the configuration key for specifying the workflow identifier that
188+
* will be executed after a dataset has been published.
189+
*/
190+
PostPublishDatasetWorkflowId,
191+
180192
/**
181193
* A special secret that, if set, needs to be given when trying to manage internal users.
182194
* This key was formerly known as "BuiltinUsers.KEY", which never was a setting name aligning with the others.

src/main/java/edu/harvard/iq/dataverse/workflow/WorkflowContext.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import edu.harvard.iq.dataverse.Dataset;
44
import edu.harvard.iq.dataverse.authorization.users.ApiToken;
55
import edu.harvard.iq.dataverse.engine.command.DataverseRequest;
6+
import edu.harvard.iq.dataverse.settings.SettingsServiceBean.Key;
67
import edu.harvard.iq.dataverse.workflow.step.WorkflowStep;
78

89
import java.util.Map;
@@ -20,7 +21,17 @@
2021
public class WorkflowContext {
2122

2223
public enum TriggerType {
23-
PrePublishDataset, PostPublishDataset
24+
PrePublishDataset(Key.PrePublishDatasetWorkflowId),
25+
PostPublishDataset(Key.PostPublishDatasetWorkflowId);
26+
27+
final Key key;
28+
TriggerType(Key key) {
29+
this.key = key;
30+
}
31+
32+
Key getKey() {
33+
return key;
34+
}
2435
}
2536

2637
private final DataverseRequest request;

src/main/java/edu/harvard/iq/dataverse/workflow/WorkflowServiceBean.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
public class WorkflowServiceBean {
5454

5555
private static final Logger logger = Logger.getLogger(WorkflowServiceBean.class.getName());
56-
private static final String WORKFLOW_ID_KEY = "WorkflowServiceBean.WorkflowId:";
5756

5857
@PersistenceContext(unitName = "VDCNet-ejbPU")
5958
EntityManager em;
@@ -452,7 +451,7 @@ public boolean deleteWorkflow(long workflowId) {
452451
if (doomedOpt.isPresent()) {
453452
// validate that this is not the default workflow
454453
for ( WorkflowContext.TriggerType tp : WorkflowContext.TriggerType.values() ) {
455-
String defaultWorkflowId = settings.get(workflowSettingKey(tp));
454+
String defaultWorkflowId = settings.getValueForKey(tp.getKey());
456455
if (defaultWorkflowId != null
457456
&& Long.parseLong(defaultWorkflowId) == doomedOpt.get().getId()) {
458457
throw new IllegalArgumentException("Workflow " + workflowId + " cannot be deleted as it is the default workflow for trigger " + tp.name() );
@@ -476,7 +475,7 @@ public PendingWorkflowInvocation getPendingWorkflow(String invocationId) {
476475
}
477476

478477
public Optional<Workflow> getDefaultWorkflow( WorkflowContext.TriggerType type ) {
479-
String defaultWorkflowId = settings.get(workflowSettingKey(type));
478+
String defaultWorkflowId = settings.getValueForKey(type.getKey());
480479
if (defaultWorkflowId == null) {
481480
return Optional.empty();
482481
}
@@ -491,18 +490,13 @@ public Optional<Workflow> getDefaultWorkflow( WorkflowContext.TriggerType type )
491490
* @param type type of the workflow.
492491
*/
493492
public void setDefaultWorkflowId(WorkflowContext.TriggerType type, Long id) {
494-
String workflowKey = workflowSettingKey(type);
495493
if (id == null) {
496-
settings.delete(workflowKey);
494+
settings.deleteValueForKey(type.getKey());
497495
} else {
498-
settings.set(workflowKey, id.toString());
496+
settings.setValueForKey(type.getKey(), id.toString());
499497
}
500498
}
501499

502-
private String workflowSettingKey(WorkflowContext.TriggerType type) {
503-
return WORKFLOW_ID_KEY+type.name();
504-
}
505-
506500
private WorkflowStep createStep(WorkflowStepData wsd) {
507501
WorkflowStepSPI provider = providers.get(wsd.getProviderId());
508502
if (provider == null) {

0 commit comments

Comments
 (0)