forked from alfio-event/alf.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use conditional annotation for ioc location manager alfio-event#127
- Loading branch information
1 parent
9930d24
commit 6a909bd
Showing
4 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/main/java/alfio/config/support/ConditionalOnConfigurationPresentProperty.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,20 @@ | ||
package alfio.config.support; | ||
|
||
import alfio.model.system.ConfigurationKeys; | ||
import org.springframework.context.annotation.Conditional; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Created by andrew on 7/10/16. | ||
*/ | ||
@Target({ ElementType.TYPE, ElementType.METHOD }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Conditional(OnConfigurationPresentCondition.class) | ||
public @interface ConditionalOnConfigurationPresentProperty { | ||
public ConfigurationKeys value(); | ||
public boolean exists() default true; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/alfio/config/support/OnConfigurationPresentCondition.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,32 @@ | ||
package alfio.config.support; | ||
|
||
import alfio.manager.system.ConfigurationManager; | ||
import alfio.model.system.Configuration; | ||
import alfio.model.system.ConfigurationKeys; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Condition; | ||
import org.springframework.context.annotation.ConditionContext; | ||
import org.springframework.core.type.AnnotatedTypeMetadata; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Created by andrew on 7/10/16. | ||
*/ | ||
public class OnConfigurationPresentCondition implements Condition { | ||
|
||
@Autowired | ||
private ConfigurationManager configurationManager; | ||
|
||
@Override | ||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { | ||
Map<String, Object> attributes = | ||
metadata.getAnnotationAttributes(ConditionalOnConfigurationPresentProperty.class.getName()); | ||
|
||
Configuration.ConfigurationPathKey key = Configuration.getSystemConfiguration( | ||
(ConfigurationKeys) attributes.get("value")); | ||
boolean configPropExistsCheck = (Boolean) attributes.get("exists"); | ||
|
||
return configPropExistsCheck ^ configurationManager.getStringConfigValue(key).isPresent(); | ||
} | ||
} |
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
6a909bd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: this doesn't actually work!!! Autowired does not work in the definition of the conditional. I'll change the implementation to mirror the structure of the Mailer system.