Search in sources :

Example 1 with QuestionNotFoundException

use of org.eyeseetea.malariacare.domain.exception.QuestionNotFoundException in project pictureapp by EyeSeeTea.

the class DataConverterStrategy method convertOrgUnitDataValue.

private void convertOrgUnitDataValue(ConvertFromSDKVisitor converter, EventExtended event) throws QuestionNotFoundException {
    if (event.getProgramUId().equals(mContext.getString(R.string.stockProgramUID))) {
        return;
    }
    Question orgUnitQuestion = Question.findByUID(ORG_UNIT_QUESTION_UID);
    if (orgUnitQuestion == null) {
        throw new QuestionNotFoundException(String.format("Question with uid %s not found", ORG_UNIT_QUESTION_UID));
    }
    DataValueExtended OrgUnitDataValue = new DataValueExtended();
    OrgUnitDataValue.setEvent(event.getEvent());
    OrgUnitDataValue.setDataElement(orgUnitQuestion.getUid());
    OrgUnitDataValue.setValue(event.getOrganisationUnitId());
    OrgUnitDataValue.accept(converter);
}
Also used : QuestionNotFoundException(org.eyeseetea.malariacare.domain.exception.QuestionNotFoundException) Question(org.eyeseetea.malariacare.data.database.model.Question) DataValueExtended(org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended)

Example 2 with QuestionNotFoundException

use of org.eyeseetea.malariacare.domain.exception.QuestionNotFoundException in project pictureapp by EyeSeeTea.

the class DataConverter method convert.

public void convert(IPullController.Callback callback, ConvertFromSDKVisitor converter) {
    String orgUnitName = PreferencesState.getInstance().getOrgUnit();
    List<OrgUnit> orgUnits = converter.getOrgUnits();
    for (OrgUnit orgUnit : orgUnits) {
        //Only events for the right ORGUNIT are loaded
        if (!orgUnitName.isEmpty() && orgUnit.getName() != null && !orgUnit.getName().equals(orgUnitName)) {
            continue;
        }
        List<Program> programs = Program.getAllPrograms();
        for (Program program : programs) {
            List<EventExtended> events = EventExtended.getExtendedList(SdkQueries.getEvents(orgUnit.getUid(), program.getUid()));
            callback.onStep(BUILDING_SURVEYS);
            for (EventExtended event : events) {
                event.accept(converter);
            }
            callback.onStep(BUILDING_VALUES);
            for (EventExtended event : events) {
                List<DataValueExtended> dataValues = DataValueExtended.getExtendedList(SdkQueries.getDataValues(event.getUid()));
                for (DataValueExtended dataValueExtended : dataValues) {
                    dataValueExtended.accept(converter);
                }
                try {
                    dataConverterStrategy.convert(converter, event);
                } catch (QuestionNotFoundException e) {
                    callback.onError(e);
                }
            }
        }
    }
    saveConvertedSurveys(callback, converter);
}
Also used : OrgUnit(org.eyeseetea.malariacare.data.database.model.OrgUnit) Program(org.eyeseetea.malariacare.data.database.model.Program) EventExtended(org.eyeseetea.malariacare.data.sync.importer.models.EventExtended) QuestionNotFoundException(org.eyeseetea.malariacare.domain.exception.QuestionNotFoundException) DataValueExtended(org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended)

Aggregations

DataValueExtended (org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended)2 QuestionNotFoundException (org.eyeseetea.malariacare.domain.exception.QuestionNotFoundException)2 OrgUnit (org.eyeseetea.malariacare.data.database.model.OrgUnit)1 Program (org.eyeseetea.malariacare.data.database.model.Program)1 Question (org.eyeseetea.malariacare.data.database.model.Question)1 EventExtended (org.eyeseetea.malariacare.data.sync.importer.models.EventExtended)1