AnsweredAssumed Answered

Looking for Gel Script to create a tab separated file and move file on MFTP server

Question asked by shalinee on Jan 25, 2017
Latest reply on Jan 26, 2017 by shalinee

Hi ,

 

We are currently using the java program to move the output file from Clarity Application server to MFTP server. Below is the attached sample code of java program.

 

package com.abc.xyz.clarity.z;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import com.niku.union.interfaces.SchedulerListener;
import com.niku.union.interfaces.JobSchedulerContext;

import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;

public class MFTFileCopyZ implements SchedulerListener

{
//@Override
public void scheduledEventFired(JobSchedulerContext jobContext_) throws Exception {
if(jobContext_ == null) {
throw new Exception("Invalid JobContext");
}
try {
final String args[] = {};
main(args);

} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException {
copyFiles();
}
public static void copyFiles() {


final Logger logger = Logger.getLogger(MFTFileCopyZ.class.getName());
FileHandler fh = null;
try {
fh=new FileHandler("loggerZ.log", false);
} catch (SecurityException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
fh.setFormatter(new SimpleFormatter());
logger.addHandler(fh);
logger.setLevel(Level.CONFIG);
boolean successful = false;

DateFormat df = new SimpleDateFormat("yyyy-MM-dd_hh_mm_ss");
df.setTimeZone(TimeZone.getTimeZone("PST"));
String today=df.format(new Date());

String recipients[] = new String [2];
recipients[0]=UtilInterfaces.getClearPropertyValue("FAILURE_EMAIL_NOTIFY1");
recipients[1]=UtilInterfaces.getClearPropertyValue("FAILURE_EMAIL_NOTIFY2");
final String MFT_SOURCE_FOLDER = UtilInterfaces.getClearPropertyValue("MFT_SOURCE_FOLDER");//location on Shared drive
final String MFT_TARGET_FOLDER = UtilInterfaces.getClearPropertyValue("MFT_TARGET_FOLDER");//location on MFT drive specified as SMB(MFT) share
final String MFT_ARCH_TARGET_FOLDER = UtilInterfaces.getClearPropertyValue("MFT_ARCH_TARGET_FOLDER");//archive location on local drive specified as SMB(MFT) share
final String SOURCE_FILE_NAME = UtilInterfaces.getClearPropertyValue("SOURCE_FILE_NAME");//wildcard search for MFT file
String DOMAIN = UtilInterfaces.getEncryptedPropertyValue("mft_domain");
String USER_NAME = UtilInterfaces.getEncryptedPropertyValue("mft_user_name");
String PASSWORD = UtilInterfaces.getEncryptedPropertyValue("mft_password");

try{

NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(DOMAIN, USER_NAME, PASSWORD);

SmbFile srcdir = new SmbFile(MFT_SOURCE_FOLDER, auth);
final SmbFile[] wildcard = srcdir.listFiles(SOURCE_FILE_NAME);
String NEWSOURCE=wildcard[0].toString();
SmbFile MFTlocalfile = new SmbFile(NEWSOURCE, auth);
final String arch_target= MFT_ARCH_TARGET_FOLDER+SOURCE_FILE_NAME.toString().substring(0,16)+"-"+today+".dat";
final String MFTtargetfile= MFT_TARGET_FOLDER+SOURCE_FILE_NAME;
SmbFile archSMBfile= new SmbFile(arch_target,auth);
SmbFile workingSMBfile = new SmbFile (MFTtargetfile,auth);
//copy working file MFT from local working file/folder to MFT share folder
workingSMBfile.createNewFile();
MFTlocalfile.copyTo(workingSMBfile);
//copy MFT working file to local archive folder
archSMBfile.createNewFile();
MFTlocalfile.copyTo(archSMBfile);
//Delete MFT file from location only if file has been copied to local archive and working file has been copied to MFT share
if ( workingSMBfile.exists() && archSMBfile.exists() ) {
MFTlocalfile.delete();
System.out.println("delete() invoked");
successful = true;
}

else{
logger.log(Level.WARNING,"Files not processed");
String message = "File Actions Failed";
UtilInterfaces.postMail("File Actions Failed", message, recipients, null);
}
if (successful == false){
logger.log(Level.WARNING,"Main Program Error");
//send email to Clarity Team in case of failure
String message = "File Actions Failed";
UtilInterfaces.postMail("File Actions Failed", message, recipients, null);
}

} catch (Exception e) {
}

}
}

 

I am looking for a gel sample to use the attached java code to transfer the file on mftp server or other gel code which will export the data in tab separated file and transfer on MFTP server.

 

 

 

Thanks,

Shal.

Attachments

Outcomes