All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.dezhik.sms.sender.api.smsru.send.SMSRuBatchSendHandler Maven / Gradle / Ivy

There is a newer version: 0.1.3
Show newest version
package ru.dezhik.sms.sender.api.smsru.send;

import java.util.Collection;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import ru.dezhik.sms.sender.RequestValidationException;
import ru.dezhik.sms.sender.api.smsru.Pair;

/**
 * @author ilya.dezhin
 */
public class SMSRuBatchSendHandler extends AbstractSMSRuSendHandler {
    @Override
    public void validate(SMSRuBatchSendRequest request) throws IllegalArgumentException {
        super.validate(request);

        final Collection> messages = request.getMessages();
        if (messages == null || messages.isEmpty()) {
            throw new RequestValidationException("No receiver/text pairs.");
        }

        for (Pair message : messages) {
            if (message.getA() == null || message.getA().isEmpty()) {
                throw new RequestValidationException("Receiver/text pairs contain null/empty receiver.");
            }
            if (message.getB() == null || message.getB().isEmpty()) {
                throw new RequestValidationException("Receiver/text pairs contain null/empty text.");
            }
        }

    }

    @Override
    public void appendParams(SMSRuBatchSendRequest request, List params) {
        super.appendParams(request, params);
        for (Pair message : request.getMessages()) {
            params.add(new BasicNameValuePair("multi[" + message.getA() + "]", message.getB()));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy