Skip to content

Commit

Permalink
BS-232 Added builder for SmsMessageFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
hrosa committed Jun 7, 2018
1 parent 8d57bbd commit c25c884
Showing 1 changed file with 103 additions and 20 deletions.
Expand Up @@ -19,38 +19,45 @@
*/
package org.restcomm.connect.dao.entities;

import org.restcomm.connect.commons.annotations.concurrency.Immutable;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.restcomm.connect.commons.annotations.concurrency.Immutable;

/**
* @author <a href="mailto:n.congvu@gmail.com">vunguyen</a>
* @author Henrique Rosa (henrique.rosa@telestax.com)
*/

@Immutable
public class SmsMessageFilter {

private final String accountSid;
private final List<String> accountSidSet; // if not-null we need the cdrs that belong to several accounts
private final String recipient;
private final String sender;
private final Date startTime; // to initialize it pass string arguments with yyyy-MM-dd format
private final Date endTime;
private final String body;
private final Integer limit;
private final Integer offset;
private final String instanceid;
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");

private String accountSid;
private List<String> accountSidSet; // if not-null we need the cdrs that belong to several accounts
private String recipient;
private String sender;
private Date startTime; // to initialize it pass string arguments with yyyy-MM-dd format
private Date endTime;
private String body;
private Integer limit;
private Integer offset;
private String instanceid;

public SmsMessageFilter() {
}

public SmsMessageFilter(String accountSid, List<String> accountSidSet, String recipient, String sender, String startTime, String endTime,
String body, Integer limit, Integer offset) throws ParseException {
this(accountSid, accountSidSet, recipient,sender,startTime,endTime, body, limit,offset,null);
String body, Integer limit, Integer offset) throws ParseException {
this(accountSid, accountSidSet, recipient, sender, startTime, endTime, body, limit, offset, null);
}

public SmsMessageFilter(String accountSid, List<String> accountSidSet, String recipient, String sender, String startTime, String endTime,
String body, Integer limit, Integer offset, String instanceId) throws ParseException {
String body, Integer limit, Integer offset, String instanceId) throws ParseException {
this.accountSid = accountSid;
this.accountSidSet = accountSidSet;

Expand All @@ -67,15 +74,13 @@ public SmsMessageFilter(String accountSid, List<String> accountSidSet, String re
this.limit = limit;
this.offset = offset;
if (startTime != null) {
SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd");
Date date = parser.parse(startTime);
Date date = DATE_FORMAT.parse(startTime);
this.startTime = date;
} else
this.startTime = null;

if (endTime != null) {
SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd");
Date date = parser.parse(endTime);
Date date = DATE_FORMAT.parse(endTime);
this.endTime = date;
} else {
this.endTime = null;
Expand Down Expand Up @@ -123,5 +128,83 @@ public int getOffset() {
return offset;
}

public String getInstanceid() { return instanceid; }
public String getInstanceid() {
return instanceid;
}

public Builder builer() {
return new Builder();
}

public class Builder {

private final SmsMessageFilter filter;

private Builder() {
this.filter = new SmsMessageFilter();
}

public Builder accountSid(String accountSid) {
this.filter.accountSid = accountSid;
return this;
}

public Builder accountSidSet(List<String> accountSidSet) {
this.filter.accountSidSet = accountSidSet;
return this;
}

public Builder recipient(String recipient) {
if (recipient != null && !recipient.isEmpty()) {
this.filter.recipient = (recipient.startsWith("%") ? "" : "%") + this.filter.recipient;
}
return this;
}

public Builder sender(String sender) {
if (sender != null && !sender.isEmpty()) {
this.filter.sender = (sender.startsWith("%") ? "" : "%") + this.filter.sender;
}
return this;
}

public Builder startTime(String startTime) throws ParseException {
if (startTime != null && !startTime.isEmpty()) {
this.filter.startTime = DATE_FORMAT.parse(startTime);
}
return this;
}

public Builder endTime(String endTime) throws ParseException {
if (endTime != null && !endTime.isEmpty()) {
this.filter.endTime = DATE_FORMAT.parse(endTime);
}
return this;
}

public Builder body(String body) {
this.filter.body = body;
return this;
}

public Builder limit(int limit) {
this.filter.limit = limit;
return this;
}

public Builder offset(int offset) {
this.filter.offset = offset;
return this;
}

public Builder instanceId(String instanceId) {
this.filter.instanceid = instanceid;
return this;
}

public SmsMessageFilter build() {
return this.filter;
}

}
}

0 comments on commit c25c884

Please sign in to comment.