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