ConfigMetadata.java 8.09 KB
Newer Older
Naung1 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
package com.csc.library.database;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.jdom.Element;

import com.csc.library.session.InitialEnvironment;
import com.csc.library.utilities.MyLog;
import com.csc.library.utilities.ReadXml;
import com.csc.library.utilities.UProfile;

public class ConfigMetadata  implements Serializable {
	private transient ReadXml read1;
	private  Element rootElement;
	private UProfile uf=null;
	private String dependlevel = "true";
	private Vector processdata = new Vector();
	private Vector permanenttable= new Vector();
	private String wfactive = "true";

	// variable for Schedule
    private String taskschedule = "false";    
   
    //Start check index
    private String checkindex="false";
    private String production="false";
    private String debug="false";
    private String info="false";
    private String display="false";
    private String warning="false";
    private String limitlogin="false";
    private String maxtemp="0";
    private  String ClearSize = "20";
    
	public ConfigMetadata(UProfile uf) {
		this.uf = uf;
	}

	public void process() {
		if(StaticProperties.myConfig==null){
			StaticProperties.myConfig=new MyHashMap();
			this.initXml();
			this.dependlevel = this.getValue("RULE_FOREINGEKEY","value","true");			
			this.wfactive = this.getValue("WORKFLOW_ACTIVE","value","true");
	        
	        // Start Taskdef
	        this.taskschedule = this.getValue("TASKSCHEDULE","value","false");
	        // End Taskdef
			
	        this.setProcessData();		
			//this.setMessage();
			
	        //Start checkindex
	        this.checkindex=this.getValue("CHECKINDEX","value","false");
	        this.production=this.getValue("PRODUCTION","value","false");
	        this.debug=this.getValue("DEBUG","value","false");
	        this.info=this.getValue("INFO","value","false");
	        this.display=this.getValue("DISPLAY","value","false");
	        this.warning=this.getValue("WARN","value","false");
	        //end checkindex	
	        
	        //limit login
	        this.limitlogin=this.getValue("LIMITLOGIN","value","false");    
	        this.maxtemp=this.getValue("TEMPTABLE","max","60");
	        this.ClearSize=this.getValue("TEMPTABLE","clear","20");
	        this.setPermentTable();
	        this.setValue();
		}else{
			this.getValue();
		}
	}

	private void setFieldMap(HashMap map, String type, String field) {
		Element em = rootElement.getChild(type).getChild(field);
		Element tmp;
		Iterator it = em.getChildren().iterator();
		while (it.hasNext()) {
			tmp = (Element) it.next();
			map.put(tmp.getText(), tmp.getAttributeValue("type") + ","+ tmp.getAttributeValue("method"));
		}
	}

	public boolean isGlobal() {
		String dbName = this.uf.getDbName().trim();
		return dbName.equalsIgnoreCase(new InitialEnvironment("GLOBAL")
				.getValue("db-name"));
	}


	private String getConfigPath() {
		return new InitialEnvironment("GLOBAL").getValue("config-dir");
	}

	public void initXml() {
		if(this.rootElement==null){
			ReadXml read = new ReadXml(this.getConfigPath() + "config");
			this.rootElement =read.getRootElement();
		}
	}

	public boolean isGlogalTable(String tableName) {
		Element global = rootElement.getChild("GLOBAL");
		java.util.Iterator it = global.getChildren().iterator();
		while (it.hasNext()) {
			Element ch = (Element) it.next();
			String data = ch.getText();
			if (tableName.equalsIgnoreCase(data))
				return true;
		}
		return false;
	}

	public String getDependLevel() {
		return this.dependlevel;
	}

	public Vector getProcessDataConfig() {
		return this.processdata;
	}
	
	private void setProcessData() {
		Element tmpChild = this.rootElement.getChild("PROCESSDATA");
		if (tmpChild != null) {
			Vector vec = new Vector(tmpChild.getChildren());
			for (int i = 0; i < vec.size(); i++) {
				this.processdata.add(((Element) vec.get(i)).getText().toLowerCase());
			}
		}
	}
	
	public String getWfActive() {
		return this.wfactive;
	}
	
