List of usage examples for com.google.gson JsonObject add
public void add(String property, JsonElement value)
From source file:com.bmc.gibraltar.automation.dataprovider.RestDataProvider.java
private static JsonObject generateJsonForUserCreation(String fullName, String loginName, String password, String emailAddress, String[] permissionGroups) { JsonObject request = new JsonObject(); request.addProperty("fullName", fullName); request.addProperty("loginName", loginName); request.addProperty("password", password); request.addProperty("emailAddress", emailAddress); request.add("groups", new Gson().toJsonTree(permissionGroups)); return request; }
From source file:com.bmc.gibraltar.automation.dataprovider.RestDataProvider.java
public String startProcessWithInputs(String processDefinitionId, HashMap<String, String> inputs) { JsonObject request = buildRequestToStartProcessInstance(processDefinitionId); JsonObject inputsOfProcessDefinition = new JsonObject(); for (Map.Entry<String, String> entry : inputs.entrySet()) { inputsOfProcessDefinition.addProperty(entry.getKey(), entry.getValue()); }/* w w w . j a v a 2 s . c o m*/ request.add("processInputValues", inputsOfProcessDefinition); String bodyOfRequest = new GsonBuilder().create().toJson(request); return processApi.startProcessInstance(bodyOfRequest).extract().toString(); }
From source file:com.bmc.gibraltar.automation.dataprovider.RestDataProvider.java
@Step public void createTask(String recordDefinitionName, String submitter, String assignee, String statusCode, String summary, String notes, String taskName, String priorityCode, String dueDate) { JsonObject bodyRequest = new JsonObject(); bodyRequest.addProperty("resourceType", "com.bmc.arsys.rx.services.record.domain.RecordInstance"); bodyRequest.addProperty("recordDefinitionName", recordDefinitionName); // fields to create a record instance JsonObject recordProperty = new JsonObject(); addRecordFieldToRequest(recordProperty, "2", submitter); // submitter of the record instance addRecordFieldToRequest(recordProperty, "4", assignee); // assignee addRecordFieldToRequest(recordProperty, "7", statusCode); // status: 0 ( staged ) addRecordFieldToRequest(recordProperty, "8", summary); // summary addRecordFieldToRequest(recordProperty, "10000101", notes); // notes addRecordFieldToRequest(recordProperty, "10007000", taskName); // task-name addRecordFieldToRequest(recordProperty, "10007122", priorityCode); // priority: 2 ( medium ) addRecordFieldToRequest(recordProperty, "536870913", dueDate); // due date bodyRequest.add("fieldInstances", recordProperty); String request = new GsonBuilder().create().toJson(bodyRequest); recordApi.createRecordInstance(request); }
From source file:com.bmc.gibraltar.automation.dataprovider.RestDataProvider.java
@Step public void updateTask(String taskGuid, String fieldToUpdate, String newFieldValue) { JsonObject bodyRequest = new JsonObject(); bodyRequest.addProperty("resourceType", "com.bmc.arsys.rx.services.record.domain.RecordInstance"); bodyRequest.addProperty("id", taskGuid); bodyRequest.addProperty("recordDefinitionName", RestApiData.TASK_RECORD_DEFINITION); JsonObject recordProperty = new JsonObject(); addRecordFieldToRequest(recordProperty, fieldToUpdate, newFieldValue); // submitter of the record instance bodyRequest.add("fieldInstances", recordProperty); String request = new GsonBuilder().create().toJson(bodyRequest); recordApi.updateRecordInstance(RestApiData.TASK_RECORD_DEFINITION, taskGuid, request); }
From source file:com.bmc.gibraltar.automation.dataprovider.RestDataProvider.java
private JsonObject addRecordFieldToRequest(JsonObject recordProperty, String fieldId, String fieldValue) { JsonObject nestedArray = new JsonObject(); nestedArray.addProperty("resourceType", "com.bmc.arsys.rx.services.record.domain.FieldInstance"); nestedArray.addProperty("id", fieldId); nestedArray.addProperty("value", fieldValue); recordProperty.add(fieldId, nestedArray); return recordProperty; }
From source file:com.bosch.osmi.bdp.access.mock.generator.MockDataGenerator.java
License:Open Source License
private void evaluate(Object object, JsonObject parent) throws InvocationTargetException, IllegalAccessException { Class<?>[] types = object.getClass().getInterfaces(); if (types != null && types.length > 0) { // TODO proably check if the interface is annotated with a marker that says that this is actually part of the Bdp API for (Class<?> type : types) { LOGGER.info("Evaluate methods of type " + type.getName()); JsonObject jsonObject = new JsonObject(); parent.add(type.getCanonicalName(), jsonObject); executeMethodsOfType(type, object, jsonObject); }/*ww w . j a v a 2 s .c o m*/ } }
From source file:com.bosch.osmi.bdp.access.mock.generator.MockDataGenerator.java
License:Open Source License
private void executeMethodsOfType(Class<?> type, Object object, JsonObject parent) throws InvocationTargetException, IllegalAccessException { Method[] methods = type.getMethods(); for (Method method : methods) { LOGGER.info("Evaluate method " + method.getName()); Object result = method.invoke(object); if (result == null) { System.out.println(); throw new IllegalStateException("Return value is null. Cannot be processed."); }/*from w w w . j a va 2 s . c o m*/ if (result instanceof String) { parent.addProperty(method.getName(), (String) result); } else if (result instanceof Boolean) { parent.addProperty(method.getName(), (Boolean) result); } else if (result instanceof Collection<?>) { JsonArray entries = new JsonArray(); parent.add(method.getName(), entries); evaluateElements((Collection<?>) result, entries); } else if (result instanceof BdpEntity) { JsonObject jsonObject = new JsonObject(); parent.add(method.getName(), jsonObject); evaluate(result, jsonObject); } else { throw new IllegalStateException( "Return value not of any processable type " + result.getClass().getCanonicalName()); } } }
From source file:com.canoo.dolphin.impl.codec.CreatePresentationModelEncoder.java
License:Apache License
@Override public JsonObject encode(CreatePresentationModelCommand command) { Assert.requireNonNull(command, "command"); final JsonObject jsonCommand = new JsonObject(); jsonCommand.addProperty(PM_ID, command.getPmId()); jsonCommand.addProperty(PM_TYPE, command.getPmType()); final JsonArray jsonArray = new JsonArray(); for (final Map<String, Object> attribute : command.getAttributes()) { final JsonObject jsonAttribute = new JsonObject(); jsonAttribute.addProperty(ATTRIBUTE_NAME, String.valueOf(attribute.get("propertyName"))); jsonAttribute.addProperty(ATTRIBUTE_ID, String.valueOf(attribute.get("id"))); final Object value = attribute.get("value"); if (value != null) { jsonAttribute.add(ATTRIBUTE_VALUE, encodeValue(attribute.get("value"))); }/* w w w.j a v a 2s.c o m*/ jsonArray.add(jsonAttribute); } jsonCommand.add(PM_ATTRIBUTES, jsonArray); jsonCommand.addProperty(ID, "CreatePresentationModel"); return jsonCommand; }
From source file:com.canoo.dolphin.impl.codec.ValueChangedCommandEncoder.java
License:Apache License
@Override public JsonObject encode(ValueChangedCommand command) { Assert.requireNonNull(command, "command"); final JsonObject jsonCommand = new JsonObject(); jsonCommand.addProperty("a", command.getAttributeId()); if (command.getOldValue() != null) { jsonCommand.add("o", encodeValue(command.getOldValue())); }/*from w w w . jav a 2 s . c o m*/ if (command.getNewValue() != null) { jsonCommand.add("n", encodeValue(command.getNewValue())); } jsonCommand.addProperty("id", "ValueChanged"); return jsonCommand; }
From source file:com.canoo.dolphin.server.mbean.beans.ModelJsonSerializer.java
License:Apache License
public static JsonObject toJson(Object dolphinModel) { if (dolphinModel == null) { return null; }/* w w w.ja v a 2 s . c o m*/ JsonObject jsonObject = new JsonObject(); for (Field field : ReflectionHelper.getInheritedDeclaredFields(dolphinModel.getClass())) { if (ReflectionHelper.isProperty(field.getType())) { Property property = (Property) ReflectionHelper.getPrivileged(field, dolphinModel); Object value = property.get(); if (value == null) { jsonObject.add(field.getName(), null); } else if (Number.class.isAssignableFrom(value.getClass()) || Double.TYPE.isAssignableFrom(value.getClass()) || Float.TYPE.isAssignableFrom(value.getClass()) || Long.TYPE.isAssignableFrom(value.getClass()) || Integer.TYPE.isAssignableFrom(value.getClass())) { jsonObject.add(field.getName(), new JsonPrimitive((Number) value)); } else if (String.class.isAssignableFrom(value.getClass())) { jsonObject.add(field.getName(), new JsonPrimitive((String) value)); } else if (Boolean.class.isAssignableFrom(value.getClass()) || Boolean.TYPE.isAssignableFrom(value.getClass())) { jsonObject.add(field.getName(), new JsonPrimitive((Boolean) value)); } else { jsonObject.add(field.getName(), toJson(value)); } } else if (ReflectionHelper.isObservableList(field.getType())) { ObservableList list = (ObservableList) ReflectionHelper.getPrivileged(field, dolphinModel); JsonArray jsonArray = new JsonArray(); for (Object value : list) { if (value == null) { //TODO //jsonArray.add(null); } else if (Number.class.isAssignableFrom(value.getClass()) || Double.TYPE.isAssignableFrom(value.getClass()) || Float.TYPE.isAssignableFrom(value.getClass()) || Long.TYPE.isAssignableFrom(value.getClass()) || Integer.TYPE.isAssignableFrom(value.getClass())) { jsonArray.add(new JsonPrimitive((Number) value)); } else if (String.class.isAssignableFrom(value.getClass())) { jsonArray.add(new JsonPrimitive((String) value)); } else if (Boolean.class.isAssignableFrom(value.getClass()) || Boolean.TYPE.isAssignableFrom(value.getClass())) { jsonArray.add(new JsonPrimitive((Boolean) value)); } else { jsonArray.add(toJson(value)); } } jsonObject.add(field.getName(), jsonArray); } } return jsonObject; }