use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class SystemSettingsTests method deleteSystemSetting.
@Test
public void deleteSystemSetting() {
prepareData();
ApiResponse response = systemSettingActions.delete(APPLICATION_INTRO_KEY);
response.validate().statusCode(204);
response = systemSettingActions.get(APPLICATION_INTRO_KEY, ContentType.TEXT.toString(), ContentType.TEXT.toString(), new QueryParamsBuilder());
response.validate().statusCode(200);
assertEquals(StringUtils.EMPTY, response.getAsString());
}
use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class TrackedEntityInstanceAclReadTests method setupAccessMap.
/**
* Finds metadata a user has access to and determines what data can be read
* or not based on sharing.
*
* @param user the user to setup
*/
private void setupAccessMap(User user) {
Map<String, List<String>> dataRead = new HashMap<>();
// Configure params to only return metadata we care about
String params = (new QueryParamsBuilder()).add("trackedEntityTypes=true").add("dataElements=true").add("relationshipTypes=true").add("programs=true").add("trackedEntityAttributes=true").add("programStages=true").add("fields=id,userAccesses,publicAccess,userGroupAccesses").build();
ApiResponse response = metadataActions.get(params);
// Build map
response.getBody().entrySet().forEach((entry) -> {
// Skip the System property.
if (!entry.getKey().equals("system")) {
dataRead.put(entry.getKey(), new ArrayList<>());
entry.getValue().getAsJsonArray().forEach(obj -> {
JsonObject object = obj.getAsJsonObject();
boolean hasDataRead = false;
if (object.has("publicAccess") && object.get("publicAccess").getAsString().matches(_DATAREAD)) {
hasDataRead = true;
} else {
JsonArray userAccesses = object.getAsJsonArray("userAccesses").getAsJsonArray();
JsonArray userGroupAccess = object.getAsJsonArray("userGroupAccesses").getAsJsonArray();
for (JsonElement access : userAccesses) {
if (access.getAsJsonObject().get("userUid").getAsString().equals(user.getUid()) && access.getAsJsonObject().get("access").getAsString().matches(_DATAREAD)) {
hasDataRead = true;
}
}
if (!hasDataRead) {
for (JsonElement access : userGroupAccess) {
if (user.getGroups().contains(access.getAsJsonObject().get("userGroupUid").getAsString()) && access.getAsJsonObject().get("access").getAsString().matches(_DATAREAD)) {
hasDataRead = true;
}
}
}
}
if (hasDataRead) {
dataRead.get(entry.getKey()).add(obj.getAsJsonObject().get("id").getAsString());
}
});
}
});
user.setDataRead(dataRead);
}
use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class MetadataImportTest method shouldReturnObjectReportsWhenSomeMetadataWasIgnoredAndAtomicModeFalse.
@Test
public void shouldReturnObjectReportsWhenSomeMetadataWasIgnoredAndAtomicModeFalse() throws Exception {
// arrange
QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder();
queryParamsBuilder.addAll("async=false", "importReportMode=DEBUG", "importStrategy=CREATE", "atomicMode=NONE");
JsonObject object = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/metadata/uniqueMetadata.json"));
// act
ApiResponse response = metadataActions.post(object, queryParamsBuilder);
response.validate().statusCode(200);
JsonObject newObj = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/metadata/uniqueMetadata.json"));
// add one of the orgunits from already imported metadata to get it
// ignored
newObj.get("organisationUnits").getAsJsonArray().add(object.get("organisationUnits").getAsJsonArray().get(0));
response = metadataActions.post(newObj, queryParamsBuilder);
// assert
response.validate().statusCode(409).rootPath("response").body("stats", notNullValue()).body("stats.total", greaterThan(1)).body("stats.ignored", equalTo(1)).body("stats.created", equalTo((Integer) response.extract("response.stats.total") - 1));
int total = (int) response.extract("response.stats.total");
List<ObjectReport> objectReports = getObjectReports(response.getTypeReports());
assertNotNull(objectReports);
validateCreatedEntities(objectReports);
assertThat(objectReports, hasItems(hasProperty("errorReports", notNullValue())));
assertEquals(total, objectReports.size(), "Not all imported entities had object reports");
}
use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class MetadataImportTest method shouldUpdateExistingMetadata.
@ParameterizedTest(name = "withImportStrategy[{0}]")
@CsvSource({ "CREATE, ignored, 409", "CREATE_AND_UPDATE, updated, 200" })
public void shouldUpdateExistingMetadata(String importStrategy, String expected, int expectedStatusCode) {
// arrange
JsonObject exported = metadataActions.get().getBody();
QueryParamsBuilder queryParamsBuilder = new QueryParamsBuilder();
queryParamsBuilder.addAll("async=false", "importReportMode=FULL", "importStrategy=" + importStrategy);
// act
ApiResponse response = metadataActions.post(exported, queryParamsBuilder);
// assert
response.validate().statusCode(expectedStatusCode).rootPath("response").body("stats", notNullValue()).rootPath("response.stats").body("total", greaterThan(0)).body("created", Matchers.equalTo(0)).body("deleted", Matchers.equalTo(0)).body("total", equalTo(response.extract("response.stats." + expected)));
List<HashMap> typeReports = response.extractList("response.typeReports.stats");
typeReports.forEach(x -> {
assertEquals(x.get(expected), x.get("total"), expected + " for " + x + " not equals to total");
});
}
use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class OrgUnitProfileTests method shouldApplyDataItems.
@Test
public void shouldApplyDataItems() {
List<String> datItems = new DataItemActions().get("", new QueryParamsBuilder().add("filter=dimensionItemType:in:[DATA_ELEMENT,PROGRAM_INDICATOR]")).extractList("dataItems.id");
JsonArray array = new JsonArray();
datItems.forEach(p -> array.add(p));
orgUnitProfileActions.post(new JsonObjectBuilder().addArray("dataItems", array).build()).validate().statusCode(200);
orgUnitProfileActions.get().validate().body("dataItems", hasSize(greaterThanOrEqualTo(1)));
// todo add validation for organisationUnitProfile/id/data
}
Aggregations