Project

General

Profile

Bug #2442 » VegbankRequestAccessionCodeTag.java

Michael Lee, 06/02/2006 09:38 AM

 
1
/*
2
 *	'$RCSfile: VegbankUpdateTag.java,v $'
3
 *	Authors: @author@
4
 *	Release: @release@
5
 *
6
 *	'$Author: mlee $'
7
 *	'$Date: 2005/09/16 00:53:31 $'
8
 *	'$Revision: 1.3 $'
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
 */
24

    
25
package org.vegbank.ui.struts.taglib;
26

    
27

    
28
import java.lang.reflect.InvocationTargetException;
29
import java.util.Locale;
30
import java.util.Map;
31
import java.util.*;
32
import java.text.SimpleDateFormat;
33
import java.math.BigDecimal;
34
import java.math.BigInteger;
35
import java.text.Format;
36

    
37
import java.text.DecimalFormat;
38
import java.text.NumberFormat;
39
import javax.servlet.jsp.JspException;
40
import javax.servlet.jsp.PageContext;
41
import javax.servlet.jsp.tagext.TagSupport;
42
import javax.servlet.http.HttpServletRequest;
43

    
44
import org.apache.commons.logging.Log;
45
import org.apache.commons.logging.LogFactory;
46
import org.apache.commons.beanutils.PropertyUtils;
47
import org.apache.struts.util.MessageResources;
48
import org.apache.struts.util.RequestUtils;
49
import org.apache.struts.util.ResponseUtils;
50
import org.apache.struts.taglib.bean.WriteTag;
51

    
52
import org.vegbank.common.Constants;
53
import org.vegbank.common.command.GenericCommand;
54
import org.vegbank.common.utility.Utility;
55
import org.vegbank.common.utility.ServletUtility;
56
import org.vegbank.ui.struts.VegbankAction;
57
import org.vegbank.common.utility.DatabaseAccess;
58
import org.vegbank.common.utility.DatabaseUtility;
59

    
60
/**
61
 * Tag that asks the database to reserve new accession codes for client databases
62
 *    (i.e. VegBranch, Carolina Veg Survey, etc.)
63
 *
64
 *
65
 * @author M. Lee
66
 * @version $Revision: 1.3 $ $Date: 2005/09/16 00:53:31 $
67
 */
68

    
69
public class VegbankRequestAccessionCodeTag extends VegbankTag {
70

    
71
	private static final Log log = LogFactory.getLog(VegbankRequestAccessionCodeTag.class);
72
	//private static final String DATABASE_ACCESSION_KEY_PREASSIGN = Utility.DATABASE_ACCESSION_KEY_PREASSIGN;
73
	public static final String AUTH_CUSTOM = "custom";
74
    private static ResourceBundle tblabbreviations =
75
			ResourceBundle.getBundle("accession");
76

    
77
    /**
78
     * Process the start tag.
79
     *
80
     * @exception JspException if a JSP exception has occurred
81
     */
82
    public int doStartTag() throws JspException {
83

    
84

    
85
		HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
86

    
87
		try {
88
           // TLD Does all this:
89
//		    if (Utility.isStringNullOrEmpty(getTable())) { log.error("Attribute 'table' is required"); return SKIP_BODY;}
90
			//if (Utility.isArrayNullOrEmpty(getFieldNamesArray())) { log.error("Attribute 'fieldNames' is required"); return SKIP_BODY;}
91
//			if (Utility.isStringNullOrEmpty(getRecordcount())) { log.error("Attribute 'recordcount' is required"); return SKIP_BODY;}
92
//			if (Utility.isStringNullOrEmpty(getRequestkey())) { log.error("Attribute 'requestkey' is required"); return SKIP_BODY;}
93
          //  String authScheme =  getAuth();
94
		  //	if (Utility.isStringNullOrEmpty(authScheme)) { authScheme = AUTH_USR_ID; }
95

    
96
            // instantiate this entity
97
            //Utility.createObject("org.vegbank.common.model." +
98
            //       Utility.upperCaseFirstLetter(entity.toLowerCase()));
99
		//	Class entityClass = Class.forName("org.vegbank.common.model." +
100
        //            Utility.upperCaseFirstLetter(entity.toLowerCase()));
101
        //    String pkName = (String)entityClass.getField("PKNAME").get(null);
102
        //    String tableName = entity;
103

    
104

    
105
            //the database key
106
            String dbKey = Utility.DATABASE_ACCESSION_KEY_PREASSIGN;
107
            //the table:
108
            log.debug("getting table abbreviations");
109
			String tableAbbrev = tblabbreviations.getString("abbr." + getTable());
110

    
111
            String reqkey = getRequestkey();
112
            int reccount = Integer.parseInt(getRecordcount());
113

    
114
              // build INSERT sql
115
			  StringBuffer sql = new StringBuffer(128);
116
			  //  StringBuffer selectsql = new StringBuffer(128);
117
			  //get main clause from SQLStore
118
			  sql.append("INSERT INTO dba_test ( dba_testrequestacc_id, databasekey, tableabbrev) ");
119
              sql.append(" values ('").append(reqkey).append("','").append(dbKey).append("','").append(tableAbbrev).append("')");
120

    
121
              log.debug("asking for accession codes via " + sql.toString());
122
              log.debug("asking for accession codes how many times: " + reccount);
123
           DatabaseAccess da = new DatabaseAccess();
124
          for (int i=0; i< reccount; i++) {
125
               da.issueUpdate(DatabaseUtility.removeSemicolons(sql.toString()));
126
		   }
127
		   log.debug("compiling accession codes");
128
		   da.issueUpdate("UPDATE dba_test SET accessionCode = databasekey || '.' || tableabbrev || '.' || dba_test_id || '.' || confirmcode  WHERE accessionCode is null");
129

    
130
           log.debug("finished with inserting new accessionCodes");
131
		} catch (Exception ex) {
132
			log.error("Error while running <vegbank:requestaccessioncode> ", ex);
133
		}
134

    
135

    
136
        return SKIP_BODY;
137
    }
138

    
139
    /**
140
	 *
141
     */
142
  	 protected String table;
143

    
144
      public String getTable() {
145
          return findAttribute("table", this.table);
146
      }
147

    
148
      public void setTable(String t) {
149
          this.table = t;
150
    }
151

    
152
    /**
153
	 *
154
     */
155
  	 protected String requestkey;
156

    
157
      public String getRequestkey() {
158
          return findAttribute("requestkey", this.requestkey);
159
      }
160

    
161
      public void setRequestkey(String rk) {
162
          this.requestkey = rk;
163
    }
164

    
165
 /**
166
	 *
167
     */
168
  	 protected String recordcount;
169

    
170
      public String getRecordcount() {
171
          return findAttribute("recordcount", this.recordcount);
172
      }
173

    
174
      public void setRecordcount(String r) {
175
          this.recordcount = r;
176
    }
177

    
178

    
179

    
180

    
181

    
182

    
183
}
(1-1/3)