Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mzanella committed May 5, 2017
2 parents 8efe900 + b668890 commit 18cc489
Show file tree
Hide file tree
Showing 17 changed files with 470 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
target/
libris.iml
*.iml
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This project uses _Maven_ to build the project. In the project root in order to
```
mvn compile
```
N.B.: `libris` needs at least Java v7 in order to compile! Previous versions won't work.

## Testing
To run the unit tests:
Expand Down
60 changes: 54 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,36 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<repository>
<id>clojars.org</id>
<url>http://clojars.org/repo</url>
</repository>
</repositories>

<build>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
Expand All @@ -36,16 +66,34 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>

<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.2</version>
</dependency>

<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>java-websocket</artifactId>
<version>1.3.3</version>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.56</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
</dependencies>
</project>
5 changes: 3 additions & 2 deletions src/main/java/it/polpetta/libris/IQuery.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package it.polpetta.libris;

import org.json.JSONObject;

import it.polpetta.libris.google.imageSearch.SearchResult;

/**
* Created by davide on 28/04/17.
*/
public interface IQuery {

public JSONObject getContest();
SearchResult getContest();
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package it.polpetta.libris.google.imageSearch;

import it.polpetta.libris.IQuery;
import org.json.JSONObject;

/**
* Created by davide on 28/04/17.
*/
public class GoogleImageSearchQuery implements IQuery {

private JSONObject res;
private SearchResult res;

public GoogleImageSearchQuery(JSONObject res){
public GoogleImageSearchQuery(SearchResult res){

this.res = res;
}

public JSONObject getContest() {
public SearchResult getContest() {
return res;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import java.io.IOException;
import java.net.URL;

import org.json.*;


/**
* Created by davide on 28/04/17.
Expand Down Expand Up @@ -49,7 +47,7 @@ public IQuery runQuery() {

ISearcher searcher = null;
AbstractFactoryMethodSearcher factory;
JSONObject res = null;
SearchResult res = null;

// FIXME
if (link != null) {
Expand Down
101 changes: 101 additions & 0 deletions src/main/java/it/polpetta/libris/google/imageSearch/SearchResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package it.polpetta.libris.google.imageSearch;

import java.util.ArrayList;

/**
* Created by zanna on 04/05/17.
*/
public class SearchResult {
private String bestGuess;
private ArrayList<String> links;
private ArrayList<String> descriptions;
private ArrayList<String> titles;
private ArrayList<String> similarImages;

private SearchResult(){}

public String toJSONString() {
StringBuilder builder = new StringBuilder();
builder.append("{")
.append("\"best_guess\":\"")
.append(bestGuess)
.append("\"")
.append(",")
.append("\"links\":[")
.append(arrayListToString(links))
.append("],")
.append("\"descriptions\":[")
.append(arrayListToString(descriptions))
.append("],")
.append("\"titles\":[")
.append(arrayListToString(titles))
.append("],")
.append("\"similar_images\":[")
.append(arrayListToString(similarImages))
.append("]}");
return builder.toString();
}

private String arrayListToString(ArrayList<String> arrayList) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < arrayList.size(); i++) {
sb.append("\"");
sb.append(arrayList.get(i));
sb.append("\"");
if (i != arrayList.size() - 1)
sb.append(",");
}
return sb.toString();
}

public static class Builder {
private String bestGuess;
private ArrayList<String> links;
private ArrayList<String> descriptions;
private ArrayList<String> titles;
private ArrayList<String> similarImages;

public Builder() {
bestGuess = "";
links = new ArrayList<>();
descriptions = new ArrayList<>();
titles = new ArrayList<>();
similarImages = new ArrayList<>();
}

public Builder withBestGuess(String bestGuess) {
this.bestGuess = bestGuess;
return this;
}

public Builder withLinks(ArrayList<String> links) {
this.links = links;
return this;
}

public Builder withDescriptions(ArrayList<String> descriptions) {
this.descriptions = descriptions;
return this;
}

public Builder withTitles(ArrayList<String> titles) {
this.titles = titles;
return this;
}

public Builder withSimilarImages(ArrayList<String> similarImages) {
this.similarImages = similarImages;
return this;
}

public SearchResult build() {
SearchResult result = new SearchResult();
result.bestGuess = bestGuess;
result.links = links;
result.descriptions = descriptions;
result.titles = titles;
result.similarImages = similarImages;
return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.polpetta.libris.google.imageSearch.searchers;

import org.json.*;
import it.polpetta.libris.google.imageSearch.SearchResult;

import java.io.IOException;

Expand All @@ -9,5 +9,5 @@
*/
public interface ISearcher {

JSONObject search() throws IOException;
SearchResult search() throws IOException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package it.polpetta.libris.google.imageSearch.searchers;

import it.polpetta.libris.google.imageSearch.Coordinates;

import java.net.URI;

/**
* Created by dpolonio on 03/05/17.
*/
public class LocalPhotoFactoryMethodSearcher extends AbstractFactoryMethodSearcher {

private URI path = null;

public LocalPhotoFactoryMethodSearcher(Coordinates location, URI path) {
super(location);

this.path = path;
}

@Override
public ISearcher makeSearcher() {
return new LocalPhotoSearcher(path, location);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package it.polpetta.libris.google.imageSearch.searchers;

import it.polpetta.libris.google.imageSearch.Coordinates;
import it.polpetta.libris.google.imageSearch.SearchResult;

import java.io.IOException;
import java.net.URI;

/**
* Created by dpolonio on 03/05/17.
*/
class LocalPhotoSearcher implements ISearcher {

private URI path = null;

LocalPhotoSearcher (URI pathToImage, Coordinates location) {
this.path = pathToImage;
}

public SearchResult search() throws IOException {

// TODO

return null;
}
}
Loading

0 comments on commit 18cc489

Please sign in to comment.