<commit_before>package com.github.fmonniot.mailbox.service;

import com.github.fmonniot.mailbox.entity.Mailbox;
import com.github.fmonniot.mailbox.entity.Message;
import com.github.fmonniot.mailbox.persistence.MailboxDao;
import com.github.fmonniot.mailbox.persistence.MessageDao;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Date;
import java.util.List;

import static jersey.repackaged.com.google.common.base.Preconditions.checkNotNull;

@Singleton
public class MessageServiceImpl implements MessageService {

    @Inject
    private MessageDao messageDao;

    @Inject
    private MailboxDao mailboxDao;

    @Inject
    private RightsService rightsService;

    @Override
    public List<Message> listForClient(Long clientId) {
        checkNotNull(clientId, "clientId cannot be null");

        Mailbox mailbox = mailboxDao.findBox(clientId);

        return messageDao.listInBox(mailbox);
    }

    @Override
    public Message post(Long clientId, Message message) {
        checkNotNull(clientId, "clientId cannot be null");
        checkNotNull(message, "message cannot be null");

        checkNotNull(message.getBox(), "a message must be sent to a box");
        checkNotNull(message.getBox().getId(), "the destination box must specify an id");

        // Check if user can post a message
        if (!rightsService.canPost(clientId, message)) {
            throw new IllegalStateException("Client has no rights to post this message");
        }<commit_msg>check that a user have a mailbox<commit_after>package com.github.fmonniot.mailbox.service;

import com.github.fmonniot.mailbox.entity.Mailbox;
import com.github.fmonniot.mailbox.entity.Message;
import com.github.fmonniot.mailbox.persistence.MailboxDao;
import com.github.fmonniot.mailbox.persistence.MessageDao;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Date;
import java.util.List;

import static jersey.repackaged.com.google.common.base.Preconditions.checkNotNull;

@Singleton
public class MessageServiceImpl implements MessageService {

    @Inject
    private MessageDao messageDao;

    @Inject
    private MailboxDao mailboxDao;

    @Inject
    private RightsService rightsService;

    @Override
    public List<Message> listForClient(Long clientId) {
        checkNotNull(clientId, "clientId cannot be null");

        Mailbox mailbox = mailboxDao.findBox(clientId);
        checkNotNull(mailbox, "This user doesn't have a mailbox.");

        return messageDao.listInBox(mailbox);
    }

    @Override
    public Message post(Long clientId, Message message) {
        checkNotNull(clientId, "clientId cannot be null");
        checkNotNull(message, "message cannot be null");

        checkNotNull(message.getBox(), "a message must be sent to a box");
        checkNotNull(message.getBox().getId(), "the destination box must specify an id");

        // Check if user can post a message
        if (!rightsService.canPost(clientId, message)) {
            throw new IllegalStateException("Client has no rights to post this message");
        }
{'fraction_non_alphanumeric': 0.09064422143088378, 'fraction_numerical': 0.0, 'mean_word_length': 3.7906976744186047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1699272', 'n_tokens_mistral': 873, 'n_tokens_neox': 878, 'n_words': 235}