Skip to content

Commit

Permalink
Merge pull request #367 from szprutamich/master
Browse files Browse the repository at this point in the history
Release 2.83
  • Loading branch information
szprutamich authored Oct 15, 2019
2 parents 09a4933 + 3df400a commit a62121f
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 238 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.testdroid</groupId>
<artifactId>testdroid-api</artifactId>
<version>2.82</version>
<version>2.83</version>
<packaging>jar</packaging>
<name>Bitbar API v2</name>
<url>https://github.com/bitbar/testdroid-api</url>
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/com/testdroid/api/APIEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import javax.xml.bind.annotation.XmlSeeAlso;
import java.io.File;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
* @author Łukasz Kajda <[email protected]>
Expand Down Expand Up @@ -49,6 +46,7 @@
APIBasicDeviceTime.class,
APIBasicJiraProject.class,
APIBillingPeriod.class,
APIBillingPeriodUsage.class,
APIBuildConfig.class,
APIBuildExecutor.class,
APIBuildResultConfig.class,
Expand Down Expand Up @@ -115,8 +113,6 @@
})
public abstract class APIEntity {

private static final DateFormat API_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd_HH:mm");

public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

static {
Expand All @@ -137,12 +133,6 @@ public APIEntity(Long id) {
this.id = id;
}

@Deprecated
@JsonIgnore
public static String format(Date date) {
return API_DATE_FORMAT.format(date);
}

@JsonIgnore
protected static String createUri(String preUri, String postUri) {
if (preUri.contains("?")) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/testdroid/api/APIKeyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import java.security.GeneralSecurityException;

import static org.apache.commons.lang3.StringUtils.EMPTY;

/**
* @author Michał Szpruta <[email protected]>
*/
Expand Down Expand Up @@ -91,6 +93,6 @@ private void initializeDefaultAPIClient(String cloudURL, String apiKey) {

@Override
protected HttpHeaders getHttpHeaders() {
return new HttpHeaders().setAccept(ACCEPT_HEADER).setBasicAuthentication(apiKey, "");
return new HttpHeaders().setAccept(ACCEPT_HEADER).setBasicAuthentication(apiKey, EMPTY);
}
}
5 changes: 3 additions & 2 deletions src/main/java/com/testdroid/api/AbstractAPIClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import static com.testdroid.api.APIEntity.OBJECT_MAPPER;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.apache.http.HttpStatus.*;

/**
Expand Down Expand Up @@ -327,7 +328,7 @@ protected <T extends APIEntity> String buildUrl(String url, Context<T> context)
if (context != null) {
for (Map.Entry<String, Collection<Object>> entry : context.build().asMap().entrySet()) {
for (Object value : entry.getValue()) {
builder.addParameter(entry.getKey(), value == null ? "" : value.toString());
builder.addParameter(entry.getKey(), value == null ? EMPTY : value.toString());
}
}
}
Expand All @@ -344,7 +345,7 @@ protected void fixMapParameters(Map<String, Object> map) {
key = entry.getKey();
value = entry.getValue();
if (value == null) {
map.put(key, "");
map.put(key, EMPTY);
}
if (value instanceof Enum<?>) {
map.put(key, value.toString());
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/testdroid/api/DefaultAPIClient.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.testdroid.api;

import com.fasterxml.jackson.core.type.TypeReference;
import com.google.api.client.auth.oauth2.BearerToken;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.http.*;
import com.google.api.client.http.apache.ApacheHttpTransport;
import com.testdroid.api.util.TypeReferenceFactory;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHost;
Expand Down Expand Up @@ -136,7 +136,7 @@ protected String acquireAccessToken() throws APIException {
HttpResponse response = null;
try {
if (username == null && password == null) {
return "";
return StringUtils.EMPTY;
}

GenericUrl url = new GenericUrl(String.format("%s/oauth/token", cloudURL));
Expand All @@ -158,8 +158,7 @@ protected String acquireAccessToken() throws APIException {
}

String responseJson = StringUtils.join(IOUtils.readLines(response.getContent(), UTF_8), "\n");
Map<String, String> json = fromJson(responseJson, new TypeReference<Map<String, String>>() {
});
Map<String, String> json = fromJson(responseJson, TypeReferenceFactory.getMapTypeReference());
accessTokenExpireTime = System.currentTimeMillis() + (Long.parseLong(json.get("expires_in")) * 1000);
refreshToken = json.get("refresh_token");
return json.get("access_token");
Expand Down Expand Up @@ -198,8 +197,7 @@ protected String refreshAccessToken() throws APIException {
}

String jsonContent = StringUtils.join(IOUtils.readLines(response.getContent(), UTF_8), "\n");
Map<String, String> json = fromJson(jsonContent, new TypeReference<Map<String, String>>() {
});
Map<String, String> json = fromJson(jsonContent, TypeReferenceFactory.getMapTypeReference());
accessTokenExpireTime = System.currentTimeMillis() + (Long.parseLong(json.get("expires_in")) * 1000);
refreshToken = json.get("refresh_token");
return json.get("access_token");
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/com/testdroid/api/filter/DateFilterEntry.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.testdroid.api.filter;

import com.testdroid.api.dto.Operand;
import com.testdroid.api.util.TimeConverter;

import java.time.LocalDateTime;

Expand All @@ -10,12 +9,6 @@
*/
public class DateTimeFilterEntry extends FilterEntry<LocalDateTime> {

@Deprecated
public DateTimeFilterEntry(DateFilterEntry dateFilterEntry) {
super(dateFilterEntry.getField(), dateFilterEntry.getOperand(), dateFilterEntry.getValue() == null ? null
: TimeConverter.fromDateFields(dateFilterEntry.getValue()));
}

public DateTimeFilterEntry(String field, Operand comparison, LocalDateTime value) {
super(field, comparison, value);
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/testdroid/api/model/APIBillingPeriod.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.xml.bind.annotation.XmlRootElement;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
* @author Damian Sniezek <[email protected]>
Expand Down Expand Up @@ -48,6 +49,8 @@ public class APIBillingPeriod extends APIEntity {

private APIBillingPeriodType apiBillingPeriodType;

private List<APIBillingPeriodUsage> usages;

public APIBillingPeriod() {
}

Expand Down Expand Up @@ -228,6 +231,14 @@ public void setAccountServiceId(Long accountServiceId) {
this.accountServiceId = accountServiceId;
}

public List<APIBillingPeriodUsage> getUsages() {
return usages;
}

public void setUsages(List<APIBillingPeriodUsage> usages) {
this.usages = usages;
}

@Override
protected <T extends APIEntity> void clone(T from) {
APIBillingPeriod period = (APIBillingPeriod) from;
Expand All @@ -247,5 +258,6 @@ protected <T extends APIEntity> void clone(T from) {
this.createTime = period.createTime;
this.apiBillingPeriodType = period.apiBillingPeriodType;
this.accountServiceId = period.accountServiceId;
this.usages = period.usages;
}
}
73 changes: 73 additions & 0 deletions src/main/java/com/testdroid/api/model/APIBillingPeriodUsage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.testdroid.api.model;

import com.testdroid.api.APIEntity;

import javax.xml.bind.annotation.XmlRootElement;

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

private APIDeviceSession.Type type;

private APIDevice.OsType osType;

private long billableSeconds;

private long nonBillableSeconds;

public APIBillingPeriodUsage() {
}

public APIBillingPeriodUsage(
APIDeviceSession.Type type, APIDevice.OsType osType, long billableSeconds, long nonBillableSeconds) {
this.type = type;
this.osType = osType;
this.billableSeconds = billableSeconds;
this.nonBillableSeconds = nonBillableSeconds;
}

public APIDeviceSession.Type getType() {
return type;
}

public APIDevice.OsType getOsType() {
return osType;
}

public long getBillableSeconds() {
return billableSeconds;
}

public long getNonBillableSeconds() {
return nonBillableSeconds;
}

public void setType(APIDeviceSession.Type type) {
this.type = type;
}

public void setOsType(APIDevice.OsType osType) {
this.osType = osType;
}

public void setBillableSeconds(long billableSeconds) {
this.billableSeconds = billableSeconds;
}

public void setNonBillableSeconds(long nonBillableSeconds) {
this.nonBillableSeconds = nonBillableSeconds;
}

@Override
protected <T extends APIEntity> void clone(T from) {
APIBillingPeriodUsage original = (APIBillingPeriodUsage) from;
cloneBase(from);
this.type = original.type;
this.osType = original.osType;
this.billableSeconds = original.billableSeconds;
this.nonBillableSeconds = original.nonBillableSeconds;
}
}
8 changes: 0 additions & 8 deletions src/main/java/com/testdroid/api/model/APIDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
@XmlRootElement
public class APIDevice extends APIEntity {

@XmlType
@Deprecated
public enum DeviceFilter {
FREE,
RECOMMENDED,
NEW
}

@XmlType
public enum DeviceGroupOrigin {
STATIC,
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/com/testdroid/api/model/APIDeviceGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
@XmlRootElement
public class APIDeviceGroup extends APIEntity {

@Deprecated
private Long creditsPrice;

private Long deviceCount;

private String displayName;
Expand All @@ -43,7 +40,6 @@ public APIDeviceGroup(
this.id = id;
this.name = name;
this.displayName = displayName;
this.creditsPrice = deviceCount;
this.deviceCount = deviceCount;
this.userId = userId;
this.osType = osType;
Expand Down Expand Up @@ -75,14 +71,6 @@ public void setDeviceCount(Long deviceCount) {
this.deviceCount = deviceCount;
}

public Long getCreditsPrice() {
return creditsPrice;
}

public void setCreditsPrice(Long creditsPrice) {
this.creditsPrice = creditsPrice;
}

public Long getUserId() {
return userId;
}
Expand Down Expand Up @@ -160,7 +148,6 @@ public void deleteDevice(APIDevice device) throws APIException {
protected <T extends APIEntity> void clone(T from) {
APIDeviceGroup apiDeviceGroup = (APIDeviceGroup) from;
cloneBase(from);
this.creditsPrice = apiDeviceGroup.creditsPrice;
this.deviceCount = apiDeviceGroup.deviceCount;
this.name = apiDeviceGroup.name;
this.displayName = apiDeviceGroup.displayName;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/testdroid/api/model/APILicense.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.time.LocalDateTime;
import java.util.Date;

import static org.apache.commons.lang3.StringUtils.EMPTY;

/**
* @author Łukasz Kajda <[email protected]>
* @author Michał Szpruta <[email protected]>
Expand All @@ -25,7 +27,7 @@ public enum Status {
CLOSED
}

public static final String DISABLED_TEXT = "";
public static final String DISABLED_TEXT = EMPTY;

public static final String ENABLED_TEXT = "on";

Expand Down Expand Up @@ -139,7 +141,7 @@ public APILicense(
}

private static String getTextValue(Integer i) {
return i != null ? Integer.toString(i) : "";
return i != null ? Integer.toString(i) : EMPTY;
}

private static String getTextValue(boolean b) {
Expand Down
Loading

0 comments on commit a62121f

Please sign in to comment.