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 */ 016package org.opengion.hayabusa.report2; 017 018import java.io.File; 019 020import org.opengion.hayabusa.db.DBTableModel; 021 022/** 023 * 帳票処理要求を管理するキューオブジェクトです。 024 * このオブジェクトでは、帳票の定義及びデータと、処理中に発生したエラーメッセージを管理します。 025 * また、このキューを生成したオブジェクトもこのオブジェクトにセットされます。 026 * 027 * @og.group 帳票システム 028 * 029 * @version 4.0 030 * @author Hiroki.Nakamura 031 * @since JDK1.6 032 */ 033public class ExecQueue { 034 035 /** 実行方法 {@value} */ 036 protected static final String OUT_ODS_ONLY = "1"; 037 /** 実行方法 {@value} */ 038 protected static final String OUT_PRINT_ONLY = "2"; 039 /** 実行方法 {@value} */ 040 protected static final String OUT_ODS_PRINT = "3"; 041 /** 実行方法 {@value} */ 042 protected static final String OUT_ODS_PDF = "P"; 043 /** 実行方法 {@value} */ 044 protected static final String OUT_ODS_PRINT_PDF = "Q"; 045 /** 実行方法 {@value} */ 046 protected static final String OUT_ODS_EXCEL = "E"; 047 /** 実行方法 {@value} */ 048 protected static final String OUT_ODS_ODS = "S"; // 4.3.3.4 (2008/11/01) 追加 049 /** 実行方法 {@value} */ 050 protected static final String IN_INPUT_ONLY = "5"; 051 /** 実行方法 {@value} */ 052 protected static final String IN_EXEC_ONLY = "6"; 053 /** 実行方法 {@value} */ 054 protected static final String IN_INPUT_EXEC = "7"; 055 /** 実行方法 {@value} */ 056 protected static final String RFID_PRINT = "A"; 057 /** 実行方法 {@value} */ 058 protected static final String RFID_ALLPRINT = "B"; 059 /** 実行方法 {@value} */ 060 protected static final String RFID_ALLERASE = "C"; 061 /** 実行方法 {@value} */ 062 protected static final String RFID_SEQERASE = "D"; 063 064 // 5.9.0.0 (2015/09/04) CSV出力対応 065 /** 実行方法 {@value} */ 066 protected static final String CSV_PRINT = "G"; 067 /** 実行方法 {@value} */ 068 protected static final String CSV_PRINT_EXCEL = "H"; 069 /** 実行方法 {@value} */ 070 protected static final String CSV_PRINT_PDF = "I"; 071 072 /** 最大シート数 {@value} */ 073 protected static final int MAX_SHEETS_PER_FILE = 256; // 5.1.2.0 (2010/01/01) 074 075 private String ykno = null; 076 private String systemId = null; 077 private DBTableModel body = null; 078 private DBTableModel header = null; 079 private DBTableModel footer = null; 080 private String listId = null; 081 private String pdfPasswd = null; 082 private String lang = null; 083 private String threadId = null; 084 private String templateName = null; 085 private String outputType = null; 086 private String printerName = null; 087 private String outputName = null; 088 private boolean fglocal = false; 089 private boolean fgcut = false; 090 private QueueManager manager = null; 091 private String prgdir = null; // 4.3.3.0 (2008/10/01) 板金RFID対応。 092 private String prgfile = null; // 4.3.3.0 (2008/10/01) 093 private String prtid = null; // 4.3.3.0 (2008/10/01) 094 095 private int pageCnt = 0; // 5.1.2.0 (2010/01/01) 処理したページ数 096 private int rowCnt = 0; // 5.1.2.0 (2010/01/01) 処理した行数 097 private boolean isDataEnd = false; // 5.1.2.0 (2010/01/01) 全データが処理されたか (メソッド名と同じ変数名変更) 098 099 private boolean useSheetName = false; // 5.7.6.2 (2014/05/16) PAGEBREAKカラムの値を、シート名として使うかどうか。 100 101 private final StringBuilder errMsg = new StringBuilder(); 102 103 /** 104 * 要求NOをセットします。 105 * 106 * @param ykno 要求NO 107 */ 108 public void setYkno( final String ykno ) { 109 this.ykno = ykno; 110 } 111 112 /** 113 * 要求NOを取得します。 114 * 115 * @return 要求NO 116 */ 117 public String getYkno() { 118 return ykno; 119 } 120 121 /** 122 * システムIDをセットします。 123 * 124 * @param systemId システムID 125 */ 126 public void setSystemId( final String systemId ) { 127 this.systemId = systemId; 128 } 129 130 /** 131 * システムIDを取得します。 132 * 133 * @return StringシステムID 134 */ 135 public String getSystemId() { 136 return systemId; 137 } 138 139 /** 140 * ボディー部分のDBTableModelをセットします。 141 * 142 * @param body DBTableModelオブジェクト 143 */ 144 public void setBody( final DBTableModel body ) { 145 this.body = body; 146 } 147 148 /** 149 * ボディー部分のDBTableModelを取得します。 150 * 151 * @return ボディー部分のDBTableModelオブジェクト 152 */ 153 public DBTableModel getBody() { 154 return body; 155 } 156 157 /** 158 * ヘッダー部分のDBTableModelをセットします。 159 * 160 * @param header DBTableModelオブジェクト 161 */ 162 public void setHeader( final DBTableModel header ) { 163 this.header = header; 164 } 165 166 /** 167 * ヘッダー部分のDBTableModelを取得します。 168 * 169 * @return ヘッダー部分のDBTableModelオブジェクト 170 */ 171 public DBTableModel getHeader() { 172 return header; 173 } 174 175 /** 176 * フッター部分のDBTableModelをセットします。 177 * 178 * @param footer DBTableModelオブジェクト 179 */ 180 public void setFooter( final DBTableModel footer ) { 181 this.footer = footer; 182 } 183 184 /** 185 * フッター部分のDBTableModelを取得します。 186 * 187 * @return フッター部分のDBTableModelオブジェクト 188 */ 189 public DBTableModel getFooter() { 190 return footer; 191 } 192 193 /** 194 * 帳票IDをセットします。 195 * 196 * @param listId 帳票ID 197 */ 198 public void setListId( final String listId ) { 199 this.listId = listId; 200 } 201 202 /** 203 * 帳票IDを取得します。 204 * 205 * @return 帳票ID 206 */ 207 public String getListId() { 208 return listId; 209 } 210 211 /** 212 * PDFパスワードをセットします。 213 * 214 * @param pdfPasswd PDFパスワード 215 */ 216 public void setPdfPasswd( final String pdfPasswd ) { 217 this.pdfPasswd = pdfPasswd; 218 } 219 220 /** 221 * PDFパスワードを取得します。 222 * 223 * @return PDFパスワード 224 */ 225 public String getPdfPasswd() { 226 return pdfPasswd; 227 } 228 229 /** 230 * 言語をセットします。 231 * 232 * @param lang 言語 233 */ 234 public void setLang( final String lang ) { 235 this.lang = lang; 236 } 237 238 /** 239 * 言語を取得します。 240 * 241 * @return 言語 242 */ 243 public String getLang() { 244 return lang; 245 } 246 247 /** 248 * 雛形ファイル名をセットします。 249 * 250 * @param templateName 雛形ファイル名 251 */ 252 public void setTemplateName( final String templateName ) { 253 this.templateName = templateName; 254 } 255 256 /** 257 * 雛形ファイル名を取得します。 258 * 259 * @return 帳票雛形ファイル名 260 */ 261 public String getTemplateName() { 262 return templateName; 263 } 264 265 /** 266 * 実行方法をセットします。 267 * 268 * @param outputType 実行方法 269 */ 270 public void setOutputType( final String outputType ) { 271 this.outputType = outputType; 272 } 273 274 /** 275 * 出力タイプを取得します。 276 * 277 * @return 出力タイプ 278 */ 279 public String getOutputType() { 280 return outputType; 281 } 282 283 /** 284 * プリンター名をセットします。 285 * 286 * @param printerName プリンター名 287 */ 288 public void setPrinterName( final String printerName ) { 289 this.printerName = printerName; 290 } 291 292 /** 293 * プリンター名を取得します。 294 * 295 * @return プリンタ名 296 */ 297 public String getPrinterName() { 298 return printerName; 299 } 300 301 /** 302 * 処理要求を処理するスレッドIDをセットします。 303 * 304 * @param threadId スレッドID 305 */ 306 public void setThreadId( final String threadId ) { 307 this.threadId = threadId; 308 } 309 310 /** 311 * 処理要求を処理するスレッドIDを取得します。 312 * 313 * @return スレッドID 314 */ 315 public String getThreadId() { 316 return threadId; 317 } 318 319 /** 320 * 出力ファイル名をセットします。 321 * 322 * @param outputName 出力ファイル名 323 */ 324 public void setOutputName( final String outputName ) { 325 this.outputName = outputName; 326 } 327 328 /** 329 * 出力ファイル名を設定します。 330 * GE50に設定されていない場合は第四引数(要求番号)を利用する。 331 * その場合、タイプに応じた拡張子が自動設定される。 332 * 333 * ".xls" : OUT_ODS_EXCEL 334 * ".pdf" : OUT_ODS_PDF , OUT_ODS_PRINT_PDF 335 * ".ods" : OUT_ODS_ODS 336 * ".xml" : RFID_PRINT , RFID_ALLPRINT , RFID_ALLERASE , RFID_SEQERASE 337 * ".csV" : CSV_PINT , CSV_PRINT_EXCEL , CSV_PRINT_PDF 338 * 339 * @og.rev 4.3.3.4 (2008/11/01) ODS出力対応 340 * @og.rev 5.4.3.0 (2011/12/26) RFIDデフォルト対応 341 * @og.rev 5.4.4.1 (2012/02/03) RFID拡張子変更 342 * @og.rev 5.9.0.0 (2015/09/04) CSV対応 343 * 344 * @param outputDir 出力ディレクトリ名 345 * @param outputFile 出力ファイル名 346 * @param type タイプ 347 * @param yokyu 要求番号(ファイル名が指定されていない場合のファイル名) 348 * 349 */ 350 public void setOutputName( final String outputDir, final String outputFile, final String type, final String yokyu ){ 351 StringBuilder filePath = new StringBuilder(); 352 filePath.append( outputDir + File.separator ); 353 354 if( outputFile == null || outputFile.length() == 0 ){ // ファイル名が指定されていない場合は要求番号を利用する。 355 if( OUT_ODS_EXCEL.equals( type ) ){ 356 filePath.append( yokyu ); 357 filePath.append( ".xls" ); 358 } 359 else if( OUT_ODS_PDF.equals( type ) || OUT_ODS_PRINT_PDF.equals( type ) ){ 360 filePath.append( yokyu ); 361 filePath.append( ".pdf" ); 362 } 363 // 4.3.3.4 (2008/11/01) 追加 364 else if( OUT_ODS_ODS.equals ( type ) ){ 365 filePath.append( yokyu ); 366 filePath.append( ".ods" ); 367 } 368 // 5.4.3.0 (2011/12/26) 追加 369 // 5.4.4.2 (2012/02/03) .txtではなく.xml 370 else if( ExecQueue.RFID_PRINT.equals( type ) || ExecQueue.RFID_ALLPRINT.equals( type ) 371 || ExecQueue.RFID_ALLERASE.equals( type ) || ExecQueue.RFID_SEQERASE.equals( type ) ) { 372 filePath.append( yokyu ); 373 filePath.append( ".xml" ); //txt-xml 374 } 375 // 5.9.9.0 (2015/09/04) 追加 376 else if( ExecQueue.CSV_PRINT.equals( type ) || ExecQueue.CSV_PRINT_EXCEL.equals( type ) 377 || ExecQueue.CSV_PRINT_PDF.equals( type ) ) { 378 filePath.append( yokyu ); 379 filePath.append( ".csv" ); 380 } 381 } 382 else { 383 filePath.append( outputFile ); 384 } 385 386 this.outputName = filePath.toString(); 387 } 388 389 /** 390 * 出力ファイル名を取得します。 391 * 392 * @og.rev 5.1.2.0 (2010/01/01) 256シートを超える場合に対応。2ファイル目以降は、_1、_2・・・をファイル名の後ろにつける 393 * 394 * @return 出力先ファイル名 395 */ 396 public String getOutputName() { 397 if( pageCnt <= MAX_SHEETS_PER_FILE ) { 398 return outputName; 399 } 400 else { 401 StringBuilder fileName = new StringBuilder(); 402 403 int idx = outputName.lastIndexOf( '.' ); 404 String name = outputName.substring( 0, idx ); 405 String suffix = outputName.substring( idx ); 406 int addNo = (int)Math.ceil( (double)pageCnt/(double)MAX_SHEETS_PER_FILE ) - 1; 407 408 fileName.append( name ).append( "_" ).append( addNo ).append( suffix ); 409 410 return fileName.toString(); 411 } 412 } 413 414 /** 415 * 実行ファイルディレクトリを指定します。 416 * 417 * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対応 418 * 419 * @param dir ディレクトリ 420 */ 421 public void setPrgDir( final String dir ) { 422 this.prgdir = dir; 423 } 424 425 /** 426 * 実行ファイルディレクトリを取得します。 427 * 428 * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対応 429 * 430 * @return プログラムディレクトリ 431 */ 432 public String getPrgDir() { 433 return prgdir; 434 } 435 436 /** 437 * 実行ファイル名をセットします。 438 * 439 * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対応 440 * @param file ファイル名 441 */ 442 public void setPrgFile( final String file ) { 443 this.prgfile = file; 444 } 445 446 /** 447 * 実行ファイル名を取得します。 448 * 449 * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対応 450 * 451 * @return プログラムファイル名 452 */ 453 public String getPrgFile() { 454 return prgfile; 455 } 456 457 /** 458 * プリンタIDをセットします。 459 * 460 * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対応 461 * @param id プリンタID 462 */ 463 public void setPrtId( final String id ) { 464 this.prtid = id; 465 } 466 467 /** 468 * プリンタIDを取得します。 469 * 470 * @og.rev 4.3.3.0 (2008/10/01) 板金RFID対応 471 * 472 * @return プリンタID 473 */ 474 public String getPrtId() { 475 return prtid; 476 } 477 478 /** 479 * ローカルリソース使用フラグをセットします(初期値:false)。 480 * 481 * @param fglocal ローカルリソース使用フラグ[true:使用する/false:使用しない] 482 */ 483 public void setFglocal( final boolean fglocal ) { 484 this.fglocal = fglocal; 485 } 486 487 /** 488 * ローカルリソース使用フラグを取得します。 489 * 490 * @return ロールリソース使用フラグ[true:使用する/false:使用しない] 491 */ 492 public boolean isFglocal() { 493 return fglocal; 494 } 495 496 /** 497 * ページエンドカットフラグをセットします(初期値:false)。 498 * 499 * @param fgcut ページエンドカットの使用可否[true:使用/false:通常] 500 */ 501 public void setFgcut( final boolean fgcut ) { 502 this.fgcut = fgcut; 503 } 504 505 /** 506 * ページエンドカットフラグを取得します。 507 * 508 * @return ページエンドカットフラグ 509 */ 510 public boolean isFgcut() { 511 return fgcut; 512 } 513 514 /** 515 * PAGEBREAKカラムの値を、シート名として使うかどうかをセットします(初期値:false)。 516 * 517 * @og.rev 5.7.6.2 (2014/05/16) 新規追加 518 * 519 * @param useSheetName PAGEBREAKカラムのシート名使用可否[true:使用/false:使用しない] 520 */ 521 public void setUseSheetName( final boolean useSheetName ) { 522 this.useSheetName = useSheetName; 523 } 524 525 /** 526 * PAGEBREAKカラムの値を、シート名として使うかどうかを取得します。 527 * 528 * @og.rev 5.7.6.2 (2014/05/16) 新規追加 529 * 530 * @return PAGEBREAKカラムのシート名使用可否[true:使用/false:使用しない] 531 */ 532 public boolean isUseSheetName() { 533 return useSheetName; 534 } 535 536 /** 537 * キューマネージャーをセットします。 538 * 539 * @param manager キューマネージャー 540 */ 541 public void setManager( final QueueManager manager ) { 542 this.manager = manager; 543 } 544 545 /** 546 * 帳票処理データをセットします。 547 * 既にテーブルモデルがセットされている場合は、再セットしません。 548 * 549 */ 550 public void setData() { 551 if( body == null && manager != null ) { 552 manager.set( this ); 553 } 554 } 555 556 /** 557 * キューを実行中の状態に更新します。 558 * 559 */ 560 public void setExecute() { 561 if( manager != null ) { 562 manager.execute( this ); 563 } 564 } 565 566 /** 567 * キューを完了済の状態に更新します。 568 * 569 */ 570 public void setComplete() { 571 if( manager != null ) { 572 manager.complete( this ); 573 } 574 } 575 576 /** 577 * キューをエラーの状態に更新します。 578 */ 579 public void setError() { 580 if( manager != null ) { 581 manager.error( this ); 582 } 583 } 584 585 /** 586 * エラーメッセージをセットします。 587 * 588 * @param msg エラーメッセージ 589 */ 590 public void addMsg( final String msg ) { 591 errMsg.append( msg ); 592 } 593 594 /** 595 * エラーメッセージを取得します。 596 * 597 * @return エラーメッセージ 598 */ 599 public String getMsg() { 600 return errMsg.toString(); 601 } 602 603 /** 604 * 処理したページ数を引数の分だけカウントアップします。 605 * 606 * @og.rev 5.1.2.0 (2010/01/01) 新規追加 607 * 608 * @param pgs カウントアップするページ数 609 */ 610 public void addExecPageCnt( final int pgs ) { 611 pageCnt += pgs; 612 } 613 614 /** 615 * 処理したページ数を返します。 616 * 617 * @og.rev 5.1.2.0 (2010/01/01) 新規追加 618 * 619 * @return 処理したページ数 620 */ 621 public int getExecPagesCnt() { 622 return pageCnt; 623 } 624 625 /** 626 * 処理した行数をセットします。 627 * 628 * @og.rev 5.1.2.0 (2010/01/01) 新規追加 629 * 630 * @param rws 処理した行数 631 */ 632 public void setExecRowCnt( final int rws ) { 633 rowCnt = rws; 634 } 635 636 /** 637 * 処理した行数を返します。 638 * 639 * @og.rev 5.1.2.0 (2010/01/01) 新規追加 640 * 641 * @return 処理した行数 642 */ 643 public int getExecRowCnt() { 644 return rowCnt; 645 } 646 647 /** 648 * 全ての行が処理されたかをセットします(初期値:false)。 649 * 650 * これは、処理結果が、256シートを超えていた場合、再度残りのデータについて 651 * 処理を行うかどうかの判定するために、利用します。 652 * 653 * @og.rev 5.1.2.0 (2010/01/01) 新規追加 654 * 655 * @param flag 全ての行が処理されたか 656 */ 657 public void setEnd( final boolean flag ) { 658 isDataEnd = flag; 659 } 660 661 /** 662 * 全ての行が処理されているかを返します。 663 * 664 * これは、処理結果が、256シートを超えていた場合、再度残りのデータについて 665 * 処理を行うかどうかの判定するために、利用します。 666 * 667 * @og.rev 5.1.2.0 (2010/01/01) 新規追加 668 * 669 * @return 全ての行が処理されたか 670 */ 671 public boolean isEnd() { 672 return isDataEnd; 673 } 674}