Skip to content
This repository has been archived by the owner on Jun 2, 2019. It is now read-only.

Commit

Permalink
fix last erros
Browse files Browse the repository at this point in the history
  • Loading branch information
T4ze committed Dec 9, 2017
1 parent e8563f6 commit 7553442
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
6 changes: 4 additions & 2 deletions domain/src/main/java/com/epita/domain/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import java.util.HashMap;

public class Document {
public final String url;
public final HashMap<String, Term> terms;
public String url;
public HashMap<String, Term> terms;

public Document() {}

public Document(final String url, final HashMap<String, Term> terms) {
this.url = url;
Expand Down
8 changes: 5 additions & 3 deletions domain/src/main/java/com/epita/domain/Term.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.util.List;

public class Term {
public final String token;
public final List<Integer> position;
public final double frequency;
public String token;
public List<Integer> position;
public double frequency;

public Term() {}

public Term(final String token, final List<Integer> position, final double frequency) {
this.token = token;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/epita/guereza/CrawlerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ private void requestNextUrl() {
}

private void storeUrls(final String[] urls) {
LOGGER.info("Store {} urls", urls.length);
sendMessage("/store/crawler", urls);
if (urls != null) {
LOGGER.info("Store {} urls", urls.length);
sendMessage("/store/crawler", new WrapperStringArray(urls));
}
}


Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/epita/guereza/EventStoreApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ protected EventStoreApp(EventBusClient eventBus, EventStore eventStore) {

private void extractThen(final EventBusClient.Message msg, final Consumer<Object> consumer) {
try {
LOGGER.info("Message Type: {}", msg.getMessageType());
Class c = ClassLoader.getSystemClassLoader().loadClass(msg.getMessageType());
Object o = new ObjectMapper().readValue(msg.getContent(), c);
if (o != null) {
Expand All @@ -43,7 +44,7 @@ public void run() {
eventStore.dispatch(ev);
}));
eventBus.subscribe("/store/crawler", msg -> extractThen(msg, o -> {
Event<String[]> ev = new Event<>("ADD_URLS", (String[]) o);
Event<WrapperStringArray> ev = new Event<>("ADD_URLS", (WrapperStringArray) o);
eventStore.dispatch(ev);
}));
eventBus.subscribe("/store/indexer", msg -> extractThen(msg, o -> {
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/com/epita/guereza/UrlStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;
import java.util.*;

public class UrlStore implements Reducer {
private static final Logger LOGGER = LoggerFactory.getLogger(CrawlerService.class);
Expand All @@ -26,15 +23,17 @@ public class UrlStore implements Reducer {

public UrlStore(final EventBusClient eventBus) {
this.eventBus = eventBus;
store(new String[] {STARTING_URL});
final List<String> initialList = new ArrayList<String>();
initialList.add(STARTING_URL);
store(initialList);
}

@SuppressWarnings("unchecked")
@Override
public void reduce(final Event<?> event) {
switch (event.type) {
case "ADD_URLS":
addUrls((Event<String[]>) event);
addUrls((Event<WrapperStringArray>) event);
break;
case "CRAWLER_REQUEST_URL":
crawlerRequestUrl((Event<String>) event);
Expand All @@ -45,7 +44,7 @@ public void reduce(final Event<?> event) {
}
}

private void store(String[] urls) {
private void store(List<String> urls) {
for (String url : urls) {
if (url == null || url.isEmpty())
continue;
Expand All @@ -58,8 +57,8 @@ private void store(String[] urls) {
}
}

private void addUrls(Event<String[]> event) {
store(event.obj);
private void addUrls(Event<WrapperStringArray> event) {
store(event.obj.content);
LOGGER.info("added URLs to the repo");
}

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/epita/guereza/WrapperStringArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.epita.guereza;

import java.util.Arrays;
import java.util.List;

public class WrapperStringArray {
public List<String> content;

public WrapperStringArray() {}

public WrapperStringArray(String[] content) {
this.content = Arrays.asList(content);
}
}

0 comments on commit 7553442

Please sign in to comment.