Skip to content

Commit

Permalink
Merge pull request #306 from szprutamich/master
Browse files Browse the repository at this point in the history
Version 2.16
  • Loading branch information
szprutamich committed Jun 7, 2016
2 parents ed87273 + 0ab8d64 commit 51ac28b
Show file tree
Hide file tree
Showing 37 changed files with 949 additions and 417 deletions.
26 changes: 4 additions & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.testdroid</groupId>
<artifactId>testdroid-api</artifactId>
<version>2.9</version>
<version>2.16</version>
<packaging>jar</packaging>
<name>Testdroid API v2</name>
<url>https://github.com/bitbar/testdroid-api</url>
Expand Down Expand Up @@ -39,14 +39,6 @@
</licenses>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>fixtures/*.zip</include>
<include>fixtures/*.apk</include>
</includes>
</resource>
<resource>
<filtering>false</filtering>
<directory>src/main/java</directory>
Expand Down Expand Up @@ -132,19 +124,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
<version>1.0-2</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/testdroid/api/APIDeviceQueryBuilder.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.testdroid.api;

import com.testdroid.api.model.APIDevice;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -49,10 +50,15 @@ public APIDeviceQueryBuilder search(String search) {
}

@Override
public APIDeviceQueryBuilder sort(Class<? extends APIEntity> type, APISort.SortItem... sortItems) {
public APIDeviceQueryBuilder sort(Class<? extends APIEntity> type, List<APISort.SortItem> sortItems) {
return (APIDeviceQueryBuilder) super.sort(type, sortItems);
}

@Override
public APIDeviceQueryBuilder filter(List<APIFilter.APIFilterItem> filterItems) {
return (APIDeviceQueryBuilder) super.filter(filterItems);
}

@Override
protected Map<String, Object> build() {
Map<String, Object> result = super.build();
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/testdroid/api/APIEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.fasterxml.jackson.annotation.JsonView;
import com.testdroid.api.model.*;
import com.testdroid.api.model.jrjc.*;
import com.testdroid.api.um.model.APIService;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
Expand Down Expand Up @@ -57,9 +56,11 @@
APIProject.class,
APIProjectJobConfig.class,
APIProjectSharing.class,
APIProjectTypeExtended.class,
APIRole.class,
APIService.class,
APIScreenshot.class,
APIScreenshotExtended.class,
APISoftwareVersion.class,
APITag.class,
APITestCaseRun.class,
Expand Down Expand Up @@ -89,7 +90,7 @@
APIJiraPriority.class,
APIJiraProject.class,
APIJiraServerInfo.class,
APIDeviceRunDataAvailability.class,
APIDeviceSessionDataAvailability.class,
APITestRunDataAvailability.class,
APIUserDeviceTime.class,
APIDeviceTimeEntry.class,
Expand Down Expand Up @@ -197,7 +198,7 @@ protected <T extends APIEntity> APIListResource<T> getListResource(
limit = 10;
}
return new APIListResource<T>(client, uri, new APIQueryBuilder().offset(offset).limit(limit).search
(search).sort(type, sort.getItems()));
(search).sort(type, sort.getSorts()));
}

@JsonIgnore
Expand Down
16 changes: 3 additions & 13 deletions src/main/java/com/testdroid/api/APIExceptionMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@
* @author Łukasz Kajda <[email protected]>
*/
@XmlRootElement
public class APIExceptionMessage {

private String message;
public class APIExceptionMessage extends APIMessage {

private Integer statusCode;

public APIExceptionMessage() {
}

public APIExceptionMessage(Integer statusCode, String message) {
super(message);
this.statusCode = statusCode;
this.message = message;
}

public Integer getStatusCode() {
Expand All @@ -30,12 +28,4 @@ public void setStatusCode(Integer statusCode) {
this.statusCode = statusCode;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

}
}
14 changes: 0 additions & 14 deletions src/main/java/com/testdroid/api/APIExportable.java

This file was deleted.

98 changes: 98 additions & 0 deletions src/main/java/com/testdroid/api/APIFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.testdroid.api;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* @author Michał Szpruta <[email protected]>
*/
public class APIFilter {

private List<APIFilterItem> filterItems;

public APIFilter() {
this.filterItems = Collections.emptyList();
}

public APIFilter(List<APIFilterItem> filterItems) {
this.filterItems = filterItems;
}

public static APIFilter create(List<APIFilterItem> filterItems) {
return new APIFilter(filterItems);
}

public String serialize() {
List<String> resultItems = new ArrayList<String>();
for (APIFilterItem item : filterItems) {
resultItems.add(item.serialize());
}
return StringUtils.join(resultItems, ";");
}

public static class APIFilterItem {

public static enum Operand {
GT,
AFTER,
LT,
BEFORE,
ON,
EQ,
ISNULL,
IN,
NOTIN,
INORNULL,
BEFOREORNULL,
BEFOREOREQUAL,
AFTERORNULL
}

public static enum Type {
N,
D,
S,
B,
LN,
LD,
LS,
LB
}

private String fieldName;

private Operand operand;

private Type type;

private Object[] values;

public APIFilterItem(Type type, String fieldName, Operand operand, Object... values) {
this.type = type;
this.fieldName = fieldName;
this.operand = operand;
this.values = values;
}

private String serialize() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(type.name().toLowerCase());
stringBuilder.append("_");
stringBuilder.append(fieldName);
stringBuilder.append("_");
stringBuilder.append(operand.name().toLowerCase());
if (values.length > 0) {
stringBuilder.append("_");
for (Object object : values) {
stringBuilder.append(object);
stringBuilder.append("|");
}
stringBuilder.setLength(stringBuilder.length() - 1);
}
return stringBuilder.toString();
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/testdroid/api/APIKeyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public APIListResource<APIDevice> getDevices(
APIDeviceQueryBuilder builder = new APIDeviceQueryBuilder().offset((int) offset).limit((int) limit)
.search(search).filterWithDeviceFilters(filters);
if (sort != null) {
builder.sort(APIDevice.class, sort.getItems());
builder.sort(APIDevice.class, sort.getSorts());
}
return new APIListResource<APIDevice>(this, DEVICES_URI, builder);
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/testdroid/api/APIMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.testdroid.api;

import javax.xml.bind.annotation.XmlRootElement;

/**
* @author Michał Szpruta <[email protected]>
*/
@XmlRootElement
public class APIMessage {

private String message;

public APIMessage() {
}

public APIMessage(String message) {
this.message = message;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

}
14 changes: 12 additions & 2 deletions src/main/java/com/testdroid/api/APIQueryBuilder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.testdroid.api;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -28,11 +29,14 @@ public class APIQueryBuilder {
*/
private APISort sort;

private APIFilter filter;

public APIQueryBuilder() {
this.offset = 0;
this.limit = 10;
this.search = null;
this.sort = null;
this.filter = null;
}

public APIQueryBuilder offset(long offset) {
Expand All @@ -56,8 +60,13 @@ public APIQueryBuilder search(String search) {
return this;
}

public APIQueryBuilder sort(Class<? extends APIEntity> type, APISort.SortItem... sortItems) {
this.sort = APISort.create(type, sortItems);
public APIQueryBuilder sort(Class<? extends APIEntity> type, List<APISort.SortItem> sortItems) {
this.sort = APISort.create(sortItems);
return this;
}

public APIQueryBuilder filter(List<APIFilter.APIFilterItem> filterItems) {
this.filter = APIFilter.create(filterItems);
return this;
}

Expand All @@ -67,6 +76,7 @@ protected Map<String, Object> build() {
put("offset", offset);
put("search", search);
put("sort", sort != null ? sort.serialize() : null);
put("filter", filter != null ? filter.serialize() : null);
}};
}
}
Loading

0 comments on commit 51ac28b

Please sign in to comment.