|
33 | 33 | import de.symeda.sormas.api.customizablefield.CustomizableFieldMetadataFacade; |
34 | 34 | import de.symeda.sormas.api.customizablefield.CustomizableFieldType; |
35 | 35 | import de.symeda.sormas.api.customizablefield.CustomizableFieldValueDto; |
| 36 | +import de.symeda.sormas.api.epidata.EpiDataDto; |
36 | 37 | import de.symeda.sormas.api.exposure.ExposureDto; |
37 | 38 | import de.symeda.sormas.api.exposure.ExposureType; |
38 | 39 | import de.symeda.sormas.api.externalmessage.survey.PatchDictionary; |
@@ -1175,6 +1176,32 @@ void patch_customizableField_text() { |
1175 | 1176 | () -> Assertions.assertEquals("world", values2.get(metadata).getValue())); |
1176 | 1177 | } |
1177 | 1178 |
|
| 1179 | + @Tag("customizable-fields") |
| 1180 | + @Test |
| 1181 | + void patch_customizableField_text_epidata() { |
| 1182 | + // PREPARE |
| 1183 | + CustomizableFieldMetadataDto metadata = createEpidataCustomField("cfText", CustomizableFieldType.TEXT); |
| 1184 | + CaseDataDto caze = creator.createUnclassifiedCase(Disease.PERTUSSIS); |
| 1185 | + String fieldKey = "Custom." + EpiDataDto.I18N_PREFIX + ".cfText"; |
| 1186 | + |
| 1187 | + // EXECUTE — value does not yet exist |
| 1188 | + DataPatchResponse response1 = victim().patch( |
| 1189 | + new CaseDataPatchRequest().setCaseUuid(caze.getUuid()) |
| 1190 | + .setReplacementStrategy(DataReplacementStrategy.ALWAYS) |
| 1191 | + .setPatchDictionary(Map.of(fieldKey, "hello"))); |
| 1192 | + |
| 1193 | + // CHECK |
| 1194 | + Map<CustomizableFieldMetadataDto, CustomizableFieldValueDto> values1 = customizableValuesForEpiData(caze.getEpiData().getUuid()); |
| 1195 | + Assertions.assertAll( |
| 1196 | + () -> Assertions.assertTrue(response1.getFailures().isEmpty(), "Failures: " + response1.getFailures()), |
| 1197 | + () -> Assertions.assertTrue(response1.isApplied()), |
| 1198 | + () -> Assertions.assertEquals("hello", values1.get(metadata).getValue())); |
| 1199 | + } |
| 1200 | + |
| 1201 | + private CustomizableFieldMetadataDto createEpidataCustomField(String name, CustomizableFieldType type) { |
| 1202 | + return createCustomFieldFor(name, type, CustomizableFieldContext.EPIDATA); |
| 1203 | + } |
| 1204 | + |
1178 | 1205 | @Tag("customizable-fields") |
1179 | 1206 | @Test |
1180 | 1207 | void patch_customizableField_textarea() { |
@@ -1541,13 +1568,20 @@ void patch_customizableField_fieldDoesNotExist() { |
1541 | 1568 | } |
1542 | 1569 |
|
1543 | 1570 | private CustomizableFieldMetadataDto createCaseCustomField(String name, CustomizableFieldType type) { |
| 1571 | + return createCustomFieldFor(name, type, CustomizableFieldContext.CASE); |
| 1572 | + } |
| 1573 | + |
| 1574 | + private CustomizableFieldMetadataDto createCustomFieldFor(String name, CustomizableFieldType type, CustomizableFieldContext context) { |
1544 | 1575 | CustomizableFieldMetadataFacade facade = getBean(CustomizableFieldMetadataFacadeEjb.CustomizableFieldMetadataFacadeEjbLocal.class); |
| 1576 | + |
1545 | 1577 | CustomizableFieldMetadataDto dto = new CustomizableFieldMetadataDto(); |
| 1578 | + |
1546 | 1579 | dto.setName(name); |
1547 | 1580 | dto.setFieldType(type); |
1548 | | - dto.setContextClass(CustomizableFieldContext.CASE); |
1549 | | - dto.setUiGroup(CustomizableFieldGroup.CASE_DATA_GENERAL); |
| 1581 | + dto.setContextClass(context); |
| 1582 | + dto.setUiGroup(CustomizableFieldGroup.getGroupsForContext(context).stream().findFirst().orElseThrow()); |
1550 | 1583 | dto.setUiLinePosition(1); |
| 1584 | + |
1551 | 1585 | return facade.save(dto); |
1552 | 1586 | } |
1553 | 1587 |
|
@@ -1595,23 +1629,24 @@ void patch_twoExposures_normalAndCustomizableFields() { |
1595 | 1629 | } |
1596 | 1630 |
|
1597 | 1631 | private Map<CustomizableFieldMetadataDto, CustomizableFieldValueDto> customizableValuesForCase(String caseUuid) { |
1598 | | - return getBean(CustomizableFieldValueFacadeEjb.CustomizableFieldValueFacadeEjbLocal.class) |
1599 | | - .getValuesForEntity(caseUuid, CustomizableFieldContext.CASE); |
| 1632 | + return customizableValuesFor(caseUuid, CustomizableFieldContext.CASE); |
1600 | 1633 | } |
1601 | 1634 |
|
1602 | 1635 | private Map<CustomizableFieldMetadataDto, CustomizableFieldValueDto> customizableValuesForExposure(String exposureUuid) { |
1603 | | - return getBean(CustomizableFieldValueFacadeEjb.CustomizableFieldValueFacadeEjbLocal.class) |
1604 | | - .getValuesForEntity(exposureUuid, CustomizableFieldContext.EXPOSURE); |
| 1636 | + return customizableValuesFor(exposureUuid, CustomizableFieldContext.EXPOSURE); |
| 1637 | + } |
| 1638 | + |
| 1639 | + private Map<CustomizableFieldMetadataDto, CustomizableFieldValueDto> customizableValuesFor( |
| 1640 | + String exposureUuid, |
| 1641 | + CustomizableFieldContext exposure) { |
| 1642 | + return getBean(CustomizableFieldValueFacadeEjb.CustomizableFieldValueFacadeEjbLocal.class).getValuesForEntity(exposureUuid, exposure); |
| 1643 | + } |
| 1644 | + |
| 1645 | + private Map<CustomizableFieldMetadataDto, CustomizableFieldValueDto> customizableValuesForEpiData(String exposureUuid) { |
| 1646 | + return customizableValuesFor(exposureUuid, CustomizableFieldContext.EPIDATA); |
1605 | 1647 | } |
1606 | 1648 |
|
1607 | 1649 | private CustomizableFieldMetadataDto createExposureCustomField(String name, CustomizableFieldType type) { |
1608 | | - CustomizableFieldMetadataFacade facade = getBean(CustomizableFieldMetadataFacadeEjb.CustomizableFieldMetadataFacadeEjbLocal.class); |
1609 | | - CustomizableFieldMetadataDto dto = new CustomizableFieldMetadataDto(); |
1610 | | - dto.setName(name); |
1611 | | - dto.setFieldType(type); |
1612 | | - dto.setContextClass(CustomizableFieldContext.EXPOSURE); |
1613 | | - dto.setUiGroup(CustomizableFieldGroup.getGroupsForContext(CustomizableFieldContext.EXPOSURE).stream().findFirst().orElseThrow()); |
1614 | | - dto.setUiLinePosition(1); |
1615 | | - return facade.save(dto); |
| 1650 | + return createCustomFieldFor(name, type, CustomizableFieldContext.EXPOSURE); |
1616 | 1651 | } |
1617 | 1652 | } |
0 commit comments