From c576de6d4f0f32c6131e827ea34ffe1a887bb905 Mon Sep 17 00:00:00 2001 From: Guille Date: Fri, 11 Jan 2019 08:58:23 +0100 Subject: [PATCH 1/7] Remove web UI checkbox to disable faster background actions --- .../aggregate/client/PreferencesSubTab.java | 10 --- ...isableFasterBackgroundActionsCheckbox.java | 72 ------------------- 2 files changed, 82 deletions(-) delete mode 100644 src/main/java/org/opendatakit/aggregate/client/widgets/DisableFasterBackgroundActionsCheckbox.java diff --git a/src/main/java/org/opendatakit/aggregate/client/PreferencesSubTab.java b/src/main/java/org/opendatakit/aggregate/client/PreferencesSubTab.java index 638a023e41..c8cf6568f1 100644 --- a/src/main/java/org/opendatakit/aggregate/client/PreferencesSubTab.java +++ b/src/main/java/org/opendatakit/aggregate/client/PreferencesSubTab.java @@ -24,7 +24,6 @@ import org.opendatakit.aggregate.buildconfig.BuildConfig; import org.opendatakit.aggregate.client.preferences.Preferences; import org.opendatakit.aggregate.client.preferences.Preferences.PreferencesCompletionCallback; -import org.opendatakit.aggregate.client.widgets.DisableFasterBackgroundActionsCheckbox; import org.opendatakit.aggregate.client.widgets.ServletPopupButton; import org.opendatakit.aggregate.client.widgets.SkipMalformedSubmissionsCheckbox; import org.opendatakit.aggregate.constants.common.HelpSliderConsts; @@ -77,14 +76,12 @@ public class PreferencesSubTab extends AggregateSubTabBase { private Label enketoApiUrl; private Label enketoApiToken; - private DisableFasterBackgroundActionsCheckbox disableFasterBackgroundActions; private SkipMalformedSubmissionsCheckbox skipMalformedSubmissions; private PreferencesCompletionCallback settingsChange = new PreferencesCompletionCallback() { @Override public void refreshFromUpdatedPreferences() { setCredentialValues(); - disableFasterBackgroundActions.updateValue(Preferences.getFasterBackgroundActionsDisabled()); skipMalformedSubmissions.updateValue(Preferences.getSkipMalformedSubmissions()); } @@ -188,13 +185,6 @@ public PreferencesSubTab() { HTML features = new HTML(FEATURES_LABEL); add(features); - disableFasterBackgroundActions = new DisableFasterBackgroundActionsCheckbox( - Preferences.getFasterBackgroundActionsDisabled(), settingsChange); - add(disableFasterBackgroundActions); - - HTML linebreak = new HTML("
"); - add(linebreak); - skipMalformedSubmissions = new SkipMalformedSubmissionsCheckbox( Preferences.getSkipMalformedSubmissions(), settingsChange); add(skipMalformedSubmissions); diff --git a/src/main/java/org/opendatakit/aggregate/client/widgets/DisableFasterBackgroundActionsCheckbox.java b/src/main/java/org/opendatakit/aggregate/client/widgets/DisableFasterBackgroundActionsCheckbox.java deleted file mode 100644 index de1ebc5682..0000000000 --- a/src/main/java/org/opendatakit/aggregate/client/widgets/DisableFasterBackgroundActionsCheckbox.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2013 University of Washington - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package org.opendatakit.aggregate.client.widgets; - -import static org.opendatakit.aggregate.client.security.SecurityUtils.secureRequest; -import static org.opendatakit.common.security.common.GrantedAuthorityName.ROLE_SITE_ACCESS_ADMIN; - -import com.google.gwt.event.logical.shared.ValueChangeEvent; -import com.google.gwt.event.logical.shared.ValueChangeHandler; -import org.opendatakit.aggregate.client.AggregateUI; -import org.opendatakit.aggregate.client.SecureGWT; -import org.opendatakit.aggregate.client.preferences.Preferences; -import org.opendatakit.aggregate.client.preferences.Preferences.PreferencesCompletionCallback; - -public final class DisableFasterBackgroundActionsCheckbox extends AggregateCheckBox implements ValueChangeHandler { - - private static final String LABEL = "Disable faster background actions (exports, publishing, form deletion) (slows quota usage on Google AppEngine)"; - private static final String TOOLTIP_TXT = "Enable/Disable Faster Background Actions"; - private static final String HELP_BALLOON_TXT = "Check this box if you need to preserve Google AppEngine quota for submissions and website activities. Otherwise leave unchecked. If checked, exports, publishing and form deletion requests will take longer to complete."; - - private PreferencesCompletionCallback settingsChange; - - public DisableFasterBackgroundActionsCheckbox(Boolean enabled, PreferencesCompletionCallback settingsChange) { - super(LABEL, false, TOOLTIP_TXT, HELP_BALLOON_TXT); - this.settingsChange = settingsChange; - setValue(enabled); - boolean accessible = AggregateUI.getUI().getUserInfo().getGrantedAuthorities().contains(ROLE_SITE_ACCESS_ADMIN); - setEnabled(accessible); - } - - public void updateValue(Boolean value) { - Boolean currentValue = getValue(); - if (currentValue != value) - setValue(value); - } - - @Override - public void onValueChange(ValueChangeEvent event) { - super.onValueChange(event); - secureRequest( - SecureGWT.getPreferenceService(), - (rpc, sessionCookie, cb) -> rpc.setFasterBackgroundActionsDisabled(event.getValue(), cb), - this::onSuccess, - this::onError - ); - } - - private void onError(Throwable cause) { - // restore old value - setValue(Preferences.getFasterBackgroundActionsDisabled()); - AggregateUI.getUI().reportError(cause); - } - - private void onSuccess() { - AggregateUI.getUI().clearError(); - Preferences.updatePreferences(settingsChange); - } -} \ No newline at end of file From 76b154e0ae83e64258c12194e5add2e83e32be86 Mon Sep 17 00:00:00 2001 From: Guille Date: Fri, 11 Jan 2019 09:00:27 +0100 Subject: [PATCH 2/7] Set faster background actions always enabled by bypassing the getter --- .../aggregate/server/ServerPreferencesProperties.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java b/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java index b1843ca2aa..a4d5a04c97 100644 --- a/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java +++ b/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java @@ -139,13 +139,8 @@ public static void setFasterWatchdogCycleEnabled(CallingContext cc, Boolean enab setServerPreferencesProperty(cc, FASTER_WATCHDOG_CYCLE_ENABLED, enabled.toString()); } - public static Boolean getFasterBackgroundActionsDisabled(CallingContext cc) throws ODKEntityNotFoundException, ODKOverQuotaException { - String value = getServerPreferencesProperty(cc, FASTER_BACKGROUND_ACTIONS_DISABLED); - if (value != null) { - return Boolean.valueOf(value); - } - // null value should be treated as false - return false; + public static Boolean getFasterBackgroundActionsDisabled(CallingContext cc) { + return true; } public static void setFasterBackgroundActionsDisabled(CallingContext cc, Boolean disabled) throws ODKEntityNotFoundException, ODKOverQuotaException { From a65398abc78b691fc7be05284cddbd42aaa77ebc Mon Sep 17 00:00:00 2001 From: Guille Date: Fri, 11 Jan 2019 09:00:57 +0100 Subject: [PATCH 3/7] Inline the call to the getter to simplify downstream code --- .../aggregate/server/ServerPreferencesProperties.java | 6 +----- .../aggregate/task/UploadSubmissionsWorkerImpl.java | 3 +-- src/main/java/org/opendatakit/aggregate/task/Watchdog.java | 2 +- .../org/opendatakit/aggregate/util/BackendActionsTable.java | 2 +- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java b/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java index a4d5a04c97..e96c2e8855 100644 --- a/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java +++ b/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java @@ -68,7 +68,7 @@ private ServerPreferencesProperties(ServerPreferencesProperties ref, User user) public static PreferenceSummary getPreferenceSummary(CallingContext cc) throws ODKEntityNotFoundException, ODKOverQuotaException { return new PreferenceSummary(getGoogleSimpleApiKey(cc), getGoogleApiClientId(cc), - getEnketoApiUrl(cc), getEnketoApiToken(cc), getFasterBackgroundActionsDisabled(cc), getSkipMalformedSubmissions(cc)); + getEnketoApiUrl(cc), getEnketoApiToken(cc), true, getSkipMalformedSubmissions(cc)); } public static String getSiteKey(CallingContext cc) throws ODKEntityNotFoundException, ODKOverQuotaException { @@ -139,10 +139,6 @@ public static void setFasterWatchdogCycleEnabled(CallingContext cc, Boolean enab setServerPreferencesProperty(cc, FASTER_WATCHDOG_CYCLE_ENABLED, enabled.toString()); } - public static Boolean getFasterBackgroundActionsDisabled(CallingContext cc) { - return true; - } - public static void setFasterBackgroundActionsDisabled(CallingContext cc, Boolean disabled) throws ODKEntityNotFoundException, ODKOverQuotaException { setServerPreferencesProperty(cc, FASTER_BACKGROUND_ACTIONS_DISABLED, disabled.toString()); } diff --git a/src/main/java/org/opendatakit/aggregate/task/UploadSubmissionsWorkerImpl.java b/src/main/java/org/opendatakit/aggregate/task/UploadSubmissionsWorkerImpl.java index 8ee9806ca3..998a10c28a 100644 --- a/src/main/java/org/opendatakit/aggregate/task/UploadSubmissionsWorkerImpl.java +++ b/src/main/java/org/opendatakit/aggregate/task/UploadSubmissionsWorkerImpl.java @@ -30,7 +30,6 @@ import org.opendatakit.aggregate.form.FormFactory; import org.opendatakit.aggregate.form.IForm; import org.opendatakit.aggregate.query.submission.QueryByDateRange; -import org.opendatakit.aggregate.server.ServerPreferencesProperties; import org.opendatakit.aggregate.submission.Submission; import org.opendatakit.common.persistence.Datastore; import org.opendatakit.common.persistence.TaskLock; @@ -209,7 +208,7 @@ public void uploadAllSubmissions() throws ODKEntityNotFoundException, ODKExterna // background activities and it started on the background thread. boolean disableFasterProcessing = true; try { - disableFasterProcessing = ServerPreferencesProperties.getFasterBackgroundActionsDisabled(cc); + disableFasterProcessing = true; } catch (ODKOverQuotaException e) { logger.warn("Quota exceeded.", e); } diff --git a/src/main/java/org/opendatakit/aggregate/task/Watchdog.java b/src/main/java/org/opendatakit/aggregate/task/Watchdog.java index d476efb844..6092bca706 100644 --- a/src/main/java/org/opendatakit/aggregate/task/Watchdog.java +++ b/src/main/java/org/opendatakit/aggregate/task/Watchdog.java @@ -324,7 +324,7 @@ public boolean getFasterWatchdogCycleEnabled() { BackendActionsTable.FAST_PUBLISHING_RETRY_MILLISECONDS + lastFasterWatchdogCycleEnabledFlagFetch) { try { - boolean disabled = ServerPreferencesProperties.getFasterBackgroundActionsDisabled(cc); + boolean disabled = true; setFasterWatchdogCycleEnabled(!disabled && ServerPreferencesProperties.getFasterWatchdogCycleEnabled(cc)); } catch (ODKEntityNotFoundException e) { e.printStackTrace(); diff --git a/src/main/java/org/opendatakit/aggregate/util/BackendActionsTable.java b/src/main/java/org/opendatakit/aggregate/util/BackendActionsTable.java index 607ff82383..7f0ad71a44 100644 --- a/src/main/java/org/opendatakit/aggregate/util/BackendActionsTable.java +++ b/src/main/java/org/opendatakit/aggregate/util/BackendActionsTable.java @@ -458,7 +458,7 @@ public static synchronized void rescheduleWatchdog(boolean hasActiveTasks, Watchdog wd = (Watchdog) cc.getBean(BeanDefs.WATCHDOG); try { - boolean disabled = ServerPreferencesProperties.getFasterBackgroundActionsDisabled(cc); + boolean disabled = true; boolean wasFastPublishing = ServerPreferencesProperties.getFasterWatchdogCycleEnabled(cc); if (!hasActiveTasks && wasFastPublishing) { From 0e1361129354ccc1871f7742ba322e75df19ad04 Mon Sep 17 00:00:00 2001 From: Guille Date: Fri, 11 Jan 2019 09:05:20 +0100 Subject: [PATCH 4/7] Simplify downstream code - round 1 - Inline the boolean value and simplify if blocks --- .../task/UploadSubmissionsWorkerImpl.java | 10 +--------- .../opendatakit/aggregate/task/Watchdog.java | 9 +-------- .../aggregate/util/BackendActionsTable.java | 19 +------------------ 3 files changed, 3 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/opendatakit/aggregate/task/UploadSubmissionsWorkerImpl.java b/src/main/java/org/opendatakit/aggregate/task/UploadSubmissionsWorkerImpl.java index 998a10c28a..bccb1e25a3 100644 --- a/src/main/java/org/opendatakit/aggregate/task/UploadSubmissionsWorkerImpl.java +++ b/src/main/java/org/opendatakit/aggregate/task/UploadSubmissionsWorkerImpl.java @@ -204,15 +204,7 @@ public void uploadAllSubmissions() throws ODKEntityNotFoundException, ODKExterna if (reQueue) { // create another task to continue upload UploadSubmissions uploadSubmissionsBean = (UploadSubmissions) cc.getBean(BeanDefs.UPLOAD_TASK_BEAN); - // schedule it on the background thread only if we are not disabling - // background activities and it started on the background thread. - boolean disableFasterProcessing = true; - try { - disableFasterProcessing = true; - } catch (ODKOverQuotaException e) { - logger.warn("Quota exceeded.", e); - } - uploadSubmissionsBean.createFormUploadTask(formServiceCursor, useLargerBatchSize && !disableFasterProcessing, cc); + uploadSubmissionsBean.createFormUploadTask(formServiceCursor, false, cc); } } diff --git a/src/main/java/org/opendatakit/aggregate/task/Watchdog.java b/src/main/java/org/opendatakit/aggregate/task/Watchdog.java index 6092bca706..1c424b08e8 100644 --- a/src/main/java/org/opendatakit/aggregate/task/Watchdog.java +++ b/src/main/java/org/opendatakit/aggregate/task/Watchdog.java @@ -323,14 +323,7 @@ public boolean getFasterWatchdogCycleEnabled() { if (System.currentTimeMillis() > BackendActionsTable.FAST_PUBLISHING_RETRY_MILLISECONDS + lastFasterWatchdogCycleEnabledFlagFetch) { - try { - boolean disabled = true; - setFasterWatchdogCycleEnabled(!disabled && ServerPreferencesProperties.getFasterWatchdogCycleEnabled(cc)); - } catch (ODKEntityNotFoundException e) { - e.printStackTrace(); - } catch (ODKOverQuotaException e) { - e.printStackTrace(); - } + setFasterWatchdogCycleEnabled(false); } return lastFasterWatchdogCycleEnabledFlag; } diff --git a/src/main/java/org/opendatakit/aggregate/util/BackendActionsTable.java b/src/main/java/org/opendatakit/aggregate/util/BackendActionsTable.java index 7f0ad71a44..f64f791e76 100644 --- a/src/main/java/org/opendatakit/aggregate/util/BackendActionsTable.java +++ b/src/main/java/org/opendatakit/aggregate/util/BackendActionsTable.java @@ -458,7 +458,6 @@ public static synchronized void rescheduleWatchdog(boolean hasActiveTasks, Watchdog wd = (Watchdog) cc.getBean(BeanDefs.WATCHDOG); try { - boolean disabled = true; boolean wasFastPublishing = ServerPreferencesProperties.getFasterWatchdogCycleEnabled(cc); if (!hasActiveTasks && wasFastPublishing) { @@ -467,24 +466,8 @@ public static synchronized void rescheduleWatchdog(boolean hasActiveTasks, wd.setFasterWatchdogCycleEnabled(false); } - if (hasActiveTasks) { - if (!disabled) { - if (!wasFastPublishing) { - // switch to the faster watchdog cycle - ServerPreferencesProperties.setFasterWatchdogCycleEnabled(cc, true); - wd.setFasterWatchdogCycleEnabled(true); - } else { - // schedule the next watchdog in the future. - // if we are culling the watchdog, then do not enqueue it. - if (!cullThisWatchdog) { - wd.onUsage(FAST_PUBLISHING_RETRY_MILLISECONDS, cc); - } - } - } - // and regardless, update the next-eligible-requeue time - // this is only used if fast publishing is disabled. + if (hasActiveTasks) scheduleFutureWatchdog(wd, FAST_PUBLISHING_RETRY_MILLISECONDS, cc); - } } catch (ODKEntityNotFoundException | ODKOverQuotaException e) { e.printStackTrace(); } From 843b647bd8623d61d4ba41b8b51ba55a213cde2a Mon Sep 17 00:00:00 2001 From: Guille Date: Fri, 11 Jan 2019 09:09:07 +0100 Subject: [PATCH 5/7] Simplify downstream code - round 2 - Remove unused or redundant variables and method arguments - Reformat code - Remove the faster background actions preference from the domain --- .../client/preferences/PreferenceSummary.java | 143 ++-- .../client/preferences/Preferences.java | 279 ++++---- .../AbstractExternalService.java | 640 +++++++++--------- .../server/ServerPreferencesProperties.java | 2 +- .../aggregate/servlet/SubmissionServlet.java | 3 +- .../aggregate/task/UploadSubmissions.java | 2 +- .../task/UploadSubmissionsWorkerImpl.java | 2 +- .../opendatakit/aggregate/task/Watchdog.java | 6 +- .../aggregate/task/WatchdogWorkerImpl.java | 6 +- .../task/WorksheetCreatorWorkerImpl.java | 2 +- .../aggregate/util/BackendActionsTable.java | 3 +- 11 files changed, 533 insertions(+), 555 deletions(-) diff --git a/src/main/java/org/opendatakit/aggregate/client/preferences/PreferenceSummary.java b/src/main/java/org/opendatakit/aggregate/client/preferences/PreferenceSummary.java index c222c70b96..cef75a6b17 100644 --- a/src/main/java/org/opendatakit/aggregate/client/preferences/PreferenceSummary.java +++ b/src/main/java/org/opendatakit/aggregate/client/preferences/PreferenceSummary.java @@ -1,75 +1,68 @@ -/* - * Copyright (C) 2011 University of Washington - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package org.opendatakit.aggregate.client.preferences; - -import java.io.Serializable; - -public class PreferenceSummary implements Serializable { - - private static final long serialVersionUID = -53448827282096798L; - - private String googleSimpleApiKey; - - private String googleApiClientId; - - private String enketoApiUrl; - - private String enketoApiToken; - - private Boolean fasterBackgroundActionsDisabled; - - private Boolean skipMalformedSubmissions; - - public PreferenceSummary() { - - } - - public PreferenceSummary(String googleSimpleApiKey, String googleApiClientId, - String enketoApiUrl, String enketoApiToken, - Boolean fasterBackgroundActionsDisabled, Boolean skipMalformedSubmissions) { - this.googleSimpleApiKey = googleSimpleApiKey; - this.googleApiClientId = googleApiClientId; - this.enketoApiUrl = enketoApiUrl; - this.enketoApiToken = enketoApiToken; - this.fasterBackgroundActionsDisabled = fasterBackgroundActionsDisabled; - this.skipMalformedSubmissions = skipMalformedSubmissions; - } - - public String getGoogleSimpleApiKey() { - return googleSimpleApiKey; - } - - public String getGoogleApiClientId() { - return googleApiClientId; - } - - public String getEnketoApiUrl() { - return enketoApiUrl; - } - - public String getEnketoApiToken() { - return enketoApiToken; - } - - public Boolean getFasterBackgroundActionsDisabled() { - return fasterBackgroundActionsDisabled; - } - - public Boolean getSkipMalformedSubmissions() { - return skipMalformedSubmissions; - } -} +/* + * Copyright (C) 2011 University of Washington + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opendatakit.aggregate.client.preferences; + +import java.io.Serializable; + +public class PreferenceSummary implements Serializable { + + private static final long serialVersionUID = -53448827282096798L; + + private String googleSimpleApiKey; + + private String googleApiClientId; + + private String enketoApiUrl; + + private String enketoApiToken; + + private Boolean skipMalformedSubmissions; + + public PreferenceSummary() { + + } + + public PreferenceSummary(String googleSimpleApiKey, String googleApiClientId, + String enketoApiUrl, String enketoApiToken, + Boolean skipMalformedSubmissions) { + this.googleSimpleApiKey = googleSimpleApiKey; + this.googleApiClientId = googleApiClientId; + this.enketoApiUrl = enketoApiUrl; + this.enketoApiToken = enketoApiToken; + this.skipMalformedSubmissions = skipMalformedSubmissions; + } + + public String getGoogleSimpleApiKey() { + return googleSimpleApiKey; + } + + public String getGoogleApiClientId() { + return googleApiClientId; + } + + public String getEnketoApiUrl() { + return enketoApiUrl; + } + + public String getEnketoApiToken() { + return enketoApiToken; + } + + public Boolean getSkipMalformedSubmissions() { + return skipMalformedSubmissions; + } +} diff --git a/src/main/java/org/opendatakit/aggregate/client/preferences/Preferences.java b/src/main/java/org/opendatakit/aggregate/client/preferences/Preferences.java index 385dcfabff..41dd874747 100644 --- a/src/main/java/org/opendatakit/aggregate/client/preferences/Preferences.java +++ b/src/main/java/org/opendatakit/aggregate/client/preferences/Preferences.java @@ -1,144 +1,135 @@ -/* - * Copyright (C) 2011 University of Washington - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package org.opendatakit.aggregate.client.preferences; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; -import java.util.ArrayList; -import java.util.TreeSet; -import org.opendatakit.aggregate.client.AggregateUI; -import org.opendatakit.aggregate.client.SecureGWT; -import org.opendatakit.common.security.common.GrantedAuthorityName; - -public class Preferences { - - private static final String NULL_PREFERENCES_ERROR = "ERROR: somehow got a null preference summary"; - private static String googleSimpleApiKey; - private static String googleApiClientId; - private static String enketoApiUrl; - private static String enketoApiToken; - private static Boolean fasterBackgroundActionsDisabled; - private static Boolean skipMalformedSubmissions; - private static int nesting = 0; - private static ArrayList userCallbacks = new ArrayList(); - private static AsyncCallback callback = new AsyncCallback() { - @Override - public void onFailure(Throwable caught) { - AggregateUI.getUI().reportError(caught); - --nesting; - if (nesting <= 0) { - nesting = 0; - ArrayList local = userCallbacks; - userCallbacks = new ArrayList(); - for (PreferencesCompletionCallback uc : local) { - uc.failedRefresh(); - } - } - } - - @Override - public void onSuccess(PreferenceSummary summary) { - if (summary == null) { - GWT.log(NULL_PREFERENCES_ERROR); - AggregateUI.getUI().reportError(new Throwable(NULL_PREFERENCES_ERROR)); - } - - googleSimpleApiKey = summary.getGoogleSimpleApiKey(); - googleApiClientId = summary.getGoogleApiClientId(); - enketoApiUrl = summary.getEnketoApiUrl(); - enketoApiToken = summary.getEnketoApiToken(); - fasterBackgroundActionsDisabled = summary.getFasterBackgroundActionsDisabled(); - skipMalformedSubmissions = summary.getSkipMalformedSubmissions(); - - --nesting; - if (nesting <= 0) { - nesting = 0; - ArrayList local = userCallbacks; - userCallbacks = new ArrayList(); - for (PreferencesCompletionCallback uc : local) { - uc.refreshFromUpdatedPreferences(); - } - } - } - }; - - public static void updatePreferences(final PreferencesCompletionCallback userCallback) { - userCallbacks.add(userCallback); - ++nesting; - SecureGWT.getPreferenceService().getPreferences(callback); - } - - public static String getGoogleSimpleApiKey() { - if (googleSimpleApiKey != null) { - return googleSimpleApiKey; - } - return ""; - } - - public static String getGoogleApiClientId() { - if (googleApiClientId != null) { - return googleApiClientId; - } - return ""; - } - - public static boolean showEnketoIntegration() { - TreeSet authorities = AggregateUI.getUI().getUserInfo().getGrantedAuthorities(); - if (authorities.contains(GrantedAuthorityName.ROLE_DATA_COLLECTOR) || authorities.contains(GrantedAuthorityName.ROLE_DATA_OWNER)) { - if (getEnketoApiUrl() != null && !getEnketoApiUrl().equals("")) { - return true; - } - } - return false; - } - - public static String getEnketoApiUrl() { - if (enketoApiUrl != null) { - return enketoApiUrl; - } - return ""; - } - - public static String getEnketoApiToken() { - if (enketoApiToken != null) { - return enketoApiToken; - } - return ""; - } - - public static Boolean getFasterBackgroundActionsDisabled() { - if (fasterBackgroundActionsDisabled != null) { - return fasterBackgroundActionsDisabled; - } - return Boolean.FALSE; - } - - public static Boolean getSkipMalformedSubmissions() { - if (skipMalformedSubmissions != null) { - return skipMalformedSubmissions; - } - return Boolean.FALSE; - } - - public static interface PreferencesCompletionCallback { - public void refreshFromUpdatedPreferences(); - - public void failedRefresh(); - } - - -} +/* + * Copyright (C) 2011 University of Washington + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opendatakit.aggregate.client.preferences; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; +import java.util.ArrayList; +import java.util.TreeSet; +import org.opendatakit.aggregate.client.AggregateUI; +import org.opendatakit.aggregate.client.SecureGWT; +import org.opendatakit.common.security.common.GrantedAuthorityName; + +public class Preferences { + + private static final String NULL_PREFERENCES_ERROR = "ERROR: somehow got a null preference summary"; + private static String googleSimpleApiKey; + private static String googleApiClientId; + private static String enketoApiUrl; + private static String enketoApiToken; + private static Boolean skipMalformedSubmissions; + private static int nesting = 0; + private static ArrayList userCallbacks = new ArrayList(); + private static AsyncCallback callback = new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + AggregateUI.getUI().reportError(caught); + --nesting; + if (nesting <= 0) { + nesting = 0; + ArrayList local = userCallbacks; + userCallbacks = new ArrayList(); + for (PreferencesCompletionCallback uc : local) { + uc.failedRefresh(); + } + } + } + + @Override + public void onSuccess(PreferenceSummary summary) { + if (summary == null) { + GWT.log(NULL_PREFERENCES_ERROR); + AggregateUI.getUI().reportError(new Throwable(NULL_PREFERENCES_ERROR)); + } + + googleSimpleApiKey = summary.getGoogleSimpleApiKey(); + googleApiClientId = summary.getGoogleApiClientId(); + enketoApiUrl = summary.getEnketoApiUrl(); + enketoApiToken = summary.getEnketoApiToken(); + skipMalformedSubmissions = summary.getSkipMalformedSubmissions(); + + --nesting; + if (nesting <= 0) { + nesting = 0; + ArrayList local = userCallbacks; + userCallbacks = new ArrayList(); + for (PreferencesCompletionCallback uc : local) { + uc.refreshFromUpdatedPreferences(); + } + } + } + }; + + public static void updatePreferences(final PreferencesCompletionCallback userCallback) { + userCallbacks.add(userCallback); + ++nesting; + SecureGWT.getPreferenceService().getPreferences(callback); + } + + public static String getGoogleSimpleApiKey() { + if (googleSimpleApiKey != null) { + return googleSimpleApiKey; + } + return ""; + } + + public static String getGoogleApiClientId() { + if (googleApiClientId != null) { + return googleApiClientId; + } + return ""; + } + + public static boolean showEnketoIntegration() { + TreeSet authorities = AggregateUI.getUI().getUserInfo().getGrantedAuthorities(); + if (authorities.contains(GrantedAuthorityName.ROLE_DATA_COLLECTOR) || authorities.contains(GrantedAuthorityName.ROLE_DATA_OWNER)) { + if (getEnketoApiUrl() != null && !getEnketoApiUrl().equals("")) { + return true; + } + } + return false; + } + + public static String getEnketoApiUrl() { + if (enketoApiUrl != null) { + return enketoApiUrl; + } + return ""; + } + + public static String getEnketoApiToken() { + if (enketoApiToken != null) { + return enketoApiToken; + } + return ""; + } + + public static Boolean getSkipMalformedSubmissions() { + if (skipMalformedSubmissions != null) { + return skipMalformedSubmissions; + } + return Boolean.FALSE; + } + + public static interface PreferencesCompletionCallback { + public void refreshFromUpdatedPreferences(); + + public void failedRefresh(); + } + + +} diff --git a/src/main/java/org/opendatakit/aggregate/externalservice/AbstractExternalService.java b/src/main/java/org/opendatakit/aggregate/externalservice/AbstractExternalService.java index 8444b4dd51..a8eeef682d 100644 --- a/src/main/java/org/opendatakit/aggregate/externalservice/AbstractExternalService.java +++ b/src/main/java/org/opendatakit/aggregate/externalservice/AbstractExternalService.java @@ -1,320 +1,320 @@ -/* - Copyright (C) 2010 University of Washington -

- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - in compliance with the License. You may obtain a copy of the License at -

- http://www.apache.org/licenses/LICENSE-2.0 -

- Unless required by applicable law or agreed to in writing, software distributed under the License - is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the License for the specific language governing permissions and limitations under - the License. - */ -package org.opendatakit.aggregate.externalservice; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.NameValuePair; -import org.apache.http.client.CookieStore; -import org.apache.http.client.CredentialsProvider; -import org.apache.http.client.HttpClient; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPatch; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.config.SocketConfig; -import org.apache.http.impl.client.BasicCookieStore; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.protocol.BasicHttpContext; -import org.apache.http.protocol.HttpContext; -import org.opendatakit.aggregate.ContextFactory; -import org.opendatakit.aggregate.client.externalserv.ExternServSummary; -import org.opendatakit.aggregate.constants.BeanDefs; -import org.opendatakit.aggregate.constants.common.ExternalServicePublicationOption; -import org.opendatakit.aggregate.constants.common.ExternalServiceType; -import org.opendatakit.aggregate.constants.common.OperationalStatus; -import org.opendatakit.aggregate.exception.ODKExternalServiceException; -import org.opendatakit.aggregate.form.IForm; -import org.opendatakit.aggregate.format.element.ElementFormatter; -import org.opendatakit.aggregate.format.header.HeaderFormatter; -import org.opendatakit.aggregate.submission.Submission; -import org.opendatakit.aggregate.task.UploadSubmissions; -import org.opendatakit.common.datamodel.DeleteHelper; -import org.opendatakit.common.persistence.CommonFieldsBase; -import org.opendatakit.common.persistence.Datastore; -import org.opendatakit.common.persistence.EntityKey; -import org.opendatakit.common.persistence.exception.ODKDatastoreException; -import org.opendatakit.common.persistence.exception.ODKEntityPersistException; -import org.opendatakit.common.persistence.exception.ODKOverQuotaException; -import org.opendatakit.common.security.User; -import org.opendatakit.common.utils.HttpClientFactory; -import org.opendatakit.common.web.CallingContext; -import org.opendatakit.common.web.constants.HtmlConsts; - - -/** - * @author wbrunette@gmail.com - * @author mitchellsundt@gmail.com - */ -public abstract class AbstractExternalService implements ExternalService { - - // these do not take entity bodies... - protected static final String DELETE = "DELETE"; - protected static final String GET = "GET"; - // these do... - protected static final String POST = "POST"; - protected static final String PUT = "PUT"; - protected static final String PATCH = "PATCH"; - // and also share all session cookies and credentials across all sessions... - // these are thread-safe, so this is OK. - protected static final CookieStore cookieStore = new BasicCookieStore(); - protected static final CredentialsProvider credsProvider = new BasicCredentialsProvider(); - protected static final int SERVICE_TIMEOUT_MILLISECONDS = 60000; - protected static final int SOCKET_ESTABLISHMENT_TIMEOUT_MILLISECONDS = 60000; - protected static final Charset UTF_CHARSET = Charset.forName(HtmlConsts.UTF8_ENCODE); - private static final String NO_BATCH_FUNCTIONALITY_ERROR = "ERROR! External Service does NOT implement a BATCH function to upload multiple submissions - AbstractExternalService"; - /** - * Datastore entity holding registration of an external service for a specific - * form and the cursor position within that form that was last processed by - * this service. - */ - protected final FormServiceCursor fsc; - protected final IForm form; - protected final ElementFormatter formatter; - protected final HeaderFormatter headerFormatter; - - protected AbstractExternalService(IForm form, FormServiceCursor formServiceCursor, ElementFormatter formatter, HeaderFormatter headerFormatter, CallingContext cc) { - this.form = form; - this.formatter = formatter; - this.headerFormatter = headerFormatter; - this.fsc = formServiceCursor; - } - - protected static FormServiceCursor createFormServiceCursor(IForm form, CommonFieldsBase entity, ExternalServicePublicationOption externalServiceOption, ExternalServiceType type, CallingContext cc) throws ODKDatastoreException { - FormServiceCursor formServiceCursor = FormServiceCursor.createFormServiceCursor(form, type, entity, cc); - formServiceCursor.setExternalServiceOption(externalServiceOption); - formServiceCursor.setIsExternalServicePrepared(false); - formServiceCursor.setOperationalStatus(OperationalStatus.ESTABLISHED); - formServiceCursor.setEstablishmentDateTime(new Date()); - formServiceCursor.setUploadCompleted(false); - return formServiceCursor; - } - - protected static final T newEntity(T parameterTableRelation, CallingContext cc) { - Datastore ds = cc.getDatastore(); - User user = cc.getCurrentUser(); - return ds.createEntityUsingRelation(parameterTableRelation, user); - } - - protected static final T retrieveEntity(T parameterTableRelation, FormServiceCursor fsc, CallingContext cc) throws ODKDatastoreException { - Datastore ds = cc.getDatastore(); - User user = cc.getCurrentUser(); - return ds.getEntity(parameterTableRelation, fsc.getAuriService(), user); - } - - protected abstract String getOwnership(); - - protected abstract CommonFieldsBase retrieveObjectEntity(); - - protected abstract List retrieveRepeatElementEntities(); - - protected abstract void insertData(Submission submission, CallingContext cc) throws ODKExternalServiceException; - - @Override - public boolean canBatchSubmissions() { - return false; - } - - @Override - public void sendSubmissions(List submissions, boolean streaming, CallingContext cc) throws ODKExternalServiceException { - throw new ODKExternalServiceException(NO_BATCH_FUNCTIONALITY_ERROR); - } - - @Override - public void sendSubmission(Submission submission, CallingContext cc) throws ODKExternalServiceException { - insertData(submission, cc); - } - - @Override - public void setUploadCompleted(CallingContext cc) throws ODKEntityPersistException, ODKOverQuotaException { - fsc.setUploadCompleted(true); - if (fsc.getExternalServicePublicationOption() == ExternalServicePublicationOption.UPLOAD_ONLY) { - fsc.setOperationalStatus(OperationalStatus.COMPLETED); - } - Datastore ds = cc.getDatastore(); - User user = cc.getCurrentUser(); - ds.putEntity(fsc, user); - } - - protected HttpResponse sendHttpRequest(String method, String url, HttpEntity entity, List qparams, CallingContext cc) throws - IOException { - - // setup client - HttpClientFactory factory = (HttpClientFactory) cc.getBean(BeanDefs.HTTP_CLIENT_FACTORY); - - SocketConfig socketConfig = SocketConfig.copy(SocketConfig.DEFAULT) - .setSoTimeout(SOCKET_ESTABLISHMENT_TIMEOUT_MILLISECONDS) - .build(); - RequestConfig requestConfig = RequestConfig.copy(RequestConfig.DEFAULT) - .setConnectTimeout(SERVICE_TIMEOUT_MILLISECONDS) - .setRedirectsEnabled(true) - .setAuthenticationEnabled(true) - .setMaxRedirects(32) - .setCircularRedirectsAllowed(true) - .build(); - - HttpClient client = factory.createHttpClient(socketConfig, null, requestConfig); - - // context holds authentication state machine, so it cannot be - // shared across independent activities. - HttpContext localContext = new BasicHttpContext(); - - localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore); - localContext.setAttribute(HttpClientContext.CREDS_PROVIDER, credsProvider); - - HttpUriRequest request = null; - if (entity == null && (POST.equals(method) || PATCH.equals(method) || PUT.equals(method))) { - throw new IllegalStateException("No body supplied for POST, PATCH or PUT request"); - } else if (entity != null && !(POST.equals(method) || PATCH.equals(method) || PUT.equals(method))) { - throw new IllegalStateException("Body was supplied for GET or DELETE request"); - } - - URI nakedUri; - try { - nakedUri = new URI(url); - } catch (Exception e) { - e.printStackTrace(); - throw new IllegalStateException(e); - } - - if (qparams == null) { - qparams = new ArrayList(); - } - URI uri; - try { - uri = new URI(nakedUri.getScheme(), nakedUri.getUserInfo(), nakedUri.getHost(), - nakedUri.getPort(), nakedUri.getPath(), URLEncodedUtils.format(qparams, HtmlConsts.UTF8_ENCODE), null); - } catch (URISyntaxException e1) { - e1.printStackTrace(); - throw new IllegalStateException(e1); - } - System.out.println(uri.toString()); - - if (GET.equals(method)) { - HttpGet get = new HttpGet(uri); - request = get; - } else if (DELETE.equals(method)) { - HttpDelete delete = new HttpDelete(uri); - request = delete; - } else if (PATCH.equals(method)) { - HttpPatch patch = new HttpPatch(uri); - patch.setEntity(entity); - request = patch; - } else if (POST.equals(method)) { - HttpPost post = new HttpPost(uri); - post.setEntity(entity); - request = post; - } else if (PUT.equals(method)) { - HttpPut put = new HttpPut(uri); - put.setEntity(entity); - request = put; - } else { - throw new IllegalStateException("Unexpected request method"); - } - - HttpResponse resp = client.execute(request); - return resp; - } - - @Override - public void delete(CallingContext cc) throws ODKDatastoreException { - CommonFieldsBase serviceEntity = retrieveObjectEntity(); - List repeats = retrieveRepeatElementEntities(); - - Datastore ds = cc.getDatastore(); - User user = cc.getCurrentUser(); - - if (repeats != null) { - List keys = new ArrayList(); - for (CommonFieldsBase repeat : repeats) { - keys.add(repeat.getEntityKey()); - } - DeleteHelper.deleteEntities(keys, cc); - repeats.clear(); - } - - ds.deleteEntity(serviceEntity.getEntityKey(), user); - ds.deleteEntity(fsc.getEntityKey(), user); - } - - @Override - public void persist(CallingContext cc) throws ODKEntityPersistException, ODKOverQuotaException { - Datastore ds = cc.getDatastore(); - User user = cc.getCurrentUser(); - - CommonFieldsBase serviceEntity = retrieveObjectEntity(); - List repeats = retrieveRepeatElementEntities(); - - if (repeats != null) { - ds.putEntities(repeats, user); - } - ds.putEntity(serviceEntity, user); - ds.putEntity(fsc, user); - } - - @Override - public FormServiceCursor getFormServiceCursor() { - return fsc; - } - - @Override - public ExternServSummary transform() { - return new ExternServSummary(fsc.getUri(), - fsc.getCreatorUriUser(), - fsc.getOperationalStatus(), - fsc.getEstablishmentDateTime(), - fsc.getExternalServicePublicationOption(), - fsc.getUploadCompleted(), - fsc.getLastUploadCursorDate(), - fsc.getLastStreamingCursorDate(), - fsc.getExternalServiceType(), - getOwnership(), - getDescriptiveTargetString()); - } - - @Override - public int hashCode() { - int hashCode = 13; - if (retrieveObjectEntity() != null) - hashCode += retrieveObjectEntity().hashCode(); - if (fsc != null) - hashCode += fsc.hashCode(); - return hashCode; - } - - protected void postUploadTask(CallingContext cc) throws ODKExternalServiceException { - // upload data to external service - if (!fsc.getExternalServicePublicationOption().equals( - ExternalServicePublicationOption.STREAM_ONLY)) { - - UploadSubmissions uploadTask = (UploadSubmissions) cc.getBean(BeanDefs.UPLOAD_TASK_BEAN); - CallingContext ccDaemon = ContextFactory.duplicateContext(cc); - ccDaemon.setAsDaemon(true); - uploadTask.createFormUploadTask(fsc, true, ccDaemon); - } - } - -} +/* + Copyright (C) 2010 University of Washington +

+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + in compliance with the License. You may obtain a copy of the License at +

+ http://www.apache.org/licenses/LICENSE-2.0 +

+ Unless required by applicable law or agreed to in writing, software distributed under the License + is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the License for the specific language governing permissions and limitations under + the License. + */ +package org.opendatakit.aggregate.externalservice; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.CookieStore; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.HttpClient; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPatch; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.client.utils.URLEncodedUtils; +import org.apache.http.config.SocketConfig; +import org.apache.http.impl.client.BasicCookieStore; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.protocol.BasicHttpContext; +import org.apache.http.protocol.HttpContext; +import org.opendatakit.aggregate.ContextFactory; +import org.opendatakit.aggregate.client.externalserv.ExternServSummary; +import org.opendatakit.aggregate.constants.BeanDefs; +import org.opendatakit.aggregate.constants.common.ExternalServicePublicationOption; +import org.opendatakit.aggregate.constants.common.ExternalServiceType; +import org.opendatakit.aggregate.constants.common.OperationalStatus; +import org.opendatakit.aggregate.exception.ODKExternalServiceException; +import org.opendatakit.aggregate.form.IForm; +import org.opendatakit.aggregate.format.element.ElementFormatter; +import org.opendatakit.aggregate.format.header.HeaderFormatter; +import org.opendatakit.aggregate.submission.Submission; +import org.opendatakit.aggregate.task.UploadSubmissions; +import org.opendatakit.common.datamodel.DeleteHelper; +import org.opendatakit.common.persistence.CommonFieldsBase; +import org.opendatakit.common.persistence.Datastore; +import org.opendatakit.common.persistence.EntityKey; +import org.opendatakit.common.persistence.exception.ODKDatastoreException; +import org.opendatakit.common.persistence.exception.ODKEntityPersistException; +import org.opendatakit.common.persistence.exception.ODKOverQuotaException; +import org.opendatakit.common.security.User; +import org.opendatakit.common.utils.HttpClientFactory; +import org.opendatakit.common.web.CallingContext; +import org.opendatakit.common.web.constants.HtmlConsts; + + +/** + * @author wbrunette@gmail.com + * @author mitchellsundt@gmail.com + */ +public abstract class AbstractExternalService implements ExternalService { + + // these do not take entity bodies... + protected static final String DELETE = "DELETE"; + protected static final String GET = "GET"; + // these do... + protected static final String POST = "POST"; + protected static final String PUT = "PUT"; + protected static final String PATCH = "PATCH"; + // and also share all session cookies and credentials across all sessions... + // these are thread-safe, so this is OK. + protected static final CookieStore cookieStore = new BasicCookieStore(); + protected static final CredentialsProvider credsProvider = new BasicCredentialsProvider(); + protected static final int SERVICE_TIMEOUT_MILLISECONDS = 60000; + protected static final int SOCKET_ESTABLISHMENT_TIMEOUT_MILLISECONDS = 60000; + protected static final Charset UTF_CHARSET = Charset.forName(HtmlConsts.UTF8_ENCODE); + private static final String NO_BATCH_FUNCTIONALITY_ERROR = "ERROR! External Service does NOT implement a BATCH function to upload multiple submissions - AbstractExternalService"; + /** + * Datastore entity holding registration of an external service for a specific + * form and the cursor position within that form that was last processed by + * this service. + */ + protected final FormServiceCursor fsc; + protected final IForm form; + protected final ElementFormatter formatter; + protected final HeaderFormatter headerFormatter; + + protected AbstractExternalService(IForm form, FormServiceCursor formServiceCursor, ElementFormatter formatter, HeaderFormatter headerFormatter, CallingContext cc) { + this.form = form; + this.formatter = formatter; + this.headerFormatter = headerFormatter; + this.fsc = formServiceCursor; + } + + protected static FormServiceCursor createFormServiceCursor(IForm form, CommonFieldsBase entity, ExternalServicePublicationOption externalServiceOption, ExternalServiceType type, CallingContext cc) throws ODKDatastoreException { + FormServiceCursor formServiceCursor = FormServiceCursor.createFormServiceCursor(form, type, entity, cc); + formServiceCursor.setExternalServiceOption(externalServiceOption); + formServiceCursor.setIsExternalServicePrepared(false); + formServiceCursor.setOperationalStatus(OperationalStatus.ESTABLISHED); + formServiceCursor.setEstablishmentDateTime(new Date()); + formServiceCursor.setUploadCompleted(false); + return formServiceCursor; + } + + protected static final T newEntity(T parameterTableRelation, CallingContext cc) { + Datastore ds = cc.getDatastore(); + User user = cc.getCurrentUser(); + return ds.createEntityUsingRelation(parameterTableRelation, user); + } + + protected static final T retrieveEntity(T parameterTableRelation, FormServiceCursor fsc, CallingContext cc) throws ODKDatastoreException { + Datastore ds = cc.getDatastore(); + User user = cc.getCurrentUser(); + return ds.getEntity(parameterTableRelation, fsc.getAuriService(), user); + } + + protected abstract String getOwnership(); + + protected abstract CommonFieldsBase retrieveObjectEntity(); + + protected abstract List retrieveRepeatElementEntities(); + + protected abstract void insertData(Submission submission, CallingContext cc) throws ODKExternalServiceException; + + @Override + public boolean canBatchSubmissions() { + return false; + } + + @Override + public void sendSubmissions(List submissions, boolean streaming, CallingContext cc) throws ODKExternalServiceException { + throw new ODKExternalServiceException(NO_BATCH_FUNCTIONALITY_ERROR); + } + + @Override + public void sendSubmission(Submission submission, CallingContext cc) throws ODKExternalServiceException { + insertData(submission, cc); + } + + @Override + public void setUploadCompleted(CallingContext cc) throws ODKEntityPersistException, ODKOverQuotaException { + fsc.setUploadCompleted(true); + if (fsc.getExternalServicePublicationOption() == ExternalServicePublicationOption.UPLOAD_ONLY) { + fsc.setOperationalStatus(OperationalStatus.COMPLETED); + } + Datastore ds = cc.getDatastore(); + User user = cc.getCurrentUser(); + ds.putEntity(fsc, user); + } + + protected HttpResponse sendHttpRequest(String method, String url, HttpEntity entity, List qparams, CallingContext cc) throws + IOException { + + // setup client + HttpClientFactory factory = (HttpClientFactory) cc.getBean(BeanDefs.HTTP_CLIENT_FACTORY); + + SocketConfig socketConfig = SocketConfig.copy(SocketConfig.DEFAULT) + .setSoTimeout(SOCKET_ESTABLISHMENT_TIMEOUT_MILLISECONDS) + .build(); + RequestConfig requestConfig = RequestConfig.copy(RequestConfig.DEFAULT) + .setConnectTimeout(SERVICE_TIMEOUT_MILLISECONDS) + .setRedirectsEnabled(true) + .setAuthenticationEnabled(true) + .setMaxRedirects(32) + .setCircularRedirectsAllowed(true) + .build(); + + HttpClient client = factory.createHttpClient(socketConfig, null, requestConfig); + + // context holds authentication state machine, so it cannot be + // shared across independent activities. + HttpContext localContext = new BasicHttpContext(); + + localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore); + localContext.setAttribute(HttpClientContext.CREDS_PROVIDER, credsProvider); + + HttpUriRequest request = null; + if (entity == null && (POST.equals(method) || PATCH.equals(method) || PUT.equals(method))) { + throw new IllegalStateException("No body supplied for POST, PATCH or PUT request"); + } else if (entity != null && !(POST.equals(method) || PATCH.equals(method) || PUT.equals(method))) { + throw new IllegalStateException("Body was supplied for GET or DELETE request"); + } + + URI nakedUri; + try { + nakedUri = new URI(url); + } catch (Exception e) { + e.printStackTrace(); + throw new IllegalStateException(e); + } + + if (qparams == null) { + qparams = new ArrayList(); + } + URI uri; + try { + uri = new URI(nakedUri.getScheme(), nakedUri.getUserInfo(), nakedUri.getHost(), + nakedUri.getPort(), nakedUri.getPath(), URLEncodedUtils.format(qparams, HtmlConsts.UTF8_ENCODE), null); + } catch (URISyntaxException e1) { + e1.printStackTrace(); + throw new IllegalStateException(e1); + } + System.out.println(uri.toString()); + + if (GET.equals(method)) { + HttpGet get = new HttpGet(uri); + request = get; + } else if (DELETE.equals(method)) { + HttpDelete delete = new HttpDelete(uri); + request = delete; + } else if (PATCH.equals(method)) { + HttpPatch patch = new HttpPatch(uri); + patch.setEntity(entity); + request = patch; + } else if (POST.equals(method)) { + HttpPost post = new HttpPost(uri); + post.setEntity(entity); + request = post; + } else if (PUT.equals(method)) { + HttpPut put = new HttpPut(uri); + put.setEntity(entity); + request = put; + } else { + throw new IllegalStateException("Unexpected request method"); + } + + HttpResponse resp = client.execute(request); + return resp; + } + + @Override + public void delete(CallingContext cc) throws ODKDatastoreException { + CommonFieldsBase serviceEntity = retrieveObjectEntity(); + List repeats = retrieveRepeatElementEntities(); + + Datastore ds = cc.getDatastore(); + User user = cc.getCurrentUser(); + + if (repeats != null) { + List keys = new ArrayList(); + for (CommonFieldsBase repeat : repeats) { + keys.add(repeat.getEntityKey()); + } + DeleteHelper.deleteEntities(keys, cc); + repeats.clear(); + } + + ds.deleteEntity(serviceEntity.getEntityKey(), user); + ds.deleteEntity(fsc.getEntityKey(), user); + } + + @Override + public void persist(CallingContext cc) throws ODKEntityPersistException, ODKOverQuotaException { + Datastore ds = cc.getDatastore(); + User user = cc.getCurrentUser(); + + CommonFieldsBase serviceEntity = retrieveObjectEntity(); + List repeats = retrieveRepeatElementEntities(); + + if (repeats != null) { + ds.putEntities(repeats, user); + } + ds.putEntity(serviceEntity, user); + ds.putEntity(fsc, user); + } + + @Override + public FormServiceCursor getFormServiceCursor() { + return fsc; + } + + @Override + public ExternServSummary transform() { + return new ExternServSummary(fsc.getUri(), + fsc.getCreatorUriUser(), + fsc.getOperationalStatus(), + fsc.getEstablishmentDateTime(), + fsc.getExternalServicePublicationOption(), + fsc.getUploadCompleted(), + fsc.getLastUploadCursorDate(), + fsc.getLastStreamingCursorDate(), + fsc.getExternalServiceType(), + getOwnership(), + getDescriptiveTargetString()); + } + + @Override + public int hashCode() { + int hashCode = 13; + if (retrieveObjectEntity() != null) + hashCode += retrieveObjectEntity().hashCode(); + if (fsc != null) + hashCode += fsc.hashCode(); + return hashCode; + } + + protected void postUploadTask(CallingContext cc) throws ODKExternalServiceException { + // upload data to external service + if (!fsc.getExternalServicePublicationOption().equals( + ExternalServicePublicationOption.STREAM_ONLY)) { + + UploadSubmissions uploadTask = (UploadSubmissions) cc.getBean(BeanDefs.UPLOAD_TASK_BEAN); + CallingContext ccDaemon = ContextFactory.duplicateContext(cc); + ccDaemon.setAsDaemon(true); + uploadTask.createFormUploadTask(fsc, ccDaemon); + } + } + +} diff --git a/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java b/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java index e96c2e8855..88762e27f2 100644 --- a/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java +++ b/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java @@ -68,7 +68,7 @@ private ServerPreferencesProperties(ServerPreferencesProperties ref, User user) public static PreferenceSummary getPreferenceSummary(CallingContext cc) throws ODKEntityNotFoundException, ODKOverQuotaException { return new PreferenceSummary(getGoogleSimpleApiKey(cc), getGoogleApiClientId(cc), - getEnketoApiUrl(cc), getEnketoApiToken(cc), true, getSkipMalformedSubmissions(cc)); + getEnketoApiUrl(cc), getEnketoApiToken(cc), getSkipMalformedSubmissions(cc)); } public static String getSiteKey(CallingContext cc) throws ODKEntityNotFoundException, ODKOverQuotaException { diff --git a/src/main/java/org/opendatakit/aggregate/servlet/SubmissionServlet.java b/src/main/java/org/opendatakit/aggregate/servlet/SubmissionServlet.java index c51c401574..d6563fc878 100644 --- a/src/main/java/org/opendatakit/aggregate/servlet/SubmissionServlet.java +++ b/src/main/java/org/opendatakit/aggregate/servlet/SubmissionServlet.java @@ -37,7 +37,6 @@ import org.opendatakit.aggregate.constants.common.OperationalStatus; import org.opendatakit.aggregate.constants.common.UIConsts; import org.opendatakit.aggregate.exception.ODKConversionException; -import org.opendatakit.aggregate.exception.ODKExternalServiceException; import org.opendatakit.aggregate.exception.ODKFormNotFoundException; import org.opendatakit.aggregate.exception.ODKFormSubmissionsDisabledException; import org.opendatakit.aggregate.exception.ODKIncompleteSubmissionData; @@ -249,7 +248,7 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOEx for (ExternalService rs : tmp) { // only create upload tasks for active publishers if (rs.getFormServiceCursor().getOperationalStatus() == OperationalStatus.ACTIVE) { - uploadTask.createFormUploadTask(rs.getFormServiceCursor(), false, ccDaemon); + uploadTask.createFormUploadTask(rs.getFormServiceCursor(), ccDaemon); } } } diff --git a/src/main/java/org/opendatakit/aggregate/task/UploadSubmissions.java b/src/main/java/org/opendatakit/aggregate/task/UploadSubmissions.java index 3922e135c7..f11ab767e4 100644 --- a/src/main/java/org/opendatakit/aggregate/task/UploadSubmissions.java +++ b/src/main/java/org/opendatakit/aggregate/task/UploadSubmissions.java @@ -27,7 +27,7 @@ public class UploadSubmissions { private static final Logger logger = LoggerFactory.getLogger(UploadSubmissions.class); - public void createFormUploadTask(FormServiceCursor fsc, boolean onBackground, CallingContext cc) { + public void createFormUploadTask(FormServiceCursor fsc, CallingContext cc) { Watchdog wd = (Watchdog) cc.getBean(BeanDefs.WATCHDOG); UploadSubmissionsWorkerImpl worker = new UploadSubmissionsWorkerImpl(fsc, wd.getFasterWatchdogCycleEnabled(), wd.getCallingContext()); AggregrateThreadExecutor.getAggregateThreadExecutor().execute(() -> { diff --git a/src/main/java/org/opendatakit/aggregate/task/UploadSubmissionsWorkerImpl.java b/src/main/java/org/opendatakit/aggregate/task/UploadSubmissionsWorkerImpl.java index bccb1e25a3..315002c55b 100644 --- a/src/main/java/org/opendatakit/aggregate/task/UploadSubmissionsWorkerImpl.java +++ b/src/main/java/org/opendatakit/aggregate/task/UploadSubmissionsWorkerImpl.java @@ -204,7 +204,7 @@ public void uploadAllSubmissions() throws ODKEntityNotFoundException, ODKExterna if (reQueue) { // create another task to continue upload UploadSubmissions uploadSubmissionsBean = (UploadSubmissions) cc.getBean(BeanDefs.UPLOAD_TASK_BEAN); - uploadSubmissionsBean.createFormUploadTask(formServiceCursor, false, cc); + uploadSubmissionsBean.createFormUploadTask(formServiceCursor, cc); } } diff --git a/src/main/java/org/opendatakit/aggregate/task/Watchdog.java b/src/main/java/org/opendatakit/aggregate/task/Watchdog.java index 1c424b08e8..620776c137 100644 --- a/src/main/java/org/opendatakit/aggregate/task/Watchdog.java +++ b/src/main/java/org/opendatakit/aggregate/task/Watchdog.java @@ -319,12 +319,8 @@ private void establishWatchdog(boolean fasterWatchdogCycleEnabled) { } public boolean getFasterWatchdogCycleEnabled() { - CallingContext cc = getCallingContext(); - if (System.currentTimeMillis() > - BackendActionsTable.FAST_PUBLISHING_RETRY_MILLISECONDS + - lastFasterWatchdogCycleEnabledFlagFetch) { + if (System.currentTimeMillis() > BackendActionsTable.FAST_PUBLISHING_RETRY_MILLISECONDS + lastFasterWatchdogCycleEnabledFlagFetch) setFasterWatchdogCycleEnabled(false); - } return lastFasterWatchdogCycleEnabledFlag; } diff --git a/src/main/java/org/opendatakit/aggregate/task/WatchdogWorkerImpl.java b/src/main/java/org/opendatakit/aggregate/task/WatchdogWorkerImpl.java index aecbdab529..c89ce5f360 100644 --- a/src/main/java/org/opendatakit/aggregate/task/WatchdogWorkerImpl.java +++ b/src/main/java/org/opendatakit/aggregate/task/WatchdogWorkerImpl.java @@ -120,7 +120,7 @@ public void checkTasks(CallingContext cc) throws ODKExternalServiceException, OD } finally { // NOTE: if the above threw an exception, we re-start the watchdog. // otherwise, we restart it only if there is work to be done. - BackendActionsTable.rescheduleWatchdog(activeTasks, cullThisWatchdog, cc); + BackendActionsTable.rescheduleWatchdog(activeTasks, cc); logger.info("---------------------END Watchdog"); } } @@ -215,7 +215,7 @@ private boolean checkUpload(FormServiceCursor fsc, UploadSubmissions uploadSubmi || lastUploadDate.compareTo(establishmentDate) < 0) { // there is still work to do activeTask = true; - uploadSubmissions.createFormUploadTask(fsc, true, cc); + uploadSubmissions.createFormUploadTask(fsc, cc); } } return activeTask; @@ -264,7 +264,7 @@ private boolean checkStreaming(FormServiceCursor fsc, UploadSubmissions uploadSu if (makeActive) { // there is work to do - uploadSubmissions.createFormUploadTask(fsc, false, cc); + uploadSubmissions.createFormUploadTask(fsc, cc); return true; } diff --git a/src/main/java/org/opendatakit/aggregate/task/WorksheetCreatorWorkerImpl.java b/src/main/java/org/opendatakit/aggregate/task/WorksheetCreatorWorkerImpl.java index 475f18c730..63f3e68b13 100644 --- a/src/main/java/org/opendatakit/aggregate/task/WorksheetCreatorWorkerImpl.java +++ b/src/main/java/org/opendatakit/aggregate/task/WorksheetCreatorWorkerImpl.java @@ -200,7 +200,7 @@ public final void doWorksheetCreator() { // if we need to upload submissions, start a task to do so UploadSubmissions us = (UploadSubmissions) cc.getBean(BeanDefs.UPLOAD_TASK_BEAN); if (!esType.equals(ExternalServicePublicationOption.STREAM_ONLY)) { - us.createFormUploadTask(spreadsheet.getFormServiceCursor(), true, cc); + us.createFormUploadTask(spreadsheet.getFormServiceCursor(), cc); } doMarkAsComplete(r); diff --git a/src/main/java/org/opendatakit/aggregate/util/BackendActionsTable.java b/src/main/java/org/opendatakit/aggregate/util/BackendActionsTable.java index f64f791e76..263eef406a 100644 --- a/src/main/java/org/opendatakit/aggregate/util/BackendActionsTable.java +++ b/src/main/java/org/opendatakit/aggregate/util/BackendActionsTable.java @@ -452,8 +452,7 @@ public static synchronized void triggerWatchdog(CallingContext cc) { * effect, but is a suggested next start time, and only if the website is * active will it be honored. */ - public static synchronized void rescheduleWatchdog(boolean hasActiveTasks, - boolean cullThisWatchdog, CallingContext cc) { + public static synchronized void rescheduleWatchdog(boolean hasActiveTasks, CallingContext cc) { Watchdog wd = (Watchdog) cc.getBean(BeanDefs.WATCHDOG); From 6d07bea77c31fc76a8ee549e00d73d4df5dd3e50 Mon Sep 17 00:00:00 2001 From: Guille Date: Fri, 11 Jan 2019 09:10:55 +0100 Subject: [PATCH 6/7] Delete the setter methods from the prefs service --- .../client/preferences/PreferenceService.java | 76 +++++++++---------- .../preferences/PreferenceServiceAsync.java | 56 +++++++------- .../server/PreferenceServiceImpl.java | 29 ------- .../server/ServerPreferencesProperties.java | 4 - 4 files changed, 63 insertions(+), 102 deletions(-) diff --git a/src/main/java/org/opendatakit/aggregate/client/preferences/PreferenceService.java b/src/main/java/org/opendatakit/aggregate/client/preferences/PreferenceService.java index 07ab8c3ad4..97c6d2534a 100644 --- a/src/main/java/org/opendatakit/aggregate/client/preferences/PreferenceService.java +++ b/src/main/java/org/opendatakit/aggregate/client/preferences/PreferenceService.java @@ -1,40 +1,36 @@ -/* - * Copyright (C) 2011 University of Washington - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package org.opendatakit.aggregate.client.preferences; - -import com.google.gwt.user.client.rpc.RemoteService; -import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; -import com.google.gwt.user.server.rpc.XsrfProtect; -import org.opendatakit.aggregate.client.exception.RequestFailureException; - -/** - * These actions require the ROLE_USER privilege, which is the least capable - * privilege (granted to all authorized users of the system). - * - * @author wbrunette@gmail.com - */ -@RemoteServiceRelativePath("preferenceservice") -public interface PreferenceService extends RemoteService { - PreferenceSummary getPreferences() throws RequestFailureException; - - @XsrfProtect - void setSkipMalformedSubmissions(Boolean skipMalformedSubmissions) throws RequestFailureException; - - @XsrfProtect - void setFasterBackgroundActionsDisabled(Boolean disabled) throws RequestFailureException; - -} +/* + * Copyright (C) 2011 University of Washington + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opendatakit.aggregate.client.preferences; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; +import com.google.gwt.user.server.rpc.XsrfProtect; +import org.opendatakit.aggregate.client.exception.RequestFailureException; + +/** + * These actions require the ROLE_USER privilege, which is the least capable + * privilege (granted to all authorized users of the system). + * + * @author wbrunette@gmail.com + */ +@RemoteServiceRelativePath("preferenceservice") +public interface PreferenceService extends RemoteService { + PreferenceSummary getPreferences() throws RequestFailureException; + + @XsrfProtect + void setSkipMalformedSubmissions(Boolean skipMalformedSubmissions) throws RequestFailureException; +} diff --git a/src/main/java/org/opendatakit/aggregate/client/preferences/PreferenceServiceAsync.java b/src/main/java/org/opendatakit/aggregate/client/preferences/PreferenceServiceAsync.java index 4e6b47ad49..4971be5525 100644 --- a/src/main/java/org/opendatakit/aggregate/client/preferences/PreferenceServiceAsync.java +++ b/src/main/java/org/opendatakit/aggregate/client/preferences/PreferenceServiceAsync.java @@ -1,29 +1,27 @@ -/* - * Copyright (C) 2011 University of Washington - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package org.opendatakit.aggregate.client.preferences; - -import com.google.gwt.user.client.rpc.AsyncCallback; - -public interface PreferenceServiceAsync { - - void getPreferences(AsyncCallback callback); - - void setFasterBackgroundActionsDisabled(Boolean disabled, AsyncCallback callback); - - void setSkipMalformedSubmissions(Boolean skipMalformedSubmissions, AsyncCallback callback); - -} +/* + * Copyright (C) 2011 University of Washington + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opendatakit.aggregate.client.preferences; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +public interface PreferenceServiceAsync { + + void getPreferences(AsyncCallback callback); + + void setSkipMalformedSubmissions(Boolean skipMalformedSubmissions, AsyncCallback callback); + +} diff --git a/src/main/java/org/opendatakit/aggregate/server/PreferenceServiceImpl.java b/src/main/java/org/opendatakit/aggregate/server/PreferenceServiceImpl.java index 06ddf23bab..bd07da50e0 100644 --- a/src/main/java/org/opendatakit/aggregate/server/PreferenceServiceImpl.java +++ b/src/main/java/org/opendatakit/aggregate/server/PreferenceServiceImpl.java @@ -21,9 +21,7 @@ import org.opendatakit.aggregate.ContextFactory; import org.opendatakit.aggregate.client.exception.RequestFailureException; import org.opendatakit.aggregate.client.preferences.PreferenceSummary; -import org.opendatakit.aggregate.constants.BeanDefs; import org.opendatakit.aggregate.constants.ErrorConsts; -import org.opendatakit.aggregate.task.Watchdog; import org.opendatakit.common.persistence.exception.ODKEntityNotFoundException; import org.opendatakit.common.persistence.exception.ODKOverQuotaException; import org.opendatakit.common.web.CallingContext; @@ -55,33 +53,6 @@ public PreferenceSummary getPreferences() throws RequestFailureException { } } - @Override - public void setFasterBackgroundActionsDisabled(Boolean disabled) throws - RequestFailureException { - HttpServletRequest req = this.getThreadLocalRequest(); - CallingContext cc = ContextFactory.getCallingContext(this, req); - - try { - ServerPreferencesProperties.setFasterBackgroundActionsDisabled(cc, disabled); - - log.info("setFasterBackgroundActionsDisabled as: " + Boolean.toString(disabled)); - Watchdog wd = (Watchdog) cc.getBean(BeanDefs.WATCHDOG); - // NOTE: this will fire off a watchdog worker - // if we are re-enabling faster publishing - // - // No-op if not changed. - wd.setFasterWatchdogCycleEnabled(!disabled); - - } catch (ODKEntityNotFoundException e) { - e.printStackTrace(); - throw new RequestFailureException(e); - } catch (ODKOverQuotaException e) { - e.printStackTrace(); - throw new RequestFailureException(ErrorConsts.QUOTA_EXCEEDED); - } - - } - @Override public void setSkipMalformedSubmissions(Boolean skipMalformedSubmissions) throws RequestFailureException { diff --git a/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java b/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java index 88762e27f2..6f7cd7bf40 100644 --- a/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java +++ b/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java @@ -139,10 +139,6 @@ public static void setFasterWatchdogCycleEnabled(CallingContext cc, Boolean enab setServerPreferencesProperty(cc, FASTER_WATCHDOG_CYCLE_ENABLED, enabled.toString()); } - public static void setFasterBackgroundActionsDisabled(CallingContext cc, Boolean disabled) throws ODKEntityNotFoundException, ODKOverQuotaException { - setServerPreferencesProperty(cc, FASTER_BACKGROUND_ACTIONS_DISABLED, disabled.toString()); - } - public static Boolean getSkipMalformedSubmissions(CallingContext cc) throws ODKEntityNotFoundException, ODKOverQuotaException { String value = getServerPreferencesProperty(cc, SKIP_MALFORMED_SUBMISSIONS); if (value != null) { From 0f411dab95598d0ae6dc55696d56f99eef5d95fb Mon Sep 17 00:00:00 2001 From: Guille Date: Fri, 11 Jan 2019 09:18:02 +0100 Subject: [PATCH 7/7] Extra cleanup of related constants and enum values no longer needed --- .../constants/common/PreferencesConsts.java | 80 +++++++++---------- .../server/ServerPreferencesProperties.java | 1 - 2 files changed, 38 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/opendatakit/aggregate/constants/common/PreferencesConsts.java b/src/main/java/org/opendatakit/aggregate/constants/common/PreferencesConsts.java index 9aefc6a65f..020916aa4d 100644 --- a/src/main/java/org/opendatakit/aggregate/constants/common/PreferencesConsts.java +++ b/src/main/java/org/opendatakit/aggregate/constants/common/PreferencesConsts.java @@ -1,42 +1,38 @@ -/* - * Copyright (C) 2011 University of Washington - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package org.opendatakit.aggregate.constants.common; - - -public enum PreferencesConsts implements HelpSliderConsts { - GOOGLE("Google API Credentials", "These credentials are used when publishing into Google services."), - ENKETO("Enketo Credentials", "These credentials are used for Enketo webforms integration."), - FEATURES("Aggregate Features", - "These settings affect the operations of the server.
" + - "1. Disable faster background actions - check this to reduce AppEngine quota usage"); - - private String title; - private String content; - - private PreferencesConsts(String titleString, String contentString) { - title = titleString; - content = contentString; - } - - public String getTitle() { - return title; - } - - public String getContent() { - return content; - } -} \ No newline at end of file +/* + * Copyright (C) 2011 University of Washington + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.opendatakit.aggregate.constants.common; + + +public enum PreferencesConsts implements HelpSliderConsts { + GOOGLE("Google API Credentials", "These credentials are used when publishing into Google services."), + ENKETO("Enketo Credentials", "These credentials are used for Enketo webforms integration."); + private String title; + private String content; + + private PreferencesConsts(String titleString, String contentString) { + title = titleString; + content = contentString; + } + + public String getTitle() { + return title; + } + + public String getContent() { + return content; + } +} diff --git a/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java b/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java index 6f7cd7bf40..10b53e4719 100644 --- a/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java +++ b/src/main/java/org/opendatakit/aggregate/server/ServerPreferencesProperties.java @@ -51,7 +51,6 @@ public class ServerPreferencesProperties extends CommonFieldsBase { private static final String SITE_KEY = "SITE_KEY"; private static final String LAST_KNOWN_REALM_STRING = "LAST_KNOWN_REALM_STRING"; private static final String FASTER_WATCHDOG_CYCLE_ENABLED = "FASTER_WATCHDOG_CYCLE_ENABLED"; - private static final String FASTER_BACKGROUND_ACTIONS_DISABLED = "FASTER_BACKGROUND_ACTIONS_DISABLED"; private static final String SKIP_MALFORMED_SUBMISSIONS = "SKIP_MALFORMED_SUBMISSIONS"; private static ServerPreferencesProperties relation = null;