1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.opencastproject.workflow.handler.distribution;
22
23 import static org.opencastproject.util.RequireUtil.notNull;
24
25 import org.opencastproject.distribution.api.DownloadDistributionService;
26 import org.opencastproject.distribution.api.StreamingDistributionService;
27 import org.opencastproject.job.api.JobContext;
28 import org.opencastproject.mediapackage.MediaPackage;
29 import org.opencastproject.serviceregistry.api.ServiceRegistry;
30 import org.opencastproject.workflow.api.WorkflowInstance;
31 import org.opencastproject.workflow.api.WorkflowOperationException;
32 import org.opencastproject.workflow.api.WorkflowOperationHandler;
33 import org.opencastproject.workflow.api.WorkflowOperationInstance;
34 import org.opencastproject.workflow.api.WorkflowOperationResult;
35 import org.opencastproject.workflow.api.WorkflowOperationResult.Action;
36
37 import org.apache.commons.lang3.BooleanUtils;
38 import org.apache.commons.lang3.StringUtils;
39 import org.osgi.service.component.annotations.Component;
40 import org.osgi.service.component.annotations.Reference;
41
42
43
44
45
46 @Component(
47 immediate = true,
48 service = WorkflowOperationHandler.class,
49 property = {
50 "service.description=Configurable Retraction Workflow Handler",
51 "workflow.operation=retract-configure"
52 }
53 )
54 public class ConfigurableRetractWorkflowOperationHandler extends ConfigurableWorkflowOperationHandlerBase {
55
56 private static final String CHANNEL_ID_KEY = "channel-id";
57
58 static final String RETRACT_STREAMING = "retract-streaming";
59 static final boolean RETRACT_STREAMING_DEFAULT = false;
60
61
62 private DownloadDistributionService downloadDistributionService;
63 private StreamingDistributionService streamingDistributionService;
64
65
66 @Reference(target = "(distribution.channel=download)")
67 void setDownloadDistributionService(DownloadDistributionService distributionService) {
68 this.downloadDistributionService = distributionService;
69 }
70
71 @Reference(target = "(distribution.channel=streaming)")
72 void setStreamingDistributionService(StreamingDistributionService distributionService) {
73 this.streamingDistributionService = distributionService;
74 }
75
76 @Override
77 protected DownloadDistributionService getDownloadDistributionService() {
78 assert (downloadDistributionService != null);
79 return downloadDistributionService;
80 }
81
82 @Override
83 protected StreamingDistributionService getStreamingDistributionService() {
84 assert (streamingDistributionService != null);
85 return streamingDistributionService;
86 }
87
88 @Override
89 public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context)
90 throws WorkflowOperationException {
91 notNull(workflowInstance, "workflowInstance");
92
93 boolean retractStreaming = RETRACT_STREAMING_DEFAULT;
94 final WorkflowOperationInstance op = workflowInstance.getCurrentOperation();
95 String retractStreamingString = op.getConfiguration(RETRACT_STREAMING);
96 if (retractStreamingString != null) {
97 retractStreaming = BooleanUtils.toBoolean(StringUtils.trimToEmpty(retractStreamingString));
98 }
99
100 final MediaPackage mp = workflowInstance.getMediaPackage();
101 final String channelId = StringUtils.trimToEmpty(workflowInstance.getCurrentOperation().getConfiguration(
102 CHANNEL_ID_KEY));
103 if (StringUtils.isBlank((channelId))) {
104 throw new WorkflowOperationException("Unable to retract this mediapackage as the configuration key "
105 + CHANNEL_ID_KEY + " is missing. Unable to determine from where to retract these elements.");
106 }
107
108 retract(mp, channelId, retractStreaming);
109
110 return createResult(mp, Action.CONTINUE);
111 }
112
113 @Reference
114 @Override
115 public void setServiceRegistry(ServiceRegistry serviceRegistry) {
116 super.setServiceRegistry(serviceRegistry);
117 }
118
119 }