Example usage for io.vertx.core.json JsonArray size

List of usage examples for io.vertx.core.json JsonArray size

Introduction

In this page you can find the example usage for io.vertx.core.json JsonArray size.

Prototype

public int size() 

Source Link

Document

Get the number of values in this JSON array

Usage

From source file:org.entcore.communication.services.impl.DefaultCommunicationService.java

License:Open Source License

@Override
public void visibleUsers(String userId, String structureId, JsonArray expectedTypes, boolean itSelf,
        boolean myGroup, boolean profile, String preFilter, String customReturn, JsonObject additionnalParams,
        String userProfile, final Handler<Either<String, JsonArray>> handler) {
    StringBuilder query = new StringBuilder();
    JsonObject params = new JsonObject();
    String condition = itSelf ? "" : "AND m.id <> {userId} ";
    StringBuilder union = null;//  ww w  .  j ava 2 s . c o  m
    String conditionUnion = itSelf ? "" : "AND m.id <> {userId} ";
    if (structureId != null && !structureId.trim().isEmpty()) {
        query.append("MATCH (n:User)-[:COMMUNIQUE*1..3]->m-[:DEPENDS*1..2]->(s:Structure {id:{schoolId}})"); //TODO manage leaf
        params.put("schoolId", structureId);
    } else {
        String l = (myGroup) ? " (length(p) >= 2 OR m.users <> 'INCOMING')" : " length(p) >= 2";
        query.append(
                " MATCH p=(n:User)-[:COMMUNIQUE*0..2]->ipg" + "-[:COMMUNIQUE*0..1]->g<-[:DEPENDS*0..1]-m ");
        condition += "AND ((" + l
                + " AND (length(p) < 3 OR (ipg:Group AND (m:User OR g<-[:DEPENDS]-m) AND length(p) = 3)))) ";
        if (userProfile == null || "Student".equals(userProfile) || "Relative".equals(userProfile)) {
            union = new StringBuilder("MATCH p=(n:User)-[:COMMUNIQUE_DIRECT]->m "
                    + "WHERE n.id = {userId} AND (NOT(HAS(m.blocked)) OR m.blocked = false) ");
        }
    }
    query.append("WHERE n.id = {userId} AND (NOT(HAS(m.blocked)) OR m.blocked = false) ");
    if (preFilter != null) {
        query.append(preFilter);
        if (union != null) {
            union.append(preFilter);
            union.append(conditionUnion);
        }
    }
    query.append(condition);
    if (expectedTypes != null && expectedTypes.size() > 0) {
        query.append("AND (");
        StringBuilder types = new StringBuilder();
        for (Object o : expectedTypes) {
            if (!(o instanceof String))
                continue;
            String t = (String) o;
            types.append(" OR m:").append(t);
        }
        query.append(types.substring(4)).append(") ");
        if (union != null) {
            union.append("AND (").append(types.substring(4)).append(") ");
        }
    }
    String pcr = " ";
    String pr = "";
    if (profile) {
        query.append(
                "OPTIONAL MATCH m-[:IN*0..1]->pgp-[:DEPENDS*0..1]->(pg:ProfileGroup)-[:HAS_PROFILE]->(profile:Profile) ");
        pcr = ", profile ";
        pr = "profile.name as type, ";
        if (union != null) {
            union.append(
                    "OPTIONAL MATCH m-[:IN*0..1]->pgp-[:DEPENDS*0..1]->(pg:ProfileGroup)-[:HAS_PROFILE]->(profile:Profile) ");
        }
    }
    if (customReturn != null && !customReturn.trim().isEmpty()) {
        query.append("WITH DISTINCT m as visibles").append(pcr);
        query.append(customReturn);
        if (union != null) {
            union.append("WITH DISTINCT m as visibles").append(pcr);
            union.append(customReturn);
        }
    } else {
        query.append("RETURN distinct m.id as id, m.name as name, "
                + "m.login as login, m.displayName as username, ").append(pr)
                .append("m.lastName as lastName, m.firstName as firstName, m.profiles as profiles "
                        + "ORDER BY name, username ");
        if (union != null) {
            union.append("RETURN distinct m.id as id, m.name as name, "
                    + "m.login as login, m.displayName as username, ").append(pr)
                    .append("m.lastName as lastName, m.firstName as firstName, m.profiles as profiles "
                            + "ORDER BY name, username ");
        }
    }
    params.put("userId", userId);
    if (additionnalParams != null) {
        params.mergeIn(additionnalParams);
    }
    String q;
    if (union != null) {
        q = query.append(" union ").append(union.toString()).toString();
    } else {
        q = query.toString();
    }
    neo4j.execute(q, params, validResultHandler(handler));
}

