GwtHelpEntry.java 7.8 KB
Newer Older
TongZuu 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
package com.csc.library.entry;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.csc.library.database.ChildManager;
import com.csc.library.database.FieldManager;
import com.csc.library.database.SystemCode;
import com.csc.library.session.DbInquiry;
import com.csc.library.session.DbRecord;
import com.csc.library.utilities.MyLog;

public class GwtHelpEntry extends HelpEntry{
	
	private int error=0;
	private int initrecord=0;
	private StringBuilder str=new StringBuilder();
	
	public GwtHelpEntry() {
		this.type = "helpEntry";
	}
	
	public ArrayList<Map<String, String>> getGwtConditionSearch() {
	 	ArrayList<Map<String,String>> consearch= new ArrayList<Map<String,String>>();
			try{	 	
			 	String[][] tmp = SystemCode.getContent("consearch");
			 	Map<String, String> mp;
			 	String l=(String)this.getUProfile().get("lang");			 	
			 	for(int index=0; index<tmp.length; index++) {
			 		mp=new HashMap<String, String>();
			 		if(tmp[index][1].indexOf(",")>-1){
				 		if(l.equalsIgnoreCase("eng")){
				 			mp.put("item",tmp[index][1].substring(0,tmp[index][1].indexOf(",")));
				 		}else{
				 			mp.put("item",tmp[index][1].substring(tmp[index][1].indexOf(",")+1));
				 		}			 		
			 		}else{
			 			mp.put("item",tmp[index][1]);
			 		}
			 		mp.put("value",tmp[index][0]);
			 		consearch.add(mp);
			 	}
			}catch(Exception ex){
				str.append("Can 't get ConditionSearch\n");
				error++;
			}
		 	return consearch;
	    }
	    
	    public ArrayList<Map<String, String>> getGwtOrderBy() {
	    	ArrayList<Map<String,String>> order= new ArrayList<Map<String,String>>();
	    	try{
		    	String orderarr[]=this.orderList.split(",");
			 	Map<String, String> mp;
			 	String[] tmp;
			 	for(int index=0; index<orderarr.length; index++) {
			 		tmp=orderarr[index].split("\\.");		 		
			 		mp=new HashMap<String, String>();
			 		mp.put("item",this.inq.getCurrentDbRecord().getField(tmp[1]).getDescription());
			 		mp.put("value",orderarr[index]);
			 		order.add(mp);
			 	}
	    	}catch (Exception ex) {
	    		str.append("Can 't get getGwtOrderBy\n");
	    		error++;
	    		return null;
			}
	        return order;
	    }
	    
	    public ArrayList<Map<String, String>> getGwtSearchBy() {	    	
	    	ArrayList<Map<String,String>> search= new ArrayList<Map<String,String>>();
	    	try{
		    	String searcharr[]=this.searchList.split(",");
			 	Map<String, String> mp;
			 	for(int index=0; index<searcharr.length; index++) {
			 		mp=new HashMap<String, String>();
			 		mp.put("item",this.inq.getCurrentDbRecord().getField(searcharr[index]).getDescription());
			 		mp.put("value",this.inq.getTableName()+"."+searcharr[index]);
			 		search.add(mp);
			 	}
	    	}catch (Exception ex) {
	    		str.append("Can 't get getGwtSearchBy\n");
	    		error++;
	    		return null;
			}
	        return search;
	    }
	    
	    public ArrayList<Map<String,String>> getGwtHeaderTitle() {
	    	ArrayList<Map<String,String>> order= new ArrayList<Map<String,String>>();
	    	try{
		    	String orderarr[]=this.showList.split(",");
			 	Map<String, String> mp;
			 	String[] tmp;
			 	FieldManager fm; 
			 	ChildManager child;
			 	for(int index=0; index<orderarr.length; index++) {
			 		tmp=orderarr[index].split("\\.");
			 		if(tmp[0].equalsIgnoreCase(this.inq.getActualName()))
			 			fm=this.inq.getCurrentDbRecord().getField(tmp[1]);
			 		else{
			 			child=this.inq.getChild(tmp[0]);
			 			if(child instanceof DbRecord){
			 				fm=((DbRecord)child).getField(tmp[1]);
			 			}else{
			 				fm=((DbInquiry)child).getCurrentDbRecord().getField(tmp[1]);
			 			}
			 		}
			 		
			 		mp=new HashMap<String, String>();
			 		mp.put("name",tmp[1]);
			 		mp.put("type",fm.getType());
			 		mp.put("label",fm.getDescription());
			 		order.add(mp);
			 	}
	    	}catch (Exception ex) {
	    		str.append("Can 't get getGwtHeaderTitle\n");
	    		error++;
	    		return null;
			}
	        return order;
	    } 
	    
	    public List<String> getGwtShowList(){
	    	return Arrays.asList(this.showList.split(","));
	    }

	    public List<String> getGwtSearchList(){
	    	return Arrays.asList(this.searchList.split(","));
	    }

	    public List<String> getGwtOrderList(){
	    	return Arrays.asList(this.orderList.split(","));
	    }
	    
	    public Map<String, Object> getGwtMetadata(){
	    	Map<String, Object> meta=new HashMap<String, Object>();
	    	Map<String, Object> result=new HashMap<String, Object>();
	    	try{
		    	error=0;
		    	str=new StringBuilder();
		    	result.put("description",this.inq.getCurrentDbRecord().getDescription());
		    	result.put("searchList",this.getGwtSearchList());
		    	result.put("orderList",this.getGwtOrderList());
		    	result.put("showList", this.getGwtShowList());
		    	result.put("tagConSearch", this.getGwtConditionSearch());
		    	result.put("tagSearchBy",this.getGwtSearchBy());
		    	result.put("tagOrder", this.getGwtOrderBy());
		    	result.put("metaData",this.getGwtHeaderTitle());
		    	
	    	}catch(Exception ex){
	    		str.append("Can 't get getGwtHeaderTitle\n");
	    		error++;
	    	}
	    	meta.put("success",Boolean.valueOf(error==0));
	    	meta.put("message",str.toString());
	    	meta.put("result",result);
	    	return meta;
	    }
	    
	    
	    public int getInitrecord() {
			return initrecord;
		}

		public void setInitrecord(int initrecord) {
			this.initrecord = initrecord;
		}

		protected void setPeriodRows(){
	        int endRow=initrecord+maxLine;
	        inq.setBetween(initrecord, endRow);
	        inq.clearOldCondition();
	    }  

		public void setPeriodRows(int initrow){
	        int endRow=initrow+maxLine;
	        inq.setBetween(initrow, endRow);
	        inq.clearOldCondition();
	    } 		
		
		public Map<String, Object> getGwtData(int initRow) {
			Map<String, Object> data= new HashMap<String, Object>();
			Map<String, Serializable> result= new HashMap<String, Serializable>();
			ArrayList<Map<String, Object>> record= new ArrayList<Map <String,Object>>();
			String error="";
	        try {
	            this.setPeriodRows(initRow);
	            inq.first();
	            if(inq.recCount()>0){
	            String showdata[];
	            String tmp1,tmp2,returnValue,tmpValue="";
				returnValue = "";
	            Map<String, Object>mp = new HashMap<String, Object>();
	            try{
		            while (inq.next()){
		            		mp = new HashMap<String, Object>();
		            		showdata=this.showList.split(",");
		            		for(int i=0;i<showdata.length;i++){
			                    tmp1 = showdata[i];
			                    tmp2 = tmp1.substring(tmp1.indexOf(".") + 1);
			                    tmp1 = tmp1.substring(0, tmp1.indexOf("."));
			                    tmpValue = this.getStringfm(tmp1, tmp2, "value", false);
			                    if(i==0)
			                    	returnValue = this.returnHelp(tmp1);
		                        mp.put(tmp2,tmpValue);
		                    }
		            			mp.put("returnValue",returnValue);
		            			record.add(mp);
		                }
	            }catch(Exception ex){
	            	error=ex.getMessage();
	            }	            
	            result.put("totalCount",this.recordCount);
	            result.put("limit",this.maxLine);
	            result.put("offset",this.initrecord);
	            result.put("records",record);
	            data.put("result",result);
	            data.put("message",error);
	            data.put("success",error.trim().length()==0);
	           }
	        }catch (Exception e) {
				MyLog.error(this, this.getUProfile(), e);
	       }
	        return data;
	    }		
	    
}