-
Notifications
You must be signed in to change notification settings - Fork 7
/
JobsSearchProvider.java
60 lines (50 loc) · 1.52 KB
/
JobsSearchProvider.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
/*
* 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 sirius.biz.tycho.search.OpenSearchProvider;
import sirius.biz.tycho.search.OpenSearchResult;
import sirius.kernel.di.std.Part;
import sirius.kernel.di.std.Register;
import sirius.kernel.nls.NLS;
import javax.annotation.Nullable;
import java.util.function.Consumer;
/**
* Makes {@link JobFactory jobs} visible to the {@link sirius.biz.tycho.search.OpenSearchController}.
*/
@Register(framework = Jobs.FRAMEWORK_JOBS)
public class JobsSearchProvider implements OpenSearchProvider {
@Part
private Jobs jobs;
@Override
public String getLabel() {
return NLS.get("JobFactory.plural");
}
@Nullable
@Override
public String getUrl() {
return "/jobs";
}
@Override
public boolean ensureAccess() {
return true;
}
@Override
public void query(String query, int maxResults, Consumer<OpenSearchResult> resultCollector) {
jobs.getAvailableJobs(query).filter(JobFactory::canStartInteractive).forEach(jobFactory -> {
OpenSearchResult result = new OpenSearchResult();
result.withLabel(jobFactory.getLabel())
.withDescription(jobFactory.getDescription())
.withURL("/job/" + jobFactory.getName());
resultCollector.accept(result);
});
}
@Override
public int getPriority() {
return 10;
}
}