AutoSaveStrangerPicture.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. package kr.co.icontrols.callengine.engine;
  2. import android.content.Context;
  3. import android.util.Log;
  4. import com.artncore.WallPadDataMgr.WallpadDeviceSet;
  5. import com.artncore.wallpadimap.RetProci;
  6. import com.util.LogUtil;
  7. import org.apache.commons.net.ftp.FTP;
  8. import kr.co.icontrols.callengine.engine.CallManager.CALLTYPE;
  9. import kr.co.icontrols.callengine.engine.CallManager.CALLSTATUS;
  10. import kr.co.icontrols.hdcftp.HDCFTPManager;
  11. import kr.co.icontrols.wallpadcall.MainActivity;
  12. import kr.co.icontrols.wallpadcall.declare.DataClasses.AutoPictureInfo;
  13. import kr.co.icontrols.wallpadcall.declare.Global;
  14. import kr.co.icontrols.wallpadcall.imap.Notice_visitor_upload_complete;
  15. import kr.co.icontrols.wallpadcall.imap.Request_visitor_access_info;
  16. public class AutoSaveStrangerPicture {
  17. static String TAG = "AutoSaveStrangerPicture";
  18. static Context mContext;
  19. static HDCFTPManager mFTPManager;
  20. public static AutoPictureInfo mAutoPictureInfo;
  21. static String strLocalURI, strRemoteURI, strFileName, strTime, strUserID, strPW, strPath;
  22. static String strRemoteIP = "10.0.1.1";
  23. public static class startAutoSaveStrangerPicture extends Thread {
  24. // 거동수상자 발생시 사진 촬영해야 서버 전송
  25. public startAutoSaveStrangerPicture(Context context, AutoPictureInfo info) {
  26. try {
  27. Log.d(TAG, "[startAutoSaveStrangerPicture] =====START =====");
  28. mContext = context;
  29. mAutoPictureInfo = info;
  30. } catch (RuntimeException re) {
  31. LogUtil.errorLogInfo("", TAG, re);
  32. } catch (Exception e) {
  33. Log.e(TAG, "[Exception] startAutoSaveStrangerPicture(Context context, AutoPictureInfo Info)");
  34. //e.printStackTrace();
  35. LogUtil.errorLogInfo("", TAG, e);
  36. }
  37. }
  38. public void run() {
  39. try {
  40. strLocalURI = MainActivity.mCallController.saveVisitorPicture(mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, mAutoPictureInfo.strRemoteSIPID, false, true, false);
  41. Log.d(TAG, "[startAutoSaveStrangerPicture.run()] strLocalURI [" + strLocalURI + "]");
  42. String strType = "NONE";
  43. if (mAutoPictureInfo.eCallType == CALLTYPE.FRONT && mAutoPictureInfo.eCallStatus == CALLSTATUS.TAKINGPIC) strType = "home";
  44. else strType = "unknown";
  45. String[] strParse_01 = strLocalURI.split("/");
  46. strFileName = strParse_01[6];
  47. Log.d(TAG, "[startAutoSaveStrangerPicture.run()] strFileName [" + strFileName + "]");
  48. String[] strParse_02 = strFileName.split("\\.");
  49. String[] strParse_03 = strParse_02[0].split("_");
  50. strTime = strParse_03[5] + "_" + strParse_03[6];
  51. Log.d(TAG, "[startAutoSaveStrangerPicture.run()] strTime [" + strTime + "]");
  52. send_visitor_access_info_request(mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, strType, strTime, strFileName, mAutoPictureInfo.strMessage);
  53. Global.sendVisitorEventBRtoMobileVendor(strType, strTime);
  54. } catch (RuntimeException re) {
  55. LogUtil.errorLogInfo("", TAG, re);
  56. } catch (Exception e) {
  57. //e.printStackTrace();
  58. LogUtil.errorLogInfo("", TAG, e);
  59. Log.e(TAG, "[Exception] startAutoSaveStrangerPicture.run()");
  60. }
  61. }
  62. }
  63. public static class UploadStrangerPicture extends Thread {
  64. int iMainServer2dot0 = 0;
  65. public UploadStrangerPicture() {
  66. Log.d(TAG, "[UploadStrangerPicture] ===== START =====");
  67. WallpadDeviceSet wallpadDeviceSet = new WallpadDeviceSet(mContext);
  68. try {
  69. iMainServer2dot0 = wallpadDeviceSet.GetNewDanjiServer();
  70. Log.d(TAG, "[UploadStrangerPicture] iMainServer2dot0 [" + iMainServer2dot0 + "]");
  71. wallpadDeviceSet.closeDB();
  72. } catch (RuntimeException re) {
  73. LogUtil.errorLogInfo("", TAG, re);
  74. } catch (Exception e) {
  75. Log.e(TAG, "[Exception] UploadStrangerPicture()");
  76. //e.printStackTrace();
  77. LogUtil.errorLogInfo("", TAG, e);
  78. wallpadDeviceSet.closeDB();
  79. }
  80. }
  81. public void run() {
  82. try {
  83. mFTPManager = new HDCFTPManager();
  84. if (!mFTPManager.connectFTP(strRemoteIP)) {
  85. Log.w(TAG, "[UploadStrangerPicture.run()] FAIL!! -> connectFTP(...)");
  86. send_visitor_upload_complete_notice(false, mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, strTime, strFileName, "null");
  87. return;
  88. }
  89. if (!mFTPManager.loginFTP(strUserID, strPW)) {
  90. Log.w(TAG, "[UploadStrangerPicture.run()] FAIL!! -> loginFTP(...)");
  91. send_visitor_upload_complete_notice(false, mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, strTime, strFileName, "null");
  92. return;
  93. }
  94. if (iMainServer2dot0 == 1) {
  95. if (!mFTPManager.setPassiveMode()) {
  96. Log.w(TAG, "[UploadStrangerPicture.run()] FAIL!! -> setPassiveMode(...)");
  97. disconnectFTP();
  98. send_visitor_upload_complete_notice(false, mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, strTime, strFileName, "null");
  99. return;
  100. }
  101. }
  102. if (!mFTPManager.setCtrlEncoding(mFTPManager.ENCODING_TYPE_EUC_KR)) {
  103. Log.w(TAG, "[UploadStrangerPicture.run()] FAIL!! -> setCtrlEncoding(...)");
  104. disconnectFTP();
  105. send_visitor_upload_complete_notice(false, mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, strTime, strFileName, "null");
  106. return;
  107. }
  108. if (!mFTPManager.setFileType(FTP.BINARY_FILE_TYPE)) {
  109. Log.w(TAG, "[UploadStrangerPicture.run()] FAIL!! -> setFileType(...)");
  110. disconnectFTP();
  111. send_visitor_upload_complete_notice(false, mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, strTime, strFileName, "null");
  112. return;
  113. }
  114. if (!mFTPManager.uploadFile(strRemoteURI, strLocalURI)) {
  115. Log.w(TAG, "[UploadStrangerPicture.run()] FAIL!! -> uploadFile(...)");
  116. disconnectFTP();
  117. send_visitor_upload_complete_notice(false, mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, strTime, strFileName, "null");
  118. return;
  119. }
  120. Thread.sleep(500);
  121. disconnectFTP();
  122. Log.d(TAG, "[UploadStrangerPicture.run()] Complete upload!!!");
  123. send_visitor_upload_complete_notice(true, mAutoPictureInfo.strDong, mAutoPictureInfo.strHo, mAutoPictureInfo.eCallType, mAutoPictureInfo.eCallStatus, strTime, strFileName, "null");
  124. } catch (RuntimeException re) {
  125. LogUtil.errorLogInfo("", TAG, re);
  126. } catch (Exception e) {
  127. Log.e(TAG, "[Exception] UploadStrangerPicture.run()");
  128. //e.printStackTrace();
  129. LogUtil.errorLogInfo("", TAG, e);
  130. }
  131. }
  132. }
  133. public static boolean disconnectFTP() {
  134. try {
  135. if (mFTPManager.logoutFTP()) {
  136. if (mFTPManager.disconnectFTP()) {
  137. Log.d(TAG, "[disconnectFTP] disconnectFTP OK!!");
  138. return true;
  139. }
  140. }
  141. Log.d(TAG, "[disconnectFTP] disconnectFTP FAIL!!");
  142. return false;
  143. } catch (RuntimeException re) {
  144. LogUtil.errorLogInfo("", TAG, re);
  145. return false;
  146. } catch (Exception e) {
  147. Log.e(TAG, "[Exception] disconnectFTP()");
  148. //e.printStackTrace();
  149. LogUtil.errorLogInfo("", TAG, e);
  150. return false;
  151. }
  152. }
  153. static String strReply_User = "";
  154. static String strReply_PW = "";
  155. static String strReply_Path = "";
  156. static private String strPass_key = "passwd";
  157. public static boolean send_visitor_access_info_request(String strDong, String strHo, String strType, String strTime, final String strFileName, String strMessage) {
  158. try {
  159. final Request_visitor_access_info visitor_access_info = new Request_visitor_access_info(mContext);
  160. if (visitor_access_info.send_visitor_access_info(strDong, strHo, strType, strTime, strFileName, strMessage)) {
  161. visitor_access_info.setResultCtrl(new RetProci() {
  162. @Override
  163. public void ProcSuccess() {
  164. Log.d(TAG, "[send_visitor_access_info_request] ProcSuccess()");
  165. visitor_access_info.SetItem("ftp_info");
  166. strReply_User = visitor_access_info.GetAttributeVal(0, "user");
  167. strReply_PW = visitor_access_info.GetAttributeVal(0, strPass_key);
  168. strReply_Path = visitor_access_info.GetAttributeVal(0, "path");
  169. Log.d(TAG, "[send_visitor_access_info_request] Reply!! User [" + strReply_User + "], PW [" + strReply_PW + "], Path [" + strReply_Path + "]");
  170. strUserID = strReply_User;
  171. strPW = strReply_PW;
  172. strPath = strReply_Path;
  173. strRemoteURI = strPath + "/" + strFileName;
  174. UploadStrangerPicture mUploadStrangerPicture = new UploadStrangerPicture();
  175. mUploadStrangerPicture.start();
  176. }
  177. @Override
  178. public void ProcError() {
  179. Log.d(TAG, "[send_visitor_access_info_request] ProcError()");
  180. }
  181. @Override
  182. public void ProcDoing() {
  183. Log.d(TAG, "[send_visitor_access_info_request] ProcDoing()");
  184. }
  185. });
  186. return true;
  187. }
  188. } catch (RuntimeException re) {
  189. LogUtil.errorLogInfo("", TAG, re);
  190. } catch (Exception e) {
  191. Log.e(TAG, "[Exception] send_visitor_access_info_request(String strDong, String strHo, String strType, String strTime, String strFileName, String strMessage)");
  192. //e.printStackTrace();
  193. LogUtil.errorLogInfo("", TAG, e);
  194. }
  195. return false;
  196. }
  197. public static boolean send_visitor_upload_complete_notice(boolean bResult, String strDong, String strHo, CALLTYPE eCallType, CALLSTATUS eCallStatus, String strTime, String strFileName, String strMessage) {
  198. try {
  199. final Notice_visitor_upload_complete visitor_upload_complete = new Notice_visitor_upload_complete(mContext);
  200. String strType = "NONE";
  201. if (eCallType == CALLTYPE.FRONT) {
  202. if (eCallStatus == CALLSTATUS.TAKINGPIC) strType = "home";
  203. else strType = "unknown";
  204. }
  205. else if (eCallType == CALLTYPE.LOBBY) {
  206. strType = "lobby";
  207. }
  208. else strType = "unknown";
  209. if (visitor_upload_complete.send_visitor_access_info(bResult, strDong, strHo, strType, strTime, strFileName, strMessage)) {
  210. visitor_upload_complete.setResultCtrl(new RetProci() {
  211. @Override
  212. public void ProcSuccess() {
  213. Log.d(TAG, "[send_visitor_upload_complete_notice] ProcSuccess()");
  214. }
  215. @Override
  216. public void ProcError() {
  217. Log.d(TAG, "[send_visitor_upload_complete_notice] ProcError()");
  218. }
  219. @Override
  220. public void ProcDoing() {
  221. Log.d(TAG, "[send_visitor_upload_complete_notice] ProcDoing()");
  222. }
  223. });
  224. return true;
  225. }
  226. } catch (RuntimeException re) {
  227. LogUtil.errorLogInfo("", TAG, re);
  228. } catch (Exception e) {
  229. Log.e(TAG, "[Exception] send_visitor_upload_complete_notice(boolean bResult, String strDong, String strHo, String strType, String strTime, String strFileName, String strMessage)");
  230. //e.printStackTrace();
  231. LogUtil.errorLogInfo("", TAG, e);
  232. }
  233. return false;
  234. }
  235. }