Skip to content
Snippets Groups Projects
Commit 140d7b6c authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6991 set client on command

parent 04590baa
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,7 @@ public interface Command { ...@@ -44,7 +44,7 @@ public interface Command {
public String getCreatedBy(); public String getCreatedBy();
public String getCreatedByName(); public String getCreatedByName();
public CommandStatus getStatus(); public CommandStatus getStatus();
String getCreatedByClient(); String getCreatedByClientName();
public Map<String, Object> getBodyObject(); public Map<String, Object> getBodyObject();
public Map<String, String> getBody(); public Map<String, String> getBody();
......
...@@ -21,7 +21,7 @@ public class TestCommand implements Command { ...@@ -21,7 +21,7 @@ public class TestCommand implements Command {
private ZonedDateTime finishedAt; private ZonedDateTime finishedAt;
private String createdBy; private String createdBy;
private String createdByName; private String createdByName;
private String createdByClient; private String createdByClientName;
private CommandStatus status; private CommandStatus status;
......
...@@ -87,6 +87,7 @@ public class CommandService { ...@@ -87,6 +87,7 @@ public class CommandService {
.body(request.getBody()) .body(request.getBody())
.bodyObject(request.getBodyObject()); .bodyObject(request.getBodyObject());
userService.findUser().map(CallContextUser::getClientName).ifPresent(builder::createdByClientName);
builder = addUserIfExists(builder, Optional.ofNullable(request.getCallContext()).map(CallContext::getUser), userService.findUser()); builder = addUserIfExists(builder, Optional.ofNullable(request.getCallContext()).map(CallContext::getUser), userService.findUser());
return builder.build(); return builder.build();
} }
......
...@@ -63,7 +63,7 @@ public class PersistedCommand implements Command { ...@@ -63,7 +63,7 @@ public class PersistedCommand implements Command {
private String createdBy; private String createdBy;
private String createdByName; private String createdByName;
private String createdByClient; private String createdByClientName;
@Setter @Setter
private CommandStatus status; private CommandStatus status;
......
...@@ -237,7 +237,7 @@ public class VorgangService { ...@@ -237,7 +237,7 @@ public class VorgangService {
} }
void validateLockCommand(Command command) { void validateLockCommand(Command command) {
if (Objects.isNull(command.getCreatedByClient())) { if (Objects.isNull(command.getCreatedByClientName())) {
throw new TechnicalException("Missing client name in lock command"); throw new TechnicalException("Missing client name in lock command");
} }
if (Objects.isNull(getReason(command.getBodyObject()))) { if (Objects.isNull(getReason(command.getBodyObject()))) {
...@@ -247,7 +247,7 @@ public class VorgangService { ...@@ -247,7 +247,7 @@ public class VorgangService {
Map<String, Object> buildLockPatch(Command command) { Map<String, Object> buildLockPatch(Command command) {
return Map.of(KEY_HEADER_LOCK, Map.of( return Map.of(KEY_HEADER_LOCK, Map.of(
Lock.FIELD_CLIENT_NAME, command.getCreatedByClient(), Lock.FIELD_CLIENT_NAME, command.getCreatedByClientName(),
Lock.FIELD_LOCKED_SINCE, ZonedDateTime.now(ZoneId.of("UTC")), Lock.FIELD_LOCKED_SINCE, ZonedDateTime.now(ZoneId.of("UTC")),
Lock.FIELD_REASON, getReason(command.getBodyObject()))); Lock.FIELD_REASON, getReason(command.getBodyObject())));
} }
......
...@@ -102,6 +102,15 @@ class CommandServiceTest { ...@@ -102,6 +102,15 @@ class CommandServiceTest {
assertThat(command.getRelationVersion()).isEqualTo(CreateCommandRequestTestFactory.RELATION_VERSION); assertThat(command.getRelationVersion()).isEqualTo(CreateCommandRequestTestFactory.RELATION_VERSION);
} }
@Test
void shouldSetClientName() {
when(currentUserService.findUser()).thenReturn(Optional.of(CallContextUserTestFactory.create()));
var command = (PersistedCommand) service.createCommand(request);
assertThat(command.getCreatedByClientName()).isEqualTo(CallContextTestFactory.CLIENT);
}
@Test @Test
void shouldHandleMissingCallContext() { void shouldHandleMissingCallContext() {
var request = CreateCommandRequestTestFactory.createBuilder().callContext(null).build(); var request = CreateCommandRequestTestFactory.createBuilder().callContext(null).build();
......
...@@ -61,7 +61,7 @@ public class CommandTestFactory { ...@@ -61,7 +61,7 @@ public class CommandTestFactory {
.createdAt(CREATED_AT) .createdAt(CREATED_AT)
.createdBy(CREATED_BY) .createdBy(CREATED_BY)
.createdByName(CREATED_BY_NAME) .createdByName(CREATED_BY_NAME)
.createdByClient(CREATED_BY_CLIENT) .createdByClientName(CREATED_BY_CLIENT)
.status(STATUS) .status(STATUS)
.relationId(RELATION_ID) .relationId(RELATION_ID)
.relationVersion(RELATION_VERSION) .relationVersion(RELATION_VERSION)
......
...@@ -563,7 +563,7 @@ class VorgangServiceTest { ...@@ -563,7 +563,7 @@ class VorgangServiceTest {
@Test @Test
void shouldThrowExceptionOnMissingClient() { void shouldThrowExceptionOnMissingClient() {
var command = CommandTestFactory.createBuilder().createdByClient(null).build(); var command = CommandTestFactory.createBuilder().createdByClientName(null).build();
assertThrows(TechnicalException.class, () -> service.validateLockCommand(command)); assertThrows(TechnicalException.class, () -> service.validateLockCommand(command));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment