-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add AOP dependency and initial Notification Service trial * Add AOP dependency and initial Notification Service trial * add slacknotification service that notifies the lanciedev channel of ticket payments and transfers * change slack notification service to slack notification Aspect * Update src/main/java/ch/wisv/areafiftylan/exception/SlackNotificationException.java Co-Authored-By: Martijn Janssen <[email protected]> * remove slacknotificationexception from aspect execution * disable slack notifications during testing * change slacknotification profile to production * Add conditional annotation for environment value used with slack * remove whitespace * remove unnecessary properties in condition on property Co-authored-by: Martijn Janssen <[email protected]>
- Loading branch information
1 parent
461d821
commit 1b95bb3
Showing
6 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
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
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,3 @@ | ||
# This file is generated by the 'io.freefair.lombok' Gradle plugin | ||
config.stopBubbling = true | ||
lombok.addLombokGeneratedAnnotation = true |
27 changes: 27 additions & 0 deletions
27
src/main/java/ch/wisv/areafiftylan/exception/SlackNotificationException.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,27 @@ | ||
/* | ||
* Copyright (c) 2018 W.I.S.V. 'Christiaan Huygens' | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package ch.wisv.areafiftylan.exception; | ||
|
||
|
||
import java.io.IOException; | ||
|
||
public class SlackNotificationException extends AreaFiftyLANException { | ||
public SlackNotificationException(IOException e) { | ||
super("Unable to send a notification to slack:" + e.getMessage()); | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
src/main/java/ch/wisv/areafiftylan/utils/SlackNotificationAspect.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,56 @@ | ||
package ch.wisv.areafiftylan.utils; | ||
|
||
import ch.wisv.areafiftylan.exception.SlackNotificationException; | ||
import ch.wisv.areafiftylan.products.model.order.Order; | ||
import ch.wisv.areafiftylan.products.model.order.OrderStatus; | ||
import in.ashwanthkumar.slack.webhook.Slack; | ||
import in.ashwanthkumar.slack.webhook.SlackMessage; | ||
import org.aspectj.lang.annotation.After; | ||
import org.aspectj.lang.annotation.AfterReturning; | ||
import org.aspectj.lang.annotation.AfterThrowing; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.IOException; | ||
|
||
@Aspect | ||
@Component | ||
@ConditionalOnProperty( | ||
value = "slack") | ||
@Profile("production") | ||
public class SlackNotificationAspect { | ||
|
||
private Slack slackApi; | ||
|
||
public SlackNotificationAspect(@Value("${slack}") String webHookUrl) { | ||
slackApi = new Slack(webHookUrl); | ||
} | ||
|
||
private void sendSlackMessage(String message) { | ||
try { | ||
slackApi.sendToChannel("#lanciedev").push(new SlackMessage(message)); | ||
} catch (IOException e) { | ||
throw new SlackNotificationException(e); | ||
} | ||
} | ||
|
||
@AfterReturning(pointcut = "execution(* ch.wisv.areafiftylan.products.service.MolliePaymentService.updateStatus(..))", returning = "order") | ||
public void notifyTicketSale(Order order) { | ||
if (order.getStatus() == OrderStatus.PAID) { | ||
sendSlackMessage(order.getTickets().size() + " tickets bought! :tada:"); | ||
} | ||
} | ||
|
||
@After("execution(* ch.wisv.areafiftylan.products.service.TicketServiceImpl.transferTicket(..))") | ||
public void notifyTicketTransfer() { | ||
sendSlackMessage("A ticket transfer has been performed"); | ||
} | ||
|
||
@AfterThrowing(pointcut = "execution(* ch.wisv.areafiftylan.exception.*.*(..)) && !execution(* ch.wisv.areafiftylan.exception.SlackNotificationException.*(..))", throwing = "ex") | ||
public void forwardException(Throwable ex) { | ||
sendSlackMessage("An exception has been thrown: " + ex.getMessage()); | ||
} | ||
} |