Skip to content

Commit 1b27390

Browse files
authored
fix: mapView should not be exported at root level (#23943)
1 parent 3e61a3d commit 1b27390

4 files changed

Lines changed: 66 additions & 17 deletions

File tree

dhis-2/dhis-services/dhis-service-schema/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@
121121
import org.hisp.dhis.schema.descriptors.LegendSchemaDescriptor;
122122
import org.hisp.dhis.schema.descriptors.LegendSetSchemaDescriptor;
123123
import org.hisp.dhis.schema.descriptors.MapSchemaDescriptor;
124-
import org.hisp.dhis.schema.descriptors.MapViewSchemaDescriptor;
125124
import org.hisp.dhis.schema.descriptors.MessageConversationSchemaDescriptor;
126125
import org.hisp.dhis.schema.descriptors.MetadataVersionSchemaDescriptor;
127126
import org.hisp.dhis.schema.descriptors.MinMaxDataElementSchemaDescriptor;
@@ -252,7 +251,6 @@ private void init() {
252251
register(new LegendSetSchemaDescriptor());
253252
register(new ExternalMapLayerSchemaDescriptor());
254253
register(new MapSchemaDescriptor());
255-
register(new MapViewSchemaDescriptor());
256254
register(new MessageConversationSchemaDescriptor());
257255
register(new MetadataVersionSchemaDescriptor());
258256
register(new OptionSchemaDescriptor());

dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/metadata/export/MetadataExportWithDependenciesTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,31 @@
3030
package org.hisp.dhis.metadata.export;
3131

3232
import static org.junit.jupiter.api.Assertions.assertEquals;
33+
import static org.junit.jupiter.api.Assertions.assertNotNull;
3334
import static org.junit.jupiter.api.Assertions.assertNull;
3435

36+
import com.fasterxml.jackson.databind.ObjectMapper;
37+
import com.fasterxml.jackson.databind.node.ObjectNode;
38+
import java.io.ByteArrayInputStream;
39+
import java.io.IOException;
40+
import java.util.List;
3541
import java.util.Map;
3642
import java.util.Set;
3743
import org.hisp.dhis.common.IdentifiableObject;
44+
import org.hisp.dhis.common.IdentifiableObjectManager;
3845
import org.hisp.dhis.common.ValueType;
3946
import org.hisp.dhis.dataelement.DataElement;
47+
import org.hisp.dhis.dxf2.metadata.MetadataExportParams;
4048
import org.hisp.dhis.dxf2.metadata.MetadataExportService;
49+
import org.hisp.dhis.dxf2.metadata.MetadataImportService;
50+
import org.hisp.dhis.mapping.MapView;
4151
import org.hisp.dhis.program.Program;
4252
import org.hisp.dhis.program.ProgramSection;
4353
import org.hisp.dhis.program.ProgramStage;
4454
import org.hisp.dhis.program.ProgramStageDataElement;
4555
import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
56+
import org.hisp.dhis.render.RenderFormat;
57+
import org.hisp.dhis.render.RenderService;
4658
import org.hisp.dhis.test.integration.PostgresIntegrationTestBase;
4759
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
4860
import org.junit.jupiter.api.DisplayName;
@@ -58,6 +70,14 @@ class MetadataExportWithDependenciesTest extends PostgresIntegrationTestBase {
5870

5971
@Autowired private MetadataExportService metadataExportService;
6072

73+
@Autowired private MetadataImportService metadataImportService;
74+
75+
@Autowired private IdentifiableObjectManager manager;
76+
77+
@Autowired private RenderService renderService;
78+
79+
@Autowired private ObjectMapper jsonMapper;
80+
6181
@Test
6282
void testExportProgramWithProgramSection() {
6383
Program program = createProgram('A');
@@ -121,4 +141,28 @@ private Program setUpProgramAndDependencies() {
121141
entityManager.merge(programStage);
122142
return program;
123143
}
144+
145+
@Test
146+
@DisplayName("MapView should not be exported at root level when exporting Map with dependencies")
147+
void exportMetadataShouldNotContainMapView() throws IOException {
148+
MapView mapView = createMapView("A");
149+
org.hisp.dhis.mapping.Map map = new org.hisp.dhis.mapping.Map();
150+
map.setName("MapA");
151+
map.setMapViews(List.of(mapView));
152+
map.setAutoFields();
153+
manager.save(map);
154+
155+
MetadataExportParams exportParams = new MetadataExportParams();
156+
exportParams.addClass(org.hisp.dhis.mapping.Map.class);
157+
exportParams.addClass(MapView.class);
158+
ObjectNode exported = metadataExportService.getMetadataAsObjectNode(exportParams);
159+
160+
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata =
161+
renderService.fromMetadata(
162+
new ByteArrayInputStream(jsonMapper.writeValueAsBytes(exported)), RenderFormat.JSON);
163+
assertNull(metadata.get(org.hisp.dhis.mapping.MapView.class));
164+
org.hisp.dhis.mapping.Map exportMap =
165+
(org.hisp.dhis.mapping.Map) metadata.get(org.hisp.dhis.mapping.Map.class).get(0);
166+
assertNotNull(exportMap.getMapViews());
167+
}
124168
}

dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/ProgramControllerTest.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -443,23 +443,29 @@ void shouldUpdateProgramAndPersistChanges() {
443443

444444
@Test
445445
void testDeleteWithMapView() {
446-
String mapViewJson =
446+
447+
String mapJson =
447448
"""
448449
{
449-
"name": "test mapview",
450-
"id": "mVIVRd23Jm9",
451-
"organisationUnitLevels": [],
452-
"maps": [],
453-
"layer": "event",
454-
"program": {
455-
"id": "PrZMWi7rBga"
456-
},
457-
"programStage": {
458-
"id": "PSzMWi7rBga"
459-
}
450+
"name": "test map",
451+
"id": "mAPVRd23Jm9",
452+
"mapViews": [
453+
{
454+
"name": "test mapview",
455+
"id": "mVIVRd23Jm9",
456+
"organisationUnitLevels": [],
457+
"layer": "event",
458+
"program": {
459+
"id": "PrZMWi7rBga"
460+
},
461+
"programStage": {
462+
"id": "PSzMWi7rBga"
463+
}
464+
}
465+
]
460466
}
461467
""";
462-
POST("/mapViews", mapViewJson).content(HttpStatus.CREATED);
468+
POST("/maps", mapJson).content(HttpStatus.CREATED);
463469

464470
assertStatus(HttpStatus.OK, DELETE("/programs/%s".formatted(PROGRAM_UID)));
465471
assertStatus(HttpStatus.NOT_FOUND, GET("/programs/%s".formatted(PROGRAM_UID)));

dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapViewController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import org.hisp.dhis.organisationunit.OrganisationUnit;
4444
import org.hisp.dhis.organisationunit.OrganisationUnitService;
4545
import org.hisp.dhis.query.GetObjectListParams;
46-
import org.hisp.dhis.webapi.controller.AbstractCrudController;
46+
import org.hisp.dhis.webapi.controller.AbstractFullReadOnlyController;
4747
import org.hisp.dhis.webapi.utils.ContextUtils;
4848
import org.springframework.beans.factory.annotation.Autowired;
4949
import org.springframework.stereotype.Controller;
@@ -59,7 +59,8 @@
5959
@Controller
6060
@RequestMapping("/api/mapViews")
6161
@OpenApi.Document(classifiers = {"team:analytics", "purpose:metadata"})
62-
public class MapViewController extends AbstractCrudController<MapView, GetObjectListParams> {
62+
public class MapViewController
63+
extends AbstractFullReadOnlyController<MapView, GetObjectListParams> {
6364
@Autowired private MappingService mappingService;
6465

6566
@Autowired private OrganisationUnitService organisationUnitService;

0 commit comments

Comments
 (0)