Example usage for org.apache.ibatis.session SqlSession selectList

List of usage examples for org.apache.ibatis.session SqlSession selectList

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSession selectList.

Prototype

<E> List<E> selectList(String statement, Object parameter);

Source Link

Document

Retrieve a list of mapped objects from the statement key and parameter.

Usage

From source file:com.mirth.connect.plugins.datapruner.DataPruner.java

License:Open Source License

private void archiveAndGetIdsToPrune(Map<String, Object> params, String channelId,
        Calendar messageDateThreshold, String archiveFolder, PruneIds messageIds, PruneIds contentMessageIds)
        throws Throwable {
    String tempChannelFolder = archiveFolder + "/." + channelId;
    String finalChannelFolder = archiveFolder + "/" + channelId;

    try {/*  w w w . j a  v  a 2  s.  c  o  m*/
        MessageWriterOptions messageWriterOptions = SerializationUtils.clone(archiverOptions);
        messageWriterOptions.setBaseFolder(System.getProperty("user.dir"));

        if (messageWriterOptions.getArchiveFormat() == null) {
            messageWriterOptions.setRootFolder(tempChannelFolder);
        } else {
            messageWriterOptions.setRootFolder(archiveFolder);
            messageWriterOptions.setArchiveFileName(channelId);
        }

        logger.debug("Running archiver, channel: " + channelId + ", root folder: "
                + messageWriterOptions.getRootFolder() + ", archive format: "
                + messageWriterOptions.getArchiveFormat() + ", archive filename: "
                + messageWriterOptions.getArchiveFileName() + ", file pattern: "
                + messageWriterOptions.getFilePattern());
        numExported = 0;
        status.setArchiving(true);
        MessageWriter archiver = MessageWriterFactory.getInstance().getMessageWriter(messageWriterOptions,
                ConfigurationController.getInstance().getEncryptor());

        AttachmentSource attachmentSource = null;
        if (messageWriterOptions.includeAttachments()) {
            attachmentSource = new AttachmentSource() {
                @Override
                public List<Attachment> getMessageAttachments(Message message) throws ClientException {
                    return MessageController.getInstance().getMessageAttachment(message.getChannelId(),
                            message.getMessageId());
                }
            };
        }
        long minMessageId = 0;
        try {
            List<Map<String, Object>> maps;
            do {
                ThreadUtils.checkInterruptedStatus();
                SqlSession session = SqlConfig.getSqlSessionManager().openSession(true);

                try {
                    params.put("minMessageId", minMessageId);
                    maps = session.selectList("Message.getMessagesToPrune", params);
                } finally {
                    session.close();
                }

                List<Long> archiveMessageIds = new ArrayList<Long>();
                Iterator<Map<String, Object>> iterator = maps.iterator();
                while (iterator.hasNext()) {
                    Map<String, Object> map = iterator.next();

                    long receivedDate = ((Calendar) map.get("mm_received_date")).getTimeInMillis();
                    long id = (Long) map.get("id");

                    if (messageDateThreshold != null && receivedDate < messageDateThreshold.getTimeInMillis()) {
                        messageIds.add(id);
                    } else {
                        contentMessageIds.add(id);
                    }

                    minMessageId = id + 1;
                    archiveMessageIds.add(id);

                    if (archiveMessageIds.size() == archiverBlockSize || !iterator.hasNext()) {
                        ThreadUtils.checkInterruptedStatus();
                        DonkeyDao dao = getDaoFactory().getDao();
                        try {
                            List<Message> messages = dao.getMessages(channelId, archiveMessageIds);

                            for (Message message : messages) {
                                if (attachmentSource != null) {
                                    List<Attachment> attachments = attachmentSource
                                            .getMessageAttachments(message);

                                    if (CollectionUtils.isNotEmpty(attachments)) {
                                        message.setAttachments(attachments);
                                    }
                                }

                                if (archiver.write(message)) {
                                    numExported++;
                                }
                            }

                            archiveMessageIds.clear();
                        } finally {
                            dao.close();
                        }
                    }
                }
            } while (maps != null && maps.size() == ID_RETRIEVE_LIMIT);

            archiver.finishWrite();
        } finally {
            archiver.close();
        }

        if (messageWriterOptions.getArchiveFormat() == null && new File(tempChannelFolder).isDirectory()) {
            try {
                FileUtils.moveDirectory(new File(tempChannelFolder), new File(finalChannelFolder));
            } catch (IOException e) {
                logger.error("Failed to move " + tempChannelFolder + " to " + finalChannelFolder, e);
            }
        }
    } catch (Throwable t) {
        FileUtils.deleteQuietly(new File(tempChannelFolder));
        FileUtils.deleteQuietly(new File(finalChannelFolder));
        throw t;
    } finally {
        status.setArchiving(false);
    }
}

