-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metodos de serviços para envio de notificação
- Loading branch information
1 parent
861ace8
commit 2812aed
Showing
28 changed files
with
445 additions
and
67 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...es.pom/muttley-hermes-api/src/main/java/br/com/muttley/hermes/api/NotificationClient.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,38 @@ | ||
package br.com.muttley.hermes.api; | ||
|
||
import br.com.muttley.feign.autoconfig.FeignTimeoutConfig; | ||
import br.com.muttley.model.hermes.notification.onesignal.Notification; | ||
import br.com.muttley.security.infra.server.FeignClientConfig; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | ||
import static org.springframework.web.bind.annotation.RequestMethod.POST; | ||
|
||
/** | ||
* @author Joel Rodrigues Moreira on 06/08/2020. | ||
* e-mail: <a href="mailto:[email protected]">[email protected]</a> | ||
* @project muttley-cloud | ||
*/ | ||
@FeignClient(value = "${muttley.hermes.server.name}", path = "/api/v1/tokens-notification", configuration = {FeignClientConfig.class, FeignTimeoutConfig.class}) | ||
public interface NotificationClient { | ||
@RequestMapping(method = POST, consumes = APPLICATION_JSON_VALUE) | ||
public void sendNotification(@RequestBody final Notification notification); | ||
|
||
@RequestMapping(value = "/{playerId}", method = POST, consumes = APPLICATION_JSON_VALUE) | ||
public void sendNotification(@PathVariable("playerId") final String playerId, @RequestBody final Notification notification); | ||
|
||
@RequestMapping(value = "/send-by-user/{userId}", method = POST, consumes = APPLICATION_JSON_VALUE) | ||
public void sendNotificationByUserId(@PathVariable("userId") final String userId, @RequestBody final Notification notification); | ||
|
||
@RequestMapping(value = "/send-by-mobile-user/{userId}", method = POST, consumes = APPLICATION_JSON_VALUE) | ||
public void sendNotificationMobileByUser(@PathVariable("userId") final String userId, @RequestBody final Notification notification); | ||
|
||
@RequestMapping(value = "/simple-send-by-user/{userId}", method = POST, consumes = APPLICATION_JSON_VALUE) | ||
public void sendNotificationByUser(@PathVariable("userId") final String userId, @PathVariable(value = "heading", required = false) final String heading, @PathVariable(value = "subtitle", required = false) final String subtitle, @PathVariable(value = "content", required = false) final String content); | ||
|
||
@RequestMapping(value = "/simple-send-by-mobile-user/{userId}", method = POST, consumes = APPLICATION_JSON_VALUE) | ||
public void sendNotificationMobileByUserId(@PathVariable("userId") final String userId, @PathVariable(value = "heading", required = false) final String heading, @PathVariable(value = "subtitle", required = false) final String subtitle, @PathVariable(value = "content", required = false) final String content); | ||
} |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package br.com.muttley.hermes.api; | ||
|
||
import br.com.muttley.feign.autoconfig.FeignTimeoutConfig; | ||
import br.com.muttley.model.hermes.notification.TokenId; | ||
import br.com.muttley.security.infra.server.FeignClientConfig; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
|
@@ -14,7 +15,7 @@ | |
* e-mail: <a href="mailto:[email protected]">[email protected]</a> | ||
* @project muttley-cloud | ||
*/ | ||
@FeignClient(value = "${muttley.hermes.server.name}", path = "/api/v1/tokens-notification", configuration = FeignClientConfig.class) | ||
@FeignClient(value = "${muttley.hermes.server.name}", path = "/api/v1/tokens-notification", configuration = {FeignClientConfig.class, FeignTimeoutConfig.class}) | ||
public interface UserTokenNotificationClient { | ||
|
||
@RequestMapping(method = POST, consumes = APPLICATION_JSON_VALUE) | ||
|
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
2 changes: 1 addition & 1 deletion
2
...ongo/MuttleyMongoSimpleTenancyConfig.java → ...ongo/MuttleyMongoSimpleTenancyConfig.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
59 changes: 59 additions & 0 deletions
59
...-server/src/main/java/br/com/muttley/hermes/server/controller/NotificationController.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,59 @@ | ||
package br.com.muttley.hermes.server.controller; | ||
|
||
import br.com.muttley.hermes.server.service.NotificationService; | ||
import br.com.muttley.model.hermes.notification.onesignal.Notification; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | ||
import static org.springframework.web.bind.annotation.RequestMethod.POST; | ||
|
||
/** | ||
* @author Joel Rodrigues Moreira on 06/08/2020. | ||
* e-mail: <a href="mailto:[email protected]">[email protected]</a> | ||
* @project muttley-cloud | ||
*/ | ||
@RestController | ||
@RequestMapping(value = "/api/v1/notifications", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE) | ||
public class NotificationController { | ||
|
||
private final NotificationService notificationService; | ||
|
||
@Autowired | ||
public NotificationController(final NotificationService notificationService) { | ||
this.notificationService = notificationService; | ||
} | ||
|
||
@RequestMapping(method = POST) | ||
public void sendNotification(@RequestBody final Notification notification) { | ||
this.notificationService.sendNotification(notification); | ||
} | ||
|
||
@RequestMapping(value = "/{playerId}", method = POST) | ||
public void sendNotification(@PathVariable("playerId") final String playerId, @RequestBody final Notification notification) { | ||
this.notificationService.sendNotification(notification.addPlayers(playerId)); | ||
} | ||
|
||
@RequestMapping(value = "/send-by-user/{userId}", method = POST) | ||
public void sendNotificationByUserId(@PathVariable("userId") final String userId, @RequestBody final Notification notification) { | ||
this.notificationService.sendNotificationByUserId(userId, notification); | ||
} | ||
|
||
@RequestMapping(value = "/send-by-mobile-user/{userId}", method = POST) | ||
public void sendNotificationMobileByUser(@PathVariable("userId") final String userId, @RequestBody final Notification notification) { | ||
this.notificationService.sendNotificationMobileByUserId(userId, notification); | ||
} | ||
|
||
@RequestMapping(value = "/simple-send-by-user/{userId}", method = POST) | ||
public void sendNotificationByUser(@PathVariable("userId") final String userId, @PathVariable(value = "heading", required = false) final String heading, @PathVariable(value = "subtitle", required = false) final String subtitle, @PathVariable(value = "content", required = false) final String content) { | ||
this.notificationService.sendNotificationByUserId(userId, heading, subtitle, content); | ||
} | ||
|
||
@RequestMapping(value = "/simple-send-by-mobile-user/{userId}", method = POST) | ||
public void sendNotificationMobileByUserId(@PathVariable("userId") final String userId, @PathVariable(value = "heading", required = false) final String heading, @PathVariable(value = "subtitle", required = false) final String subtitle, @PathVariable(value = "content", required = false) final String content) { | ||
this.notificationService.sendNotificationMobileByUserId(userId, heading, subtitle, content); | ||
} | ||
} |
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
20 changes: 2 additions & 18 deletions
20
...erver/src/main/java/br/com/muttley/hermes/server/listeners/NotificationEventListener.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 |
---|---|---|
@@ -1,39 +1,23 @@ | ||
package br.com.muttley.hermes.server.listeners; | ||
|
||
import br.com.muttley.notification.onesignal.model.Content; | ||
import br.com.muttley.notification.onesignal.model.Notification; | ||
import br.com.muttley.notification.onesignal.model.NotificationData; | ||
import br.com.muttley.notification.onesignal.model.events.NotificationEvent; | ||
import br.com.muttley.model.hermes.notification.onesignal.events.NotificationEvent; | ||
import br.com.muttley.notification.onesignal.service.OneSignalNotificationService; | ||
import br.com.muttley.redis.service.RedisService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static br.com.muttley.notification.onesignal.model.MuttleyLanguage.English; | ||
|
||
/** | ||
* @author Joel Rodrigues Moreira on 05/08/2020. | ||
* e-mail: <a href="mailto:[email protected]">[email protected]</a> | ||
* @project muttley-cloud | ||
*/ | ||
@Component | ||
public class NotificationEventListener implements ApplicationListener<NotificationEvent> { | ||
private static final String KEY_REDIS = "muttley-notification-cache"; | ||
private final RedisService redisService; | ||
private final OneSignalNotificationService oneSignalService; | ||
|
||
@Autowired | ||
public NotificationEventListener(final RedisService redisService, final OneSignalNotificationService oneSignalService) { | ||
this.redisService = redisService; | ||
public NotificationEventListener(final OneSignalNotificationService oneSignalService) { | ||
this.oneSignalService = oneSignalService; | ||
this.oneSignalService.sendNotification(new Notification().setAppId("f9f00ebb-1d73-4e6b-a127-b6a086f48111") | ||
.addPlayers("6c9e98ff-2542-4278-848b-1310abd57b04") | ||
.setData(new NotificationData().setType("asdfasd").setPayload("asdfasdf")) | ||
.addContent(new Content(English, "English")) | ||
.addHeadings(new Content(English, "headings")) | ||
.addSubtitles(new Content(English, "subtitles")) | ||
); | ||
} | ||
|
||
@Override | ||
|
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
40 changes: 40 additions & 0 deletions
40
...hermes-server/src/main/java/br/com/muttley/hermes/server/service/NotificationService.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,40 @@ | ||
package br.com.muttley.hermes.server.service; | ||
|
||
import br.com.muttley.model.hermes.notification.onesignal.Content; | ||
import br.com.muttley.model.hermes.notification.onesignal.Notification; | ||
import br.com.muttley.model.security.UserView; | ||
|
||
/** | ||
* @author Joel Rodrigues Moreira on 06/08/2020. | ||
* e-mail: <a href="mailto:[email protected]">[email protected]</a> | ||
* @project muttley-cloud | ||
*/ | ||
public interface NotificationService { | ||
void sendNotification(final Notification notification); | ||
|
||
void sendNotification(final String playerId, final Notification notification); | ||
|
||
void sendNotification(final UserView user, final Notification notification); | ||
|
||
void sendNotificationByUserId(final String userId, final Notification notification); | ||
|
||
void sendNotificationMobile(final UserView user, final Notification notification); | ||
|
||
void sendNotificationMobileByUserId(final String userId, final Notification notification); | ||
|
||
void sendNotification(final UserView user, final Content headings, final Content subtitles, final Content contents); | ||
|
||
void sendNotificationByUserId(final String userId, final Content headings, final Content subtitles, final Content contents); | ||
|
||
void sendNotificationMobile(final UserView user, final Content headings, final Content subtitles, final Content contents); | ||
|
||
void sendNotificationMobileByUserId(final String userId, final Content headings, final Content subtitles, final Content contents); | ||
|
||
void sendNotification(final UserView user, final String heading, final String subtitle, final String content); | ||
|
||
void sendNotificationByUserId(final String userId, final String heading, final String subtitle, final String content); | ||
|
||
void sendNotificationMobile(final UserView user, final String heading, final String subtitle, final String content); | ||
|
||
void sendNotificationMobileByUserId(final String userId, final String heading, final String subtitle, final String content); | ||
} |
8 changes: 7 additions & 1 deletion
8
...ver/src/main/java/br/com/muttley/hermes/server/service/UserTokensNotificationService.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 |
---|---|---|
@@ -1,17 +1,23 @@ | ||
package br.com.muttley.hermes.server.service; | ||
|
||
import br.com.muttley.domain.Service; | ||
import br.com.muttley.exception.throwables.MuttleyNotFoundException; | ||
import br.com.muttley.model.hermes.notification.TokenId; | ||
import br.com.muttley.model.hermes.notification.UserTokensNotification; | ||
import br.com.muttley.model.security.User; | ||
import br.com.muttley.model.security.UserView; | ||
|
||
/** | ||
* @author Joel Rodrigues Moreira on 04/08/2020. | ||
* e-mail: <a href="mailto:[email protected]">[email protected]</a> | ||
* @project muttley-cloud | ||
*/ | ||
public interface UserTokensNotificationService extends Service<UserTokensNotification> { | ||
UserTokensNotification findByUser(final User user); | ||
UserTokensNotification findByUser(final User user) throws MuttleyNotFoundException; | ||
|
||
UserTokensNotification findByUser(final UserView user) throws MuttleyNotFoundException; | ||
|
||
UserTokensNotification findByUser(final String userId) throws MuttleyNotFoundException; | ||
|
||
void addTokenNotification(final User user, final TokenId tokenId); | ||
} |
Oops, something went wrong.