Skip to content

Commit c0fca47

Browse files
author
Daniel Tolbert
authored
Merge pull request #18 from Bandwidth/Dx-994
DX 994
2 parents c55fbb2 + 7b8444e commit c0fca47

File tree

7 files changed

+296
-2
lines changed

7 files changed

+296
-2
lines changed

src/main/java/com/bandwidth/iris/sdk/IrisClient.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.apache.http.entity.StringEntity;
1717
import org.apache.http.impl.client.DefaultHttpClient;
1818
import org.apache.http.util.EntityUtils;
19+
import java.io.FileOutputStream;
1920

2021
import javax.xml.stream.XMLInputFactory;
2122
import java.io.File;
@@ -68,6 +69,16 @@ public <T> T get(String uri, Class<T> returnType) throws Exception {
6869
return processResponse(response.getResponseBody(), returnType);
6970
}
7071

72+
public byte[] getFile(String uri) throws Exception {
73+
HttpGet get = new HttpGet(uri);
74+
HttpResponse response = httpClient.execute(get);
75+
76+
if (response.getStatusLine().getStatusCode() != 200) {
77+
throw new IrisClientException("Status code getting LOAS file: " + response.getStatusLine().getStatusCode());
78+
}
79+
return response.getEntity() != null ? EntityUtils.toByteArray(response.getEntity()) : new byte[]{};
80+
}
81+
7182
public IrisResponse get(String uri) throws Exception {
7283
HttpGet get = new HttpGet(uri);
7384
return executeRequest(get);

src/main/java/com/bandwidth/iris/sdk/IrisPath.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ public class IrisPath {
2626
public static final String IMPORT_TN_CHECKER = "importTnChecker";
2727
public static final String CSRS = "csrs";
2828
public static final String NOTES = "notes";
29+
public static final String LOAS = "loas";
2930

3031
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.bandwidth.iris.sdk.model;
2+
3+
import com.bandwidth.iris.sdk.IrisClient;
4+
import com.bandwidth.iris.sdk.IrisPath;
5+
6+
import javax.xml.bind.annotation.*;
7+
8+
9+
@XmlRootElement(name="fileListResponse")
10+
@XmlAccessorType(XmlAccessType.FIELD)
11+
public class FileListResponse extends BaseModel {
12+
13+
@XmlElement(name = "fileCount")
14+
private int fileCount;
15+
16+
@XmlElement(name = "fileNames")
17+
private String[] fileNames;
18+
19+
@XmlElement(name = "resultCode")
20+
private int resultCode;
21+
22+
@XmlElement(name = "resultMessage")
23+
private String resultMessage;
24+
25+
public int getFileCount() {
26+
return fileCount;
27+
}
28+
29+
public void setFileCount(int fileCount) {
30+
this.fileCount = fileCount;
31+
}
32+
33+
public String[] getFileNames() {
34+
return fileNames;
35+
}
36+
37+
public void setFileNames(String[] fileNames) {
38+
this.fileNames = fileNames;
39+
}
40+
41+
public int getResultCode() {
42+
return resultCode;
43+
}
44+
45+
public void setResultCode(int resultCode) {
46+
this.resultCode = resultCode;
47+
}
48+
49+
public String getResultMessage() {
50+
return resultMessage;
51+
}
52+
53+
public void setResultMessage(String resultMessage) {
54+
this.resultMessage = resultMessage;
55+
}
56+
57+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.bandwidth.iris.sdk.model;
2+
3+
import javax.xml.bind.annotation.XmlAccessType;
4+
import javax.xml.bind.annotation.XmlAccessorType;
5+
import javax.xml.bind.annotation.XmlElement;
6+
import javax.xml.bind.annotation.XmlRootElement;
7+
8+
@XmlRootElement(name="fileUploadResponse")
9+
@XmlAccessorType(XmlAccessType.FIELD)
10+
public class FileUploadResponse {
11+
12+
13+
@XmlElement(name = "fileName")
14+
private String fileName;
15+
16+
@XmlElement(name = "resultCode")
17+
private int resultCode;
18+
19+
@XmlElement(name = "resultMessage")
20+
private String resultMessage;
21+
22+
23+
public String getFileName() {
24+
return fileName;
25+
}
26+
27+
public void setFileName(String fileName) {
28+
this.fileName = fileName;
29+
}
30+
31+
public int getResultCode() {
32+
return resultCode;
33+
}
34+
35+
public void setResultCode(int resultCode) {
36+
this.resultCode = resultCode;
37+
}
38+
39+
public String getResultMessage() {
40+
return resultMessage;
41+
}
42+
43+
public void setResultMessage(String resultMessage) {
44+
this.resultMessage = resultMessage;
45+
}
46+
}

src/main/java/com/bandwidth/iris/sdk/model/ImportTnOrder.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.bandwidth.iris.sdk.IrisPath;
55

66
import javax.xml.bind.annotation.*;
7+
8+
import java.io.File;
79
import java.util.List;
810
import java.util.Map;
911

@@ -67,6 +69,38 @@ public static OrderHistoryWrapper GetHistory( IrisClient client, String orderId
6769
return client.get( client.buildAccountModelUri( new String[] {IrisPath.IMPORT_TN_ORDERS, orderId, "history" } ), OrderHistoryWrapper.class);
6870
}
6971

72+
public static FileListResponse GetLoas( IrisClient client, String orderId ) throws Exception {
73+
return client.get( client.buildAccountModelUri( new String[] {IrisPath.IMPORT_TN_ORDERS, orderId, IrisPath.LOAS } ), FileListResponse.class);
74+
}
75+
76+
public static void UploadLoasFile(IrisClient client, String orderId, File file, String contentType ) throws Exception {
77+
client.postFile( client.buildAccountModelUri( new String[] {IrisPath.IMPORT_TN_ORDERS, orderId, IrisPath.LOAS } ), file, contentType);
78+
}
79+
80+
public static byte[] GetLoasFile(IrisClient client, String orderId, String loasId ) throws Exception {
81+
return client.getFile( client.buildAccountModelUri( new String[] {IrisPath.IMPORT_TN_ORDERS, orderId, IrisPath.LOAS, loasId } ) );
82+
}
83+
84+
public static void ReplaceLoasFile(IrisClient client, String orderId, String fileid, File file, String contentType ) throws Exception {
85+
client.putFile( client.buildAccountModelUri( new String[] {IrisPath.IMPORT_TN_ORDERS, orderId, IrisPath.LOAS, fileid } ), file, contentType);
86+
}
87+
88+
public static void DeleteLoasFile( IrisClient client, String orderId, String fileid ) throws Exception {
89+
client.delete( client.buildAccountModelUri( new String[] {IrisPath.IMPORT_TN_ORDERS, orderId, IrisPath.LOAS, fileid } ));
90+
}
91+
92+
public static FileMetaData GetLoasFileMetadata( IrisClient client, String orderId, String fileid) throws Exception {
93+
return client.get( client.buildAccountModelUri( new String[] {IrisPath.IMPORT_TN_ORDERS, orderId, IrisPath.LOAS, fileid, "metadata" } ), FileMetaData.class);
94+
}
95+
96+
public static void CreateLoasFileMetadata( IrisClient client, String orderId, String fileId, FileMetaData metadata) throws Exception {
97+
client.put( client.buildAccountModelUri( new String[] {IrisPath.IMPORT_TN_ORDERS, orderId, IrisPath.LOAS, fileId, "metadata" } ), metadata );
98+
}
99+
100+
public static void DeleteLoasFileMetadata( IrisClient client, String orderId, String fileId) throws Exception {
101+
client.delete( client.buildAccountModelUri( new String[] {IrisPath.IMPORT_TN_ORDERS, orderId, IrisPath.LOAS, fileId, "metadata" } ));
102+
}
103+
70104
public String getCustomerOrderId() {
71105
return customerOrderId;
72106
}

src/test/java/com/bandwidth/iris/sdk/ImportTnOrderTests.java

Lines changed: 140 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import com.bandwidth.iris.sdk.model.*;
44
import org.junit.Test;
55

6-
import java.util.HashMap;
6+
import java.io.File;
77
import java.util.List;
8-
import java.util.Map;
98

109
import static com.github.tomakehurst.wiremock.client.WireMock.*;
1110
import static org.junit.Assert.assertEquals;
@@ -119,4 +118,143 @@ public void TestGetHistory() throws Exception {
119118
assertEquals("received", first.getStatus());
120119

121120
}
121+
122+
@Test
123+
public void TestGetLoas() throws Exception {
124+
String orderId = "orderId";
125+
126+
String url = "/v1.0/accounts/accountId/importTnOrders/" + orderId + "/loas";
127+
stubFor(get(urlMatching(url))
128+
.willReturn(aResponse()
129+
.withStatus(200).withBody(IrisClientTestUtils.fileListLoas)));
130+
131+
FileListResponse response = ImportTnOrder.GetLoas(getDefaultClient(), orderId );
132+
133+
assertEquals(2, response.getFileCount());
134+
assertEquals("LOA file list successfully returned", response.getResultMessage());
135+
assertEquals(0, response.getResultCode());
136+
assertEquals(2, response.getFileNames().length);
137+
138+
assertEquals("803f3cc5-beae-469e-bd65-e9891ccdffb9-1092874634747.pdf", response.getFileNames()[0]);
139+
assertEquals("803f3cc5-beae-469e-bd65-e9891ccdffb9-1430814967669.pdf", response.getFileNames()[1]);
140+
141+
}
142+
143+
@Test
144+
public void TestPostLoas() throws Exception {
145+
String orderId = "orderId";
146+
147+
String url = "/v1.0/accounts/accountId/importTnOrders/" + orderId + "/loas";
148+
stubFor(post(urlMatching(url))
149+
.willReturn(aResponse()
150+
.withStatus(200).withBody(IrisClientTestUtils.fileListLoas)));
151+
152+
ImportTnOrder.UploadLoasFile(getDefaultClient(), orderId , new File("pom.xml"), "application/xml");
153+
154+
}
155+
156+
@Test
157+
public void TestGetLoasFile() throws Exception {
158+
String orderId = "orderId";
159+
String fileId = "id";
160+
161+
byte[] data = new byte[100];
162+
data[1] = 1;
163+
164+
String url = "/v1.0/accounts/accountId/importTnOrders/" + orderId + "/loas/" + fileId;
165+
stubFor(get(urlMatching(url))
166+
.willReturn(aResponse()
167+
.withStatus(200).withBody(data)));
168+
169+
byte[] fileData = ImportTnOrder.GetLoasFile(getDefaultClient(), orderId , fileId);
170+
171+
assertEquals(fileData.length, data.length);
172+
assertEquals(fileData[1], data[1]);
173+
174+
}
175+
176+
@Test
177+
public void TestPutLoasFile() throws Exception {
178+
String orderId = "orderId";
179+
String fileId = "id";
180+
181+
byte[] data = new byte[100];
182+
data[1] = 1;
183+
184+
String url = "/v1.0/accounts/accountId/importTnOrders/" + orderId + "/loas/" + fileId;
185+
stubFor(put(urlMatching(url))
186+
.willReturn(aResponse()
187+
.withStatus(200)));
188+
189+
ImportTnOrder.ReplaceLoasFile(getDefaultClient(), orderId , fileId, new File("pom.xml"), "application/xml");
190+
191+
192+
}
193+
194+
@Test
195+
public void TestDeleteLoasFile() throws Exception {
196+
String orderId = "orderId";
197+
String fileId = "id";
198+
199+
byte[] data = new byte[100];
200+
data[1] = 1;
201+
202+
String url = "/v1.0/accounts/accountId/importTnOrders/" + orderId + "/loas/" + fileId;
203+
stubFor(delete(urlMatching(url))
204+
.willReturn(aResponse()
205+
.withStatus(200)));
206+
207+
ImportTnOrder.DeleteLoasFile(getDefaultClient(), orderId , fileId);
208+
209+
210+
}
211+
212+
@Test
213+
public void TestDeleteLoasFileMetadata() throws Exception {
214+
String orderId = "orderId";
215+
String fileId = "id";
216+
217+
byte[] data = new byte[100];
218+
data[1] = 1;
219+
220+
String url = "/v1.0/accounts/accountId/importTnOrders/" + orderId + "/loas/" + fileId + "/metadata";
221+
stubFor(delete(urlMatching(url))
222+
.willReturn(aResponse()
223+
.withStatus(200)));
224+
225+
ImportTnOrder.DeleteLoasFileMetadata(getDefaultClient(), orderId , fileId);
226+
227+
228+
}
229+
230+
@Test
231+
public void TestGetLoasFileMetadata() throws Exception {
232+
String orderId = "orderId";
233+
String fileId = "id";
234+
235+
String url = "/v1.0/accounts/accountId/importTnOrders/" + orderId + "/loas/" + fileId + "/metadata";
236+
stubFor(get(urlMatching(url))
237+
.willReturn(aResponse()
238+
.withStatus(200).withBody(IrisClientTestUtils.validFileMetaDataResponseXml)));
239+
240+
FileMetaData fileMetaData = ImportTnOrder.GetLoasFileMetadata(getDefaultClient(), orderId , fileId);
241+
242+
assertNotNull(fileMetaData);
243+
assertEquals("file.pdf", fileMetaData.getDocumentName());
244+
}
245+
246+
@Test
247+
public void TestPutLoasFileMetadata() throws Exception {
248+
String orderId = "orderId";
249+
String fileId = "id";
250+
251+
String url = "/v1.0/accounts/accountId/importTnOrders/" + orderId + "/loas/" + fileId + "/metadata";
252+
stubFor(put(urlMatching(url))
253+
.willReturn(aResponse()
254+
.withStatus(200)));
255+
256+
ImportTnOrder.CreateLoasFileMetadata(getDefaultClient(), orderId , fileId, new FileMetaData());
257+
258+
}
259+
122260
}

src/test/java/com/bandwidth/iris/sdk/IrisClientTestUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
public class IrisClientTestUtils {
44

5+
public static final String fileListLoas = "<fileListResponse>\n" +
6+
" <fileCount>2</fileCount>\n" +
7+
" <fileNames>803f3cc5-beae-469e-bd65-e9891ccdffb9-1092874634747.pdf</fileNames>\n" +
8+
" <fileNames>803f3cc5-beae-469e-bd65-e9891ccdffb9-1430814967669.pdf</fileNames>\n" +
9+
" <resultCode>0</resultCode>\n" +
10+
" <resultMessage>LOA file list successfully returned</resultMessage>\n" +
11+
"</fileListResponse>";
512

613
public static final String callbackSubscription = "<SubscriptionsResponse><Subscriptions><Subscription>\n" +
714
" <EventType>MESSAGING_LOST</EventType>\n" +

0 commit comments

Comments
 (0)