Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@

/**
* Thread safe client to the Scanii content processing service.
* Please note that this client does not throw checked exceptions, all exceptions are wrapped around a ScaniiException that extends RuntimeException
* Please note that this client does not throw checked exceptions; all exceptions are wrapped around a ScaniiException that extends RuntimeException
*
* @see <a href="http://docs.scanii.com/v2.1/resources.html">http://docs.scanii.com/v2.1/resources.html</a>
* @see <a href="https://uvasoftware.github.io/openapi/v22/">spec</a>
*/
public class DefaultScaniiClient implements ScaniiClient {
private static final Logger LOG = Loggers.build();
Expand Down Expand Up @@ -85,7 +85,7 @@ public ScaniiProcessingResult process(Path content, String callback, Map<String,
throw new IllegalArgumentException("content path does not exist");
}

HttpPost req = new HttpPost(target.resolve("/v2.1/files"));
HttpPost req = new HttpPost(target.resolve("/v2.2/files"));
buildMultiPart(content, callback, metadata, req);

return processResponse(req);
Expand All @@ -97,7 +97,7 @@ public ScaniiProcessingResult process(InputStream content, String callback, Map<
Objects.requireNonNull(content, "content stream cannot be null");
Objects.requireNonNull(metadata, "metadata cannot be null");

HttpPost req = new HttpPost(target.resolve("/v2.1/files"));
HttpPost req = new HttpPost(target.resolve("/v2.2/files"));
buildMultiPart(content, callback, metadata, req);

return processResponse(req);
Expand Down Expand Up @@ -133,7 +133,7 @@ public ScaniiPendingResult processAsync(Path content, String callback, Map<Strin
throw new IllegalArgumentException("content path does not exist");
}

HttpPost req = new HttpPost(target.resolve("/v2.1/files/async"));
HttpPost req = new HttpPost(target.resolve("/v2.2/files/async"));
buildMultiPart(content, callback, metadata, req);

return processAsyncResponse(req);
Expand Down Expand Up @@ -166,7 +166,7 @@ public ScaniiPendingResult processAsync(InputStream content, String callback, Ma
Objects.requireNonNull(content, "content stream cannot be null");
Objects.requireNonNull(metadata, "metadata cannot be null");

HttpPost req = new HttpPost(target.resolve("/v2.1/files/async"));
HttpPost req = new HttpPost(target.resolve("/v2.2/files/async"));
buildMultiPart(content, callback, metadata, req);

return processAsyncResponse(req);
Expand All @@ -187,7 +187,7 @@ public ScaniiPendingResult processAsync(InputStream content) {
public Optional<ScaniiProcessingResult> retrieve(String id) {
Objects.requireNonNull(id, "resource id cannot be null");

HttpGet req = new HttpGet(target.resolve("/v2.1/files/" + id));
HttpGet req = new HttpGet(target.resolve("/v2.2/files/" + id));
addHeaders(req);

try {
Expand Down Expand Up @@ -227,7 +227,7 @@ public ScaniiPendingResult fetch(String location, String callback, Map<String, S
Objects.requireNonNull(location, "content location cannot be null");
Objects.requireNonNull(metadata, "metadata cannot be null");

HttpPost req = new HttpPost(target.resolve("/v2.1/files/fetch"));
HttpPost req = new HttpPost(target.resolve("/v2.2/files/fetch"));
addHeaders(req);

List<NameValuePair> fields = new ArrayList<>();
Expand Down Expand Up @@ -269,7 +269,7 @@ public ScaniiPendingResult fetch(String location, String callback, Map<String, S

@Override
public boolean ping() {
HttpGet req = new HttpGet(target.resolve("/v2.1/ping"));
HttpGet req = new HttpGet(target.resolve("/v2.2/ping"));
addHeaders(req);

try {
Expand All @@ -286,7 +286,7 @@ public ScaniiAuthToken createAuthToken(int timeout, TimeUnit timeoutUnit) {
throw new IllegalArgumentException("timeout must be a positive number");
}

HttpPost req = new HttpPost(target.resolve("/v2.1/auth/tokens"));
HttpPost req = new HttpPost(target.resolve("/v2.2/auth/tokens"));
addHeaders(req);

List<NameValuePair> fields = new ArrayList<>();
Expand Down Expand Up @@ -322,7 +322,7 @@ public ScaniiAuthToken createAuthToken(int timeout, TimeUnit timeoutUnit) {
public boolean deleteAuthToken(String id) {
Objects.requireNonNull(id, "id cannot be null");

HttpDelete req = new HttpDelete(target.resolve("/v2.1/auth/tokens/" + id));
HttpDelete req = new HttpDelete(target.resolve("/v2.2/auth/tokens/" + id));
addHeaders(req);

try {
Expand All @@ -343,7 +343,7 @@ public boolean deleteAuthToken(String id) {
public ScaniiAuthToken retrieveAuthToken(String id) {
Objects.requireNonNull(id, "id cannot be null");

HttpGet req = new HttpGet(target.resolve("/v2.1/auth/tokens/" + id));
HttpGet req = new HttpGet(target.resolve("/v2.2/auth/tokens/" + id));
addHeaders(req);

try {
Expand All @@ -369,7 +369,7 @@ public ScaniiAuthToken retrieveAuthToken(String id) {

@Override
public ScaniiAccountInfo retrieveAccountInfo() {
HttpGet req = new HttpGet(target.resolve("/v2.1/account.json"));
HttpGet req = new HttpGet(target.resolve("/v2.2/account.json"));
addHeaders(req);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Map;
import java.util.Set;

@SuppressWarnings("unused")
public class ScaniiAccountInfo extends ScaniiResult {
@JsonProperty("name")
private String name;
Expand Down Expand Up @@ -113,7 +114,7 @@ public String toString() {
'}';
}

private static class User {
public static class User {
@JsonProperty("creation_date")
private Instant creationDate;
@JsonProperty("last_login_date")
Expand All @@ -136,7 +137,7 @@ public void setLastLoginDate(Instant lastLoginDate) {
}
}

private static class ApiKey {
public static class ApiKey {
@JsonProperty("active")
private boolean active;
@JsonProperty("creation_date")
Expand Down
30 changes: 19 additions & 11 deletions src/test/java/com/uvasoftware/scanii/ScaniiClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void testProcessWithMetadata() throws Exception {
ScaniiProcessingResult result;

// simple processing clean
result = client.process(Systems.randomFile(1024), new HashMap<String, String>() {{
result = client.process(Systems.randomFile(1024), new HashMap<>() {{
put("foo", "bar");
}});
Assertions.assertNotNull(result.getResourceId());
Expand All @@ -96,7 +96,7 @@ void testProcessInputStreamWithMetadata() throws Exception {
FileInputStream is = new FileInputStream(Systems.randomFile(1024).toFile());

// simple processing clean
result = client.process(is, new HashMap<String, String>() {{
result = client.process(is, new HashMap<>() {{
put("foo", "bar");
}});
Assertions.assertNotNull(result.getResourceId());
Expand All @@ -109,7 +109,7 @@ void testProcessWithMetadataAndCallback() throws Exception {
ScaniiProcessingResult result;

// simple processing clean
result = client.process(Systems.randomFile(1024), "https://httpbin.org/post", new HashMap<String, String>() {{
result = client.process(Systems.randomFile(1024), "https://httpbin.org/post", new HashMap<>() {{
put("foo", "bar");
}});
Assertions.assertNotNull(result.getResourceId());
Expand All @@ -125,7 +125,7 @@ void testProcessInputStreamWithMetadataAndCallback() throws Exception {
FileInputStream is = new FileInputStream(Systems.randomFile(1024).toFile());

// simple processing clean
result = client.process(is, "https://httpbin.org/post", new HashMap<String, String>() {{
result = client.process(is, "https://httpbin.org/post", new HashMap<>() {{
put("foo", "bar");
}});
Assertions.assertNotNull(result.getResourceId());
Expand Down Expand Up @@ -181,7 +181,7 @@ void testProcessAsync() throws Exception {

@Test
void testProcessAsyncWithMetadata() throws Exception {
ScaniiPendingResult result = client.processAsync(Systems.randomFile(1024), new HashMap<String, String>() {{
ScaniiPendingResult result = client.processAsync(Systems.randomFile(1024), new HashMap<>() {{
put("foo", "bar");
}});

Expand All @@ -199,7 +199,7 @@ void testProcessAsyncInputStreamWithMetadata() throws Exception {

FileInputStream is = new FileInputStream(Systems.randomFile(1024).toFile());

ScaniiPendingResult result = client.processAsync(is, new HashMap<String, String>() {{
ScaniiPendingResult result = client.processAsync(is, new HashMap<>() {{
put("foo", "bar");
}});

Expand All @@ -211,7 +211,7 @@ void testProcessAsyncInputStreamWithMetadata() throws Exception {

@Test
void testProcessAsyncWithMetadataAndCallback() throws Exception {
ScaniiPendingResult result = client.processAsync(Systems.randomFile(1024), "https://httpbin.org/post", new HashMap<String, String>() {{
ScaniiPendingResult result = client.processAsync(Systems.randomFile(1024), "https://httpbin.org/post", new HashMap<>() {{
put("foo", "bar");
}});

Expand All @@ -227,7 +227,7 @@ void testProcessAsyncInputStreamWithMetadataAndCallback() throws Exception {

FileInputStream is = new FileInputStream(Systems.randomFile(1024).toFile());

ScaniiPendingResult result = client.processAsync(is, "https://httpbin.org/post", new HashMap<String, String>() {{
ScaniiPendingResult result = client.processAsync(is, "https://httpbin.org/post", new HashMap<>() {{
put("foo", "bar");
}});

Expand Down Expand Up @@ -293,7 +293,7 @@ void testFetchWithCallback() throws InterruptedException {
@Test
void testFetchWithMetadata() throws Exception {

ScaniiPendingResult result = client.fetch("https://scanii.s3.amazonaws.com/eicarcom2.zip", "http://google.com", new HashMap<String, String>() {{
ScaniiPendingResult result = client.fetch("https://scanii.s3.amazonaws.com/eicarcom2.zip", "http://google.com", new HashMap<>() {{
put("foo", "bar");
}});
Assertions.assertNotNull(result.getResourceId());
Expand Down Expand Up @@ -372,8 +372,16 @@ void shouldRetrieveAccountInfo() {
Assertions.assertTrue(account.getStartingBalance() > 0);
Assertions.assertNotNull(account.getCreationDate());
Assertions.assertNotNull(account.getModificationDate());
Assertions.assertTrue(account.getUsers().size() > 0);
Assertions.assertTrue(account.getKeys().size() > 0);
Assertions.assertFalse(account.getUsers().isEmpty());
Assertions.assertFalse(account.getKeys().isEmpty());
Assertions.assertFalse(account.getKeys().isEmpty());

var firstKey = account.getKeys().values().stream().findFirst().orElseThrow();
Assertions.assertNotNull(firstKey.getCreationDate());
Assertions.assertNotNull(firstKey.getLastSeenDate());
Assertions.assertNotNull(firstKey.getDetectionCategoriesEnabled());


}

@Test
Expand Down