com.blackbirdai.client.model.VRecRequest Maven / Gradle / Ivy
package com.blackbirdai.client.model;
import com.blackbirdai.client.InvalidRequestException;
import com.blackbirdai.client.util.Encoders;
import com.blackbirdai.client.util.Joiners;
import com.blackbirdai.client.util.Patterns;
import com.google.common.collect.Lists;
import java.util.List;
/**
* Container for the parameters of a search request.
*/
public class VRecRequest {
private final String id;
private Integer num = null;
private List fields = null;
private List filterParams = null;
private GroupParam groupParam = null;
private String sId = null;
private String uId = null;
/**
* Default empty constructor for VRecRequest.
*/
public VRecRequest(String id) {
this.id = id;
}
/**
* Updates 'num' parameter.
*
* @return A reference to this updated object.
*/
public VRecRequest withNum(Integer num) {
this.num = num;
return this;
}
/**
* Update 'fields' parameters. Overwrites previous 'fields' parameters.
*
* @return A reference to this updated object.
*/
public VRecRequest withFields(List fields) {
this.fields = fields;
return this;
}
/**
* Appends a 'fields' parameter.
*
* @return A reference to this updated object.
*/
public VRecRequest addField(String field) {
if (this.fields == null) {
this.fields = Lists.newArrayList();
}
this.fields.add(field);
return this;
}
/**
* Update 'filter' parameters. Overwrites previous 'filter' parameters.
*
* @return A reference to this updated object.
*/
public VRecRequest withFilters(List filterParams) {
this.filterParams = filterParams;
return this;
}
/**
* Append a 'filter' parameter.
*
* @return A reference to this updated object.
*/
public VRecRequest addFilter(FilterParam filterParam) {
if (this.filterParams == null) {
this.filterParams = Lists.newArrayList();
}
this.filterParams.add(filterParam);
return this;
}
/**
* Update 'group' parameter.
*
* @return Updated object.
*/
public VRecRequest withGroup(GroupParam groupParam) {
this.groupParam = groupParam;
return this;
}
/**
* Update 'sid' parameter (session-id).
*
* @return Updated object.
*/
public VRecRequest withSId(String sId) {
this.sId = sId;
return this;
}
/**
* Update 'uid' parameter (user-id).
*
* @return Updated object.
*/
public VRecRequest withUId(String uId) {
this.uId = uId;
return this;
}
/**
* For internal use. Returns query-string for http request.
* @exclude
*/
public String toQueryStr(String instanceId, String subject) throws InvalidRequestException {
StringBuilder builder = new StringBuilder("/v1/" + instanceId + "/" + subject + "/vrec?id=");
builder.append(id);
if (num != null) {
builder.append("&num=");
builder.append(num);
}
if (fields != null) {
for (String field: fields) {
if (!Patterns.FIELD_P.matcher(field).matches()) {
throw new InvalidRequestException("Invalid field-name found: " + field);
}
}
builder.append("&fields=");
Joiners.COMMA_JOINER.appendTo(builder, fields);
}
if (filterParams != null) {
for (FilterParam filterParam : filterParams) {
builder.append('&');
filterParam.appendQueryStr(builder);
}
}
if (groupParam != null) {
groupParam.appendQueryStr(builder);
}
if (sId != null) {
builder.append("&sid=");
builder.append(Encoders.urlEncode(sId));
}
if (uId != null) {
builder.append("&uid=");
builder.append(Encoders.urlEncode(uId));
}
return builder.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy