Skip to content

Commit

Permalink
Merge pull request #342 from szprutamich/master
Browse files Browse the repository at this point in the history
Version 2.65
  • Loading branch information
szprutamich authored Sep 25, 2018
2 parents ad44042 + b20b24d commit 8d07b9f
Show file tree
Hide file tree
Showing 19 changed files with 408 additions and 242 deletions.
2 changes: 1 addition & 1 deletion 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.64</version>
<version>2.65</version>
<packaging>jar</packaging>
<name>Testdroid API v2</name>
<url>https://github.com/bitbar/testdroid-api</url>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/testdroid/api/APIEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
APIDeviceSessionStep.class,
APIDeviceStatus.class,
APIDeviceTimeCountSessionReportEntry.class,
APIDeviceTimeEntry.class,
APIDeviceUsage.class,
APIEnum.class,
APIExceptionMessage.class,
Expand Down Expand Up @@ -108,6 +107,7 @@
APITestRunParameter.class,
APIUser.class,
APIUserDeviceTime.class,
APIUserDeviceTimeSummary.class,
APIUserFile.class,
APIUserFileProperty.class,
APIUserFileTag.class,
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/com/testdroid/api/APIList.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.testdroid.api;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.testdroid.api.dto.Context;
import com.testdroid.api.filter.FilterEntry;

import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
Expand All @@ -12,6 +13,7 @@
import java.util.List;

import static com.testdroid.api.dto.Context.*;
import static java.util.stream.Collectors.joining;

