-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standalone and deployable RESTful services
- Loading branch information
Maria Voinea
authored and
Maria Voinea
committed
Mar 16, 2014
1 parent
c767edb
commit 8d9e5a9
Showing
12 changed files
with
197 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
crowdchef-core/src/main/java/com/crowdchef/core/CoreController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.crowdchef.core; | ||
|
||
|
||
import com.crowdchef.core.handlers.RecipeHandler; | ||
import com.crowdchef.core.handlers.UserHandler; | ||
import com.crowdchef.core.retriever.Indexer; | ||
import com.crowdchef.core.retriever.Searcher; | ||
import com.crowdchef.datamodel.CrowdChefDatabase; | ||
import com.crowdchef.datamodel.entities.Recipe; | ||
import com.crowdchef.datamodel.entities.User; | ||
import com.crowdchef.datamodel.entities.UserInfo; | ||
import com.google.gson.*; | ||
import org.json.JSONObject; | ||
|
||
import java.util.List; | ||
|
||
public class CoreController { | ||
private CrowdChefDatabase database; | ||
private UserHandler userHandler; | ||
private RecipeHandler recipeHandler; | ||
private final Searcher searcher; | ||
private final Indexer indexer; | ||
|
||
public CoreController() { | ||
this.database = new CrowdChefDatabase(); | ||
this.userHandler = new UserHandler(this.database); | ||
this.recipeHandler = new RecipeHandler(this.database); | ||
this.searcher = new Searcher(); | ||
this.indexer = new Indexer(); | ||
} | ||
|
||
public static Gson buildGson(final Class<?> skippedFieldClass){ | ||
return new GsonBuilder() | ||
.setExclusionStrategies(new ExclusionStrategy() { | ||
|
||
public boolean shouldSkipClass(Class<?> clazz) { | ||
return false; | ||
} | ||
|
||
public boolean shouldSkipField(FieldAttributes f) { | ||
return f.getDeclaredClass() == skippedFieldClass; | ||
} | ||
|
||
}) | ||
.create(); | ||
} | ||
|
||
public JsonElement listRecipes(){ | ||
Gson gson = new Gson(); | ||
List<Recipe> recipes = recipeHandler.getRecipes(); | ||
return buildGson(User.class).toJsonTree(recipes); | ||
} | ||
|
||
public JsonElement getUserInfo(Long id) { | ||
return buildGson(User.class).toJsonTree(userHandler.getUserInfo(id)); | ||
} | ||
|
||
public JsonElement search(String searchQuery, String field) { | ||
searcher.search(searchQuery, field); | ||
return null; | ||
} | ||
|
||
} |
31 changes: 0 additions & 31 deletions
31
crowdchef-core/src/main/java/com/crowdchef/core/DatabaseController.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
crowdchef-core/src/test/java/com/crowdchef/core/test/CoreControllerTester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.crowdchef.core.test; | ||
|
||
|
||
import com.crowdchef.core.CoreController; | ||
|
||
public class CoreControllerTester { | ||
public static void main(String[] args) { | ||
CoreController controller = new CoreController(); | ||
System.out.println(controller.getUserInfo(new Long(1))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 2 additions & 5 deletions
7
crowdchef-webservice/src/main/java/com/crowdchef/webservice/CrowdChefRESTServerMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
package com.crowdchef.webservice; | ||
|
||
import com.crowdchef.*; | ||
|
||
import static spark.Spark.setPort; | ||
|
||
public class CrowdChefRESTServerMain { | ||
public static void main(String[] args) | ||
{ | ||
public static void main(String[] args) { | ||
setPort(9090); | ||
new WebService(new Searcher(), new Indexer()).start(); | ||
new WebService().init(); | ||
|
||
} | ||
} |
53 changes: 31 additions & 22 deletions
53
crowdchef-webservice/src/main/java/com/crowdchef/webservice/WebService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE web-app PUBLIC | ||
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" | ||
"http://java.sun.com/dtd/web-app_2_3.dtd" > | ||
|
||
<web-app> | ||
<filter> | ||
<filter-name>SparkFilter</filter-name> | ||
<filter-class>spark.servlet.SparkFilter</filter-class> | ||
<init-param> | ||
<param-name>applicationClass</param-name> | ||
<param-value>com.crowdchef.webservice.WebService</param-value> | ||
</init-param> | ||
</filter> | ||
|
||
<filter-mapping> | ||
<filter-name>SparkFilter</filter-name> | ||
<url-pattern>/*</url-pattern> | ||
</filter-mapping> | ||
</web-app> |