Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
import org.hisp.dhis.schema.descriptors.LegendSchemaDescriptor;
import org.hisp.dhis.schema.descriptors.LegendSetSchemaDescriptor;
import org.hisp.dhis.schema.descriptors.MapSchemaDescriptor;
import org.hisp.dhis.schema.descriptors.MapViewSchemaDescriptor;
import org.hisp.dhis.schema.descriptors.MessageConversationSchemaDescriptor;
import org.hisp.dhis.schema.descriptors.MetadataVersionSchemaDescriptor;
import org.hisp.dhis.schema.descriptors.MinMaxDataElementSchemaDescriptor;
Expand Down Expand Up @@ -252,7 +251,6 @@ private void init() {
register(new LegendSetSchemaDescriptor());
register(new ExternalMapLayerSchemaDescriptor());
register(new MapSchemaDescriptor());
register(new MapViewSchemaDescriptor());
register(new MessageConversationSchemaDescriptor());
register(new MetadataVersionSchemaDescriptor());
register(new OptionSchemaDescriptor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,31 @@
package org.hisp.dhis.metadata.export;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dxf2.metadata.MetadataExportParams;
import org.hisp.dhis.dxf2.metadata.MetadataExportService;
import org.hisp.dhis.dxf2.metadata.MetadataImportService;
import org.hisp.dhis.mapping.MapView;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramSection;
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.program.ProgramStageDataElement;
import org.hisp.dhis.program.ProgramTrackedEntityAttribute;
import org.hisp.dhis.render.RenderFormat;
import org.hisp.dhis.render.RenderService;
import org.hisp.dhis.test.integration.PostgresIntegrationTestBase;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -58,6 +70,14 @@ class MetadataExportWithDependenciesTest extends PostgresIntegrationTestBase {

@Autowired private MetadataExportService metadataExportService;

@Autowired private MetadataImportService metadataImportService;

@Autowired private IdentifiableObjectManager manager;

@Autowired private RenderService renderService;

@Autowired private ObjectMapper jsonMapper;

@Test
void testExportProgramWithProgramSection() {
Program program = createProgram('A');
Expand Down Expand Up @@ -121,4 +141,28 @@ private Program setUpProgramAndDependencies() {
entityManager.merge(programStage);
return program;
}

@Test
@DisplayName("MapView should not be exported at root level when exporting Map with dependencies")
void exportMetadataShouldNotContainMapView() throws IOException {
MapView mapView = createMapView("A");
org.hisp.dhis.mapping.Map map = new org.hisp.dhis.mapping.Map();
map.setName("MapA");
map.setMapViews(List.of(mapView));
map.setAutoFields();
manager.save(map);

MetadataExportParams exportParams = new MetadataExportParams();
exportParams.addClass(org.hisp.dhis.mapping.Map.class);
exportParams.addClass(MapView.class);
ObjectNode exported = metadataExportService.getMetadataAsObjectNode(exportParams);

Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata =
renderService.fromMetadata(
new ByteArrayInputStream(jsonMapper.writeValueAsBytes(exported)), RenderFormat.JSON);
assertNull(metadata.get(org.hisp.dhis.mapping.MapView.class));
org.hisp.dhis.mapping.Map exportMap =
(org.hisp.dhis.mapping.Map) metadata.get(org.hisp.dhis.mapping.Map.class).get(0);
assertNotNull(exportMap.getMapViews());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -443,23 +443,29 @@ void shouldUpdateProgramAndPersistChanges() {

@Test
void testDeleteWithMapView() {
String mapViewJson =

String mapJson =
"""
{
"name": "test mapview",
"id": "mVIVRd23Jm9",
"organisationUnitLevels": [],
"maps": [],
"layer": "event",
"program": {
"id": "PrZMWi7rBga"
},
"programStage": {
"id": "PSzMWi7rBga"
}
"name": "test map",
"id": "mAPVRd23Jm9",
"mapViews": [
{
"name": "test mapview",
"id": "mVIVRd23Jm9",
"organisationUnitLevels": [],
"layer": "event",
"program": {
"id": "PrZMWi7rBga"
},
"programStage": {
"id": "PSzMWi7rBga"
}
}
]
}
""";
POST("/mapViews", mapViewJson).content(HttpStatus.CREATED);
POST("/maps", mapJson).content(HttpStatus.CREATED);

assertStatus(HttpStatus.OK, DELETE("/programs/%s".formatted(PROGRAM_UID)));
assertStatus(HttpStatus.NOT_FOUND, GET("/programs/%s".formatted(PROGRAM_UID)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.query.GetObjectListParams;
import org.hisp.dhis.webapi.controller.AbstractCrudController;
import org.hisp.dhis.webapi.controller.AbstractFullReadOnlyController;
import org.hisp.dhis.webapi.utils.ContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
Expand All @@ -59,7 +59,8 @@
@Controller
@RequestMapping("/api/mapViews")
@OpenApi.Document(classifiers = {"team:analytics", "purpose:metadata"})
public class MapViewController extends AbstractCrudController<MapView, GetObjectListParams> {
public class MapViewController
extends AbstractFullReadOnlyController<MapView, GetObjectListParams> {
@Autowired private MappingService mappingService;

@Autowired private OrganisationUnitService organisationUnitService;
Expand Down
Loading