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 @@ -118,7 +118,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 @@ -251,7 +250,6 @@ private void init() {
register(new LegendSetSchemaDescriptor());
register(new ExternalMapLayerSchemaDescriptor());
register(new MapSchemaDescriptor());
register(new MapViewSchemaDescriptor());
register(new MessageConversationSchemaDescriptor());
register(new MetadataVersionSchemaDescriptor());
register(new OAuth2ClientSchemaDescriptor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2995,7 +2995,7 @@ public static User createRandomAdminUserWithEntityManager(EntityManager entityMa
entityManager.persist(role);

User user = new User();
user.setUid("A_" + CodeGenerator.generateUid().substring(2));
user.setUid(CodeGenerator.generateUid());
user.setFirstName("Admin");
user.setSurname("User");
user.setUsername(DEFAULT_USERNAME + "_test_" + CodeGenerator.generateUid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,33 @@
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 javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
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.SingleSetupIntegrationTestBase;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -54,6 +66,14 @@ class MetadataExportWithDependenciesTest extends SingleSetupIntegrationTestBase
@PersistenceContext private EntityManager entityManager;
@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 @@ -117,4 +137,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 @@ -366,13 +366,17 @@ void testCopyProgramWithNoPublicSharing() {

@Test
void testDeleteWithMapView() {
String mapViewJson =

String mapJson =
"""
{
"name": "test map",
"id": "mAPVRd23Jm9",
"mapViews": [
{
"name": "test mapview",
"id": "mVIVRd23Jm9",
"organisationUnitLevels": [],
"maps": [],
"layer": "event",
"program": {
"id": "PrZMWi7rBga"
Expand All @@ -381,11 +385,15 @@ void testDeleteWithMapView() {
"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)));
JsonMixed mapview = GET("/mapViews/mVIVRd23Jm9").content().as(JsonMixed.class);
assertFalse(mapview.has("program"));
assertFalse(mapview.has("programStage"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
import org.hisp.dhis.query.Order;
import org.hisp.dhis.query.Query;
import org.hisp.dhis.query.QueryParserException;
import org.hisp.dhis.schema.descriptors.MapViewSchemaDescriptor;
import org.hisp.dhis.webapi.controller.AbstractCrudController;
import org.hisp.dhis.webapi.controller.AbstractFullReadOnlyController;
import org.hisp.dhis.webapi.utils.ContextUtils;
import org.hisp.dhis.webapi.webdomain.WebMetadata;
import org.hisp.dhis.webapi.webdomain.WebOptions;
Expand All @@ -64,8 +63,8 @@
*/
@OpenApi.Tags("metadata")
@Controller
@RequestMapping(value = MapViewSchemaDescriptor.API_ENDPOINT)
public class MapViewController extends AbstractCrudController<MapView> {
@RequestMapping("/mapViews")
public class MapViewController extends AbstractFullReadOnlyController<MapView> {
@Autowired private MappingService mappingService;

@Autowired private OrganisationUnitService organisationUnitService;
Expand Down
Loading