use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project weave by continuuity.
the class WeaveRunnableSpecificationCodec method serialize.
@Override
public JsonElement serialize(WeaveRunnableSpecification src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject json = new JsonObject();
json.addProperty("classname", src.getClassName());
json.addProperty("name", src.getName());
json.add("arguments", context.serialize(src.getConfigs(), new TypeToken<Map<String, String>>() {
}.getType()));
return json;
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project weave by continuuity.
the class WeaveRunnableSpecificationCodec method deserialize.
@Override
public WeaveRunnableSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObj = json.getAsJsonObject();
String className = jsonObj.get("classname").getAsString();
String name = jsonObj.get("name").getAsString();
Map<String, String> arguments = context.deserialize(jsonObj.get("arguments"), new TypeToken<Map<String, String>>() {
}.getType());
return new DefaultWeaveRunnableSpecification(className, name, arguments);
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project openhab1-addons by openhab.
the class WithingsApiClient method call.
private JsonObject call(String signedUrl) throws IOException, MalformedURLException, WithingsConnectionException, UnsupportedEncodingException {
HttpURLConnection httpURLConnection;
httpURLConnection = (HttpURLConnection) new URL(signedUrl).openConnection();
httpURLConnection.connect();
int responseCode = httpURLConnection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new WithingsConnectionException("Illegal response code: " + responseCode);
}
Reader reader = null;
try {
InputStream inputStream = httpURLConnection.getInputStream();
reader = new InputStreamReader(inputStream, "UTF-8");
JsonObject jsonObject = (JsonObject) jsonParser.parse(reader);
return jsonObject;
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignored) {
}
}
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project Engine by VoltzEngine-Project.
the class ModelStateJsonProcessor method process.
@Override
public IRenderState process(JsonObject renderStateObject, String stateID, String globalRenderType, String subRenderType) {
ModelState renderState;
//Data
String modelID = null;
Pos offset = null;
Pos scale = null;
EulerAngle rotation = null;
//Load model ID, child objects may or may not contain this
if (renderStateObject.has("modelID")) {
modelID = renderStateObject.get("modelID").getAsString();
}
//Loads position offset
if (renderStateObject.has("offset")) {
offset = JsonConverterPos.fromJson(renderStateObject.get("offset"));
if (offset == null) {
throw new IllegalArgumentException("Unknown value type for offset " + renderStateObject.get("offset"));
}
}
//Loads scale value
if (renderStateObject.has("scale")) {
scale = JsonConverterPos.fromJson(renderStateObject.get("scale"));
if (scale == null) {
throw new IllegalArgumentException("Unknown value type for scale " + renderStateObject.get("scale"));
}
}
//Loads rotations
if (renderStateObject.has("rotation")) {
JsonObject rotationObject = renderStateObject.get("rotation").getAsJsonObject();
double yaw = 0;
double pitch = 0;
double roll = 0;
if (rotationObject.has("yaw")) {
yaw = rotationObject.getAsJsonPrimitive("yaw").getAsDouble();
}
if (rotationObject.has("pitch")) {
pitch = rotationObject.getAsJsonPrimitive("pitch").getAsDouble();
}
if (rotationObject.has("roll")) {
roll = rotationObject.getAsJsonPrimitive("roll").getAsDouble();
}
rotation = new EulerAngle(yaw, pitch, roll);
}
//Creates state object
if (globalRenderType.equalsIgnoreCase("tile")) {
renderState = new TileState(stateID, modelID, offset, scale, rotation);
} else {
renderState = new ModelState(stateID, modelID, offset, scale, rotation);
}
if (renderStateObject.has("renderOnlyParts")) {
renderState.renderOnlyParts = renderStateObject.get("renderOnlyParts").getAsBoolean();
}
if (renderStateObject.has("renderParent")) {
renderState.renderParent = renderStateObject.get("renderParent").getAsBoolean();
}
//Loads parts to render if all is not selected
if (renderStateObject.has("parts")) {
String parts = renderStateObject.get("parts").getAsString();
if (!parts.equals("all")) {
renderState.parts = parts.split(",");
}
}
return renderState;
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project Engine by VoltzEngine-Project.
the class RenderJsonProcessor method process.
@Override
public RenderData process(JsonElement element) {
final JsonObject object = element.getAsJsonObject();
ensureValuesExist(object, "contentID", "states", "type");
String contentID = object.get("contentID").getAsString();
String overAllRenderType = object.get("type").getAsString();
RenderData data;
if (overAllRenderType.equalsIgnoreCase("tile")) {
data = new TileRenderData(this, contentID, overAllRenderType);
if (object.has("tileClass")) {
try {
((TileRenderData) data).tileClass = (Class<? extends TileEntity>) Class.forName(object.get("tileClass").getAsString());
} catch (Exception e) {
throw new IllegalArgumentException("Failed to load class for name '" + object.get("tileClass").getAsString() + "'");
}
}
} else {
data = new RenderData(this, contentID, overAllRenderType);
}
JsonArray array = object.get("states").getAsJsonArray();
for (JsonElement arrayElement : array) {
if (arrayElement instanceof JsonObject) {
JsonObject renderStateObject = arrayElement.getAsJsonObject();
//For loop handling for the lazy
if (renderStateObject.has("for")) {
renderStateObject = renderStateObject.getAsJsonObject("for");
ensureValuesExist(renderStateObject, "start", "end", "state");
int start = renderStateObject.getAsJsonPrimitive("start").getAsInt();
int end = renderStateObject.getAsJsonPrimitive("end").getAsInt();
if (start >= end) {
throw new IllegalArgumentException("Start can not be greater than or equal to end for a for loop.");
}
JsonObject template = renderStateObject.getAsJsonObject("state");
for (int i = start; i <= end; i++) {
JsonObject state = new JsonObject();
//Copy template and rename values as needed
for (Map.Entry<String, JsonElement> entry : template.entrySet()) {
if (entry.getValue() instanceof JsonPrimitive && ((JsonPrimitive) entry.getValue()).isString()) {
String s = entry.getValue().getAsString();
s = s.replace("%number%", "" + i);
state.add(entry.getKey(), new JsonPrimitive(s));
} else {
state.add(entry.getKey(), entry.getValue());
}
}
//Load state
handle(state, data, overAllRenderType);
}
} else {
handle(renderStateObject, data, overAllRenderType);
}
}
}
//Handle post calls
for (IRenderState state : data.renderStatesByName.values()) {
//Handles post processor actions
if (stateToProcessor.containsKey(state)) {
stateToProcessor.get(state).postHandle(state, data);
}
}
//Clear run data
stateToProcessor.clear();
//TODO ensure modelID exists if model state
return data;
}
Aggregations