diff options
| author | Simon Rettberg | 2015-06-02 19:53:31 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2015-06-02 19:53:31 +0200 |
| commit | 1bc83891c68ee269727e81a13cc70da698bcc7a7 (patch) | |
| tree | b052a72ad7d65864068752f71c5ed2b49a171276 /dozentenmodulserver/src/main/java/models | |
| parent | [server] Started work on the internal file server (diff) | |
| download | tutor-module-1bc83891c68ee269727e81a13cc70da698bcc7a7.tar.gz tutor-module-1bc83891c68ee269727e81a13cc70da698bcc7a7.tar.xz tutor-module-1bc83891c68ee269727e81a13cc70da698bcc7a7.zip | |
[server] Compiling again, still lots of stubs
Diffstat (limited to 'dozentenmodulserver/src/main/java/models')
| -rw-r--r-- | dozentenmodulserver/src/main/java/models/Configuration.java | 87 |
1 files changed, 60 insertions, 27 deletions
diff --git a/dozentenmodulserver/src/main/java/models/Configuration.java b/dozentenmodulserver/src/main/java/models/Configuration.java index 1e616466..244e542b 100644 --- a/dozentenmodulserver/src/main/java/models/Configuration.java +++ b/dozentenmodulserver/src/main/java/models/Configuration.java @@ -1,39 +1,72 @@ package models; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.apache.log4j.Logger; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; + public class Configuration { - - private String absolute_path; - private String sql_connection; - private String sql_user; - private String sql_pass; - - public static Configuration config =new Configuration(); - - public String getAbsolute_path() { - return absolute_path; - } - public void setAbsolute_path(String absolute_path) { - this.absolute_path = absolute_path; + + private static final Logger LOGGER = Logger.getLogger(Configuration.class); + private static final DateTimeFormatter subdirDate = DateTimeFormat.forPattern("yy-MM"); + + private static File vmStoreBasePath; + private static File vmStoreProdPath; + private static String dbUri; + private static String dbUsername; + private static String dbPassword; + + public static boolean load() throws IOException { + // Load configuration from java properties file + Properties prop = new Properties(); + InputStream in = new FileInputStream("./config.properties"); + try { + prop.load(in); + } finally { + in.close(); + } + + vmStoreBasePath = new File(prop.getProperty("vmstore.path")); + vmStoreProdPath = new File(vmStoreBasePath, "prod"); + dbUri = prop.getProperty("db.uri"); + dbUsername = prop.getProperty("db.username"); + dbPassword = prop.getProperty("db.password"); + + // Currently all fields are mandatory but there might be optional settings in the future + return vmStoreBasePath != null && dbUri != null && dbUsername != null && dbPassword != null; } - public String getSql_connection() { - return sql_connection; + + // Static ("real") fields + + public static File getVmStoreBasePath() { + return vmStoreBasePath; } - public void setSql_connection(String sql_connection) { - this.sql_connection = sql_connection; + + public static String getDbUri() { + return dbUri; } - public String getSql_user() { - return sql_user; + + public static String getDbUsername() { + return dbUsername; } - public void setSql_user(String sql_user) { - this.sql_user = sql_user; + + public static String getDbPassword() { + return dbPassword; } - public String getSql_pass() { - return sql_pass; + + public static File getVmStoreProdPath() { + return vmStoreProdPath; } - public void setSql_pass(String sql_pass) { - this.sql_pass = sql_pass; + + // Dynamically Computed fields + + public static File getCurrentVmStorePath() { + return new File(vmStoreProdPath, subdirDate.print(System.currentTimeMillis())); } - - } |