From source file:org.entcore.conversation.controllers.ConversationController.java

License:Open Source License

@Put("move/userfolder/:folderId")
@SecuredAction(value = "", type = ActionType.RESOURCE)
@ResourceFilter(FoldersMessagesFilter.class)
public void move(final HttpServerRequest request) {
    final String folderId = request.params().get("folderId");
    bodyToJson(request, new Handler<JsonObject>() {
        @Override/*from   w w  w. j  av a 2 s .  c om*/
        public void handle(JsonObject body) {
            final JsonArray messageIds = body.getJsonArray("id");
            if (messageIds == null || messageIds.size() == 0) {
                badRequest(request);
                return;
            }

            Handler<UserInfos> userInfosHandler = new Handler<UserInfos>() {
                public void handle(final UserInfos user) {
                    if (user == null) {
                        unauthorized(request);
                        return;
                    }
                    conversationService.moveToFolder(messageIds.getList(), folderId, user,
                            defaultResponseHandler(request));
                }
            };

            UserUtils.getUserInfos(eb, request, userInfosHandler);

        }
    });
}

From source file:org.entcore.conversation.filters.VisiblesFilter.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public void authorize(HttpServerRequest request, Binding binding, final UserInfos user,
        final Handler<Boolean> handler) {

    final String parentMessageId = request.params().get("In-Reply-To");
    final Set<String> ids = new HashSet<>();
    final String customReturn = "WHERE visibles.id IN {ids} RETURN DISTINCT visibles.id";
    final JsonObject params = new JsonObject();

    RequestUtils.bodyToJson(request, new Handler<JsonObject>() {
        public void handle(final JsonObject message) {
            ids.addAll(message.getJsonArray("to", new fr.wseduc.webutils.collections.JsonArray()).getList());
            ids.addAll(message.getJsonArray("cc", new fr.wseduc.webutils.collections.JsonArray()).getList());

            final Handler<Void> checkHandler = new Handler<Void>() {
                public void handle(Void v) {
                    params.put("ids", new fr.wseduc.webutils.collections.JsonArray(new ArrayList<>(ids)));
                    findVisibles(neo.getEventBus(), user.getUserId(), customReturn, params, true, true, false,
                            new Handler<JsonArray>() {
                                public void handle(JsonArray visibles) {
                                    handler.handle(visibles.size() == ids.size());
                                }/*from  w  w  w.j  av a  2  s. c om*/
                            });
                }
            };

            if (parentMessageId == null || parentMessageId.trim().isEmpty()) {
                checkHandler.handle(null);
                return;
            }

            sql.prepared("SELECT m.*  " + "FROM conversation.messages m " + "WHERE m.id = ?",
                    new fr.wseduc.webutils.collections.JsonArray().add(parentMessageId),
                    SqlResult.validUniqueResultHandler(new Handler<Either<String, JsonObject>>() {
                        public void handle(Either<String, JsonObject> parentMsgEvent) {
                            if (parentMsgEvent.isLeft()) {
                                handler.handle(false);
                                return;
                            }

                            JsonObject parentMsg = parentMsgEvent.right().getValue();
                            ids.remove(parentMsg.getString("from"));
                            ids.removeAll(
                                    parentMsg.getJsonArray("to", new fr.wseduc.webutils.collections.JsonArray())
                                            .getList());
                            ids.removeAll(
                                    parentMsg.getJsonArray("cc", new fr.wseduc.webutils.collections.JsonArray())
                                            .getList());

                            checkHandler.handle(null);
                        }
                    }, "cc", "to"));
        }
    });

}

From source file:org.entcore.conversation.service.impl.DefaultConversationService.java

License:Open Source License

private void addDisplayNames(final JsonObject message, final Handler<JsonObject> handler) {
    String query = "MATCH (v:Visible) " + "WHERE v.id IN {ids} "
            + "RETURN COLLECT(distinct (v.id + '$' + coalesce(v.displayName, ' ') + '$' + "
            + "coalesce(v.name, ' ') + '$' + coalesce(v.groupDisplayName, ' '))) as displayNames ";
    Set<String> ids = new HashSet<>();
    ids.addAll(message.getJsonArray("to", new fr.wseduc.webutils.collections.JsonArray()).getList());
    ids.addAll(message.getJsonArray("cc", new fr.wseduc.webutils.collections.JsonArray()).getList());
    if (message.containsKey("from")) {
        ids.add(message.getString("from"));
    }/*from ww w .j a  va2  s . c  o m*/
    neo.execute(query,
            new JsonObject().put("ids", new fr.wseduc.webutils.collections.JsonArray(new ArrayList<>(ids))),
            new Handler<Message<JsonObject>>() {
                @Override
                public void handle(Message<JsonObject> m) {
                    JsonArray r = m.body().getJsonArray("result");
                    if ("ok".equals(m.body().getString("status")) && r != null && r.size() == 1) {
                        JsonObject j = r.getJsonObject(0);
                        JsonArray d = j.getJsonArray("displayNames");
                        if (d != null && d.size() > 0) {
                            message.put("displayNames", d);
                        }
                    }
                    handler.handle(message);
                }
            });
}

From source file:org.entcore.conversation.service.impl.DefaultConversationService.java

License:Open Source License

private void send(final String parentMessageId, final String messageId, final UserInfos user,
        final Handler<Either<String, JsonObject>> result) {
    if (validationParamsError(user, result, messageId))
        return;//  www.  j  a  va2 s  . c  o  m

    String attachmentsRetrieval = "MATCH (message:ConversationMessage)<-[link:HAS_CONVERSATION_MESSAGE]-(:ConversationSystemFolder)"
            + "<-[:HAS_CONVERSATION_FOLDER]-(c:Conversation) "
            + "WHERE message.id = {messageId} AND message.state = {draft} AND message.from = {userId} AND c.userId = {userId} AND c.active = {true} "
            + "OPTIONAL MATCH (message)-[:HAS_ATTACHMENT]->(a: MessageAttachment) "
            + "WHERE a.id IN link.attachments "
            + "WITH CASE WHEN a IS NULL THEN [] ELSE collect({id: a.id, size: a.size}) END as attachments "
            + "RETURN attachments";

    JsonObject params = new JsonObject().put("userId", user.getUserId()).put("messageId", messageId)
            .put("draft", State.DRAFT.name()).put("true", true);

    neo.execute(attachmentsRetrieval, params,
            validUniqueResultHandler(new Handler<Either<String, JsonObject>>() {
                public void handle(Either<String, JsonObject> event) {
                    if (event.isLeft() || event.isRight() && event.right().getValue() == null) {
                        result.handle(new Either.Left<String, JsonObject>("conversation.send.error"));
                        return;
                    }

                    JsonArray attachments = event.right().getValue().getJsonArray("attachments",
                            new fr.wseduc.webutils.collections.JsonArray());

                    if (attachments.size() < 1) {
                        sendWithoutAttachments(parentMessageId, messageId, user, result);
                    } else {
                        sendWithAttachments(parentMessageId, messageId, attachments, user, result);
                    }

                }
            }));
}

From source file:org.entcore.conversation.service.impl.DefaultConversationService.java

License:Open Source License

private void sendWithoutAttachments(final String parentMessageId, String messageId, UserInfos user,
        final Handler<Either<String, JsonObject>> result) {
    String usersQuery;//www  . jav  a 2 s .co  m
    JsonObject params = new JsonObject().put("userId", user.getUserId()).put("messageId", messageId)
            .put("draft", State.DRAFT.name()).put("outbox", "OUTBOX").put("inbox", "INBOX")
            .put("sent", State.SENT.name()).put("true", true);
    if (parentMessageId != null && !parentMessageId.trim().isEmpty()) { // reply
        usersQuery = "MATCH (m:ConversationMessage { id : {parentMessageId}}) "
                + "WITH (COLLECT(visibles.id) + coalesce(m.to, '') + coalesce(m.cc, '') + coalesce(m.from, '')) as vis "
                + "MATCH (v:Visible) " + "WHERE v.id IN vis " + "WITH DISTINCT v ";
        params.put("parentMessageId", parentMessageId);
    } else {
        usersQuery = "WITH visibles as v ";
    }
    String query = usersQuery + "MATCH v<-[:IN*0..1]-(u:User), (message:ConversationMessage) "
            + "WHERE (v: User or v:Group) "
            + "AND message.id = {messageId} AND message.state = {draft} AND message.from = {userId} AND "
            + "(v.id IN message.to OR v.id IN message.cc) "
            + "WITH DISTINCT u, message, (v.id + '$' + coalesce(v.displayName, ' ') + '$' + "
            + "coalesce(v.name, ' ') + '$' + coalesce(v.groupDisplayName, ' ')) as dNames "
            + "MATCH u-[:HAS_CONVERSATION]->(c:Conversation {active:{true}})"
            + "-[:HAS_CONVERSATION_FOLDER]->(f:ConversationSystemFolder {name:{inbox}}) "
            + "CREATE UNIQUE f-[:HAS_CONVERSATION_MESSAGE { unread: {true} }]->message "
            + "WITH COLLECT(c.userId) as sentIds, COLLECT(u) as users, message, "
            + "COLLECT(distinct dNames) as displayNames "
            + "MATCH (s:User {id : {userId}})-[:HAS_CONVERSATION]->(:Conversation)"
            + "-[:HAS_CONVERSATION_FOLDER]->(fOut:ConversationSystemFolder {name : {outbox}}), "
            + "message<-[r:HAS_CONVERSATION_MESSAGE]-(fDraft:ConversationSystemFolder {name : {draft}}) "
            + "SET message.state = {sent}, "
            + "message.displayNames = displayNames + (s.id + '$' + coalesce(s.displayName, ' ') + '$ $ ') "
            + "CREATE UNIQUE fOut-[:HAS_CONVERSATION_MESSAGE { insideFolder: r.insideFolder }]->message "
            + "DELETE r "
            + "RETURN EXTRACT(u IN FIlTER(x IN users WHERE NOT(x.id IN sentIds)) | u.displayName) as undelivered,  "
            + "EXTRACT(u IN FIlTER(x IN users WHERE x.id IN sentIds AND NOT(x.activationCode IS NULL)) "
            + "| u.displayName) as inactive, LENGTH(sentIds) as sent, "
            + "sentIds, message.id as id, message.subject as subject";
    findVisibles(eb, user.getUserId(), query, params, true, true, false, new Handler<JsonArray>() {
        @Override
        public void handle(JsonArray event) {
            if (event != null && event.size() == 1 && (event.getValue(0) instanceof JsonObject)) {
                result.handle(new Either.Right<String, JsonObject>(event.getJsonObject(0)));
            } else {
                result.handle(new Either.Left<String, JsonObject>("conversation.send.error"));
            }
        }
    });
}

From source file:org.entcore.conversation.service.impl.DefaultConversationService.java

License:Open Source License

