Skip to content
Snippets Groups Projects
Commit 92c4042c authored by Eike Cochu's avatar Eike Cochu
Browse files

updated cmd lib in preparation for usage in rest project

parent 58d486c2
Branches
No related tags found
No related merge requests found
...@@ -28,11 +28,18 @@ public class DeleteCommand implements Command { ...@@ -28,11 +28,18 @@ public class DeleteCommand implements Command {
private DatabaseService<ProcessedArticle> dbArticles; private DatabaseService<ProcessedArticle> dbArticles;
private Filebase filebase; private Filebase filebase;
public DeleteCommand(String[] strings) { /**
addIds(strings); * Creates a new delete command. Use {@link DeleteCommand#run()} to run this
* command.
*
* @param ids
* array of ids to be used for deletion.
*/
public DeleteCommand(String[] ids) {
addIds(ids);
} }
private void addIds(String[] strings) { public void addIds(String[] strings) {
for (String str : strings) { for (String str : strings) {
if (str.contains(File.pathSeparator)) { if (str.contains(File.pathSeparator)) {
String[] parts = str.split(File.pathSeparator); String[] parts = str.split(File.pathSeparator);
...@@ -42,7 +49,7 @@ public class DeleteCommand implements Command { ...@@ -42,7 +49,7 @@ public class DeleteCommand implements Command {
} }
} }
void deleteEntry(String id) throws ExecutionException { public void deleteEntry(String id) throws ExecutionException {
ArrayList<Exception> errors = new ArrayList<>(); ArrayList<Exception> errors = new ArrayList<>();
try { try {
...@@ -71,7 +78,8 @@ public class DeleteCommand implements Command { ...@@ -71,7 +78,8 @@ public class DeleteCommand implements Command {
public void run() throws ExecutionException { public void run() throws ExecutionException {
try { try {
config = Config.getConfig(); config = Config.getConfig();
dbArticles = DatabaseService.getDatabaseService(config, Constants.Collection.ARTICLES, ProcessedArticle.class); dbArticles = DatabaseService.getDatabaseService(config, Constants.Collection.ARTICLES,
ProcessedArticle.class);
filebase = Filebase.getFilebase(config); filebase = Filebase.getFilebase(config);
} catch (IOException | FilebaseException | ConfigException e) { } catch (IOException | FilebaseException | ConfigException e) {
throw new ExecutionException(e); throw new ExecutionException(e);
......
...@@ -52,6 +52,15 @@ public class ImportCommand implements Command { ...@@ -52,6 +52,15 @@ public class ImportCommand implements Command {
private Processor preprocessor; private Processor preprocessor;
private LDAAnalyzer analyzer; private LDAAnalyzer analyzer;
/**
* Import command to import articles into the database, do topic modeling
* and save everything. Use {@link ImportCommand#run()} to execute this
* command.
*
* @param paths
* Paths to all *.json files containing artiles or folders
* containing *.json files. Not recursive.
*/
public ImportCommand(String[] paths) { public ImportCommand(String[] paths) {
addPaths(paths); addPaths(paths);
} }
...@@ -62,13 +71,13 @@ public class ImportCommand implements Command { ...@@ -62,13 +71,13 @@ public class ImportCommand implements Command {
} }
} }
private void addPaths(File[] paths) { public void addPaths(File[] paths) {
for (int i = 0; i < paths.length; i++) { for (int i = 0; i < paths.length; i++) {
addPath(paths[i]); addPath(paths[i]);
} }
} }
private void addPath(File file) { public void addPath(File file) {
if (file.isFile()) { if (file.isFile()) {
files.add(file); files.add(file);
} else if (file.isDirectory()) { } else if (file.isDirectory()) {
...@@ -90,7 +99,7 @@ public class ImportCommand implements Command { ...@@ -90,7 +99,7 @@ public class ImportCommand implements Command {
* @return * @return
* @throws ImportException * @throws ImportException
*/ */
void importArticle(JSONObject obj) throws ImportException { private void importArticle(JSONObject obj) throws ImportException {
out.debug("importing \"" + StringUtils.ellipsize(obj.get("title").toString(), 80) + "\""); out.debug("importing \"" + StringUtils.ellipsize(obj.get("title").toString(), 80) + "\"");
ProcessedArticle article = new ProcessedArticle(); ProcessedArticle article = new ProcessedArticle();
article.fromJSON(obj); article.fromJSON(obj);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment