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 */
016 package org.opengion.plugin.daemon;
017
018 import org.opengion.hayabusa.common.HybsSystem;
019 import org.opengion.hayabusa.report.GE50Access;
020 import org.opengion.fukurou.util.LogWriter;
021 import org.opengion.fukurou.util.StringUtil;
022 import org.opengion.fukurou.util.HybsTimerTask;
023
024 import org.opengion.fukurou.mail.MailReceiveListener ;
025 import org.opengion.fukurou.mail.MailRX ;
026
027 import java.util.Date;
028
029 /**
030 * 【メールãƒ??モン】メールサーバã?を監視して、EXCELファイルのDB登録処ç�??ãƒ??モンですã?
031 * æŒ?®šã?条件でメールサーバã?を監視し、添付ã?EXCELファイルを取りå?しますã?
032 * 添付ファイルは、EXCEL取り込みインターフェースにå‰?‚Š、要求番号.xls にリネã?ãƒ?�—て
033 * æ‰?®šã?ãƒ?‚£レクトリ(EXCEL_IN_FILE_URLで定義)にセーブし、帳票要求テーブルに登録しますã?(GE50)
034 * それ以降ã?処ç�??、EXCEL帳票ãƒ??モン以下ã?共通å?ç�?�§処ç�?�•れますã?
035 * EXCEL取り込み処ç�??、このメール自動取り込みと、ファイルアãƒ??ロードã?方式を
036 * サポã?トしてã�?�¾すã?
037 *
038 * @og.rev 3.8.0.0 (2005/06/07) 新規追åŠ?
039 * @og.rev 4.3.4.4 (2009/01/01) プラグインåŒ?
040 * @og.group ãƒ??モン
041 *
042 * @version 4.0
043 * @author Kazuhiko Hasegawa
044 * @since JDK5.0,
045 */
046 public class Daemon_MailReceive extends HybsTimerTask {
047 //* こã?プログラãƒ??VERSIONæ–?—å?を設定しますã? {@value} */
048 private static final String VERSION = "5.3.0.0 (2010/12/01)" ;
049
050 private int loopCnt = 0;
051 private static final int LOOP_COUNTER = 24; // カウンタã‚?4回に設å®?
052
053 private MailRX mailRX = null;
054
055 /**
056 * こã?タイマã?タスクによって初期化されるアクションですã?
057 * パラメータを使用した初期化を行いますã?
058 *
059 */
060 @Override
061 public void initDaemon() {
062
063 String host = StringUtil.nval( getValue( "HOST" ) , HybsSystem.sys( "COMMON_MAIL_SERVER" ) );
064 String user = StringUtil.nval( getValue( "USER" ) , HybsSystem.sys( "MAIL_DAEMON_DEFAULT_USER" ) );
065 String passwd = StringUtil.nval( getValue( "PASSWD" ) , HybsSystem.sys( "MAIL_DAEMON_DEFAULT_PASS" ) );
066
067 mailRX = new MailRX();
068 mailRX.setHost( host );
069 mailRX.setUser( user );
070 mailRX.setPasswd( passwd );
071 mailRX.setDelete( true );
072
073 // 現段階では、Subjectによるメール取得振åˆ??行いませんã€?
074 // 条件に合わなã�?‚¨ラーメールを取りå?す機会がなくなるためですã?
075 // String subject = getValue( "SUBJECT" );
076 // if( subject != null && subject.length() > 0 ) {
077 // HybsEntry entry = new HybsEntry( "Subject",subject );
078 // mailRX.addMatchTerm( entry );
079 // }
080
081 String receiveListener = getValue( "RECEIVE_LISTENER" );
082 MailReceiveListener listener = (MailReceiveListener)HybsSystem.newInstance( receiveListener );
083 mailRX.setMailReceiveListener( listener );
084 }
085
086 /**
087 * タイマã?タスクのãƒ??モン処ç�??開始ã?イントですã?
088 *
089 * @og.rev 5.3.0.0 (2010/12/01) エラーハンドリングを修正
090 *
091 */
092 @Override
093 protected void startDaemon() {
094 if( loopCnt % LOOP_COUNTER == 0 ) {
095 loopCnt = 1;
096 System.out.println();
097 System.out.print( toString() + " " + new Date() + " " );
098 }
099 else {
100 System.out.print( "." );
101 loopCnt++ ;
102 }
103
104 try {
105 mailRX.start();
106 }
107 // catch( Throwable ex ) {
108 // GE50Access GE50 = new GE50Access( "CYYYYY","M_Daemon","MailReceive" );
109 //
110 // GE50.setSystemId( "ERR" );
111 // GE50.makeYkno();
112 //
113 // GE50.insertGE50( GE50Access.FG_ERR1 );
114 //
115 // String errMsg = StringUtil.stringStackTrace( ex );
116 // GE50.insertErrorGE56( errMsg );
117 //
118 // LogWriter.log( errMsg );
119 // }
120 // 5.3.0.0 (2010/12/01) エラーハンドリングを修正
121 catch( Throwable ex ) {
122 String errMsg = StringUtil.stringStackTrace( ex ) ;
123 System.out.println( errMsg );
124 LogWriter.log( errMsg );
125
126 GE50Access ge50 = new GE50Access( "CYYYYY","M_Daemon","MailReceive" );
127
128 ge50.setSystemId( "ERR" );
129 ge50.makeYkno();
130
131 ge50.insertErrorGE56( errMsg );
132 ge50.insertGE50( GE50Access.FG_ERR1 );
133
134 }
135 }
136 }