Package com.sishuok.es.common.entity.search

Examples of com.sishuok.es.common.entity.search.Searchable


    @Autowired
    private PushApi pushApi;

    @Override
    public Page<Message> findUserMessage(Long userId, MessageState state, Pageable pageable) {
        Searchable searchable = Searchable.newSearchable();
        searchable.setPage(pageable);

        switch (state) {
            //sender的
            case draft_box:
            case out_box:
                searchable.addSearchFilter("senderId", SearchOperator.eq, userId);
                searchable.addSearchFilter("senderState", SearchOperator.eq, state);
                break;
            //receiver的
            case in_box:
                searchable.addSearchFilter("receiverId", SearchOperator.eq, userId);
                searchable.addSearchFilter("receiverState", SearchOperator.eq, state);
                break;
            //sender or receiver的
            case store_box:
            case trash_box:
                //sender

                SearchFilter senderFilter = SearchFilterHelper.newCondition("senderId", SearchOperator.eq, userId);
                SearchFilter senderStateFilter = SearchFilterHelper.newCondition("senderState", SearchOperator.eq, state);
                SearchFilter and1 = SearchFilterHelper.and(senderFilter, senderStateFilter);

                //receiver
                SearchFilter receiverFilter = SearchFilterHelper.newCondition("receiverId", SearchOperator.eq, userId);
                SearchFilter receiverStateFilter = SearchFilterHelper.newCondition("receiverState", SearchOperator.eq, state);
                SearchFilter and2 = SearchFilterHelper.and(receiverFilter, receiverStateFilter);

                searchable.or(and1, and2);
        }


        return messageService.findAll(searchable);
    }
View Full Code Here


        return messageService.findAll(searchable);
    }

    @Override
    public List<Message> findAncestorsAndDescendants(Message message) {
        Searchable searchable = Searchable.newSearchable();

        searchable.addSort(Sort.Direction.ASC, "id");

        SearchFilter filter = null;
        //祖先 不为空 从祖先查起
        if (!StringUtils.isEmpty(message.getParentIds())) {
            String ancestorsId = message.getParentIds().split("/")[0];
            filter = SearchFilterHelper.or(
                    SearchFilterHelper.newCondition("parentIds", SearchOperator.prefixLike, ancestorsId + "/"),
                    SearchFilterHelper.newCondition("id", SearchOperator.eq, ancestorsId)
            );
        } else {
            //祖先为空 查自己的后代
            String descendantsParentIds = message.makeSelfAsParentIds();
            filter = SearchFilterHelper.newCondition("parentIds", SearchOperator.prefixLike, descendantsParentIds);
        }

        searchable.addSearchFilter(filter);
        List<Message> result = messageService.findAllWithSort(searchable);
        //把自己排除
        result.remove(message);

        //删除 不可见的消息 如垃圾箱/已删除
View Full Code Here

    }

    @Test
    public void testNotifySuccess() {

        Searchable searchable = Searchable.newSearchable();
        searchable.addSearchFilter("userId", SearchOperator.eq, user.getId());
        searchable.addSort(Sort.Direction.DESC, "id");
        Long expectedCount = notificationDataService.count(searchable) + 1;


        String message = "haha";
        Map<String, Object> context = Maps.newHashMap();
View Full Code Here

        groupRelation2.setOrganizationId(organization2.getId());

        groupRelationService.save(groupRelation1);
        groupRelationService.save(groupRelation2);

        Searchable searchable = Searchable.newSearchable();
        searchable.addSearchFilter("groupId", SearchOperator.eq, group.getId());
        Assert.assertEquals(2, groupRelationService.count());

        organizationService.delete(organization1);

        groupClearRelationTask.clearDeletedGroupRelation();
View Full Code Here

        messageApi.sendSystemMessage(userIds, message);

        Long actualCount = messageService.count();
        Assert.assertEquals(expectedCount, actualCount);

        Searchable searchable = Searchable.newSearchable();
        searchable.addSearchFilter("receiverId", SearchOperator.in, userIds);
        List<Message> list = messageService.findAllWithNoPageNoSort(searchable);
        Assert.assertEquals(userIds.length, list.size());
        Assert.assertEquals(MessageType.system_message, list.get(0).getType());

        Page<Message> page = messageApi.findUserMessage(receiverId, MessageState.in_box, null);
View Full Code Here

        Long actualCount = messageService.count();
        Assert.assertEquals(expectedCount, actualCount);

        Long[] userIds = new Long[]{user1.getId()};
        Searchable searchable = Searchable.newSearchable();
        searchable.addSearchFilter("receiverId", SearchOperator.in, userIds);
        List<Message> list = messageService.findAllWithNoPageNoSort(searchable);
        Assert.assertEquals(userIds.length, list.size());
        Assert.assertEquals(MessageType.system_message, list.get(0).getType());
    }
View Full Code Here

        repositoryHelper.getEntityManager().persist(user1);
        repositoryHelper.getEntityManager().persist(user2);
        repositoryHelper.getEntityManager().persist(user3);
        repositoryHelper.getEntityManager().persist(user4);

        Searchable searchable = Searchable.newSearchable();

        searchable.addSearchParam("id_in", new Long[]{user1.getId(), user2.getId(), user3.getId()});

        searchable.setPage(0, 2);
        searchable.addSort(Sort.Direction.DESC, "id");


        String ql = "from User where 1=1";
        List<User> list = repositoryHelper.findAll(ql, searchable, SearchCallback.DEFAULT);
View Full Code Here

        repositoryHelper.getEntityManager().persist(user1);
        repositoryHelper.getEntityManager().persist(user2);
        repositoryHelper.getEntityManager().persist(user3);
        repositoryHelper.getEntityManager().persist(user4);

        Searchable searchable = Searchable.newSearchable();

        searchable.addSearchParam("realname", "zhang");
        searchable.addSearchParam("id_lt", user4.getId());

        searchable.setPage(0, 2);
        searchable.addSort(Sort.Direction.DESC, "id");


        SearchCallback customCallback = new DefaultSearchCallback() {
            @Override
            public void prepareQL(StringBuilder ql, Searchable search) {
View Full Code Here

        repositoryHelper.getEntityManager().persist(user1);
        repositoryHelper.getEntityManager().persist(user2);
        repositoryHelper.getEntityManager().persist(user3);
        repositoryHelper.getEntityManager().persist(user4);

        Searchable searchable = Searchable.newSearchable();

        searchable.addSearchParam("realname", "zhang");
        searchable.addSearchParam("id_lt", user4.getId());

        searchable.setPage(0, 2);
        searchable.addSort(Sort.Direction.DESC, "id");


        SearchCallback customCallback = new DefaultSearchCallback() {
            @Override
            public void prepareQL(StringBuilder ql, Searchable search) {
View Full Code Here

        repositoryHelper.getEntityManager().persist(user1);
        repositoryHelper.getEntityManager().persist(user2);
        repositoryHelper.getEntityManager().persist(user3);
        repositoryHelper.getEntityManager().persist(user4);

        Searchable searchable = Searchable.newSearchable();

        searchable.addSearchParam("id_in", new Long[]{user1.getId(), user2.getId(), user3.getId()});

        searchable.addSort(Sort.Direction.DESC, "id");


        String ql = "select count(*) from User where 1=1";
        long total = repositoryHelper.count(ql, searchable, SearchCallback.DEFAULT);

View Full Code Here

TOP

Related Classes of com.sishuok.es.common.entity.search.Searchable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.