-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #342 from szprutamich/master
Version 2.65
- Loading branch information
Showing
19 changed files
with
408 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -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]> | ||
|
@@ -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); | ||
} | ||
|
||
/** | ||
|
@@ -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(); | ||
} | ||
|
||
/** | ||
|
@@ -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(); | ||
} | ||
|
||
/** | ||
|
@@ -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(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]> | ||
|
@@ -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; | ||
|
@@ -45,7 +100,7 @@ public enum State { | |
|
||
private APISoftwareVersion softwareVersion; | ||
|
||
private State state; | ||
private ComplexState state; | ||
|
||
private Date stateTime; | ||
|
||
|
@@ -63,8 +118,6 @@ public enum State { | |
|
||
private APIDevice.OsType osType; | ||
|
||
private boolean dirty; | ||
|
||
public APIAdminDevice() { | ||
} | ||
|
||
|
@@ -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() { | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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) { | ||
|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.