-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathJobFactory.java
205 lines (183 loc) · 6.95 KB
/
JobFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - [email protected]
*/
package sirius.biz.jobs;
import com.fasterxml.jackson.databind.JsonNode;
import sirius.biz.jobs.infos.JobInfo;
import sirius.biz.jobs.params.Parameter;
import sirius.kernel.commons.Value;
import sirius.kernel.di.std.AutoRegister;
import sirius.kernel.di.std.Named;
import sirius.kernel.di.std.Priorized;
import sirius.kernel.health.HandledException;
import sirius.web.http.WebContext;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;
/**
* Represents a job which can be executed either by the user (via the UI), via a HTTP call or by the system itself (e.g. a scheduler).
* <p>
* Note that a job (factory) only exists once and has to be stateless.
* <p>
* Also note, that an implementation should most probably subclass {@link BasicJobFactory} as it performs all the
* heavy lifting.
*/
@AutoRegister
public interface JobFactory extends Named, Priorized {
/**
* Returns the label to show for this job.
*
* @return the label (translated name) of this job
*/
String getLabel();
/**
* Returns the icon to used when displaying this job.
* <p>
* This is actually the css class to use (e.g. to apply a Fontawesome icon).
*
* @return the icon of this job
*/
String getIcon();
/**
* Returns a short description of this job.
* <p>
* This is shown in lists and should therefore be quite concise.
*
* @return the description for this job
*/
@Nullable
String getDescription();
/**
* Returns a short description of the job which may contain HTML markup.
* <p>
* If present, this will replace {@link #getDescription()} when rendering the details
* page.
*
* @return the description for this job which might contain HTML markup
*/
@Nullable
String getHTMLDescription();
/**
* Returns a detailed description of this job.
* <p>
* This description is shown in the documentation page of the job and might be more elaborated.
*
* @return the detailed description for this job
*/
@Nullable
String getDetailDescription();
/**
* Provides a detailed documentation of what the job does, which data it expects etc.
*
* @return a list of documentation sections for the job
*/
List<JobInfo> getJobInfos();
/**
* Determines if the job is accessible by the current user.
* <p>
* The default implementation evaluates all {@link sirius.web.security.Permission} annotations present on
* the class-level.
*
* @return <tt>true</tt> if the current user can access a job, <tt>false</tt> otherwise
*/
boolean isAccessibleToCurrentUser();
/**
* Returns the parameters accepted by this job.
*
* @return the list of parameters of this job
*/
List<Parameter<?>> getParameters();
/**
* Determines if there are visible parameters in this job.
*
* @param context web context
* @return <tt>true</tt> if visible parameters found, otherwise <tt>false</tt>
*/
boolean hasVisibleParameters(Map<String, String> context);
/**
* Generates a URL which can be invoked to start this job while using the given object as a parameter value.
* <p>
* This is used by the <tt>t:jobs</tt> tag to display appropriate jobs next to a data object.
*
* @param uri the uri of the current page (which contains the <tt>t:jobs</tt> tag
* @param targetObject the optional target object which is being shown / processed / edited by the page
* @return an url which starts the launch screen for this job while using the given parameter as value or
* <tt>null</tt> to indicate that this jobs cannot be started in the ui or that the given object isn't an
* appropriate parameter.
*/
@Nullable
String generatePresetUrl(@Nonnull String uri, @Nullable Object targetObject);
/**
* Determines if this job can be started in the UI.
*
* @return <tt>true</tt> if this job can be started in the ui
*/
boolean canStartInteractive();
/**
* Starts this job by responding to the given request.
* <p>
* Note that the job itself has to enforce its {@link #getRequiredPermissions()}.
*
* @param request the request to respond to
*/
void startInteractively(WebContext request);
/**
* Determines if this job can be started in the background.
*
* @return <tt>true</tt> if an execution in the background is possible, <tt>false</tt> otherwise
*/
boolean canStartInBackground();
/**
* Starts this job in the background.
* <p>
* Note that the job itself has to enforce its {@link #getRequiredPermissions()}.
*
* @param parameterProvider the parameters provided to the job
* @return the id of the {@link sirius.biz.process.Process} which has been started to cover the execution or
* <tt>null</tt> if no process was used.
*/
@Nullable
String startInBackground(Function<String, Value> parameterProvider);
/**
* Builds a context using values from the given <tt>parameterProvider</tt> and the
* {@link #getParameters() parameters} specified by this job.
*
* @param parameterProvider used to provide parameter values
* @param enforceRequiredParameters determines if required parameters should be enforced
* @param errorConsumer will be supplied with detected errors
* @return all provided parameters wrapped as context
*/
Map<String, String> buildAndVerifyContext(Function<String, Value> parameterProvider,
boolean enforceRequiredParameters,
BiConsumer<Parameter<?>, HandledException> errorConsumer);
/**
* Returns the name of the <tt>category</tt> this job belongs to.
* <p>
* Within sirius, one of {@link StandardCategories} should be picked. For products a similar set of constants
* should probably exist.
*
* @return the name of the job category
*/
String getCategory();
/**
* Computes a JsonNode containing the required update operations for the JavaScript frontend.
*
* @param webContext the web context containing the values of all the parameters
* @return a JsonNode that can be handled by the JavaScript
*/
JsonNode computeRequiredParameterUpdates(WebContext webContext);
/**
* Computes a JsonNode containing the required update operations for the JavaScript frontend.
*
* @param ctx the context containing the values of all the parameters
* @return a JsonNode that can be handled by the JavaScript
*/
JsonNode computeRequiredParameterUpdates(Map<String, String> ctx);
}