Skip to content

Commit bb69320

Browse files
author
Jarkko Laitinen
committed
Merge branch 'development'
2 parents 019d089 + 84b53aa commit bb69320

File tree

6 files changed

+309
-148
lines changed

6 files changed

+309
-148
lines changed

fi/cosky/RouteEventUpdateRequest.java

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package fi.cosky.sdk;
2+
3+
import java.util.Date;
4+
5+
public class RouteEventUpdateRequest extends BaseData {
6+
private int clientId;
7+
private int userId;
8+
private int problemId;
9+
private int vehicleId;
10+
private int eventSequenceNumber;
11+
private Date actualArrivalTime;
12+
private String state;
13+
public int getClientId() {
14+
return clientId;
15+
}
16+
public void setClientId(int clientId) {
17+
this.clientId = clientId;
18+
}
19+
public int getUserId() {
20+
return userId;
21+
}
22+
public void setUserId(int userId) {
23+
this.userId = userId;
24+
}
25+
public int getProblemId() {
26+
return problemId;
27+
}
28+
public void setProblemId(int problemId) {
29+
this.problemId = problemId;
30+
}
31+
public int getVehicleId() {
32+
return vehicleId;
33+
}
34+
public void setVehicleId(int vehicleId) {
35+
this.vehicleId = vehicleId;
36+
}
37+
public int getEventSequenceNumber() {
38+
return eventSequenceNumber;
39+
}
40+
public void setEventSequenceNumber(int eventSequenceNumber) {
41+
this.eventSequenceNumber = eventSequenceNumber;
42+
}
43+
public Date getActualArrivalTime() {
44+
return actualArrivalTime;
45+
}
46+
public void setActualArrivalTime(Date actualArrivalTime) {
47+
this.actualArrivalTime = actualArrivalTime;
48+
}
49+
public String getState() {
50+
return state;
51+
}
52+
public void setState(String state) {
53+
this.state = state;
54+
}
55+
}

fi/cosky/sdk/API.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public API(String baseUrl) {
4848
this.retry = true;
4949
}
5050

51+
private boolean authenticate() {
52+
return authenticate(this.ClientKey, this.ClientSecret);
53+
}
54+
55+
5156
public boolean authenticate(String username, String password) {
5257
this.ClientKey = username;
5358
this.ClientSecret = password;
@@ -97,7 +102,7 @@ public <T extends BaseData> T navigate(Class<T> tClass, Link l, HashMap<String,
97102

98103
if (l.getRel().equals("authenticate")) {
99104
HashMap<String, String> headers = new HashMap<String, String>();
100-
String authorization = "Basic " + Base64.encodeBase64String((ClientKey + ":" + ClientSecret).getBytes());
105+
String authorization = "Basic " + Base64.encodeBase64String((this.ClientKey + ":" + this.ClientSecret).getBytes());
101106
headers.put("authorization", authorization);
102107
result = sendRequestWithAddedHeaders(Verb.POST, this.baseUrl + l.getUri(), tClass, null, headers);
103108
return (T) result;
@@ -226,7 +231,7 @@ private <T extends BaseData> T sendRequest(Verb verb, String url, Class<T> tClas
226231
osw.close();
227232
}
228233
}
229-
else if (verb == verb.POST && object == null) {
234+
else if (verb == Verb.POST && object == null) {
230235
connection.addRequestProperty("Content-Length", "0");
231236
OutputStreamWriter osw = new OutputStreamWriter(connection.getOutputStream());
232237
osw.write("");
@@ -247,8 +252,9 @@ else if (verb == verb.POST && object == null) {
247252
if (connection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
248253
System.out.println("Authentication expired " + connection.getResponseMessage());
249254
if (retry && this.tokenData != null) {
255+
this.tokenData = null;
250256
retry = false;
251-
if( authenticate(this.ClientKey, this.ClientSecret) ) {
257+
if( authenticate() ) {
252258
System.out.println("Authenticated again");
253259
return sendRequest(verb, url, tClass, object);
254260
}
@@ -297,7 +303,6 @@ else if (connection.getResponseCode() >= HttpURLConnection.HTTP_INTERNAL_ERROR )
297303
String abba = null;
298304
if ((abba = connection.getHeaderField("ETag")) != null) {
299305
sb.insert(sb.lastIndexOf("}"), ",\"VersionNumber\":" + abba + "");
300-
301306
}
302307

303308
result = sb.toString();
@@ -361,7 +366,8 @@ private <T extends BaseData> T sendRequestWithAddedHeaders(Verb verb, String url
361366
System.out.println("Authentication expired: " + connection.getResponseMessage());
362367
if ( retry && this.tokenData != null ) {
363368
retry = false;
364-
if( authenticate(this.ClientKey, this.ClientSecret) ) {
369+
this.tokenData = null;
370+
if( authenticate() ) {
365371
System.out.println("Authenticated again");
366372
return sendRequestWithAddedHeaders(verb, url, tClass, object, headers);
367373
}

fi/cosky/sdk/TaskData.java

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class TaskData extends BaseData {
1414
private int Id;
1515
private int VersionNumber;
1616
private List<String> IncompatibleVehicleTypes;
17+
private List<String> CompatibleVehicleTypes;
1718
private double Profit;
1819

1920
public String getInfo() {
@@ -67,7 +68,15 @@ public List<String> getIncompatibleVehicleTypes() {
6768
public void setIncompatibleVehicleTypes(List<String> incompatibleVehicleTypes) {
6869
IncompatibleVehicleTypes = incompatibleVehicleTypes;
6970
}
71+
72+
public List<String> getCompatibleVehicleTypes() {
73+
return CompatibleVehicleTypes;
74+
}
7075

76+
public void setCompatibleVehicleTypes(List<String> compatibleVehicleTypes) {
77+
CompatibleVehicleTypes = compatibleVehicleTypes;
78+
}
79+
7180
public double getProfit() {
7281
return Profit;
7382
}

fi/cosky/sdk/TaskUpdateRequest.java

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class TaskUpdateRequest extends BaseData {
1515
private int ClientId;
1616
private int UserId;
1717
private List<String> IncompatibleVehicleTypes;
18+
private List<String> CompatibleVehicleTypes;
1819
private double Profit;
1920

2021
public String getInfo() {
@@ -73,6 +74,14 @@ public void setIncompatibleVehicleTypes(List<String> incompatibleVehicleTypes) {
7374
IncompatibleVehicleTypes = incompatibleVehicleTypes;
7475
}
7576

77+
public List<String> getCompatibleVehicleTypes() {
78+
return CompatibleVehicleTypes;
79+
}
80+
81+
public void setCompatibleVehicleTypes(List<String> compatibleVehicleTypes) {
82+
CompatibleVehicleTypes = compatibleVehicleTypes;
83+
}
84+
7685
public List<TaskEventUpdateRequest> getTaskEvents() {
7786
return TaskEvents;
7887
}

0 commit comments

Comments
 (0)