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.report;
017
018import org.opengion.fukurou.util.Shell;
019import org.opengion.hayabusa.common.HybsSystem;
020import org.opengion.hayabusa.db.DBTableModel;
021import static org.opengion.fukurou.system.HybsConst.BUFFER_MIDDLE;      // 6.4.2.1 (2016/02/05)
022
023/**
024 * CSVPrintPoint インターフェース のデフォルト実装クラスです。
025 * execute() をオーバーライドして、各種CSV取込み方式のシステムに対応して下さい。
026 *
027 * @og.group 帳票システム
028 *
029 * @version  5.0
030 * @author       Masakazu Takahashi
031 * @since    JDK6.0,
032 */
033public abstract class AbstractCSVPrintPointService implements CSVPrintPointService {
034
035        /** カラム */ protected String                     ykno            ;
036        /** カラム */ protected String                     systemId        ;
037        /** カラム */ protected String                     fgrun           ;
038        /** カラム */ protected String                     hostName        ;
039        /** カラム */ protected String                     prtName         ;
040        /** カラム */ protected DBTableModel       table           ;
041        /** カラム */ protected DBTableModel       tableH          ;
042        /** カラム */ protected DBTableModel       tableF          ;
043        /** カラム */ protected String                     prgdir          ;
044        /** カラム */ protected String                     prgfile         ;
045        /** カラム */ protected String                     outdir          ;
046        /** カラム */ protected String                     prtid           ;
047        /** カラム */ protected String                     portnm          ;
048        /** カラム */ protected String                     listid          ;
049        /** カラム */ protected String                     modelname       ;
050
051        /** カラム */ protected String                     grpid           ;                       // 5.9.2.2 (2015/11/20)
052        /** カラム */ protected String                     dmngrp          ;                       // 5.9.2.2 (2015/11/20)
053        /** カラム */ protected String                     option          ;                       // 5.9.3.0 (2015/12/04)
054        /** カラム */ protected String                     fgcut           ;                       // 5.9.3.0 (2015/12/04)
055
056        /** エラーメッセージ */ protected final StringBuilder   errMsg  = new StringBuilder( BUFFER_MIDDLE );   // エラーメッセージ
057        /** 完了フラグ */                   protected               String                  fgkan   = GE50Access.FG_ERR2;   // 初期値はアプリエラー
058
059        private static final int TIMEOUT = HybsSystem.sysInt( "REPORT_DAEMON_TIMEOUT" );        // Shellタイムアウト 6.3.9.1 (2015/11/27) private static final化
060        /** シェルコマンド */ protected String         shellCmd        ;
061
062        /** 実行フラグ {@value} */ protected static final String FGRUN_EXCEL  = "H";
063        /** 実行フラグ {@value} */ protected static final String FGRUN_PDF    = "I";
064        /** 実行フラグ {@value} */ protected final static String FGRUN_EXCEL2 = "J";        // 5.9.4.2 (2016/01/13)
065
066        private static final String CR          = System.getProperty("line.separator");
067
068        /**
069         * デフォルトコンストラクター
070         *
071         * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
072         */
073        protected AbstractCSVPrintPointService() { super(); }           // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
074
075        /**
076         * 発行処理
077         * 対象のシステムに応じてこのメソッドをオーバーライドします
078         * 実行後はfgkanの値を正しい値でセットしなおして下さい。
079         *
080         * @return 結果 [true:正常/false:異常]
081         */
082        public abstract boolean execute();
083
084        /**
085         * 帳票起動された要求番号をセットします。
086         *
087         * @param   no 要求NO
088         */
089        public void setYkno( final String no ) {
090                ykno = no;
091        }
092
093        /**
094         * システムIDをセットします。
095         *
096         * @param   id システムID
097         */
098        public void setSystemId( final String id ) {
099                systemId = id;
100        }
101
102        /**
103         * 実行方法をセットします。
104         *
105         * @param   flag 実行方法
106         */
107        public void setFgrun( final String flag ) {
108                fgrun = flag;
109        }
110
111        /**
112         * 帳票デーモンが実行されているホスト名をセットします。
113         *
114         * @param   host ホスト名
115         */
116        public void setHostName( final String host ) {
117                hostName = host;
118        }
119
120        /**
121         * プリンター名をセットします。
122         *
123         * @param   printerName プリンタ名
124         */
125        public void setPrinterName( final String printerName ) {
126                prtName = printerName;
127        }
128
129        /**
130         * DBTableModel をセットします。
131         *
132         * @param   tbl DBTableModelオブジェクト
133         */
134        public void setTable( final DBTableModel tbl ) {
135                table = tbl;
136        }
137
138        /**
139         * DBTableModel をセットします。
140         *
141         * @param   tbl DBTableModelオブジェクト
142         */
143        public void setTableH( final DBTableModel tbl ) {
144                tableH = tbl;
145        }
146
147        /**
148         * DBTableModel をセットします。
149         *
150         * @param   tbl DBTableModelオブジェクト
151         */
152        public void setTableF( final DBTableModel tbl ) {
153                tableF = tbl;
154        }
155
156        /**
157         * 起動するバッチ等のプログラム(ディレクトリ)をセットします。
158         *
159         * @param dir バッチプログラムディレクトリ
160         */
161        public void setPrgDir( final String dir ){
162                prgdir = dir;
163        }
164
165        /**
166         * 起動するバッチ等のプログラムをセットします。
167         * 空の場合は起動しません。
168         *
169         * @param file バッチプログラム名
170         */
171        public void setPrgFile( final String file ){
172                prgfile = file;
173        }
174
175        /**
176         * ファイル出力時のディレクトリを指定します。
177         *
178         * @param dir ファイル出力ディレクトリ
179         */
180        public void setOutDir( final String dir ){
181                outdir = dir;
182        }
183
184        /**
185         * プリンタIDを指定します。
186         *
187         * @param id プリンタID
188         */
189        public void setPrtId( final String id ){
190                prtid = id;
191        }
192
193        /**
194         * プリンタのポート名。
195         *
196         * @param port ポート名
197         */
198        public void setPortnm( final String port ){
199                portnm = port;
200        }
201
202        /**
203         * 帳票IDをセットします。
204         *
205         * @param   id 帳票ID
206         */
207        public void setListId( final String id ) {
208                listid = id;
209        }
210
211        /**
212         * 雛形ファイル名をセットします。
213         *
214         * @param   name 雛形ファイル名
215         */
216        public void setModelname( final String name ) {
217                modelname = name;
218        }
219
220        /**
221         * グループIDをセットします。
222         *
223         * @param   id グループID
224         */
225        public void setGrpId( final String id ) {
226                grpid = id;
227        }
228
229        /**
230         * デーモングループをセットします。
231         *
232         * @param   name デーモングループ
233         */
234        public void setDmnGrp( final String name ) {
235                dmngrp = name;
236        }
237
238        /**
239         * オプション文字列をセットします。
240         *
241         * @og.rev 5.9.3.0 (2015/12/04)
242         *
243         * @param   opt オプション文字列
244         */
245        public void setOption( final String opt ) {
246                option = opt;
247        }
248
249        /**
250         * ページエンドカットフラグをセットします。
251         *
252         * @og.rev 5.9.3.0 (2015/12/04)
253         *
254         * @param   flg エンドカットフラグ
255         */
256        public void setFgcut( final String flg ) {
257                fgcut = flg;
258        }
259
260        /**
261         * 完成フラグを返します。
262         *
263         * @return 完成フラグ String
264         */
265        public String getFgkan(){
266                return fgkan;
267        }
268
269        /**
270         * エラーメッセージを返します。
271         *
272         * @return エラーメッセージ String
273         */
274        public String getErrMsg(){
275                return errMsg.toString();
276        }
277
278        /**
279         * シェルの実行を行います。
280         *
281         * @og.rev 5.4.3.0 (2011/12/26)
282         *
283         * @return 結果 [true:正常/false:異常]
284         */
285        protected boolean programRun(){
286                final Shell shell = new Shell();
287                shell.setCommand( shellCmd,true );              // BATCHプロセスで実行する
288                shell.setWait( true );                                  // プロセスの終了を待つ
289                shell.setTimeout( TIMEOUT );
290
291                if( shell.exec() != 0 ) {
292                        errMsg.append( "Shell Command exequte Error." ).append( CR )
293                                .append( "==============================" ).append( CR )
294                                .append( shellCmd ).append( CR )
295                                .append( shell.getStdoutData() ).append( CR )
296                                .append( shell.getStderrData() ).append( CR )
297                                .append( CR );
298                        return false;
299                }
300
301                return true;
302        }
303
304}