private void sendWithAttachments(final String parentMessageId, final String messageId, JsonArray attachments,
        final UserInfos user, final Handler<Either<String, JsonObject>> result) {
    long totalAttachmentsSize = 0l;
    for (Object o : attachments) {
        totalAttachmentsSize = totalAttachmentsSize + ((JsonObject) o).getLong("size", 0l);
    }/*from   w  w w  . j  ava  2  s .  c  o  m*/

    final String usersQuery;
    JsonObject params = new JsonObject().put("userId", user.getUserId()).put("messageId", messageId)
            .put("draft", State.DRAFT.name()).put("outbox", "OUTBOX").put("inbox", "INBOX")
            .put("sent", State.SENT.name()).put("attachmentsSize", totalAttachmentsSize).put("true", true);
    if (parentMessageId != null && !parentMessageId.trim().isEmpty()) { // reply
        usersQuery = "MATCH (m:ConversationMessage { id : {parentMessageId}}) "
                + "WITH (COLLECT(visibles.id) + coalesce(m.to, '') + coalesce(m.cc, '') + coalesce(m.from, '')) as vis "
                + "MATCH (v:Visible) " + "WHERE v.id IN vis " + "WITH DISTINCT v ";
        params.put("parentMessageId", parentMessageId);
    } else {
        usersQuery = "WITH visibles as v ";
    }

    String query = usersQuery
            + "MATCH v<-[:IN*0..1]-(u:User), (message:ConversationMessage)-[:HAS_ATTACHMENT]->(attachment: MessageAttachment) "
            + "WHERE (v: User or v:Group) "
            + "AND message.id = {messageId} AND message.state = {draft} AND message.from = {userId} AND "
            + "(v.id IN message.to OR v.id IN message.cc) "
            + "WITH DISTINCT u, message, (v.id + '$' + coalesce(v.displayName, ' ') + '$' + "
            + "coalesce(v.name, ' ') + '$' + coalesce(v.groupDisplayName, ' ')) as dNames, COLLECT(distinct attachment.id) as attachments "
            + "MATCH (ub: UserBook)<-[:USERBOOK]-(u)-[:HAS_CONVERSATION]->(c:Conversation {active:{true}})"
            + "-[:HAS_CONVERSATION_FOLDER]->(f:ConversationSystemFolder {name:{inbox}}) "
            + "WHERE (ub.quota - ub.storage) >= {attachmentsSize} "
            + "CREATE UNIQUE f-[:HAS_CONVERSATION_MESSAGE { unread: {true}, attachments: attachments }]->message "
            + "SET ub.storage = ub.storage + {attachmentsSize} "
            + "WITH message, COLLECT(c.userId) as sentIds, COLLECT(distinct u) as users, "
            + "COLLECT(distinct dNames) as displayNames "
            + "MATCH (s:User {id : {userId}})-[:HAS_CONVERSATION]->(:Conversation)"
            + "-[:HAS_CONVERSATION_FOLDER]->(fOut:ConversationSystemFolder {name : {outbox}}), "
            + "message<-[r:HAS_CONVERSATION_MESSAGE]-(fDraft:ConversationSystemFolder {name : {draft}}) "
            + "SET message.state = {sent}, "
            + "message.displayNames = displayNames + (s.id + '$' + coalesce(s.displayName, ' ') + '$ $ ') "
            + "CREATE UNIQUE fOut-[:HAS_CONVERSATION_MESSAGE { insideFolder: r.insideFolder, attachments: r.attachments }]->message "
            + "DELETE r " + "RETURN sentIds, message.id as id";

    findVisibles(eb, user.getUserId(), query, params, true, true, false, new Handler<JsonArray>() {
        @Override
        public void handle(JsonArray event) {
            if (event != null && event.size() == 1 && (event.getValue(0) instanceof JsonObject)) {

                JsonObject resultObj = event.getJsonObject(0);
                JsonArray sentIds = resultObj.getJsonArray("sentIds");
                String messageId = resultObj.getString("id");

                String query = usersQuery + "MATCH v<-[:IN*0..1]-(u:User), (message:ConversationMessage) "
                        + "WHERE (v: User or v:Group) "
                        + "AND message.id = {messageId} AND message.from = {userId} AND "
                        + "(v.id IN message.to OR v.id IN message.cc) "
                        + "RETURN EXTRACT(user IN FIlTER(x IN COLLECT(u) WHERE NOT(x.id IN {sentIds}))|user.displayName) as undelivered, {sentIds} as sentIds, [] as inactive, "
                        + "{sentIdsLength} as sent, message.id as id, message.subject as subject";

                JsonObject params = new JsonObject().put("userId", user.getUserId()).put("messageId", messageId)
                        .put("sentIds", sentIds).put("sentIdsLength", sentIds.size());
                if (parentMessageId != null && !parentMessageId.trim().isEmpty()) {
                    params.put("parentMessageId", parentMessageId);
                }

                findVisibles(eb, user.getUserId(), query, params, true, true, false, new Handler<JsonArray>() {
                    @Override
                    public void handle(JsonArray event) {
                        if (event != null && event.size() == 1 && (event.getValue(0) instanceof JsonObject)) {
                            result.handle(new Either.Right<String, JsonObject>(event.getJsonObject(0)));
                        } else {
                            result.handle(new Either.Left<String, JsonObject>("conversation.send.error"));
                        }
                    }
                });
            } else {
                result.handle(new Either.Left<String, JsonObject>("conversation.send.error"));
            }
        }
    });
}

From source file:org.entcore.conversation.service.impl.DefaultConversationService.java

License:Open Source License

@Override
public void removeAttachment(String messageId, String attachmentId, UserInfos user,
        final Handler<Either<String, JsonObject>> result) {
    if (validationParamsError(user, result, messageId, attachmentId))
        return;//from   w  w  w .  j  a  va2s. co  m

    String get = "MATCH (attachment: MessageAttachment)<-[aLink: HAS_ATTACHMENT]-(m: ConversationMessage)<-[r: HAS_CONVERSATION_MESSAGE]-(f: ConversationSystemFolder)"
            + "<-[:HAS_CONVERSATION_FOLDER]-(c:Conversation) "
            + "WHERE m.id = {messageId} AND c.userId = {userId} AND c.active = {true} AND attachment.id = {attachmentId} AND {attachmentId} IN r.attachments ";

    String query = get
            + "SET r.attachments = filter(attachmentId IN r.attachments WHERE attachmentId <> {attachmentId}) "
            + "RETURN attachment.id as fileId, attachment.size as fileSize";

    String q3 = "MATCH (attachment:MessageAttachment)<-[attachmentLink: HAS_ATTACHMENT]-(:ConversationMessage)<-[messageLinks: HAS_CONVERSATION_MESSAGE]-(:ConversationSystemFolder) "
            + "WHERE attachment.id = {attachmentId} "
            + "WITH attachmentLink, attachment, none(item IN collect(messageLinks.attachments) WHERE attachment.id IN item) as deletionCheck "
            + "WHERE deletionCheck = true " + "DELETE attachmentLink " + "WITH attachment "
            + "WHERE NOT(attachment-[:HAS_ATTACHMENT]-()) " + "DELETE attachment "
            + "RETURN true as deletionCheck";

    JsonObject params = new JsonObject().put("userId", user.getUserId()).put("messageId", messageId)
            .put("attachmentId", attachmentId).put("true", true);

    StatementsBuilder b = new StatementsBuilder();
    b.add(query, params);
    b.add(q3, params);

    neo.executeTransaction(b.build(), null, true, validResultsHandler(new Handler<Either<String, JsonArray>>() {
        @Override
        public void handle(Either<String, JsonArray> event) {
            if (event.isLeft()) {
                result.handle(new Either.Left<String, JsonObject>(event.left().getValue()));
                return;
            }

            JsonArray result1 = event.right().getValue().getJsonArray(0);
            JsonArray result3 = event.right().getValue().getJsonArray(1);

            JsonObject jsonResult = result1.size() > 0 ? result1.getJsonObject(0) : new JsonObject();
            jsonResult.put("deletionCheck",
                    result3.size() > 0 ? result3.getJsonObject(0).getBoolean("deletionCheck", false) : false);

            result.handle(new Either.Right<String, JsonObject>(jsonResult));
        }
    }));
}

From source file:org.entcore.conversation.service.impl.DeleteOrphan.java

License:Open Source License