	private String getValue(String childname,String attrname,String defaultvalue) {
		if (this.rootElement.getChild(childname) != null){
			String a = this.rootElement.getChild(childname).getAttributeValue(attrname);
			if (a !=null && !a.equals("")) 
				return a;
		}
		return defaultvalue;
	}
        
    public String getTaskSchedule() {
        return this.taskschedule;
    }
    
        /**
     * check Index of table
     */
    public boolean checkIndexTable(){
        if(this.checkindex!=null && this.checkindex.equalsIgnoreCase("true"))
            return true;        
        return false;
    }

    public boolean getDebugStatus(){
        if(this.debug!=null && this.debug.equalsIgnoreCase("true"))
            return true;        
        return false;
    }
    public boolean getInfoStatus(){
        if(this.info!=null && this.info.equalsIgnoreCase("true"))
            return true;        
        return false;
    }
    public boolean getProductionStatus(){
        if(this.production!=null && this.production.equalsIgnoreCase("true"))
            return true;        
        return false;
    }
    public boolean getDisplayStatus(){
        if(this.display!=null && this.display.equalsIgnoreCase("true"))
            return true;        
        return false;
    }
    
    public boolean getWarningStatus(){
        if(this.warning!=null && this.warning.equalsIgnoreCase("true"))
            return true;        
        return false;
    }
    public boolean getLimitLogin(){
    	if(this.limitlogin!=null && this.limitlogin.equalsIgnoreCase("true"))
    		return true;
    	return false;
    	
    }
    
	private void setPermentTable() {
		Element tmpChild = this.rootElement.getChild("PERMANENT_TABLE");
		if (tmpChild != null) {
			Vector vec = new Vector(tmpChild.getChildren());
			for (int i = 0; i < vec.size(); i++) {
				this.permanenttable.add(convertTable(((Element) vec.get(i)).getText().toLowerCase()));
			}
		}
	}
	
	public Vector getPermanentTable(){
		return this.permanenttable;
	}
	
	public int getMaxTemporary(){
		return Integer.parseInt(this.maxtemp);
	}
	
	public int getClearSize(){
		return Integer.parseInt(this.ClearSize);
	}
	
	
	private void setValue(){
   		StaticProperties.myConfig.put("dependlevel",dependlevel);
		StaticProperties.myConfig.put("wfactive",wfactive);
		StaticProperties.myConfig.put("taskschedule",taskschedule);
		StaticProperties.myConfig.put("checkindex",checkindex);
		StaticProperties.myConfig.put("production",production);
		StaticProperties.myConfig.put("debug",debug);
		StaticProperties.myConfig.put("info",info);
		StaticProperties.myConfig.put("display",display);
		StaticProperties.myConfig.put("warning",warning);
		StaticProperties.myConfig.put("limitlogin",limitlogin);    
        StaticProperties.myConfig.put("maxtemp",maxtemp);	
        StaticProperties.myConfig.put("permanenttable",permanenttable);
        StaticProperties.myConfig.put("processdata",processdata);        
        StaticProperties.myConfig.put("clearsize",ClearSize);        
	}
	
	private void getValue(){
        dependlevel	=(String)StaticProperties.myConfig.get("dependlevel");
        wfactive   	=(String)StaticProperties.myConfig.get("wfactive");
        taskschedule=(String)StaticProperties.myConfig.get("taskschedule");
        checkindex	=(String)StaticProperties.myConfig.get("checkindex");
        production	=(String)StaticProperties.myConfig.get("production");
        debug		=(String)StaticProperties.myConfig.get("debug");
        info		=(String)StaticProperties.myConfig.get("info");
        display		=(String)StaticProperties.myConfig.get("display");
        warning		=(String)StaticProperties.myConfig.get("warning");
        limitlogin	=(String)StaticProperties.myConfig.get("limitlogin");    
        maxtemp		=(String)StaticProperties.myConfig.get("maxtemp");		
		permanenttable=(Vector)StaticProperties.myConfig.get("permanenttable");
		processdata=(Vector)StaticProperties.myConfig.get("processdata");
		ClearSize=(String) StaticProperties.myConfig.get("clearsize"); 
	}
	
	private String convertTable(String tableName) {
		String tName = tableName.toLowerCase();
		return tName.substring(0, 1).toUpperCase() + tName.substring(1, tName.length());
	}	
}