private StringBuffer dumpAllToString() { StringBuffer buffer = new StringBuffer(); for(String k : allNotifications.keySet()) { JsonObject o = allNotifications.get(k); String json = JsonUtils.toString(o); buffer.append(json); buffer.append("\n"); } return buffer; } }
/** * Called by spring on bean initialisation, loads all serialized * notifications into allNotifications. */ public void deserializeAllNotifications() { String notificationsFolderPath = platformProperties.getProperty("localNotificationsFolderPath"); notificationsFilePath = notificationsFolderPath + File.separator + "local_notifications.txt"; final File file = new File(notificationsFilePath); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } if (file.exists()) { try { List<String> alllines = Files.readAllLines(file.toPath()); for (String line : alllines) { JsonObject jsonObject = JsonUtils.toJsonObject(line); String uuid = jsonObject.get("uuid").getAsString(); allNotifications.put(uuid, jsonObject); } } catch (IOException e) { e.printStackTrace(); } } }
Object querySpec = JsonUtils.getJsonString(query, "querySpec"); Object effectivity = JsonUtils.getJsonString(query, "effectivity"); Object linkClass = JsonUtils.getJsonString(query, "linkClass"); Integer page = JsonUtils.getJsonInt(query, "page", 0); Integer pageSize = JsonUtils.getJsonInt(query, "pageSize", -1); String sort = JsonUtils.getJsonString(query, "sort"); String audience = JsonUtils.getJsonString(query, "audience"); String queryPredicate = JsonUtils.getJsonString(query, "queryPredicate"); Object linkConstraintName = JsonUtils.getJsonString(query, "linkConstraintName", "");
RequestBody body = RequestBody.create(JSON, JsonUtils.toString(query)); Request request = new Request.Builder() .url(url) T o = JsonUtils.toJsonObject(response.body().string(), clazz); response.body().close(); return o;
/** * @{inheritedDoc} */ @Override public IOperationResult getAllLifecycles(JsonObject query) { try { String oid = query.get("containerOid").getAsString(); Object page = JsonUtils.getJsonInt(query, "page", 0); Object pageSize = JsonUtils.getJsonInt(query, "pageSize", -1); String byPathUrl = rootUrl.concat(String.format(GET_ALL_LFC_URL, oid, page, pageSize)); IOperationResult result = doGet(query, byPathUrl, MultipleResult.class); return result; } catch (Exception e) { e.printStackTrace(); return IOperationResult.generalMultipleResutError(); } }
private List<OperationData> toOperationData(List<JsonObject> jsonObjects) { List<OperationData> datas = new ArrayList<OperationData>(); for (JsonObject obj : jsonObjects) { OperationData operationData = new OperationData.Builder().attributes(JsonUtils.toMap(obj)).build(); datas.add(operationData); } return datas; }
RequestBody body = RequestBody.create(JSON, JsonUtils.toString(query)); Request request = null; T o = JsonUtils.toJsonObject(response.body().string(), clazz); response.body().close(); return o;
/** * @{inheritedDoc} */ @Override public IOperationResult getPaginatedRoleBsIterations(JsonObject query) { try { String oid = query.get("oid").getAsString(); String linkConstraintName = query.get("linkConstraintName").getAsString(); String linkClass = query.get("linkClass").getAsString(); Integer page = JsonUtils.getJsonInt(query,"page"); Integer pageSize = JsonUtils.getJsonInt(query,"pageSize"); String byOidUrl = rootUrl.concat(String.format(GET_PAGINATED_ROLEBs_ULR_ITERATIONS, oid, linkConstraintName, linkClass, pageSize.toString(), page.toString())); IOperationResult result = doGet(null, byOidUrl, MultipleResult.class); return result; } catch (Exception e) { e.printStackTrace(); return IOperationResult.generalMultipleResutError(); } }
@Override public void init() { if ((loginSessionHolder != null) && (loginSessionHolder.getLoginResult() != null)) { final OperationData data = (OperationData) loginSessionHolder.getLoginResult().rootData(); container = JsonUtils.toJsonObject((String)data.getLinks().get("container")); user = JsonUtils.toJsonObject((String)data.getLinks().get("user")); account = JsonUtils.toJsonObject((String)data.getLinks().get("account")); mode = loginSessionHolder.getMode() == null ? RootContextMode.Connected : loginSessionHolder.getMode(); } }
/** * @return */ public String toJson() { if (entry == null) { return null; } return JsonUtils.toString(entry.get()); } }
/** * @{inheritedDoc} */ @Override public IOperationResult paginateRc(JsonObject query) { try { String fullId = query.get("oid").getAsString(); String containerOid = query.get("containerOid").getAsString(); Integer page = JsonUtils.getJsonInt(query,"page"); Integer pageSize = JsonUtils.getJsonInt(query,"pageSize"); String sort = JsonUtils.getJsonString(query,"sort"); String audience = JsonUtils.getJsonString(query,"audience"); String queryPredicate = JsonUtils.getJsonString(query, "queryPredicate"); String url = rootUrl.concat(String.format(PAGINATE_RC_URI, fullId, page, pageSize, sort, audience, containerOid, queryPredicate)); IOperationResult result = doGet(query, url, MultipleResult.class); return result; } catch (Exception e) { e.printStackTrace(); return IOperationResult.generalMultipleResutError(); } } }
/** * @throws OperationException * @{inheritedDoc} */ @Override public IOperationResult createNotification(JsonObject query) throws OperationException { try { String notif = query.get("notification").getAsString(); JsonObject jsonObject = JsonUtils.toJsonObject(notif); String uuid = UUID.randomUUID().toString(); jsonObject.addProperty("uuid", uuid); allNotifications.put(uuid, jsonObject); // dump all line to file StringBuffer buffer = dumpAllToString(); Files.write(new File(notificationsFilePath).toPath(), buffer.toString().getBytes(), StandardOpenOption.TRUNCATE_EXISTING); SingleResult result = new SingleResult.Builder().addMeta("done", "1").build(); return result; } catch (IOException e) { e.printStackTrace(); throw new OperationException(e); } }
@Override public void doOperation(JsonObject params, Consumer<IOperationResult> resultHandler, Consumer<Throwable> exHandler) { final SingleResult sr = new SingleResult(); final Serializable sessionId = UUID.randomUUID().toString(); sr.addMetaData("session_id", sessionId); final OperationData operationData = new OperationData(); sr.setData(operationData); JsonObject account = new JsonObject(); account.addProperty("login", "lorenzo@nexitia.com"); account.addProperty("nickName", "lorenzo"); final JsonObject user = new JsonObject(); user.addProperty("nickName", "lorenzo"); account.addProperty("mail", "lorenzo@nexitia.com"); final JsonObject container = new JsonObject(); container.addProperty("fullId", "1:people"); container.addProperty("path", "/"); operationData.getLinks().put("container", JsonUtils.toString(container)); operationData.getLinks().put("account", JsonUtils.toString(account)); operationData.getLinks().put("user", JsonUtils.toString(user)); resultHandler.accept(sr); } }
Object querySpec = JsonUtils.getJsonString(query, "querySpec"); Object effectivity = JsonUtils.getJsonString(query, "effectivity"); Object linkClass = JsonUtils.getJsonString(query, "linkClass"); Integer page = JsonUtils.getJsonInt(query, "page", 0); Integer pageSize = JsonUtils.getJsonInt(query, "pageSize", -1); String sort = JsonUtils.getJsonString(query, "sort"); String audience = JsonUtils.getJsonString(query,"audience"); String queryPredicate = JsonUtils.getJsonString(query,"queryPredicate");
@Override public void onResponse(Response response) throws IOException { try { IOperationResult o = JsonUtils.toJsonObject(response.body().string(), clazz); resHandler.accept(o); } catch (IOException e) { e.printStackTrace(); } finally { response.body().close(); } }
/** * @{inheritedDoc} */ @Override public void create(INotification notification, OperationCallback callback) { // can only create local notifications if (notification.getType() == NotificationType.LOCAL) { if (offlineSaveOperation == null) { String message = "can.not.find.service"; callback.onError(new NullPointerException(message)); return; } try { String notif = JsonUtils.toString(notification); JsonObject query = new JsonObject(); query.addProperty("notification", notif); query.addProperty("date", DateUtils.dateString(notification.getCreationDate(), DateUtils.FILE_SAVE_FORMAT)); offlineSaveOperation.doOperation(query, callback.getOnSuccess(), callback.getOnError()); } catch (Exception e) { e.printStackTrace(); callback.onError(e); } } else { String message = "unsupported.notification.type"; callback.onError(new IllegalArgumentException(message)); } }
/** * @{inheritedDoc} */ @Override public IOperationResult getFolderTemplates(JsonObject query) { try { final String containerOid = query.get("containerOid").getAsString(); final Integer page = JsonUtils.getJsonInt(query, "page", 0); final Integer pageSize = JsonUtils.getJsonInt(query,"pageSize", 20); final String sort = JsonUtils.getJsonString(query,"sort", ""); final String audience = JsonUtils.getJsonString(query,"audience", ""); final String url = rootUrl.concat(String.format(URI_FT, containerOid, page, pageSize, sort, audience)); final IOperationResult result = doGet(query, url, MultipleResult.class); return result; } catch (final Exception e) { e.printStackTrace(); return IOperationResult.generalMultipleResutError(); } }
JsonObject jsonObject = JsonUtils.toJsonObject(jsonString);
/** * @{inheritedDoc} */ @Override public void editCommit(IEmaginController sourceController, VLViewComponentXML inlineActionConfiguration, List<IInputComponentWrapper> rows) { IPersistenceServiceDelegate.super.editCommit(sourceController, inlineActionConfiguration, rows); String action = inlineActionConfiguration.getPropertyValue(ACTION_NAME); Map<String, Object> vals = extracValue(rows); vals.put(HIDDEN_PREFIX + ACTION_NAME, action); // commit all mofications in same controller IInputComponentWrapper row0 = rows.get(0); Object model = row0.getController().getModel(); String rootModelOid = (String) ReflectionUIUtils.invokeGetterOn(model, DATA_TYPE); int version = (Integer) ReflectionUIUtils.invokeGetterOn(model, DATA_ATTRIBUTES_VERSION); vals.put(HIDDEN_PREFIX + PERSISTENCE_FULL_ID, rootModelOid); vals.put(HIDDEN_PREFIX + PERSISTENCE_VERSION, version); //persistableUpdateOperation.doOperation(JsonObject.fromObject(vals), this::successHandler, getErrorHandler()); persistableUpdateOperation.doOperation(JsonUtils.toJsonObject(vals), this::successHandler, getErrorHandler()); }
T o = JsonUtils.toJsonObject(response.body().string(), clazz); response.body().close(); return o;