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