@Override
public void handle(Long event) {
    final Sql sql = Sql.getInstance();
    final SqlStatementsBuilder builder = new SqlStatementsBuilder();
    builder.raw(DELETE_ORPHAN_MESSAGE);/*from w  w  w . j a v a  2  s  . c o  m*/
    builder.raw(SELECT_ORPHAN_ATTACHMENT);
    sql.transaction(builder.build(), new DeliveryOptions().setSendTimeout(TIMEOUT),
            SqlResult.validResultHandler(1, new Handler<Either<String, JsonArray>>() {
                @Override
                public void handle(Either<String, JsonArray> res) {
                    if (res.isRight()) {
                        log.info("Successful delete orphan conversation messages.");
                        final JsonArray attachments = res.right().getValue();
                        if (attachments != null && attachments.size() > 0) {
                            log.info("Orphan attachments : " + attachments.encode());
                            JsonArray ids = new fr.wseduc.webutils.collections.JsonArray();
                            for (Object attObj : attachments) {
                                if (!(attObj instanceof JsonObject))
                                    continue;
                                JsonObject unusedAttachment = (JsonObject) attObj;
                                final String attachmentId = unusedAttachment.getString("orphanid");
                                ids.add(attachmentId);
                                storage.removeFile(attachmentId, new Handler<JsonObject>() {
                                    public void handle(JsonObject event) {
                                        if (!"ok".equals(event.getString("status"))) {
                                            log.error("Error while tying to delete attachment file (_id: {"
                                                    + attachmentId + "})");
                                        }
                                    }
                                });
                            }
                            final String deletOrphanAttachments = "delete from conversation.attachments where id IN "
                                    + Sql.listPrepared(ids.getList());
                            sql.prepared(deletOrphanAttachments, ids,
                                    new DeliveryOptions().setSendTimeout(TIMEOUT),
                                    new Handler<Message<JsonObject>>() {
                                        @Override
                                        public void handle(Message<JsonObject> event) {
                                            if (!"ok".equals(event.body().getString("status"))) {
                                                log.error("Error deleting orphan attachments : "
                                                        + event.body().getString("message", ""));
                                            } else {
                                                log.info("Successful delete orphan conversation attachments.");
                                            }
                                        }
                                    });
                        }
                    } else {
                        log.error("Orphan conversation error : " + res.left().getValue());
                    }
                }
            }));
}

From source file:org.entcore.conversation.service.impl.Neo4jConversationService.java

License:Open Source License

public void addDisplayNames(final JsonObject message, final JsonObject parentMessage,
        final Handler<JsonObject> handler) {
    if (!displayNamesCondition(message)) {
        handler.handle(message);// w w w .ja v a2 s .  c om
        return;
    }

    String query = "MATCH (v:Visible) " + "WHERE v.id IN {ids} "
            + "RETURN COLLECT(distinct (v.id + '$' + coalesce(v.displayName, ' ') + '$' + "
            + "coalesce(v.name, ' ') + '$' + coalesce(v.groupDisplayName, ' '))) as displayNames ";

    Set<String> ids = new HashSet<>();
    ids.addAll(message.getJsonArray("to", new fr.wseduc.webutils.collections.JsonArray()).getList());
    ids.addAll(message.getJsonArray("cc", new fr.wseduc.webutils.collections.JsonArray()).getList());
    if (message.containsKey("from")) {
        ids.add(message.getString("from"));
    }
    if (parentMessage != null) {
        ids.addAll(parentMessage.getJsonArray("to", new fr.wseduc.webutils.collections.JsonArray()).getList());
        ids.addAll(parentMessage.getJsonArray("cc", new fr.wseduc.webutils.collections.JsonArray()).getList());
        if (parentMessage.containsKey("from"))
            ids.add(parentMessage.getString("from"));
    }
    neo.execute(query,
            new JsonObject().put("ids", new fr.wseduc.webutils.collections.JsonArray(new ArrayList<>(ids))),
            new Handler<Message<JsonObject>>() {
                @Override
                public void handle(Message<JsonObject> m) {
                    JsonArray r = m.body().getJsonArray("result");
                    if ("ok".equals(m.body().getString("status")) && r != null && r.size() == 1) {
                        JsonObject j = r.getJsonObject(0);
                        JsonArray d = j.getJsonArray("displayNames");
                        if (d != null && d.size() > 0) {
                            message.put("displayNames", d);
                        }
                    }
                    handler.handle(message);
                }
            });
}