From source file:com.mirth.connect.plugins.datapruner.DataPrunerMessageList.java

License:Open Source License

@Override
protected List<Message> getItems(int offset, int limit) throws Exception {
    List<Map<String, Object>> maps;
    SqlSession session = SqlConfig.getSqlSessionManager().openSession();
    params.put("offset", offset);
    params.put("limit", limit);

    try {/*www.j av  a 2s. co  m*/
        maps = session.selectList("Message.getMessagesToPrune", params);
    } finally {
        session.close();
    }

    List<Message> messages = new ArrayList<Message>();
    DonkeyDao dao = daoFactory.getDao();

    try {
        for (Map<String, Object> map : maps) {
            Long messageId = (Long) map.get("id");
            long connectorReceivedDateMillis = ((Calendar) map.get("mm_received_date")).getTimeInMillis();

            Map<Integer, ConnectorMessage> connectorMessages = null;
            connectorMessages = dao.getConnectorMessages(channelId, messageId);

            Message message = new Message();
            message.setMessageId(messageId);
            message.setChannelId(channelId);
            message.setReceivedDate((Calendar) map.get("received_date"));
            message.setProcessed((Boolean) map.get("processed"));
            message.setServerId((String) map.get("server_id"));
            message.setImportId((Long) map.get("import_id"));
            message.getConnectorMessages().putAll(connectorMessages);

            messages.add(message);

            contentMessageIds.add(messageId);

            if (messageDateThreshold != null
                    && connectorReceivedDateMillis < messageDateThreshold.getTimeInMillis()) {
                messageIds.add(messageId);
            }
        }

        return messages;
    } finally {
        dao.close();
    }
}

From source file:com.mirth.connect.server.controllers.DonkeyMessageController.java

License:Open Source License

private List<MessageSearchResult> searchMessages(MessageFilter filter, String channelId, int offset,
        int limit) {
    long startTime = System.currentTimeMillis();

    FilterOptions filterOptions = new FilterOptions(filter, channelId);
    long maxMessageId = filterOptions.getMaxMessageId();
    long minMessageId = filterOptions.getMinMessageId();

    Long localChannelId = ChannelController.getInstance().getLocalChannelId(channelId);
    Map<String, Object> params = getBasicParameters(filter, localChannelId);

    try {/*from w w  w.jav a  2  s  .c o  m*/
        NavigableMap<Long, MessageSearchResult> messages = new TreeMap<Long, MessageSearchResult>();
        SqlSession session = SqlConfig.getSqlSessionManager();

        int offsetRemaining = offset;
        /*
         * If the limit is greater than the default batch size, use the limit, but cap it at
         * 50000.
         */
        long batchSize = Math.min(Math.max(limit, 500), 50000);
        long totalSearched = 0;

        while (messages.size() < limit && maxMessageId >= minMessageId) {
            /*
             * Slowly increase the batch size in case all the necessary results are found early
             * on.
             */
            if (totalSearched >= 100000 && batchSize < 50000) {
                batchSize = 50000;
            } else if (totalSearched >= 10000 && batchSize < 10000) {
                batchSize = 10000;
            } else if (totalSearched >= 1000 && batchSize < 1000) {
                batchSize = 1000;
            }

            /*
             * Search in descending order so that messages will be found from the greatest to
             * lowest message id
             */
            long currentMinMessageId = Math.max(maxMessageId - batchSize + 1, minMessageId);
            params.put("maxMessageId", maxMessageId);
            params.put("minMessageId", currentMinMessageId);
            maxMessageId -= batchSize;
            totalSearched += batchSize;

            Map<Long, MessageSearchResult> foundMessages = searchAll(session, params, filter, localChannelId,
                    false, filterOptions);

            if (!foundMessages.isEmpty()) {
                /*
                 * Skip results until there is no offset remaining. This is required when
                 * viewing results beyond the first page
                 */
                if (offsetRemaining >= foundMessages.size()) {
                    offsetRemaining -= foundMessages.size();
                } else if (offsetRemaining == 0) {
                    messages.putAll(foundMessages);
                } else {
                    NavigableMap<Long, MessageSearchResult> orderedMessages = new TreeMap<Long, MessageSearchResult>(
                            foundMessages);

                    while (offsetRemaining-- > 0) {
                        orderedMessages.pollLastEntry();
                    }

                    messages.putAll(orderedMessages);
                }
            }
        }

        // Remove results beyond the limit requested
        while (messages.size() > limit) {
            messages.pollFirstEntry();
        }

        List<MessageSearchResult> results = new ArrayList<MessageSearchResult>(messages.size());

        /*
         * Now that we have the message and metadata ids that should be returned as the result,
         * we need to retrieve the message data for those.
         */
        if (!messages.isEmpty()) {
            Iterator<Long> iterator = messages.descendingKeySet().iterator();

            while (iterator.hasNext()) {
                Map<String, Object> messageParams = new HashMap<String, Object>();
                messageParams.put("localChannelId", localChannelId);

                ListRangeIterator listRangeIterator = new ListRangeIterator(iterator,
                        ListRangeIterator.DEFAULT_LIST_LIMIT, false, null);

                while (listRangeIterator.hasNext()) {
                    ListRangeItem item = listRangeIterator.next();
                    List<Long> list = item.getList();
                    Long startRange = item.getStartRange();
                    Long endRange = item.getEndRange();

                    if (list != null || (startRange != null && endRange != null)) {
                        if (list != null) {
                            messageParams.remove("minMessageId");
                            messageParams.remove("maxMessageId");
                            messageParams.put("includeMessageList", StringUtils.join(list, ","));
                        } else {
                            messageParams.remove("includeMessageList");
                            messageParams.put("minMessageId", endRange);
                            messageParams.put("maxMessageId", startRange);
                        }

                        // Get the current batch of results
                        List<MessageSearchResult> currentResults = session
                                .selectList("Message.selectMessagesById", messageParams);

                        // Add the metadata ids to each result
                        for (MessageSearchResult currentResult : currentResults) {
                            currentResult.setMetaDataIdSet(
                                    messages.get(currentResult.getMessageId()).getMetaDataIdSet());
                        }

                        // Add the current batch to the final list of results
                        results.addAll(currentResults);
                    }
                }
            }
        }

        return results;
    } finally {
        long endTime = System.currentTimeMillis();
        logger.debug("Search executed in " + (endTime - startTime) + "ms");
    }
}

From source file:com.mirth.connect.server.controllers.DonkeyMessageController.java

License:Open Source License

private Map<Long, MessageSearchResult> searchAll(SqlSession session, Map<String, Object> params,
        MessageFilter filter, Long localChannelId, boolean includeMessageData, FilterOptions filterOptions) {
    Map<Long, MessageSearchResult> foundMessages = new HashMap<Long, MessageSearchResult>();

    // Search the message table to find which message ids meet the search criteria.
    List<MessageTextResult> messageResults = session.selectList("Message.searchMessageTable", params);
    /*/*from  w  w  w.  j  a va  2s .co m*/
     * If the message table search provided no records then there is no need to perform any more
     * searches on this range of message ids.
     */
    if (!messageResults.isEmpty()) {
        Set<Long> messageIdSet = new HashSet<Long>(messageResults.size());
        for (MessageTextResult messageResult : messageResults) {
            messageIdSet.add(messageResult.getMessageId());
        }

        /*
         * Search the metadata table to find which message and metadataids meet the search
         * criteria. If a text search is being performed, we also check the connector name
         * column while we're at it.
         */

        List<MessageTextResult> metaDataResults = session.selectList("Message.searchMetaDataTable", params);
        /*
         * Messages that matched the text search criteria. Since text search spans across
         * multiple tables (metadata, content, custom metadata), the map is created it can be
         * used for the searches on each table.
         */
        Map<Long, MessageSearchResult> textMessages = new HashMap<Long, MessageSearchResult>();
        /*
         * Messages that met the criteria on the message and metadata tables and still need to
         * have lengthy search run on them.
         */
        Map<Long, MessageSearchResult> potentialMessages = new HashMap<Long, MessageSearchResult>();
        for (MessageTextResult metaDataResult : metaDataResults) {
            if (messageIdSet.contains(metaDataResult.getMessageId())) {
                if (filterOptions.isSearchText() && metaDataResult.isTextFound() != null
                        && metaDataResult.isTextFound()) {
                    /*
                     * Text search was found in the metadata table so add the message/metadata
                     * id to the text messages.
                     */
                    addMessageToMap(textMessages, metaDataResult.getMessageId(),
                            metaDataResult.getMetaDataId());

                    if (filterOptions.isSearchCustomMetaData() || filterOptions.isSearchContent()) {
                        /*
                         * If content or custom metadata is being searched, still add the
                         * message to potentialMessages so the lengthy search will be run.
                         */
                        addMessageToMap(potentialMessages, metaDataResult.getMessageId(),
                                metaDataResult.getMetaDataId());
                    }
                } else if (filterOptions.isSearchCustomMetaData() || filterOptions.isSearchContent()
                        || filterOptions.isSearchText()) {
                    /*
                     * If no text search was found and any lengthy search is required, add the
                     * message to potentialMessages.
                     */
                    addMessageToMap(potentialMessages, metaDataResult.getMessageId(),
                            metaDataResult.getMetaDataId());
                } else {
                    /*
                     * If no lengthy search is required, just add the message to foundMesages.
                     */
                    addMessageToMap(foundMessages, metaDataResult.getMessageId(),
                            metaDataResult.getMetaDataId());
                }
            }
        }

        // These are no longer used so allow GC to reclaim their memory
        metaDataResults = null;
        messageIdSet = null;
        if (!includeMessageData) {
            messageResults = null;
        }

        if (potentialMessages.isEmpty()) {
            // If lengthy search is not being run, add all text messages to found messages
            foundMessages.putAll(textMessages);
        } else {
            long potentialMin = Long.MAX_VALUE;
            long potentialMax = Long.MIN_VALUE;

            for (long key : potentialMessages.keySet()) {
                if (key < potentialMin) {
                    potentialMin = key;
                }
                if (key > potentialMax) {
                    potentialMax = key;
                }
            }

            Map<String, Object> contentParams = new HashMap<String, Object>();
            contentParams.put("localChannelId", localChannelId);
            contentParams.put("includedMetaDataIds", filter.getIncludedMetaDataIds());
            contentParams.put("excludedMetaDataIds", filter.getExcludedMetaDataIds());
            contentParams.put("minMessageId", potentialMin);
            contentParams.put("maxMessageId", potentialMax);

            boolean searchCustomMetaData = filterOptions.isSearchCustomMetaData();
            boolean searchContent = filterOptions.isSearchContent();
            boolean searchText = filterOptions.isSearchText();

            /*
             * The map of messages that contains the combined results from all of the lengthy
             * searches. For all searches that are being performed, a message and metadata id
             * must be found in all three in order for the message to remain in this map
             */
            Map<Long, MessageSearchResult> tempMessages = null;

            if (searchCustomMetaData) {
                tempMessages = new HashMap<Long, MessageSearchResult>();
                // Perform the custom metadata search
                searchCustomMetaData(session, new HashMap<String, Object>(contentParams), potentialMessages,
                        tempMessages, filter.getMetaDataSearch());

                /*
                 * If tempMessages is empty, there is no need to search on either the content or
                 * text because the join will never return any results
                 */
                if (tempMessages.isEmpty()) {
                    searchContent = false;
                    searchText = false;
                }
            }
            if (searchContent) {
                Map<Long, MessageSearchResult> contentMessages = new HashMap<Long, MessageSearchResult>();
                // Perform the content search
                searchContent(session, new HashMap<String, Object>(contentParams), potentialMessages,
                        contentMessages, filter.getContentSearch());

                if (tempMessages == null) {
                    /*
                     * If temp messages has not been created yet, then there is no need to join
                     * the results from this search and previous searches. Just set the current
                     * messages as the temp messages
                     */
                    tempMessages = contentMessages;
                } else {
                    /*
                     * Otherwise join the two maps so that the only results left in tempMessages
                     * are those that also exist in the current message map
                     */
                    joinMessages(tempMessages, contentMessages);
                }

                /*
                 * If tempMessages is empty, there is no need to search on either the text
                 * because the join will never return any results
                 */
                if (tempMessages.isEmpty()) {
                    searchText = false;
                }
            }
            if (searchText) {
                // Perform the text search
                searchText(session, new HashMap<String, Object>(contentParams), potentialMessages, textMessages,
                        filter.getTextSearchRegex(), filter.getTextSearch(),
                        filter.getTextSearchMetaDataColumns());

                if (tempMessages == null) {
                    /*
                     * If temp messages has not been created yet, then there is no need to join
                     * the results from this search and previous searches. Just set the current
                     * messages as the temp messages
                     */
                    tempMessages = textMessages;
                } else {
                    /*
                     * Otherwise join the two maps so that the only results left in tempMessages
                     * are those that also exist in the current message map
                     */
                    joinMessages(tempMessages, textMessages);
                }
            }

            /*
             * Add all the results from tempMessages after all the joins have been completed
             * into foundMessages
             */
            foundMessages.putAll(tempMessages);
        }

        /*
         * If message data was requested then copy it from the message search into the final
         * results
         */
        if (!foundMessages.isEmpty() && includeMessageData) {
            // Build a map of the message data results for quicker access
            Map<Long, MessageTextResult> messageDataResults = new HashMap<Long, MessageTextResult>(
                    messageResults.size());
            for (MessageTextResult messageResult : messageResults) {
                messageDataResults.put(messageResult.getMessageId(), messageResult);
            }

            /*
             * For each found result, copy over any message data that may have been retrieved
             * already
             */
            for (Entry<Long, MessageSearchResult> entry : foundMessages.entrySet()) {
                Long messageId = entry.getKey();
                MessageSearchResult result = entry.getValue();

                MessageTextResult textResult = messageDataResults.get(messageId);
                if (textResult != null) {
                    result.setImportId(textResult.getImportId());
                    result.setProcessed(textResult.getProcessed());
                }
            }
        }
    }

    return foundMessages;
}

