refactoring

This commit is contained in:
ggmaleva 2021-09-29 12:37:58 +03:00
parent 6d3ef0d162
commit 7c62728776
No known key found for this signature in database
GPG Key ID: 0E412B78565B108F
5 changed files with 28 additions and 35 deletions

View File

@ -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";

View File

@ -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);
}
}

View File

@ -1,6 +1,6 @@
package com.rbkmoney.wb.list.manager.exception;
public class UnknownRowTypeException extends RuntimeException {
public class UnknownRowTypeException extends RuntimeException { // TODO нужно ли оно?
public UnknownRowTypeException() {
}

View File

@ -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!");
}
};
}
}

View File

@ -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;
}
}