List of usage examples for com.google.gson JsonObject getAsJsonObject
public JsonObject getAsJsonObject(String memberName)
From source file:com.sixt.service.framework.servicetest.helper.DockerPortResolver.java
License:Apache License
protected int parseExposedPort(String dockerJson, int internalPort) { try {/*from w w w. j a v a2 s.c o m*/ JsonArray jobj = new JsonParser().parse(dockerJson).getAsJsonArray(); JsonObject network = jobj.get(0).getAsJsonObject().get("NetworkSettings").getAsJsonObject(); JsonObject ports = network.getAsJsonObject("Ports"); JsonArray mappings = ports.getAsJsonArray("" + internalPort + "/tcp"); if (mappings != null) { return mappings.get(0).getAsJsonObject().get("HostPort").getAsInt(); } } catch (Exception ex) { logger.warn("Error parsing exposed port", ex); } return -1; }
From source file:com.sldeditor.exportdata.esri.MXDParser.java
License:Open Source License
/** * Process fields./* w w w . j av a2 s . c om*/ * * @param layerName the layer name * @param dataSourcePropertiesElement the data source properties element * @return the data source properties */ private DataSourcePropertiesInterface processDataSource(String layerName, JsonElement dataSourcePropertiesElement) { Map<String, String> propertyMap = new LinkedHashMap<String, String>(); if (dataSourcePropertiesElement != null) { JsonObject dsObj = dataSourcePropertiesElement.getAsJsonObject(); JsonElement typeElement = dsObj.get(DatasourceKeys.TYPE); if (typeElement != null) { propertyMap.put(DatasourceKeys.TYPE, typeElement.getAsString()); } JsonElement pathElement = dsObj.get(DatasourceKeys.PATH); if (pathElement != null) { propertyMap.put(DatasourceKeys.PATH, pathElement.getAsString()); } JsonObject properties = dsObj.getAsJsonObject(DatasourceKeys.PROPERTIES); if (properties != null) { for (Map.Entry<String, JsonElement> field : properties.entrySet()) { propertyMap.put(field.getKey(), field.getValue().getAsString()); } } } DataSourcePropertiesInterface dataSourceProperties = DataSourceManager.getInstance().convert(propertyMap); return dataSourceProperties; }
From source file:com.streamsets.pipeline.stage.destination.elasticsearch.ElasticsearchTarget.java
License:Apache License
private List<ErrorItem> extractErrorItems(JsonObject json) { List<ErrorItem> errorItems = new ArrayList<>(); JsonArray items = json.getAsJsonArray("items"); for (int i = 0; i < items.size(); i++) { JsonObject item = items.get(i).getAsJsonObject().entrySet().iterator().next().getValue() .getAsJsonObject();/* www.ja v a2 s. c om*/ int status = item.get("status").getAsInt(); if (status >= 400) { Object error = item.get("error"); // In some old versions, "error" is a simple string not a json object. if (error instanceof JsonObject) { errorItems.add(new ErrorItem(i, item.getAsJsonObject("error").get("reason").getAsString())); } else if (error instanceof JsonPrimitive) { errorItems.add(new ErrorItem(i, item.getAsJsonPrimitive("error").getAsString())); } else { // Error would be null if json has no "error" field. errorItems.add(new ErrorItem(i, "")); } } } return errorItems; }
From source file:com.surgeplay.visage.util.Profiles.java
License:Open Source License
public static boolean isSlim(GameProfile profile) throws IOException { if (profile.getProperties().containsKey("textures")) { String texJson = new String(Base64 .decode(profile.getProperties().get("textures").getValue().getBytes(StandardCharsets.UTF_8))); JsonObject obj = gson.fromJson(texJson, JsonObject.class); JsonObject tex = obj.getAsJsonObject("textures"); if (tex.has("SKIN")) { JsonObject skin = tex.getAsJsonObject("SKIN"); if (skin.has("metadata")) { if ("slim".equals(skin.getAsJsonObject("metadata").get("model").getAsString())) return true; }// ww w .j a v a 2s . co m return false; } } return UUIDs.isAlex(profile.getId()); }
From source file:com.synflow.cx.internal.validation.ClockDomainComputer.java
License:Open Source License
@Override public JsonObject caseActor(Actor actor) { JsonObject properties = actor.getProperties(); JsonObject domains = properties.getAsJsonObject(PROP_DOMAINS); if (properties.has(PORT_MAP)) { // if the flag is here, domains are available return domains; }//from w w w . jav a 2 s . c om if (domains == null) { // no domain, creates one domains = createPortMap(actor); } else { // domains exists, but not in port map format, convert them domains = convertToPortMap(domains); } // adds/updates domains to properties, and adds the "port map domains" flag properties.add(PROP_DOMAINS, domains); properties.add(PORT_MAP, null); return domains; }
From source file:com.synflow.cx.internal.validation.ClockDomainComputer.java
License:Open Source License
@Override public JsonObject caseDPN(DPN dpn) { JsonObject properties = dpn.getProperties(); JsonObject domains = properties.getAsJsonObject(PROP_DOMAINS); if (domains != null) { return domains; }/* w w w . j a v a2s . c om*/ // creates domains and adds them to properties so next time they will just be reused domains = new JsonObject(); properties.add(PROP_DOMAINS, domains); // compute domains for input ports for (Port port : dpn.getInputs()) { Set<String> candidates = new HashSet<>(); for (Connection connection : dpn.getOutgoing(port)) { for (Endpoint endpoint : getClocked(dpn, connection.getTargetEndpoint())) { candidates.add(getClockDomain(endpoint)); } } addCandidates(domains, port, candidates); } // compute domains for output ports for (Port port : dpn.getOutputs()) { Endpoint incoming = dpn.getIncoming(port); if (incoming != null) { Set<String> candidates = new HashSet<>(); for (Endpoint endpoint : getClocked(dpn, incoming)) { candidates.add(getClockDomain(endpoint)); } addCandidates(domains, port, candidates); } } return domains; }
From source file:com.test.goeuro.csvGenerator.CSVFileGenerator.java
/** * * @param respondArray/*from w ww .j ava 2s .c o m*/ */ public void createCSVFileAndWriteData(JsonArray respondArray) throws FileNotFoundException, IOException { FileWriter fileWriter = null; CSVPrinter csvFilePrinter = null; CSVFormat csvFileFormat = CSVFormat.EXCEL.withRecordSeparator(NEW_LINE_SEPARATOR); try { System.out.println("generating CVS file ...."); fileWriter = new FileWriter(new File(Constants.FILE_NAME)); csvFilePrinter = new CSVPrinter(fileWriter, csvFileFormat); csvFilePrinter.printRecord(FILE_HEADER); for (JsonElement jsonElement : respondArray) { List apiRespondData = new ArrayList(); JsonObject jsonObject = jsonElement.getAsJsonObject(); apiRespondData.add(jsonObject.get(Constants._ID).getAsString()); apiRespondData.add(jsonObject.get(Constants.NAME).getAsString()); apiRespondData.add(jsonObject.get(Constants.TYPE).getAsString()); JsonObject inGeoPosObject = jsonObject.getAsJsonObject(Constants.GEO_POSITION); apiRespondData.add(inGeoPosObject.get(Constants.LATITUDE).getAsDouble()); apiRespondData.add(inGeoPosObject.get(Constants.LONGITUDE).getAsDouble()); csvFilePrinter.printRecord(apiRespondData); } System.out.println("CSV generated successfully"); } catch (FileNotFoundException fnfex) { Logger.getLogger(CSVFileGenerator.class.getName()).log(Level.SEVERE, null, fnfex); System.out.println("Error in Open csv file"); fnfex.printStackTrace(); } catch (IOException ioex) { Logger.getLogger(CSVFileGenerator.class.getName()).log(Level.SEVERE, null, ioex); System.out.println("Error in Open/Write CsvFileWriter!!!"); ioex.printStackTrace(); } finally { try { fileWriter.flush(); fileWriter.close(); csvFilePrinter.close(); } catch (IOException e) { System.out.println("Error while flushing/closing fileWriter/csvPrinter !!!"); e.printStackTrace(); } catch (Exception ex) { System.out.println("Error while flushing/closing fileWriter/csvPrinter !!!"); ex.printStackTrace(); } } }
From source file:com.thesmartweb.swebrank.ElasticGetWordList.java
License:Apache License
/** * Method gets all the words of all the documents regardless of topic for the ids passed as input * @param ids It contains all the ids for which the words are going to be captured * @param config_path configuration directory to get the names of the elastic search indexes * @return All the words in a List// www .ja v a 2s . c o m */ public List<String> get(List<String> ids, String config_path) { try { //Node node = nodeBuilder().client(true).clusterName("lshrankldacluster").node(); //Client client = node.client(); Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "lshrankldacluster") .build(); Client client = new TransportClient(settings) .addTransportAddress(new InetSocketTransportAddress("localhost", 9300)); ReadInput ri = new ReadInput(); List<String> elasticIndexes = ri.GetKeyFile(config_path, "elasticSearchIndexes"); List<String> wordList = new ArrayList<>(); for (String id : ids) { SearchResponse responseSearch = client.prepareSearch(elasticIndexes.get(2)) .setSearchType(SearchType.QUERY_AND_FETCH).setQuery(QueryBuilders.idsQuery().ids(id)) .execute().actionGet(); XContentBuilder builder = XContentFactory.jsonBuilder(); builder.startObject(); responseSearch.toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); String JSONresponse = builder.string(); JsonParser parser = new JsonParser(); JsonObject JSONobject = (JsonObject) parser.parse(JSONresponse); JsonObject hitsJsonObject = JSONobject.getAsJsonObject("hits"); JsonArray hitsJsonArray = hitsJsonObject.getAsJsonArray("hits"); for (JsonElement hitJsonElement : hitsJsonArray) { JsonObject jsonElementObj = hitJsonElement.getAsJsonObject(); jsonElementObj = jsonElementObj.getAsJsonObject("_source"); JsonArray TopicsArray = jsonElementObj.getAsJsonArray("TopicsWordMap"); for (JsonElement Topic : TopicsArray) { JsonObject TopicObj = Topic.getAsJsonObject(); JsonObject wordsmap = TopicObj.getAsJsonObject("wordsmap"); Set<Map.Entry<String, JsonElement>> entrySet = wordsmap.entrySet(); Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> next = iterator.next(); String word = next.getKey(); wordList.add(word); } } } } //node.close(); client.close(); return wordList; } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); List<String> wordList = new ArrayList<>(); return wordList; } }
From source file:com.thesmartweb.swebrank.ElasticGetWordList.java
License:Apache License
/** * Method gets all the top N max words for each topic of all the documents with their IDs (of the documents) passed as input. * @param ids It contains all the ids for which the words are going to be captured * @param top It contains the number of max words to be returned * @return All the words in a List/*w w w .j a v a 2 s. c om*/ */ public List<String> getMaxWords(List<String> ids, int top, String config_path) { try { ReadInput ri = new ReadInput(); List<String> elasticIndexes = ri.GetKeyFile(config_path, "elasticSearchIndexes"); Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "lshrankldacluster") .build(); Client client = new TransportClient(settings) .addTransportAddress(new InetSocketTransportAddress("localhost", 9300)); //Node node = nodeBuilder().client(true).clusterName("lshrankldacluster").node(); //Client client = node.client(); List<String> MaxwordList = new ArrayList<>(); HashMap<String, Double> wordsMap = new HashMap<>(); SortedSetMultimap<Double, String> wordsMultisorted = TreeMultimap.create(); for (String id : ids) {//for every id loop SearchResponse responseSearch = client.prepareSearch(elasticIndexes.get(2)) .setSearchType(SearchType.QUERY_AND_FETCH).setQuery(QueryBuilders.idsQuery().ids(id)) .execute().actionGet();//search for this id //----build an object with the response XContentBuilder builder = XContentFactory.jsonBuilder(); builder.startObject(); responseSearch.toXContent(builder, ToXContent.EMPTY_PARAMS); builder.endObject(); String JSONresponse = builder.string(); //----parse the JSON response JsonParser parser = new JsonParser(); JsonObject JSONobject = (JsonObject) parser.parse(JSONresponse); JsonObject hitsJsonObject = JSONobject.getAsJsonObject("hits"); JsonArray hitsJsonArray = hitsJsonObject.getAsJsonArray("hits"); //get all the JSON hits (check ElasticSearch typical response format for more) for (JsonElement hitJsonElement : hitsJsonArray) { JsonObject jsonElementObj = hitJsonElement.getAsJsonObject(); jsonElementObj = jsonElementObj.getAsJsonObject("_source"); JsonArray TopicsArray = jsonElementObj.getAsJsonArray("TopicsWordMap");//get the topics word map (every word has a probability for (JsonElement Topic : TopicsArray) {//for every topic I get the word with the max score JsonObject TopicObj = Topic.getAsJsonObject(); JsonObject wordsmap = TopicObj.getAsJsonObject("wordsmap");//get the wordmap Set<Map.Entry<String, JsonElement>> entrySet = wordsmap.entrySet(); Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); double max = 0.0; String maxword = ""; while (iterator.hasNext()) { Map.Entry<String, JsonElement> next = iterator.next(); if (next.getValue().getAsDouble() > max) { maxword = next.getKey(); max = next.getValue().getAsDouble(); } } if (wordsMap.containsKey(maxword)) { if (wordsMap.get(maxword) < max) { wordsMap.put(maxword, max); } } else { wordsMap.put(maxword, max); } } } } //we are going to sort all the max words Map<String, Double> wordsMapsorted = new HashMap<>(); wordsMapsorted = sortByValue(wordsMap);//sorts the map in ascending fashion Iterator<Entry<String, Double>> iterator = wordsMapsorted.entrySet().iterator(); //we are going to get the first top words from the list of Max words int beginindex = 0; //===we find the beginning index if (wordsMapsorted.entrySet().size() > top) { beginindex = wordsMapsorted.entrySet().size() - top; } int index = 0; //if the beginning index is larger we try to find the element while (index < beginindex) { iterator.next(); index++; } //while the maxword list size is smaller than the top number and we have an extra value, add this word while (MaxwordList.size() < top && iterator.hasNext()) { String word = iterator.next().getKey(); MaxwordList.add(word); } client.close(); //node.close(); return MaxwordList; } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); List<String> MaxwordList = new ArrayList<>(); return MaxwordList; } }
From source file:com.tmobile.TMobileParsing.java
protected static BillingAccount extractBillingAccount(JsonObject jsonProfile) { BillingAccount billingAccount = new BillingAccount(); JsonObject jsonBillingAccount = jsonProfile.getAsJsonObject("billingAccount"); String lastBillingDate = jsonBillingAccount.get("lastBillingDate").getAsString(); String paymentType = jsonBillingAccount.get("paymentType").getAsString(); String nextBillingDate = jsonBillingAccount.get("nextBillingDate").getAsString(); billingAccount.setLastBillingDate(lastBillingDate); billingAccount.setPaymentType(paymentType); billingAccount.setNextBillingDate(nextBillingDate); return billingAccount; }