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
No related branches found
No related tags found
No related merge requests found
......@@ -28,11 +28,18 @@ public class DeleteCommand implements Command {
private DatabaseService<ProcessedArticle> dbArticles;
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) {
if (str.contains(File.pathSeparator)) {
String[] parts = str.split(File.pathSeparator);
......@@ -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<>();
try {
......@@ -71,7 +78,8 @@ public class DeleteCommand implements Command {
public void run() throws ExecutionException {
try {
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);
} catch (IOException | FilebaseException | ConfigException e) {
throw new ExecutionException(e);
......
......@@ -52,6 +52,15 @@ public class ImportCommand implements Command {
private Processor preprocessor;
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) {
addPaths(paths);
}
......@@ -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++) {
addPath(paths[i]);
}
}
private void addPath(File file) {
public void addPath(File file) {
if (file.isFile()) {
files.add(file);
} else if (file.isDirectory()) {
......@@ -90,7 +99,7 @@ public class ImportCommand implements Command {
* @return
* @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) + "\"");
ProcessedArticle article = new ProcessedArticle();
article.fromJSON(obj);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment