Search in sources :

Example 1 with LbdsSyncDao

use of de.symeda.sormas.app.backend.lbds.LbdsSyncDao in project SORMAS-Project by hzi-braunschweig.

the class LbdsIntentSender method getNewCasesToSendLbds.

private static List<CaseDataDto> getNewCasesToSendLbds() {
    CaseDao caseDao = DatabaseHelper.getCaseDao();
    LbdsSyncDao lbdsSyncDao = DatabaseHelper.getLbdsSyncDao();
    CaseDtoHelper caseDtoHelper = new CaseDtoHelper();
    List<Case> modifiedCases = caseDao.getModifiedEntities();
    List<CaseDataDto> casesToSend = new ArrayList<>();
    for (Case caze : modifiedCases) {
        if ((!caze.isNew()) || lbdsSyncDao.hasBeenSuccessfullySent(caze)) {
            continue;
        }
        CaseDataDto caseDataDto = caseDtoHelper.adoToDto(caze);
        if (caseDataDto.getHealthFacility() == null) {
            caseDataDto.setHealthFacility(new FacilityReferenceDto(FacilityDto.NONE_FACILITY_UUID));
        }
        try {
            LbdsDtoHelper.stripLbdsDto(caseDataDto);
        } catch (IllegalAccessException | IntrospectionException | InvocationTargetException e) {
            throw new IllegalArgumentException("LBDS preparation failed for case " + caze.getUuid(), e);
        }
        casesToSend.add(caseDataDto);
    }
    return casesToSend;
}
Also used : CaseDtoHelper(de.symeda.sormas.app.backend.caze.CaseDtoHelper) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) ArrayList(java.util.ArrayList) IntrospectionException(com.googlecode.openbeans.IntrospectionException) CaseDao(de.symeda.sormas.app.backend.caze.CaseDao) InvocationTargetException(java.lang.reflect.InvocationTargetException) Case(de.symeda.sormas.app.backend.caze.Case) LbdsSyncDao(de.symeda.sormas.app.backend.lbds.LbdsSyncDao)

Example 2 with LbdsSyncDao

use of de.symeda.sormas.app.backend.lbds.LbdsSyncDao in project SORMAS-Project by hzi-braunschweig.

the class LbdsIntentSender method sendNewCasesLbds.

public static void sendNewCasesLbds(Context context) {
    Log.i("SORMAS_LBDS", "==========================");
    Log.i("SORMAS_LBDS", "Sync Cases LBDS");
    List<CaseDataDto> casesToSend = getNewCasesToSendLbds();
    LbdsSyncDao lbdsSyncDao = DatabaseHelper.getLbdsSyncDao();
    if (!casesToSend.isEmpty()) {
        List<String> caseUuids = casesToSend.stream().map(CaseDataDto::getUuid).collect(Collectors.toList());
        Log.i("SORMAS_LBDS", "Send cases: " + StringUtils.join(caseUuids, ", "));
        HttpMethod method = createLbdsHttpMethodCases(casesToSend);
        sendLbdsRequest(context, method);
        for (String caseUuid : caseUuids) {
            lbdsSyncDao.logLbdsSend(caseUuid);
        }
        NotificationHelper.showNotification((NotificationContext) context, NotificationType.SUCCESS, String.format(context.getResources().getString(R.string.lbds_cases_transferred), casesToSend.size()));
    } else {
        Log.i("SORMAS_LBDS", "Nothing to send.");
        NotificationHelper.showNotification((NotificationContext) context, NotificationType.INFO, context.getResources().getString(R.string.info_lbds_no_case_to_transfer));
    }
    Log.i("SORMAS_LBDS", "==========================");
}
Also used : LbdsSyncDao(de.symeda.sormas.app.backend.lbds.LbdsSyncDao) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) HttpMethod(org.hzi.sormas.lbds.core.http.HttpMethod)

Example 3 with LbdsSyncDao

use of de.symeda.sormas.app.backend.lbds.LbdsSyncDao in project SORMAS-Project by hzi-braunschweig.

the class LbdsIntentSender method sendNewCasePersonsLbds.

public static void sendNewCasePersonsLbds(Context context) {
    Log.i("SORMAS_LBDS", "==========================");
    Log.i("SORMAS_LBDS", "Sync Persons LBDS");
    LbdsSyncDao lbdsSyncDao = DatabaseHelper.getLbdsSyncDao();
    List<PersonDto> personsToSend = getNewPersonsToSendLbds();
    if (!personsToSend.isEmpty()) {
        List<String> personUuids = personsToSend.stream().map(PersonDto::getUuid).collect(Collectors.toList());
        Log.i("SORMAS_LBDS", "Send persons: " + StringUtils.join(personUuids, ", "));
        HttpMethod method = createLbdsHttpMethodPersons(personsToSend);
        sendLbdsRequest(context, method);
        for (String personUuid : personUuids) {
            lbdsSyncDao.logLbdsSend(personUuid);
        }
        NotificationHelper.showNotification((NotificationContext) context, NotificationType.SUCCESS, String.format(context.getResources().getString(R.string.lbds_persons_transferred), personsToSend.size()));
    } else {
        Log.i("SORMAS_LBDS", "Nothing to send.");
        NotificationHelper.showNotification((NotificationContext) context, NotificationType.INFO, context.getResources().getString(R.string.info_lbds_no_person_to_transfer));
    }
    Log.i("SORMAS_LBDS", "==========================");
}
Also used : LbdsSyncDao(de.symeda.sormas.app.backend.lbds.LbdsSyncDao) PersonDto(de.symeda.sormas.api.person.PersonDto) HttpMethod(org.hzi.sormas.lbds.core.http.HttpMethod)

Example 4 with LbdsSyncDao

use of de.symeda.sormas.app.backend.lbds.LbdsSyncDao in project SORMAS-Project by hzi-braunschweig.

the class LbdsIntentSender method getNewPersonsToSendLbds.

public static List<PersonDto> getNewPersonsToSendLbds() {
    List<CaseDataDto> casesToSend = getNewCasesToSendLbds();
    PersonDao personDao = DatabaseHelper.getPersonDao();
    LbdsSyncDao lbdsSyncDao = DatabaseHelper.getLbdsSyncDao();
    PersonDtoHelper personDtoHelper = new PersonDtoHelper();
    List<PersonDto> personsToSend = new ArrayList<>();
    for (CaseDataDto caze : casesToSend) {
        Person person = personDao.queryUuid(caze.getPerson().getUuid());
        if ((!person.isNew()) || lbdsSyncDao.hasBeenSuccessfullySent(person)) {
            continue;
        }
        PersonDto personDto = personDtoHelper.adoToDto(person);
        try {
            LbdsDtoHelper.stripLbdsDto(personDto);
        } catch (IllegalAccessException | IntrospectionException | InvocationTargetException e) {
            throw new IllegalArgumentException("LBDS preparation failed for person " + person.getUuid(), e);
        }
        personsToSend.add(personDto);
    }
    return personsToSend;
}
Also used : PersonDtoHelper(de.symeda.sormas.app.backend.person.PersonDtoHelper) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) ArrayList(java.util.ArrayList) IntrospectionException(com.googlecode.openbeans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersonDao(de.symeda.sormas.app.backend.person.PersonDao) LbdsSyncDao(de.symeda.sormas.app.backend.lbds.LbdsSyncDao) Person(de.symeda.sormas.app.backend.person.Person)

Example 5 with LbdsSyncDao

use of de.symeda.sormas.app.backend.lbds.LbdsSyncDao in project SORMAS-Project by hzi-braunschweig.

the class LbdsRecevierComponent method processLbdsResponsePersons.

private void processLbdsResponsePersons(Context context, HttpContainer httpContainerResponse) {
    HttpMethod methodFromResponse = httpContainerResponse.getMethod();
    HttpResult resultFromResponse = httpContainerResponse.getResult();
    Log.i("SORMAS_LBDS", "Request: " + methodFromResponse);
    Log.i("SORMAS_LBDS", "Result Headers: " + resultFromResponse.headers);
    Log.i("SORMAS_LBDS", "Result Body: " + resultFromResponse.body);
    Gson gson = RetroProvider.initGson();
    List<PersonDto> sentPersonDtos = gson.fromJson(methodFromResponse.payload, new TypeToken<List<PersonDto>>() {
    }.getType());
    List<PushResult> responsePushResults = gson.fromJson(resultFromResponse.body, new TypeToken<List<PushResult>>() {
    }.getType());
    Log.i("SORMAS_LBDS", "sent " + sentPersonDtos.size() + " PersonDtos and received " + responsePushResults.size() + " PushResults");
    if (sentPersonDtos.size() != responsePushResults.size()) {
        Log.i("SORMAS_LBDS", "List lengths differ, abort.");
        throw new IllegalArgumentException("Number of sent Dtos and received PushResults must be equal");
    }
    LbdsSyncDao lbdsSyncDao = DatabaseHelper.getLbdsSyncDao();
    int successful = 0;
    int ignored = 0;
    for (int i = 0; i < sentPersonDtos.size(); i++) {
        PersonDto personDto = sentPersonDtos.get(i);
        String uuid = personDto.getUuid();
        PushResult pushResult = responsePushResults.get(i);
        if (pushResult == PushResult.OK) {
            Log.i("SORMAS_LBDS", "Process PushResult " + pushResult + " for PersonDto " + uuid);
            lbdsSyncDao.logLbdsReceive(uuid);
            successful++;
        } else {
            Log.i("SORMAS_LBDS", "Ignore PushResult " + pushResult + " for PersonDto " + uuid);
            ignored++;
        }
    }
    Toast.makeText(context, String.format(context.getResources().getString(R.string.lbds_response_persons), successful, ignored), Toast.LENGTH_LONG).show();
}
Also used : LbdsSyncDao(de.symeda.sormas.app.backend.lbds.LbdsSyncDao) PersonDto(de.symeda.sormas.api.person.PersonDto) TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) HttpResult(org.hzi.sormas.lbds.core.http.HttpResult) PushResult(de.symeda.sormas.api.PushResult) HttpMethod(org.hzi.sormas.lbds.core.http.HttpMethod)

Aggregations

LbdsSyncDao (de.symeda.sormas.app.backend.lbds.LbdsSyncDao)6 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)4 HttpMethod (org.hzi.sormas.lbds.core.http.HttpMethod)4 PersonDto (de.symeda.sormas.api.person.PersonDto)3 Gson (com.google.gson.Gson)2 TypeToken (com.google.gson.reflect.TypeToken)2 IntrospectionException (com.googlecode.openbeans.IntrospectionException)2 PushResult (de.symeda.sormas.api.PushResult)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 HttpResult (org.hzi.sormas.lbds.core.http.HttpResult)2 FacilityReferenceDto (de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto)1 Case (de.symeda.sormas.app.backend.caze.Case)1 CaseDao (de.symeda.sormas.app.backend.caze.CaseDao)1 CaseDtoHelper (de.symeda.sormas.app.backend.caze.CaseDtoHelper)1 Person (de.symeda.sormas.app.backend.person.Person)1 PersonDao (de.symeda.sormas.app.backend.person.PersonDao)1 PersonDtoHelper (de.symeda.sormas.app.backend.person.PersonDtoHelper)1