Java Code Examples for javax.json.JsonObject#getJsonObject()
The following examples show how to use
javax.json.JsonObject#getJsonObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Command.java From Doradus with Apache License 2.0 | 6 votes |
private String getQueryInputEntity() { JsonObjectBuilder jsonQuery = Json.createObjectBuilder(); String inputEntityParam = metadataJson.getString(INPUT_ENTITY); JsonObject parametersNode = metadataJson.getJsonObject(PARAMETERS); if (parametersNode != null) { JsonObject paramDetail = parametersNode.getJsonObject(inputEntityParam); for (String param: paramDetail.keySet()) { Object value = commandParams.get(param); if (value!=null) { jsonQuery.add(param, value.toString()); } } return Json.createObjectBuilder().add(inputEntityParam, jsonQuery).build().toString(); } return null; }
Example 2
Source File: JobDefinition.java From herd-mdl with Apache License 2.0 | 6 votes |
private String getActualObjectName( JobDefinition jobDef ) { try { if ( !StringUtils.isEmpty( jobDef.getCorrelation() ) && !jobDef.getCorrelation().equals( "null" ) ) { JsonReader reader = Json.createReader( new StringReader( jobDef.getCorrelation() ) ); JsonObject object = reader.readObject(); if ( object.containsKey( "businessObject" ) ) { JsonObject bo = object.getJsonObject( "businessObject" ); if ( bo.containsKey( "late_reporting_for" ) ) { String objName = bo.getString( "late_reporting_for" ); return objName; } } } } catch ( Exception ex ) { log.warn( "Error parsing correlation:" + jobDef.getCorrelation() ); } return jobDef.getObjectDefinition().getObjectName(); }
Example 3
Source File: Command.java From Doradus with Apache License 2.0 | 5 votes |
private String getParamsURI() { StringBuilder uriBuilder = new StringBuilder(); JsonObject parametersNode = metadataJson.getJsonObject(PARAMETERS); if (parametersNode != null) { JsonObject paramDetail = parametersNode.getJsonObject(PARAMS); for (String param: paramDetail.keySet()) { if (commandParams.containsKey(param)) { uriBuilder.append(param).append("=").append(commandParams.get(param)); } } } return uriBuilder.toString(); }
Example 4
Source File: CodeGenerator.java From FHIR with Apache License 2.0 | 5 votes |
private List<JsonObject> getElementDefinitions(JsonObject structureDefinition, boolean snapshot) { List<JsonObject> elementDefinitions = new ArrayList<>(); JsonObject snapshotOrDifferential = structureDefinition.getJsonObject(snapshot ? "snapshot" : "differential"); for (JsonValue element : snapshotOrDifferential.getJsonArray("element")) { elementDefinitions.add(element.asJsonObject()); if (snapshot) { String path = element.asJsonObject().getString("path"); if ("DataRequirement.codeFilter.extension".equals(path) || "DataRequirement.dateFilter.extension".equals(path) || "DataRequirement.sort.extension".equals(path) || "Dosage.doseAndRate.extension".equals(path) || "ElementDefinition.slicing.extension".equals(path) || "ElementDefinition.slicing.discriminator.extension".equals(path) || "ElementDefinition.base.extension".equals(path) || "ElementDefinition.type.extension".equals(path) || "ElementDefinition.example.extension".equals(path) || "ElementDefinition.constraint.extension".equals(path) || "ElementDefinition.binding.extension".equals(path) || "ElementDefinition.mapping.extension".equals(path) || "SubstanceAmount.referenceRange.extension".equals(path) || "Timing.repeat.extension".equals(path)) { elementDefinitions.add(getModifierExtensionDefinition(path.replace(".extension", ""))); } } } return elementDefinitions; }
Example 5
Source File: CadfReporterStep.java From FHIR with Apache License 2.0 | 5 votes |
public static CadfReporterStep parse(JsonObject jsonObject) throws FHIRException, IOException, ClassNotFoundException { CadfReporterStep.Builder builder = CadfReporterStep.builder(); if (jsonObject.get("reporter") != null) { JsonObject reporter = jsonObject.getJsonObject("reporter"); CadfResource resource = CadfResource.Parser.parse(reporter); builder.reporter(resource); } if (jsonObject.get("reporterId") != null) { String reporterId = jsonObject.getString("reporterId"); builder.reporterId(reporterId); } if (jsonObject.get("reporterTime") != null) { String rTime = jsonObject.getString("reporterTime"); TemporalAccessor reporterTime = DATE_TIME_PARSER_FORMATTER.parse(rTime); builder.reporterTime(ZonedDateTime.from(reporterTime)); } if (jsonObject.get("role") != null) { String role = jsonObject.getString("role"); builder.role(ReporterRole.valueOf(role)); } if (jsonObject.get("attachments") != null) { JsonArray annotations = jsonObject.getJsonArray("attachments"); for (int i = 0; i < annotations.size(); i++) { JsonObject obj = (JsonObject) annotations.get(0); CadfAttachment item = CadfAttachment.Parser.parse(obj); builder.attachment(item); } } return builder.build(); }
Example 6
Source File: ApiReqKaisouSlotDeprive.java From logbook-kai with MIT License | 5 votes |
@Override public void accept(JsonObject json, RequestMetaData req, ResponseMetaData res) { JsonObject data = json.getJsonObject("api_data"); if (data != null) { JsonObject shipData = data.getJsonObject("api_ship_data"); if (shipData != null) { this.replace(shipData.getJsonObject("api_set_ship")); this.replace(shipData.getJsonObject("api_unset_ship")); } } }
Example 7
Source File: ReportMerger.java From KITE with Apache License 2.0 | 5 votes |
private static void fixWrongStatus(String pathToReportFolder) throws IOException { File reportFolder = new File(pathToReportFolder); File[] subFiles = reportFolder.listFiles(); for (int index = 0; index < subFiles.length; index++) { if (subFiles[index].getName().contains("result.json")) { JsonObject result = readJsonFile(subFiles[index].getAbsolutePath()); JsonObject statusDetail = result.getJsonObject("statusDetails"); String message = statusDetail.getString("message"); boolean issue = message.equalsIgnoreCase("The test has passed successfully!") && !result.getString("status").equals("PASSED"); if (issue) { JsonArray steps = result.getJsonArray("steps"); for (int i = 0; i < steps.size(); i++) { JsonObject step = (JsonObject)steps.get(i); if (!step.getString("status").equals("PASSED")){ statusDetail = step.getJsonObject("statusDetails"); break; } } JsonObjectBuilder builder = Json.createObjectBuilder(); for (String key: result.keySet()) { if (!key.equals("statusDetails")) { builder.add(key, result.get(key)); } else { builder.add(key, statusDetail); } } FileUtils.forceDelete(new File(subFiles[index].getAbsolutePath())); printJsonTofile(builder.build().toString(), subFiles[index].getAbsolutePath()); } } } }
Example 8
Source File: ApiReqCombinedBattleEcNightToDay.java From logbook-kai with MIT License | 5 votes |
@Override public void accept(JsonObject json, RequestMetaData req, ResponseMetaData res) { JsonObject data = json.getJsonObject("api_data"); if (data != null) { AppCondition condition = AppCondition.get(); BattleLog log = condition.getBattleResult(); if (log != null) { condition.setBattleCount(condition.getBattleCount() + 1); log.setBattleCount(condition.getBattleCount()); log.setRoute(condition.getRoute()); log.setBattle(CombinedBattleEcNightToDay.toBattle(data)); // ローデータを設定する if (AppConfig.get().isIncludeRawData()) { BattleLog.setRawData(log, BattleLog.RawData::setBattle, data, req); } // 艦隊スナップショットを作る if (log.getCombinedType() != CombinedType.未結成 && AppCondition.get().getDeckId() == 1) { BattleLog.snapshot(log, 1, 2); } else { BattleLog.snapshot(log, AppCondition.get().getDeckId()); } if (AppConfig.get().isApplyBattle()) { // 艦隊を更新 PhaseState p = new PhaseState(log); p.apply(log.getBattle()); ShipCollection.get() .getShipMap() .putAll(Stream.of(p.getAfterFriend(), p.getAfterFriendCombined()) .flatMap(List::stream) .filter(Objects::nonNull) .collect(Collectors.toMap(Ship::getId, v -> v))); } } } }
Example 9
Source File: DataHandler.java From javametrics with Apache License 2.0 | 5 votes |
@Override public void processData(List<String> jsonData) { for (Iterator<String> iterator = jsonData.iterator(); iterator.hasNext();) { String jsonStr = iterator.next(); JsonReader jsonReader = Json.createReader(new StringReader(jsonStr)); try { JsonObject jsonObject = jsonReader.readObject(); String topicName = jsonObject.getString("topic", null); if (topicName != null) { if (topicName.equals("http")) { JsonObject payload = jsonObject.getJsonObject("payload"); long requestTime = payload.getJsonNumber("time").longValue(); long requestDuration = payload.getJsonNumber("duration").longValue(); String requestUrl = payload.getString("url", ""); String requestMethod = payload.getString("method", ""); synchronized (aggregateHttpData) { aggregateHttpData.aggregate(requestTime, requestDuration, requestUrl, requestMethod); } } else { emit(jsonObject.toString()); } } } catch (JsonException je) { // Skip this object, log the exception and keep trying with // the rest of the list je.printStackTrace(); } } emitHttp(); }
Example 10
Source File: SemanticQuery.java From vicinity-gateway-api with GNU General Public License v3.0 | 5 votes |
public String getSemanticInterface(JsonObject td) { if (td == null) { logger.warning("thingDescription is null."); return null; } JsonObject content = td.getJsonObject("td"); if (content == null) { logger.warning("thingDescription is null."); return null; } return content.getString("semanticInterface", null); }
Example 11
Source File: ResourceProcessor.java From FHIR with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { JsonReaderFactory jsonReaderFactory = Json.createReaderFactory(null); JsonWriterFactory jsonWriterFactory = Json.createWriterFactory(null); JsonBuilderFactory jsonBuilderFactory = Json.createBuilderFactory(null); File dir = new File("src/main/resources/hl7/fhir/us/davinci-pdex-plan-net/package/"); for (File file : dir.listFiles()) { String fileName = file.getName(); if (!fileName.endsWith(".json") || file.isDirectory()) { continue; } JsonObject jsonObject = null; try (BufferedReader reader = new BufferedReader(new FileReader(file))) { JsonReader jsonReader = jsonReaderFactory.createReader(reader); jsonObject = jsonReader.readObject(); JsonObjectBuilder jsonObjectBuilder = jsonBuilderFactory.createObjectBuilder(jsonObject); JsonObject text = jsonObject.getJsonObject("text"); if (text != null) { JsonObjectBuilder textBuilder = jsonBuilderFactory.createObjectBuilder(text); String div = text.getString("div"); div = div.replace("<p><pre>", "<pre>").replace("</pre></p>", "</pre>"); textBuilder.add("div", div); jsonObjectBuilder.add("text", textBuilder); } if (!jsonObject.containsKey("version")) { System.out.println("file: " + file + " does not have a version"); jsonObjectBuilder.add("version", "0.1.0"); } jsonObject = jsonObjectBuilder.build(); } try (FileWriter writer = new FileWriter(file)) { JsonWriter jsonWriter = jsonWriterFactory.createWriter(writer); jsonWriter.write(jsonObject); } } }
Example 12
Source File: Context.java From FHIR with Apache License 2.0 | 4 votes |
public static Context parse(InputStream in) throws FHIRException { try (JsonReader jsonReader = JSON_READER_FACTORY.createReader(in, StandardCharsets.UTF_8)) { JsonObject jsonObject = jsonReader.readObject(); Context.Builder builder = Context.builder(); JsonValue t = jsonObject.get("request_unique_id"); if (t != null) { String requestUniqueId = jsonObject.getString("request_unique_id"); builder.requestUniqueId(requestUniqueId); } t = jsonObject.get("action"); if (t != null) { String action = jsonObject.getString("action"); builder.action(action); } t = jsonObject.get("operation_name"); if (t != null) { String operationName = jsonObject.getString("operation_name"); builder.operationName(operationName); } t = jsonObject.get("purpose"); if (t != null) { String purpose = jsonObject.getString("purpose"); builder.purpose(purpose); } t = jsonObject.get("start_time"); if (t != null) { String startTime = jsonObject.getString("start_time"); builder.startTime(startTime); } t = jsonObject.get("end_time"); if (t != null) { String endTime = jsonObject.getString("end_time"); builder.endTime(endTime); } t = jsonObject.get("api_parameters"); if (t != null) { JsonObject apiParameters = jsonObject.getJsonObject("api_parameters"); ApiParameters p = ApiParameters.Parser.parse(apiParameters); builder.apiParameters(p); } t = jsonObject.get("query"); if (t != null) { String queryParameters = jsonObject.getString("query"); builder.queryParameters(queryParameters); } t = jsonObject.get("data"); if (t != null) { JsonObject data = jsonObject.getJsonObject("data"); Data d = Data.Parser.parse(data); builder.data(d); } t = jsonObject.get("batch"); if (t != null) { JsonObject batch = jsonObject.getJsonObject("batch"); Batch b = Batch.Parser.parse(batch); builder.batch(b); } return builder.build(); } catch (Exception e) { throw new FHIRException("Problem parsing the Context", e); } }
Example 13
Source File: PropertyGroup.java From FHIR with Apache License 2.0 | 4 votes |
/** * This function will find the JSON "sub object" rooted at "this.jsonObj" that is associated with the specified * hierarchical property name. * <p>For example, consider the following JSON structure: * <pre> * { * "level1":{ * "level2":{ * "myProperty":"myValue" * } * } * } * </pre> * If this function was invoked with a property name of "level1/level2/myProperty", * then the result will be the JsonObject associated with the "level2" field within the JSON * structure above. * * @param pathElements * an array of path elements that make up the hierarchical property name (e.g. {"level1", "level2", * "myProperty"}) * @return the JsonObject sub-structure that contains the specified property. */ protected JsonObject getPropertySubGroup(String[] pathElements) { if (pathElements != null) { JsonObject cursor = this.jsonObj; int limit = pathElements.length - 1; for (int i = 0; i < limit; i++) { cursor = cursor.getJsonObject(pathElements[i]); if (cursor == null) { break; } } return cursor; } return null; }
Example 14
Source File: ApiReqCombinedBattleBattleresult.java From logbook-kai with MIT License | 4 votes |
@Override public void accept(JsonObject json, RequestMetaData req, ResponseMetaData res) { JsonObject data = json.getJsonObject("api_data"); if (data != null) { BattleResult result = BattleResult.toBattleResult(data); BattleLog log = AppCondition.get().getBattleResult(); if (log != null) { // 削除 AppCondition.get().setBattleResult(null); AppCondition.get().setBattleResultConfirm(log); log.setResult(result); // ローデータを設定する if (AppConfig.get().isIncludeRawData()) { BattleLog.setRawData(log, BattleLog.RawData::setResult, data, req); } log.setTime(Logs.nowString()); // 艦隊スナップショットを作る if (log.getCombinedType() != CombinedType.未結成 && AppCondition.get().getDeckId() == 1) { BattleLog.snapshot(log, 1, 2); } else { BattleLog.snapshot(log, AppCondition.get().getDeckId()); } // 戦闘ログの保存 BattleLogs.write(log); LogWriter.getInstance(BattleResultLogFormat::new) .write(log); if (AppConfig.get().isApplyResult()) { // 艦隊を更新 PhaseState p = new PhaseState(log); p.apply(log.getBattle()); p.apply(log.getMidnight()); ShipCollection.get() .getShipMap() .putAll(Stream.of(p.getAfterFriend(), p.getAfterFriendCombined()) .flatMap(List::stream) .filter(Objects::nonNull) .collect(Collectors.toMap(Ship::getId, v -> v))); } } if (result.achievementGimmick1()) { Platform.runLater( () -> Tools.Conrtols.showNotify(null, "ギミック解除", "海域に変化が確認されました。", Duration.seconds(15))); // 通知音再生 if (AppConfig.get().isUseSound()) { Platform.runLater(Audios.playDefaultNotifySound()); } // 棒読みちゃん連携 if (AppBouyomiConfig.get().isEnable()) { BouyomiChanUtils.speak(Type.AchievementGimmick1); } } if (result.achievementGimmick2()) { Platform.runLater( () -> Tools.Conrtols.showNotify(null, "ギミック解除", "ギミックの達成を確認しました。", Duration.seconds(15))); // 通知音再生 if (AppConfig.get().isUseSound()) { Platform.runLater(Audios.playDefaultNotifySound()); } // 棒読みちゃん連携 if (AppBouyomiConfig.get().isEnable()) { BouyomiChanUtils.speak(Type.AchievementGimmick2); } } } }
Example 15
Source File: ApiReqMapNext.java From logbook-kai with MIT License | 4 votes |
@Override public void accept(JsonObject json, RequestMetaData req, ResponseMetaData res) { JsonObject data = json.getJsonObject("api_data"); if (data != null) { MapStartNext next = MapStartNext.toMapStartNext(data); AppCondition condition = AppCondition.get(); BattleLog log = condition.getBattleResult(); if (log == null) { log = new BattleLog(); condition.setBattleResult(log); } log.setCombinedType(CombinedType.toCombinedType(condition.getCombinedType())); log.getNext().add(next); // ルート情報 condition.getRoute().add(new StringJoiner("-") .add(data.getJsonNumber("api_maparea_id").toString()) .add(data.getJsonNumber("api_mapinfo_no").toString()) .add(data.getJsonNumber("api_no").toString()) .toString()); if (AppConfig.get().isAlertBadlyNext() || AppBouyomiConfig.get().isEnable()) { // 大破した艦娘 List<Ship> badlyShips = DeckPortCollection.get() .getDeckPortMap() .get(condition.getDeckId()) .getBadlyShips(); // 連合艦隊時は第2艦隊も見る if (condition.isCombinedFlag()) { badlyShips.addAll(DeckPortCollection.get() .getDeckPortMap() .get(2).getBadlyShips()); } if (!badlyShips.isEmpty()) { Platform.runLater(() -> displayAlert(badlyShips)); // 棒読みちゃん連携 sendBouyomi(badlyShips); } } if (next.achievementGimmick1()) { Platform.runLater( () -> Tools.Conrtols.showNotify(null, "ギミック解除", "海域に変化が確認されました。", Duration.seconds(15))); // 通知音再生 if (AppConfig.get().isUseSound()) { Platform.runLater(Audios.playDefaultNotifySound()); } // 棒読みちゃん連携 if (AppBouyomiConfig.get().isEnable()) { BouyomiChanUtils.speak(Type.AchievementGimmick1); } } if (next.achievementGimmick2()) { Platform.runLater( () -> Tools.Conrtols.showNotify(null, "ギミック解除", "ギミックの達成を確認しました。", Duration.seconds(15))); // 通知音再生 if (AppConfig.get().isUseSound()) { Platform.runLater(Audios.playDefaultNotifySound()); } // 棒読みちゃん連携 if (AppBouyomiConfig.get().isEnable()) { BouyomiChanUtils.speak(Type.AchievementGimmick2); } } } }
Example 16
Source File: SKFSServlet.java From fido2 with GNU Lesser General Public License v2.1 | 4 votes |
/** * The process of activating an already registered but de-activated fido * authenticator. This process will turn the status of the key in the * database back to ACTIVE. The inputs needed are the name of the user and * the random id to point to a unique registered key for that user. This * random id can be obtained by calling getkeysinfo method. * * @param svcinfo * @param patchkey - * @param did - Long value of the domain to service this request * @param kid - String value of the key to deregister * @return - A Json in String format. The Json will have 3 key-value pairs; * 1. 'Response' : String, with a simple message telling if the process was * successful or not. 2. 'Message' : Empty string since there is no * cryptographic work involved in activation 3. 'Error' : String, with error * message incase something went wrong. Will be empty if successful. */ @POST @Path("/updatekeyinfo") @Consumes({"application/json"}) @Produces({"application/json"}) public Response updatekeyinfo(String input) { ServiceInfo svcinfoObj; JsonObject inputJson = skfsCommon.getJsonObjectFromString(input); if (inputJson == null) { return Response.status(Response.Status.BAD_REQUEST).entity(skfsCommon.getMessageProperty("FIDO-ERR-0014") + " input").build(); } //convert payload to pre reg object PatchFidoKeyRequest patchreq = new PatchFidoKeyRequest(); JsonObject svcinfo = inputJson.getJsonObject("svcinfo"); svcinfoObj = skfsCommon.checkSvcInfo("REST", svcinfo.toString()); Response svcres = checksvcinfoerror(svcinfoObj); if(svcres !=null){ return svcres; } JsonObject patchpayload = inputJson.getJsonObject("payload"); String keyid=""; if(patchpayload.containsKey("status")){ patchreq.setStatus(patchpayload.getString("status")); } if(patchpayload.containsKey("modify_location")){ patchreq.setModify_location(patchpayload.getString("modify_location")); } if(patchpayload.containsKey("displayname")){ patchreq.setDisplayname(patchpayload.getString("displayname")); } if(patchpayload.containsKey("keyid")){ patchreq.setKeyid(patchpayload.getString("keyid")); keyid = patchpayload.getString("keyid"); } boolean isAuthorized; if (svcinfoObj.getAuthtype().equalsIgnoreCase("password")) { try { isAuthorized = authorizebean.execute(svcinfoObj.getDid(), svcinfoObj.getSvcusername(), svcinfoObj.getSvcpassword(), skfsConstants.LDAP_ROLE_FIDO); } catch (Exception ex) { skfsLogger.log(skfsConstants.SKFE_LOGGER, Level.SEVERE, skfsCommon.getMessageProperty("FIDO-ERR-0003"), ex.getMessage()); return Response.status(Response.Status.BAD_REQUEST).entity(skfsCommon.getMessageProperty("FIDO-ERR-0003") + ex.getMessage()).build(); } if (!isAuthorized) { skfsLogger.log(skfsConstants.SKFE_LOGGER, Level.SEVERE, "FIDO-ERR-0033", ""); return Response.status(Response.Status.UNAUTHORIZED).build(); } } else { if (!authRest.execute(svcinfoObj.getDid(), request, patchreq)) { return Response.status(Response.Status.UNAUTHORIZED).build(); } } return u2fHelperBean.patchfidokey(svcinfoObj.getDid(), keyid, patchreq); }
Example 17
Source File: ApiReqSortieBattleresult.java From logbook-kai with MIT License | 4 votes |
@Override public void accept(JsonObject json, RequestMetaData req, ResponseMetaData res) { JsonObject data = json.getJsonObject("api_data"); if (data != null) { BattleResult result = BattleResult.toBattleResult(data); BattleLog log = AppCondition.get().getBattleResult(); if (log != null) { // 削除 AppCondition.get().setBattleResult(null); AppCondition.get().setBattleResultConfirm(log); log.setResult(result); // ローデータを設定する if (AppConfig.get().isIncludeRawData()) { BattleLog.setRawData(log, BattleLog.RawData::setResult, data, req); } log.setTime(Logs.nowString()); // 出撃艦隊 Integer dockId = Optional.ofNullable(log.getBattle()) .map(IFormation::getDockId) .orElse(1); // 艦隊スナップショットを作る BattleLog.snapshot(log, dockId); // 戦闘ログの保存 BattleLogs.write(log); LogWriter.getInstance(BattleResultLogFormat::new) .write(log); if (AppConfig.get().isApplyResult()) { // 艦隊を更新 PhaseState p = new PhaseState(log); p.apply(log.getBattle()); p.apply(log.getMidnight()); ShipCollection.get() .getShipMap() .putAll(p.getAfterFriend().stream() .filter(Objects::nonNull) .collect(Collectors.toMap(Ship::getId, v -> v))); } } if (result.achievementGimmick1()) { Platform.runLater( () -> Tools.Conrtols.showNotify(null, "ギミック解除", "海域に変化が確認されました。", Duration.seconds(15))); // 通知音再生 if (AppConfig.get().isUseSound()) { Platform.runLater(Audios.playDefaultNotifySound()); } // 棒読みちゃん連携 if (AppBouyomiConfig.get().isEnable()) { BouyomiChanUtils.speak(Type.AchievementGimmick1); } } if (result.achievementGimmick2()) { Platform.runLater( () -> Tools.Conrtols.showNotify(null, "ギミック解除", "ギミックの達成を確認しました。", Duration.seconds(15))); // 通知音再生 if (AppConfig.get().isUseSound()) { Platform.runLater(Audios.playDefaultNotifySound()); } // 棒読みちゃん連携 if (AppBouyomiConfig.get().isEnable()) { BouyomiChanUtils.speak(Type.AchievementGimmick2); } } } }
Example 18
Source File: JobExecutionResponse.java From FHIR with Apache License 2.0 | 4 votes |
public static JobExecutionResponse parse(InputStream in) throws FHIROperationException { try (JsonReader jsonReader = JSON_READER_FACTORY.createReader(in, StandardCharsets.UTF_8)) { JsonObject jsonObject = jsonReader.readObject(); JobExecutionResponse.Builder builder = JobExecutionResponse.builder(); if (jsonObject.containsKey("jobName")) { String jobName = jsonObject.getString("jobName"); builder.jobName(jobName); } if (jsonObject.containsKey("instanceId")) { Integer instanceId = jsonObject.getInt("instanceId"); builder.instanceId(instanceId); } if (jsonObject.containsKey("appName")) { String appName = jsonObject.getString("appName"); builder.appName(appName); } if (jsonObject.containsKey("batchStatus")) { String batchStatus = jsonObject.getString("batchStatus"); builder.batchStatus(batchStatus); } if (jsonObject.containsKey("exitStatus")) { String exitStatus = jsonObject.getString("exitStatus"); builder.exitStatus(exitStatus); } if (jsonObject.containsKey("jobXMLName")) { String jobXMLName = jsonObject.getString("jobXMLName"); builder.jobXMLName(jobXMLName); } if (jsonObject.containsKey("instanceName")) { String instanceName = jsonObject.getString("instanceName"); builder.instanceName(instanceName); } if (jsonObject.containsKey("lastUpdatedTime")) { String lastUpdatedTime = jsonObject.getString("lastUpdatedTime"); builder.lastUpdatedTime(lastUpdatedTime); } if (jsonObject.containsKey("_links")) { JsonArray arr = jsonObject.getJsonArray("_links"); ListIterator<JsonValue> iter = arr.listIterator(); while (iter.hasNext()) { JsonValue v = iter.next(); JsonObject vObj = v.asJsonObject(); if (vObj.containsKey("rel") && vObj.containsKey("href")) { String rel = vObj.getString("rel"); String href = vObj.getString("href"); builder.link(rel, href); } } } if (jsonObject.containsKey("submitter")) { String submitter = jsonObject.getString("submitter"); builder.submitter(submitter); } if (jsonObject.containsKey("instanceState")) { String instanceState = jsonObject.getString("instanceState"); builder.instanceState(instanceState); } if (jsonObject.containsKey("jobParameters")) { JsonObject obj = jsonObject.getJsonObject("jobParameters"); JobParameter.Parser.parse(builder, obj); } return builder.build(); } catch (Exception e) { throw new FHIROperationException("Problem parsing the Bulk Export Job's response from the server", e); } }
Example 19
Source File: FeatureServiceImpl.java From sling-whiteboard with Apache License 2.0 | 4 votes |
private FeatureExtension[] getExtensions(JsonObject json) { JsonObject jo = json.getJsonObject("extensions"); if (jo == null) return new FeatureExtension[] {}; List<FeatureExtension> extensions = new ArrayList<>(); for (Map.Entry<String,JsonValue> entry : jo.entrySet()) { JsonObject exData = entry.getValue().asJsonObject(); FeatureExtension.Type type; if (exData.containsKey("text")) { type = FeatureExtension.Type.TEXT; } else if (exData.containsKey("artifacts")) { type = FeatureExtension.Type.ARTIFACTS; } else if (exData.containsKey("json")) { type = FeatureExtension.Type.JSON; } else { throw new IllegalStateException("Invalid extension: " + entry); } String k = exData.getString("kind", "optional"); FeatureExtension.Kind kind = FeatureExtension.Kind.valueOf(k.toUpperCase()); FeatureExtensionBuilder builder = builderFactory.newExtensionBuilder(entry.getKey(), type, kind); switch (type) { case TEXT: builder.addText(exData.getString("text")); break; case ARTIFACTS: JsonArray ja2 = exData.getJsonArray("artifacts"); for (JsonValue jv : ja2) { if (jv.getValueType() == JsonValue.ValueType.STRING) { String id = ((JsonString) jv).getString(); builder.addArtifact(ID.fromMavenID(id)); } } break; case JSON: builder.setJSON(exData.getJsonObject("json").toString()); break; } extensions.add(builder.build()); } return extensions.toArray(new FeatureExtension[] {}); }
Example 20
Source File: ExecutionTest.java From smallrye-graphql with Apache License 2.0 | 3 votes |
@Test public void testBasicQuery() { JsonObject data = executeAndGetData(TEST_QUERY); JsonObject testObject = data.getJsonObject("testObject"); assertNotNull(testObject); assertFalse(testObject.isNull("name"), "name should not be null"); assertEquals("Phillip", testObject.getString("name")); assertFalse(testObject.isNull("id"), "id should not be null"); }