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;
}
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", "==========================");
}
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", "==========================");
}
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;
}
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();
}
Aggregations