123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- package kr.co.icontrols.callengine.engine;
- import android.content.Context;
- import android.util.Log;
- import com.artncore.WallPadDataMgr.WallpadDeviceSet;
- import com.artncore.wallpadimap.RetProci;
- import com.util.LogUtil;
- import org.apache.commons.net.ftp.FTP;
- import kr.co.icontrols.callengine.engine.CallManager.CALLTYPE;
- import kr.co.icontrols.callengine.engine.CallManager.CALLSTATUS;
- import kr.co.icontrols.hdcftp.HDCFTPManager;
- import kr.co.icontrols.wallpadcall.MainActivity;
- import kr.co.icontrols.wallpadcall.declare.DataClasses.AutoPictureInfo;
- import kr.co.icontrols.wallpadcall.declare.Global;
- import kr.co.icontrols.wallpadcall.imap.Notice_visitor_upload_complete;
- import kr.co.icontrols.wallpadcall.imap.Request_visitor_access_info;
- public class AutoSaveStrangerPicture {
- static String TAG = "AutoSaveStrangerPicture";
- static Context mContext;
- static HDCFTPManager mFTPManager;
- public static AutoPictureInfo mAutoPictureInfo;
- static String strLocalURI, strRemoteURI, strFileName, strTime, strUserID, strPW, strPath;
- static String strRemoteIP = "10.0.1.1";
- public static class startAutoSaveStrangerPicture extends Thread {
- // 거동수상자 발생시 사진 촬영해야 서버 전송
- public startAutoSaveStrangerPicture(Context context, AutoPictureInfo info) {
- try {
- Log.d(TAG, "[startAutoSaveStrangerPicture] =====START =====");
- mContext = context;
- mAutoPictureInfo = info;
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] startAutoSaveStrangerPicture(Context context, AutoPictureInfo Info)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- public void run() {
- try {
- strLocalURI = MainActivity.mCallController.saveVisitorPicture(mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, mAutoPictureInfo.strRemoteSIPID, false, true, false);
- Log.d(TAG, "[startAutoSaveStrangerPicture.run()] strLocalURI [" + strLocalURI + "]");
- String strType = "NONE";
- if (mAutoPictureInfo.eCallType == CALLTYPE.FRONT && mAutoPictureInfo.eCallStatus == CALLSTATUS.TAKINGPIC) strType = "home";
- else strType = "unknown";
- String[] strParse_01 = strLocalURI.split("/");
- strFileName = strParse_01[6];
- Log.d(TAG, "[startAutoSaveStrangerPicture.run()] strFileName [" + strFileName + "]");
- String[] strParse_02 = strFileName.split("\\.");
- String[] strParse_03 = strParse_02[0].split("_");
- strTime = strParse_03[5] + "_" + strParse_03[6];
- Log.d(TAG, "[startAutoSaveStrangerPicture.run()] strTime [" + strTime + "]");
- send_visitor_access_info_request(mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, strType, strTime, strFileName, mAutoPictureInfo.strMessage);
- Global.sendVisitorEventBRtoMobileVendor(strType, strTime);
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- Log.e(TAG, "[Exception] startAutoSaveStrangerPicture.run()");
- }
- }
- }
- public static class UploadStrangerPicture extends Thread {
- int iMainServer2dot0 = 0;
- public UploadStrangerPicture() {
- Log.d(TAG, "[UploadStrangerPicture] ===== START =====");
- WallpadDeviceSet wallpadDeviceSet = new WallpadDeviceSet(mContext);
- try {
- iMainServer2dot0 = wallpadDeviceSet.GetNewDanjiServer();
- Log.d(TAG, "[UploadStrangerPicture] iMainServer2dot0 [" + iMainServer2dot0 + "]");
- wallpadDeviceSet.closeDB();
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] UploadStrangerPicture()");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- wallpadDeviceSet.closeDB();
- }
- }
- public void run() {
- try {
- mFTPManager = new HDCFTPManager();
- if (!mFTPManager.connectFTP(strRemoteIP)) {
- Log.w(TAG, "[UploadStrangerPicture.run()] FAIL!! -> connectFTP(...)");
- send_visitor_upload_complete_notice(false, mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, strTime, strFileName, "null");
- return;
- }
- if (!mFTPManager.loginFTP(strUserID, strPW)) {
- Log.w(TAG, "[UploadStrangerPicture.run()] FAIL!! -> loginFTP(...)");
- send_visitor_upload_complete_notice(false, mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, strTime, strFileName, "null");
- return;
- }
- if (iMainServer2dot0 == 1) {
- if (!mFTPManager.setPassiveMode()) {
- Log.w(TAG, "[UploadStrangerPicture.run()] FAIL!! -> setPassiveMode(...)");
- disconnectFTP();
- send_visitor_upload_complete_notice(false, mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, strTime, strFileName, "null");
- return;
- }
- }
- if (!mFTPManager.setCtrlEncoding(mFTPManager.ENCODING_TYPE_EUC_KR)) {
- Log.w(TAG, "[UploadStrangerPicture.run()] FAIL!! -> setCtrlEncoding(...)");
- disconnectFTP();
- send_visitor_upload_complete_notice(false, mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, strTime, strFileName, "null");
- return;
- }
- if (!mFTPManager.setFileType(FTP.BINARY_FILE_TYPE)) {
- Log.w(TAG, "[UploadStrangerPicture.run()] FAIL!! -> setFileType(...)");
- disconnectFTP();
- send_visitor_upload_complete_notice(false, mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, strTime, strFileName, "null");
- return;
- }
- if (!mFTPManager.uploadFile(strRemoteURI, strLocalURI)) {
- Log.w(TAG, "[UploadStrangerPicture.run()] FAIL!! -> uploadFile(...)");
- disconnectFTP();
- send_visitor_upload_complete_notice(false, mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, strTime, strFileName, "null");
- return;
- }
- Thread.sleep(500);
- disconnectFTP();
- Log.d(TAG, "[UploadStrangerPicture.run()] Complete upload!!!");
- send_visitor_upload_complete_notice(true, mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, strTime, strFileName, "null");
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] UploadStrangerPicture.run()");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- }
- }
- public static boolean disconnectFTP() {
- try {
- if (mFTPManager.logoutFTP()) {
- if (mFTPManager.disconnectFTP()) {
- Log.d(TAG, "[disconnectFTP] disconnectFTP OK!!");
- return true;
- }
- }
- Log.d(TAG, "[disconnectFTP] disconnectFTP FAIL!!");
- return false;
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- return false;
- } catch (Exception e) {
- Log.e(TAG, "[Exception] disconnectFTP()");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- return false;
- }
- }
- static String strReply_User = "";
- static String strReply_PW = "";
- static String strReply_Path = "";
- static private String strPass_key = "passwd";
- public static boolean send_visitor_access_info_request(String strDong, String strHo, String strType, String strTime, final String strFileName, String strMessage) {
- try {
- final Request_visitor_access_info visitor_access_info = new Request_visitor_access_info(mContext);
- if (visitor_access_info.send_visitor_access_info(strDong, strHo, strType, strTime, strFileName, strMessage)) {
- visitor_access_info.setResultCtrl(new RetProci() {
- @Override
- public void ProcSuccess() {
- Log.d(TAG, "[send_visitor_access_info_request] ProcSuccess()");
- visitor_access_info.SetItem("ftp_info");
- strReply_User = visitor_access_info.GetAttributeVal(0, "user");
- strReply_PW = visitor_access_info.GetAttributeVal(0, strPass_key);
- strReply_Path = visitor_access_info.GetAttributeVal(0, "path");
- Log.d(TAG, "[send_visitor_access_info_request] Reply!! User [" + strReply_User + "], PW [" + strReply_PW + "], Path [" + strReply_Path + "]");
- strUserID = strReply_User;
- strPW = strReply_PW;
- strPath = strReply_Path;
- strRemoteURI = strPath + "/" + strFileName;
- UploadStrangerPicture mUploadStrangerPicture = new UploadStrangerPicture();
- mUploadStrangerPicture.start();
- }
- @Override
- public void ProcError() {
- Log.d(TAG, "[send_visitor_access_info_request] ProcError()");
- }
- @Override
- public void ProcDoing() {
- Log.d(TAG, "[send_visitor_access_info_request] ProcDoing()");
- }
- });
- return true;
- }
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] send_visitor_access_info_request(String strDong, String strHo, String strType, String strTime, String strFileName, String strMessage)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- return false;
- }
- public static boolean send_visitor_upload_complete_notice(boolean bResult, String strDong, String strHo, CALLTYPE eCallType, CALLSTATUS eCallStatus, String strTime, String strFileName, String strMessage) {
- try {
- final Notice_visitor_upload_complete visitor_upload_complete = new Notice_visitor_upload_complete(mContext);
- String strType = "NONE";
- if (eCallType == CALLTYPE.FRONT) {
- if (eCallStatus == CALLSTATUS.TAKINGPIC) strType = "home";
- else strType = "unknown";
- }
- else if (eCallType == CALLTYPE.LOBBY) {
- strType = "lobby";
- }
- else strType = "unknown";
- if (visitor_upload_complete.send_visitor_access_info(bResult, strDong, strHo, strType, strTime, strFileName, strMessage)) {
- visitor_upload_complete.setResultCtrl(new RetProci() {
- @Override
- public void ProcSuccess() {
- Log.d(TAG, "[send_visitor_upload_complete_notice] ProcSuccess()");
- }
- @Override
- public void ProcError() {
- Log.d(TAG, "[send_visitor_upload_complete_notice] ProcError()");
- }
- @Override
- public void ProcDoing() {
- Log.d(TAG, "[send_visitor_upload_complete_notice] ProcDoing()");
- }
- });
- return true;
- }
- } catch (RuntimeException re) {
- LogUtil.errorLogInfo("", TAG, re);
- } catch (Exception e) {
- Log.e(TAG, "[Exception] send_visitor_upload_complete_notice(boolean bResult, String strDong, String strHo, String strType, String strTime, String strFileName, String strMessage)");
- //e.printStackTrace();
- LogUtil.errorLogInfo("", TAG, e);
- }
- return false;
- }
- }
|