diff --git a/src/main/java/com/rbkmoney/wb/list/manager/constant/RowType.java b/src/main/java/com/rbkmoney/wb/list/manager/constant/RowType.java index c09f27e..4cd055a 100644 --- a/src/main/java/com/rbkmoney/wb/list/manager/constant/RowType.java +++ b/src/main/java/com/rbkmoney/wb/list/manager/constant/RowType.java @@ -1,5 +1,9 @@ package com.rbkmoney.wb.list.manager.constant; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class RowType { public static final String P_2_P = "p2p"; diff --git a/src/main/java/com/rbkmoney/wb/list/manager/exception/RiakExecutionException.java b/src/main/java/com/rbkmoney/wb/list/manager/exception/RiakExecutionException.java index 8645972..85fdbb3 100644 --- a/src/main/java/com/rbkmoney/wb/list/manager/exception/RiakExecutionException.java +++ b/src/main/java/com/rbkmoney/wb/list/manager/exception/RiakExecutionException.java @@ -5,22 +5,7 @@ public class RiakExecutionException extends RuntimeException { public RiakExecutionException() { } - public RiakExecutionException(String message) { - super(message); - } - - public RiakExecutionException(String message, Throwable cause) { - super(message, cause); - } - public RiakExecutionException(Throwable cause) { super(cause); } - - public RiakExecutionException(String message, - Throwable cause, - boolean enableSuppression, - boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } } diff --git a/src/main/java/com/rbkmoney/wb/list/manager/exception/UnknownRowTypeException.java b/src/main/java/com/rbkmoney/wb/list/manager/exception/UnknownRowTypeException.java index 2605d2f..a40a90f 100644 --- a/src/main/java/com/rbkmoney/wb/list/manager/exception/UnknownRowTypeException.java +++ b/src/main/java/com/rbkmoney/wb/list/manager/exception/UnknownRowTypeException.java @@ -1,6 +1,6 @@ package com.rbkmoney.wb.list.manager.exception; -public class UnknownRowTypeException extends RuntimeException { +public class UnknownRowTypeException extends RuntimeException { // TODO нужно ли оно? public UnknownRowTypeException() { } diff --git a/src/main/java/com/rbkmoney/wb/list/manager/service/CommandServiceImpl.java b/src/main/java/com/rbkmoney/wb/list/manager/service/CommandServiceImpl.java index c9fba1e..19085bd 100644 --- a/src/main/java/com/rbkmoney/wb/list/manager/service/CommandServiceImpl.java +++ b/src/main/java/com/rbkmoney/wb/list/manager/service/CommandServiceImpl.java @@ -21,24 +21,28 @@ public class CommandServiceImpl implements CommandService { @Override public Event apply(ChangeCommand command) { log.info("CommandService apply command: {}", command); - Event event = new Event(); Row row = commandToRowConverter.convert(command); log.info("CommandService apply row: {}", row); - switch (command.command) { - case CREATE: - listRepository.create(row); - event.setEventType(EventType.CREATED); - break; - case DELETE: - listRepository.remove(row); - event.setEventType(EventType.DELETED); - break; - default: - log.warn("CommandService command for list not found! command: {}", command); - throw new RuntimeException("WbListStreamFactory command for list not found!"); - } + Event event = applyCommandAndGetEvent(command, row); event.setRow(command.getRow()); return event; } + private Event applyCommandAndGetEvent(ChangeCommand command, Row row) { + return switch (command.getCommand()) { + case CREATE -> { + listRepository.create(row); + yield new Event().setEventType(EventType.CREATED); + } + case DELETE -> { + listRepository.remove(row); + yield new Event().setEventType(EventType.DELETED); + } + default -> { + log.warn("CommandService command for list not found! command: {}", command); + throw new RuntimeException("WbListStreamFactory command for list not found!"); + } + }; + } + } diff --git a/src/main/java/com/rbkmoney/wb/list/manager/utils/KeyGenerator.java b/src/main/java/com/rbkmoney/wb/list/manager/utils/KeyGenerator.java index 210c27f..93d6471 100644 --- a/src/main/java/com/rbkmoney/wb/list/manager/utils/KeyGenerator.java +++ b/src/main/java/com/rbkmoney/wb/list/manager/utils/KeyGenerator.java @@ -28,7 +28,7 @@ public class KeyGenerator { public static String generateKey(ListType listType, String listName, String value, String... params) { StringBuilder stringBuilder = new StringBuilder(); - if (params != null) { + if (params != null && params.length != 0) { for (String param : params) { addIfExist(param, stringBuilder); } @@ -42,11 +42,11 @@ public class KeyGenerator { .toString(); } - private static StringBuilder addIfExist(String id, StringBuilder stringBuilder) { - if (!StringUtils.isEmpty(id)) { - stringBuilder.append(id) + private static void addIfExist(String param, StringBuilder stringBuilder) { + if (StringUtils.hasLength(param)) { + stringBuilder + .append(param) .append(DELIMITER); } - return stringBuilder; } }