From source file:com.mirth.connect.server.controllers.DonkeyMessageController.java

License:Open Source License

private void searchCustomMetaData(SqlSession session, Map<String, Object> params,
        Map<Long, MessageSearchResult> potentialMessages, Map<Long, MessageSearchResult> customMetaDataMessages,
        List<MetaDataSearchElement> metaDataSearchElements) {
    params.put("metaDataSearch", metaDataSearchElements);

    /*//from   ww w .  j av  a 2  s  . c  o  m
     * Search the custom meta data table for message and metadata ids matching the metadata
     * search criteria
     */
    List<MessageTextResult> results = session.selectList("Message.searchCustomMetaDataTable", params);

    for (MessageTextResult result : results) {
        Long messageId = result.getMessageId();
        Integer metaDataId = result.getMetaDataId();

        if (potentialMessages.containsKey(messageId)) {
            Set<Integer> allowedMetaDataIds = potentialMessages.get(messageId).getMetaDataIdSet();
            /*
             * Ignore the message and metadata id if they are not allowed because they were
             * already filtered in a previous step
             */
            if (allowedMetaDataIds.contains(metaDataId)) {
                addMessageToMap(customMetaDataMessages, messageId, metaDataId);
            }
        }
    }
}

From source file:com.mirth.connect.server.controllers.DonkeyMessageController.java

License:Open Source License

