airport.services.chat.ServiceChatBasic.java Source code

Java tutorial

Introduction

Here is the source code for airport.services.chat.ServiceChatBasic.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package airport.services.chat;

import airport.database.services.chat.Message;
import airport.database.services.chat.ChatDao;
import airport.database.services.users.User;
import airport.services.statistics.ServiceStatistics;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author mcdoker
 */
@Service
public class ServiceChatBasic implements ServiceChat {

    private final static Logger LOG = Logger.getLogger(ServiceChatBasic.class);

    @Autowired
    private ChatDao CHAT_DAO;
    @Autowired
    private ServiceStatistics serviceStatistics;

    @Override
    public List<Message> getMessageMiss(int number) {
        List<Message> resultMessages = CHAT_DAO.getMessageMiss(number);

        if (LOG.isInfoEnabled()) {
            LOG.info("get miss messages. Messages : " + resultMessages);
        }

        return resultMessages;
    };

    @Override
    public void addMessage(User user, String text) {
        if (text == null || text.isEmpty()) {
            return;
        }

        serviceStatistics.incAmountSendMessage(user);
        CHAT_DAO.addMessage(user, text, new Timestamp(new Date().getTime()));

        if (LOG.isInfoEnabled()) {
            LOG.info("add message");
        }
    }

    @Override
    public int getNumberLastMessage() {
        int numberLastMessage = CHAT_DAO.getLastNumberMessage();

        if (LOG.isInfoEnabled()) {
            LOG.info("get number last message. Number last message : " + numberLastMessage);
        }

        return numberLastMessage;
    }

}