| Total Complexity | 4 |
| Total Lines | 24 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | package com.github.netkorp.telegram.framework.condition; |
||
| 14 | @Component |
||
| 15 | public class ExcludeCondition implements Condition { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Determine if the condition matches. |
||
| 19 | * |
||
| 20 | * @param context the condition context |
||
| 21 | * @param metadata metadata of the {@link AnnotationMetadata class} |
||
| 22 | * or {@link MethodMetadata method} being checked |
||
| 23 | * @return {@code true} if the condition matches and the component can be registered, |
||
| 24 | * or {@code false} to veto the annotated component's registration |
||
| 25 | */ |
||
| 26 | @Override |
||
| 27 | public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { |
||
| 28 | String excludeValue = context.getEnvironment().getProperty("telegram.commands.exclude"); |
||
| 29 | if (excludeValue != null && context.getBeanFactory() != null) { |
||
| 30 | Map<String, Object> attributes = metadata.getAnnotationAttributes(TelegramCommand.class.getName()); |
||
| 31 | if (attributes != null) { |
||
| 32 | String commandName = (String) attributes.get("name"); |
||
| 33 | return !Arrays.asList(excludeValue.split(",")).contains(commandName); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | return true; |
||
| 38 | } |
||
| 40 |