/** * Look up in the home directory for the corresponding * reporting configuration. */ public void loadHomeDirectory(){ homeFolder = System.getProperty(ENV_HOME_FOLDER); if(homeFolder == null) throw new RuntimeException("The reports.home env variable should be specified at start up"); Path reportsHome = Paths.get(homeFolder); Path mainConfig = reportsHome.resolve(MAIN_CONFIG_FILE_NAME); if(!Files.exists(mainConfig)) throw new RuntimeException("There is no '"+MAIN_CONFIG_FILE_NAME+"' inside the home folder"); JsonParser jsonParser = new BasicJsonParser(); Map<String, Object> jsonMap = null; try { jsonMap = jsonParser.parseMap(new String(Files.readAllBytes(mainConfig))); } catch (IOException e) { throw new RuntimeException("Filed to read the '"+MAIN_CONFIG_FILE_NAME+"' file", e); } reports = (List<String>)jsonMap.get(MAIN_CONFIG_REPORTS_PROPERTY); }
/** * Based on the definition found in the given path, * creates a new instance of ReportDefinition. * @param reportPath path where the report source lies * @return Report Definition instance */ public ReportDefinition loadReportDefinition(String reportPath){ Path reportDefinitionFile = Paths.get(reportPath).resolve("report.json"); JsonParser jsonParser = new BasicJsonParser(); Map<String, Object> jsonMap = null; try { jsonMap = jsonParser.parseMap(new String(Files.readAllBytes(reportDefinitionFile))); } catch (IOException e) { throw new RuntimeException("Failed to read the '"+reportDefinitionFile+"' file", e); } ReportDefinition reportDefinition = new ReportDefinition(); Map<String, ReportParamDataType> params = new HashMap<>(); reportDefinition.setName(jsonMap.get(ReportDefinitionProperties.NAME.getName()).toString()); reportDefinition.setReportFile(jsonMap.get(ReportDefinitionProperties.REPORT_FILE.getName()).toString()); reportDefinition.setReportPath(Paths.get(reportPath)); reportDefinition.setParams(params); Map<String, String> rawParams = (Map<String, String>)jsonMap.get(ReportDefinitionProperties.PARAMS.getName()); Set<Map.Entry<String, String>> entrySet = rawParams.entrySet(); for(Map.Entry<String, String> entry: entrySet){ params.put(entry.getKey(), ReportParamDataType.fromKey(entry.getValue())); } return reportDefinition; }
public Json2MapReader(String json) { JsonParser parser = JsonParserFactory.getJsonParser(); map = parser.parseMap(json); // For creating test files: // try { // FileWriter writer = new FileWriter(new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss.SSS").format(new Date()) + "-json.txt"); // writer.append(json); // writer.close(); // } catch (IOException e) { // System.out.println(e.getMessage()); // } }
private void processJson(ConfigurableEnvironment environment, String json) { try { JsonParser parser = JsonParserFactory.getJsonParser(); Map<String, Object> map = parser.parseMap(json); if (!map.isEmpty()) { addJsonPropertySource(environment, new MapPropertySource("spring.application.json", flatten(map))); } } catch (Exception ex) { logger.warn("Cannot parse JSON for spring.application.json: " + json, ex); } }
@Bean @Profile("cloud") public PubSub pubSubCloud(Environment environment) throws Exception { String vcapServicesEnv = environment.getProperty("VCAP_SERVICES"); JsonParser parser = JsonParserFactory.getJsonParser(); Map<String, Object> services = parser.parseMap(vcapServicesEnv); List<Map<String, Object>> googlePubsub = (List<Map<String, Object>>) services.get("google-pubsub"); Map<String, Object> credentials = (Map<String, Object>) googlePubsub.get(0).get("credentials"); String privateKeyData = (String) credentials.get("PrivateKeyData"); GoogleCredential googleCredential = GoogleCredential.fromStream(new ByteArrayInputStream(Base64.decodeBase64(privateKeyData))); return PubSubOptions.newBuilder().setAuthCredentials(AuthCredentials.createFor(googleCredential.getServiceAccountId(), googleCredential.getServiceAccountPrivateKey())) .setProjectId(pubSubBinderConfigurationProperties.getProjectName()).build().getService(); }
public void setCredentialsJson(String credentialsJson) { JsonParser parser = JsonParserFactory.getJsonParser(); this.credentialsJson = parser.parseMap(credentialsJson); }
private Map<String, Object> getJsonMapFromEnvironment() { JsonParser jsonParser = JsonParserFactory.getJsonParser(); Map<String, Object> jsonMap; jsonMap = jsonParser.parseMap(getVCapVariable()); return (Map<String, Object>) ((List<Map<String, Object>>) jsonMap.get( "p-cassandra")).get(0).get("credentials"); }