Skip to content
Snippets Groups Projects
Commit 3e3855b0 authored by OZGCloud's avatar OZGCloud
Browse files

Merge branch 'master' into OZG-5167-nachricht-an-antragsteller

parents 8b40d545 6114d231
Branches
Tags
No related merge requests found
Showing
with 173 additions and 24 deletions
......@@ -3,7 +3,8 @@ export enum BescheidLinkRel {
UPLOAD_BESCHEID_FILE = 'uploadBescheidFile',
UPLOAD_ATTACHMENT = 'uploadAttachment',
UPDATE = 'update',
CREATE_BESCHEID_DOCUMENT = 'createBescheidDocument',
CREATE_DOCUMENT = 'createDocument',
CREATE_DOCUMENT_FROM_FILE = 'createDocumentFromFile',
ATTACHMENTS = 'attachments',
BESCHEID_DOCUMENT = 'bescheidDocument',
SEND = 'send',
......
......@@ -66,7 +66,7 @@ describe('BescheidUtil', () => {
binaryFileResource,
);
expect(props.linkRel).toBe(BescheidLinkRel.CREATE_BESCHEID_DOCUMENT);
expect(props.linkRel).toBe(BescheidLinkRel.CREATE_DOCUMENT_FROM_FILE);
});
describe('command', () => {
......@@ -195,7 +195,7 @@ describe('BescheidUtil', () => {
it('should have linkRel', () => {
const props: CreateCommandProps = buildCreateBescheidDocumentCommandProps(bescheidResource);
expect(props.linkRel).toBe(BescheidLinkRel.CREATE_BESCHEID_DOCUMENT);
expect(props.linkRel).toBe(BescheidLinkRel.CREATE_DOCUMENT);
});
describe('command', () => {
......
......@@ -28,7 +28,7 @@ export function buildCreateBescheidDocumentFromFileProps(
): CreateCommandProps {
return {
resource: bescheid,
linkRel: BescheidLinkRel.CREATE_BESCHEID_DOCUMENT,
linkRel: BescheidLinkRel.CREATE_DOCUMENT_FROM_FILE,
command: buildCreateBescheidDocumentFromFileCommand(binaryFile),
snackBarMessage: EMPTY_STRING,
};
......@@ -67,7 +67,7 @@ export function buildCreateBescheidDocumentCommandProps(
): CreateCommandProps {
return {
resource,
linkRel: BescheidLinkRel.CREATE_BESCHEID_DOCUMENT,
linkRel: BescheidLinkRel.CREATE_DOCUMENT,
command: {
order: CommandOrder.CREATE_BESCHEID_DOCUMENT,
body: null,
......
<ng-container *ngIf="bescheidDraftStateResource.resource as bescheidDraft">
<div class="mt-4">
<ods-button
*ngIf="bescheidDraft | hasLink: bescheidLinkRel.CREATE_BESCHEID_DOCUMENT"
*ngIf="bescheidDraft | hasLink: bescheidLinkRel.CREATE_DOCUMENT"
class="w-72"
[isLoading]="(createBescheidDocumentInProgress$ | async).loading"
(click)="createBescheidDocument()"
......
......@@ -60,7 +60,7 @@ describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => {
describe('create bescheid document button', () => {
beforeEach(() => {
component.bescheidDraftStateResource = createStateResource(
createBescheidResource([BescheidLinkRel.CREATE_BESCHEID_DOCUMENT]),
createBescheidResource([BescheidLinkRel.CREATE_DOCUMENT]),
);
fixture.detectChanges();
......@@ -81,7 +81,7 @@ describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => {
it('should be visible if link is present', () => {
component.bescheidDraftStateResource = createStateResource(
createBescheidResource([BescheidLinkRel.CREATE_BESCHEID_DOCUMENT]),
createBescheidResource([BescheidLinkRel.CREATE_DOCUMENT]),
);
fixture.detectChanges();
......
......@@ -23,12 +23,15 @@ public class BescheidModelAssembler implements RepresentationModelAssembler<Besc
static final String REL_UPLOAD_ATTACHMENT = "uploadAttachment";
static final String REL_ATTACHMENTS = "attachments";
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_SEND = "send";
private static final Predicate<Bescheid> HAS_ATTACHMENTS = bescheid -> !bescheid.getAttachments().isEmpty();
private final BescheidService bescheidService;
@Override
public EntityModel<Bescheid> toModel(Bescheid bescheid) {
var selfLink = linkTo(methodOn(BescheidController.class).getDraft(bescheid.getVorgangId()));
......@@ -49,7 +52,9 @@ public class BescheidModelAssembler implements RepresentationModelAssembler<Besc
.ifMatch(HAS_ATTACHMENTS)
.addLink(attachmentsLink.withRel(REL_ATTACHMENTS))
.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))
.buildModel();
}
......
......@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
import de.ozgcloud.alfa.common.GrpcUtil;
import de.ozgcloud.bescheid.BescheidServiceGrpc.BescheidServiceBlockingStub;
import de.ozgcloud.bescheid.GrpcBescheid;
import de.ozgcloud.bescheid.GrpcBescheidManagerConfigRequest;
import de.ozgcloud.bescheid.GrpcGetBescheidDraftRequest;
import de.ozgcloud.bescheid.GrpcGetBescheidDraftResponse;
import net.devh.boot.grpc.client.inject.GrpcClient;
......@@ -35,4 +36,9 @@ class BescheidRemoteService {
Optional<GrpcBescheid> getBescheidFromResponse(GrpcGetBescheidDraftResponse response) {
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 {
public Optional<Bescheid> getBescheidDraft(String vorgangId) {
return remoteService.getBescheidDraft(vorgangId);
}
public boolean canCreateBescheidDocumentAutomatically() {
return remoteService.canCreateBescheidDocument();
}
}
......@@ -2,6 +2,7 @@ package de.ozgcloud.alfa.bescheid;
import static de.ozgcloud.alfa.bescheid.BescheidModelAssembler.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.Collections;
......@@ -9,11 +10,12 @@ import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.IanaLinkRelations;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.LinkRelation;
import org.springframework.web.util.UriTemplate;
import de.ozgcloud.alfa.common.command.CommandController;
......@@ -22,8 +24,12 @@ import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory;
class BescheidModelAssemblerTest {
@Spy
@InjectMocks
private BescheidModelAssembler assembler;
@Mock
private BescheidService bescheidService;
@Nested
class TestToModel {
......@@ -88,10 +94,29 @@ class BescheidModelAssemblerTest {
}
@Test
void shouldHaveCreateBescheidDocumentLink() {
void shouldHaveCreateDocumentLink() {
when(bescheidService.canCreateBescheidDocumentAutomatically()).thenReturn(true);
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());
}
......@@ -111,16 +136,6 @@ class BescheidModelAssemblerTest {
.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
void shouldHaveSendLink() {
var model = callToModel();
......
......@@ -14,6 +14,8 @@ import org.mockito.Spy;
import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory;
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.GrpcGetBescheidDraftResponse;
......@@ -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;
import org.junit.jupiter.api.Nested;
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.Mock;
import org.mockito.Spy;
......@@ -41,4 +43,25 @@ class BescheidServiceTest {
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 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<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>
<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