use of com.google.gson.reflect.TypeToken in project zeppelin by apache.
the class NotebookServer method runAllParagraphs.
private void runAllParagraphs(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
final String noteId = (String) fromMessage.get("noteId");
if (StringUtils.isBlank(noteId)) {
return;
}
if (!hasParagraphWriterPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "run all paragraphs")) {
return;
}
List<Map<String, Object>> paragraphs = gson.fromJson(String.valueOf(fromMessage.data.get("paragraphs")), new TypeToken<List<Map<String, Object>>>() {
}.getType());
for (Map<String, Object> raw : paragraphs) {
String paragraphId = (String) raw.get("id");
if (paragraphId == null) {
continue;
}
String text = (String) raw.get("paragraph");
String title = (String) raw.get("title");
Map<String, Object> params = (Map<String, Object>) raw.get("params");
Map<String, Object> config = (Map<String, Object>) raw.get("config");
Note note = notebook.getNote(noteId);
Paragraph p = setParagraphUsingMessage(note, fromMessage, paragraphId, text, title, params, config);
persistAndExecuteSingleParagraph(conn, note, p);
}
}
use of com.google.gson.reflect.TypeToken in project cryptomator by cryptomator.
the class WelcomeController method checkForUpdates.
private void checkForUpdates() {
checkForUpdatesStatus.setText(localization.getString("welcome.checkForUpdates.label.currentlyChecking"));
checkForUpdatesIndicator.setVisible(true);
asyncTaskService.asyncTaskOf(() -> {
RequestConfig requestConfig = //
RequestConfig.custom().setConnectTimeout(//
5000).setConnectionRequestTimeout(//
5000).setSocketTimeout(//
5000).build();
HttpClientBuilder httpClientBuilder = //
HttpClients.custom().disableCookieManagement().setDefaultRequestConfig(//
requestConfig).setUserAgent("Cryptomator VersionChecker/" + ApplicationVersion.orElse("SNAPSHOT"));
LOG.debug("Checking for updates...");
try (CloseableHttpClient client = httpClientBuilder.build()) {
HttpGet request = new HttpGet("https://cryptomator.org/downloads/latestVersion.json");
try (CloseableHttpResponse response = client.execute(request)) {
if (response.getStatusLine().getStatusCode() == 200 && response.getEntity() != null) {
try (InputStream in = response.getEntity().getContent()) {
Gson gson = new GsonBuilder().setLenient().create();
Reader utf8Reader = new InputStreamReader(in, StandardCharsets.UTF_8);
Map<String, String> map = gson.fromJson(utf8Reader, new TypeToken<Map<String, String>>() {
}.getType());
if (map != null) {
this.compareVersions(map);
}
}
}
}
}
}).andFinally(() -> {
checkForUpdatesStatus.setText("");
checkForUpdatesIndicator.setVisible(false);
}).run();
}
use of com.google.gson.reflect.TypeToken in project sharding-jdbc by dangdangdotcom.
the class RdbTransactionLogStorage method findEligibleTransactionLogs.
@Override
public List<TransactionLog> findEligibleTransactionLogs(final int size, final int maxDeliveryTryTimes, final long maxDeliveryTryDelayMillis) {
List<TransactionLog> result = new ArrayList<>(size);
String sql = "SELECT `id`, `transaction_type`, `data_source`, `sql`, `parameters`, `creation_time`, `async_delivery_try_times` " + "FROM `transaction_log` WHERE `async_delivery_try_times`<? AND `transaction_type`=? AND `creation_time`<? LIMIT ?;";
try (Connection conn = dataSource.getConnection()) {
try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
preparedStatement.setInt(1, maxDeliveryTryTimes);
preparedStatement.setString(2, SoftTransactionType.BestEffortsDelivery.name());
preparedStatement.setLong(3, System.currentTimeMillis() - maxDeliveryTryDelayMillis);
preparedStatement.setInt(4, size);
try (ResultSet rs = preparedStatement.executeQuery()) {
while (rs.next()) {
Gson gson = new Gson();
//TODO 对于批量执行的参数需要解析成两层列表
List<Object> parameters = gson.fromJson(rs.getString(5), new TypeToken<List<Object>>() {
}.getType());
result.add(new TransactionLog(rs.getString(1), "", SoftTransactionType.valueOf(rs.getString(2)), rs.getString(3), rs.getString(4), parameters, rs.getLong(6), rs.getInt(7)));
}
}
}
} catch (final SQLException ex) {
throw new TransactionLogStorageException(ex);
}
return result;
}
use of com.google.gson.reflect.TypeToken in project SmartCity-Market by TechnionYP5777.
the class Manager method getAllWorkers.
@Override
public HashMap<String, Boolean> getAllWorkers() throws CriticalError, EmployeeNotConnected, ConnectionFailure {
log.info("Creating getAllWorkers command wrapper");
String serverResponse = sendRequestWithRespondToServer((new CommandWrapper(getClientId(), CommandDescriptor.GET_ALL_WORKERS, Serialization.serialize(""))).serialize());
CommandWrapper commandDescriptor = getCommandWrapper(serverResponse);
try {
resultDescriptorHandler(commandDescriptor.getResultDescriptor());
} catch (InvalidCommandDescriptor | EmployeeAlreadyConnected | AuthenticationError | ProductStillForSale | AmountBiggerThanAvailable | ProductPackageDoesNotExist | ProductAlreadyExistInCatalog | ProductNotExistInCatalog | WorkerAlreadyExists | ParamIDAlreadyExists | ParamIDDoesNotExist | WorkerDoesNotExist | IngredientStillInUse | ManfacturerStillInUse | InvalidParameter ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
log.info("getAllWorkers command succeed.");
return new Gson().fromJson(commandDescriptor.getData(), new TypeToken<HashMap<String, Boolean>>() {
}.getType());
}
use of com.google.gson.reflect.TypeToken in project selenium-tests by Wikia.
the class GraphApi method createFacebookTestUser.
public HashMap<String, String> createFacebookTestUser(String appId) {
try {
HttpResponse response = createTestUser(appId);
String entity = EntityUtils.toString(response.getEntity());
return new Gson().fromJson(entity, new TypeToken<HashMap<String, String>>() {
}.getType());
} catch (IOException e) {
PageObjectLogging.log(URI_SYNTAX_EXCEPTION, ExceptionUtils.getStackTrace(e), false);
throw new WebDriverException(ERROR_MESSAGE);
} catch (URISyntaxException e) {
PageObjectLogging.log(URI_SYNTAX_EXCEPTION, ExceptionUtils.getStackTrace(e), false);
throw new WebDriverException(ERROR_MESSAGE);
}
}
Aggregations