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

updated rest interface to implement json api v1.0

parent 429674af
No related branches found
No related tags found
No related merge requests found
Showing
with 1104 additions and 27 deletions
...@@ -271,6 +271,49 @@ ...@@ -271,6 +271,49 @@
}, },
"buffers": "buffers":
[ [
{
"file": "vipra-ui/app/routes/articles.js",
"settings":
{
"buffer_size": 213,
"line_ending": "Unix"
}
},
{
"file": "vipra-ui/app/templates/articles.hbs",
"settings":
{
"buffer_size": 103,
"line_ending": "Unix"
}
},
{
"file": "vipra-ui/app/models/article.js",
"settings":
{
"buffer_size": 159,
"line_ending": "Unix"
}
},
{
"file": "vipra-ui/app/adapters/application.js",
"settings":
{
"buffer_size": 137,
"line_ending": "Unix"
}
},
{
"contents": "import DS from 'ember-data';\n\nexport default DS.RESTSerializer.extend({\n \n});\n",
"file": "vipra-ui/app/serializers/application.js",
"file_size": 76,
"file_write_time": 130945949499834628,
"settings":
{
"buffer_size": 79,
"line_ending": "Unix"
}
}
], ],
"build_system": "", "build_system": "",
"build_system_choices": "build_system_choices":
...@@ -450,11 +493,23 @@ ...@@ -450,11 +493,23 @@
"expanded_folders": "expanded_folders":
[ [
"/home/eike/Repositories/fu/ss15/ma/impl", "/home/eike/Repositories/fu/ss15/ma/impl",
"/home/eike/Repositories/fu/ss15/ma/impl/vm", "/home/eike/Repositories/fu/ss15/ma/impl/vipra-ui",
"/home/eike/Repositories/fu/ss15/ma/impl/vipra-ui/app",
"/home/eike/Repositories/fu/ss15/ma/impl/vipra-ui/app/adapters",
"/home/eike/Repositories/fu/ss15/ma/impl/vipra-ui/app/models",
"/home/eike/Repositories/fu/ss15/ma/impl/vipra-ui/app/routes",
"/home/eike/Repositories/fu/ss15/ma/impl/vipra-ui/app/serializers",
"/home/eike/Repositories/fu/ss15/ma/impl/vipra-ui/app/templates",
"/home/eike/Repositories/fu/ss15/ma/impl/vipra-ui/app/templates/components",
"/home/eike/Repositories/fu/ss15/ma/impl/vm/config" "/home/eike/Repositories/fu/ss15/ma/impl/vm/config"
], ],
"file_history": "file_history":
[ [
"/home/eike/Repositories/fu/ss15/ma/impl/vipra-ui/app/app.js",
"/home/eike/Repositories/fu/ss15/ma/impl/vipra-ui/app/templates/articles.hbs",
"/home/eike/Repositories/fu/ss15/ma/impl/vipra-ui/app/templates/application.hbs",
"/home/eike/Repositories/fu/ss15/ma/impl/vipra-ui/app/templates/index.hbs",
"/home/eike/Repositories/fu/ss15/ma/impl/vipra-ui/app/router.js",
"/home/eike/Repositories/fu/ss15/ma/impl/vm/bootstrap.sh", "/home/eike/Repositories/fu/ss15/ma/impl/vm/bootstrap.sh",
"/home/eike/Repositories/fu/ss15/ma/doc/thesis/thesis.tex", "/home/eike/Repositories/fu/ss15/ma/doc/thesis/thesis.tex",
"/home/eike/Repositories/fu/ss15/ma/impl/Vagrantfile", "/home/eike/Repositories/fu/ss15/ma/impl/Vagrantfile",
...@@ -845,8 +900,484 @@ ...@@ -845,8 +900,484 @@
"groups": "groups":
[ [
{ {
"selected": 0,
"sheets": "sheets":
[ [
{
"buffer": 0,
"file": "vipra-ui/app/routes/articles.js",
"semi_transient": false,
"settings":
{
"buffer_size": 213,
"regions":
{
},
"selection":
[
[
213,
213
]
],
"settings":
{
"BracketHighlighterBusy": false,
"bh_regions":
[
"bh_curly",
"bh_curly_center",
"bh_curly_open",
"bh_curly_close",
"bh_curly_content",
"bh_c_define",
"bh_c_define_center",
"bh_c_define_open",
"bh_c_define_close",
"bh_c_define_content",
"bh_double_quote",
"bh_double_quote_center",
"bh_double_quote_open",
"bh_double_quote_close",
"bh_double_quote_content",
"bh_tag",
"bh_tag_center",
"bh_tag_open",
"bh_tag_close",
"bh_tag_content",
"bh_default",
"bh_default_center",
"bh_default_open",
"bh_default_close",
"bh_default_content",
"bh_angle",
"bh_angle_center",
"bh_angle_open",
"bh_angle_close",
"bh_angle_content",
"bh_unmatched",
"bh_unmatched_center",
"bh_unmatched_open",
"bh_unmatched_close",
"bh_unmatched_content",
"bh_single_quote",
"bh_single_quote_center",
"bh_single_quote_open",
"bh_single_quote_close",
"bh_single_quote_content",
"bh_round",
"bh_round_center",
"bh_round_open",
"bh_round_close",
"bh_round_content",
"bh_regex",
"bh_regex_center",
"bh_regex_open",
"bh_regex_close",
"bh_regex_content",
"bh_square",
"bh_square_center",
"bh_square_open",
"bh_square_close",
"bh_square_content"
],
"editorconfig": true,
"ensure_newline_at_eof_on_save": true,
"incomplete_sync": null,
"remote_loading": false,
"synced": false,
"syntax": "Packages/JavaScript/JavaScript.sublime-syntax",
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 0,
"type": "text"
},
{
"buffer": 1,
"file": "vipra-ui/app/templates/articles.hbs",
"semi_transient": false,
"settings":
{
"buffer_size": 103,
"regions":
{
},
"selection":
[
[
80,
80
]
],
"settings":
{
"BracketHighlighterBusy": false,
"bh_regions":
[
"bh_curly",
"bh_curly_center",
"bh_curly_open",
"bh_curly_close",
"bh_curly_content",
"bh_c_define",
"bh_c_define_center",
"bh_c_define_open",
"bh_c_define_close",
"bh_c_define_content",
"bh_double_quote",
"bh_double_quote_center",
"bh_double_quote_open",
"bh_double_quote_close",
"bh_double_quote_content",
"bh_tag",
"bh_tag_center",
"bh_tag_open",
"bh_tag_close",
"bh_tag_content",
"bh_default",
"bh_default_center",
"bh_default_open",
"bh_default_close",
"bh_default_content",
"bh_angle",
"bh_angle_center",
"bh_angle_open",
"bh_angle_close",
"bh_angle_content",
"bh_unmatched",
"bh_unmatched_center",
"bh_unmatched_open",
"bh_unmatched_close",
"bh_unmatched_content",
"bh_single_quote",
"bh_single_quote_center",
"bh_single_quote_open",
"bh_single_quote_close",
"bh_single_quote_content",
"bh_round",
"bh_round_center",
"bh_round_open",
"bh_round_close",
"bh_round_content",
"bh_regex",
"bh_regex_center",
"bh_regex_open",
"bh_regex_close",
"bh_regex_content",
"bh_square",
"bh_square_center",
"bh_square_open",
"bh_square_close",
"bh_square_content"
],
"editorconfig": true,
"ensure_newline_at_eof_on_save": false,
"incomplete_sync": null,
"remote_loading": false,
"synced": false,
"syntax": "Packages/Handlebars/grammars/Handlebars.tmLanguage",
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 1,
"type": "text"
},
{
"buffer": 2,
"file": "vipra-ui/app/models/article.js",
"semi_transient": false,
"settings":
{
"buffer_size": 159,
"regions":
{
},
"selection":
[
[
62,
62
]
],
"settings":
{
"BracketHighlighterBusy": false,
"bh_regions":
[
"bh_curly",
"bh_curly_center",
"bh_curly_open",
"bh_curly_close",
"bh_curly_content",
"bh_c_define",
"bh_c_define_center",
"bh_c_define_open",
"bh_c_define_close",
"bh_c_define_content",
"bh_double_quote",
"bh_double_quote_center",
"bh_double_quote_open",
"bh_double_quote_close",
"bh_double_quote_content",
"bh_tag",
"bh_tag_center",
"bh_tag_open",
"bh_tag_close",
"bh_tag_content",
"bh_default",
"bh_default_center",
"bh_default_open",
"bh_default_close",
"bh_default_content",
"bh_angle",
"bh_angle_center",
"bh_angle_open",
"bh_angle_close",
"bh_angle_content",
"bh_unmatched",
"bh_unmatched_center",
"bh_unmatched_open",
"bh_unmatched_close",
"bh_unmatched_content",
"bh_single_quote",
"bh_single_quote_center",
"bh_single_quote_open",
"bh_single_quote_close",
"bh_single_quote_content",
"bh_round",
"bh_round_center",
"bh_round_open",
"bh_round_close",
"bh_round_content",
"bh_regex",
"bh_regex_center",
"bh_regex_open",
"bh_regex_close",
"bh_regex_content",
"bh_square",
"bh_square_center",
"bh_square_open",
"bh_square_close",
"bh_square_content"
],
"editorconfig": true,
"ensure_newline_at_eof_on_save": true,
"incomplete_sync": null,
"remote_loading": false,
"synced": false,
"syntax": "Packages/JavaScript/JavaScript.sublime-syntax",
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 2,
"type": "text"
},
{
"buffer": 3,
"file": "vipra-ui/app/adapters/application.js",
"semi_transient": false,
"settings":
{
"buffer_size": 137,
"regions":
{
},
"selection":
[
[
132,
132
]
],
"settings":
{
"BracketHighlighterBusy": false,
"bh_regions":
[
"bh_curly",
"bh_curly_center",
"bh_curly_open",
"bh_curly_close",
"bh_curly_content",
"bh_c_define",
"bh_c_define_center",
"bh_c_define_open",
"bh_c_define_close",
"bh_c_define_content",
"bh_double_quote",
"bh_double_quote_center",
"bh_double_quote_open",
"bh_double_quote_close",
"bh_double_quote_content",
"bh_tag",
"bh_tag_center",
"bh_tag_open",
"bh_tag_close",
"bh_tag_content",
"bh_default",
"bh_default_center",
"bh_default_open",
"bh_default_close",
"bh_default_content",
"bh_angle",
"bh_angle_center",
"bh_angle_open",
"bh_angle_close",
"bh_angle_content",
"bh_unmatched",
"bh_unmatched_center",
"bh_unmatched_open",
"bh_unmatched_close",
"bh_unmatched_content",
"bh_single_quote",
"bh_single_quote_center",
"bh_single_quote_open",
"bh_single_quote_close",
"bh_single_quote_content",
"bh_round",
"bh_round_center",
"bh_round_open",
"bh_round_close",
"bh_round_content",
"bh_regex",
"bh_regex_center",
"bh_regex_open",
"bh_regex_close",
"bh_regex_content",
"bh_square",
"bh_square_center",
"bh_square_open",
"bh_square_close",
"bh_square_content"
],
"editorconfig": true,
"ensure_newline_at_eof_on_save": true,
"incomplete_sync": null,
"remote_loading": false,
"synced": false,
"syntax": "Packages/JavaScript/JavaScript.sublime-syntax",
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 4,
"type": "text"
},
{
"buffer": 4,
"file": "vipra-ui/app/serializers/application.js",
"semi_transient": false,
"settings":
{
"buffer_size": 79,
"regions":
{
},
"selection":
[
[
74,
74
]
],
"settings":
{
"BracketHighlighterBusy": false,
"bh_regions":
[
"bh_curly",
"bh_curly_center",
"bh_curly_open",
"bh_curly_close",
"bh_curly_content",
"bh_c_define",
"bh_c_define_center",
"bh_c_define_open",
"bh_c_define_close",
"bh_c_define_content",
"bh_double_quote",
"bh_double_quote_center",
"bh_double_quote_open",
"bh_double_quote_close",
"bh_double_quote_content",
"bh_tag",
"bh_tag_center",
"bh_tag_open",
"bh_tag_close",
"bh_tag_content",
"bh_default",
"bh_default_center",
"bh_default_open",
"bh_default_close",
"bh_default_content",
"bh_angle",
"bh_angle_center",
"bh_angle_open",
"bh_angle_close",
"bh_angle_content",
"bh_unmatched",
"bh_unmatched_center",
"bh_unmatched_open",
"bh_unmatched_close",
"bh_unmatched_content",
"bh_single_quote",
"bh_single_quote_center",
"bh_single_quote_open",
"bh_single_quote_close",
"bh_single_quote_content",
"bh_round",
"bh_round_center",
"bh_round_open",
"bh_round_close",
"bh_round_content",
"bh_regex",
"bh_regex_center",
"bh_regex_open",
"bh_regex_close",
"bh_regex_content",
"bh_square",
"bh_square_center",
"bh_square_open",
"bh_square_close",
"bh_square_content"
],
"editorconfig": true,
"ensure_newline_at_eof_on_save": true,
"incomplete_sync": null,
"remote_loading": false,
"synced": false,
"syntax": "Packages/JavaScript/JavaScript.sublime-syntax",
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 3,
"type": "text"
}
] ]
} }
], ],
...@@ -1013,7 +1544,7 @@ ...@@ -1013,7 +1544,7 @@
"show_open_files": true, "show_open_files": true,
"show_tabs": true, "show_tabs": true,
"side_bar_visible": true, "side_bar_visible": true,
"side_bar_width": 253.0, "side_bar_width": 247.0,
"status_bar_visible": true, "status_bar_visible": true,
"template_settings": "template_settings":
{ {
......
...@@ -4,14 +4,15 @@ ...@@ -4,14 +4,15 @@
<classpathentry kind="src" path="src/main/resources"/> <classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="src/test/java"/> <classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" path="src/test/resources"/> <classpathentry kind="src" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="owner.project.facets" value="java"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
......
...@@ -5,6 +5,11 @@ ...@@ -5,6 +5,11 @@
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name> <name>org.eclipse.jdt.core.javabuilder</name>
<arguments> <arguments>
...@@ -15,9 +20,24 @@ ...@@ -15,9 +20,24 @@
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature> <nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures> </natures>
<linkedResources>
<link>
<name>src/main/resources/config.properties</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/vipra-config/config.properties</locationURI>
</link>
</linkedResources>
</projectDescription> </projectDescription>
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.compiler.source=1.8
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="vipra-cmd">
<wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
<wb-resource deploy-path="/" source-path="/src/test/java"/>
<wb-resource deploy-path="/" source-path="/src/test/resources"/>
</wb-module>
</project-modules>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="java"/>
<fixed facet="jst.utility"/>
<installed facet="jst.utility" version="1.0"/>
<installed facet="java" version="1.8"/>
</faceted-project>
...@@ -23,7 +23,18 @@ ...@@ -23,7 +23,18 @@
<artifactId>commons-cli</artifactId> <artifactId>commons-cli</artifactId>
<version>1.3.1</version> <version>1.3.1</version>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<!-- Logging --> <!-- Logging -->
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
...@@ -40,11 +51,12 @@ ...@@ -40,11 +51,12 @@
<artifactId>log4j-slf4j-impl</artifactId> <artifactId>log4j-slf4j-impl</artifactId>
<version>${log4jVersion}</version> <version>${log4jVersion}</version>
</dependency> </dependency>
<!-- MongoDB Database Adapter -->
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.mongodb</groupId>
<artifactId>log4j-web</artifactId> <artifactId>mongodb-driver</artifactId>
<version>${log4jVersion}</version> <version>3.0.4</version>
<scope>runtime</scope>
</dependency> </dependency>
<!-- Testing --> <!-- Testing -->
......
package de.vipra.cmd; package de.vipra.cmd;
import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
public class CmdOptions extends Options { public class CmdOptions extends Options {
...@@ -11,8 +13,15 @@ public class CmdOptions extends Options { ...@@ -11,8 +13,15 @@ public class CmdOptions extends Options {
public static final String OPT_IMPORT = "i"; public static final String OPT_IMPORT = "i";
public CmdOptions() { public CmdOptions() {
addOption(OPT_HELP, "help", false, "print this message"); addOption(Option.builder(OPT_HELP).longOpt("help").desc("print this message").build());
addOption(OPT_IMPORT, "import", true, "import articles into the database");
OptionGroup opts = new OptionGroup();
opts.setRequired(true);
opts.addOption(Option.builder(OPT_IMPORT).longOpt("import").hasArgs().argName("files/dirs...")
.desc("import articles into the database").build());
addOptionGroup(opts);
} }
public void printHelp() { public void printHelp() {
......
package de.vipra.cmd;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class Configuration extends Properties {
private static final long serialVersionUID = 1L;
public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 27017;
public static final String DEFAULT_DB = "test";
public Configuration() {
this(Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties"));
}
public Configuration(InputStream in) {
try {
load(in);
} catch (IOException e) {}
}
public String getString(String key, String defaultValue) {
return getProperty(key, defaultValue);
}
public int getInt(String key, int defaultValue) {
try {
return Integer.parseInt(getProperty(key, Integer.toString(defaultValue)));
} catch (NumberFormatException e) {
return defaultValue;
}
}
public boolean getBool(String key, boolean defaultValue) {
return Boolean.parseBoolean(getProperty(key, Boolean.toString(defaultValue)));
}
}
package de.vipra.cmd;
public class ExecutionException extends Exception {
private static final long serialVersionUID = 1L;
public ExecutionException(String msg) {
super(msg);
}
}
...@@ -4,15 +4,11 @@ import org.apache.commons.cli.CommandLine; ...@@ -4,15 +4,11 @@ import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.vipra.cmd.option.ImportOption; import de.vipra.cmd.option.ImportOption;
public class Main { public class Main {
public static final Logger log = LoggerFactory.getLogger(Main.class);
public static void main(String[] args) { public static void main(String[] args) {
CommandLineParser parser = new DefaultParser(); CommandLineParser parser = new DefaultParser();
CmdOptions options = new CmdOptions(); CmdOptions options = new CmdOptions();
...@@ -21,13 +17,15 @@ public class Main { ...@@ -21,13 +17,15 @@ public class Main {
if (cmd.hasOption(CmdOptions.OPT_HELP)) { if (cmd.hasOption(CmdOptions.OPT_HELP)) {
options.printHelp(); options.printHelp();
} else if (cmd.hasOption(CmdOptions.OPT_IMPORT)) { } else if (cmd.hasOption(CmdOptions.OPT_IMPORT)) {
ImportOption opt = new ImportOption(cmd); String[] paths = cmd.getOptionValues(CmdOptions.OPT_IMPORT);
ImportOption opt = new ImportOption(paths);
opt.doImport(); opt.doImport();
} else {
options.printHelp();
} }
} catch (ParseException e) { } catch (ParseException e) {
log.error("error parsing cmd line: " + e.getMessage());
options.printHelp(); options.printHelp();
} } catch (ExecutionException e) {}
} }
} }
package de.vipra.cmd;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoDatabase;
public class MongoDB {
private static MongoDB mongo;
private final MongoClient client;
private final MongoDatabase db;
private MongoDB(Configuration config) {
String host = config.getString("db.host", Configuration.DEFAULT_HOST);
Integer port = config.getInt("db.port", Configuration.DEFAULT_PORT);
String databaseName = config.getString("db.name", Configuration.DEFAULT_DB);
client = new MongoClient(host, port);
db = client.getDatabase(databaseName);
}
public MongoClient getClient() {
return client;
}
public MongoDatabase getDatabase() {
return db;
}
public static MongoDB getInstance() {
if (mongo == null) {
Configuration config = new Configuration();
mongo = new MongoDB(config);
}
return mongo;
}
public static MongoDB getInstance(Configuration config) {
if (mongo == null) {
mongo = new MongoDB(config);
}
return mongo;
}
}
package de.vipra.cmd.option; package de.vipra.cmd.option;
import org.apache.commons.cli.CommandLine; import java.io.File;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import de.vipra.cmd.ExecutionException;
import de.vipra.cmd.MongoDB;
public class ImportOption { public class ImportOption {
public ImportOption(CommandLine cmd) { private ArrayList<File> files = new ArrayList<>();
private JSONParser parser = new JSONParser();
private MongoDB mongo = MongoDB.getInstance();
public ImportOption(String[] paths) throws ExecutionException {
addPaths(paths);
}
private void addPaths(String[] paths) throws ExecutionException {
for (int i = 0; i < paths.length; i++) {
addPath(new File(paths[i]));
}
}
private void addPaths(File[] paths) throws ExecutionException {
for (int i = 0; i < paths.length; i++) {
addPath(paths[i]);
}
}
private void addPath(File file) throws ExecutionException {
if (!file.exists()) {
throw new ExecutionException("file/dir does not exist");
}
if (file.isFile()) {
files.add(file);
} else if (file.isDirectory()) {
File[] files = file.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return dir.isFile();
}
});
addPaths(files);
}
}
private void importFile(File file) throws IOException, ParseException {
Object data = parser.parse(new FileReader(file));
try {
JSONArray array = (JSONArray) data;
for (Object object : array) {
importArticle((JSONObject) object);
}
} catch (Exception e) {
importArticle((JSONObject) data);
}
} }
private void importArticle(JSONObject obj) {
}
public void doImport() { public void doImport() {
for (File file : files) {
try {
importFile(file);
} catch (Exception e) {}
}
} }
} }
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
<Configuration> <Configuration>
<Appenders> <Appenders>
<Console name="Console" target="SYSTEM_OUT"> <Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n" /> <PatternLayout pattern="%level - %msg%n" />
</Console> </Console>
</Appenders> </Appenders>
<Loggers> <Loggers>
<Root level="all"> <Root level="error">
<AppenderRef ref="Console" /> <AppenderRef ref="Console" />
</Root> </Root>
</Loggers> </Loggers>
......
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="all">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
\ No newline at end of file
db.host=localhost
db.port=27017
db.name=test
\ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<name>vipra-rest</name> <name>vipra-rest</name>
<comment></comment> <comment></comment>
<projects> <projects>
<project>vipra-cmd</project>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand> <buildCommand>
...@@ -39,4 +40,11 @@ ...@@ -39,4 +40,11 @@
<nature>org.eclipse.wst.common.project.facet.core.nature</nature> <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature> <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures> </natures>
<linkedResources>
<link>
<name>src/main/resources/config.properties</name>
<type>1</type>
<locationURI>PARENT-1-PROJECT_LOC/vipra-config/config.properties</locationURI>
</link>
</linkedResources>
</projectDescription> </projectDescription>
This diff is collapsed.
eclipse.preferences.version=1
formatter_profile=_Vipra
formatter_settings_version=12
...@@ -5,6 +5,6 @@ ...@@ -5,6 +5,6 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="java-output-path" value="/vipra-rest/target/classes"/> <property name="java-output-path" value="/vipra-rest/target/classes"/>
<property name="context-root" value="rest"/> <property name="context-root" value="vipra-rest"/>
</wb-module> </wb-module>
</project-modules> </project-modules>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment