/*
*
* author:  gvenzl
* created: 24 Mar 2016
*
* name: Configurator.java
*
*/

package com.dbpm.config;

import com.dbpm.Module;
import com.dbpm.db.DBTYPE;
import com.dbpm.logger.Logger;
import com.dbpm.utils.Parameter;

public class Configurator implements Module {

	private boolean remove = false;
	private boolean dbStorage = false;
	private String user;
	private String password;
	private String host;
	private String port;
	private String dbName;
	private String platform;
	
	public Configurator (String[] args) throws IllegalArgumentException {
		
		if (args[1].equals(RepoStorage.DB.name().toLowerCase())) {
			dbStorage = true;
		
			for (int i=2;i<args.length;i++) {
				if (args[i].toUpperCase().equals(RepoStorage.DB.name())) { dbStorage = true; }
				else if (args[i].equals(Parameter.USER)) { user = args[++i]; }
				else if (args[i].equals(Parameter.PASSWORD)) { password = args[++i]; }
				else if (args[i].equals(Parameter.HOST)) { host = args[++i]; }
				else if (args[i].equals(Parameter.PORT)) { port = args[++i]; }
				else if (args[i].equals(Parameter.DBNAME)) { dbName = args[++i]; }
				else if (args[i].equals(Parameter.PLATFORM)) {
					platform = args[++i];
					
					boolean supported = false;
					for (DBTYPE type : DBTYPE.values()) {
						if (platform.equals(type.name().toLowerCase())) {
							supported = true;
							break;
						}
					}
					
					if (!supported) {
						throw new IllegalArgumentException("Unsupported platform.");
					}
				}
				// Ignore verbose as already set in DBPM.
				else if (args[i].equals(Parameter.VERBOSE)) { }
				else {
					throw new IllegalArgumentException("Unknown argument: " + args[i]);
				}
			}
		}
		else if (args[1].equals(RepoStorage.FILE.name().toLowerCase()) && args.length > 2) {
			for (int i=2;i<args.length;i++) {
				if (!args[i].equals(Parameter.VERBOSE)) {
					throw new IllegalArgumentException("Too many arguments.");
				}
			}
		}
		else if (args[1].equals("remove")) {
			remove = true;
		}
	}
	
	@Override
	public void run() {
		Config config;
		
		try {
			if (remove) {
				new Config().removeConfiguration();
			}
			else {
				if (!dbStorage) {
					config = new Config();
				}
				else {
					config = new Config(platform, user, password, host, port, dbName);
				}
				config.createConfiguration();
			}
		}
		catch (Exception e) {
			Logger.error(e.getMessage());
		}
	}

}

@@ -475,16 +475,636 @@
 form;%0A%09%0A
+%09/**%0A%09 * Instantiates a new Configurator object.%0A%09 * @param args The arguments for the configuration.%3Cbr/%3E%0A%09 * Those can be:%3Cbr/%3E%3Cbr/%3E%0A%09 * db - Store configuration inside the database%3Cbr/%3E%0A%09 * -user - The username to store the configuration in.%3Cbr/%3E%0A%09 * -passwor - The password for the user%3Cbr/%3E%0A%09 * -host - The host where the database is located%3Cbr/%3E%0A%09 * -port - The port on which the database is reachable%3Cbr/%3E%0A%09 * -dbname - The database name%3Cbr/%3E%0A%09 * -platform - The database platform%3Cbr/%3E%0A%09 * %3Cbr/%3E%3Cbr/%3E%0A%09 * file - stores the configuartion in a file on the filesystem.%0A%09 * %0A%09 * @throws IllegalArgumentException%0A%09 */%0A
 %09public 
@@ -1166,16 +1166,16 @@
 ption %7B%0A
-
 %09%09%0A%09%09if 
@@ -1311,22 +1311,8 @@
 %5Bi%5D.
-toUpperCase().
 equa
@@ -1335,16 +1335,30 @@
 B.name()
+.toLowerCase()
 )) %7B dbS

Add Javadoc and change semantic check to conform with the above.