List of usage examples for com.google.gson JsonObject has
public boolean has(String memberName)
From source file:com.github.sommeri.sourcemap.SourceMapConsumerV3.java
License:Apache License
/** * @param sourceMapRoot/*from w w w . ja v a 2 s.c o m*/ * @throws SourceMapParseException */ private void parseMetaMap(JsonObject sourceMapRoot, SourceMapSupplier sectionSupplier) throws SourceMapParseException { if (sectionSupplier == null) { sectionSupplier = new DefaultSourceMapSupplier(); } try { // Check basic assertions about the format. int version = sourceMapRoot.get("version").getAsInt(); if (version != 3) { throw new SourceMapParseException("Unknown version: " + version); } String file = sourceMapRoot.get("file").getAsString(); if (file.isEmpty()) { throw new SourceMapParseException("File entry is missing or empty"); } if (sourceMapRoot.has("lineCount") || sourceMapRoot.has("mappings") || sourceMapRoot.has("sources") || sourceMapRoot.has("names")) { throw new SourceMapParseException("Invalid map format"); } SourceMapGeneratorV3 generator = new SourceMapGeneratorV3(); JsonArray sections = sourceMapRoot.get("sections").getAsJsonArray(); for (int i = 0, count = sections.size(); i < count; i++) { JsonObject section = sections.get(i).getAsJsonObject(); if (section.has("map") && section.has("url")) { throw new SourceMapParseException( "Invalid map format: section may not have both 'map' and 'url'"); } JsonObject offset = section.get("offset").getAsJsonObject(); int line = offset.get("line").getAsInt(); int column = offset.get("column").getAsInt(); String mapSectionContents; if (section.has("url")) { String url = section.get("url").getAsString(); mapSectionContents = sectionSupplier.getSourceMap(url); if (mapSectionContents == null) { throw new SourceMapParseException("Unable to retrieve: " + url); } } else if (section.has("map")) { mapSectionContents = section.get("map").getAsString(); } else { throw new SourceMapParseException( "Invalid map format: section must have either 'map' or 'url'"); } generator.mergeMapSection(line, column, mapSectionContents); } StringBuilder sb = new StringBuilder(); try { generator.appendTo(sb, file); } catch (IOException e) { // Can't happen. throw new RuntimeException(e); } parse(sb.toString()); } catch (IOException ex) { throw new SourceMapParseException("IO exception: " + ex); } }
From source file:com.gmail.tracebachi.DeltaSkins.Shared.Runnables.SkinFetchRunnable.java
License:Open Source License
@Override public void run() { String skinUuid = profile.getSkinUuid(); if (skinUuid.equals(PlayerProfile.NULL_UUID)) { plugin.severe("SkinUuid in profile for " + profile.getName() + " is null. " + "Skin cannot be fetched with invalid profile."); return;//from w w w. j a v a2 s. c o m } try { JsonObject skinObject = plugin.getMojangApi().getSkin(skinUuid); if (skinObject != null && skinObject.has("properties")) { JsonObject skinProperties = skinObject.get("properties").getAsJsonArray().get(0).getAsJsonObject(); SkinData skinData = new SkinData(skinUuid, skinProperties.get("value").getAsString(), skinProperties.get("signature").getAsString()); plugin.onSkinFetched(profile, skinData); } } catch (RateLimitedException ex) { plugin.info("Rate limited in fetching skin for {" + "name: " + profile.getName() + ", " + "skinUuid: " + skinUuid + "}."); } catch (NullPointerException ex) { plugin.severe("Failed to deserialize skin data for {" + "name: " + profile.getName() + ", " + "skinUuid: " + skinUuid + "}."); ex.printStackTrace(); } catch (IOException ex) { plugin.severe("Failed to fetch skin data for {" + "name: " + profile.getName() + ", " + "skinUuid: " + skinUuid + "}."); ex.printStackTrace(); } }
From source file:com.gockelhut.jsvcgen.JsonRpcServiceBase.java
License:Apache License
protected <TResponse> TResponse decodeResponse(InputStream responseInput, Class<TResponse> responseClass) { JsonObject responseObj = new JsonParser().parse(new InputStreamReader(responseInput)).getAsJsonObject(); if (responseObj.has("error")) { throw extractErrorResponse(responseObj); } else {/*from w w w. ja va2 s . co m*/ return gsonBuilder.create().fromJson(responseObj.get("result"), responseClass); } }
From source file:com.goodow.wind.server.rpc.DeltaHandler.java
License:Apache License
private JsonObject fetchHistories(SessionId sid, JsonArray keys) throws IOException, SlobNotFoundException, AccessDeniedException { SlobStore store = slobFacilities.getSlobStore(); JsonObject toRtn = new JsonObject(); JsonArray msgs = new JsonArray(); String token = null;// ww w .j av a 2 s. c om for (JsonElement e : keys) { JsonObject obj = e.getAsJsonObject(); ObjectId key = new ObjectId(obj.get(Params.ID).getAsString()); long version = obj.get(Params.VERSION).getAsLong(); Long endVersion = obj.has(Params.END_VERSION) ? obj.get(Params.END_VERSION).getAsLong() : null; ConnectResult r = store.reconnect(key, sid); JsonObject msg; if (r.getChannelToken() != null) { assert token == null || token.equals(r.getChannelToken()); token = r.getChannelToken(); } HistoryResult history = store.loadHistory(key, version, endVersion); msg = LocalMutationProcessor.jsonBroadcastData(key.toString(), serializeHistory(version, history.getData())); msg.addProperty(Params.VERSION, r.getVersion()); msgs.add(msg); } if (token != null) { toRtn.addProperty(Params.TOKEN, token); } toRtn.add(Params.DELTAS, msgs); return toRtn; }
From source file:com.google.api.ads.adwords.awalerting.report.AwqlReportQuery.java
License:Open Source License
/** * @param config the JSON configuration of the report query *///from w ww. j a v a2s. c om public AwqlReportQuery(JsonObject config) { reportType = config.get(ReportQueryTags.REPORT_TYPE).getAsString(); fields = config.get(ReportQueryTags.FIELDS).getAsString(); conditions = config.has(ReportQueryTags.CONDITIONS) ? config.get(ReportQueryTags.CONDITIONS).getAsString() : null; dateRange = config.has(ReportQueryTags.DATE_RANGE) ? config.get(ReportQueryTags.DATE_RANGE).getAsString() : null; }
From source file:com.google.api.ads.adwords.awalerting.sampleimpl.action.PerAccountManagerEmailSender.java
License:Open Source License
public PerAccountManagerEmailSender(JsonObject config) { subject = config.get(SUBJECT_TAG).getAsString(); ccList = null;/* w w w . j a va2s . c o m*/ if (config.has(CC_TAG)) { ccList = Arrays.asList(config.get(CC_TAG).getAsString().split(",")); } emailsMap = new HashMap<String, AlertEmail>(); }
From source file:com.google.api.ads.adwords.awalerting.sampleimpl.action.SimpleLogFileWriter.java
License:Open Source License
public SimpleLogFileWriter(JsonObject config) throws IOException { filePathname = config.get(LOG_FILE_PATHNAME_TAG).getAsString(); boolean appendMode = true; if (config.has(APPEND_MODE_TAG)) { appendMode = config.get(APPEND_MODE_TAG).getAsBoolean(); }// w w w . j av a 2 s. c om writer = new BufferedWriter(new FileWriter(filePathname, appendMode)); }
From source file:com.google.api.ads.adwords.awalerting.sampleimpl.downloader.SqlDbReportDownloader.java
License:Open Source License
/** * Get SQL query string according to config, and build column names list. * * @return the sql query string/* w w w.java2 s. com*/ */ private String getSqlQueryWithReportColumnNames() { JsonObject queryConfig = getQueryConfig(); StringBuilder sqlQueryBuilder = new StringBuilder(); sqlQueryBuilder.append("SELECT "); Preconditions.checkArgument(queryConfig.has(COLUMN_MAPPINGS_TAG), "Missing compulsory property: %s - %s", REPORT_QUERY_TAG, COLUMN_MAPPINGS_TAG); JsonArray columnMappings = queryConfig.getAsJsonArray(COLUMN_MAPPINGS_TAG); // Use LinkedHashMap to preserve order (SQL query and result parsing must have matched order). Map<String, String> fieldsMapping = new LinkedHashMap<String, String>(columnMappings.size()); // Process database column -> report column mapping String dbColumnName; String reportColumnName; for (JsonElement columnMapping : columnMappings) { JsonObject mapping = columnMapping.getAsJsonObject(); Preconditions.checkArgument(mapping.has(DATABASE_COLUMN_NAME_TAG), "Missing compulsory property: %s - %s - %s", REPORT_QUERY_TAG, COLUMN_MAPPINGS_TAG, DATABASE_COLUMN_NAME_TAG); Preconditions.checkArgument(mapping.has(REPORT_COLUMN_NAME_TAG), "Missing compulsory property: %s - %s - %s", REPORT_QUERY_TAG, COLUMN_MAPPINGS_TAG, REPORT_COLUMN_NAME_TAG); dbColumnName = mapping.get(DATABASE_COLUMN_NAME_TAG).getAsString(); reportColumnName = mapping.get(REPORT_COLUMN_NAME_TAG).getAsString(); fieldsMapping.put(dbColumnName, reportColumnName); } sqlQueryBuilder.append(Joiner.on(", ").withKeyValueSeparator(" AS ").join(fieldsMapping)); Preconditions.checkArgument(queryConfig.has(TABLE_TAG), "Missing compulsory property: %s - %s", REPORT_QUERY_TAG, TABLE_TAG); sqlQueryBuilder.append(" FROM ").append(queryConfig.get(TABLE_TAG).getAsString()); boolean hasWhereClause = false; if (queryConfig.has(DATE_RANGE_TAG)) { DateRange dateRange = DateRange.fromString(queryConfig.get(DATE_RANGE_TAG).getAsString()); String dateRangeCondition = String.format(DATA_RANGE_CONDITION_FORMAT, DATE_COLUMN_NAME, dateRange.getStartDate(), dateRange.getEndDate()); sqlQueryBuilder.append(" WHERE ").append(dateRangeCondition); hasWhereClause = true; } if (queryConfig.has(CONDITIONS_TAG)) { sqlQueryBuilder.append(hasWhereClause ? " AND " : " WHERR ") .append(queryConfig.get(CONDITIONS_TAG).getAsString()); } String sqlQuery = sqlQueryBuilder.toString(); LOGGER.info("SQL query: {}", sqlQuery); return sqlQuery; }
From source file:com.google.api.ads.adwords.awalerting.sampleimpl.downloader.SqlDbReportDownloader.java
License:Open Source License
/** * Get report type from the config, defaulting to the unknown type. * @return the report type// w w w. ja va 2 s . co m */ private ReportDefinitionReportType getReportType() { JsonObject queryConfig = getQueryConfig(); ReportDefinitionReportType reportType = ReportDefinitionReportType.UNKNOWN; if (queryConfig.has(REPORT_TYPE_TAG)) { String reportTypeStr = queryConfig.get(REPORT_TYPE_TAG).getAsString(); reportType = ReportDefinitionReportType.valueOf(reportTypeStr); } return reportType; }
From source file:com.google.api.ads.adwords.awalerting.sampleimpl.rule.ConvertMoneyValue.java
License:Open Source License
public ConvertMoneyValue(JsonObject config) { if (config.has(MONEY_FIELD_TAG) && config.has(MONEY_FIELDS_TAG)) { String errorMsg = String.format( "Error in ConvertMoneyValue constructor: cannot have both \"%s\" and \"%s\" in config.", MONEY_FIELD_TAG, MONEY_FIELDS_TAG); throw new IllegalArgumentException(errorMsg); }/*from w ww . j a va 2 s . c o m*/ moneyFields = new HashSet<String>(); if (config.has(MONEY_FIELD_TAG)) { moneyFields.add(config.get(MONEY_FIELD_TAG).getAsString()); } else if (config.has(MONEY_FIELDS_TAG)) { JsonArray array = config.get(MONEY_FIELDS_TAG).getAsJsonArray(); for (int i = 0; i < array.size(); i++) { moneyFields.add(array.get(i).getAsString()); } } else { // Use default moneyFields.add(DEFAULT_MONEY_FIELD); } }