use of net.osmand.OperationLog in project Osmand by osmandapp.
the class BackupImporter method importItems.
void importItems(@NonNull List<SettingsItem> items, boolean forceReadData) throws IllegalArgumentException {
if (Algorithms.isEmpty(items)) {
throw new IllegalArgumentException("No items");
}
Collection<RemoteFile> remoteFiles = backupHelper.getBackup().getRemoteFiles(RemoteFilesType.UNIQUE).values();
if (Algorithms.isEmpty(remoteFiles)) {
throw new IllegalArgumentException("No remote files");
}
OperationLog operationLog = new OperationLog("importItems", BackupHelper.DEBUG);
operationLog.startOperation();
List<ItemFileImportTask> tasks = new ArrayList<>();
Map<RemoteFile, SettingsItem> remoteFileItems = new HashMap<>();
for (RemoteFile remoteFile : remoteFiles) {
SettingsItem item = null;
for (SettingsItem settingsItem : items) {
String fileName = remoteFile.item != null ? remoteFile.item.getFileName() : null;
if (fileName != null && settingsItem.applyFileName(fileName)) {
item = settingsItem;
remoteFileItems.put(remoteFile, item);
break;
}
}
if (item != null && (!item.shouldReadOnCollecting() || forceReadData)) {
tasks.add(new ItemFileImportTask(remoteFile, item, forceReadData));
}
}
ThreadPoolTaskExecutor<ItemFileImportTask> executor = createExecutor();
executor.run(tasks);
for (Entry<RemoteFile, SettingsItem> fileItem : remoteFileItems.entrySet()) {
fileItem.getValue().setLocalModifiedTime(fileItem.getKey().getClienttimems());
}
operationLog.finishOperation();
}
use of net.osmand.OperationLog in project Osmand by osmandapp.
the class BackupHelper method updateOrderId.
void updateOrderId(@Nullable OnUpdateSubscriptionListener listener) {
Map<String, String> params = new HashMap<>();
params.put("email", getEmail());
String orderId = getOrderId();
if (Algorithms.isEmpty(orderId)) {
if (listener != null) {
String message = "Order id is empty";
String error = "{\"error\":{\"errorCode\":" + STATUS_NO_ORDER_ID_ERROR + ",\"message\":\"" + message + "\"}}";
listener.onUpdateSubscription(STATUS_NO_ORDER_ID_ERROR, message, error);
}
return;
} else {
params.put("orderid", orderId);
}
String androidId = getAndroidId();
if (!Algorithms.isEmpty(androidId)) {
params.put("deviceid", androidId);
}
OperationLog operationLog = new OperationLog("updateOrderId", DEBUG);
AndroidNetworkUtils.sendRequest(app, UPDATE_ORDER_ID_URL, params, "Update order id", false, true, (resultJson, error, resultCode) -> {
int status;
String message;
if (!Algorithms.isEmpty(error)) {
message = "Update order id error: " + new BackupError(error);
status = STATUS_SERVER_ERROR;
} else if (!Algorithms.isEmpty(resultJson)) {
try {
JSONObject result = new JSONObject(resultJson);
if (result.has("status") && "ok".equals(result.getString("status"))) {
message = "Order id have been updated successfully";
status = STATUS_SUCCESS;
} else {
message = "Update order id error: unknown";
status = STATUS_SERVER_ERROR;
}
} catch (JSONException e) {
message = "Update order id error: json parsing";
status = STATUS_PARSE_JSON_ERROR;
}
} else {
message = "Update order id error: empty response";
status = STATUS_EMPTY_RESPONSE_ERROR;
}
if (listener != null) {
listener.onUpdateSubscription(status, message, error);
}
operationLog.finishOperation(status + " " + message);
});
}
use of net.osmand.OperationLog in project Osmand by osmandapp.
the class RegisterDeviceCommand method doInBackground.
@Override
protected Object doInBackground(Object... objects) {
Map<String, String> params = new HashMap<>();
BackupHelper helper = getHelper();
params.put("email", helper.getEmail());
String orderId = helper.getOrderId();
if (orderId != null) {
params.put("orderid", orderId);
}
String androidId = helper.getAndroidId();
if (!Algorithms.isEmpty(androidId)) {
params.put("deviceid", androidId);
}
params.put("token", token);
OperationLog operationLog = createOperationLog("registerDevice");
AndroidNetworkUtils.sendRequest(getApp(), DEVICE_REGISTER_URL, params, "Register device", false, true, (resultJson, error, resultCode) -> {
int status;
String message;
BackupError backupError = null;
if (resultCode != null && isTemporallyUnavailableErrorCode(resultCode)) {
message = "Device registration error code: " + resultCode;
error = "{\"error\":{\"errorCode\":" + STATUS_SERVER_TEMPORALLY_UNAVAILABLE_ERROR + ",\"message\":\"" + message + "\"}}";
}
if (!Algorithms.isEmpty(error)) {
backupError = new BackupError(error);
message = "Device registration error: " + backupError;
status = STATUS_SERVER_ERROR;
} else if (!Algorithms.isEmpty(resultJson)) {
OsmandSettings settings = getApp().getSettings();
try {
JSONObject result = new JSONObject(resultJson);
settings.BACKUP_DEVICE_ID.set(result.getString("id"));
settings.BACKUP_USER_ID.set(result.getString("userid"));
settings.BACKUP_NATIVE_DEVICE_ID.set(result.getString("deviceid"));
settings.BACKUP_ACCESS_TOKEN.set(result.getString("accesstoken"));
settings.BACKUP_ACCESS_TOKEN_UPDATE_TIME.set(result.getString("udpatetime"));
message = "Device have been registered successfully";
status = STATUS_SUCCESS;
} catch (JSONException e) {
message = "Device registration error: json parsing";
status = STATUS_PARSE_JSON_ERROR;
}
} else {
message = "Device registration error: empty response";
status = STATUS_EMPTY_RESPONSE_ERROR;
}
publishProgress(status, message, backupError);
operationLog.finishOperation(status + " " + message);
});
return null;
}
Aggregations