2222import java .util .Map ;
2323import java .util .stream .Collectors ;
2424
25- import static java .util .Arrays .stream ;
2625import static org .apache .commons .lang3 .Validate .notNull ;
2726import static org .slf4j .LoggerFactory .getLogger ;
2827
@@ -44,10 +43,6 @@ public DetectIssueRoute(RocketChatConfiguration config, IssueRestClient issueCli
4443 this .jiraKeyParser = notNull (jiraKeyParser );
4544 }
4645
47- private static boolean isAllowed (Collection <String > blacklist , Collection <String > whitelist , String ... values ) {
48- return stream (values ).allMatch ((value ) -> isAllowed (blacklist , whitelist , value ));
49- }
50-
5146 private static boolean isAllowed (Collection <String > blacklist , Collection <String > whitelist , String value ) {
5247 return !blacklist .contains (value ) && (whitelist .isEmpty () || whitelist .contains (value ));
5348 }
@@ -56,23 +51,33 @@ private static boolean isNotFound(com.google.common.base.Optional<Integer> statu
5651 return statusCode .isPresent () && statusCode .get () == HttpStatus .NOT_FOUND_404 ;
5752 }
5853
54+ private Issue getJiraIssue (String jiraKey ) {
55+ Promise <Issue > issuePromise = issueClient .getIssue (jiraKey );
56+ try {
57+ return issuePromise .claim ();
58+ } catch (RestClientException e ) {
59+ if (isNotFound (e .getStatusCode ())) {
60+ return null ;
61+ }
62+ throw e ;
63+ }
64+ }
65+
5966 @ Override
6067 protected ToRocketChatMessage handle (Request request , Response response , FromRocketChatMessage fromRocketChatMessage ) throws Exception {
6168 String token = fromRocketChatMessage .getToken ();
6269 if (!config .getTokens ().isEmpty () && !config .getTokens ().contains (token )) {
6370 log .info ("Forbidden token encountered: {}. Ignoring" , token );
6471 return null ;
6572 }
66- String userId = fromRocketChatMessage .getUserId ();
6773 String userName = fromRocketChatMessage .getUserName ();
68- if (!isAllowed (config .getBlacklistedUsers (), config .getWhitelistedUsers (), userId , userName )) {
69- log .info ("Forbidden user encountered. ID : {}, Name: {} . Ignoring" , userId , userName );
74+ if (!isAllowed (config .getBlacklistedUsers (), config .getWhitelistedUsers (), userName )) {
75+ log .info ("Forbidden user encountered: {}. Ignoring" , userName );
7076 return null ;
7177 }
72- String channelId = fromRocketChatMessage .getChannelId ();
7378 String channelName = fromRocketChatMessage .getChannelName ();
74- if (!isAllowed (config .getBlacklistedChannels (), config .getWhitelistedChannels (), channelId , channelName )) {
75- log .info ("Forbidden channel encountered. ID : {}, Name: {} . Ignoring" , channelId , channelName );
79+ if (!isAllowed (config .getBlacklistedChannels (), config .getWhitelistedChannels (), channelName )) {
80+ log .info ("Forbidden channel encountered: {}. Ignoring" , channelName );
7681 return null ;
7782 }
7883 log .info ("Message is being processed..." );
@@ -103,17 +108,4 @@ protected ToRocketChatMessage handle(Request request, Response response, FromRoc
103108 message .setAttachments (attachments );
104109 return message ;
105110 }
106-
107- private Issue getJiraIssue (String jiraKey ) {
108- Promise <Issue > issuePromise = issueClient .getIssue (jiraKey );
109- try {
110- return issuePromise .claim ();
111- } catch (RestClientException e ) {
112- if (isNotFound (e .getStatusCode ())) {
113- return null ;
114- }
115- throw e ;
116- }
117- }
118-
119111}
0 commit comments