/**
* @author Łukasz Kajda <[email protected]>
Expand Down Expand Up @@ -58,17 +60,19 @@ public APIList(String requestURL, List<T> data, Integer total, Context<T> ctx) {
this.sort = sort;
this.data = data;
this.context = ctx;
String filter = ctx.getFilters().stream().map(FilterEntry::toString).collect(joining(FILTER_DELIMITER));
if (offset + limit < total) {
this.next = getListURL(requestURL, offset + limit, limit, search, sort);
this.next = getListURL(requestURL, offset + limit, limit, search, sort, filter);
}
if (offset - limit >= 0) {
this.previous = getListURL(requestURL, offset - limit, limit, search, sort);
this.previous = getListURL(requestURL, offset - limit, limit, search, sort, filter);
}
}

private String getListURL(String requestURL, long offset, long limit, String search, String sort) {
return String.format("%s?%s=%s&%s=%s&%s=%s&%s=%s", requestURL, OFFSET_REQUEST_PARAM, offset,
LIMIT_REQUEST_PARAM, limit, SEARCH_REQUEST_PARAM, search, SORT_REQUEST_PARAM, sort);
private String getListURL(String requestURL, long offset, long limit, String search, String sort, String filter) {
return String.format("%s?%s=%s&%s=%s&%s=%s&%s=%s&%s=%s", requestURL, OFFSET_REQUEST_PARAM, offset,
LIMIT_REQUEST_PARAM, limit, SEARCH_REQUEST_PARAM, search, SORT_REQUEST_PARAM, sort,
FILTER_REQUEST_PARAM, filter);
}

/**
Expand Down Expand Up @@ -96,7 +100,7 @@ public APIList<T> getNextItems() throws APIException {
if (!isNextAvailable()) {
return null;
}
return new APIListResource(client, selfURI, context.setOffset(offset + limit)).getEntity();
return new APIListResource<>(client, selfURI, context.setOffset(offset + limit)).getEntity();
}

/**
Expand All @@ -112,7 +116,7 @@ public APIList<T> getPreviousItems() throws APIException {
if (!isPreviousAvailable()) {
return null;
}
return new APIListResource(client, selfURI, context.setOffset(offset - limit)).getEntity();
return new APIListResource<>(client, selfURI, context.setOffset(offset - limit)).getEntity();
}

/**
Expand Down Expand Up @@ -145,6 +149,7 @@ public T get(int index) {
return this.data.get(index);
}

@JsonProperty(access = JsonProperty.Access.READ_ONLY)
public boolean isEmpty() {
return this.data.isEmpty();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/testdroid/api/APIListResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public APIListResource<T> getNext() throws APIException {
return null;
}
APIList<T> list = getEntity();
return new APIListResource(client, resourceURI, context.setOffset(list.getOffset() + list.getLimit()));
return new APIListResource<>(client, resourceURI, context.setOffset(list.getOffset() + list.getLimit()));
}

/**
Expand All @@ -96,6 +96,6 @@ public APIListResource<T> getPrevious() throws APIException {
return null;
}
APIList<T> list = getEntity();
return new APIListResource(client, resourceURI, context.setOffset(list.getOffset() - list.getLimit()));
return new APIListResource<>(client, resourceURI, context.setOffset(list.getOffset() - list.getLimit()));
}
}
9 changes: 5 additions & 4 deletions src/main/java/com/testdroid/api/dto/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.testdroid.api.APISort;
import com.testdroid.api.filter.FilterEntry;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -122,6 +119,10 @@ public List<FilterEntry> getFilters() {
return filters;
}

public Optional<FilterEntry> findFilter(String field, Operand operand) {
return filters.stream().filter(f -> f.getField().equals(field) && f.getOperand().equals(operand)).findAny();
}

public Context<T> setFilters(List<FilterEntry> filters) {
this.filters = filters;
return this;
Expand Down
88 changes: 67 additions & 21 deletions src/main/java/com/testdroid/api/model/APIAdminDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.testdroid.api.APIEntity;
import org.apache.commons.lang3.tuple.Pair;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import java.util.Date;
import java.util.*;

/**
* @author Łukasz Kajda <[email protected]>
Expand All @@ -27,6 +28,60 @@ public enum State {
OFFLINE
}

@XmlType(namespace = "APIAdminDevice")
public enum SubState {
CLEANING,
DIRTY,
FREE,
TESTING
}

@XmlType(namespace = "APIAdminDevice")
public enum ComplexState {
OFFLINE(State.OFFLINE, SubState.DIRTY), // for backward compatibility
ONLINE(State.ONLINE, SubState.FREE), // for backward compatibility
OFFLINE_CLEANING(State.OFFLINE, SubState.CLEANING),
OFFLINE_DIRTY(State.OFFLINE, SubState.DIRTY),
OFFLINE_FREE(State.OFFLINE, SubState.FREE),
OFFLINE_TESTING(State.OFFLINE, SubState.TESTING),
ONLINE_CLEANING(State.ONLINE, SubState.CLEANING),
ONLINE_DIRTY(State.ONLINE, SubState.DIRTY),
ONLINE_FREE(State.ONLINE, SubState.FREE),
ONLINE_TESTING(State.ONLINE, SubState.TESTING);

private State state;

private SubState subState;

private static final Map<Pair<State, SubState>, ComplexState> MAP = new HashMap<>(values().length, 1);

static {
Arrays.stream(values()).forEach(c -> MAP.put(Pair.of(c.state, c.subState), c));
}

ComplexState(State state, SubState subState) {
this.state = state;
this.subState = subState;
}

public State getState() {
return state;
}

public SubState getSubState() {
return subState;
}

public ComplexState compute(State state) {
return MAP.get(Pair.of(state, subState));
}

public ComplexState compute(SubState subState) {
return MAP.get(Pair.of(state, subState));
}

}

private APICluster cluster;

private Long deviceModelId;
Expand All @@ -45,7 +100,7 @@ public enum State {

private APISoftwareVersion softwareVersion;

private State state;
private ComplexState state;

private Date stateTime;

Expand All @@ -63,8 +118,6 @@ public enum State {

private APIDevice.OsType osType;

private boolean dirty;

public APIAdminDevice() {
}

Expand All @@ -75,29 +128,31 @@ public APIAdminDevice(Long id) {

public APIAdminDevice(
Long id, String name, boolean enabled, String serialId, String fingerprint, String unlockGesture,
APISoftwareVersion softwareVersion, Long deviceModelId, String deviceModelName, State state,
Date stateTime, InitStep initStep, String ipAddress, APICluster cluster, Date lastOnlineTime,
Long accountId, String mainUserEmail, Boolean locked, APIDevice.OsType osType, Boolean dirty) {
Long softwareVersionId, String releaseVersion, Integer apiLevel, Long deviceModelId, String deviceModelName,
ComplexState state, Date stateTime, InitStep initStep, String ipAddress, Long clusterId, String clusterName,
String clusterUrl, APICluster.State clusterState, Date clusterStateTime, Date clusterStateChangeTime,
Boolean clusterEnabled, Date lastOnlineTime, Long accountId, String mainUserEmail, Boolean locked,
APIDevice.OsType osType) {
super(id);
this.name = name;
this.enabled = enabled;
this.serialId = serialId;
this.fingerprint = fingerprint;
this.unlockGesture = unlockGesture;
this.softwareVersion = softwareVersion;
this.softwareVersion = new APISoftwareVersion(softwareVersionId, releaseVersion, apiLevel);
this.deviceModelId = deviceModelId;
this.deviceModelName = deviceModelName;
this.state = state;
this.stateTime = stateTime;
this.initStep = initStep;
this.ipAddress = ipAddress;
this.cluster = cluster;
this.cluster = new APICluster(clusterId, clusterName, clusterUrl, clusterState,
clusterStateTime, clusterStateChangeTime, clusterEnabled);
this.lastOnlineTime = lastOnlineTime;
this.accountId = accountId;
this.mainUserEmail = mainUserEmail;
this.locked = locked;
this.osType = osType;
this.dirty = dirty;
}

public String getName() {
Expand Down Expand Up @@ -156,11 +211,11 @@ public void setDeviceModelId(Long deviceModelId) {
this.deviceModelId = deviceModelId;
}

public State getState() {
public ComplexState getState() {
return state;
}

public void setState(State state) {
public void setState(ComplexState state) {
this.state = state;
}

Expand Down Expand Up @@ -244,14 +299,6 @@ public void setOsType(APIDevice.OsType osType) {
this.osType = osType;
}

public boolean isDirty() {
return dirty;
}

public void setDirty(boolean dirty) {
this.dirty = dirty;
}

@Override
@JsonIgnore
protected <T extends APIEntity> void clone(T from) {
Expand All @@ -275,6 +322,5 @@ protected <T extends APIEntity> void clone(T from) {
this.mainUserEmail = adminDevice.mainUserEmail;
this.locked = adminDevice.locked;
this.osType = adminDevice.osType;
this.dirty = adminDevice.dirty;
}
}
20 changes: 4 additions & 16 deletions src/main/java/com/testdroid/api/model/APIAdminDeviceEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public enum DeviceEventType {

private DeviceEventType type;

private APIAdminDevice.State state;

private Boolean dirty;
private APIAdminDevice.ComplexState state;

private APIAdminDevice device;

Expand All @@ -40,7 +38,7 @@ public APIAdminDeviceEvent() {
}

public APIAdminDeviceEvent(Long id, LocalDateTime time, APIAdminDeviceEvent.DeviceEventType type,
APIAdminDevice.State state, Boolean dirty, Long deviceId,
APIAdminDevice.ComplexState state, Long deviceId,
Long clusterId, String name, String url, APICluster.State clusterState, Date stateTime,
Date stateChangeTime, Boolean enabled,
Long deviceSessionId, Date createTime, Date startTime, Date endTime, String startedByDisplayName,
Expand All @@ -51,7 +49,6 @@ public APIAdminDeviceEvent(Long id, LocalDateTime time, APIAdminDeviceEvent.Devi
this.time = TimeConverter.toDate(time);
this.type = type;
this.state = state;
this.dirty = dirty;
this.device = new APIAdminDevice(deviceId);
this.cluster = new APICluster(clusterId, name, url, clusterState, stateTime, stateChangeTime, enabled);
this.deviceSession = new APIAdminDeviceSession(deviceSessionId, createTime, startTime, endTime,
Expand Down Expand Up @@ -99,29 +96,20 @@ public void setDeviceSession(APIAdminDeviceSession deviceSession) {
this.deviceSession = deviceSession;
}

public APIAdminDevice.State getState() {
public APIAdminDevice.ComplexState getState() {
return state;
}

public void setState(APIAdminDevice.State state) {
public void setState(APIAdminDevice.ComplexState state) {
this.state = state;
}

public Boolean getDirty() {
return dirty;
}

public void setDirty(Boolean dirty) {
this.dirty = dirty;
}

@Override
protected <T extends APIEntity> void clone(T from) {
APIAdminDeviceEvent deviceEvent = (APIAdminDeviceEvent) from;
cloneBase(from);
this.time = deviceEvent.time;
this.state = deviceEvent.state;
this.dirty = deviceEvent.dirty;
this.device = deviceEvent.device;
this.cluster = deviceEvent.cluster;
this.deviceSession = deviceEvent.deviceSession;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class APIAdminDeviceProblemPair extends APIEntity {

@XmlType(namespace = "APIAdminDeviceProblemPair", name = "APIAdminDeviceProblemPairType")
public enum Type {
CLEANING,
DIRTY,
OFFLINE,
LOW_BATTERY,
Expand Down
Loading

0 comments on commit 8d07b9f

Please sign in to comment.