Skip to content
Snippets Groups Projects
Commit 6114d231 authored by OZGCloud's avatar OZGCloud
Browse files

Merge pull request 'OZG-5570-bescheid-kein-smartdocuments' (#551) from...

Merge pull request 'OZG-5570-bescheid-kein-smartdocuments' (#551) from OZG-5570-bescheid-kein-smartdocuments into master

Reviewed-on: https://git.ozg-sh.de/ozgcloud-app/alfa/pulls/551


Reviewed-by: default avatarOZGCloud <ozgcloud@mgm-tp.com>
parents 56c58aa8 6785e6ae
No related branches found
No related tags found
No related merge requests found
Showing
with 173 additions and 24 deletions
...@@ -3,7 +3,8 @@ export enum BescheidLinkRel { ...@@ -3,7 +3,8 @@ export enum BescheidLinkRel {
UPLOAD_BESCHEID_FILE = 'uploadBescheidFile', UPLOAD_BESCHEID_FILE = 'uploadBescheidFile',
UPLOAD_ATTACHMENT = 'uploadAttachment', UPLOAD_ATTACHMENT = 'uploadAttachment',
UPDATE = 'update', UPDATE = 'update',
CREATE_BESCHEID_DOCUMENT = 'createBescheidDocument', CREATE_DOCUMENT = 'createDocument',
CREATE_DOCUMENT_FROM_FILE = 'createDocumentFromFile',
ATTACHMENTS = 'attachments', ATTACHMENTS = 'attachments',
BESCHEID_DOCUMENT = 'bescheidDocument', BESCHEID_DOCUMENT = 'bescheidDocument',
SEND = 'send', SEND = 'send',
......
...@@ -66,7 +66,7 @@ describe('BescheidUtil', () => { ...@@ -66,7 +66,7 @@ describe('BescheidUtil', () => {
binaryFileResource, binaryFileResource,
); );
expect(props.linkRel).toBe(BescheidLinkRel.CREATE_BESCHEID_DOCUMENT); expect(props.linkRel).toBe(BescheidLinkRel.CREATE_DOCUMENT_FROM_FILE);
}); });
describe('command', () => { describe('command', () => {
...@@ -195,7 +195,7 @@ describe('BescheidUtil', () => { ...@@ -195,7 +195,7 @@ describe('BescheidUtil', () => {
it('should have linkRel', () => { it('should have linkRel', () => {
const props: CreateCommandProps = buildCreateBescheidDocumentCommandProps(bescheidResource); const props: CreateCommandProps = buildCreateBescheidDocumentCommandProps(bescheidResource);
expect(props.linkRel).toBe(BescheidLinkRel.CREATE_BESCHEID_DOCUMENT); expect(props.linkRel).toBe(BescheidLinkRel.CREATE_DOCUMENT);
}); });
describe('command', () => { describe('command', () => {
......
...@@ -28,7 +28,7 @@ export function buildCreateBescheidDocumentFromFileProps( ...@@ -28,7 +28,7 @@ export function buildCreateBescheidDocumentFromFileProps(
): CreateCommandProps { ): CreateCommandProps {
return { return {
resource: bescheid, resource: bescheid,
linkRel: BescheidLinkRel.CREATE_BESCHEID_DOCUMENT, linkRel: BescheidLinkRel.CREATE_DOCUMENT_FROM_FILE,
command: buildCreateBescheidDocumentFromFileCommand(binaryFile), command: buildCreateBescheidDocumentFromFileCommand(binaryFile),
snackBarMessage: EMPTY_STRING, snackBarMessage: EMPTY_STRING,
}; };
...@@ -67,7 +67,7 @@ export function buildCreateBescheidDocumentCommandProps( ...@@ -67,7 +67,7 @@ export function buildCreateBescheidDocumentCommandProps(
): CreateCommandProps { ): CreateCommandProps {
return { return {
resource, resource,
linkRel: BescheidLinkRel.CREATE_BESCHEID_DOCUMENT, linkRel: BescheidLinkRel.CREATE_DOCUMENT,
command: { command: {
order: CommandOrder.CREATE_BESCHEID_DOCUMENT, order: CommandOrder.CREATE_BESCHEID_DOCUMENT,
body: null, body: null,
......
<ng-container *ngIf="bescheidDraftStateResource.resource as bescheidDraft"> <ng-container *ngIf="bescheidDraftStateResource.resource as bescheidDraft">
<div class="mt-4"> <div class="mt-4">
<ods-button <ods-button
*ngIf="bescheidDraft | hasLink: bescheidLinkRel.CREATE_BESCHEID_DOCUMENT" *ngIf="bescheidDraft | hasLink: bescheidLinkRel.CREATE_DOCUMENT"
class="w-72" class="w-72"
[isLoading]="(createBescheidDocumentInProgress$ | async).loading" [isLoading]="(createBescheidDocumentInProgress$ | async).loading"
(click)="createBescheidDocument()" (click)="createBescheidDocument()"
......
...@@ -60,7 +60,7 @@ describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => { ...@@ -60,7 +60,7 @@ describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => {
describe('create bescheid document button', () => { describe('create bescheid document button', () => {
beforeEach(() => { beforeEach(() => {
component.bescheidDraftStateResource = createStateResource( component.bescheidDraftStateResource = createStateResource(
createBescheidResource([BescheidLinkRel.CREATE_BESCHEID_DOCUMENT]), createBescheidResource([BescheidLinkRel.CREATE_DOCUMENT]),
); );
fixture.detectChanges(); fixture.detectChanges();
...@@ -81,7 +81,7 @@ describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => { ...@@ -81,7 +81,7 @@ describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => {
it('should be visible if link is present', () => { it('should be visible if link is present', () => {
component.bescheidDraftStateResource = createStateResource( component.bescheidDraftStateResource = createStateResource(
createBescheidResource([BescheidLinkRel.CREATE_BESCHEID_DOCUMENT]), createBescheidResource([BescheidLinkRel.CREATE_DOCUMENT]),
); );
fixture.detectChanges(); fixture.detectChanges();
......
...@@ -23,12 +23,15 @@ public class BescheidModelAssembler implements RepresentationModelAssembler<Besc ...@@ -23,12 +23,15 @@ public class BescheidModelAssembler implements RepresentationModelAssembler<Besc
static final String REL_UPLOAD_ATTACHMENT = "uploadAttachment"; static final String REL_UPLOAD_ATTACHMENT = "uploadAttachment";
static final String REL_ATTACHMENTS = "attachments"; static final String REL_ATTACHMENTS = "attachments";
static final String REL_UPDATE = "update"; static final String REL_UPDATE = "update";
static final String REL_CREATE_BESCHEID_DOCUMENT = "createBescheidDocument"; static final String REL_CREATE_DOCUMENT = "createDocument";
static final String REL_CREATE_DOCUMENT_FROM_FILE = "createDocumentFromFile";
static final String REL_BESCHEID_DOCUMENT = "bescheidDocument"; static final String REL_BESCHEID_DOCUMENT = "bescheidDocument";
static final String REL_SEND = "send"; static final String REL_SEND = "send";
private static final Predicate<Bescheid> HAS_ATTACHMENTS = bescheid -> !bescheid.getAttachments().isEmpty(); private static final Predicate<Bescheid> HAS_ATTACHMENTS = bescheid -> !bescheid.getAttachments().isEmpty();
private final BescheidService bescheidService;
@Override @Override
public EntityModel<Bescheid> toModel(Bescheid bescheid) { public EntityModel<Bescheid> toModel(Bescheid bescheid) {
var selfLink = linkTo(methodOn(BescheidController.class).getDraft(bescheid.getVorgangId())); var selfLink = linkTo(methodOn(BescheidController.class).getDraft(bescheid.getVorgangId()));
...@@ -49,7 +52,9 @@ public class BescheidModelAssembler implements RepresentationModelAssembler<Besc ...@@ -49,7 +52,9 @@ public class BescheidModelAssembler implements RepresentationModelAssembler<Besc
.ifMatch(HAS_ATTACHMENTS) .ifMatch(HAS_ATTACHMENTS)
.addLink(attachmentsLink.withRel(REL_ATTACHMENTS)) .addLink(attachmentsLink.withRel(REL_ATTACHMENTS))
.addLink(createCommandLink.withRel(REL_UPDATE)) .addLink(createCommandLink.withRel(REL_UPDATE))
.addLink(createCommandLink.withRel(REL_CREATE_BESCHEID_DOCUMENT)) .ifMatch(bescheidService::canCreateBescheidDocumentAutomatically)
.addLink(createCommandLink.withRel(REL_CREATE_DOCUMENT))
.addLink(createCommandLink.withRel(REL_CREATE_DOCUMENT_FROM_FILE))
.addLink(createCommandLink.withRel(REL_SEND)) .addLink(createCommandLink.withRel(REL_SEND))
.buildModel(); .buildModel();
} }
......
...@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service; ...@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
import de.ozgcloud.alfa.common.GrpcUtil; import de.ozgcloud.alfa.common.GrpcUtil;
import de.ozgcloud.bescheid.BescheidServiceGrpc.BescheidServiceBlockingStub; import de.ozgcloud.bescheid.BescheidServiceGrpc.BescheidServiceBlockingStub;
import de.ozgcloud.bescheid.GrpcBescheid; import de.ozgcloud.bescheid.GrpcBescheid;
import de.ozgcloud.bescheid.GrpcBescheidManagerConfigRequest;
import de.ozgcloud.bescheid.GrpcGetBescheidDraftRequest; import de.ozgcloud.bescheid.GrpcGetBescheidDraftRequest;
import de.ozgcloud.bescheid.GrpcGetBescheidDraftResponse; import de.ozgcloud.bescheid.GrpcGetBescheidDraftResponse;
import net.devh.boot.grpc.client.inject.GrpcClient; import net.devh.boot.grpc.client.inject.GrpcClient;
...@@ -35,4 +36,9 @@ class BescheidRemoteService { ...@@ -35,4 +36,9 @@ class BescheidRemoteService {
Optional<GrpcBescheid> getBescheidFromResponse(GrpcGetBescheidDraftResponse response) { Optional<GrpcBescheid> getBescheidFromResponse(GrpcGetBescheidDraftResponse response) {
return response.hasBescheid() ? Optional.of(response.getBescheid()) : Optional.empty(); return response.hasBescheid() ? Optional.of(response.getBescheid()) : Optional.empty();
} }
public boolean canCreateBescheidDocument() {
var response = bescheidServiceStub.getConfig(GrpcBescheidManagerConfigRequest.newBuilder().build());
return response.hasFeatures() && response.getFeatures().getCanCreateBescheidDocument();
}
} }
\ No newline at end of file
...@@ -15,4 +15,8 @@ public class BescheidService { ...@@ -15,4 +15,8 @@ public class BescheidService {
public Optional<Bescheid> getBescheidDraft(String vorgangId) { public Optional<Bescheid> getBescheidDraft(String vorgangId) {
return remoteService.getBescheidDraft(vorgangId); return remoteService.getBescheidDraft(vorgangId);
} }
public boolean canCreateBescheidDocumentAutomatically() {
return remoteService.canCreateBescheidDocument();
}
} }
...@@ -2,6 +2,7 @@ package de.ozgcloud.alfa.bescheid; ...@@ -2,6 +2,7 @@ package de.ozgcloud.alfa.bescheid;
import static de.ozgcloud.alfa.bescheid.BescheidModelAssembler.*; import static de.ozgcloud.alfa.bescheid.BescheidModelAssembler.*;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.Collections; import java.util.Collections;
...@@ -9,11 +10,12 @@ import org.junit.jupiter.api.Nested; ...@@ -9,11 +10,12 @@ import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullAndEmptySource; import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy; import org.mockito.Spy;
import org.springframework.hateoas.EntityModel; import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.IanaLinkRelations; import org.springframework.hateoas.IanaLinkRelations;
import org.springframework.hateoas.Link; import org.springframework.hateoas.Link;
import org.springframework.hateoas.LinkRelation;
import org.springframework.web.util.UriTemplate; import org.springframework.web.util.UriTemplate;
import de.ozgcloud.alfa.common.command.CommandController; import de.ozgcloud.alfa.common.command.CommandController;
...@@ -22,8 +24,12 @@ import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory; ...@@ -22,8 +24,12 @@ import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory;
class BescheidModelAssemblerTest { class BescheidModelAssemblerTest {
@Spy @Spy
@InjectMocks
private BescheidModelAssembler assembler; private BescheidModelAssembler assembler;
@Mock
private BescheidService bescheidService;
@Nested @Nested
class TestToModel { class TestToModel {
...@@ -88,10 +94,29 @@ class BescheidModelAssemblerTest { ...@@ -88,10 +94,29 @@ class BescheidModelAssemblerTest {
} }
@Test @Test
void shouldHaveCreateBescheidDocumentLink() { void shouldHaveCreateDocumentLink() {
when(bescheidService.canCreateBescheidDocumentAutomatically()).thenReturn(true);
var model = callToModel(); var model = callToModel();
assertThat(model.getLink(REL_CREATE_BESCHEID_DOCUMENT)).isPresent().get().extracting(Link::getHref) assertThat(model.getLink(REL_CREATE_DOCUMENT)).isPresent().get().extracting(Link::getHref)
.isEqualTo(createCommandLink());
}
@Test
void shoulNotdHaveCreateDocumentLink() {
when(bescheidService.canCreateBescheidDocumentAutomatically()).thenReturn(false);
var model = callToModel();
assertThat(model.getLink(REL_CREATE_DOCUMENT)).isEmpty();
}
@Test
void shouldHaveCreateDocumentFromFileLink() {
var model = callToModel();
assertThat(model.getLink(REL_CREATE_DOCUMENT_FROM_FILE)).isPresent().get().extracting(Link::getHref)
.isEqualTo(createCommandLink()); .isEqualTo(createCommandLink());
} }
...@@ -111,16 +136,6 @@ class BescheidModelAssemblerTest { ...@@ -111,16 +136,6 @@ class BescheidModelAssemblerTest {
.isEqualTo(String.format("%s/%s", DocumentController.PATH, BescheidTestFactory.BESCHEID_DOCUMENT)); .isEqualTo(String.format("%s/%s", DocumentController.PATH, BescheidTestFactory.BESCHEID_DOCUMENT));
} }
@Test
void shouldHaveOnlyExpectedLinks() {
var model = callToModel();
assertThat(model.getLinks()).extracting(Link::getRel).containsExactlyInAnyOrder(
IanaLinkRelations.SELF, LinkRelation.of(REL_DELETE), LinkRelation.of(REL_UPLOAD_BESCHEID_FILE),
LinkRelation.of(REL_UPLOAD_ATTACHMENT), LinkRelation.of(REL_ATTACHMENTS), LinkRelation.of(REL_UPDATE),
LinkRelation.of(REL_CREATE_BESCHEID_DOCUMENT), LinkRelation.of(REL_BESCHEID_DOCUMENT), LinkRelation.of(REL_SEND));
}
@Test @Test
void shouldHaveSendLink() { void shouldHaveSendLink() {
var model = callToModel(); var model = callToModel();
......
...@@ -14,6 +14,8 @@ import org.mockito.Spy; ...@@ -14,6 +14,8 @@ import org.mockito.Spy;
import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory; import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory;
import de.ozgcloud.bescheid.BescheidServiceGrpc.BescheidServiceBlockingStub; import de.ozgcloud.bescheid.BescheidServiceGrpc.BescheidServiceBlockingStub;
import de.ozgcloud.bescheid.GrpcBescheidManagerConfigRequest;
import de.ozgcloud.bescheid.GrpcBescheidManagerConfigResponse;
import de.ozgcloud.bescheid.GrpcGetBescheidDraftRequest; import de.ozgcloud.bescheid.GrpcGetBescheidDraftRequest;
import de.ozgcloud.bescheid.GrpcGetBescheidDraftResponse; import de.ozgcloud.bescheid.GrpcGetBescheidDraftResponse;
...@@ -119,4 +121,53 @@ class BescheidRemoteServiceTest { ...@@ -119,4 +121,53 @@ class BescheidRemoteServiceTest {
} }
} }
@Nested
class TestCanCreateBescheidDocument {
private final GrpcBescheidManagerConfigRequest request = GrpcBescheidManagerConfigRequestTestFactory.create();
private final GrpcBescheidManagerConfigResponse respone = GrpcBescheidManagerConfigResponseTestFactory.create();
@BeforeEach
void setUp() {
when(bescheidServiceStub.getConfig(request)).thenReturn(respone);
}
@Test
void shouldCallRemoteService() {
service.canCreateBescheidDocument();
verify(bescheidServiceStub).getConfig(request);
}
@Test
void shouldReturnTrue() {
var canCreate = service.canCreateBescheidDocument();
assertThat(canCreate).isTrue();
}
@Test
void shouldReturnFalseIfNoFeaturesAvailable() {
when(bescheidServiceStub.getConfig(request)).thenReturn(GrpcBescheidManagerConfigResponse.newBuilder().build());
var canCreate = service.canCreateBescheidDocument();
assertThat(canCreate).isFalse();
}
@Test
void shouldReturnFalseIfFeatureDisabled() {
var respones = GrpcBescheidManagerConfigResponseTestFactory.createBuilder()
.setFeatures(GrpcBescheidManagerFeaturesTestFactory.createBuilder()
.setCanCreateBescheidDocument(false)
.build())
.build();
when(bescheidServiceStub.getConfig(request)).thenReturn(respones);
var canCreate = service.canCreateBescheidDocument();
assertThat(canCreate).isFalse();
}
}
} }
\ No newline at end of file
...@@ -7,6 +7,8 @@ import java.util.Optional; ...@@ -7,6 +7,8 @@ import java.util.Optional;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Spy; import org.mockito.Spy;
...@@ -41,4 +43,25 @@ class BescheidServiceTest { ...@@ -41,4 +43,25 @@ class BescheidServiceTest {
assertThat(result).isEqualTo(remoteServiceResult); assertThat(result).isEqualTo(remoteServiceResult);
} }
} }
@Nested
class TestCanCreateBescheidDocumentAutomatically {
@Test
void shouldCallRemoteService() {
service.canCreateBescheidDocumentAutomatically();
verify(remoteService).canCreateBescheidDocument();
}
@ParameterizedTest
@ValueSource(booleans = { true, false })
void shouldRetrun(boolean canCreateBescheidDocument) {
when(remoteService.canCreateBescheidDocument()).thenReturn(canCreateBescheidDocument);
var canCreateAutomatically = service.canCreateBescheidDocumentAutomatically();
assertThat(canCreateAutomatically).isEqualTo(canCreateBescheidDocument);
}
}
} }
package de.ozgcloud.alfa.bescheid;
import de.ozgcloud.bescheid.GrpcBescheidManagerConfigRequest;
public class GrpcBescheidManagerConfigRequestTestFactory {
public static GrpcBescheidManagerConfigRequest create() {
return createBuilder().build();
}
public static GrpcBescheidManagerConfigRequest.Builder createBuilder() {
return GrpcBescheidManagerConfigRequest.newBuilder();
}
}
package de.ozgcloud.alfa.bescheid;
import de.ozgcloud.bescheid.GrpcBescheidManagerConfigResponse;
public class GrpcBescheidManagerConfigResponseTestFactory {
public static GrpcBescheidManagerConfigResponse create() {
return createBuilder().build();
}
public static GrpcBescheidManagerConfigResponse.Builder createBuilder() {
return GrpcBescheidManagerConfigResponse.newBuilder().setFeatures(GrpcBescheidManagerFeaturesTestFactory.create());
}
}
package de.ozgcloud.alfa.bescheid;
import de.ozgcloud.bescheid.GrpcBescheidManagerFeatures;
public class GrpcBescheidManagerFeaturesTestFactory {
public static final boolean CAN_CREATE_BESCHEID = true;
public static GrpcBescheidManagerFeatures create() {
return createBuilder().build();
}
public static GrpcBescheidManagerFeatures.Builder createBuilder() {
return GrpcBescheidManagerFeatures.newBuilder().setCanCreateBescheidDocument(CAN_CREATE_BESCHEID);
}
}
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<vorgang-manager.version>2.6.0</vorgang-manager.version> <vorgang-manager.version>2.7.0-SNAPSHOT</vorgang-manager.version>
<ozgcloud-common-pdf.version>3.0.1</ozgcloud-common-pdf.version> <ozgcloud-common-pdf.version>3.0.1</ozgcloud-common-pdf.version>
<user-manager.version>2.2.0</user-manager.version> <user-manager.version>2.2.0</user-manager.version>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment