-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INTYGFV-16770: Added aggregator for get certificate events (#1089)
- Loading branch information
1 parent
eafa8b8
commit 2002c73
Showing
12 changed files
with
516 additions
and
1 deletion.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...va/se/inera/intyg/webcert/web/csintegration/aggregate/GetCertificateEventsAggregator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (C) 2024 Inera AB (http://www.inera.se) | ||
* | ||
* This file is part of sklintyg (https://github.com/sklintyg). | ||
* | ||
* sklintyg is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* sklintyg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package se.inera.intyg.webcert.web.csintegration.aggregate; | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.stereotype.Service; | ||
import se.inera.intyg.common.support.modules.support.facade.dto.CertificateEventDTO; | ||
import se.inera.intyg.webcert.web.csintegration.util.CertificateServiceProfile; | ||
import se.inera.intyg.webcert.web.service.facade.GetCertificateEventsFacadeService; | ||
|
||
@Service("getCertificateEventsAggregator") | ||
public class GetCertificateEventsAggregator implements GetCertificateEventsFacadeService { | ||
|
||
private final GetCertificateEventsFacadeService getCertificateEventsFromWC; | ||
private final GetCertificateEventsFacadeService getCertificateEventsFromCS; | ||
private final CertificateServiceProfile certificateServiceProfile; | ||
|
||
public GetCertificateEventsAggregator( | ||
@Qualifier("getCertificateEventsFromWebcert") | ||
GetCertificateEventsFacadeService getCertificateEventsFromWC, | ||
@Qualifier("getCertificateEventsFromCertificateService") | ||
GetCertificateEventsFacadeService replaceCertificateFromCertificateService, | ||
CertificateServiceProfile certificateServiceProfile) { | ||
this.getCertificateEventsFromWC = getCertificateEventsFromWC; | ||
this.getCertificateEventsFromCS = replaceCertificateFromCertificateService; | ||
this.certificateServiceProfile = certificateServiceProfile; | ||
} | ||
|
||
@Override | ||
public CertificateEventDTO[] getCertificateEvents(String certificateId) { | ||
if (!certificateServiceProfile.active()) { | ||
return getCertificateEventsFromWC.getCertificateEvents(certificateId); | ||
} | ||
|
||
final var responseFromCS = getCertificateEventsFromCS.getCertificateEvents(certificateId); | ||
|
||
return responseFromCS != null ? responseFromCS : getCertificateEventsFromWC.getCertificateEvents(certificateId); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...tyg/webcert/web/csintegration/certificate/GetCertificateEventsFromCertificateService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2024 Inera AB (http://www.inera.se) | ||
* | ||
* This file is part of sklintyg (https://github.com/sklintyg). | ||
* | ||
* sklintyg is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* sklintyg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package se.inera.intyg.webcert.web.csintegration.certificate; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import se.inera.intyg.common.support.modules.support.facade.dto.CertificateEventDTO; | ||
import se.inera.intyg.webcert.web.csintegration.integration.CSIntegrationRequestFactory; | ||
import se.inera.intyg.webcert.web.csintegration.integration.CSIntegrationService; | ||
import se.inera.intyg.webcert.web.service.facade.GetCertificateEventsFacadeService; | ||
|
||
@Service("getCertificateEventsFromCertificateService") | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class GetCertificateEventsFromCertificateService implements GetCertificateEventsFacadeService { | ||
|
||
private final CSIntegrationService csIntegrationService; | ||
private final CSIntegrationRequestFactory csIntegrationRequestFactory; | ||
|
||
@Override | ||
public CertificateEventDTO[] getCertificateEvents(String certificateId) { | ||
log.debug("Attempting to retrieve events for certificate '{}' from Certificate Service", certificateId); | ||
|
||
if (Boolean.FALSE.equals(csIntegrationService.certificateExists(certificateId))) { | ||
log.debug("Certificate '{}' does not exist in certificate service", certificateId); | ||
return null; | ||
} | ||
|
||
final var events = csIntegrationService.getCertificateEvents( | ||
certificateId, csIntegrationRequestFactory.getCertificateEventsRequest() | ||
); | ||
|
||
log.debug("Got '{}' events for certificate '{}' from Certificate Service", events.length, certificateId); | ||
|
||
return events; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...inera/intyg/webcert/web/csintegration/integration/dto/GetCertificateEventsRequestDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (C) 2024 Inera AB (http://www.inera.se) | ||
* | ||
* This file is part of sklintyg (https://github.com/sklintyg). | ||
* | ||
* sklintyg is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* sklintyg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package se.inera.intyg.webcert.web.csintegration.integration.dto; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; | ||
import lombok.Builder; | ||
import lombok.Value; | ||
import se.inera.intyg.webcert.web.csintegration.integration.dto.GetCertificateEventsRequestDTO.GetCertificateEventsRequestDTOBuilder; | ||
import se.inera.intyg.webcert.web.csintegration.unit.CertificateServiceUnitDTO; | ||
import se.inera.intyg.webcert.web.csintegration.user.CertificateServiceUserDTO; | ||
|
||
@JsonDeserialize(builder = GetCertificateEventsRequestDTOBuilder.class) | ||
@Value | ||
@Builder | ||
public class GetCertificateEventsRequestDTO { | ||
|
||
CertificateServiceUserDTO user; | ||
CertificateServiceUnitDTO unit; | ||
CertificateServiceUnitDTO careUnit; | ||
CertificateServiceUnitDTO careProvider; | ||
|
||
@JsonPOJOBuilder(withPrefix = "") | ||
public static class GetCertificateEventsRequestDTOBuilder { | ||
|
||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...nera/intyg/webcert/web/csintegration/integration/dto/GetCertificateEventsResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2024 Inera AB (http://www.inera.se) | ||
* | ||
* This file is part of sklintyg (https://github.com/sklintyg). | ||
* | ||
* sklintyg is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* sklintyg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package se.inera.intyg.webcert.web.csintegration.integration.dto; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Value; | ||
import se.inera.intyg.common.support.modules.support.facade.dto.CertificateEventDTO; | ||
import se.inera.intyg.webcert.web.csintegration.integration.dto.GetCertificateEventsResponseDTO.GetCertificateEventsResponseDTOBuilder; | ||
|
||
@JsonDeserialize(builder = GetCertificateEventsResponseDTOBuilder.class) | ||
@Value | ||
@Builder | ||
public class GetCertificateEventsResponseDTO { | ||
|
||
List<CertificateEventDTO> events; | ||
|
||
@JsonPOJOBuilder(withPrefix = "") | ||
public static class GetCertificateEventsResponseDTOBuilder { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...e/inera/intyg/webcert/web/csintegration/aggregate/GetCertificateEventsAggregatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (C) 2024 Inera AB (http://www.inera.se) | ||
* | ||
* This file is part of sklintyg (https://github.com/sklintyg). | ||
* | ||
* sklintyg is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* sklintyg is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package se.inera.intyg.webcert.web.csintegration.aggregate; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
import se.inera.intyg.common.support.modules.support.facade.dto.CertificateEventDTO; | ||
import se.inera.intyg.webcert.web.csintegration.util.CertificateServiceProfile; | ||
import se.inera.intyg.webcert.web.service.facade.GetCertificateEventsFacadeService; | ||
|
||
class GetCertificateEventsAggregatorTest { | ||
|
||
private static final String ID = "ID"; | ||
private static final CertificateEventDTO[] EVENTS = {new CertificateEventDTO()}; | ||
|
||
GetCertificateEventsFacadeService getCertificateEventsFromWC; | ||
GetCertificateEventsFacadeService getCertificateEventsFromCS; | ||
CertificateServiceProfile certificateServiceProfile; | ||
GetCertificateEventsFacadeService aggregator; | ||
|
||
@BeforeEach | ||
void setup() { | ||
getCertificateEventsFromWC = mock(GetCertificateEventsFacadeService.class); | ||
getCertificateEventsFromCS = mock(GetCertificateEventsFacadeService.class); | ||
certificateServiceProfile = mock(CertificateServiceProfile.class); | ||
|
||
aggregator = new GetCertificateEventsAggregator( | ||
getCertificateEventsFromWC, | ||
getCertificateEventsFromCS, | ||
certificateServiceProfile); | ||
} | ||
|
||
@Test | ||
void shouldForwardFromWebcertIfProfileIsInactive() { | ||
aggregator.getCertificateEvents(ID); | ||
|
||
Mockito.verify(getCertificateEventsFromWC).getCertificateEvents(ID); | ||
} | ||
|
||
@Nested | ||
class ActiveProfile { | ||
|
||
@BeforeEach | ||
void setup() { | ||
when(certificateServiceProfile.active()) | ||
.thenReturn(true); | ||
} | ||
|
||
@Test | ||
void shouldForwardFromCSIfProfileIsActiveAndCertificateExistsInCS() { | ||
when(getCertificateEventsFromCS.getCertificateEvents(ID)) | ||
.thenReturn(EVENTS); | ||
aggregator.getCertificateEvents(ID); | ||
|
||
Mockito.verify(getCertificateEventsFromWC, times(0)).getCertificateEvents(ID); | ||
} | ||
|
||
@Test | ||
void shouldForwardFromWCIfProfileIsInactiveAndCertificateDoesNotExistInCS() { | ||
aggregator.getCertificateEvents(ID); | ||
|
||
Mockito.verify(getCertificateEventsFromWC, times(1)).getCertificateEvents(ID); | ||
} | ||
} | ||
} |
Oops, something went wrong.