Skip to content
Snippets Groups Projects
Commit 2d8c3890 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-5630 implement comments from code review

parent d3355a74
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<properties> <properties>
<vorgang-manager.version>2.7.0-SNAPSHOT</vorgang-manager.version> <vorgang-manager.version>2.7.0-SNAPSHOT</vorgang-manager.version>
<nachrichten-manager.version>2.7.0-SNAPSHOT</nachrichten-manager.version> <nachrichten-manager.version>2.7.0-SNAPSHOT</nachrichten-manager.version>
<api-lib.version>0.7.0</api-lib.version> <api-lib.version>0.8.0-SNAPSHOT</api-lib.version>
</properties> </properties>
<dependencies> <dependencies>
......
...@@ -46,7 +46,7 @@ public class Bescheid { ...@@ -46,7 +46,7 @@ public class Bescheid {
private Vorgang.ServiceKonto serviceKonto; private Vorgang.ServiceKonto serviceKonto;
public enum Status { public enum Status {
DRAFT, BESCHEID, SEND; DRAFT, SEND;
public boolean not(String value) { public boolean not(String value) {
return !hasValue(value); return !hasValue(value);
......
package de.ozgcloud.bescheid; package de.ozgcloud.bescheid;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
...@@ -137,12 +136,11 @@ class BescheidService { ...@@ -137,12 +136,11 @@ class BescheidService {
} }
void sendBescheid(AttachedItem bescheidItem) { void sendBescheid(AttachedItem bescheidItem) {
attachedItemService.patch(setBescheidSendStatus(bescheidItem)); attachedItemService.setBescheidStatus(bescheidItem.getId(), bescheidItem.getVersion(), Bescheid.Status.SEND);
try { try {
vorgangService.bescheiden(bescheidItem.getVorgangId()); vorgangService.bescheiden(bescheidItem.getVorgangId());
} catch (Exception e) { } catch (Exception e) {
var item = attachedItemService.getItem(bescheidItem.getId()); attachedItemService.setBescheidStatus(bescheidItem.getId(), bescheidItem.getVersion(), Bescheid.Status.DRAFT);
attachedItemService.patch(setBescheidDraftStatus(item));
throw e; throw e;
} }
bescheidClientAttributeService.setAntragResult(bescheidItem.getVorgangId(), getBewilligt(bescheidItem)); bescheidClientAttributeService.setAntragResult(bescheidItem.getVorgangId(), getBewilligt(bescheidItem));
...@@ -152,14 +150,6 @@ class BescheidService { ...@@ -152,14 +150,6 @@ class BescheidService {
return MapUtils.getBooleanValue(bescheidItem.getItem(), Bescheid.FIELD_BEWILLIGT, false); return MapUtils.getBooleanValue(bescheidItem.getItem(), Bescheid.FIELD_BEWILLIGT, false);
} }
AttachedItem setBescheidSendStatus(AttachedItem bescheidItem) {
return bescheidItem.toBuilder().item(Map.of(Bescheid.FIELD_STATUS, Bescheid.Status.SEND.name())).build();
}
AttachedItem setBescheidDraftStatus(AttachedItem bescheidItem) {
return bescheidItem.toBuilder().item(Map.of(Bescheid.FIELD_STATUS, Bescheid.Status.DRAFT.name())).build();
}
public BescheidManagerConfig getConfig() { public BescheidManagerConfig getConfig() {
return BescheidManagerConfig.builder() return BescheidManagerConfig.builder()
.version(buildProperties.getVersion()) .version(buildProperties.getVersion())
......
...@@ -36,6 +36,7 @@ import org.springframework.stereotype.Service; ...@@ -36,6 +36,7 @@ import org.springframework.stereotype.Service;
import de.ozgcloud.apilib.common.command.OzgCloudCommand; import de.ozgcloud.apilib.common.command.OzgCloudCommand;
import de.ozgcloud.apilib.common.command.OzgCloudCommandService; import de.ozgcloud.apilib.common.command.OzgCloudCommandService;
import de.ozgcloud.apilib.common.command.grpc.CommandMapper; import de.ozgcloud.apilib.common.command.grpc.CommandMapper;
import de.ozgcloud.bescheid.Bescheid;
import de.ozgcloud.bescheid.BescheidCallContextAttachingInterceptor; import de.ozgcloud.bescheid.BescheidCallContextAttachingInterceptor;
import de.ozgcloud.command.Command; import de.ozgcloud.command.Command;
import de.ozgcloud.common.errorhandling.TechnicalException; import de.ozgcloud.common.errorhandling.TechnicalException;
...@@ -190,28 +191,21 @@ public class AttachedItemService { ...@@ -190,28 +191,21 @@ public class AttachedItemService {
return remoteService.getItem(id); return remoteService.getItem(id);
} }
public void patch(AttachedItem item) { public void setBescheidStatus(String id, long version, Bescheid.Status status) {
commandService.createAndWaitUntilDone(buildPatchBescheidCommand(item)); commandService.createAndWaitUntilDone(buildPatchBescheidCommand(id, version, status));
} }
OzgCloudCommand buildPatchBescheidCommand(AttachedItem bescheidItem) { OzgCloudCommand buildPatchBescheidCommand(String bescheidId, long bescheidVersion, Bescheid.Status bescheidStatus) {
return OzgCloudCommand.builder() return OzgCloudCommand.builder()
.vorgangId(commandMapper.toOzgCloudVorgangId(bescheidItem.getVorgangId())) .relationId(commandMapper.mapRelationId(bescheidId))
.relationId(commandMapper.mapRelationId(bescheidItem.getId())) .relationVersion(bescheidVersion)
.relationVersion(bescheidItem.getVersion())
.order(PATCH_ATTACHED_ITEM) .order(PATCH_ATTACHED_ITEM)
.bodyObject(buildObjectMap(bescheidItem)) .bodyObject(buildObjectMap(bescheidId, bescheidStatus))
.build(); .build();
} }
Map<String, Object> buildObjectMap(AttachedItem bescheidItem) { Map<String, Object> buildObjectMap(String bescheidId, Bescheid.Status bescheidStatus) {
var bodyObject = new HashMap<String, Object>(); return Map.of(AttachedItem.PROPERTY_ID, bescheidId,
bodyObject.put(AttachedItem.PROPERTY_ID, bescheidItem.getId()); AttachedItem.PROPERTY_ITEM, Map.of(Bescheid.FIELD_STATUS, bescheidStatus.name()));
bodyObject.put(AttachedItem.PROPERTY_CLIENT, bescheidItem.getClient());
bodyObject.put(AttachedItem.PROPERTY_VORGANG_ID, bescheidItem.getVorgangId());
bodyObject.put(AttachedItem.PROPERTY_ITEM_NAME, bescheidItem.getItemName());
bodyObject.put(AttachedItem.PROPERTY_VERSION, bescheidItem.getVersion());
bodyObject.put(AttachedItem.PROPERTY_ITEM, bescheidItem.getItem());
return bodyObject;
} }
} }
...@@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.*; ...@@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
...@@ -26,6 +25,7 @@ import org.springframework.test.util.ReflectionTestUtils; ...@@ -26,6 +25,7 @@ import org.springframework.test.util.ReflectionTestUtils;
import de.ozgcloud.bescheid.attacheditem.AttachedItem; import de.ozgcloud.bescheid.attacheditem.AttachedItem;
import de.ozgcloud.bescheid.attacheditem.AttachedItemService; import de.ozgcloud.bescheid.attacheditem.AttachedItemService;
import de.ozgcloud.bescheid.attacheditem.AttachedItemTestFactory; import de.ozgcloud.bescheid.attacheditem.AttachedItemTestFactory;
import de.ozgcloud.bescheid.attacheditem.BescheidItemTestFactory;
import de.ozgcloud.bescheid.attributes.ClientAttributeService; import de.ozgcloud.bescheid.attributes.ClientAttributeService;
import de.ozgcloud.bescheid.common.callcontext.CurrentUserService; import de.ozgcloud.bescheid.common.callcontext.CurrentUserService;
import de.ozgcloud.bescheid.common.callcontext.UserProfile; import de.ozgcloud.bescheid.common.callcontext.UserProfile;
...@@ -462,19 +462,10 @@ class BescheidServiceTest { ...@@ -462,19 +462,10 @@ class BescheidServiceTest {
private AttachedItem bescheidSendItem; private AttachedItem bescheidSendItem;
@Test @Test
void shouldCallBuildBescheidSend() { void shouldCallSetBescheidStatusSent() {
sendBescheid(); sendBescheid();
verify(service).setBescheidSendStatus(bescheidItem); verify(attachedItemService).setBescheidStatus(BescheidItemTestFactory.ID, BescheidItemTestFactory.VERSION, Bescheid.Status.SEND);
}
@Test
void shouldCallPatch() {
doReturn(bescheidSendItem).when(service).setBescheidSendStatus(any());
sendBescheid();
verify(attachedItemService).patch(bescheidSendItem);
} }
@Test @Test
...@@ -485,34 +476,12 @@ class BescheidServiceTest { ...@@ -485,34 +476,12 @@ class BescheidServiceTest {
} }
@Test @Test
void shouldCallGetItem() { void shouldCallSetBescheidStatusDraft() {
when(attachedItemService.getItem(any())).thenReturn(AttachedItemTestFactory.createBescheid());
doThrow(new TechnicalException("error")).when(vorgangService).bescheiden(anyString()); doThrow(new TechnicalException("error")).when(vorgangService).bescheiden(anyString());
assertThrows(TechnicalException.class, this::sendBescheid); assertThrows(TechnicalException.class, this::sendBescheid);
verify(attachedItemService).getItem(AttachedItemTestFactory.ID); verify(attachedItemService).setBescheidStatus(BescheidItemTestFactory.ID, BescheidItemTestFactory.VERSION, Bescheid.Status.SEND);
}
@Test
void shouldCallSetBescheidDraftStatus() {
doThrow(new TechnicalException("error")).when(vorgangService).bescheiden(anyString());
var updatedBescheidUitem = AttachedItemTestFactory.createBescheid();
when(attachedItemService.getItem(any())).thenReturn(updatedBescheidUitem);
assertThrows(TechnicalException.class, this::sendBescheid);
verify(service).setBescheidDraftStatus(updatedBescheidUitem);
}
@Test
void shouldCallPatchWhenBescheidenFails() {
doReturn(bescheidSendItem).when(service).setBescheidDraftStatus(any());
doThrow(new TechnicalException("error")).when(vorgangService).bescheiden(anyString());
assertThrows(TechnicalException.class, this::sendBescheid);
verify(attachedItemService).patch(bescheidSendItem);
} }
@Test @Test
...@@ -558,32 +527,6 @@ class BescheidServiceTest { ...@@ -558,32 +527,6 @@ class BescheidServiceTest {
} }
} }
@Nested
class TestSetBescheidSendStatus {
@Test
void shouldSetSendStatus() {
var bescheidItem = AttachedItemTestFactory.createBescheid();
var result = service.setBescheidSendStatus(bescheidItem);
assertThat(result.getItem()).containsEntry(Bescheid.FIELD_STATUS, Bescheid.Status.SEND.name());
}
}
@Nested
class TestSetBescheidDraftStatus {
@Test
void shouldSetDraftStatus() {
var bescheidItem = AttachedItemTestFactory.createBescheidBuilder().item(Collections.emptyMap()).build();
var result = service.setBescheidDraftStatus(bescheidItem);
assertThat(result.getItem()).containsEntry(Bescheid.FIELD_STATUS, Bescheid.Status.DRAFT.name());
}
}
@Nested @Nested
class TestGetConfig { class TestGetConfig {
......
...@@ -48,6 +48,7 @@ import de.ozgcloud.apilib.common.command.OzgCloudCommandService; ...@@ -48,6 +48,7 @@ import de.ozgcloud.apilib.common.command.OzgCloudCommandService;
import de.ozgcloud.apilib.common.command.grpc.CommandMapper; import de.ozgcloud.apilib.common.command.grpc.CommandMapper;
import de.ozgcloud.apilib.common.datatypes.GenericId; import de.ozgcloud.apilib.common.datatypes.GenericId;
import de.ozgcloud.apilib.vorgang.OzgCloudVorgangId; import de.ozgcloud.apilib.vorgang.OzgCloudVorgangId;
import de.ozgcloud.bescheid.Bescheid;
import de.ozgcloud.bescheid.BescheidCallContextAttachingInterceptor; import de.ozgcloud.bescheid.BescheidCallContextAttachingInterceptor;
import de.ozgcloud.command.Command; import de.ozgcloud.command.Command;
import de.ozgcloud.command.CommandTestFactory; import de.ozgcloud.command.CommandTestFactory;
...@@ -759,44 +760,31 @@ class AttachedItemServiceTest { ...@@ -759,44 +760,31 @@ class AttachedItemServiceTest {
void shouldCallBuildPatchBescheidCommand() { void shouldCallBuildPatchBescheidCommand() {
var item = AttachedItemTestFactory.createDocument(); var item = AttachedItemTestFactory.createDocument();
service.patch(item); setBescheidStatus();
verify(service).buildPatchBescheidCommand(item); verify(service).buildPatchBescheidCommand(AttachedItemTestFactory.ID, AttachedItemTestFactory.VERSION, Bescheid.Status.DRAFT);
} }
@Test @Test
void shouldCallCommandService() { void shouldCallCommandService() {
doReturn(command).when(service).buildPatchBescheidCommand(any()); doReturn(command).when(service).buildPatchBescheidCommand(any(), anyLong(), any());
service.patch(AttachedItemTestFactory.createDocument()); setBescheidStatus();
verify(commandService).createAndWaitUntilDone(command); verify(commandService).createAndWaitUntilDone(command);
} }
private void setBescheidStatus() {
service.setBescheidStatus(AttachedItemTestFactory.ID, AttachedItemTestFactory.VERSION, Bescheid.Status.DRAFT);
}
} }
@Nested @Nested
class TestBuildPatchBescheidCommand { class TestBuildPatchBescheidCommand {
@Test
void shouldCallVorgangIdMapper() {
service.buildPatchBescheidCommand(AttachedItemTestFactory.createDocument());
verify(commandMapper).toOzgCloudVorgangId(CommandTestFactory.VORGANG_ID);
}
@Test
void shouldSetVorgangId() {
var expectedVorgangId = OzgCloudVorgangId.from(CommandTestFactory.VORGANG_ID);
when(commandMapper.toOzgCloudVorgangId(any())).thenReturn(expectedVorgangId);
var result = service.buildPatchBescheidCommand(AttachedItemTestFactory.createDocument());
assertThat(result.getVorgangId()).isEqualTo(expectedVorgangId);
}
@Test @Test
void shouldCallRelationIdMapper() { void shouldCallRelationIdMapper() {
service.buildPatchBescheidCommand(AttachedItemTestFactory.createDocument()); buildPatchBescheidCommand();
verify(commandMapper).mapRelationId(AttachedItemTestFactory.ID); verify(commandMapper).mapRelationId(AttachedItemTestFactory.ID);
} }
...@@ -806,92 +794,62 @@ class AttachedItemServiceTest { ...@@ -806,92 +794,62 @@ class AttachedItemServiceTest {
var expectedId = GenericId.from(AttachedItemTestFactory.ID); var expectedId = GenericId.from(AttachedItemTestFactory.ID);
when(commandMapper.mapRelationId(any())).thenReturn(expectedId); when(commandMapper.mapRelationId(any())).thenReturn(expectedId);
var result = service.buildPatchBescheidCommand(AttachedItemTestFactory.createDocument()); var result = buildPatchBescheidCommand();
assertThat(result.getRelationId()).isEqualTo(expectedId); assertThat(result.getRelationId()).isEqualTo(expectedId);
} }
@Test @Test
void shouldSetRelationVersion() { void shouldSetRelationVersion() {
var result = service.buildPatchBescheidCommand(AttachedItemTestFactory.createDocument()); var result = buildPatchBescheidCommand();
assertThat(result.getRelationVersion()).isEqualTo(AttachedItemTestFactory.VERSION); assertThat(result.getRelationVersion()).isEqualTo(AttachedItemTestFactory.VERSION);
} }
@Test @Test
void shouldSetOrder() { void shouldSetOrder() {
var result = service.buildPatchBescheidCommand(AttachedItemTestFactory.createDocument()); var result = buildPatchBescheidCommand();
assertThat(result.getOrder()).isEqualTo(AttachedItemService.PATCH_ATTACHED_ITEM); assertThat(result.getOrder()).isEqualTo(AttachedItemService.PATCH_ATTACHED_ITEM);
} }
@Test @Test
void shouldCallBuildObjectMap() { void shouldCallBuildObjectMap() {
var bescheidItem = AttachedItemTestFactory.createDocument(); var result = buildPatchBescheidCommand();
service.buildPatchBescheidCommand(bescheidItem); verify(service).buildObjectMap(AttachedItemTestFactory.ID, Bescheid.Status.DRAFT);
verify(service).buildObjectMap(bescheidItem);
} }
@Test @Test
void shouldSetBodyObject() { void shouldSetBodyObject() {
var expectedMap = Map.of("key", (Object) "value"); var bodyObject = Map.of("key", (Object) "value");
doReturn(expectedMap).when(service).buildObjectMap(any()); doReturn(bodyObject).when(service).buildObjectMap(any(), any());
var result = service.buildPatchBescheidCommand(AttachedItemTestFactory.createDocument());
assertThat(result.getBodyObject()).containsAllEntriesOf(expectedMap);
}
}
@Nested
class TestBuildBodyObject {
@Test var result = buildPatchBescheidCommand();
void shouldSetId() {
var result = buildObjectMap();
assertThat(result).containsEntry(AttachedItem.PROPERTY_ID, AttachedItemTestFactory.ID); assertThat(result.getBodyObject()).isSameAs(bodyObject);
} }
@Test private OzgCloudCommand buildPatchBescheidCommand() {
void shouldSetClient() { return service.buildPatchBescheidCommand(BescheidItemTestFactory.ID, BescheidItemTestFactory.VERSION, Bescheid.Status.DRAFT);
var result = buildObjectMap();
assertThat(result).containsEntry(AttachedItem.PROPERTY_CLIENT, AttachedItemTestFactory.CLIENT);
} }
@Test
void shouldSetVorgangId() {
var result = buildObjectMap();
assertThat(result).containsEntry(AttachedItem.PROPERTY_VORGANG_ID, CommandTestFactory.VORGANG_ID);
} }
@Test @Nested
void shouldSetItemName() { class TestBuildObjectMap {
var result = buildObjectMap();
assertThat(result).containsEntry(AttachedItem.PROPERTY_ITEM_NAME, AttachedItemService.BESCHEID_ITEM_NAME);
}
@Test @Test
void shouldSetVersion() { void shouldSetBescheidId() {
var result = buildObjectMap(); var result = service.buildObjectMap(AttachedItemTestFactory.ID, Bescheid.Status.DRAFT);
assertThat(result).containsEntry(AttachedItem.PROPERTY_VERSION, AttachedItemTestFactory.VERSION); assertThat(result).containsEntry(AttachedItem.PROPERTY_ID, AttachedItemTestFactory.ID);
} }
@Test @Test
void shouldSetItem() { void shouldSetBescheidStatus() {
var result = buildObjectMap(); var result = service.buildObjectMap(AttachedItemTestFactory.ID, Bescheid.Status.DRAFT);
assertThat(result).containsEntry(AttachedItem.PROPERTY_ITEM, AttachedItemTestFactory.createBescheidItem());
}
private Map<String, Object> buildObjectMap() { assertThat(result).extracting(AttachedItem.PROPERTY_ITEM, MAP).containsEntry(Bescheid.FIELD_STATUS, Bescheid.Status.DRAFT.name());
return service.buildObjectMap(AttachedItemTestFactory.createBescheid());
} }
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment