mirror of
https://github.com/valitydev/wb-list-manager.git
synced 2024-11-06 01:35:17 +00:00
refactoring
This commit is contained in:
parent
6d3ef0d162
commit
7c62728776
@ -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";
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.rbkmoney.wb.list.manager.exception;
|
||||
|
||||
public class UnknownRowTypeException extends RuntimeException {
|
||||
public class UnknownRowTypeException extends RuntimeException { // TODO нужно ли оно?
|
||||
|
||||
public UnknownRowTypeException() {
|
||||
}
|
||||
|
@ -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!");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user