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