Skip to content

Commit

Permalink
Merge pull request #221 from odk-x/development
Browse files Browse the repository at this point in the history
prepare for 2.1.9 release
  • Loading branch information
wbrunette authored Dec 15, 2021
2 parents f51328b + b7c6ca5 commit 8575c07
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.opendatakit.consts.IntentConsts;
import org.opendatakit.fragment.AboutMenuFragment;
import org.opendatakit.logging.WebLogger;
import org.opendatakit.logging.desktop.WebLoggerDesktopFactoryImpl;
import org.opendatakit.properties.CommonToolProperties;
import org.opendatakit.properties.PropertiesSingleton;
import org.opendatakit.services.R;
Expand Down Expand Up @@ -317,7 +318,9 @@ public static void showAuthenticationErrorDialog(final Activity activity, String
builder.setMessage(message);
builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
activity.finish();
if (activity instanceof VerifyServerSettingsActivity){
activity.finish();
}
dialog.dismiss();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,6 @@ public List<TableResource> synchronizeConfigurationAndContent(boolean pushToServ
return new ArrayList<>();
}

// set device properties to cause all ODK tools to re-run their initialization tasks.
sc.setAllToolsToReInitialize();

// Everything was successful-enough to warrant deleting any sync
// ETags from syncing to a different server. This ensures that we
// only ever have the sync etags from the current server in case
// the user is switching servers for some reason.
manifestProcessor.deleteAllSyncETagsExceptForCurrentServer();

sc.updateNotification(SyncProgressState.STARTING,
R.string.sync_retrieving_tables_list_from_server, null, 0.0, false);

Expand Down Expand Up @@ -326,6 +317,32 @@ public List<TableResource> synchronizeConfigurationAndContent(boolean pushToServ
return new ArrayList<TableResource>();
}

// Fail if local table schemaETags don't match those on the server
if (!pushToServer) {
boolean matched = doDeviceTableSchemaETagsMatchServerETags(tables, localTableIds, db);
if (!matched) {
return new ArrayList<TableResource>();
}
}

// Only initialize if app level file manifest or table level file manifest is different from
// server
boolean initializeTools = true;
if (!pushToServer) {
initializeTools = shouldInitializeAllTools(tableList, tables);
}

if (initializeTools) {
// set device properties to cause all ODK tools to re-run their initialization tasks.
sc.setAllToolsToReInitialize();

// Everything was successful-enough to warrant deleting any sync
// ETags from syncing to a different server. This ensures that we
// only ever have the sync etags from the current server in case
// the user is switching servers for some reason.
manifestProcessor.deleteAllSyncETagsExceptForCurrentServer();
}

// Figure out how many major steps there are to the sync
{
Set<String> uniqueTableIds = new HashSet<String>();
Expand Down Expand Up @@ -614,6 +631,63 @@ public List<TableResource> synchronizeConfigurationAndContent(boolean pushToServ
return workingListOfTables;
}

private boolean doDeviceTableSchemaETagsMatchServerETags(List<TableResource> tables,
List<String> localTableIds, DbHandle db)
throws ServicesAvailabilityException {
try {
db = sc.getDatabase();
for (TableResource table : tables) {
if (localTableIds.contains(table.getTableId())) {
TableDefinitionEntry entry = sc.getDatabaseService().getTableDefinitionEntry(
sc.getAppName(), db, table.getTableId());
if (!table.getSchemaETag().equals(entry.getSchemaETag())) {
sc.setAppLevelSyncOutcome(SyncOutcome.TABLE_SCHEMA_COLUMN_DEFINITION_MISMATCH);
log.e(TAG,
"[synchronizeConfigurationAndContent] schemaETag on server does not match " +
"local table");
return false;
}
}
}
} catch (Exception e) {
sc.setAppLevelSyncOutcome(sc.exceptionEquivalentOutcome(e));
log.e(TAG,
"[synchronizeConfigurationAndContent] exception getting local table definition" +
" entry: " + e.toString());
return false;
} finally {
if (db != null) {
sc.releaseDatabase(db);
}
}
return true;
}

private boolean shouldInitializeAllTools(TableResourceList tableList, List<TableResource> tables)
throws ServicesAvailabilityException {
String appLevelManifest = null;
if (tableList != null && tableList.getAppLevelManifestETag() != null) {
appLevelManifest = tableList.getAppLevelManifestETag();
}

if (appLevelManifest == null) {
return true;
} else if (!appLevelManifest.equals(manifestProcessor.getManifestSyncETag(null))) {
return true;
}

for (TableResource table : tables) {
String tableLevelManifest = table.getTableLevelManifestETag();
if (tableLevelManifest == null) {
return true;
} else if (!tableLevelManifest.equals(
manifestProcessor.getManifestSyncETag(table.getTableId()))) {
return true;
}
}
return false;
}

/**
* Synchronize the table represented by the given TableProperties with the
* cloud.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ private void updateFileSyncETag(URI fileDownloadUri, String tableId, long lastMo
* @return
* @throws ServicesAvailabilityException
*/
private String getManifestSyncETag(String tableId) throws ServicesAvailabilityException {
public String getManifestSyncETag(String tableId) throws ServicesAvailabilityException {

URI fileManifestUri;

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gradle.ext.gradleConfigVersion = 153
gradle.ext.gradleConfigVersion = 154

if (!gradle.ext.has('workspacePath')) {
logger.warn("rootDir: " + rootDir.getAbsolutePath());
Expand Down

0 comments on commit 8575c07

Please sign in to comment.