use of de.symeda.sormas.app.rest.ServerCommunicationException in project SORMAS-Project by hzi-braunschweig.
the class AdoDtoHelper method pullMissing.
public void pullMissing(List<String> uuids) throws ServerCommunicationException, ServerConnectionException, DaoException, NoConnectionException {
final AbstractAdoDao<ADO> dao = DatabaseHelper.getAdoDao(getAdoClass());
uuids = dao.filterMissing(uuids);
if (!uuids.isEmpty()) {
Response<List<DTO>> response;
try {
response = pullByUuids(uuids).execute();
} catch (IOException e) {
throw new ServerCommunicationException(e);
}
handlePullResponse(false, dao, response);
}
}
use of de.symeda.sormas.app.rest.ServerCommunicationException in project SORMAS-Project by hzi-braunschweig.
the class AdoDtoHelper method repullEntities.
public void repullEntities(Context context) throws DaoException, ServerCommunicationException, ServerConnectionException, NoConnectionException {
try {
final AbstractAdoDao<ADO> dao = DatabaseHelper.getAdoDao(getAdoClass());
long approximateJsonSizeInBytes = getApproximateJsonSizeInBytes();
final int batchSize = approximateJsonSizeInBytes != 0 ? RetroProvider.getNumberOfEntitiesToBePulledInOneBatch(approximateJsonSizeInBytes, context) : Integer.MAX_VALUE;
int lastBatchSize = batchSize;
while (lastBatchSize == batchSize) {
Call<List<DTO>> dtoCall = pullAllSince(lastSyncedEntityDate != null ? lastSyncedEntityDate.getTime() : 0, batchSize, lastSyncedEntityDate != null && lastSyncedEntityUuid != null ? lastSyncedEntityUuid : EntityDto.NO_LAST_SYNCED_UUID);
if (dtoCall == null) {
return;
}
Response<List<DTO>> response;
try {
response = dtoCall.execute();
} catch (IOException e) {
throw new ServerCommunicationException(e);
}
lastBatchSize = handlePullResponse(false, dao, response);
}
} catch (RuntimeException e) {
Log.e(getClass().getName(), "Exception thrown when trying to pull entities");
throw new DaoException(e);
}
}
use of de.symeda.sormas.app.rest.ServerCommunicationException in project SORMAS-Project by hzi-braunschweig.
the class AdoDtoHelper method pullEntities.
public void pullEntities(final boolean markAsRead, Context context) throws DaoException, ServerCommunicationException, ServerConnectionException, NoConnectionException {
try {
final AbstractAdoDao<ADO> dao = DatabaseHelper.getAdoDao(getAdoClass());
Date maxModifiedDate = dao.getLatestChangeDate();
long approximateJsonSizeInBytes = getApproximateJsonSizeInBytes();
final int batchSize = approximateJsonSizeInBytes != 0 ? RetroProvider.getNumberOfEntitiesToBePulledInOneBatch(approximateJsonSizeInBytes, context) : Integer.MAX_VALUE;
int lastBatchSize = batchSize;
lastSyncedEntityDate = maxModifiedDate;
while (lastBatchSize == batchSize) {
Call<List<DTO>> dtoCall = pullAllSince(lastSyncedEntityDate.getTime(), batchSize, lastSyncedEntityDate != null && lastSyncedEntityUuid != null ? lastSyncedEntityUuid : EntityDto.NO_LAST_SYNCED_UUID);
if (dtoCall == null) {
return;
}
Response<List<DTO>> response;
try {
response = dtoCall.execute();
} catch (IOException e) {
throw new ServerCommunicationException(e);
}
lastBatchSize = handlePullResponse(markAsRead, dao, response);
}
} catch (RuntimeException e) {
Log.e(getClass().getName(), "Exception thrown when trying to pull entities");
throw new DaoException(e);
}
}
use of de.symeda.sormas.app.rest.ServerCommunicationException in project SORMAS-Project by hzi-braunschweig.
the class FacilityDtoHelper method pullEntities.
/**
* Pulls the data chunkwise per region
*
* @param markAsRead
* @param context
* @throws DaoException
* @throws SQLException
* @throws IOException
*/
@Override
public void pullEntities(final boolean markAsRead, Context context) throws DaoException, ServerCommunicationException, ServerConnectionException, NoConnectionException {
try {
final FacilityDao facilityDao = DatabaseHelper.getFacilityDao();
List<Region> regions = DatabaseHelper.getRegionDao().queryForAll();
for (Region region : regions) {
Date maxModifiedDate = facilityDao.getLatestChangeDateByRegion(region);
long maxModifiedTime = maxModifiedDate != null ? maxModifiedDate.getTime() : 0;
databaseWasEmpty = maxModifiedDate == null;
Call<List<FacilityDto>> dtoCall = pullAllByRegionSince(region, maxModifiedTime);
if (dtoCall == null) {
return;
}
handlePullResponse(markAsRead, facilityDao, dtoCall.execute());
}
{
// Pull 'Other' health facility which has no region set
Date maxModifiedDate = facilityDao.getLatestChangeDateByRegion(null);
long maxModifiedTime = maxModifiedDate != null ? maxModifiedDate.getTime() : 0;
databaseWasEmpty = maxModifiedDate == null;
Call<List<FacilityDto>> dtoCall = pullAllWithoutRegionSince(maxModifiedTime);
if (dtoCall == null) {
return;
}
handlePullResponse(markAsRead, facilityDao, dtoCall.execute());
}
} catch (IOException e) {
throw new ServerCommunicationException(e);
} finally {
databaseWasEmpty = false;
}
}
use of de.symeda.sormas.app.rest.ServerCommunicationException in project SORMAS-Project by hzi-braunschweig.
the class AdoDtoHelper method pushEntities.
/**
* @return true: another pull is needed, because data has been changed on the server
*/
public boolean pushEntities(boolean onlyNewEntities) throws DaoException, ServerConnectionException, ServerCommunicationException, NoConnectionException {
final AbstractAdoDao<ADO> dao = DatabaseHelper.getAdoDao(getAdoClass());
final List<ADO> modifiedAdos = onlyNewEntities ? dao.queryForNew() : dao.queryForModified();
List<DTO> modifiedDtos = new ArrayList<>(modifiedAdos.size());
for (ADO ado : modifiedAdos) {
DTO dto = adoToDto(ado);
modifiedDtos.add(dto);
}
if (modifiedDtos.isEmpty()) {
return false;
}
Call<List<PushResult>> call = pushAll(modifiedDtos);
Response<List<PushResult>> response;
try {
response = call.execute();
} catch (IOException e) {
throw new ServerCommunicationException(e);
}
if (!response.isSuccessful()) {
RetroProvider.throwException(response);
}
final List<PushResult> pushResults = response.body();
if (pushResults.size() != modifiedDtos.size()) {
throw new ServerCommunicationException("Server responded with wrong count of received entities: " + pushResults.size() + " - expected: " + modifiedDtos.size());
}
pushedTooOldCount = 0;
pushedErrorCount = 0;
dao.callBatchTasks(new Callable<Void>() {
public Void call() throws Exception {
for (int i = 0; i < modifiedAdos.size(); i++) {
ADO ado = modifiedAdos.get(i);
PushResult pushResult = pushResults.get(i);
switch(pushResult) {
case OK:
// data has been pushed, we no longer need the old unmodified version
dao.accept(ado);
break;
case TOO_OLD:
pushedTooOldCount++;
break;
case ERROR:
pushedErrorCount++;
break;
default:
throw new IllegalArgumentException(pushResult.toString());
}
}
return null;
}
});
if (modifiedAdos.size() > 0) {
Log.d(dao.getTableName(), "Pushed: " + modifiedAdos.size() + " Too old: " + pushedTooOldCount + " Erros: " + pushedErrorCount);
}
return true;
}
Aggregations