mirror of
https://github.com/valitydev/fraudbusters-management.git
synced 2024-11-06 08:25:17 +00:00
add implementation new protocols
This commit is contained in:
parent
620f13c410
commit
b4a64f0f25
8
pom.xml
8
pom.xml
@ -38,7 +38,8 @@
|
||||
<fraudo.version>0.0.17</fraudo.version>
|
||||
<geck.version>0.6.11</geck.version>
|
||||
<db.common.lib.version>0.0.3</db.common.lib.version>
|
||||
<swag-fraudbusters-management.version>1.78-2dbc0ef-server</swag-fraudbusters-management.version>
|
||||
<swag-fraudbusters-management.version>1.85-0ac0610-server</swag-fraudbusters-management.version>
|
||||
<fraudbusters.notificator.proto.version>1.9-742bc9d</fraudbusters.notificator.proto.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -98,6 +99,11 @@
|
||||
<artifactId>fraudo</artifactId>
|
||||
<version>${fraudo.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>fraudbusters-notificator-proto</artifactId>
|
||||
<version>${fraudbusters.notificator.proto.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--spring-->
|
||||
<dependency>
|
||||
|
@ -0,0 +1,50 @@
|
||||
package com.rbkmoney.fraudbusters.management.config;
|
||||
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.ChannelServiceSrv;
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.NotificationServiceSrv;
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.NotificationTemplateServiceSrv;
|
||||
import com.rbkmoney.woody.thrift.impl.http.THSpawnClientBuilder;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Configuration
|
||||
public class NotificatorConfig {
|
||||
|
||||
@Bean
|
||||
public NotificationServiceSrv.Iface notificationClient(@Value("${service.notification.url}") Resource resource,
|
||||
@Value("${service.notification.networkTimeout}")
|
||||
int networkTimeout)
|
||||
throws IOException {
|
||||
return new THSpawnClientBuilder()
|
||||
.withNetworkTimeout(networkTimeout)
|
||||
.withAddress(resource.getURI())
|
||||
.build(NotificationServiceSrv.Iface.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ChannelServiceSrv.Iface notificationChannelClient(
|
||||
@Value("${service.notification-channel.url}") Resource resource,
|
||||
@Value("${service.notification-channel.networkTimeout}") int networkTimeout)
|
||||
throws IOException {
|
||||
return new THSpawnClientBuilder()
|
||||
.withNetworkTimeout(networkTimeout)
|
||||
.withAddress(resource.getURI())
|
||||
.build(ChannelServiceSrv.Iface.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NotificationTemplateServiceSrv.Iface notificationTemplateClient(
|
||||
@Value("${service.notification-template.url}") Resource resource,
|
||||
@Value("${service.notification-template.networkTimeout}") int networkTimeout)
|
||||
throws IOException {
|
||||
return new THSpawnClientBuilder()
|
||||
.withNetworkTimeout(networkTimeout)
|
||||
.withAddress(resource.getURI())
|
||||
.build(NotificationTemplateServiceSrv.Iface.class);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.rbkmoney.fraudbusters.management.converter;
|
||||
|
||||
public interface BiConverter<S, T> {
|
||||
|
||||
T toTarget(S s);
|
||||
|
||||
S toSource(T t);
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.rbkmoney.fraudbusters.management.converter;
|
||||
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.ChannelType;
|
||||
import com.rbkmoney.swag.fraudbusters.management.model.Channel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Objects;
|
||||
|
||||
@Component
|
||||
public class ChannelConverter
|
||||
implements BiConverter<com.rbkmoney.damsel.fraudbusters_notificator.Channel, Channel> {
|
||||
|
||||
@Override
|
||||
public Channel toTarget(com.rbkmoney.damsel.fraudbusters_notificator.Channel channel) {
|
||||
if (Objects.isNull(channel)) {
|
||||
return null;
|
||||
}
|
||||
Channel result = new Channel();
|
||||
result.setName(channel.getName());
|
||||
result.setDestination(channel.getDestination());
|
||||
result.setType(Channel.TypeEnum.fromValue(channel.getType().name()));
|
||||
result.setCreatedAt(LocalDateTime.parse(channel.getCreatedAt(), DateTimeFormatter.ISO_DATE_TIME));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.rbkmoney.damsel.fraudbusters_notificator.Channel toSource(Channel channel) {
|
||||
if (Objects.isNull(channel)) {
|
||||
return null;
|
||||
}
|
||||
com.rbkmoney.damsel.fraudbusters_notificator.Channel result =
|
||||
new com.rbkmoney.damsel.fraudbusters_notificator.Channel();
|
||||
result.setName(channel.getName());
|
||||
result.setDestination(channel.getDestination());
|
||||
result.setType(ChannelType.valueOf(channel.getType().getValue()));
|
||||
result.setCreatedAt(channel.getCreatedAt().format(DateTimeFormatter.ISO_DATE_TIME));
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.rbkmoney.fraudbusters.management.converter;
|
||||
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.NotificationStatus;
|
||||
import com.rbkmoney.swag.fraudbusters.management.model.Notification;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Objects;
|
||||
|
||||
@Component
|
||||
public class NotificationConverter
|
||||
implements BiConverter<com.rbkmoney.damsel.fraudbusters_notificator.Notification, Notification> {
|
||||
|
||||
@Override
|
||||
public Notification toTarget(com.rbkmoney.damsel.fraudbusters_notificator.Notification notification) {
|
||||
if (Objects.isNull(notification)) {
|
||||
return null;
|
||||
}
|
||||
Notification result = new Notification();
|
||||
result.setId(notification.getId());
|
||||
result.setName(notification.getName());
|
||||
result.setSubject(notification.getSubject());
|
||||
result.setChannel(notification.getChannel());
|
||||
result.setFrequency(notification.getFrequency());
|
||||
result.setPeriod(notification.getPeriod());
|
||||
result.setStatus(Notification.StatusEnum.fromValue(notification.getStatus().name()));
|
||||
result.setTemplateId(notification.getTemplateId());
|
||||
result.setUpdatedAt(LocalDateTime.parse(notification.getUpdatedAt(), DateTimeFormatter.ISO_DATE_TIME));
|
||||
result.setCreatedAt(LocalDateTime.parse(notification.getCreatedAt(), DateTimeFormatter.ISO_DATE_TIME));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.rbkmoney.damsel.fraudbusters_notificator.Notification toSource(Notification notification) {
|
||||
if (Objects.isNull(notification)) {
|
||||
return null;
|
||||
}
|
||||
com.rbkmoney.damsel.fraudbusters_notificator.Notification result =
|
||||
new com.rbkmoney.damsel.fraudbusters_notificator.Notification();
|
||||
result.setId(notification.getId());
|
||||
result.setName(notification.getName());
|
||||
result.setSubject(notification.getSubject());
|
||||
result.setChannel(notification.getChannel());
|
||||
result.setFrequency(notification.getFrequency());
|
||||
result.setPeriod(notification.getPeriod());
|
||||
result.setStatus(NotificationStatus.valueOf(notification.getStatus().getValue()));
|
||||
result.setTemplateId(notification.getTemplateId());
|
||||
result.setUpdatedAt(notification.getUpdatedAt().format(DateTimeFormatter.ISO_DATE_TIME));
|
||||
result.setCreatedAt(notification.getCreatedAt().format(DateTimeFormatter.ISO_DATE_TIME));
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.rbkmoney.fraudbusters.management.converter;
|
||||
|
||||
import com.rbkmoney.swag.fraudbusters.management.model.NotificationTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Objects;
|
||||
|
||||
@Component
|
||||
public class NotificationTemplateConverter
|
||||
implements
|
||||
BiConverter<com.rbkmoney.damsel.fraudbusters_notificator.NotificationTemplate, NotificationTemplate> {
|
||||
|
||||
@Override
|
||||
public NotificationTemplate toTarget(
|
||||
com.rbkmoney.damsel.fraudbusters_notificator.NotificationTemplate notificationTemplate) {
|
||||
if (Objects.isNull(notificationTemplate)) {
|
||||
return null;
|
||||
}
|
||||
NotificationTemplate result = new NotificationTemplate();
|
||||
result.setId(notificationTemplate.getId());
|
||||
result.setName(notificationTemplate.getName());
|
||||
result.setBasicParams(notificationTemplate.getBasicParams());
|
||||
result.setQueryText(notificationTemplate.getQueryText());
|
||||
result.setSkeleton(notificationTemplate.getSkeleton());
|
||||
result.setType(notificationTemplate.getType());
|
||||
result.setUpdatedAt(LocalDateTime.parse(notificationTemplate.getUpdatedAt(), DateTimeFormatter.ISO_DATE_TIME));
|
||||
result.setCreatedAt(LocalDateTime.parse(notificationTemplate.getCreatedAt(), DateTimeFormatter.ISO_DATE_TIME));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.rbkmoney.damsel.fraudbusters_notificator.NotificationTemplate toSource(
|
||||
NotificationTemplate notificationTemplate) {
|
||||
if (Objects.isNull(notificationTemplate)) {
|
||||
return null;
|
||||
}
|
||||
com.rbkmoney.damsel.fraudbusters_notificator.NotificationTemplate result =
|
||||
new com.rbkmoney.damsel.fraudbusters_notificator.NotificationTemplate();
|
||||
result.setId(notificationTemplate.getId());
|
||||
result.setName(notificationTemplate.getName());
|
||||
result.setBasicParams(notificationTemplate.getBasicParams());
|
||||
result.setQueryText(notificationTemplate.getQueryText());
|
||||
result.setSkeleton(notificationTemplate.getSkeleton());
|
||||
result.setType(notificationTemplate.getType());
|
||||
result.setUpdatedAt(notificationTemplate.getUpdatedAt().format(DateTimeFormatter.ISO_DATE_TIME));
|
||||
result.setCreatedAt(notificationTemplate.getCreatedAt().format(DateTimeFormatter.ISO_DATE_TIME));
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
package com.rbkmoney.fraudbusters.management.resource.notificator;
|
||||
|
||||
import com.rbkmoney.swag.fraudbusters.management.api.NotificationsApi;
|
||||
import com.rbkmoney.swag.fraudbusters.management.model.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class NotificationProxyFacade implements NotificationsApi {
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
@Value("${service.fb-notificator.url}")
|
||||
private String baseUrl;
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<com.rbkmoney.swag.fraudbusters.management.model.Channel> createChannel(
|
||||
com.rbkmoney.swag.fraudbusters.management.model.@Valid Channel channel) {
|
||||
return restTemplate.postForEntity(baseUrl + "/channels", channel, Channel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<Notification> createOrUpdateNotification(@Valid Notification notification) {
|
||||
ResponseEntity<Notification> notificationResponseEntity =
|
||||
restTemplate.postForEntity(baseUrl + "/notifications", notification, Notification.class);
|
||||
log.info("NotificationProxyFacade create notification: {}", notification);
|
||||
return notificationResponseEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<Void> removeChannel(String name) {
|
||||
restTemplate.delete(baseUrl + "/channels/{name}", name);
|
||||
log.info("NotificationProxyFacade delete channel with name: {}", name);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<Void> removeNotification(Long id) {
|
||||
restTemplate.delete(baseUrl + "/notifications/{id}", id);
|
||||
log.info("NotificationProxyFacade delete notification with id: {}", id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<com.rbkmoney.swag.fraudbusters.management.model.ValidationResponse> validateNotification(
|
||||
com.rbkmoney.swag.fraudbusters.management.model.@Valid Notification notification) {
|
||||
return restTemplate.postForEntity(baseUrl + "/notifications/validation",
|
||||
notification, ValidationResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<NotificationListResponse> getNotifications() {
|
||||
return restTemplate.getForEntity(baseUrl + "/notifications", NotificationListResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<ChannelListResponse> getChannels() {
|
||||
return restTemplate.getForEntity(baseUrl + "/channels", ChannelListResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<Void> updateNotificationStatus(Long id,
|
||||
@Valid NotificationStatus notificationStatus) {
|
||||
restTemplate.put(baseUrl + "/notifications/{id}/status", notificationStatus, id);
|
||||
log.info("NotificationProxyFacade update notification status: {}", notificationStatus);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
@ -0,0 +1,170 @@
|
||||
package com.rbkmoney.fraudbusters.management.resource.notificator;
|
||||
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.Filter;
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.Page;
|
||||
import com.rbkmoney.fraudbusters.management.converter.BiConverter;
|
||||
import com.rbkmoney.fraudbusters.management.service.iface.ChannelService;
|
||||
import com.rbkmoney.fraudbusters.management.service.iface.NotificationService;
|
||||
import com.rbkmoney.fraudbusters.management.service.iface.NotificationTemplateService;
|
||||
import com.rbkmoney.swag.fraudbusters.management.api.NotificationsApi;
|
||||
import com.rbkmoney.swag.fraudbusters.management.model.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class NotificationResource implements NotificationsApi {
|
||||
|
||||
private final NotificationService notificationService;
|
||||
private final BiConverter<com.rbkmoney.damsel.fraudbusters_notificator.Notification, Notification>
|
||||
notificationConverter;
|
||||
private final NotificationTemplateService notificationTemplateService;
|
||||
private final BiConverter<com.rbkmoney.damsel.fraudbusters_notificator.NotificationTemplate, NotificationTemplate>
|
||||
notificationTemplateConverter;
|
||||
private final ChannelService channelService;
|
||||
private final BiConverter<com.rbkmoney.damsel.fraudbusters_notificator.Channel, Channel> channelConverter;
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<Channel> createChannel(@Valid Channel channel) {
|
||||
com.rbkmoney.damsel.fraudbusters_notificator.Channel createdChannel =
|
||||
channelService.create(channelConverter.toSource(channel));
|
||||
log.info("NotificationResource create channel: {}", createdChannel);
|
||||
return ResponseEntity.ok(channelConverter.toTarget(createdChannel));
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<Notification> createOrUpdateNotification(@Valid Notification notification) {
|
||||
com.rbkmoney.damsel.fraudbusters_notificator.Notification createdNotification =
|
||||
notificationService.create(notificationConverter.toSource(notification));
|
||||
log.info("NotificationResource create notification: {}", createdNotification);
|
||||
return ResponseEntity.ok(notificationConverter.toTarget(createdNotification));
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<Void> removeChannel(String name) {
|
||||
channelService.delete(name);
|
||||
log.info("NotificationResource delete channel with name: {}", name);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<Void> removeNotification(Long id) {
|
||||
notificationService.delete(id);
|
||||
log.info("NotificationResource delete notification with id: {}", id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<ValidationResponse> validateNotification(
|
||||
com.rbkmoney.swag.fraudbusters.management.model.@Valid Notification notification) {
|
||||
com.rbkmoney.damsel.fraudbusters_notificator.ValidationResponse validationResponse =
|
||||
notificationService.validate(notificationConverter.toSource(notification));
|
||||
ValidationResponse response = new ValidationResponse();
|
||||
if (validationResponse.isSetErrors()) {
|
||||
List<String> errors = validationResponse.getErrors();
|
||||
List<ValidationError> validationErrors = errors.stream()
|
||||
.map(error -> new ValidationError().errorReason(error))
|
||||
.collect(Collectors.toList());
|
||||
response.setErrors(validationErrors);
|
||||
}
|
||||
if (validationResponse.isSetResult()) {
|
||||
response.setResult(validationResponse.getResult());
|
||||
}
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<NotificationListResponse> getNotifications(
|
||||
@Valid @RequestParam(value = "lastId", required = false) Long lastId,
|
||||
@Valid @RequestParam(value = "size", required = false) Integer size,
|
||||
@Valid @RequestParam(value = "searchValue", required = false) String searchValue) {
|
||||
com.rbkmoney.damsel.fraudbusters_notificator.NotificationListResponse notificationListResponse =
|
||||
notificationService
|
||||
.getAll(new Page()
|
||||
.setContinuationId(lastId)
|
||||
.setSize(size),
|
||||
new Filter()
|
||||
.setSearchField(searchValue));
|
||||
List<Notification> filteredNotifications = notificationListResponse.getNotifications().stream()
|
||||
.map(notificationConverter::toTarget)
|
||||
.collect(Collectors.toList());
|
||||
NotificationListResponse response = new NotificationListResponse();
|
||||
response.setResult(filteredNotifications);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<ChannelListResponse> getChannels(
|
||||
@Valid @RequestParam(value = "lastId", required = false) Long lastId,
|
||||
@Valid @RequestParam(value = "size", required = false) Integer size,
|
||||
@Valid @RequestParam(value = "searchValue", required = false) String searchValue) {
|
||||
com.rbkmoney.damsel.fraudbusters_notificator.ChannelListResponse channelListResponse =
|
||||
channelService.getAll(new Page()
|
||||
.setContinuationId(lastId)
|
||||
.setSize(size),
|
||||
new Filter()
|
||||
.setSearchField(searchValue));
|
||||
List<Channel> channels = channelListResponse.getChannels().stream()
|
||||
.map(channelConverter::toTarget)
|
||||
.collect(Collectors.toList());
|
||||
ChannelListResponse response = new ChannelListResponse();
|
||||
response.setResult(channels);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<Void> updateNotificationStatus(Long id,
|
||||
@Valid NotificationStatus notificationStatus) {
|
||||
com.rbkmoney.damsel.fraudbusters_notificator.NotificationStatus status =
|
||||
com.rbkmoney.damsel.fraudbusters_notificator.NotificationStatus
|
||||
.valueOf(notificationStatus.getStatus().getValue());
|
||||
notificationService.updateStatus(id, status);
|
||||
log.info("NotificationResource update notification status: {}", notificationStatus);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<ChannelTypeListResponse> getChannelTypes() {
|
||||
com.rbkmoney.damsel.fraudbusters_notificator.ChannelTypeListResponse channelTypeListResponse =
|
||||
channelService.getAllTypes();
|
||||
List<ChannelType> channelTypes = channelTypeListResponse.getChannelTypes().stream()
|
||||
.map(value -> new ChannelType().type(ChannelType.TypeEnum.fromValue(value)))
|
||||
.collect(Collectors.toList());
|
||||
ChannelTypeListResponse response = new ChannelTypeListResponse();
|
||||
response.setResult(channelTypes);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAnyRole('fraud-officer')")
|
||||
public ResponseEntity<NotificationTemplateListResponse> getTemplates() {
|
||||
com.rbkmoney.damsel.fraudbusters_notificator.NotificationTemplateListResponse notificationTemplateListResponse =
|
||||
notificationTemplateService.getAll();
|
||||
List<NotificationTemplate> notificationTemplates =
|
||||
notificationTemplateListResponse.getNotificationTemplates().stream()
|
||||
.map(notificationTemplateConverter::toTarget)
|
||||
.collect(Collectors.toList());
|
||||
NotificationTemplateListResponse response = new NotificationTemplateListResponse();
|
||||
response.setResult(notificationTemplates);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.rbkmoney.fraudbusters.management.service;
|
||||
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.*;
|
||||
import com.rbkmoney.fraudbusters.management.service.iface.ChannelService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.thrift.TException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ChannelServiceImpl implements ChannelService {
|
||||
|
||||
private final ChannelServiceSrv.Iface channelClient;
|
||||
|
||||
@Override
|
||||
public Channel create(Channel channel) {
|
||||
try {
|
||||
return channelClient.create(channel);
|
||||
} catch (TException e) {
|
||||
log.error("Error call ChannelService create ", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String name) {
|
||||
try {
|
||||
channelClient.remove(name);
|
||||
} catch (TException e) {
|
||||
log.error("Error call ChannelService remove ", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelListResponse getAll(Page page, Filter filter) {
|
||||
try {
|
||||
return channelClient.getAll(page, filter);
|
||||
} catch (TException e) {
|
||||
log.error("Error call ChannelService getAll ", e);
|
||||
return new ChannelListResponse()
|
||||
.setChannels(Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelTypeListResponse getAllTypes() {
|
||||
try {
|
||||
return channelClient.getAllTypes();
|
||||
} catch (TException e) {
|
||||
log.error("Error call ChannelService getAllTypes ", e);
|
||||
return new ChannelTypeListResponse()
|
||||
.setChannelTypes(Collections.emptyList());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.rbkmoney.fraudbusters.management.service;
|
||||
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.*;
|
||||
import com.rbkmoney.fraudbusters.management.service.iface.NotificationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.thrift.TException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class NotificationServiceImpl implements NotificationService {
|
||||
|
||||
private final NotificationServiceSrv.Iface notificationClient;
|
||||
|
||||
@Override
|
||||
public Notification create(Notification notification) {
|
||||
try {
|
||||
return notificationClient.create(notification);
|
||||
} catch (TException e) {
|
||||
log.error("Error call NotificationService create ", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
try {
|
||||
notificationClient.remove(id);
|
||||
} catch (TException e) {
|
||||
log.error("Error call NotificationService remove ", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStatus(Long id, NotificationStatus status) {
|
||||
try {
|
||||
notificationClient.updateStatus(id, status);
|
||||
} catch (TException e) {
|
||||
log.error("Error call NotificationService updateStatus ", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationResponse validate(Notification notification) {
|
||||
try {
|
||||
return notificationClient.validate(notification);
|
||||
} catch (TException e) {
|
||||
log.error("Error call NotificationService validate ", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NotificationListResponse getAll(Page page, Filter filter) {
|
||||
try {
|
||||
return notificationClient.getAll(page, filter);
|
||||
} catch (TException e) {
|
||||
log.error("Error call NotificationService getAll ", e);
|
||||
return new NotificationListResponse()
|
||||
.setNotifications(Collections.emptyList());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.rbkmoney.fraudbusters.management.service;
|
||||
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.NotificationTemplateListResponse;
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.NotificationTemplateServiceSrv;
|
||||
import com.rbkmoney.fraudbusters.management.service.iface.NotificationTemplateService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.thrift.TException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class NotificationTemplateServiceImpl implements NotificationTemplateService {
|
||||
|
||||
private final NotificationTemplateServiceSrv.Iface notificationTemplateClient;
|
||||
|
||||
@Override
|
||||
public NotificationTemplateListResponse getAll() {
|
||||
try {
|
||||
return notificationTemplateClient.getAll();
|
||||
} catch (TException e) {
|
||||
log.error("Error call NotificationTemplateService getAll ", e);
|
||||
return new NotificationTemplateListResponse()
|
||||
.setNotificationTemplates(Collections.emptyList());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.rbkmoney.fraudbusters.management.service.iface;
|
||||
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.*;
|
||||
|
||||
public interface ChannelService {
|
||||
|
||||
Channel create(Channel channel);
|
||||
|
||||
void delete(String name);
|
||||
|
||||
ChannelListResponse getAll(Page page, Filter filter);
|
||||
|
||||
ChannelTypeListResponse getAllTypes();
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.rbkmoney.fraudbusters.management.service.iface;
|
||||
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.*;
|
||||
|
||||
public interface NotificationService {
|
||||
|
||||
Notification create(Notification notification);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
void updateStatus(Long id, NotificationStatus status);
|
||||
|
||||
ValidationResponse validate(Notification notification);
|
||||
|
||||
NotificationListResponse getAll(Page page, Filter filter);
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.rbkmoney.fraudbusters.management.service.iface;
|
||||
|
||||
import com.rbkmoney.damsel.fraudbusters_notificator.NotificationTemplateListResponse;
|
||||
|
||||
public interface NotificationTemplateService {
|
||||
|
||||
NotificationTemplateListResponse getAll();
|
||||
|
||||
}
|
@ -76,8 +76,15 @@ service:
|
||||
cleaner:
|
||||
cron: "-"
|
||||
fresh-period: 30
|
||||
fb-notificator:
|
||||
url: "http://fraudbusters-notificator:8080/"
|
||||
notification:
|
||||
url: http://localhost:8999/notification/v1
|
||||
networkTimeout: 5000
|
||||
notification-channel:
|
||||
url: http://localhost:8999/notification-channel/v1
|
||||
networkTimeout: 5000
|
||||
notification-template:
|
||||
url: http://localhost:8999/notification-template/v1
|
||||
networkTimeout: 5000
|
||||
|
||||
keycloak:
|
||||
auth-server-url: http://localhost:8080/auth
|
||||
|
Loading…
Reference in New Issue
Block a user