/** * @throws OperationException * @{inheritedDoc} */ @Override public IOperationResult setStatus(JsonObject query) throws OperationException { try { String uuids = query.get("uuids").getAsString(); String status = query.get("status").getAsString(); Arrays.asList(uuids.split(";")).forEach(uuid -> { JsonObject jsonObject = allNotifications.get(uuid); jsonObject.addProperty("status", status); }); // 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); } }
/** * @{inheritedDoc} */ @Override public IOperationResult markAllNotificationsReaden(JsonObject query) throws OperationException { try { allNotifications.forEach((key, value) -> value.addProperty("status", "READEN")); // 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); } }
/** * @throws OperationException * @{inheritedDoc} */ @Override public IOperationResult deleteNotification(JsonObject query) throws OperationException { try { String uuid = query.get("uuid").getAsString(); allNotifications.remove(uuid); // 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); } }
/** * @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); } }
/** * @{inheritedDoc} */ @Override public IOperationResult deleteAllNotifications(JsonObject query) throws OperationException { try { allNotifications.clear(); // 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); } }
/** * {@inheritDoc} */ @Override public void doOperation(JsonObject params, Consumer<IOperationResult> resultHandler, Consumer<Throwable> exHandler) { final SingleResult res = new SingleResult.Builder().addMeta("Bye", "Bye").build(); resultHandler.accept(res); }