forked from box/mojito
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated properties to extract scheduler name from property name
- Loading branch information
Showing
4 changed files
with
63 additions
and
32 deletions.
There are no files selected for viewing
22 changes: 0 additions & 22 deletions
22
webapp/src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfig.java
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
.../src/main/java/com/box/l10n/mojito/quartz/multi/QuartzMultiSchedulerConfigProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.box.l10n.mojito.quartz.multi; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import javax.annotation.PostConstruct; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ConfigurationProperties("l10n.org.multi-quartz") | ||
@ConditionalOnProperty(name = "l10n.org.multi-quartz.enabled", havingValue = "true") | ||
public class QuartzMultiSchedulerConfigProperties { | ||
|
||
Map<String, String> scheduler; | ||
|
||
List<SchedulerConfig> schedulerConfigs = new ArrayList<>(); | ||
|
||
public Map<String, String> getScheduler() { | ||
return scheduler; | ||
} | ||
|
||
public void setScheduler(Map<String, String> scheduler) { | ||
this.scheduler = scheduler; | ||
} | ||
|
||
public List<SchedulerConfig> getSchedulerConfigs() { | ||
return schedulerConfigs; | ||
} | ||
|
||
@PostConstruct | ||
public void init() { | ||
schedulerConfigs.addAll(extractSchedulerConfigs()); | ||
} | ||
|
||
private Collection<SchedulerConfig> extractSchedulerConfigs() { | ||
Map<String, SchedulerConfig> configs = new HashMap<>(); | ||
|
||
for (Map.Entry<String, String> entry : scheduler.entrySet()) { | ||
String schedulerName = entry.getKey().substring(0, entry.getKey().indexOf(".")); | ||
SchedulerConfig schedulerConfig = configs.getOrDefault(schedulerName, new SchedulerConfig()); | ||
schedulerConfig.setName(schedulerName); | ||
if (schedulerConfig.getQuartz() == null) { | ||
schedulerConfig.setQuartz(new HashMap<>()); | ||
} | ||
String propertyName = entry.getKey().substring(entry.getKey().indexOf(".") + 1); | ||
schedulerConfig | ||
.getQuartz() | ||
.put( | ||
propertyName.startsWith("quartz.") | ||
? propertyName.substring(propertyName.indexOf(".") + 1) | ||
: propertyName, | ||
entry.getValue()); | ||
configs.put(schedulerName, schedulerConfig); | ||
} | ||
return configs.values(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters