Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #46 from amagar088/master
Browse files Browse the repository at this point in the history
Added attributes to subscriber object and made some minor improvisations
  • Loading branch information
amagar088 committed May 17, 2016
2 parents 864e573 + 96ae191 commit 36691a3
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@

# Maven
target/
/bin/
75 changes: 75 additions & 0 deletions src/main/java/com/exacttarget/fuelsdk/ETApiProperty.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.exacttarget.fuelsdk;

import javax.xml.bind.annotation.XmlElement;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.cxf.xjc.runtime.JAXBToStringStyle;

import com.exacttarget.fuelsdk.annotations.ExternalName;

public class ETApiProperty {

@ExternalName("Name")
protected String name;
@ExternalName("Value")
protected String value;

/**
* Gets the value of the name property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getName() {
return name;
}

/**
* Sets the value of the name property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setName(String value) {
this.name = value;
}

/**
* Gets the value of the value property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getValue() {
return value;
}

/**
* Sets the value of the value property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setValue(String value) {
this.value = value;
}

/**
* Generates a String representation of the contents of this type.
* This is an extension method, produced by the 'ts' xjc plugin
*
*/
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, JAXBToStringStyle.DEFAULT_STYLE);
}

}
81 changes: 80 additions & 1 deletion src/main/java/com/exacttarget/fuelsdk/ETDataExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;

import com.exacttarget.fuelsdk.ETDataExtensionColumn.Type;
import com.exacttarget.fuelsdk.annotations.ExternalName;
import com.exacttarget.fuelsdk.annotations.InternalName;
import com.exacttarget.fuelsdk.annotations.RestObject;
Expand All @@ -64,6 +67,7 @@
"ID", "Fields"
})
public class ETDataExtension extends ETSoapObject {
static final int DEFAULT_PAGE_SIZE = 2500;
private static Logger logger = Logger.getLogger(ETDataExtension.class);

@ExternalName("id")
Expand Down Expand Up @@ -351,6 +355,36 @@ public static ETResponse<ETDataExtensionRow> select(ETClient client,
"DataExtensionObject[" + name + "]",
filter,
ETDataExtensionRow.class);

List<ETResult<ETDataExtensionRow>> rowSet = sortRowSet(response.getResults(), filter);

List<ETResult<ETDataExtensionRow>> paginatedRowSet;
if (page == null) {
page = response.getPage();
if (page == null) {
page = 1;
}
}
int iPage = page;
if (pageSize == null) {
pageSize = response.getPageSize();
if (pageSize == null) {
pageSize = DEFAULT_PAGE_SIZE;
}
}
int iPageSize = pageSize;
int pageStart = (iPage - 1) * iPageSize;
int pageEnd = pageStart + iPageSize;
if (pageStart < rowSet.size()) {
if (pageEnd > rowSet.size()) {
pageEnd = rowSet.size();
}
} else {
pageEnd = pageStart;
}
paginatedRowSet = rowSet.subList(pageStart, pageEnd);
response = createResponse(response, paginatedRowSet, page, pageSize, pageEnd, rowSet.size());
logger.debug("final response: " + response);

//
// XXX reenable support for paginated retrieves via REST API
Expand Down Expand Up @@ -396,7 +430,52 @@ public static ETResponse<ETDataExtensionRow> select(ETClient client,

return response;
}

private static List<ETResult<ETDataExtensionRow>> sortRowSet(List<ETResult<ETDataExtensionRow>> rowSet, ETFilter filter) throws ETSdkException {
logger.debug("rowSet: " + rowSet);
logger.debug("filter: " + filter);
if (filter.getOrderBy() != null && filter.getOrderBy().size() > 0) {
// Sort the results
final String orderByColumn = filter.getOrderBy().get(0).toLowerCase();
List<String> list = filter.getProperties();
if (list.contains(orderByColumn)) {
final boolean sortAsc = filter.getOrderByAsc();
List<ETResult<ETDataExtensionRow>> sortedRowSet = rowSet;
Collections.sort(sortedRowSet, new Comparator<ETResult<ETDataExtensionRow>>() {
public int compare(ETResult<ETDataExtensionRow> o1, ETResult<ETDataExtensionRow> o2) {
if (o1.getObject().getColumn(orderByColumn) == null) {
return 0;
}
int result = o1.getObject().getColumn(orderByColumn).compareTo(o2.getObject().getColumn(orderByColumn));
return (sortAsc ? result : -result);
}
});
rowSet = sortedRowSet;
logger.debug("sortedRowSet: " + sortedRowSet);
} else {
throw new ETSdkException("Can't order by '" + orderByColumn + "' as it is not in selected columns list: "
+ list);
}
}
return rowSet;
}

private static ETResponse<ETDataExtensionRow> createResponse(ETResponse<ETDataExtensionRow> response,
List<ETResult<ETDataExtensionRow>> paginatedRowSet,
Integer page, Integer pageSize, Integer pageEnd,
Integer totalCount) {
ETResponse<ETDataExtensionRow> pr = new ETResponse<ETDataExtensionRow>();
pr.setResponseCode(response.getResponseCode());
pr.setResponseMessage(response.getResponseMessage());
pr.setStatus(response.getStatus());
pr.setPage(page);
pr.setPageSize(pageSize);
pr.setTotalCount(totalCount);
pr.setMoreResults((pageEnd < totalCount));
pr.setRequestId(response.getRequestId());
pr.getResults().addAll(paginatedRowSet);
return pr;
}

public static ETResponse<ETDataExtensionRow> select(ETClient client,
String dataExtension,
Integer page,
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/exacttarget/fuelsdk/ETDataExtensionRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,22 @@ public void setColumns(Map<String, String> columns) {
setColumn(column.getKey(), column.getValue());
}
}

public boolean equals(Object obj) {
if (obj == null) return false;
if (!obj.getClass().equals(getClass())) {
return false;
}
// Note: We are using compared object as a source of columns
// This way we can use it to check for any changes that may apply from this to original object
ETDataExtensionRow src, target;
src = (ETDataExtensionRow) obj;
target = this;
for (String column : src.getColumnNames()) {
if (!src.getColumn(column).equals(target.getColumn(column))) {
return false;
}
}
return true;
}
}
16 changes: 12 additions & 4 deletions src/main/java/com/exacttarget/fuelsdk/ETSoapObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,23 @@ protected static <T extends ETSoapObject> ETResponse<T> retrieve(ETClient client
if (logger.isTraceEnabled()) {
logger.trace("RetrieveRequest:");
logger.trace(" objectType = " + retrieveRequest.getObjectType());
String line = null;
StringBuilder line = new StringBuilder(" properties = { ");
//String line = null;
for (String property : retrieveRequest.getProperties()) {
if (line == null) {

line.append(property).append(", ");
}
if (retrieveRequest.getProperties().size() > 0) {
line.setLength(line.length() - 2);
/*if (line == null) {
line = " properties = { " + property;
} else {
line += ", " + property;
}
}*/
}
logger.trace(line + " }");
line.append(" }");
logger.trace(line.toString());
//logger.trace(line + " }");
if (filter != null) {
logger.trace(" filter = " + toFilterPart(expression));
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/exacttarget/fuelsdk/ETSubscriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.exacttarget.fuelsdk.annotations.ExternalName;
import com.exacttarget.fuelsdk.annotations.InternalName;
import com.exacttarget.fuelsdk.annotations.SoapObject;
import com.exacttarget.fuelsdk.internal.Attribute;
import com.exacttarget.fuelsdk.internal.Subscriber;

/**
Expand Down Expand Up @@ -72,6 +73,8 @@ public class ETSubscriber extends ETSoapObject {
private Date unsubscribedDate = null;
@ExternalName("lists")
private List<ETSubscriberList> lists = null;
@ExternalName("attributes")
protected List<Attribute> attributes;

public ETSubscriber() {}

Expand Down Expand Up @@ -147,6 +150,16 @@ public List<ETSubscriberList> getLists() {
}
return lists;
}

/**
* Gets the value of the attributes property.
*/
public List<Attribute> getAttributes() {
if (attributes == null) {
attributes = new ArrayList<Attribute>();
}
return this.attributes;
}

/**
* @deprecated
Expand Down

1 comment on commit 36691a3

@sgerrand
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💝

Please sign in to comment.