001 /*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016 package org.opengion.hayabusa.report;
017
018 import java.util.HashMap;
019 import java.util.Map;
020
021 import org.opengion.fukurou.db.DBUtil;
022 import org.opengion.fukurou.util.ApplicationInfo;
023 import org.opengion.fukurou.util.StringUtil;
024 import org.opengion.hayabusa.common.HybsSystem;
025 import org.opengion.hayabusa.db.DBTableModel;
026 import org.opengion.hayabusa.report2.QueueManager_DB.DBTableModelCreator;
027 import org.opengion.hayabusa.resource.ResourceFactory;
028 import org.opengion.hayabusa.resource.ResourceManager;
029
030 /**
031 * DBTableModelオブジェクトをレポ?ト形式に返還するタグリブクラスです?
032 * こ?オブジェクトに???タ(DBTableModel)と、コントローラ(DBTableReport クラス)を与えて?
033 * 外部からコントロールすることで、各種形式で ??タ(DBTableModel)を表示させること?
034 * 可能です?
035 *
036 * @og.group 帳票シス?
037 *
038 * @version 4.0
039 * @author Hiroki Nakamura
040 * @since JDK5.0,
041 */
042 public class RFIDPrintRequest {
043
044 private static final String CR = HybsSystem.CR ;
045
046 private final StringBuilder errMsg = new StringBuilder();
047
048 // DBTableModel に対して設定する情報
049 // private DBTableModel table = null; // 4.3.1.1 (2008/08/23) ローカル変数?
050 private ResourceManager resource = null;
051
052 // 受け渡し変数
053 private final String SYSTEM_ID ;
054 private final String YKNO ;
055 private final String LISTID ;
056 private final String LANG ;
057 private final String FGRUN ;
058 private final String PRTID ;
059 private final String PRGDIR ; // 4.3.3.0 (2008/10/01) 板金RFID対応で追?
060 private final String PRGFILE ; // 4.3.3.0 (2008/10/01) 追?
061 private final String OUTDIR ; // 4.3.3.0 (2008/10/01) 追?
062 private final boolean DEBUG ;
063 private final String FILENAME ; // 5.4.3.9 (2012/01/25)
064
065 // オブジェクト変数
066 // private String bSQL = null; // 5.5.2.4 (2012/05/16) ?の消し忘れ?
067 private boolean fgLOCAL = false;
068 private String prtName = null;
069 private String hostName = null;
070 private String portnm = null;
071 private String fgkan = GE50Access.FG_ERR2; // 4.3.3.0 (2008/10/01) 初期値エラー
072 private final Map<String,String[]> rfidLayout = new HashMap<String,String[]>();
073
074 // GE54 の帳票定義??を取得するSQL?す?
075 private static final String GE54_SELECT =
076 "SELECT BSQL,FGLOCAL,SYSTEM_ID" +
077 " FROM GE54" +
078 " WHERE FGJ = '1'" +
079 " AND SYSTEM_ID IN (?,'**')" +
080 " AND LISTID = ?" ;
081 // private static final int GE54_BSQL = 0;
082 private static final int GE54_FGLOCAL = 1;
083 private static final int GE54_SYSTEM_ID = 2;
084
085 // 5.4.4.0 (2012/02/01) 互換モード対応漏れ
086 private static final String HOST = HybsSystem.sysBool( "VER4_COMPATIBLE_MODE" ) ? "HOST" : "HOST_ID";
087
088 // GE55 の出力?マスタ??を取得するSQL?す?
089 // 5.1.0.0 (2009/11/04) HOST ?HOST_ID
090 // 5.4.3.1 (2011/12/27) PORTNM
091 // 5.4.4.0 (2012/02/01) 互換モー?
092 private static final String GE55_SELECT =
093 "SELECT PRTNM,"+HOST+",SYSTEM_ID,PORTNM" +
094 " FROM GE55" +
095 " WHERE FGJ = '1'" +
096 " AND SYSTEM_ID IN (?,'**')" +
097 " AND PRTID = ?" ;
098 private static final int GE55_PRTNM = 0;
099 private static final int GE55_HOST_ID = 1;
100 private static final int GE55_SYSTEM_ID = 2;
101 private static final int GE55_PORTNM = 3;
102
103 // 5.2.0.0 (2010/09/01) Ver4互換モード対?
104 private static final String CLM = HybsSystem.sysBool( "VER4_COMPATIBLE_MODE" ) ? "COLUMN_NAME" : "CLM";
105
106 // GE58 の帳票レイアウトテーブルを取得するSQL?す?
107 // 5.2.0.0 (2010/09/01) Ver4互換モード対?
108 private static final String GE58_SELECT =
109 "SELECT KBOUT,DATA1,DATA2,DATA3,DATA4,DATA5,DATA6,DATA7,DATA8" +
110 " ,DATA9,DATA10,DATA11,DATA12,DATA13,DATA14,DATA15,"+CLM +
111 " FROM GE58 WHERE SYSTEM_ID IN (?,'**')" +
112 " AND LISTID = ?";
113 public static final int GE58_KBOUT = 0;
114 public static final int GE58_DATA1 = 1;
115 public static final int GE58_DATA2 = 2;
116 public static final int GE58_DATA3 = 3;
117 public static final int GE58_DATA4 = 4;
118 public static final int GE58_DATA5 = 5;
119 public static final int GE58_DATA6 = 6;
120 public static final int GE58_DATA7 = 7;
121 public static final int GE58_DATA8 = 8;
122 public static final int GE58_DATA9 = 9;
123 public static final int GE58_DATA10 = 10;
124 public static final int GE58_DATA11 = 11;
125 public static final int GE58_DATA12 = 12;
126 public static final int GE58_DATA13 = 13;
127 public static final int GE58_DATA14 = 14;
128 public static final int GE58_DATA15 = 15;
129 public static final int GE58_CLM_NAME = 16;
130
131 // コネクションにアプリケーション??を追記するかど???
132 public static final boolean USE_DB_APPLICATION_INFO = HybsSystem.sysBool( "USE_DB_APPLICATION_INFO" ) ;
133 private final ApplicationInfo appInfo;
134 private final String DBID = HybsSystem.sys( "RESOURCE_DBID" ); // 5.5.5.1 (2012/08/07) リソース系DBID 付け忘れ対?
135
136 /**
137 * コンストラクター
138 * 引数を受けとって、インスタンスを作?します?
139 * @param systemId シス?ID
140 * @param ykno 要求番号
141 * @param listId 帳票ID
142 * @param lang ??
143 * @param fgrun 実行方?
144 * @param prtid プリンタID
145 * @param prgdir プログラ?ィレクトリ
146 * @param prgfile プログラ?ァイル
147 * @param outdir 出力ディレクトリ
148 * @param layoutFile レイアウトファイル
149 * @param isDebug ??フラグ
150 *
151 * @og.rev 4.3.3.0 (2008/10/01) 板?RFID対応?引数にprgdir,prgfile,outdir追?
152 * @og.rev 5.4.3.1 (2011/12/27) portnm追?
153 * @og.rev 5.4.3.9 (2012/01/25) 雛形ファイル名追?
154 *
155 */
156 public RFIDPrintRequest( final String systemId, final String ykno
157 , final String listId, final String lang, final String fgrun, final String prtid
158 , final String prgdir, final String prgfile, final String outdir , final String layoutFile, final boolean isDebug ) {
159 SYSTEM_ID = systemId;
160 YKNO = ykno;
161 LISTID = listId;
162 LANG = lang;
163 FGRUN = fgrun;
164 PRTID = prtid;
165 PRGDIR = prgdir; // 4.3.3.0 (2008/10/01)
166 PRGFILE = prgfile; // 4.3.3.0 (2008/10/01)
167 OUTDIR = outdir; // 4.3.3.0 (2008/10/01)
168 DEBUG = isDebug;
169 FILENAME = layoutFile; // 5.4.3.9 (2012/01/25)
170
171 // アクセスログ取得?為,ApplicationInfoオブジェクトを設?
172 if( USE_DB_APPLICATION_INFO ) {
173 appInfo = new ApplicationInfo();
174 // ユーザーID,IPアドレス,ホスト名
175 appInfo.setClientInfo( SYSTEM_ID,HybsSystem.HOST_ADRS,HybsSystem.HOST_NAME );
176 // 画面ID,操?プログラ?D
177 appInfo.setModuleInfo( "ReportConverter",YKNO,LISTID );
178 }
179 else {
180 appInfo = null;
181 }
182 }
183
184 /**
185 * 初期??タセ?を行います?
186 * ここでは、GE54,GE58,GE55 ??ブルより?な??を取得します?
187 *
188 * @og.rev 4.3.3.0 (2008/10/01) 板?RFID対?PRGDIR,PRGFILE追??
189 * @og.rev 5.4.3.0 (2011/12/26) GE54のbSQLは取らな??する
190 * @og.rev 5.4.3.9 (2012/01/25) GE58はなくてもよ?
191 * @og.rev 5.5.5.1 (2012/08/07) リソース系DBID 付け忘れ対?
192 *
193 * @return 結果 [true:正常/false:異常]
194 */
195 public boolean initialDataSet() {
196
197 // ===== GE54 から帳票定義??を取得しま?=========================================
198 String[] args = new String[] { SYSTEM_ID,LISTID };
199 // String[][] vals = DBUtil.dbExecute( GE54_SELECT,args,appInfo );
200 String[][] vals = DBUtil.dbExecute( GE54_SELECT,args,appInfo, DBID ); // 5.5.5.1 (2012/08/07)
201 if( vals == null || vals.length == 0 ) {
202 errMsg.append( "Data does not exist in GE54 table." ).append( CR );
203 errMsg.append( "==============================" ).append( CR );
204 errMsg.append( "SYSTEM_ID=[" ).append( SYSTEM_ID ).append( "] , " );
205 errMsg.append( "LISTID=[" ).append( LISTID ).append( "]" );
206 errMsg.append( CR );
207 return false;
208 }
209
210 // 検索結果が?帰ったとき?SYSTEM_ID ??されて?方の??タ(?を採用する?
211 int row = 0;
212 for( int i=0; i<vals.length; i++ ) {
213 if( SYSTEM_ID.equalsIgnoreCase( vals[i][GE54_SYSTEM_ID] ) ) { row = i; break; }
214 }
215
216 // 4.5.3.0 GE54のbSQLは?となって?ので下方で別で取る
217 // bSQL = StringUtil.nval( vals[row][GE54_BSQL],bSQL );
218 // if( bSQL == null || bSQL.length() == 0 ) {
219 // errMsg.append( "Body SQL Columns does not exist in GE54 table." ).append( CR );
220 // errMsg.append( "==============================" ).append( CR );
221 // errMsg.append( "SYSTEM_ID=[" ).append( SYSTEM_ID ).append( "] , " );
222 // errMsg.append( "LISTID=[" ).append( LISTID ).append( "] " );
223 // errMsg.append( CR );
224 // return false;
225 // }
226
227 // ローカルリソースフラグ
228 // 4.3.3.0 (2008/10/01)
229 // fgLOCAL = ( vals[row][GE54_FGLOCAL] != null && vals[row][GE54_FGLOCAL].trim().equals( "1" ) ) ? true : false ;
230 String localFlag = vals[row][GE54_FGLOCAL];
231 fgLOCAL = ( localFlag != null && "1".equals( localFlag.trim() )) ? true : false ;
232
233 // ===== GE58 から帳票定義??を取得しま?=========================================
234 String[] argsGe58 = new String[] { SYSTEM_ID,LISTID };
235 // String[][] valsGe58 = DBUtil.dbExecute( GE58_SELECT,argsGe58,appInfo );
236 String[][] valsGe58 = DBUtil.dbExecute( GE58_SELECT,argsGe58,appInfo, DBID ); // 5.5.5.1 (2012/08/07)
237 // 5.4.3.9 (2012/01/25) GE58はなくてもよ?
238 // if( valsGe58 == null || valsGe58.length == 0 ) {
239 // errMsg.append( "Data does not exist in GE58 table." ).append( CR );
240 // errMsg.append( "==============================" ).append( CR );
241 // errMsg.append( "SYSTEM_ID=[" ).append( SYSTEM_ID ).append( "] , " );
242 // errMsg.append( "LISTID=[" ).append( LISTID ).append( "]" );
243 // errMsg.append( CR );
244 // return false;
245 // }
246
247 for( int i=0; i<valsGe58.length; i++ ) {
248 rfidLayout.put( valsGe58[i][GE58_CLM_NAME], valsGe58[i] );
249 }
250
251 // ===== GE55 から出力?マスタ??を取得しま?=========================================
252 String[] argsGe55 = new String[] { SYSTEM_ID,PRTID };
253 // String[][] valsGe55 = DBUtil.dbExecute( GE55_SELECT,argsGe55,appInfo );
254 String[][] valsGe55 = DBUtil.dbExecute( GE55_SELECT,argsGe55,appInfo, DBID ); // 5.5.5.1 (2012/08/07)
255 if( valsGe55 == null || valsGe55.length == 0 ) {
256 errMsg.append( "Data does not exist in GE55 table." ).append( CR );
257 errMsg.append( "==============================" ).append( CR );
258 errMsg.append( "SYSTEM_ID=[" ).append( SYSTEM_ID ).append( "] , " );
259 errMsg.append( "PRTID=[" ).append( PRTID ).append( "]" );
260 errMsg.append( CR );
261 return false;
262 }
263
264 // 検索結果が?帰ったとき?SYSTEM_ID ??されて?方の??タ(?を採用する?
265 int rowGe55 = 0;
266 for( int i=0; i<vals.length; i++ ) {
267 if( SYSTEM_ID.equalsIgnoreCase( vals[i][GE55_SYSTEM_ID] ) ) { rowGe55 = i; break; }
268 }
269
270 prtName = valsGe55[rowGe55][GE55_PRTNM];
271 hostName = valsGe55[rowGe55][GE55_HOST_ID];
272 portnm = valsGe55[rowGe55][GE55_PORTNM];
273
274 return true;
275 }
276
277 /**
278 * RFID発行用??タを作?し?発行リクエスト?処?行います?
279 *
280 * @og.rev 5.4.3.0 (2011/12/26) _DEFAULT対?
281 * @og.rev 5.4.3.4 (2012/01/12) listid追?
282 * @og.rev 5.4.3.9 (2012/01/25) FILENAME追?
283 *
284 * @return 結果 [true:正常/false:異常]
285 */
286 public boolean execute() {
287 System.out.print( "RRID RequestData Creating ... " );
288
289 // FGLOCAL ?時は、SYSTEM_ID を指定してリソース作?
290 if( fgLOCAL ) {
291 // ローカルリソース?時は、SYSTEM_ID,LANG を使用します?先読みは、使用しません?
292 resource = ResourceFactory.newInstance( SYSTEM_ID,LANG,false );
293 }
294 else {
295 // 従来と互換性のあるモー?ローカルリソースは使用しな??
296 resource = ResourceFactory.newInstance( LANG );
297 }
298
299 // String[] where = new String[] { SYSTEM_ID , YKNO } ; // 5.5.2.4 (2012/05/16) 削除のし忘れ
300
301 // ボディー??の取?
302 // table = DBTableModelUtil.makeDBTable( bSQL, where, resource ,appInfo );
303 // DBTableModel table = DBTableModelUtil.makeDBTable( bSQL, where, resource ,appInfo );
304 // 5.2.3.0 tableのとり方変更
305 DBTableModelCreator tmc = new DBTableModelCreator( SYSTEM_ID, LISTID, YKNO, "B", resource );
306 DBTableModel table = tmc.getTable();
307 if( table.getRowCount() <= 0 ) {
308 errMsg.append( "Database Body row count is Zero." ).append( CR );
309 errMsg.append( "==============================" ).append( CR );
310 // 5.5.2.4 (2012/05/16) ?の消し忘れ?
311 // errMsg.append( bSQL );
312 errMsg.append( "SYSTEM_ID=" ).append( SYSTEM_ID );
313 errMsg.append( ",LISTID=" ).append( LISTID );
314 errMsg.append( ",YKNO=" ).append( YKNO );
315 errMsg.append( CR );
316 return false;
317 }
318 // 検索時??件数での打ち?をエラーとする?
319 if( table.isOverflow() ) {
320 errMsg.append( "Database is Overflow. [" );
321 errMsg.append( table.getRowCount() );
322 errMsg.append( "]" ).append( CR ).append( CR );
323 errMsg.append( "==============================" ).append( CR );
324 errMsg.append( "Check SystemParameter Data in DB_MAX_ROW_COUNT Overflow" );
325 errMsg.append( CR );
326 return false;
327 }
328
329 // RFID発行用クラスを実行する?
330 RFIDPrintPointService service = null;
331 try {
332 service = (RFIDPrintPointService)StringUtil.newInstance( HybsSystem.sys( "REPORT_RFID_SERVICE_CLASS" ) );
333 service.setYkno( YKNO );
334 service.setSystemId( SYSTEM_ID );
335 service.setFgrun( FGRUN );
336 service.setHostName( hostName );
337 service.setPrinterName( prtName );
338 service.setTable( table );
339 service.setLayout( rfidLayout );
340 service.setPrgDir( PRGDIR ); // 4.3.3.0 (2008/10/01) 板?RFID対?
341 service.setPrgFile( PRGFILE ); // 4.3.3.0 (2008/10/01)
342 service.setOutDir( OUTDIR ); // 4.3.3.0 (2008/10/01)
343 service.setPrtId( PRTID ); // 5.4.3.0 (2011/12/26)
344 service.setPortnm( portnm ); // 5.4.3.1 (2011/12/27)
345 service.setListId( LISTID ); // 5.4.3.4 (2012/01/12)
346 service.setLayoutFile( FILENAME ); // 5.4.3.9 (2012/01/25)
347
348 // service.execute();
349 boolean flag = service.execute(); // 4.3.3.0 (2008/10/01) booleanを返す
350
351 fgkan = service.getFgkan(); // 4.3.3.0 (2008/10/01) FGKANを受け取るよ?する
352
353 if( DEBUG ) {
354 System.out.println( service );
355 }
356
357 if( ! flag ){ // 4.3.3.0 (2008/10/01)
358 errMsg.append( service.getErrMsg() );
359 return false;
360 }
361 }
362 catch ( Throwable ex ) {
363 fgkan = GE50Access.FG_ERR2; // 4.3.3.0 (2008/10/01) エラー時?アプリエラーにしておく
364 errMsg.append( "RFID Print Request Execution Error. " ).append( CR );
365 errMsg.append( "==============================" ).append( CR );
366 errMsg.append( "SYSTEM_ID=[" ).append( SYSTEM_ID ).append( "] , " );
367 errMsg.append( "YKNO=[" ).append( YKNO ).append( "]" ).append( CR );
368 errMsg.append( HybsSystem.sys( "REPORT_RFID_SERVICE_CLASS" ) ).append( CR );
369 errMsg.append( ex.toString() );
370 errMsg.append( CR );
371 // errMsg.append( service.getErrMsg() );
372 if( service != null ) { errMsg.append( service.getErrMsg() ); } // 5.5.2.6 (2012/05/25) findbugs対?
373 return false;
374 }
375
376 System.out.println( "End." );
377 return true ;
378 }
379
380 /**
381 * エラーが存在した場合に、エラーメ?ージを返します?
382 *
383 * @return エラーメ?ージ String
384 */
385 public String getErrMsg() {
386 return errMsg.toString();
387 }
388
389 /**
390 * 完?ラグを返します?
391 *
392 * @og.rev 4.3.3.0 (2008/10/01) 板金RFID メソ?追?
393 *
394 * @return 完?ラグ String
395 */
396 public String getFgkan() {
397 return fgkan;
398 }
399 }