use of org.hisp.dhis.actions.IdGenerator in project dhis2-core by dhis2.
the class XmlFileReader method replacePropertyValuesWith.
@Override
public FileReader replacePropertyValuesWith(String propertyName, String replacedValue) {
XPath xPath = XPathFactory.newInstance().newXPath();
try {
NodeList nodes = (NodeList) xPath.evaluate("//*[@" + propertyName + "]", document, XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i).getAttributes().getNamedItem(propertyName);
if (replacedValue.equalsIgnoreCase("uniqueid")) {
node.setNodeValue(new IdGenerator().generateUniqueId());
continue;
}
node.setNodeValue(replacedValue);
}
} catch (XPathExpressionException e) {
e.printStackTrace();
}
return this;
}
use of org.hisp.dhis.actions.IdGenerator in project dhis2-core by dhis2.
the class EventImportDataValueValidationTests method setupData.
private void setupData() throws Exception {
programId = new IdGenerator().generateUniqueId();
programStageId = new IdGenerator().generateUniqueId();
JsonObject jsonObject = new JsonObjectBuilder(new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/eventProgram.json"))).addPropertyByJsonPath("programStages[0].program.id", programId).addPropertyByJsonPath("programs[0].id", programId).addPropertyByJsonPath("programs[0].programStages[0].id", programStageId).addPropertyByJsonPath("programStages[0].id", programStageId).addPropertyByJsonPath("programStages[0].programStageDataElements", null).build();
new MetadataActions().importAndValidateMetadata(jsonObject);
String dataElementId = dataElementActions.get("?fields=id&filter=domainType:eq:TRACKER&filter=valueType:eq:TEXT&pageSize=1").extractString("dataElements.id[0]");
assertNotNull(dataElementId, "Failed to create data elements");
mandatoryDataElementId = dataElementId;
programActions.addDataElement(programStageId, dataElementId, true).validate().statusCode(200);
}
use of org.hisp.dhis.actions.IdGenerator in project dhis2-core by dhis2.
the class EnrollmentsTests method shouldOnlyEnrollOnce.
@ValueSource(strings = { "true", "false" })
@ParameterizedTest
public void shouldOnlyEnrollOnce(String shouldEnrollOnce) throws Exception {
// arrange
String program = programActions.createTrackerProgram(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS).extractUid();
JsonObject object = programActions.get(program).getBodyAsJsonBuilder().addProperty("onlyEnrollOnce", shouldEnrollOnce).addProperty("publicAccess", "rwrw----").build();
programActions.update(program, object).validateStatus(200);
String tei = super.importTei();
JsonObject enrollment = new EnrollmentDataBuilder().setId(new IdGenerator().generateUniqueId()).array(program, Constants.ORG_UNIT_IDS[2], tei, "COMPLETED");
trackerActions.postAndGetJobReport(enrollment).validateSuccessfulImport();
// act
TrackerApiResponse response = trackerActions.postAndGetJobReport(new EnrollmentDataBuilder().array(program, Constants.ORG_UNIT_IDS[2], tei, "ACTIVE"));
// assert
if (Boolean.parseBoolean(shouldEnrollOnce)) {
response.validateErrorReport().body("errorCode", hasItems("E1016"));
return;
}
response.validateSuccessfulImport();
trackerActions.getTrackedEntity(tei + "?fields=enrollments").validate().body("enrollments", hasSize(2));
}
use of org.hisp.dhis.actions.IdGenerator in project dhis2-core by dhis2.
the class EnrollmentAttributeTests method shouldValidateUniquenessWithinThePayload.
@Test
public void shouldValidateUniquenessWithinThePayload() throws Exception {
String tei = importTei();
String teiB = importTei();
String value = DataGenerator.randomString();
Function<String, JsonObject> singleEnrollment = (teiId) -> {
return new EnrollmentDataBuilder().setId(new IdGenerator().generateUniqueId()).setTei(teiId).addAttribute(uniqueAttributeId, value).setProgram(programId).setOu(Constants.ORG_UNIT_IDS[1]).single();
};
JsonObject payload = new JsonObjectBuilder().addOrAppendToArray("enrollments", singleEnrollment.apply(tei), singleEnrollment.apply(teiB)).build();
trackerActions.postAndGetJobReport(payload).validateErrorReport();
}
use of org.hisp.dhis.actions.IdGenerator in project dhis2-core by dhis2.
the class EnrollmentAttributeTests method shouldRemoveAttributeValue.
@Test
public void shouldRemoveAttributeValue() throws Exception {
String tei = importTei();
JsonObject payload = new EnrollmentDataBuilder().setId(new IdGenerator().generateUniqueId()).setTei(tei).addAttribute(optionSetAttributeId, "TA_YES").array(programId, Constants.ORG_UNIT_IDS[1]);
trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
payload = new JsonObjectBuilder(payload).addPropertyByJsonPath("enrollments[0].attributes[0].value", null).build();
trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
trackerActions.getTrackedEntity(tei + "?program=" + programId).validateStatus(200).validate().statusCode(200).body("attributes", hasSize(greaterThanOrEqualTo(1))).body("attributes.attribute", not(hasItem(optionSetAttributeId))).body("attributes.value", not(hasItem("TA_YES")));
}
Aggregations