mirror of
https://github.com/valitydev/fraudbusters-management.git
synced 2024-11-06 16:35:20 +00:00
Add template url
This commit is contained in:
parent
eb107325a7
commit
99d07fbc1f
15
pom.xml
15
pom.xml
@ -36,6 +36,9 @@
|
||||
<wb.list.proto.version>1.20-2c2fb6a</wb.list.proto.version>
|
||||
<kafka.streams.version>2.1.0</kafka.streams.version>
|
||||
<kafka.clients.version>2.1.0</kafka.clients.version>
|
||||
<fraudbusters.proto.version>1.10-ebbe9be</fraudbusters.proto.version>
|
||||
<kafka.common.lib.version>0.0.1-SNAPSHOT</kafka.common.lib.version>
|
||||
<fraudo.version>0.0.3-SNAPSHOT</fraudo.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -73,7 +76,17 @@
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>kafka-common-lib</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<version>${kafka.common.lib.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>fraudbusters-proto</artifactId>
|
||||
<version>${fraudbusters.proto.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rbkmoney</groupId>
|
||||
<artifactId>fraudo</artifactId>
|
||||
<version>${fraudo.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--spring-->
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.rbkmoney.fraudbusters.management.dao.template;
|
||||
|
||||
import com.rbkmoney.fraudbusters.management.domain.enums.ListType;
|
||||
import com.rbkmoney.fraudbusters.management.domain.tables.pojos.WbListRecords;
|
||||
import com.rbkmoney.fraudbusters.management.exception.DaoException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TemplateDao {
|
||||
|
||||
void saveListRecord(WbListRecords listRecord) throws DaoException;
|
||||
|
||||
void removeRecord(String id) throws DaoException;
|
||||
|
||||
void removeRecord(WbListRecords listRecord) throws DaoException;
|
||||
|
||||
WbListRecords getById(String id) throws DaoException;
|
||||
|
||||
List<WbListRecords> getFilteredListRecords(String partyId, String shopId, ListType listType, String listName) throws DaoException;
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.rbkmoney.fraudbusters.management.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TemplateModel {
|
||||
|
||||
private String id;
|
||||
private String template;
|
||||
|
||||
}
|
@ -17,7 +17,7 @@ public class WbListEventListener {
|
||||
private final WbListDao wbListDao;
|
||||
private final EventToListRecordConverter eventToListRecordConverter;
|
||||
|
||||
@KafkaListener(topics = "${kafka.wblist.topic.event.sink}", containerFactory = "kafkaListenerContainerFactory")
|
||||
@KafkaListener(topics = "${kafka.topic.wblist.event.sink}", containerFactory = "kafkaListenerContainerFactory")
|
||||
public void listen(Event event) {
|
||||
log.info("WbListListener event: {}", event);
|
||||
WbListRecords record = eventToListRecordConverter.convert(event);
|
||||
|
@ -0,0 +1,55 @@
|
||||
package com.rbkmoney.fraudbusters.management.resource;
|
||||
|
||||
import com.rbkmoney.damsel.fraudbusters.Command;
|
||||
import com.rbkmoney.damsel.fraudbusters.CommandBody;
|
||||
import com.rbkmoney.damsel.fraudbusters.CommandType;
|
||||
import com.rbkmoney.damsel.fraudbusters.Template;
|
||||
import com.rbkmoney.fraudbusters.management.converter.ListRecordToRowConverter;
|
||||
import com.rbkmoney.fraudbusters.management.converter.WbListRecordsToListRecordConverter;
|
||||
import com.rbkmoney.fraudbusters.management.dao.wblist.WbListDao;
|
||||
import com.rbkmoney.fraudbusters.management.domain.TemplateModel;
|
||||
import com.rbkmoney.fraudbusters.management.service.FraudbustersCommandService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class TemplateManagementResource {
|
||||
|
||||
private final FraudbustersCommandService fraudbustersCommandService;
|
||||
|
||||
@PostMapping(value = "/template")
|
||||
public ResponseEntity<String> insertTemplate(@Validated @RequestBody TemplateModel templateModel) throws ExecutionException, InterruptedException {
|
||||
log.info("TemplateManagementResource insertTemplate templateModel: {}", templateModel);
|
||||
Command command = createCommand(templateModel, CommandType.CREATE);
|
||||
String idMessage = fraudbustersCommandService.sendCommandSync(command);
|
||||
return ResponseEntity.ok().body(idMessage);
|
||||
}
|
||||
|
||||
private Command createCommand(@RequestBody @Validated TemplateModel templateModel, CommandType type) {
|
||||
Command command = new Command();
|
||||
Template template = new Template();
|
||||
template.setTemplate(templateModel.getTemplate().getBytes());
|
||||
command.setCommandBody(CommandBody.template(template));
|
||||
command.setCommandType(type);
|
||||
return command;
|
||||
}
|
||||
|
||||
@DeleteMapping(value = "/template")
|
||||
public ResponseEntity<String> removeTemplate(@Validated @RequestBody TemplateModel templateModel) throws ExecutionException, InterruptedException {
|
||||
log.info("TemplateManagementResource removeTemplate templateModel: {}", templateModel);
|
||||
Command command = createCommand(templateModel, CommandType.DELETE);
|
||||
String idMessage = fraudbustersCommandService.sendCommandSync(command);
|
||||
return ResponseEntity.ok().body(idMessage);
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,7 @@ import com.rbkmoney.fraudbusters.management.converter.WbListRecordsToListRecordC
|
||||
import com.rbkmoney.fraudbusters.management.dao.wblist.WbListDao;
|
||||
import com.rbkmoney.fraudbusters.management.domain.ListRecord;
|
||||
import com.rbkmoney.fraudbusters.management.domain.tables.pojos.WbListRecords;
|
||||
import com.rbkmoney.fraudbusters.management.service.CommandService;
|
||||
import com.rbkmoney.fraudbusters.management.service.WbListCommandService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -28,13 +28,13 @@ public class WbListResource {
|
||||
private final ListRecordToRowConverter listRecordToRowConverter;
|
||||
private final WbListDao wbListDao;
|
||||
private final WbListRecordsToListRecordConverter wbListRecordsToListRecordConverter;
|
||||
private final CommandService commandService;
|
||||
private final WbListCommandService wbListCommandService;
|
||||
|
||||
@PostMapping(value = "/whiteList")
|
||||
public ResponseEntity<String> insertRowToWhite(@Validated @RequestBody ListRecord record) throws ExecutionException, InterruptedException {
|
||||
Row row = listRecordToRowConverter.destinationToSource(record);
|
||||
log.info("WbListResource whiteList add record {}", record);
|
||||
String idMessage = commandService.sendCommandSync(row, ListType.white, Command.CREATE);
|
||||
String idMessage = wbListCommandService.sendCommandSync(row, ListType.white, Command.CREATE);
|
||||
return ResponseEntity.ok().body(idMessage);
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ public class WbListResource {
|
||||
public ResponseEntity<String> removeRowFromWhiteList(@Validated @RequestBody ListRecord record) throws ExecutionException, InterruptedException {
|
||||
Row row = listRecordToRowConverter.destinationToSource(record);
|
||||
log.info("WbListResource whiteList remove record {}", record);
|
||||
String idMessage = commandService.sendCommandSync(row, ListType.white, Command.DELETE);
|
||||
String idMessage = wbListCommandService.sendCommandSync(row, ListType.white, Command.DELETE);
|
||||
return ResponseEntity.ok().body(idMessage);
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ public class WbListResource {
|
||||
public ResponseEntity<String> insertRowToBlack(@RequestBody ListRecord record) throws ExecutionException, InterruptedException {
|
||||
Row row = listRecordToRowConverter.destinationToSource(record);
|
||||
log.info("WbListResource whiteList add record {}", record);
|
||||
String idMessage = commandService.sendCommandSync(row, ListType.black, Command.CREATE);
|
||||
String idMessage = wbListCommandService.sendCommandSync(row, ListType.black, Command.CREATE);
|
||||
return ResponseEntity.ok().body(idMessage);
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ public class WbListResource {
|
||||
public ResponseEntity<String> removeRowFromBlackList(@RequestBody ListRecord record) throws ExecutionException, InterruptedException {
|
||||
Row row = listRecordToRowConverter.destinationToSource(record);
|
||||
log.info("WbListResource whiteList add record {}", record);
|
||||
String idMessage = commandService.sendCommandSync(row, ListType.black, Command.DELETE);
|
||||
String idMessage = wbListCommandService.sendCommandSync(row, ListType.black, Command.DELETE);
|
||||
return ResponseEntity.ok().body(idMessage);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,29 @@
|
||||
package com.rbkmoney.fraudbusters.management.service;
|
||||
|
||||
import com.rbkmoney.damsel.fraudbusters.Command;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class FraudbustersCommandService {
|
||||
|
||||
private final KafkaTemplate kafkaTemplate;
|
||||
|
||||
@Value("${kafka.topic.fraudbusters.template}")
|
||||
public String topicCommand;
|
||||
|
||||
public String sendCommandSync(Command command) throws ExecutionException, InterruptedException {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
command.getCommandBody().getTemplate().setId(uuid);
|
||||
kafkaTemplate.send(topicCommand, uuid, command)
|
||||
.get();
|
||||
return uuid;
|
||||
}
|
||||
|
||||
}
|
@ -14,15 +14,15 @@ import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class CommandService {
|
||||
public class WbListCommandService {
|
||||
|
||||
private final KafkaTemplate kafkaTemplate;
|
||||
|
||||
@Value("${kafka.wblist.topic.command}")
|
||||
@Value("${kafka.topic.wblist.command}")
|
||||
public String topicCommand;
|
||||
|
||||
public String sendCommandSync(Row row, ListType white, Command command) throws ExecutionException, InterruptedException {
|
||||
row.setListType(white);
|
||||
public String sendCommandSync(Row row, ListType type, Command command) throws ExecutionException, InterruptedException {
|
||||
row.setListType(type);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
kafkaTemplate.send(topicCommand, uuid, createChangeCommand(row, command))
|
||||
.get();
|
@ -31,9 +31,13 @@ info:
|
||||
|
||||
kafka:
|
||||
bootstrap.servers: "localhost:29092"
|
||||
wblist.topic:
|
||||
command: "wb-list-command"
|
||||
event.sink: "wb-list-event-sink"
|
||||
topic:
|
||||
wblist:
|
||||
command: "wb-list-command"
|
||||
event.sink: "wb-list-event-sink"
|
||||
fraudbusters:
|
||||
template: "wb-list-command"
|
||||
reference: "wb-list-command"
|
||||
ssl:
|
||||
enable: false
|
||||
keystore-location: src/main/resources/cert/kenny-k.struzhkin.p12
|
||||
|
@ -10,7 +10,7 @@ import com.rbkmoney.fraudbusters.management.exception.DaoException;
|
||||
import com.rbkmoney.fraudbusters.management.exception.KafkaSerializationException;
|
||||
import com.rbkmoney.fraudbusters.management.listener.WbListEventListener;
|
||||
import com.rbkmoney.fraudbusters.management.resource.WbListResource;
|
||||
import com.rbkmoney.fraudbusters.management.service.CommandService;
|
||||
import com.rbkmoney.fraudbusters.management.service.WbListCommandService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
@ -53,11 +53,11 @@ public class ExceptionApplicationTest {
|
||||
public static final String ID_TEST = "42";
|
||||
public static final String TEST_MESSAGE = "test_message";
|
||||
|
||||
@Value("${kafka.wblist.topic.event.sink}")
|
||||
@Value("${kafka.topic.wblist.event.sink}")
|
||||
public String topicEventSink;
|
||||
|
||||
@MockBean
|
||||
public CommandService commandService;
|
||||
public WbListCommandService wbListCommandService;
|
||||
@MockBean
|
||||
public ListRecordToRowConverter listRecordToRowConverter;
|
||||
@MockBean
|
||||
@ -88,7 +88,7 @@ public class ExceptionApplicationTest {
|
||||
@Test(expected = HttpClientErrorException.BadRequest.class)
|
||||
public void executionRestTestBadRequest() throws ExecutionException, InterruptedException {
|
||||
RestTemplate restTemplate = restTemplateBuilder.build();
|
||||
Mockito.when(commandService.sendCommandSync(any(), any(), any())).thenReturn(ID_TEST);
|
||||
Mockito.when(wbListCommandService.sendCommandSync(any(), any(), any())).thenReturn(ID_TEST);
|
||||
|
||||
ListRecord listRecord = new ListRecord();
|
||||
String format = String.format(SERVICE_URL, serverPort);
|
||||
@ -100,7 +100,7 @@ public class ExceptionApplicationTest {
|
||||
@Test
|
||||
public void executionRestTest() throws ExecutionException, InterruptedException {
|
||||
RestTemplate restTemplate = restTemplateBuilder.build();
|
||||
Mockito.when(commandService.sendCommandSync(any(), any(), any())).thenReturn(ID_TEST);
|
||||
Mockito.when(wbListCommandService.sendCommandSync(any(), any(), any())).thenReturn(ID_TEST);
|
||||
|
||||
ListRecord listRecord = createRow();
|
||||
String format = String.format(SERVICE_URL, serverPort);
|
||||
@ -112,7 +112,7 @@ public class ExceptionApplicationTest {
|
||||
@Test(expected = HttpServerErrorException.InternalServerError.class)
|
||||
public void executionRestDaoExceptionTest() throws ExecutionException, InterruptedException {
|
||||
RestTemplate restTemplate = restTemplateBuilder.build();
|
||||
Mockito.when(commandService.sendCommandSync(any(), any(), any())).thenThrow(new DaoException(TEST_MESSAGE));
|
||||
Mockito.when(wbListCommandService.sendCommandSync(any(), any(), any())).thenThrow(new DaoException(TEST_MESSAGE));
|
||||
|
||||
ListRecord listRecord = createRow();
|
||||
String format = String.format(SERVICE_URL, serverPort);
|
||||
@ -122,7 +122,7 @@ public class ExceptionApplicationTest {
|
||||
@Test(expected = HttpServerErrorException.InternalServerError.class)
|
||||
public void executionRestKafkaSerializationTest() throws ExecutionException, InterruptedException {
|
||||
RestTemplate restTemplate = restTemplateBuilder.build();
|
||||
Mockito.when(commandService.sendCommandSync(any(), any(), any())).thenThrow(new KafkaSerializationException(TEST_MESSAGE));
|
||||
Mockito.when(wbListCommandService.sendCommandSync(any(), any(), any())).thenThrow(new KafkaSerializationException(TEST_MESSAGE));
|
||||
|
||||
ListRecord listRecord = createRow();
|
||||
String format = String.format(SERVICE_URL, serverPort);
|
||||
@ -132,7 +132,7 @@ public class ExceptionApplicationTest {
|
||||
@Test(expected = HttpClientErrorException.BadRequest.class)
|
||||
public void getRestTestBadRequest() throws ExecutionException, InterruptedException {
|
||||
RestTemplate restTemplate = restTemplateBuilder.build();
|
||||
Mockito.when(commandService.sendCommandSync(any(), any(), any())).thenThrow(new KafkaSerializationException(TEST_MESSAGE));
|
||||
Mockito.when(wbListCommandService.sendCommandSync(any(), any(), any())).thenThrow(new KafkaSerializationException(TEST_MESSAGE));
|
||||
HashMap<String, Object> uriVariables = new HashMap<>();
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(String.format(SERVICE_URL, serverPort) + "/whiteList")
|
||||
.queryParam("partyId", PARTY_ID)
|
||||
|
@ -46,9 +46,9 @@ public class FraudbustersManagementApplicationTest extends AbstractKafkaIntegrat
|
||||
private static final String PARTY_ID = "partyId";
|
||||
private static final String LIST_NAME = "listName";
|
||||
|
||||
@Value("${kafka.wblist.topic.event.sink}")
|
||||
@Value("${kafka.topic.wblist.event.sink}")
|
||||
public String topicEventSink;
|
||||
@Value("${kafka.wblist.topic.command}")
|
||||
@Value("${kafka.topic.wblist.command}")
|
||||
public String topicCommand;
|
||||
|
||||
@MockBean
|
||||
|
Loading…
Reference in New Issue
Block a user