Skip to content

Commit

Permalink
Merge branch 'lombok'
Browse files Browse the repository at this point in the history
  • Loading branch information
REDNBLACK committed May 4, 2016
2 parents 34da6ca + 243762b commit a4d825b
Show file tree
Hide file tree
Showing 40 changed files with 252 additions and 451 deletions.
9 changes: 9 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
plugins {
id 'io.franzbecker.gradle-lombok' version '1.6'
}

version = "0.7.7"

lombok {
version = "1.16.8"
sha256 = "fe32b29b7b33eb2b19866cbc5345c59c9984a6036cc396856a04c0d09f99ea68"
}

ext {
guiceVersion = "4.0"
hibernateVersion = "5.1.0.Final"
Expand Down
13 changes: 7 additions & 6 deletions core/src/main/java/org/f0w/k2i/core/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.google.inject.Stage;
import com.google.inject.persist.PersistService;
import com.typesafe.config.Config;
import lombok.NonNull;
import org.f0w.k2i.core.event.ImportFinishedEvent;
import org.f0w.k2i.core.event.ImportProgressAdvancedEvent;
import org.f0w.k2i.core.event.ImportStartedEvent;
Expand All @@ -21,7 +22,7 @@
import java.util.Collections;
import java.util.List;

import static java.util.Objects.requireNonNull;
import static org.f0w.k2i.core.util.IOUtils.checkFile;

/**
* Main facade implemented as {@link Runnable} for working with core module.
Expand All @@ -33,15 +34,15 @@ public final class Client implements Runnable {
private final ImportProgressService importProgressService;
private final PersistService persistService;

public Client(Path filePath, Config config) {
public Client(@NonNull Path filePath, @NonNull Config config) {
this(filePath, config, false);
}

public Client(Path filePath, Config config, boolean cleanRun) {
public Client(@NonNull Path filePath, @NonNull Config config, boolean cleanRun) {
this(filePath, config, cleanRun, Collections.emptyList());
}

public Client(Path filePath, Config config, boolean cleanRun, List<?> listeners) {
public Client(@NonNull Path filePath, @NonNull Config config, boolean cleanRun, @NonNull List<?> listeners) {
Injector injector = Guice.createInjector(
Stage.PRODUCTION,
new ConfigurationProvider(config),
Expand All @@ -55,10 +56,10 @@ public Client(Path filePath, Config config, boolean cleanRun, List<?> listeners)
handlerType = injector.getInstance(MovieHandler.Type.class);
handlerChain = injector.getInstance(MovieHandler.class);
importProgressService = injector.getInstance(ImportProgressService.class)
.initialize(filePath, cleanRun);
.initialize(checkFile(filePath), cleanRun);

eventBus = new EventBus();
requireNonNull(listeners).forEach(eventBus::register);
listeners.forEach(eventBus::register);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.f0w.k2i.core.comparator;

import lombok.NonNull;
import org.f0w.k2i.core.model.entity.Movie;

/**
Expand All @@ -14,7 +15,7 @@ public interface MovieComparator {
* @param movie2 Second movie
* @return Are two movie objects equals to each other
*/
boolean areEqual(Movie movie1, Movie movie2);
boolean areEqual(@NonNull Movie movie1, @NonNull Movie movie2);

/**
* Available MovieComparator types
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.f0w.k2i.core.comparator.title;

import lombok.NonNull;
import org.f0w.k2i.core.comparator.AbstractMovieComparator;
import org.f0w.k2i.core.model.entity.Movie;

Expand All @@ -13,7 +14,7 @@ public final class ContainsTitleComparator extends AbstractMovieComparator {
* {@inheritDoc}
*/
@Override
public boolean areEqual(Movie movie1, Movie movie2) {
public boolean areEqual(@NonNull Movie movie1, @NonNull Movie movie2) {
String title1 = movie1.getTitle();
String title2 = movie2.getTitle();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.f0w.k2i.core.comparator.title;

import lombok.NonNull;
import org.f0w.k2i.core.comparator.AbstractMovieComparator;
import org.f0w.k2i.core.model.entity.Movie;

Expand All @@ -11,7 +12,7 @@ public final class EndsWithTitleComparator extends AbstractMovieComparator {
* {@inheritDoc}
*/
@Override
public boolean areEqual(Movie movie1, Movie movie2) {
public boolean areEqual(@NonNull Movie movie1, @NonNull Movie movie2) {
String title1 = movie1.getTitle().toLowerCase();
String title2 = movie2.getTitle().toLowerCase();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.f0w.k2i.core.comparator.title;

import lombok.NonNull;
import org.f0w.k2i.core.comparator.AbstractMovieComparator;
import org.f0w.k2i.core.model.entity.Movie;

Expand All @@ -11,7 +12,7 @@ public final class EqualsTitleComparator extends AbstractMovieComparator {
* {@inheritDoc}
*/
@Override
public boolean areEqual(Movie movie1, Movie movie2) {
public boolean areEqual(@NonNull Movie movie1, @NonNull Movie movie2) {
String title1 = movie1.getTitle();
String title2 = movie2.getTitle();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.f0w.k2i.core.comparator.title;

import com.google.common.collect.ImmutableList;
import lombok.NonNull;
import org.f0w.k2i.core.comparator.AbstractMovieComparator;
import org.f0w.k2i.core.model.entity.Movie;
import org.f0w.k2i.core.util.string.NumericToWord;
Expand Down Expand Up @@ -113,7 +114,7 @@ public final class SmartTitleComparator extends AbstractMovieComparator {
* {@inheritDoc}
*/
@Override
public boolean areEqual(Movie movie1, Movie movie2) {
public boolean areEqual(@NonNull Movie movie1, @NonNull Movie movie2) {
for (StringModifier m1 : modifiers) {
for (StringModifier m2 : modifiers) {
String m1Title = m1.modify(movie1.getTitle());
Expand All @@ -139,6 +140,6 @@ public boolean areEqual(Movie movie1, Movie movie2) {

@FunctionalInterface
private interface StringModifier {
String modify(String string);
String modify(@NonNull String string);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.f0w.k2i.core.comparator.title;

import lombok.NonNull;
import org.f0w.k2i.core.comparator.AbstractMovieComparator;
import org.f0w.k2i.core.model.entity.Movie;

Expand All @@ -11,7 +12,7 @@ public final class StartsWithTitleComparator extends AbstractMovieComparator {
* {@inheritDoc}
*/
@Override
public boolean areEqual(Movie movie1, Movie movie2) {
public boolean areEqual(@NonNull Movie movie1, @NonNull Movie movie2) {
String title1 = movie1.getTitle().toLowerCase();
String title2 = movie2.getTitle().toLowerCase();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.f0w.k2i.core.comparator.year;

import com.google.common.collect.Range;
import com.google.inject.Inject;
import com.typesafe.config.Config;
import lombok.NonNull;
import org.f0w.k2i.core.comparator.AbstractMovieComparator;
import org.f0w.k2i.core.model.entity.Movie;

Expand All @@ -12,16 +12,15 @@
public final class DeviationYearComparator extends AbstractMovieComparator {
private final Config config;

@Inject
public DeviationYearComparator(Config config) {
public DeviationYearComparator(@NonNull Config config) {
this.config = config;
}

/**
* {@inheritDoc}
*/
@Override
public boolean areEqual(Movie movie1, Movie movie2) {
public boolean areEqual(@NonNull Movie movie1, @NonNull Movie movie2) {
int yearDeviation = config.getInt("year_deviation");
int movie2Year = movie2.getYear();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.f0w.k2i.core.comparator.year;

import lombok.NonNull;
import org.f0w.k2i.core.comparator.AbstractMovieComparator;
import org.f0w.k2i.core.model.entity.Movie;

Expand All @@ -11,7 +12,7 @@ public final class EqualsYearComparator extends AbstractMovieComparator {
* {@inheritDoc}
*/
@Override
public boolean areEqual(Movie movie1, Movie movie2) {
public boolean areEqual(@NonNull Movie movie1, @NonNull Movie movie2) {
boolean result = movie1.getYear() == movie2.getYear();

LOG.debug(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package org.f0w.k2i.core.exchange;

import lombok.NonNull;
import lombok.Setter;
import org.jsoup.Connection;

import java.util.Optional;


public abstract class AbstractExchangeable<IN, OUT> implements Exchangeable<IN, OUT> {
@Setter
@NonNull
protected Connection.Response response;

/**
* {@inheritDoc}
*/
@Override
public void setResponse(Connection.Response response) {
this.response = response;
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.f0w.k2i.core.exchange;

import lombok.NonNull;
import org.jsoup.Connection;

import java.io.IOException;
Expand All @@ -12,14 +13,14 @@
* @param <OUT> Output
*/
public interface Exchangeable<IN, OUT> {
void sendRequest(IN param) throws IOException;
void sendRequest(@NonNull IN param) throws IOException;

/**
* Sets the response
*
* @param response Response to set
*/
void setResponse(Connection.Response response);
void setResponse(@NonNull Connection.Response response);

/**
* @return Raw response from server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.google.inject.Inject;
import com.typesafe.config.Config;
import lombok.NonNull;
import lombok.val;
import org.f0w.k2i.core.model.entity.Movie;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
Expand All @@ -27,15 +29,15 @@ public MovieAuthStringFetcher(Config config) {
* @throws IOException If an I/O error occurs
*/
@Override
public void sendRequest(Movie movie) throws IOException {
final String moviePageLink = "http://www.imdb.com/title/";
public void sendRequest(@NonNull Movie movie) throws IOException {
val moviePageLink = "http://www.imdb.com/title/";

Connection request = Jsoup.connect(moviePageLink + movie.getImdbId())
Connection client = Jsoup.connect(moviePageLink + movie.getImdbId())
.userAgent(config.getString("user_agent"))
.timeout(config.getInt("timeout"))
.cookie("id", config.getString("auth"));

setResponse(request.execute());
setResponse(client.execute());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,32 @@
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import com.typesafe.config.Config;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import lombok.val;
import org.f0w.k2i.core.model.entity.Movie;
import org.jsoup.Connection;
import org.jsoup.Jsoup;

import java.io.IOException;
import java.util.Map;

import static java.util.Objects.requireNonNull;

/**
* Changes Movie rating on IMDB.
*/
public final class MovieRatingChanger extends JSONPostExchangeable<Movie> {
private final Config config;

@Getter
@Setter
@NonNull
private String authString;

@Inject
public MovieRatingChanger(Config config) {
this.config = config;
}

/**
* Get the authString value.
*
* @return {@link this#authString}
*/
private String getAuthString() {
return authString;
}

/**
* Set the {@link this#authString) to a not null value.
*
* @param authString
*/
public void setAuthString(final String authString) {
this.authString = requireNonNull(authString);
}

/**
* Sends POST request and changes Movie rating,
* using using {@link MovieAuthStringFetcher#getProcessedResponse()} authorization string
Expand All @@ -52,9 +39,8 @@ public void setAuthString(final String authString) {
*/
@Override
public void sendRequest(Movie movie) throws IOException {
final String movieRatingChangeLink = "http://www.imdb.com/ratings/_ajax/title";

Map<String, String> postData = new ImmutableMap.Builder<String, String>()
val movieRatingChangeLink = "http://www.imdb.com/ratings/_ajax/title";
val postData = new ImmutableMap.Builder<String, String>()
.put("tconst", movie.getImdbId())
.put("rating", String.valueOf(movie.getRating()))
.put("auth", getAuthString())
Expand All @@ -64,14 +50,14 @@ public void sendRequest(Movie movie) throws IOException {
.put("subpageType", "main")
.build();

Connection request = Jsoup.connect(movieRatingChangeLink)
Connection client = Jsoup.connect(movieRatingChangeLink)
.method(Connection.Method.POST)
.userAgent(config.getString("user_agent"))
.timeout(config.getInt("timeout"))
.cookie("id", config.getString("auth"))
.ignoreContentType(true)
.data(postData);

setResponse(request.execute());
setResponse(client.execute());
}
}
Loading

0 comments on commit a4d825b

Please sign in to comment.