private void searchContent(SqlSession session, Map<String, Object> params,
        Map<Long, MessageSearchResult> potentialMessages, Map<Long, MessageSearchResult> contentMessages,
        List<ContentSearchElement> contentSearchElements) {
    int index = 0;

    while (index < contentSearchElements.size() && (index == 0 || !contentMessages.isEmpty())) {
        ContentSearchElement element = contentSearchElements.get(index);

        if (CollectionUtils.isNotEmpty(element.getSearches())) {
            params.put("contentType", element.getContentCode());
            params.put("contents", element.getSearches());

            /*/*from ww  w. ja v a 2 s  .  c o  m*/
             * Search the content table for message and metadata ids matching the content search
             * criteria
             */
            List<MessageTextResult> results = session.selectList("Message.searchContentTable", params);

            Map<Long, MessageSearchResult> tempMessages = new HashMap<Long, MessageSearchResult>();

            for (MessageTextResult result : results) {
                Long messageId = result.getMessageId();
                Integer metaDataId = result.getMetaDataId();

                if (potentialMessages.containsKey(messageId)) {
                    Set<Integer> allowedMetaDataIds = potentialMessages.get(messageId).getMetaDataIdSet();
                    /*
                     * Ignore the message and metadata id if they are not allowed because they
                     * were already filtered in a previous step
                     */
                    if (allowedMetaDataIds.contains(metaDataId)) {
                        if (index == 0) {
                            /*
                             * For the first search, add the results to the final result map
                             * since there is nothing to join from
                             */
                            addMessageToMap(contentMessages, messageId, metaDataId);
                        } else {
                            /*
                             * For other searches, add the results to the temp result map so
                             * they can be joined with the final result map
                             */
                            addMessageToMap(tempMessages, messageId, metaDataId);
                        }
                    }
                }
            }

            /*
             * If the raw content is being searched, perform an additional search on the source
             * encoded content since the destination
             */
            if (ContentType.fromCode(element.getContentCode()) == ContentType.RAW) {
                params.put("metaDataId", 0);
                params.put("contentType", ContentType.ENCODED.getContentTypeCode());

                results = session.selectList("Message.searchContentTable", params);
                params.remove("metaDataId");

                for (MessageTextResult result : results) {
                    Long messageId = result.getMessageId();

                    if (potentialMessages.containsKey(messageId)) {
                        Set<Integer> allowedMetaDataIds = potentialMessages.get(messageId).getMetaDataIdSet();
                        for (Integer allowedMetaDataId : allowedMetaDataIds) {
                            if (allowedMetaDataId != 0) {
                                /*
                                 * If the source encoded is found, then all destinations have
                                 * matched on the raw content, so all allowed metadata ids other
                                 * than 0 (source) need to be added
                                 */
                                if (index == 0) {
                                    /*
                                     * For the first search, add the results to the final result
                                     * map since there is nothing to join from
                                     */
                                    addMessageToMap(contentMessages, messageId, allowedMetaDataId);
                                } else {
                                    /*
                                     * For other searches, add the results to the temp result
                                     * map so they can be joined with the final result map
                                     */
                                    addMessageToMap(tempMessages, messageId, allowedMetaDataId);
                                }
                            }
                        }
                    }
                }
            }

            if (index > 0) {
                /*
                 * If there are more than one searches performed, join the results since the
                 * message and metadata ids must be found in all searches in order to be
                 * considered "found"
                 */
                joinMessages(contentMessages, tempMessages);
            }
        }

        index++;
    }
}

From source file:com.mirth.connect.server.controllers.DonkeyMessageController.java

License:Open Source License

private void searchText(SqlSession session, Map<String, Object> params,
        Map<Long, MessageSearchResult> potentialMessages, Map<Long, MessageSearchResult> textMessages,
        Boolean textSearchRegex, String text, List<String> textSearchMetaDataColumns) {
    params.put("contents", Collections.singletonList(text));
    params.put("textSearch", text);
    params.put("textSearchRegex", textSearchRegex);
    params.put("textSearchMetaDataColumns", textSearchMetaDataColumns);
    List<MessageTextResult> results;

    if (CollectionUtils.isNotEmpty(textSearchMetaDataColumns)) {
        /*/*from w  ww. j  a  v a2s. c o m*/
         * Search the custom meta data table for message and metadata ids matching the text
         * search criteria
         */
        results = session.selectList("Message.searchCustomMetaDataTable", params);

        for (MessageTextResult result : results) {
            Long messageId = result.getMessageId();
            Integer metaDataId = result.getMetaDataId();

            if (potentialMessages.containsKey(messageId)) {
                Set<Integer> allowedMetaDataIds = potentialMessages.get(messageId).getMetaDataIdSet();
                /*
                 * Ignore the message and metadata id if they are not allowed because they were
                 * already filtered in a previous step
                 */
                if (allowedMetaDataIds.contains(metaDataId)) {
                    addMessageToMap(textMessages, messageId, metaDataId);
                }
            }
        }
    }

    /*
     * Search the content table for message and metadata ids matching the text search criteria
     */
    results = session.selectList("Message.searchContentTable", params);

    for (MessageTextResult result : results) {
        Long messageId = result.getMessageId();
        Integer metaDataId = result.getMetaDataId();
        Integer contentCode = result.getContentType();
        ContentType contentType = ContentType.fromCode(contentCode);

        if (potentialMessages.containsKey(messageId)) {
            Set<Integer> allowedMetaDataIds = potentialMessages.get(messageId).getMetaDataIdSet();
            if (metaDataId == 0 && contentType == ContentType.ENCODED) {
                /*
                 * If the text search is found in the source encoded content, then all the
                 * allowed destinations would match on the raw content so all allowed metadata
                 * ids for this message need to be added
                 */
                for (Integer allowedMetaDataId : allowedMetaDataIds) {
                    addMessageToMap(textMessages, messageId, allowedMetaDataId);
                }
            } else if (allowedMetaDataIds.contains(metaDataId)) {
                /*
                 * Ignore the message and metadata id if they are not allowed because they were
                 * already filtered in a previous step
                 */
                addMessageToMap(textMessages, messageId, metaDataId);
            }
        }
    }
}

From source file:com.onnurimotors.wm.service.WmService.java

public Object visit(HttpServletRequest request) {
    SqlSession session = sqlSession();
    String license = request.getParameter("license").replaceAll("\\s+", "");
    int is_new_customer;
    String title, msg;/*from  w  w w.  j  a v a 2s  . c o  m*/
    Date date = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.add(Calendar.HOUR_OF_DAY, 9);
    date = cal.getTime();
    DateFormat format_date = new SimpleDateFormat("yyyy-MM-dd");
    DateFormat format_time = new SimpleDateFormat("HH:mm:ss");
    VEHICLE vehicle = new VEHICLE();
    HISTORY history = new HISTORY();
    vehicle.setLICENSE(license);
    vehicle.setVEHICLE_ID(-1);

    // retrieve vehicle list which match license
    ArrayList<VEHICLE> result = (ArrayList<VEHICLE>) session.selectList("watchman.mybatis.selectVehicle",
            vehicle);

    // if there is no matched vehicle
    if (result.size() == 0) {
        vehicle = new VEHICLE();
        vehicle.setIS_NOTIFIABLE(1);
        vehicle.setLICENSE(license);
        vehicle.setMODEL("");
        vehicle.setUSER_NAME("");
        vehicle.setBIRTH("");
        vehicle.setPHONE_NUMBER("");
        vehicle.setCOMMENT("");
        session.insert("watchman.mybatis.insertVehicle", vehicle);
        session.commit();
        is_new_customer = 1;
    } else {
        vehicle = result.get(0);
        is_new_customer = 0;
    }

    history.setVEHICLE_ID(vehicle.getVEHICLE_ID());
    history.setDATE_VISIT(format_date.format(date));
    history.setTIME_VISIT(format_time.format(date));
    session.insert("watchman.mybatis.insertHistory", history);
    session.commit();

    // msg to app used by employee of onnurimotors
    title = "";
    msg = "";
    if (vehicle.getIS_NOTIFIABLE() == 1) {
        if (is_new_customer == 0) {
            title = title + " ?\n";
            msg = msg + " ?\n";
        } else {
            title = title + "?  ?\n";
            msg = msg + " ?\n";
        }
        msg = msg + ": " + vehicle.getLICENSE() + "\n";
        msg = msg + "?: " + vehicle.getMODEL() + "\n";
        msg = msg + "??: " + vehicle.getUSER_NAME() + "\n";
        msg = msg + "??: " + vehicle.getBIRTH() + "\n";
        msg = msg + ": " + vehicle.getCOMMENT() + "\n";

        /*ArrayList<VEHICLE_HISTORY> result2 = (ArrayList<VEHICLE_HISTORY>) session.selectList("watchman.mybatis.selectAllHistoryVehicle", vehicle);
        for(int i = 0; i < result2.size(); i++) {
           msg = msg + result2.get(i).getDATE_VISIT() + " " + result2.get(i).getTIME_VISIT() + "<br />";
        }*/

        PARAMETER_VEHICLE parameter_vehicle = new PARAMETER_VEHICLE();
        parameter_vehicle.setVEHICLE_ID(vehicle.getVEHICLE_ID());
        ArrayList<MANAGEMENT_DATE> result3 = (ArrayList<MANAGEMENT_DATE>) session
                .selectList("watchman.mybatis.selectManagementDateOfVehicle", parameter_vehicle);
        msg = msg + "<? >\n";
        for (int i = 0; i < 10 && i < result3.size(); i++) {
            msg = msg + result3.get(i).getDATE_VISIT() + " " + result3.get(i).getCOMMENT() + "\n";
        }

        ArrayList<EMPLOYEE> employees = (ArrayList<EMPLOYEE>) session
                .selectList("watchman.mybatis.selectReceivers");
        for (int i = 0; i < employees.size(); i++) {
            pService.sendPushNotification(employees.get(i).getKAKAO_ACCOUNT(), title, msg);
            pService.sendPush(employees.get(i).getKAKAO_ACCOUNT(), title, msg);
        }
    }

    session.close();

    // if is_notifiable is false, return empty message
    return msg;
}

From source file:com.onnurimotors.wm.service.WmService.java

public Object getHistory(HttpServletRequest request, Model model) {
    SqlSession session = sqlSession();
    ArrayList<HISTORY> historys = null;
    PARAMETER_HISTORY param = new PARAMETER_HISTORY();

    String history_id = request.getParameter("HISTORY_ID");
    param.setHISTORY_ID(-1);/*from   w  w w.jav a  2s  .c om*/
    if (history_id != null && !history_id.equals("")) {
        param.setHISTORY_ID(Integer.parseInt(history_id));
    }
    param.setDATE_VISIT("");
    param.setVEHICLE_ID(-1);

    String page = request.getParameter("PAGE");
    String size_page = request.getParameter("SIZE_PAGE");
    param.setPAGE(0);
    param.setSIZE_PAGE(10);
    if (page != null && !page.equals("")) {
        if (size_page != null && !size_page.equals("")) {
            param.setPAGE((Integer.parseInt(page) - 1) * Integer.parseInt(size_page));
            param.setSIZE_PAGE(Integer.parseInt(size_page));
        } else {
            param.setPAGE((Integer.parseInt(page) - 1) * 10);
        }
        historys = (ArrayList<HISTORY>) session.selectList("watchman.mybatis.selectHistory", param);
    } else if (size_page != null && !size_page.equals("")) {
        param.setSIZE_PAGE(Integer.parseInt(size_page));
        historys = (ArrayList<HISTORY>) session.selectList("watchman.mybatis.selectHistory", param);
    } else {
        historys = (ArrayList<HISTORY>) session.selectList("watchman.mybatis.selectAllHistory", param);
    }

    if (model != null) {
        model.addAttribute("historys", historys);
    }

    session.close();

    return historys;
}

From source file:com.onnurimotors.wm.service.WmService.java

public Object getVehicle(HttpServletRequest request, Model model, int vid) {
    SqlSession session = sqlSession();
    VEHICLE vehicle = new VEHICLE();
    vehicle.setLICENSE("");
    vehicle.setVEHICLE_ID(-1);//from  ww w . j  a v a  2s  .c om
    if (request != null) {
        String license = request.getParameter("license");
        String vehicle_id = request.getParameter("vehicle_id");
        if (license != null && !license.equals("")) {
            vehicle.setLICENSE("%" + license + "%");
            if (model != null) {
                model.addAttribute("license", license);
            }
        } else {
            if (model != null) {
                model.addAttribute("license", "");
            }
        }
        if (vehicle_id != null && !vehicle_id.equals("")) {
            vehicle.setVEHICLE_ID(Integer.parseInt(vehicle_id));
        }
    }
    if (vid != -1) {
        vehicle.setVEHICLE_ID(vid);
    }
    List<VEHICLE> vehicles = (ArrayList<VEHICLE>) session.selectList("watchman.mybatis.selectVehicle", vehicle);

    if (model != null) {
        model.addAttribute("vehicles", vehicles);
    }

    session.close();

    return vehicles;
}