Skip to content

Commit

Permalink
[GITFLOW]merging 'hotfix-1.76.3' into 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
MateStrysewske committed Nov 8, 2022
2 parents a2cd659 + 544920c commit 25d7b3a
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 47 deletions.
2 changes: 1 addition & 1 deletion sormas-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<parent>
<groupId>de.symeda.sormas</groupId>
<artifactId>sormas-base</artifactId>
<version>1.76.2</version>
<version>1.76.3</version>
<relativePath>../sormas-base</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion sormas-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>sormas-base</artifactId>
<groupId>de.symeda.sormas</groupId>
<version>1.76.2</version>
<version>1.76.3</version>
<relativePath>../sormas-base</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion sormas-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>sormas-base</artifactId>
<groupId>de.symeda.sormas</groupId>
<version>1.76.2</version>
<version>1.76.3</version>
<relativePath>../sormas-base</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2598,7 +2598,9 @@ public void deleteCaseAsDuplicate(String caseUuid, String duplicateOfCaseUuid) {
public void deleteCaseInExternalSurveillanceTool(Case caze) throws ExternalSurveillanceToolException {

if (externalSurveillanceToolGatewayFacade.isFeatureEnabled() && caze.getExternalID() != null && !caze.getExternalID().isEmpty()) {
List<CaseDataDto> casesWithSameExternalId = getByExternalId(caze.getExternalID());
// getByExternalId(caze) throws NPE (see #10820) so we use the service directly.
// Can potentially be changed back once 10844 is done.
List<Case> casesWithSameExternalId = service.getByExternalId(caze.getExternalID());
if (casesWithSameExternalId != null && casesWithSameExternalId.size() == 1) {
externalSurveillanceToolGatewayFacade.deleteCases(Collections.singletonList(toDto(caze)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import de.symeda.sormas.api.RequestContextHolder;
import de.symeda.sormas.api.caze.CaseClassification;
import de.symeda.sormas.api.caze.CaseCriteria;
import de.symeda.sormas.api.caze.CaseDataDto;
import de.symeda.sormas.api.caze.CaseIndexDto;
import de.symeda.sormas.api.caze.CaseListEntryDto;
import de.symeda.sormas.api.caze.CaseLogic;
Expand Down Expand Up @@ -1083,18 +1084,28 @@ public void dearchive(List<String> entityUuids, String dearchiveReason) {

public void setArchiveInExternalSurveillanceToolForEntities(List<String> entityUuids, boolean archived) {
if (externalSurveillanceToolGatewayFacade.isFeatureEnabled()) {
List<String> sharedCaseUuids = externalShareInfoService.getSharedCaseUuidsWithoutDeletedStatus(entityUuids);

if (!sharedCaseUuids.isEmpty()) {
try {
externalSurveillanceToolGatewayFacade.sendCases(sharedCaseUuids, archived);
} catch (ExternalSurveillanceToolException e) {
throw new ExternalSurveillanceToolRuntimeException(e.getMessage(), e.getErrorCode());
List<String> uuidsAllowedToBeShared = getEntityUuidsAllowedToBeShared(entityUuids);
if (!uuidsAllowedToBeShared.isEmpty()) {
List<String> sharedCaseUuids = externalShareInfoService.getSharedCaseUuidsWithoutDeletedStatus(uuidsAllowedToBeShared);

if (!sharedCaseUuids.isEmpty()) {
try {
externalSurveillanceToolGatewayFacade.sendCases(sharedCaseUuids, archived);
} catch (ExternalSurveillanceToolException e) {
throw new ExternalSurveillanceToolRuntimeException(e.getMessage(), e.getErrorCode());
}
}
}
}
}

public List<String> getEntityUuidsAllowedToBeShared(List<String> entityUuids) {
List<CaseDataDto> casesAllowedToBeShare =
caseFacade.getByUuids(entityUuids).stream().filter(c -> !c.isDontShareWithReportingTool()).collect(Collectors.toList());

return casesAllowedToBeShare.stream().map(CaseDataDto::getUuid).collect(Collectors.toList());
}

public void setArchiveInExternalSurveillanceToolForEntity(String entityUuid, boolean archived) {
setArchiveInExternalSurveillanceToolForEntities(Collections.singletonList(entityUuid), archived);
}
Expand All @@ -1119,7 +1130,9 @@ public void delete(Case caze, DeletionDetails deletionDetails) {

private void deleteCaseInExternalSurveillanceTool(Case caze) {
try {
caseFacade.deleteCaseInExternalSurveillanceTool(caze);
if (!caze.isDontShareWithReportingTool()) {
caseFacade.deleteCaseInExternalSurveillanceTool(caze);
}
} catch (ExternalSurveillanceToolException e) {
throw new ExternalSurveillanceToolRuntimeException(e.getMessage(), e.getErrorCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ public long count(ShareRequestCriteria criteria) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
Root<ShareRequestInfo> requestRoot = cq.from(ShareRequestInfo.class);
requestRoot.join(ShareRequestInfo.SHARES);

Predicate filter = null;

if (criteria != null) {
filter = shareRequestInfoService.buildCriteriaFilter(criteria, cb, requestRoot);
}
Expand All @@ -186,7 +188,7 @@ public long count(ShareRequestCriteria criteria) {
cq.where(filter);
}

cq.select(cb.count(requestRoot));
cq.select(cb.countDistinct(requestRoot));

return em.createQuery(cq).getSingleResult();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.containing;
import static com.github.tomakehurst.wiremock.client.WireMock.exactly;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
Expand Down Expand Up @@ -178,6 +180,7 @@
import de.symeda.sormas.api.visit.VisitStatus;
import de.symeda.sormas.backend.AbstractBeanTest;
import de.symeda.sormas.backend.MockProducer;
import de.symeda.sormas.backend.TestDataCreator;
import de.symeda.sormas.backend.TestDataCreator.RDCF;
import de.symeda.sormas.backend.TestDataCreator.RDCFEntities;
import de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal;
Expand Down Expand Up @@ -1313,7 +1316,7 @@ public void testGetExportListWithoutDeletedSamples() {
public void testCaseDeletion() throws ExternalSurveillanceToolRuntimeException {
Date since = new Date();

RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
TestDataCreator.RDCF rdcf = creator.createRDCF();
UserDto user = creator.createUser(
rdcf.region.getUuid(),
rdcf.district.getUuid(),
Expand All @@ -1331,7 +1334,9 @@ public void testCaseDeletion() throws ExternalSurveillanceToolRuntimeException {
CaseClassification.PROBABLE,
InvestigationStatus.PENDING,
new Date(),
rdcf);
rdcf,
c -> c.setDontShareWithReportingTool(true));

PersonDto contactPerson = creator.createPerson("Contact", "Person");
ContactDto contact =
creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null);
Expand Down Expand Up @@ -1363,7 +1368,13 @@ public void testCaseDeletion() throws ExternalSurveillanceToolRuntimeException {
assertNotNull(getAdditionalTestFacade().getByUuid(additionalTest.getUuid()));
assertNotNull(getTaskFacade().getByUuid(task.getUuid()));

stubFor(
post(urlEqualTo("/export")).withRequestBody(containing(caze.getUuid()))
.withRequestBody(containing("caseUuids"))
.willReturn(aResponse().withStatus(HttpStatus.SC_OK)));

getCaseFacade().delete(caze.getUuid(), new DeletionDetails(DeletionReason.OTHER_REASON, "test reason"));
wireMockRule.verify(exactly(0), postRequestedFor(urlEqualTo("/export")));

// Deleted flag should be set for case, sample and pathogen test; Additional test should be deleted; Contact should not have the deleted flag; Task should not be deleted
assertTrue(getCaseFacade().getDeletedUuidsSince(since).contains(caze.getUuid()));
Expand Down Expand Up @@ -2189,7 +2200,7 @@ public void testDoesEpidNumberExistLargeNumbers() {
@Test
public void testArchiveAllArchivableCases() {

RDCFEntities rdcf = creator.createRDCFEntities();
TestDataCreator.RDCF rdcf = creator.createRDCF();
UserReferenceDto user = creator.createUser(rdcf).toReference();
PersonReferenceDto person = creator.createPerson("Walter", "Schuster").toReference();

Expand All @@ -2207,7 +2218,7 @@ public void testArchiveAllArchivableCases() {
assertTrue(cut.isArchived(case1.getUuid()));

// One other case
CaseDataDto case2 = creator.createCase(user, person, rdcf);
CaseDataDto case2 = creator.createCase(user, person, rdcf, c -> c.setDontShareWithReportingTool(true));
Case caze2 = getCaseService().getByUuid(case2.getUuid());
getExternalShareInfoService().createAndPersistShareInfo(caze2, ExternalShareStatus.SHARED);
assertFalse(cut.isArchived(case2.getUuid()));
Expand All @@ -2228,6 +2239,30 @@ public void testArchiveAllArchivableCases() {
assertTrue(cut.isArchived(case2.getUuid()));
}

@Test
public void testArchiveAllArchivableCases_WithNotAllowedCaseToShareWithReportingTool() {
TestDataCreator.RDCF rdcf = creator.createRDCF();
UserReferenceDto user = creator.createUser(rdcf).toReference();
PersonReferenceDto person = creator.createPerson("Walter", "Schuster").toReference();

CaseFacadeEjbLocal cut = getBean(CaseFacadeEjbLocal.class);

CaseDataDto case2 = creator.createCase(user, person, rdcf, c -> c.setDontShareWithReportingTool(true));
Case caze2 = getCaseService().getByUuid(case2.getUuid());
getExternalShareInfoService().createAndPersistShareInfo(caze2, ExternalShareStatus.SHARED);
assertFalse(cut.isArchived(case2.getUuid()));

stubFor(
post(urlEqualTo("/export")).withRequestBody(containing(case2.getUuid()))
.withRequestBody(containing("caseUuids"))
.willReturn(aResponse().withStatus(HttpStatus.SC_OK)));

// Case of "yesterday" should be archived but the case should not be shared with the Reporting Tool
cut.archiveAllArchivableCases(70, LocalDate.now().plusDays(71));
assertTrue(cut.isArchived(case2.getUuid()));
wireMockRule.verify(exactly(0), postRequestedFor(urlEqualTo("/export")));
}

@Test
public void testCreateInvestigationTask() {
RDCF rdcf = creator.createRDCF();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
package de.symeda.sormas.backend.caze;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.containing;
import static com.github.tomakehurst.wiremock.client.WireMock.exactly;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;

import org.apache.http.HttpStatus;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import com.github.tomakehurst.wiremock.junit.WireMockRule;

import de.symeda.sormas.api.caze.CaseDataDto;
import de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException;
import de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolFacade;
Expand All @@ -13,20 +29,6 @@
import de.symeda.sormas.backend.AbstractBeanTest;
import de.symeda.sormas.backend.MockProducer;
import de.symeda.sormas.backend.TestDataCreator;
import org.apache.http.HttpStatus;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.containing;
import static com.github.tomakehurst.wiremock.client.WireMock.exactly;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;

public class CaseServiceTest extends AbstractBeanTest {

Expand Down Expand Up @@ -66,13 +68,14 @@ public void init() {
}

@Test
public void testSetArchiveInExternalSurveillanceToolForEntity_WithProperEntity() throws ExternalSurveillanceToolException {
public void testSetArchiveInExternalSurveillanceToolForEntity_WithProperEntity_WithCaseAllowedToShare() throws ExternalSurveillanceToolException {
TestDataCreator.RDCF rdcf = creator.createRDCF();
UserReferenceDto user = creator.createUser(rdcf).toReference();
PersonReferenceDto person = creator.createPerson("Walter", "Schuster").toReference();

CaseDataDto caze = creator.createCase(user, person, rdcf);
CaseDataDto caze = creator.createCase(user, person, rdcf, c -> c.setDontShareWithReportingTool(false));
Case case1 = getCaseService().getByUuid(caze.getUuid());
case1.setDontShareWithReportingTool(false);
getExternalShareInfoService().createAndPersistShareInfo(case1, ExternalShareStatus.SHARED);
CaseService caseService = getBean(CaseService.class);

Expand All @@ -85,6 +88,28 @@ public void testSetArchiveInExternalSurveillanceToolForEntity_WithProperEntity()
wireMockRule.verify(exactly(1), postRequestedFor(urlEqualTo("/export")));
}

@Test
public void testSetArchiveInExternalSurveillanceToolForEntity_WithProperEntity_WithoutCaseAllowedToShare()
throws ExternalSurveillanceToolException {
TestDataCreator.RDCF rdcf = creator.createRDCF();
UserReferenceDto user = creator.createUser(rdcf).toReference();
PersonReferenceDto person = creator.createPerson("Walter", "Schuster").toReference();

CaseDataDto caze = creator.createCase(user, person, rdcf, c -> c.setDontShareWithReportingTool(true));

Case case1 = getCaseService().getByUuid(caze.getUuid());
getExternalShareInfoService().createAndPersistShareInfo(case1, ExternalShareStatus.SHARED);
CaseService caseService = getBean(CaseService.class);

stubFor(
post(urlEqualTo("/export")).withRequestBody(containing(caze.getUuid()))
.withRequestBody(containing("caseUuids"))
.willReturn(aResponse().withStatus(HttpStatus.SC_OK)));

caseService.setArchiveInExternalSurveillanceToolForEntity(caze.getUuid(), true);
wireMockRule.verify(exactly(0), postRequestedFor(urlEqualTo("/export")));
}

@Test
public void testSetArchiveInExternalSurveillanceToolForEntity_WithoutProperEntity() throws ExternalSurveillanceToolException {
TestDataCreator.RDCF rdcf = creator.createRDCF();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package de.symeda.sormas.backend.deletionconfiguration;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.containing;
import static com.github.tomakehurst.wiremock.client.WireMock.exactly;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
Expand All @@ -14,11 +22,15 @@
import javax.validation.ConstraintViolationException;

import org.apache.commons.lang3.time.DateUtils;
import org.apache.http.HttpStatus;
import org.hibernate.internal.SessionImpl;
import org.hibernate.query.spi.QueryImplementor;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import com.github.tomakehurst.wiremock.junit.WireMockRule;

import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.caze.CaseDataDto;
import de.symeda.sormas.api.common.CoreEntityType;
Expand Down Expand Up @@ -66,6 +78,11 @@

public class CoreEntityDeletionServiceTest extends SormasToSormasTest {

private static final int WIREMOCK_TESTING_PORT = 8888;

@Rule
public WireMockRule wireMockRule = new WireMockRule(options().port(WIREMOCK_TESTING_PORT), false);

@Before
public void setupConfig() {
MockProducer.getProperties().setProperty(ConfigFacadeEjb.INTERFACE_PATIENT_DIARY_URL, "url");
Expand All @@ -81,7 +98,7 @@ public void testCaseAutomaticDeletion() throws IOException {
UserDto user = creator
.createUser(rdcf, creator.getUserRoleReference(DefaultUserRole.ADMIN), creator.getUserRoleReference(DefaultUserRole.NATIONAL_USER));
PersonDto person = creator.createPerson();
CaseDataDto caze = creator.createCase(user.toReference(), person.toReference(), rdcf);
CaseDataDto caze = creator.createCase(user.toReference(), person.toReference(), rdcf, c -> c.setDontShareWithReportingTool(true));

creator.createClinicalVisit(caze);
creator.createTreatment(caze);
Expand Down Expand Up @@ -155,7 +172,13 @@ public void testCaseAutomaticDeletion() throws IOException {
assertEquals(2, getCaseService().count());

useSystemUser();

stubFor(
post(urlEqualTo("/export")).withRequestBody(containing(caze.getUuid()))
.withRequestBody(containing("caseUuids"))
.willReturn(aResponse().withStatus(HttpStatus.SC_OK)));
getCoreEntityDeletionService().executeAutomaticDeletion();
wireMockRule.verify(exactly(0), postRequestedFor(urlEqualTo("/export")));
loginWith(user);

ContactDto resultingContactUpdated = getContactFacade().getByUuid(resultingContact.getUuid());
Expand Down
Loading

0 comments on commit 25d7b3a

Please sign in to comment.