use of org.hisp.dhis.android.core.program.Program in project dhis2-android-sdk by dhis2.
the class MetadataCall method getAssignedTrackedEntityUids.
private Set<String> getAssignedTrackedEntityUids(List<Program> programs) {
if (programs == null) {
return null;
}
Set<String> uids = new HashSet<>();
int size = programs.size();
for (int i = 0; i < size; i++) {
Program program = programs.get(i);
if (program.trackedEntity() != null) {
uids.add(program.trackedEntity().uid());
}
}
return uids;
}
use of org.hisp.dhis.android.core.program.Program in project dhis2-android-sdk by dhis2.
the class ProgramModelPayloadShould method map_from_json_string.
@Test
public void map_from_json_string() throws Exception {
ObjectMapper objectMapper = Inject.objectMapper();
Payload<Program> payload = objectMapper.readValue("{\n" + "\n" + " \"programs\": [\n" + " {\n" + " \"id\": \"IpHINAT79UW\",\n" + " \"version\": 3,\n" + " \"programStages\": [\n" + " {\n" + " \"id\": \"A03MvHHogjR\",\n" + " \"programStageDataElements\": [\n" + " {\n" + " \"id\": \"LBNxoXdMnkv\",\n" + " \"dataElement\": {\n" + " \"id\": \"a3kGcGDCuk6\"\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"yYMGxXpfl0Z\",\n" + " \"dataElement\": {\n" + " \"id\": \"H6uSAMO5WLD\"\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"u2FvnCDCBcD\",\n" + " \"dataElement\": {\n" + " \"id\": \"UXz7xuGCEhU\"\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"XLFc6tTftb5\",\n" + " \"dataElement\": {\n" + " \"id\": \"wQLfBvPrXqq\",\n" + " \"optionSet\": {\n" + " \"id\": \"f38bstJioPs\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"p8eX3rSkKN0\",\n" + " \"dataElement\": {\n" + " \"id\": \"bx6fsa0t90x\"\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"O4dwFWakvGO\",\n" + " \"dataElement\": {\n" + " \"id\": \"ebaJjqltK5N\",\n" + " \"optionSet\": {\n" + " \"id\": \"kzgQRhOCadd\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"xtjAxBGQNNV\",\n" + " \"dataElement\": {\n" + " \"id\": \"X8zyunlgUfM\",\n" + " \"optionSet\": {\n" + " \"id\": \"x31y45jvIQL\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"JYyXbTmBBls\",\n" + " \"dataElement\": {\n" + " \"id\": \"uf3svrmp8Oj\"\n" + " }\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"id\": \"ZzYYXq4fJie\",\n" + " \"programStageDataElements\": [\n" + " {\n" + " \"id\": \"ztoQtbuXzsI\",\n" + " \"dataElement\": {\n" + " \"id\": \"GQY2lXrypjO\"\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"vdc1saaN2ma\",\n" + " \"dataElement\": {\n" + " \"id\": \"X8zyunlgUfM\",\n" + " \"optionSet\": {\n" + " \"id\": \"x31y45jvIQL\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"Vpx18GqyLcK\",\n" + " \"dataElement\": {\n" + " \"id\": \"FqlgKAG8HOu\"\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"WlYechRHVo3\",\n" + " \"dataElement\": {\n" + " \"id\": \"vTUhAUZFoys\",\n" + " \"optionSet\": {\n" + " \"id\": \"kzgQRhOCadd\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"WucAVPYvcEO\",\n" + " \"dataElement\": {\n" + " \"id\": \"rxBfISxXS2U\"\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"EL5dr5x0WbZ\",\n" + " \"dataElement\": {\n" + " \"id\": \"lNNb3truQoi\",\n" + " \"optionSet\": {\n" + " \"id\": \"nH8Y04zS7UV\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"IpPWDRlHJSe\",\n" + " \"dataElement\": {\n" + " \"id\": \"pOe0ogW4OWd\",\n" + " \"optionSet\": {\n" + " \"id\": \"udkr3ihaeD3\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"xSTVGEIbarb\",\n" + " \"dataElement\": {\n" + " \"id\": \"HLmTEmupdX0\"\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"YCO2FVT0wXL\",\n" + " \"dataElement\": {\n" + " \"id\": \"cYGaxwK615G\",\n" + " \"optionSet\": {\n" + " \"id\": \"oXR37f2wOb1\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"VlOvjLKnoyw\",\n" + " \"dataElement\": {\n" + " \"id\": \"hDZbpskhqDd\",\n" + " \"optionSet\": {\n" + " \"id\": \"OGmE3wUMEzu\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"rqmcdr07fxQ\",\n" + " \"dataElement\": {\n" + " \"id\": \"sj3j9Hwc7so\",\n" + " \"optionSet\": {\n" + " \"id\": \"dgsftM0rXu2\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"LfgZNmadu4W\",\n" + " \"dataElement\": {\n" + " \"id\": \"aei1xRjSU2l\",\n" + " \"optionSet\": {\n" + " \"id\": \"XdI8KRJiRoZ\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"sfYk4rKw18B\",\n" + " \"dataElement\": {\n" + " \"id\": \"BeynU4L6VCQ\",\n" + " \"optionSet\": {\n" + " \"id\": \"XdI8KRJiRoZ\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"LiV2YoatDud\",\n" + " \"dataElement\": {\n" + " \"id\": \"OuJ6sgPyAbC\"\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " ],\n" + " \"programTrackedEntityAttributes\": [\n" + " {\n" + " \"id\": \"K6BlNQdIxd1\",\n" + " \"trackedEntityAttribute\": {\n" + " \"id\": \"w75KJ2mc4zz\"\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"oGv9KGJpqkl\",\n" + " \"trackedEntityAttribute\": {\n" + " \"id\": \"zDhUuAYrxNC\"\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"YhqgQ6Iy4c4\",\n" + " \"trackedEntityAttribute\": {\n" + " \"id\": \"cejWyOfXge6\",\n" + " \"optionSet\": {\n" + " \"id\": \"pC3N9N77UmT\"\n" + " }\n" + " }\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"id\": \"q04UBOqq3rp\",\n" + " \"version\": 1,\n" + " \"programStages\": [\n" + " {\n" + " \"id\": \"pSllsjpfLH2\",\n" + " \"programStageDataElements\": [\n" + " {\n" + " \"id\": \"apYCBRwEc44\",\n" + " \"dataElement\": {\n" + " \"id\": \"f3Rn9XPEQuv\",\n" + " \"optionSet\": {\n" + " \"id\": \"s3GoZHCmXL2\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"OOGft1qHHnN\",\n" + " \"dataElement\": {\n" + " \"id\": \"Dv7iIitX44Y\",\n" + " \"optionSet\": {\n" + " \"id\": \"VQ2lai3OfVG\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"ulVsVS36Zpm\",\n" + " \"dataElement\": {\n" + " \"id\": \"UuL3eX8KJHY\",\n" + " \"optionSet\": {\n" + " \"id\": \"PmE3Ev4ZcHX\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"o5M0cNMVKY3\",\n" + " \"dataElement\": {\n" + " \"id\": \"deQEw93Vr4j\",\n" + " \"optionSet\": {\n" + " \"id\": \"s3GoZHCmXL2\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"cLhp2K7tqAP\",\n" + " \"dataElement\": {\n" + " \"id\": \"DvrjjquRrvF\",\n" + " \"optionSet\": {\n" + " \"id\": \"Da7byW1wGzq\"\n" + " }\n" + " }\n" + " },\n" + " {\n" + " \"id\": \"BAZe68syer0\",\n" + " \"dataElement\": {\n" + " \"id\": \"lsJCUffec9h\"\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " ],\n" + " \"programTrackedEntityAttributes\": [ ]\n" + " }\n" + " ]\n" + "\n" + "}", new TypeReference<Payload<Program>>() {
});
List<Program> programs = payload.items();
assertThat(programs).isNotNull();
assertThat(programs).isNotEmpty();
assertThat(programs.size()).isEqualTo(2);
Program program = programs.get(0);
assertThat(program.uid()).isEqualTo("IpHINAT79UW");
assertThat(program.version()).isEqualTo(3);
assertThat(program.programStages()).isNotNull();
assertThat(program.programStages()).isNotEmpty();
Program program1 = programs.get(1);
assertThat(program1.uid()).isEqualTo("q04UBOqq3rp");
assertThat(program1.version()).isEqualTo(1);
assertThat(program1.programStages()).isNotNull();
assertThat(program1.programStages()).isNotEmpty();
ObjectWithUid programStage1 = program1.programStages().get(0);
assertThat(programStage1.uid()).isEqualTo("pSllsjpfLH2");
}
use of org.hisp.dhis.android.core.program.Program in project dhis2-android-sdk by dhis2.
the class MetadataCall method call.
@SuppressWarnings("PMD.NPathComplexity")
@Override
public Response call() throws Exception {
synchronized (this) {
if (isExecuted) {
throw new IllegalStateException("Already executed");
}
isExecuted = true;
}
Response response = null;
Transaction transaction = databaseAdapter.beginNewTransaction();
try {
response = new SystemInfoCall(databaseAdapter, systemInfoStore, systemInfoService, resourceStore).call();
if (!response.isSuccessful()) {
return response;
}
GenericCallData data = GenericCallData.create(databaseAdapter, new ResourceHandler(resourceStore), retrofit);
Response<User> userResponse = new UserCall(userService, databaseAdapter, userStore, userCredentialsStore, userRoleStore, resourceStore, data.serverDate()).call();
response = userResponse;
if (!response.isSuccessful()) {
return response;
}
response = downloadCategories(data.serverDate());
if (!response.isSuccessful()) {
return response;
}
response = downloadCategoryCombos(data.serverDate());
if (!response.isSuccessful()) {
return response;
}
Response<Payload<Program>> programAccessResponse = ProgramAccessEndpointCall.FACTORY.create(data, programService).call();
response = programAccessResponse;
if (!response.isSuccessful()) {
return response;
}
Set<String> programUids = getProgramUidsWithDataReadAccess(programAccessResponse.body().items());
response = new ProgramCall(programService, databaseAdapter, resourceStore, programUids, programStore, data.serverDate(), trackedEntityAttributeStore, programTrackedEntityAttributeStore, programRuleVariableStore, programIndicatorStore, programStageSectionProgramIndicatorLinkStore, programRuleActionStore, programRuleStore, relationshipStore, styleHandler, renderTypeHandler).call();
if (!response.isSuccessful()) {
return response;
}
List<Program> programs = ((Response<Payload<Program>>) response).body().items();
Set<String> assignedProgramStageUids = getAssignedProgramStageUids(programs);
Response programStageResponse = programStageCallFactory.create(data, assignedProgramStageUids).call();
if (!programStageResponse.isSuccessful()) {
return programStageResponse;
}
Set<String> trackedEntityUids = getAssignedTrackedEntityUids(programs);
response = new TrackedEntityCall(trackedEntityUids, databaseAdapter, trackedEntityStore, resourceStore, trackedEntityService, data.serverDate()).call();
if (!response.isSuccessful()) {
return response;
}
User user = userResponse.body();
Response<Payload<OrganisationUnit>> organisationUnitResponse = organisationUnitCallFactory.create(data, user, programUids).call();
if (!organisationUnitResponse.isSuccessful()) {
return organisationUnitResponse;
}
List<ProgramStage> programStages = ((Response<Payload<ProgramStage>>) programStageResponse).body().items();
Set<String> optionSetUids = getAssignedOptionSetUids(programs, programStages);
response = new OptionSetCall(data, optionSetService, optionSetHandler, optionSetUids).call();
if (!response.isSuccessful()) {
return response;
}
List<OrganisationUnit> organisationUnits = organisationUnitResponse.body().items();
response = dataSetParentCallFactory.create(user, data, organisationUnits).call();
if (!response.isSuccessful()) {
return response;
}
transaction.setSuccessful();
return response;
} finally {
transaction.end();
}
}
Aggregations