use of org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject in project dhis2-core by dhis2.
the class SharingControllerTest method testPostSharing_InvalidPublicSharing.
@Test
void testPostSharing_InvalidPublicSharing() {
String groupId = assertStatus(HttpStatus.CREATED, POST("/userGroups", "{'name':'test'}"));
JsonIdentifiableObject group = GET("/userGroups/{id}", groupId).content().as(JsonIdentifiableObject.class);
JsonNode sharing = group.getSharing().node().extract().addMember("publicAccess", "\"xyz\"");
assertWebMessage("Conflict", 409, "ERROR", "Invalid public access string: xyz", POST("/sharing?type=userGroup&id=" + groupId, "{'object': " + sharing.getDeclaration() + "}").content(HttpStatus.CONFLICT));
}
use of org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject in project dhis2-core by dhis2.
the class MetadataImportExportControllerTest method testPostValidGeoJsonAttribute.
@Test
void testPostValidGeoJsonAttribute() throws IOException {
POST("/metadata", "{\"organisationUnits\": [ {\"id\":\"rXnqqH2Pu6N\",\"name\": \"My Unit 2\",\"shortName\": \"OU2\",\"openingDate\": \"2020-01-01\"," + "\"attributeValues\": [{\"value\": \"{\\\"type\\\": \\\"Polygon\\\"," + "\\\"coordinates\\\": [[[100,0],[101,0],[101,1],[100,1],[100,0]]] }\"," + "\"attribute\": {\"id\": \"RRH9IFiZZYN\"}}]}]," + "\"attributes\":[{\"id\":\"RRH9IFiZZYN\",\"valueType\":\"GEOJSON\",\"organisationUnitAttribute\":true,\"name\":\"testgeojson\"}]}").content(HttpStatus.OK);
JsonIdentifiableObject organisationUnit = GET("/organisationUnits/{id}", "rXnqqH2Pu6N").content().asObject(JsonIdentifiableObject.class);
assertEquals(1, organisationUnit.getAttributeValues().size());
JsonAttributeValue attributeValue = organisationUnit.getAttributeValues().get(0);
GeoJsonObject geoJSON = new ObjectMapper().readValue(attributeValue.getValue(), GeoJsonObject.class);
assertTrue(geoJSON instanceof Polygon);
Polygon polygon = (Polygon) geoJSON;
assertEquals(100, polygon.getCoordinates().get(0).get(0).getLongitude());
}
use of org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject in project dhis2-core by dhis2.
the class BulkPatchSharingControllerTest method testApplyPatchWithInvalidUidAtomic.
/**
* Payload contains two DataElements but only one exists in database. Atomic
* = true so no sharing settings will be saved.
*
* @throws IOException
*/
@Test
void testApplyPatchWithInvalidUidAtomic() throws IOException {
assertStatus(HttpStatus.CREATED, POST("/users", createUser("usera", userAId)));
assertStatus(HttpStatus.CREATED, POST("/users", createUser("userb", userBId)));
userCId = assertStatus(HttpStatus.CREATED, POST("/users", createUser("userc")));
assertStatus(HttpStatus.CREATED, POST("/dataElements", jsonMapper.writeValueAsString(createDataElement('B', deBId, userCId))));
HttpResponse response = PATCH("/dataElements/sharing?atomic=true", "patch/bulk_sharing_patch.json");
assertEquals(HttpStatus.CONFLICT, response.status());
assertEquals("Invalid UID `" + deAId + "` for property `dataElement`", getFirstErrorMessage(response));
JsonIdentifiableObject savedDeB = GET("/dataElements/{uid}", deBId).content(HttpStatus.OK).as(JsonIdentifiableObject.class);
assertEquals(0, savedDeB.getSharing().getUsers().size());
}
use of org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject in project dhis2-core by dhis2.
the class AbstractCrudControllerTest method testSetSharing.
@Test
void testSetSharing() {
String userId = getCurrentUser().getUid();
// first create an object which can be shared
String programId = assertStatus(HttpStatus.CREATED, POST("/programs/", "{'name':'test', 'shortName':'test', 'programType':'WITHOUT_REGISTRATION'}"));
String sharing = "{'owner':'" + userId + "', 'public':'rwrw----', 'external': true }";
assertStatus(HttpStatus.NO_CONTENT, PUT("/programs/" + programId + "/sharing", sharing));
JsonIdentifiableObject program = GET("/programs/{id}", programId).content().as(JsonIdentifiableObject.class);
assertTrue(program.exists());
assertEquals("rwrw----", program.getSharing().getPublic().string());
assertFalse(program.getSharing().isExternal(), "programs cannot be external");
}
use of org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject in project dhis2-core by dhis2.
the class BulkPatchSharingControllerTest method testApplyPatchWithInvalidUid.
/**
* Payload contains two DataElements but only one exists in database.
*
* @throws IOException
*/
@Test
void testApplyPatchWithInvalidUid() throws IOException {
assertStatus(HttpStatus.CREATED, POST("/users", createUser("usera", userAId)));
assertStatus(HttpStatus.CREATED, POST("/users", createUser("userb", userBId)));
userCId = assertStatus(HttpStatus.CREATED, POST("/users", createUser("userc")));
assertStatus(HttpStatus.CREATED, POST("/dataElements", toJsonString(createDataElement('B', deBId, userCId))));
HttpResponse response = PATCH("/dataElements/sharing", "patch/bulk_sharing_patch.json");
assertEquals(HttpStatus.CONFLICT, response.status());
assertEquals("Invalid UID `" + deAId + "` for property `dataElement`", getFirstErrorMessage(response));
JsonIdentifiableObject savedDeB = GET("/dataElements/{uid}", deBId).content(HttpStatus.OK).as(JsonIdentifiableObject.class);
assertEquals(2, savedDeB.getSharing().getUsers().size());
assertNotNull(savedDeB.getSharing().getUsers().get(userAId));
assertNotNull(savedDeB.getSharing().getUsers().get(userBId));
}
Aggregations