-- added fancybox 1.3.1 to project, initially for showing screenshots. See documentat...
[Bookkeeping.git] / src / com / interrupt / bookkeeping / cc / bkell / Configure.java
blobdd043167fe6706307bb9c7679a9961e8e16d1912
1 package com.interrupt.bookkeeping.cc.bkell;
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.util.Properties;
7 import org.apache.log4j.Logger;
9 import com.interrupt.bob.base.Bob;
10 import com.interrupt.bob.base.IBob;
11 import com.interrupt.bob.base.IVisitor;
12 import com.interrupt.bookkeeping.cc.bkell.aauth.Aauthentication;
13 import com.interrupt.bookkeeping.exception.SystemException;
14 import com.interrupt.bookkeeping.users.IUser;
15 import com.interrupt.spittoon.Spittoon;
16 import com.interrupt.util.Util;
18 public class Configure {
21 public void run() {
23 Logger logger = Logger.getLogger(Configure.class);
24 logger.debug("Configuring Bookkeeping database...");
27 InputStream inStream = ClassLoader.getSystemResourceAsStream("bookkeeping.properties");
28 Properties props = new Properties();
29 try {
30 props.load(inStream);
32 catch(IOException e) {
33 throw new SystemException(e);
36 /**
37 * 'Bob' setup
39 System.setProperty("bob.home", props.getProperty("bob.home"));
40 System.setProperty("bob.base", props.getProperty("bob.base"));
41 System.setProperty("bob.gen", props.getProperty("bob.gen"));
42 System.setProperty("bob.end", props.getProperty("bob.gen"));
43 System.setProperty("bob.end", props.getProperty("bob.def"));
46 /**
47 * Spittoon initialisation
49 Spittoon spittoon = new Spittoon();
50 spittoon.initialise();
51 spittoon.setupRoot();
53 /**
54 * Spittoon DB setup
56 //String axpath = "/system[ @id='main.system' ]/aauthentication[ @id='main.authentication' ]/users[ @id='aauth.users' ]/user[ @id='root' ]";
57 String axpath = "/system[ @id='main.system' ]";
58 String axml = Util.loadTextFile("setup.aauthentication.xml");
59 String aurl = spittoon.getAauthDbUrl();
60 logger.debug("Aauth XPath["+ axpath +"]");
61 logger.debug("Loaded axml["+axml+"]");
63 //String gxpath = "/system[ @id='main.system' ]/groups[ @id='main.groups' ]/bookkeeping[ @id='main.bookkeeping' ]/journals[ @id='main.journals' ]/journal[ @id='generalledger' ]/entries[ @id='main.entries' ]";
64 String gxpath = "/system[ @id='main.system' ]";
65 String gxml = Util.loadTextFile("setup.groups.xml");
66 String gurl = spittoon.getGroupsDbUrl();
67 logger.debug("Groups XPath["+ gxpath +"]");
68 logger.debug("Loaded gxml["+gxml+"]");
70 //** generating default root password hash
71 String passwd = props.getProperty("defaultRootPasswd");
72 Aauthentication aauth = new Aauthentication();
73 String passwdHash = aauth.hashPassword(passwd);
74 logger.debug("Here 1 > defaultRootPasswd["+passwd+"] / passwdHash["+passwdHash+"]");
76 class FindRootUser implements IVisitor {
78 private Logger logger = Logger.getLogger(Configure.class);
79 private String phash = null;
80 public FindRootUser(String passwdh) {
81 phash = passwdh;
83 public void visit(IBob bob) {
85 logger.error("FindRootUser.visit > tag["+bob.getTagName()+"] / id["+bob.getAttributeValue("id")+"]");
86 if( bob.getTagName().equals("user") &&
87 bob.getAttributeValue("id").equals("root")) {
88 ((IUser)bob).setPassword(phash);
94 //** setting root passwd
95 FindRootUser fruser = new FindRootUser(passwdHash);
97 IBob loadedAauth = com.interrupt.bob.util.Util.loadBobFromXML(axml);
98 logger.debug("Loaded Bob from axml["+loadedAauth.toXML(false)+"]");
100 loadedAauth.accept(fruser);
101 logger.debug("Loaded Bob AFTER FindRootUser / Create Root User ["+loadedAauth.toXML(false)+"]");
104 //** creating collections in the XML database
105 logger.debug("Creating database collections for > AAUTH url["+aurl+"] / xpath["+axpath+"] > GROUPS url["+gurl+"] / xpath["+gxpath+"]");
107 logger.debug("Creating aauthentication collections...");
108 spittoon.createR(aurl, axpath, loadedAauth.toXML(false));
110 logger.debug("Creating groups collections...");
111 spittoon.createR(gurl, gxpath, gxml);
115 public static void main(String args[]) {
117 Configure configure = new Configure();
118 configure.run();