Skip to content

Commit

Permalink
getting ready for production
Browse files Browse the repository at this point in the history
  • Loading branch information
TomBrennan91 committed Feb 1, 2019
1 parent 5cc4272 commit 3f53c26
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 23 deletions.
7 changes: 7 additions & 0 deletions .idea/dictionaries/Tom_Brennan.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions restAccesor.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<center>
<head>
<title>Review Aggregator Aggregator</title>
<title>Review Aggregator Aggregator (V1.0)</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
</head>
Expand Down Expand Up @@ -32,7 +32,7 @@
<div class="input-group mb-3">
<div class="btn-group btn-group-toggle" data-toggle="buttons" id="inputAdditional">
<div class="input-group-prepend">
<label class="input-group-text" for="inputAdditional">Additional Information</label>
<label class="input-group-text" for="inputAdditional">Additional Info</label>
</div>
<label class="btn btn-outline-primary active">
<input class="info" type="checkbox" id="yearBox" checked autocomplete="off">
Expand Down Expand Up @@ -80,7 +80,7 @@
<option value="type">Type</option>
</select>
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-outline-primary active" >
<label class="btn btn-outline-primary active">
<input type="radio" name="options" id="desc" autocomplete="off" checked>
<i class="fas fa-sort-amount-down"></i> Descending
</label>
Expand All @@ -103,16 +103,16 @@
<option value="votes">IMDB Votes</option>
</select>
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-outline-primary active" >
<input type="radio" name="options" id="greaterThan" autocomplete="off" checked>
<label class="btn btn-outline-primary active">
<input type="radio" name="filterOptions" id="greaterThan" autocomplete="off" checked>
<i class="fas fa-greater-than"></i> Greater Than
</label>
<label class="btn btn-outline-primary">
<input type="radio" name="options" id="lessThan" autocomplete="off">
<input type="radio" name="filterOptions" id="lessThan" autocomplete="off">
<i class="fas fa-less-than"></i> Less Than
</label>
</div>
<input type="text" class="form-control" id="filterValue">
<input type="number" class="form-control" id="filterValue">
</div>

<button type="button" class="btn btn-primary btn-lg" onclick="postAndUpdate()">
Expand Down
6 changes: 2 additions & 4 deletions restAccessor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function postAndUpdate(){
var titles = document.forms["form"].elements[0].value;
titles = titles.replace(/\n/g,"~");
postAjax('http://localhost:8080/review?sort=' + getSortingParameter() + getFilterParameter(), titles , function (data){updateOutput(data);});
postAjax('http://localhost:8080/review?sort=' + getSortingParameter() + "&filter=" + getFilterParameter(), titles , function (data){updateOutput(data);});
}

function postAjax(url, data, success) {
Expand Down Expand Up @@ -124,6 +124,4 @@ function empty(data){
}

var spinner = document.getElementById("spinner");
spinner.style.display = "none";

document.getElementById("desc").checked = true;
spinner.style.display = "none";
21 changes: 21 additions & 0 deletions src/main/java/review/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

@SpringBootApplication
public class Application {
public static void main(String[] args) {
setAPIKey();
SpringApplication.run(Application.class, args);
}

public static String getAPIKey() {
return APIKey;
}

private static String APIKey;

private static void setAPIKey(){
try {
BufferedReader in = new BufferedReader(new FileReader("apiKey.env"));
APIKey = in.readLine();
System.out.println("API Key = " + APIKey);
} catch (IOException e){
e.printStackTrace();
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/review/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

@JsonIgnoreProperties(ignoreUnknown = true)
public class Review {

private String title;
private String year;
private String runtime;
Expand Down Expand Up @@ -52,12 +51,13 @@ private static String getHTML(String urlToRead) throws Exception {
}

public static Review getReviewFromTitle(String title) throws Exception{
String jsonReview = getHTML("http://www.omdbapi.com/?apikey=714ddca5&t=" + URLEncoder.encode(title, "UTF-8"));
String jsonReview = getHTML("http://www.omdbapi.com/?apikey=" + Application.getAPIKey() + "&t=" + URLEncoder.encode(title, "UTF-8"));
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
return objectMapper.readValue(jsonReview, Review.class);
}


public String getGenre() {
return genre;
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/review/ReviewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ public ArrayList<Review> reviews(@RequestBody String input,
}
}

filterReviews(reviews, filter);

sortReviews(reviews, sorting);

try {
filterReviews(reviews, filter);
sortReviews(reviews, sorting);
} catch (NumberFormatException e){
System.err.println(e.getMessage());
}

System.out.println(titles.length + " -> " + reviews.size());
return reviews;
}

private void sortReviews( ArrayList<Review> reviews, String sorting){
private void sortReviews( ArrayList<Review> reviews, String sorting) throws NumberFormatException{
String[] splitSorting = sorting.split(":");

switch (splitSorting[0]){
Expand Down Expand Up @@ -77,7 +79,7 @@ private void sortReviews( ArrayList<Review> reviews, String sorting){
}


private void filterReviews(ArrayList<Review> reviews, String filter){
private void filterReviews(ArrayList<Review> reviews, String filter) throws NumberFormatException {
if (filter.equalsIgnoreCase("")) return;
String[] splitFilter = filter.split(":");
if (splitFilter.length < 3) return;
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/review/ReviewRepository.java

This file was deleted.

0 comments on commit 3f53c26

Please sign in to comment.