/** * @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); } }
return new SingleResult.Builder().build();
/** * @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); } }
/** * Pointcut around {@link IOperation#doOperation(java.util.Map)} * * @param pjp * @return * @throws Throwable */ //@Around("execution (* public com.nexitia.emaginplatform.core.commons.bridge.*.doOperation(..)") //public Object checkServerStatusBeforeCall(ProceedingJoinPoint pjp) throws Throwable { public Object checkServerStatusBeforeCall() throws Throwable { if (clientStatus.isDown()) { return CompletableFuture.supplyAsync(() -> { OperationMessage message = new OperationMessageBuilder() .title(bundle.getString("SERVER_DOWN_MESSAGE_TITLE")) .detail(bundle.getString("SERVER_DOWN_MESSAGE_BODY")) .build(); return new SingleResult.Builder().addMessage(message).build(); }); } // return pjp.proceed(); return null; } }
/** * @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); } }
/** * @{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); } }
/** * @{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); }