Search in sources :

Example 1 with SysFtpTranVO

use of com.netsteadfast.greenstep.vo.SysFtpTranVO in project bamboobsc by billchen198318.

the class SystemFtpClientUtils method getFilesByFtp.

private static void getFilesByFtp(SystemFtpClientResultObj resultObj) throws Exception {
    SysFtpVO ftp = resultObj.getSysFtp();
    SysFtpTranVO tran = resultObj.getSysFtpTran();
    FtpClientUtils ftpClient = new FtpClientUtils();
    File storeDir = getStoreDir();
    try {
        ftpClient.login(ftp.getAddress(), ftp.getUser(), ftp.getPass());
        for (String name : resultObj.getNames()) {
            ftpClient.get(tran.getCwd(), storeDir, name);
        }
        fillStoreDirFiles(storeDir, resultObj);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    } finally {
        storeDir = null;
        ftpClient.close();
        ftpClient = null;
    }
}
Also used : SysFtpTranVO(com.netsteadfast.greenstep.vo.SysFtpTranVO) File(java.io.File) IOException(java.io.IOException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysFtpVO(com.netsteadfast.greenstep.vo.SysFtpVO)

Example 2 with SysFtpTranVO

use of com.netsteadfast.greenstep.vo.SysFtpTranVO in project bamboobsc by billchen198318.

the class SystemFtpClientUtils method getFileOnly.

/**
	 * 取出FTP或SFTP上的檔案
	 * 
	 * @param tranId	TB_SYS_FTP_TRAN.TRAN_ID
	 * @return
	 * @throws ServiceException
	 * @throws Exception
	 */
public static SystemFtpClientResultObj getFileOnly(String tranId) throws ServiceException, Exception {
    if (StringUtils.isBlank(tranId)) {
        throw new Exception(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    logger.info("getFileOnly begin...");
    SystemFtpClientResultObj resultObj = new SystemFtpClientResultObj();
    SysFtpTranVO tran = findSysFtpTran(tranId);
    SysFtpVO ftp = findSysFtp(tran.getFtpId());
    List<TbSysFtpTranSegm> segms = findSysFtpTranSegm(tran.getFtpId(), tran.getTranId());
    resultObj.setSysFtp(ftp);
    resultObj.setSysFtpTran(tran);
    resultObj.setSysFtpTranSegms(segms);
    getFiles(resultObj);
    logger.info("getFileOnly end...");
    return resultObj;
}
Also used : TbSysFtpTranSegm(com.netsteadfast.greenstep.po.hbm.TbSysFtpTranSegm) SysFtpTranVO(com.netsteadfast.greenstep.vo.SysFtpTranVO) IOException(java.io.IOException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SystemFtpClientResultObj(com.netsteadfast.greenstep.model.SystemFtpClientResultObj) SysFtpVO(com.netsteadfast.greenstep.vo.SysFtpVO)

Example 3 with SysFtpTranVO

use of com.netsteadfast.greenstep.vo.SysFtpTranVO in project bamboobsc by billchen198318.

the class SystemFtpClientUtils method putFiles.

/**
	 * 放檔案至FTP或SFTP上
	 * 
	 * @param tranId	TB_SYS_FTP_TRAN.TRAN_ID
	 * @return
	 * @throws ServiceException
	 * @throws Exception
	 */
public static boolean putFiles(String tranId) throws ServiceException, Exception {
    if (StringUtils.isBlank(tranId)) {
        throw new Exception(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    SysFtpTranVO tran = findSysFtpTran(tranId);
    SysFtpVO ftp = findSysFtp(tran.getFtpId());
    if (!SystemFtpClientModel.TRAN_PUT.equals(tran.getTranType())) {
        logger.warn("Not a PUT mode TB_SYS_FTP_TRAN.TRAN_ID: " + tranId);
        return false;
    }
    /**
		 * 這裡的 NAME_EXPRESSION 回傳的 names 檔案文字路徑必須 如 : /var/upload/20150514.txt
		 * **不可** 是 20150514.txt
		 */
    List<String> fileFullPathNames = getFileNames(tran.getExprType(), tran.getNameExpression());
    if (SystemFtpClientModel.FTP.equals(ftp.getType())) {
        // FTP
        putFilesByFtp(ftp, tran, fileFullPathNames);
    } else {
        // SFTP
        putFileBySFtp(ftp, tran, fileFullPathNames);
    }
    return true;
}
Also used : SysFtpTranVO(com.netsteadfast.greenstep.vo.SysFtpTranVO) IOException(java.io.IOException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) SysFtpVO(com.netsteadfast.greenstep.vo.SysFtpVO)

Example 4 with SysFtpTranVO

use of com.netsteadfast.greenstep.vo.SysFtpTranVO in project bamboobsc by billchen198318.

the class SystemFtpClientUtils method processText.

private static void processText(SystemFtpClientResultObj resultObj) throws Exception {
    SysFtpTranVO tran = resultObj.getSysFtpTran();
    List<SystemFtpClientData> datas = new LinkedList<SystemFtpClientData>();
    List<TbSysFtpTranSegm> segms = resultObj.getSysFtpTranSegms();
    for (File file : resultObj.getFiles()) {
        SystemFtpClientData ftpData = new SystemFtpClientData();
        List<Map<String, String>> fillDataList = new LinkedList<Map<String, String>>();
        logWarnFileSize(file);
        List<String> strLines = FileUtils.readLines(file, resultObj.getSysFtpTran().getEncoding());
        if (YesNo.YES.equals(resultObj.getSysFtpTran().getUseSegm())) {
            for (int i = 0; i < strLines.size(); i++) {
                String strData = strLines.get(i);
                if (strData.length() < 1) {
                    logger.warn("The file: " + file.getPath() + " found zero line.");
                    continue;
                }
                if (i < tran.getBeginLen()) {
                    // not begin line.
                    continue;
                }
                Map<String, String> dataMap = new HashMap<String, String>();
                fillStrLine2Map(resultObj.getSysFtpTran(), segms, dataMap, strData);
                fillDataList.add(dataMap);
            }
        }
        ftpData.setContent(getContent(strLines));
        ftpData.setDatas(fillDataList);
        ftpData.setFile(file);
        datas.add(ftpData);
    }
    resultObj.setDatas(datas);
}
Also used : TbSysFtpTranSegm(com.netsteadfast.greenstep.po.hbm.TbSysFtpTranSegm) HashMap(java.util.HashMap) SysFtpTranVO(com.netsteadfast.greenstep.vo.SysFtpTranVO) LinkedList(java.util.LinkedList) SystemFtpClientData(com.netsteadfast.greenstep.model.SystemFtpClientData) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with SysFtpTranVO

use of com.netsteadfast.greenstep.vo.SysFtpTranVO in project bamboobsc by billchen198318.

the class SystemFtpClientUtils method processXml.

private static void processXml(SystemFtpClientResultObj resultObj) throws Exception {
    SysFtpTranVO tran = resultObj.getSysFtpTran();
    List<SystemFtpClientData> datas = new LinkedList<SystemFtpClientData>();
    JAXBContext jaxbContext = null;
    Unmarshaller jaxbUnmarshaller = null;
    if (!StringUtils.isBlank(tran.getXmlClassName())) {
        Class<?> xmlBeanClazz = Class.forName(tran.getXmlClassName());
        jaxbContext = JAXBContext.newInstance(xmlBeanClazz);
        jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    }
    for (File file : resultObj.getFiles()) {
        SystemFtpClientData ftpData = new SystemFtpClientData();
        logWarnFileSize(file);
        // xml 原則上都是用utf-8
        String content = FileUtils.readFileToString(file, Constants.BASE_ENCODING);
        ftpData.setContent(content);
        ftpData.setDatas(null);
        ftpData.setFile(file);
        if (jaxbUnmarshaller != null) {
            Object obj = jaxbUnmarshaller.unmarshal(// xml 原則上都是用utf-8
            new ByteArrayInputStream(content.getBytes(Constants.BASE_ENCODING)));
            ftpData.setXmlBean(obj);
        }
        datas.add(ftpData);
    }
    resultObj.setDatas(datas);
}
Also used : SystemFtpClientData(com.netsteadfast.greenstep.model.SystemFtpClientData) ByteArrayInputStream(java.io.ByteArrayInputStream) JAXBContext(javax.xml.bind.JAXBContext) SysFtpTranVO(com.netsteadfast.greenstep.vo.SysFtpTranVO) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) LinkedList(java.util.LinkedList)

Aggregations

SysFtpTranVO (com.netsteadfast.greenstep.vo.SysFtpTranVO)7 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)4 SysFtpVO (com.netsteadfast.greenstep.vo.SysFtpVO)3 File (java.io.File)3 IOException (java.io.IOException)3 SystemFtpClientData (com.netsteadfast.greenstep.model.SystemFtpClientData)2 SystemFtpClientResultObj (com.netsteadfast.greenstep.model.SystemFtpClientResultObj)2 TbSysFtpTranSegm (com.netsteadfast.greenstep.po.hbm.TbSysFtpTranSegm)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Map (java.util.Map)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1