use of org.hisp.dhis.android.core.resource.ResourceHandler in project dhis2-android-sdk by dhis2.
the class CategoryEndpointCallShould method provideCategoryEndpointCall.
private CategoryEndpointCall provideCategoryEndpointCall() {
CategoryQuery query = CategoryQuery.builder().paging(true).pageSize(CategoryQuery.DEFAULT_PAGE_SIZE).page(1).build();
ResponseValidator<Category> validator = new ResponseValidator<>();
CategoryStore store = new CategoryStoreImpl(databaseAdapter());
CategoryOptionStore categoryOptionStore = new CategoryOptionStoreImpl(databaseAdapter());
CategoryOptionHandler categoryOptionHandler = new CategoryOptionHandler(categoryOptionStore);
CategoryCategoryOptionLinkStore categoryCategoryOptionLinkStore = new CategoryCategoryOptionLinkStoreImpl(databaseAdapter());
CategoryHandler handler = new CategoryHandler(store, categoryOptionHandler, categoryCategoryOptionLinkStore);
ResourceStore resourceStore = new ResourceStoreImpl(databaseAdapter());
ResourceHandler resourceHandler = new ResourceHandler(resourceStore);
Date serverDate = new Date();
return new CategoryEndpointCall(query, categoryService, validator, handler, resourceHandler, databaseAdapter(), serverDate);
}
use of org.hisp.dhis.android.core.resource.ResourceHandler in project dhis2-android-sdk by dhis2.
the class TrackedEntityInstanceCallFactory method create.
public static TrackedEntityInstanceEndPointCall create(Retrofit retrofit, DatabaseAdapter databaseAdapter, String trackedEntityInstanceUid) {
TrackedEntityInstanceService trackedEntityInstanceService = retrofit.create(TrackedEntityInstanceService.class);
TrackedEntityInstanceHandler trackedEntityInstanceHandler = HandlerFactory.createTrackedEntityInstanceHandler(databaseAdapter);
ResourceHandler resourceHandler = HandlerFactory.createResourceHandler(databaseAdapter);
TrackedEntityInstanceEndPointCall trackedEntityInstanceEndPointCall = new TrackedEntityInstanceEndPointCall(trackedEntityInstanceService, databaseAdapter, trackedEntityInstanceHandler, resourceHandler, new Date(), trackedEntityInstanceUid);
return trackedEntityInstanceEndPointCall;
}
use of org.hisp.dhis.android.core.resource.ResourceHandler 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();
}
}
use of org.hisp.dhis.android.core.resource.ResourceHandler in project dhis2-android-sdk by dhis2.
the class SystemInfoCall method insertOrUpdateSystemInfo.
private void insertOrUpdateSystemInfo(Response<SystemInfo> response) {
SystemInfoHandler systemInfoHandler = new SystemInfoHandler(systemInfoStore);
ResourceHandler resourceHandler = new ResourceHandler(resourceStore);
Transaction transaction = databaseAdapter.beginNewTransaction();
try {
if (response.body() != null) {
SystemInfo systemInfo = response.body();
systemInfoHandler.handleSystemInfo(systemInfo);
resourceHandler.handleResource(ResourceModel.Type.SYSTEM_INFO, systemInfo.serverDate());
}
transaction.setSuccessful();
} finally {
transaction.end();
}
}
use of org.hisp.dhis.android.core.resource.ResourceHandler in project dhis2-android-sdk by dhis2.
the class UserCall method call.
@Override
public Response<User> call() throws Exception {
synchronized (this) {
if (isExecuted) {
throw new IllegalStateException("Already executed");
}
isExecuted = true;
}
Response<User> response = getUser();
if (response.isSuccessful()) {
UserHandler userHandler = new UserHandler(userStore);
UserCredentialsHandler userCredentialsHandler = new UserCredentialsHandler(userCredentialsStore);
UserRoleHandler userRoleHandler = new UserRoleHandler(userRoleStore);
ResourceHandler resourceHandler = new ResourceHandler(resourceStore);
Transaction transaction = databaseAdapter.beginNewTransaction();
try {
User user = response.body();
// TODO: check that this is user is authenticated and is persisted in db
userHandler.handleUser(user);
UserCredentials userCredentials = user.userCredentials();
userCredentialsHandler.handleUserCredentials(userCredentials, user);
List<UserRole> userRoles = userCredentials.userRoles();
userRoleHandler.handleUserRoles(userRoles);
resourceHandler.handleResource(ResourceModel.Type.USER, serverDate);
transaction.setSuccessful();
} catch (SQLiteConstraintException constraintException) {
// constraintException.printStackTrace();
Log.d("CAll", "call: constraintException");
} finally {
transaction.end();
}
}
return response;
}
Aggregations