2019-01-09 17:57:37 +03:00
|
|
|
package ru.bvn13.imdbspider.spider.tasker;
|
|
|
|
|
2019-01-10 18:14:57 +03:00
|
|
|
import org.jsoup.select.Elements;
|
2019-01-09 17:57:37 +03:00
|
|
|
import ru.bvn13.imdbspider.exceptions.ImdbSpiderException;
|
|
|
|
import ru.bvn13.imdbspider.imdb.DataType;
|
|
|
|
|
2019-01-10 18:14:57 +03:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.function.BiConsumer;
|
|
|
|
|
2019-01-09 17:57:37 +03:00
|
|
|
/**
|
|
|
|
* @author boyko_vn at 09.01.2019
|
|
|
|
*/
|
|
|
|
public class Task {
|
|
|
|
|
|
|
|
private String url;
|
|
|
|
|
|
|
|
private DataType dataType;
|
2019-01-10 18:14:57 +03:00
|
|
|
private String cssSelector;
|
|
|
|
private Elements cssSelectorResult;
|
|
|
|
|
|
|
|
private Class resultType;
|
|
|
|
private Object result;
|
2019-01-09 17:57:37 +03:00
|
|
|
|
|
|
|
private ImdbSpiderException exception;
|
|
|
|
|
2019-01-10 18:14:57 +03:00
|
|
|
private BiConsumer<Task, String> postprocess;
|
|
|
|
|
|
|
|
private Task parentTask;
|
|
|
|
private List<Task> nestedTasks;
|
|
|
|
|
2019-01-09 17:57:37 +03:00
|
|
|
public Task() {
|
|
|
|
}
|
|
|
|
|
2019-01-10 18:14:57 +03:00
|
|
|
public Task(String cssSelector) {
|
|
|
|
this.cssSelector = cssSelector;
|
2019-01-09 17:57:37 +03:00
|
|
|
}
|
|
|
|
|
2019-01-10 18:14:57 +03:00
|
|
|
public Task(String url, String cssSelector) {
|
2019-01-09 17:57:37 +03:00
|
|
|
this.url = url;
|
2019-01-10 18:14:57 +03:00
|
|
|
this.cssSelector = cssSelector;
|
2019-01-09 17:57:37 +03:00
|
|
|
}
|
|
|
|
|
2019-01-10 18:14:57 +03:00
|
|
|
public Task(String url, String cssSelector, DataType dataType) {
|
2019-01-09 17:57:37 +03:00
|
|
|
this.url = url;
|
2019-01-10 18:14:57 +03:00
|
|
|
this.cssSelector = cssSelector;
|
2019-01-09 17:57:37 +03:00
|
|
|
this.dataType = dataType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getUrl() {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2019-01-10 18:14:57 +03:00
|
|
|
public Task setUrl(String url) {
|
2019-01-09 17:57:37 +03:00
|
|
|
this.url = url;
|
2019-01-10 18:14:57 +03:00
|
|
|
return this;
|
2019-01-09 17:57:37 +03:00
|
|
|
}
|
|
|
|
|
2019-01-10 18:14:57 +03:00
|
|
|
public String getCssSelector() {
|
|
|
|
return cssSelector;
|
2019-01-09 17:57:37 +03:00
|
|
|
}
|
|
|
|
|
2019-01-10 18:14:57 +03:00
|
|
|
public Task setCssSelector(String cssSelector) {
|
|
|
|
this.cssSelector = cssSelector;
|
|
|
|
return this;
|
2019-01-09 17:57:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public DataType getDataType() {
|
|
|
|
return dataType;
|
|
|
|
}
|
|
|
|
|
2019-01-10 18:14:57 +03:00
|
|
|
public Task setDataType(DataType dataType) {
|
2019-01-09 17:57:37 +03:00
|
|
|
this.dataType = dataType;
|
2019-01-10 18:14:57 +03:00
|
|
|
return this;
|
2019-01-09 17:57:37 +03:00
|
|
|
}
|
|
|
|
|
2019-01-10 18:14:57 +03:00
|
|
|
public Elements getCssSelectorResult() {
|
|
|
|
return cssSelectorResult;
|
2019-01-09 17:57:37 +03:00
|
|
|
}
|
|
|
|
|
2019-01-10 18:14:57 +03:00
|
|
|
public Task setCssSelectorResult(Elements cssSelectorResult) {
|
|
|
|
this.cssSelectorResult = cssSelectorResult;
|
|
|
|
return this;
|
2019-01-09 17:57:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public ImdbSpiderException getException() {
|
|
|
|
return exception;
|
|
|
|
}
|
|
|
|
|
2019-01-10 18:14:57 +03:00
|
|
|
public Task setException(ImdbSpiderException exception) {
|
2019-01-09 17:57:37 +03:00
|
|
|
this.exception = exception;
|
2019-01-10 18:14:57 +03:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BiConsumer<Task, String> getPostprocess() {
|
|
|
|
return postprocess;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task setPostprocess(BiConsumer<Task, String> postprocess) {
|
|
|
|
this.postprocess = postprocess;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Class getResultType() {
|
|
|
|
return resultType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task setResultType(Class resultType) {
|
|
|
|
this.resultType = resultType;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object getResult() {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task setResult(Object result) {
|
|
|
|
this.result = result;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasNextTasks() {
|
|
|
|
return (nestedTasks != null && !nestedTasks.isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Task> getNestedTasks() {
|
|
|
|
if (nestedTasks == null) {
|
|
|
|
nestedTasks = new ArrayList<>();
|
|
|
|
}
|
|
|
|
return nestedTasks;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task setNestedTasks(List<Task> nestedTasks) {
|
|
|
|
this.nestedTasks = nestedTasks;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task getParentTask() {
|
|
|
|
return parentTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task setParentTask(Task parentTask) {
|
|
|
|
this.parentTask = parentTask;
|
|
|
|
return this;
|
2019-01-09 17:57:37 +03:00
|
|
|
}
|
|
|
|
}
|