package org.hisp.dhis.android.core.common;

import org.hisp.dhis.android.core.D2;
import org.hisp.dhis.android.core.data.database.DatabaseAdapter;
import org.hisp.dhis.android.core.event.EventCall;
import org.hisp.dhis.android.core.event.EventHandler;
import org.hisp.dhis.android.core.event.EventQuery;
import org.hisp.dhis.android.core.event.EventService;
import org.hisp.dhis.android.core.event.EventStore;
import org.hisp.dhis.android.core.event.EventStoreImpl;
import org.hisp.dhis.android.core.resource.ResourceHandler;
import org.hisp.dhis.android.core.resource.ResourceStore;
import org.hisp.dhis.android.core.resource.ResourceStoreImpl;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueHandler;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStore;
import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStoreImpl;

import java.util.Date;

import retrofit2.Retrofit;

public class EventCallFactory {
    public static EventCall create(Retrofit retrofit,
            DatabaseAdapter databaseAdapter, String orgUnit, int pageLimit) {

        EventService eventService = retrofit.create(EventService.class);

        EventStore eventStore = new EventStoreImpl(databaseAdapter);

        TrackedEntityDataValueStore trackedEntityDataValueStore =
                new TrackedEntityDataValueStoreImpl(databaseAdapter);

        TrackedEntityDataValueHandler trackedEntityDataValueHandler =
                new TrackedEntityDataValueHandler(trackedEntityDataValueStore);

        EventHandler eventHandler = new EventHandler(eventStore, trackedEntityDataValueHandler);

        ResourceStore resourceStore = new ResourceStoreImpl(databaseAdapter);
        ResourceHandler resourceHandler = new ResourceHandler(resourceStore);

        EventQuery eventQuery = EventQuery.Builder
                .create()
                .withOrgUnit(orgUnit)
                .withPageLimit(pageLimit)
                .build();

        EventCall eventCall = new EventCall(eventService, databaseAdapter, resourceHandler,
                eventHandler, new Date(), eventQuery);

        return eventCall;
    }
}

@@ -41,46 +41,8 @@
 n;%0A%0A
-import org.hisp.dhis.android.core.D2;%0A
 impo
@@ -351,1400 +351,509 @@
 ore.
-event.EventStore;%0Aimport org.hisp.dhis.android.core.event.EventStoreImpl;%0Aimport org.hisp.dhis.android.core.resource.ResourceHandler;%0Aimport org.hisp.dhis.android.core.resource.ResourceStore;%0Aimport org.hisp.dhis.android.core.resource.ResourceStoreImpl;%0Aimport org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueHandler;%0Aimport org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStore;%0Aimport org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStoreImpl;%0A%0Aimport java.util.Date;%0A%0Aimport retrofit2.Retrofit;%0A%0Apublic class EventCallFactory %7B%0A    public static EventCall create(Retrofit retrofit,%0A            DatabaseAdapter databaseAdapter, String orgUnit, int pageLimit) %7B%0A%0A        EventService eventService = retrofit.create(EventService.class);%0A%0A        EventStore eventStore = new EventStoreImpl(databaseAdapter);%0A%0A        TrackedEntityDataValueStore trackedEntityDataValueStore =%0A                new TrackedEntityDataValueStoreImpl(databaseAdapter);%0A%0A        TrackedEntityDataValueHandler trackedEntityDataValueHandler =%0A                new TrackedEntityDataValueHandler(trackedEntityDataValueStore);%0A%0A        EventHandler eventHandler = new EventHandler(eventStore, trackedEntityDataValueHandler);%0A%0A        ResourceStore resourceStore = new ResourceStoreImpl(databaseAdapter);%0A        ResourceHandler resourceHandler = new ResourceHandler(resourceStore
+resource.ResourceHandler;%0A%0Aimport java.util.Date;%0A%0Aimport retrofit2.Retrofit;%0A%0Apublic class EventCallFactory %7B%0A    public static EventCall create(Retrofit retrofit,%0A            DatabaseAdapter databaseAdapter, String orgUnit, int pageLimit) %7B%0A%0A        EventService eventService = retrofit.create(EventService.class);%0A%0A        EventHandler eventHandler = HandlerFactory.createEventHandler(databaseAdapter);%0A%0A        ResourceHandler resourceHandler = HandlerFactory.createResourceHandler(databaseAdapter
 );%0A%0A

use HandlerFactory from EventCallFactory to avoid duplicate code