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 |
|
package info.magnolia.content.observer; |
35 |
|
|
36 |
|
import info.magnolia.dirwatch.DirectoryWatcherService; |
37 |
|
import info.magnolia.init.MagnoliaConfigurationProperties; |
38 |
|
import info.magnolia.module.ModuleLifecycle; |
39 |
|
import info.magnolia.module.ModuleLifecycleContext; |
40 |
|
|
41 |
|
import java.io.IOException; |
42 |
|
import java.nio.file.Path; |
43 |
|
import java.nio.file.Paths; |
44 |
|
|
45 |
|
import javax.inject.Inject; |
46 |
|
|
47 |
|
import org.apache.commons.lang3.StringUtils; |
48 |
|
import org.slf4j.Logger; |
49 |
|
import org.slf4j.LoggerFactory; |
50 |
|
|
51 |
|
import com.google.common.base.Predicate; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
@link |
57 |
|
|
58 |
|
|
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 5 |
Complexity Density: 0.5 |
|
60 |
|
public class ContentImporterModule implements ModuleLifecycle { |
61 |
|
|
62 |
|
private static final Logger log = LoggerFactory.getLogger(ContentImporterModule.class); |
63 |
|
|
64 |
|
private static final String CONTENT_BOOTSTRAP_DIR_PROPERTY_KEY = "magnolia.content.bootstrap.dir"; |
65 |
|
|
66 |
|
private final String rootPath; |
67 |
|
private final DirectoryWatcherService directoryWatcherService; |
68 |
|
private final TaskCreatorWatcherCallback taskCreatorCallback; |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
70 |
5 |
@Inject... |
71 |
|
public ContentImporterModule(MagnoliaConfigurationProperties properties, |
72 |
|
DirectoryWatcherService directoryWatcherService, |
73 |
|
TaskCreatorWatcherCallback taskCreatorCallback) { |
74 |
5 |
this.rootPath = properties.getProperty(CONTENT_BOOTSTRAP_DIR_PROPERTY_KEY); |
75 |
5 |
this.directoryWatcherService = directoryWatcherService; |
76 |
5 |
this.taskCreatorCallback = taskCreatorCallback; |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
79 |
3 |
@Override... |
80 |
|
public void start(ModuleLifecycleContext moduleLifecycleContext) { |
81 |
3 |
if (StringUtils.isNotBlank(rootPath)) { |
82 |
2 |
try { |
83 |
2 |
Path path = Paths.get(rootPath); |
84 |
2 |
log.info("Starting Content Importer module. Watching directory '{}' for files to import.", path); |
85 |
2 |
directoryWatcherService.register(path, new AlwaysTruePredicate(), taskCreatorCallback); |
86 |
|
} catch (IOException e) { |
87 |
1 |
throw new RuntimeException("Could not start observation of content bootstrap files", e); |
88 |
|
} |
89 |
|
} else { |
90 |
1 |
log.info("Content bootstrap directory is not defined with property of '{}' in magnolia.properties file, " + |
91 |
|
"therefore observation is not started.", CONTENT_BOOTSTRAP_DIR_PROPERTY_KEY); |
92 |
|
} |
93 |
|
} |
94 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
95 |
1 |
@Override... |
96 |
|
public void stop(ModuleLifecycleContext moduleLifecycleContext) { |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
@link |
101 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
|
private static class AlwaysTruePredicate implements Predicate<Path> { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
0 |
@Override... |
104 |
|
public boolean apply(Path ignored) { |
105 |
0 |
return true; |
106 |
|
} |
107 |
|
} |
108 |
|
} |