-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop'
- Loading branch information
Showing
52 changed files
with
1,351 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,12 @@ | |
|
||
package org.hisp.dhis.android.dashboard.api.controllers; | ||
|
||
import static org.hisp.dhis.android.dashboard.api.models.BaseIdentifiableObject.merge; | ||
import static org.hisp.dhis.android.dashboard.api.models.BaseIdentifiableObject.toMap; | ||
import static org.hisp.dhis.android.dashboard.api.utils.NetworkUtils.findLocationHeader; | ||
import static org.hisp.dhis.android.dashboard.api.utils.NetworkUtils.handleApiException; | ||
import static org.hisp.dhis.android.dashboard.api.utils.NetworkUtils.unwrapResponse; | ||
|
||
import android.net.Uri; | ||
|
||
import com.raizlabs.android.dbflow.sql.builder.Condition; | ||
|
@@ -49,6 +55,7 @@ | |
import org.hisp.dhis.android.dashboard.api.persistence.preferences.DateTimeManager; | ||
import org.hisp.dhis.android.dashboard.api.persistence.preferences.ResourceType; | ||
import org.hisp.dhis.android.dashboard.api.utils.DbUtils; | ||
import org.hisp.dhis.android.dashboard.api.utils.SyncStrategy; | ||
import org.joda.time.DateTime; | ||
|
||
import java.util.ArrayList; | ||
|
@@ -62,12 +69,6 @@ | |
import retrofit.client.Response; | ||
import retrofit.mime.TypedString; | ||
|
||
import static org.hisp.dhis.android.dashboard.api.models.BaseIdentifiableObject.merge; | ||
import static org.hisp.dhis.android.dashboard.api.models.BaseIdentifiableObject.toMap; | ||
import static org.hisp.dhis.android.dashboard.api.utils.NetworkUtils.findLocationHeader; | ||
import static org.hisp.dhis.android.dashboard.api.utils.NetworkUtils.handleApiException; | ||
import static org.hisp.dhis.android.dashboard.api.utils.NetworkUtils.unwrapResponse; | ||
|
||
/** | ||
* @author Araz Abishov <[email protected]>. | ||
*/ | ||
|
@@ -78,8 +79,8 @@ public InterpretationController(DhisApi dhisApi) { | |
mDhisApi = dhisApi; | ||
} | ||
|
||
public void syncInterpretations() throws APIException { | ||
getInterpretationDataFromServer(); | ||
public void syncInterpretations(SyncStrategy syncStrategy) throws APIException { | ||
getInterpretationDataFromServer(syncStrategy); | ||
sendLocalChanges(); | ||
} | ||
|
||
|
@@ -355,12 +356,17 @@ private void updateInterpretationCommentTimeStamp(InterpretationComment comment) | |
} | ||
} | ||
|
||
private void getInterpretationDataFromServer() throws APIException { | ||
private void getInterpretationDataFromServer(SyncStrategy syncStrategy) throws APIException { | ||
DateTime lastUpdated = DateTimeManager.getInstance() | ||
.getLastUpdated(ResourceType.INTERPRETATIONS); | ||
DateTime serverTime = mDhisApi.getSystemInfo().getServerDate(); | ||
|
||
List<Interpretation> interpretations = updateInterpretations(lastUpdated); | ||
List<Interpretation> interpretations; | ||
if (syncStrategy == SyncStrategy.DOWNLOAD_ONLY_NEW) { | ||
interpretations = updateInterpretations(lastUpdated); | ||
} else { | ||
interpretations = updateInterpretations(null); | ||
} | ||
List<InterpretationComment> comments = updateInterpretationComments(interpretations); | ||
List<User> users = updateInterpretationUsers(interpretations, comments); | ||
|
||
|
120 changes: 120 additions & 0 deletions
120
api/src/main/java/org/hisp/dhis/android/dashboard/api/controllers/MapController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package org.hisp.dhis.android.dashboard.api.controllers; | ||
|
||
import static org.hisp.dhis.android.dashboard.api.models.BaseIdentifiableObject.merge; | ||
import static org.hisp.dhis.android.dashboard.api.models.BaseIdentifiableObject.toMap; | ||
import static org.hisp.dhis.android.dashboard.api.utils.NetworkUtils.unwrapResponse; | ||
|
||
import android.content.Context; | ||
import android.net.Uri; | ||
import android.widget.ImageView; | ||
|
||
import com.raizlabs.android.dbflow.sql.language.Select; | ||
import com.squareup.okhttp.HttpUrl; | ||
import com.squareup.picasso.NetworkPolicy; | ||
import com.squareup.picasso.Picasso; | ||
|
||
import org.hisp.dhis.android.dashboard.api.models.Dashboard; | ||
import org.hisp.dhis.android.dashboard.api.models.DashboardElement; | ||
import org.hisp.dhis.android.dashboard.api.models.DashboardItem; | ||
import org.hisp.dhis.android.dashboard.api.models.DataMap; | ||
import org.hisp.dhis.android.dashboard.api.models.meta.DbOperation; | ||
import org.hisp.dhis.android.dashboard.api.network.APIException; | ||
import org.hisp.dhis.android.dashboard.api.network.BaseMapLayerDhisTransformation; | ||
import org.hisp.dhis.android.dashboard.api.network.DhisApi; | ||
import org.hisp.dhis.android.dashboard.api.persistence.preferences.DateTimeManager; | ||
import org.hisp.dhis.android.dashboard.api.persistence.preferences.ResourceType; | ||
import org.hisp.dhis.android.dashboard.api.utils.DbUtils; | ||
import org.hisp.dhis.android.dashboard.api.utils.PicassoProvider; | ||
import org.joda.time.DateTime; | ||
|
||
import java.util.HashMap; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Queue; | ||
|
||
public class MapController { | ||
private DhisApi mDhisApi; | ||
|
||
private static List<DataMap> mDataMaps; | ||
|
||
public MapController(DhisApi dhisApi) { | ||
mDhisApi = dhisApi; | ||
} | ||
|
||
public static List<DataMap> queryDataMaps() { | ||
return new Select().from(DataMap.class) | ||
.queryList(); | ||
} | ||
|
||
public static DataMap getDataMap(String uid) { | ||
DataMap dataMapToReturn = null; | ||
|
||
if (mDataMaps == null) | ||
mDataMaps = queryDataMaps(); | ||
|
||
for (DataMap dataMap:mDataMaps) { | ||
if (dataMap.getUId().equals(uid)) | ||
dataMapToReturn = dataMap; | ||
} | ||
|
||
return dataMapToReturn; | ||
} | ||
|
||
public void syncDataMaps() throws APIException { | ||
getDataMapsFromServer(); | ||
} | ||
|
||
private void getDataMapsFromServer() throws APIException { | ||
DateTime lastUpdated = DateTimeManager.getInstance() | ||
.getLastUpdated(ResourceType.DASHBOARDS); | ||
DateTime serverDateTime = mDhisApi.getSystemInfo() | ||
.getServerDate(); | ||
|
||
List<DataMap> dataMaps = updateDataMaps(lastUpdated); | ||
|
||
Queue<DbOperation> operations = new LinkedList<>(); | ||
operations.addAll(DbUtils.createOperations(queryDataMaps(), dataMaps)); | ||
|
||
DbUtils.applyBatch(operations); | ||
DateTimeManager.getInstance() | ||
.setLastUpdated(ResourceType.DASHBOARDS, serverDateTime); | ||
} | ||
|
||
private List<DataMap> updateDataMaps(DateTime lastUpdated) throws APIException { | ||
final Map<String, String> QUERY_MAP_BASIC = new HashMap<>(); | ||
final Map<String, String> QUERY_MAP_FULL = new HashMap<>(); | ||
final String BASE = "id,created,lastUpdated,name,displayName,access"; | ||
|
||
QUERY_MAP_BASIC.put("fields", "id"); | ||
QUERY_MAP_FULL.put("fields", BASE + "basemap,latitude,longitude,zoom"); | ||
|
||
/* if (lastUpdated != null) { | ||
QUERY_MAP_FULL.put("filter", | ||
"lastUpdated:gt:" + lastUpdated.toLocalDateTime().toString()); | ||
}*/ | ||
|
||
// List of dashboards with UUIDs (without content). This list is used | ||
// only to determine what was removed on server. | ||
List<DataMap> actualDataMaps = unwrapResponse(mDhisApi | ||
.getDataMaps(QUERY_MAP_BASIC), "maps"); | ||
|
||
// List of updated dashboards with content. | ||
List<DataMap> updatedDataMaps = unwrapResponse(mDhisApi | ||
.getDataMaps(QUERY_MAP_FULL), "maps"); | ||
|
||
// List of persisted dashboards. | ||
List<DataMap> persistedDataMaps = queryDataMaps(); | ||
|
||
return merge(actualDataMaps, updatedDataMaps, persistedDataMaps); | ||
} | ||
|
||
private String getMapUIDs(String request) { | ||
HttpUrl url = HttpUrl.parse(request); | ||
|
||
String uid = url.pathSegments().get(3); | ||
|
||
return uid; | ||
} | ||
|
||
} |
Oops, something went wrong.