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