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