Program: 115164
Project: 115164
Buggy source:
@Override protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
  CoreResources cr=new CoreResources();
  Locale locale=new Locale("String_Node_Str");
  ResourceBundleProvider.updateLocale(locale);
  ResourceBundle pageMessages=ResourceBundleProvider.getPageMessagesBundle();
  List<File> markForDelete=new LinkedList<File>();
  Boolean zipped=true;
  Boolean deleteOld=true;
  Boolean exceptions=false;
  JobDataMap dataMap=context.getMergedJobDataMap();
  String localeStr=dataMap.getString(LOCALE);
  String[] doNotDeleteUntilExtract=new String[4];
  int cnt=dataMap.getInt("String_Node_Str");
  DatasetBean datasetBean=null;
  if (localeStr != null) {
    locale=new Locale(localeStr);
    ResourceBundleProvider.updateLocale(locale);
    pageMessages=ResourceBundleProvider.getPageMessagesBundle();
  }
  String alertEmail=dataMap.getString(EMAIL);
  java.io.InputStream in=null;
  FileOutputStream endFileStream=null;
  try {
    ApplicationContext appContext=(ApplicationContext)context.getScheduler().getContext().get("String_Node_Str");
    mailSender=(OpenClinicaMailSender)appContext.getBean("String_Node_Str");
    dataSource=(DataSource)appContext.getBean("String_Node_Str");
    coreResources=(CoreResources)appContext.getBean("String_Node_Str");
    ruleSetRuleDao=(RuleSetRuleDao)appContext.getBean("String_Node_Str");
    DatasetDAO dsdao=new DatasetDAO(dataSource);
    int userAccountId=dataMap.getInt(USER_ID);
    int studyId=dataMap.getInt(STUDY_ID);
    String outputPath=dataMap.getString(POST_FILE_PATH);
    logger.debug("String_Node_Str" + outputPath);
    String generalFileDir=dataMap.getString(XML_FILE_PATH);
    int epBeanId=dataMap.getInt(EXTRACT_PROPERTY);
    int dsId=dataMap.getInt(DATASET_ID);
    ExtractPropertyBean epBean=(ExtractPropertyBean)dataMap.get(EP_BEAN);
    File doNotDelDir=new File(generalFileDir);
    if (doNotDelDir.isDirectory()) {
      doNotDeleteUntilExtract=doNotDelDir.list();
    }
    zipped=epBean.getZipFormat();
    deleteOld=epBean.getDeleteOld();
    long sysTimeBegin=System.currentTimeMillis();
    userAccountDao=new UserAccountDAO(dataSource);
    UserAccountBean userBean=(UserAccountBean)userAccountDao.findByPK(userAccountId);
    generateFileService=new GenerateExtractFileService(dataSource,userBean,coreResources,ruleSetRuleDao);
    studyDao=new StudyDAO(dataSource);
    StudyBean currentStudy=(StudyBean)studyDao.findByPK(studyId);
    StudyBean parentStudy=(StudyBean)studyDao.findByPK(currentStudy.getParentStudyId());
    String successMsg=epBean.getSuccessMessage();
    String failureMsg=epBean.getFailureMessage();
    final long start=System.currentTimeMillis();
    datasetBean=(DatasetBean)dsdao.findByPK(dsId);
    ExtractBean eb=generateFileService.generateExtractBean(datasetBean,currentStudy,parentStudy);
    datasetBean.setName(datasetBean.getName().replaceAll("String_Node_Str","String_Node_Str"));
    logger.debug("String_Node_Str");
    HashMap answerMap=generateFileService.createODMFile(epBean.getFormat(),sysTimeBegin,generalFileDir,datasetBean,currentStudy,"String_Node_Str",eb,currentStudy.getId(),currentStudy.getParentStudyId(),"String_Node_Str",(Boolean)dataMap.get(ZIPPED),false,(Boolean)dataMap.get(DELETE_OLD),epBean.getOdmType());
    String ODMXMLFileName="String_Node_Str";
    int fId=0;
    for (Iterator it=answerMap.entrySet().iterator(); it.hasNext(); ) {
      java.util.Map.Entry entry=(java.util.Map.Entry)it.next();
      Object key=entry.getKey();
      Object value=entry.getValue();
      ODMXMLFileName=(String)key;
      Integer fileID=(Integer)value;
      fId=fileID.intValue();
      logger.debug("String_Node_Str" + fId + "String_Node_Str"+ ODMXMLFileName);
    }
    File output=new File(outputPath);
    if (!output.isDirectory()) {
      output.mkdirs();
    }
    TransformerFactory tFactory=TransformerFactory.newInstance();
    int numXLS=epBean.getFileName().length;
    int fileCntr=0;
    String xmlFilePath=generalFileDir + ODMXMLFileName;
    String endFile=null;
    File oldFilesPath=new File(generalFileDir);
    while (fileCntr < numXLS) {
      String xsltPath=dataMap.getString(XSLT_PATH) + File.separator + epBean.getFileName()[fileCntr];
      in=new java.io.FileInputStream(xsltPath);
      Transformer transformer=tFactory.newTransformer(new StreamSource(in));
      endFile=outputPath + File.separator + epBean.getExportFileName()[fileCntr];
      endFileStream=new FileOutputStream(endFile);
      transformer.transform(new StreamSource(xmlFilePath),new StreamResult(endFileStream));
      in.close();
      endFileStream.close();
      fileCntr++;
    }
    if (oldFilesPath.isDirectory()) {
      markForDelete=Arrays.asList(oldFilesPath.listFiles());
    }
    final double done=setFormat((new Double(System.currentTimeMillis() - start)) / 1000);
    logger.info("String_Node_Str" + done + "String_Node_Str");
    ProcessingFunction function=epBean.getPostProcessing();
    String subject="String_Node_Str";
    String jobName=dataMap.getString(XsltTriggerService.JOB_NAME);
    StringBuffer emailBuffer=new StringBuffer("String_Node_Str");
    emailBuffer.append("String_Node_Str" + pageMessages.getString("String_Node_Str") + "String_Node_Str"+ EmailEngine.getAdminEmail()+ "String_Node_Str"+ pageMessages.getString("String_Node_Str")+ "String_Node_Str"+ pageMessages.getString("String_Node_Str")+ "String_Node_Str");
    emailBuffer.append("String_Node_Str" + datasetBean.getName() + "String_Node_Str");
    emailBuffer.append("String_Node_Str" + currentStudy.getName() + "String_Node_Str");
    if (function != null && function.getClass().equals(org.akaza.openclinica.bean.service.SqlProcessingFunction.class)) {
      String dbUrl=((org.akaza.openclinica.bean.service.SqlProcessingFunction)function).getDatabaseUrl();
      int lastIndex=dbUrl.lastIndexOf("String_Node_Str");
      String schemaName=dbUrl.substring(lastIndex);
      int HostIndex=dbUrl.substring(0,lastIndex).indexOf("String_Node_Str");
      String Host=dbUrl.substring(HostIndex,lastIndex);
      emailBuffer.append("String_Node_Str" + ((org.akaza.openclinica.bean.service.SqlProcessingFunction)function).getDatabaseType() + "String_Node_Str");
      emailBuffer.append("String_Node_Str" + schemaName.replace("String_Node_Str","String_Node_Str") + "String_Node_Str");
      emailBuffer.append("String_Node_Str" + Host.replace("String_Node_Str","String_Node_Str") + "String_Node_Str");
    }
    emailBuffer.append("String_Node_Str" + pageMessages.getString("String_Node_Str") + datasetBean.getName()+ pageMessages.getString("String_Node_Str")+ "String_Node_Str");
    if (function != null) {
      function.setTransformFileName(outputPath + File.separator + dataMap.getString(POST_FILE_NAME));
      function.setODMXMLFileName(endFile);
      function.setXslFileName(dataMap.getString(XSL_FILE_PATH));
      function.setDeleteOld((Boolean)dataMap.get(POST_PROC_DELETE_OLD));
      function.setZip((Boolean)dataMap.get(POST_PROC_ZIP));
      function.setLocation(dataMap.getString(POST_PROC_LOCATION));
      function.setExportFileName(dataMap.getString(POST_PROC_EXPORT_NAME));
      File oldFiles[]=getOldFiles(outputPath,dataMap.getString(POST_PROC_LOCATION));
      function.setOldFiles(oldFiles);
      File intermediateFiles[]=getInterFiles(dataMap.getString(POST_FILE_PATH));
      ProcessingResultType message=function.run();
      if (message.getCode().intValue() != 2)       deleteOldFiles(intermediateFiles);
      final long done2=System.currentTimeMillis() - start;
      logger.info("String_Node_Str" + done2 + "String_Node_Str"+ message.getCode());
      logger.info("String_Node_Str" + done2 + "String_Node_Str"+ message.getCode());
      if (!function.getClass().equals(org.akaza.openclinica.bean.service.SqlProcessingFunction.class)) {
        String archivedFile=dataMap.getString(POST_FILE_NAME) + "String_Node_Str" + function.getFileType();
        if (function.isZip())         archivedFile=archivedFile + "String_Node_Str";
        if (function.getClass().equals(org.akaza.openclinica.bean.service.PdfProcessingFunction.class))         archivedFile=function.getArchivedFileName();
        ArchivedDatasetFileBean fbFinal=generateFileRecord(archivedFile,outputPath,datasetBean,done,new File(outputPath + File.separator + archivedFile).length(),ExportFormatBean.PDFFILE,userAccountId);
        if (successMsg == null || successMsg.isEmpty()) {
        }
        if (successMsg.contains("String_Node_Str")) {
          successMsg=successMsg.replace("String_Node_Str","String_Node_Str" + CoreResources.getField("String_Node_Str") + "String_Node_Str"+ fbFinal.getId()+ "String_Node_Str"+ CoreResources.getField("String_Node_Str")+ "String_Node_Str"+ fbFinal.getId()+ "String_Node_Str");
        }
        emailBuffer.append("String_Node_Str" + successMsg + "String_Node_Str");
        logMe("String_Node_Str" + sysTimeBegin);
        logMe("String_Node_Str" + System.currentTimeMillis());
        double sysTimeEnd=setFormat((System.currentTimeMillis() - sysTimeBegin) / 1000);
        logMe("String_Node_Str" + sysTimeEnd);
        if (fbFinal != null) {
          fbFinal.setFileSize((int)bytesToKilo(new File(archivedFile).length()));
          fbFinal.setRunTime(sysTimeEnd);
        }
      }
      if (message.getCode().intValue() == 1) {
        if (jobName != null) {
          subject="String_Node_Str" + jobName;
        }
 else {
          subject="String_Node_Str" + datasetBean.getName();
        }
      }
 else       if (message.getCode().intValue() == 2) {
        if (jobName != null) {
          subject="String_Node_Str" + jobName;
        }
 else {
          subject="String_Node_Str" + datasetBean.getName();
        }
        if (failureMsg != null && !failureMsg.isEmpty()) {
          emailBuffer.append(failureMsg);
        }
        emailBuffer.append("String_Node_Str" + message.getDescription());
        postErrorMessage(message.getDescription(),context);
      }
 else       if (message.getCode().intValue() == 3) {
        if (jobName != null) {
          subject="String_Node_Str" + jobName;
        }
 else {
          subject="String_Node_Str" + datasetBean.getName();
        }
      }
    }
 else {
      String archivedFilename=dataMap.getString(POST_FILE_NAME);
      if (zipped)       archivedFilename=dataMap.getString(POST_FILE_NAME) + "String_Node_Str";
      List<File> intermediateFiles=generateFileService.getOldFiles();
      String[] dontDelFiles=epBean.getDoNotDelFiles();
      if (dontDelFiles.length > 1 && zipped) {
        logMe("String_Node_Str" + cnt + "String_Node_Str"+ dontDelFiles.length);
        logMe("String_Node_Str" + cnt + "String_Node_Str"+ dontDelFiles);
        File temp=new File(endFile);
        String path=outputPath + File.separator;
        logMe("String_Node_Str" + path);
        logMe("String_Node_Str" + epBean.getZipName());
        String zipName=(epBean.getZipName() == null || epBean.getZipName().isEmpty()) ? endFile + "String_Node_Str" : path + epBean.getZipName() + "String_Node_Str";
        archivedFilename=new File(zipName).getName();
        zipAll(path,epBean.getDoNotDelFiles(),zipName);
        String[] tempArray={archivedFilename};
        dontDelFiles=tempArray;
        endFile=archivedFilename;
      }
 else       if (zipped) {
        markForDelete=zipxmls(markForDelete,endFile);
        endFile=endFile + "String_Node_Str";
        String[] temp=new String[dontDelFiles.length];
        int i=0;
        while (i < dontDelFiles.length) {
          temp[i]=dontDelFiles[i] + "String_Node_Str";
          i++;
        }
        dontDelFiles=temp;
        FilenameFilter xmlFilter=new XMLFileFilter();
        File tempFile=new File(generalFileDir);
        deleteOldFiles(tempFile.listFiles(xmlFilter));
      }
      final double sysTimeEnd=setFormat((System.currentTimeMillis() - start) / 60000);
      ArchivedDatasetFileBean fbFinal=generateFileRecord(archivedFilename,outputPath,datasetBean,done,new File(outputPath + File.separator + archivedFilename).length(),ExportFormatBean.TXTFILE,userAccountId);
      if (jobName != null) {
        subject="String_Node_Str" + jobName;
      }
 else {
        subject="String_Node_Str" + datasetBean.getName();
      }
      if (successMsg == null || successMsg.isEmpty()) {
        logger.info("String_Node_Str" + emailBuffer);
      }
 else {
        if (successMsg.contains("String_Node_Str")) {
          successMsg=successMsg.replace("String_Node_Str","String_Node_Str" + CoreResources.getField("String_Node_Str") + "String_Node_Str"+ fbFinal.getId()+ "String_Node_Str"+ CoreResources.getField("String_Node_Str")+ "String_Node_Str"+ fbFinal.getId()+ "String_Node_Str");
        }
        emailBuffer.append("String_Node_Str" + successMsg + "String_Node_Str");
      }
      if (deleteOld) {
        deleteIntermFiles(intermediateFiles,endFile,dontDelFiles);
        deleteIntermFiles(markForDelete,endFile,dontDelFiles);
      }
    }
    emailBuffer.append("String_Node_Str" + pageMessages.getString("String_Node_Str") + "String_Node_Str");
    try {
      mailSender.sendEmail(alertEmail,EmailEngine.getAdminEmail(),subject,emailBuffer.toString(),true);
    }
 catch (    OpenClinicaSystemException ose) {
      logger.info("String_Node_Str" + ose.getMessage());
      logger.error("String_Node_Str" + ose.getMessage());
    }
    logger.info("String_Node_Str" + alertEmail + "String_Node_Str"+ EmailEngine.getAdminEmail());
    if (successMsg == null)     successMsg="String_Node_Str";
    postSuccessMessage(successMsg,context);
    logMe(emailBuffer.toString());
  }
 catch (  TransformerConfigurationException e) {
    sendErrorEmail(e.getMessage(),context,alertEmail);
    postErrorMessage(e.getMessage(),context);
    e.printStackTrace();
    logger.error(e.getStackTrace().toString());
    exceptions=true;
  }
catch (  FileNotFoundException e) {
    sendErrorEmail(e.getMessage(),context,alertEmail);
    postErrorMessage(e.getMessage(),context);
    e.printStackTrace();
    logger.error(e.getStackTrace().toString());
    exceptions=true;
  }
catch (  TransformerFactoryConfigurationError e) {
    sendErrorEmail(e.getMessage(),context,alertEmail);
    postErrorMessage(e.getMessage(),context);
    e.printStackTrace();
    logger.error(e.getStackTrace().toString());
    exceptions=true;
  }
catch (  TransformerException e) {
    sendErrorEmail(e.getMessage(),context,alertEmail);
    postErrorMessage(e.getMessage(),context);
    e.printStackTrace();
    logger.error(e.getStackTrace().toString());
    exceptions=true;
  }
catch (  Exception ee) {
    sendErrorEmail(ee.getMessage(),context,alertEmail);
    postErrorMessage(ee.getMessage(),context);
    ee.printStackTrace();
    logger.error(ee.getStackTrace().toString());
    exceptions=true;
  }
 finally {
    if (in != null)     try {
      in.close();
    }
 catch (    IOException e) {
      e.printStackTrace();
    }
    if (endFileStream != null)     try {
      endFileStream.close();
    }
 catch (    IOException e) {
      e.printStackTrace();
    }
    if (exceptions) {
      logger.debug("String_Node_Str");
      String generalFileDir=dataMap.getString(XML_FILE_PATH);
      File oldFilesPath=new File(generalFileDir);
      String endFile="String_Node_Str";
      ExtractPropertyBean epBean=(ExtractPropertyBean)dataMap.get(EP_BEAN);
      endFile=dataMap.getString(POST_FILE_PATH) + File.separator + dataMap.getString(POST_FILE_NAME);
      if (oldFilesPath.isDirectory()) {
        markForDelete=Arrays.asList(oldFilesPath.listFiles());
      }
      logger.debug("String_Node_Str");
      if (deleteOld) {
        deleteIntermFiles(markForDelete,endFile,doNotDeleteUntilExtract);
      }
    }
    if (datasetBean != null)     resetArchiveDataset(datasetBean.getId());
  }
}

Fixed version (ground truth):
@Override protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
  CoreResources cr=new CoreResources();
  Locale locale=new Locale("String_Node_Str");
  ResourceBundleProvider.updateLocale(locale);
  ResourceBundle pageMessages=ResourceBundleProvider.getPageMessagesBundle();
  List<File> markForDelete=new LinkedList<File>();
  Boolean zipped=true;
  Boolean deleteOld=true;
  Boolean exceptions=false;
  JobDataMap dataMap=context.getMergedJobDataMap();
  String localeStr=dataMap.getString(LOCALE);
  String[] doNotDeleteUntilExtract=new String[4];
  int cnt=dataMap.getInt("String_Node_Str");
  DatasetBean datasetBean=null;
  if (localeStr != null) {
    locale=new Locale(localeStr);
    ResourceBundleProvider.updateLocale(locale);
    pageMessages=ResourceBundleProvider.getPageMessagesBundle();
  }
  String alertEmail=dataMap.getString(EMAIL);
  java.io.InputStream in=null;
  FileOutputStream endFileStream=null;
  UserAccountBean userBean=null;
  try {
    ApplicationContext appContext=(ApplicationContext)context.getScheduler().getContext().get("String_Node_Str");
    mailSender=(OpenClinicaMailSender)appContext.getBean("String_Node_Str");
    dataSource=(DataSource)appContext.getBean("String_Node_Str");
    coreResources=(CoreResources)appContext.getBean("String_Node_Str");
    ruleSetRuleDao=(RuleSetRuleDao)appContext.getBean("String_Node_Str");
    auditEventDAO=new AuditEventDAO(dataSource);
    StringBuffer auditMessage=new StringBuffer();
    DatasetDAO dsdao=new DatasetDAO(dataSource);
    int userAccountId=dataMap.getInt(USER_ID);
    int studyId=dataMap.getInt(STUDY_ID);
    String outputPath=dataMap.getString(POST_FILE_PATH);
    logger.debug("String_Node_Str" + outputPath);
    String generalFileDir=dataMap.getString(XML_FILE_PATH);
    int epBeanId=dataMap.getInt(EXTRACT_PROPERTY);
    int dsId=dataMap.getInt(DATASET_ID);
    ExtractPropertyBean epBean=(ExtractPropertyBean)dataMap.get(EP_BEAN);
    File doNotDelDir=new File(generalFileDir);
    if (doNotDelDir.isDirectory()) {
      doNotDeleteUntilExtract=doNotDelDir.list();
    }
    zipped=epBean.getZipFormat();
    deleteOld=epBean.getDeleteOld();
    long sysTimeBegin=System.currentTimeMillis();
    userAccountDao=new UserAccountDAO(dataSource);
    userBean=(UserAccountBean)userAccountDao.findByPK(userAccountId);
    generateFileService=new GenerateExtractFileService(dataSource,userBean,coreResources,ruleSetRuleDao);
    studyDao=new StudyDAO(dataSource);
    StudyBean currentStudy=(StudyBean)studyDao.findByPK(studyId);
    StudyBean parentStudy=(StudyBean)studyDao.findByPK(currentStudy.getParentStudyId());
    String successMsg=epBean.getSuccessMessage();
    String failureMsg=epBean.getFailureMessage();
    final long start=System.currentTimeMillis();
    datasetBean=(DatasetBean)dsdao.findByPK(dsId);
    ExtractBean eb=generateFileService.generateExtractBean(datasetBean,currentStudy,parentStudy);
    datasetBean.setName(datasetBean.getName().replaceAll("String_Node_Str","String_Node_Str"));
    logger.debug("String_Node_Str");
    HashMap answerMap=generateFileService.createODMFile(epBean.getFormat(),sysTimeBegin,generalFileDir,datasetBean,currentStudy,"String_Node_Str",eb,currentStudy.getId(),currentStudy.getParentStudyId(),"String_Node_Str",(Boolean)dataMap.get(ZIPPED),false,(Boolean)dataMap.get(DELETE_OLD),epBean.getOdmType());
    String ODMXMLFileName="String_Node_Str";
    int fId=0;
    for (Iterator it=answerMap.entrySet().iterator(); it.hasNext(); ) {
      java.util.Map.Entry entry=(java.util.Map.Entry)it.next();
      Object key=entry.getKey();
      Object value=entry.getValue();
      ODMXMLFileName=(String)key;
      Integer fileID=(Integer)value;
      fId=fileID.intValue();
      logger.debug("String_Node_Str" + fId + "String_Node_Str"+ ODMXMLFileName);
    }
    File output=new File(outputPath);
    if (!output.isDirectory()) {
      output.mkdirs();
    }
    TransformerFactory tFactory=TransformerFactory.newInstance();
    int numXLS=epBean.getFileName().length;
    int fileCntr=0;
    String xmlFilePath=generalFileDir + ODMXMLFileName;
    String endFile=null;
    File oldFilesPath=new File(generalFileDir);
    while (fileCntr < numXLS) {
      String xsltPath=dataMap.getString(XSLT_PATH) + File.separator + epBean.getFileName()[fileCntr];
      in=new java.io.FileInputStream(xsltPath);
      Transformer transformer=tFactory.newTransformer(new StreamSource(in));
      endFile=outputPath + File.separator + epBean.getExportFileName()[fileCntr];
      endFileStream=new FileOutputStream(endFile);
      transformer.transform(new StreamSource(xmlFilePath),new StreamResult(endFileStream));
      in.close();
      endFileStream.close();
      fileCntr++;
    }
    if (oldFilesPath.isDirectory()) {
      markForDelete=Arrays.asList(oldFilesPath.listFiles());
    }
    final double done=setFormat((new Double(System.currentTimeMillis() - start)) / 1000);
    logger.info("String_Node_Str" + done + "String_Node_Str");
    ProcessingFunction function=epBean.getPostProcessing();
    String subject="String_Node_Str";
    String jobName=dataMap.getString(XsltTriggerService.JOB_NAME);
    StringBuffer emailBuffer=new StringBuffer("String_Node_Str");
    emailBuffer.append("String_Node_Str" + pageMessages.getString("String_Node_Str") + "String_Node_Str"+ EmailEngine.getAdminEmail()+ "String_Node_Str"+ pageMessages.getString("String_Node_Str")+ "String_Node_Str"+ pageMessages.getString("String_Node_Str")+ "String_Node_Str");
    emailBuffer.append("String_Node_Str" + datasetBean.getName() + "String_Node_Str");
    emailBuffer.append("String_Node_Str" + currentStudy.getName() + "String_Node_Str");
    if (function != null && function.getClass().equals(org.akaza.openclinica.bean.service.SqlProcessingFunction.class)) {
      String dbUrl=((org.akaza.openclinica.bean.service.SqlProcessingFunction)function).getDatabaseUrl();
      int lastIndex=dbUrl.lastIndexOf("String_Node_Str");
      String schemaName=dbUrl.substring(lastIndex);
      int HostIndex=dbUrl.substring(0,lastIndex).indexOf("String_Node_Str");
      String Host=dbUrl.substring(HostIndex,lastIndex);
      emailBuffer.append("String_Node_Str" + ((org.akaza.openclinica.bean.service.SqlProcessingFunction)function).getDatabaseType() + "String_Node_Str");
      emailBuffer.append("String_Node_Str" + schemaName.replace("String_Node_Str","String_Node_Str") + "String_Node_Str");
      emailBuffer.append("String_Node_Str" + Host.replace("String_Node_Str","String_Node_Str") + "String_Node_Str");
    }
    emailBuffer.append("String_Node_Str" + pageMessages.getString("String_Node_Str") + datasetBean.getName()+ pageMessages.getString("String_Node_Str")+ "String_Node_Str");
    if (function != null) {
      function.setTransformFileName(outputPath + File.separator + dataMap.getString(POST_FILE_NAME));
      function.setODMXMLFileName(endFile);
      function.setXslFileName(dataMap.getString(XSL_FILE_PATH));
      function.setDeleteOld((Boolean)dataMap.get(POST_PROC_DELETE_OLD));
      function.setZip((Boolean)dataMap.get(POST_PROC_ZIP));
      function.setLocation(dataMap.getString(POST_PROC_LOCATION));
      function.setExportFileName(dataMap.getString(POST_PROC_EXPORT_NAME));
      File oldFiles[]=getOldFiles(outputPath,dataMap.getString(POST_PROC_LOCATION));
      function.setOldFiles(oldFiles);
      File intermediateFiles[]=getInterFiles(dataMap.getString(POST_FILE_PATH));
      ProcessingResultType message=function.run();
      if (message.getCode().intValue() != 2)       deleteOldFiles(intermediateFiles);
      final long done2=System.currentTimeMillis() - start;
      logger.info("String_Node_Str" + done2 + "String_Node_Str"+ message.getCode());
      logger.info("String_Node_Str" + done2 + "String_Node_Str"+ message.getCode());
      if (!function.getClass().equals(org.akaza.openclinica.bean.service.SqlProcessingFunction.class)) {
        String archivedFile=dataMap.getString(POST_FILE_NAME) + "String_Node_Str" + function.getFileType();
        if (function.isZip())         archivedFile=archivedFile + "String_Node_Str";
        if (function.getClass().equals(org.akaza.openclinica.bean.service.PdfProcessingFunction.class))         archivedFile=function.getArchivedFileName();
        ArchivedDatasetFileBean fbFinal=generateFileRecord(archivedFile,outputPath,datasetBean,done,new File(outputPath + File.separator + archivedFile).length(),ExportFormatBean.PDFFILE,userAccountId);
        if (successMsg == null || successMsg.isEmpty()) {
        }
        if (successMsg.contains("String_Node_Str")) {
          successMsg=successMsg.replace("String_Node_Str","String_Node_Str" + CoreResources.getField("String_Node_Str") + "String_Node_Str"+ fbFinal.getId()+ "String_Node_Str"+ CoreResources.getField("String_Node_Str")+ "String_Node_Str"+ fbFinal.getId()+ "String_Node_Str");
        }
        emailBuffer.append("String_Node_Str" + successMsg + "String_Node_Str");
        logMe("String_Node_Str" + sysTimeBegin);
        logMe("String_Node_Str" + System.currentTimeMillis());
        double sysTimeEnd=setFormat((System.currentTimeMillis() - sysTimeBegin) / 1000);
        logMe("String_Node_Str" + sysTimeEnd);
        if (fbFinal != null) {
          fbFinal.setFileSize((int)bytesToKilo(new File(archivedFile).length()));
          fbFinal.setRunTime(sysTimeEnd);
        }
      }
      if (message.getCode().intValue() == 1) {
        if (jobName != null) {
          subject="String_Node_Str" + jobName;
        }
 else {
          subject="String_Node_Str" + datasetBean.getName();
        }
      }
 else       if (message.getCode().intValue() == 2) {
        if (jobName != null) {
          subject="String_Node_Str" + jobName;
        }
 else {
          subject="String_Node_Str" + datasetBean.getName();
        }
        if (failureMsg != null && !failureMsg.isEmpty()) {
          emailBuffer.append(failureMsg);
        }
        emailBuffer.append("String_Node_Str" + message.getDescription());
        postErrorMessage(message.getDescription(),context);
      }
 else       if (message.getCode().intValue() == 3) {
        if (jobName != null) {
          subject="String_Node_Str" + jobName;
        }
 else {
          subject="String_Node_Str" + datasetBean.getName();
        }
      }
    }
 else {
      String archivedFilename=dataMap.getString(POST_FILE_NAME);
      if (zipped)       archivedFilename=dataMap.getString(POST_FILE_NAME) + "String_Node_Str";
      List<File> intermediateFiles=generateFileService.getOldFiles();
      String[] dontDelFiles=epBean.getDoNotDelFiles();
      if (dontDelFiles.length > 1 && zipped) {
        logMe("String_Node_Str" + cnt + "String_Node_Str"+ dontDelFiles.length);
        logMe("String_Node_Str" + cnt + "String_Node_Str"+ dontDelFiles);
        File temp=new File(endFile);
        String path=outputPath + File.separator;
        logMe("String_Node_Str" + path);
        logMe("String_Node_Str" + epBean.getZipName());
        String zipName=(epBean.getZipName() == null || epBean.getZipName().isEmpty()) ? endFile + "String_Node_Str" : path + epBean.getZipName() + "String_Node_Str";
        archivedFilename=new File(zipName).getName();
        zipAll(path,epBean.getDoNotDelFiles(),zipName);
        String[] tempArray={archivedFilename};
        dontDelFiles=tempArray;
        endFile=archivedFilename;
      }
 else       if (zipped) {
        markForDelete=zipxmls(markForDelete,endFile);
        endFile=endFile + "String_Node_Str";
        String[] temp=new String[dontDelFiles.length];
        int i=0;
        while (i < dontDelFiles.length) {
          temp[i]=dontDelFiles[i] + "String_Node_Str";
          i++;
        }
        dontDelFiles=temp;
        FilenameFilter xmlFilter=new XMLFileFilter();
        File tempFile=new File(generalFileDir);
        deleteOldFiles(tempFile.listFiles(xmlFilter));
      }
      final double sysTimeEnd=setFormat((System.currentTimeMillis() - start) / 60000);
      ArchivedDatasetFileBean fbFinal=generateFileRecord(archivedFilename,outputPath,datasetBean,done,new File(outputPath + File.separator + archivedFilename).length(),ExportFormatBean.TXTFILE,userAccountId);
      if (jobName != null) {
        subject="String_Node_Str" + jobName;
      }
 else {
        subject="String_Node_Str" + datasetBean.getName();
      }
      if (successMsg == null || successMsg.isEmpty()) {
        logger.info("String_Node_Str" + emailBuffer);
      }
 else {
        if (successMsg.contains("String_Node_Str")) {
          successMsg=successMsg.replace("String_Node_Str","String_Node_Str" + CoreResources.getField("String_Node_Str") + "String_Node_Str"+ fbFinal.getId()+ "String_Node_Str"+ CoreResources.getField("String_Node_Str")+ "String_Node_Str"+ fbFinal.getId()+ "String_Node_Str");
        }
        emailBuffer.append("String_Node_Str" + successMsg + "String_Node_Str");
      }
      if (deleteOld) {
        deleteIntermFiles(intermediateFiles,endFile,dontDelFiles);
        deleteIntermFiles(markForDelete,endFile,dontDelFiles);
      }
    }
    emailBuffer.append("String_Node_Str" + pageMessages.getString("String_Node_Str") + "String_Node_Str");
    try {
      mailSender.sendEmail(alertEmail,EmailEngine.getAdminEmail(),subject,emailBuffer.toString(),true);
      String extractName=(String)dataMap.get(XsltTriggerService.JOB_NAME);
      TriggerBean triggerBean=new TriggerBean();
      triggerBean.setDataset(datasetBean);
      triggerBean.setUserAccount(userBean);
      triggerBean.setFullName(extractName);
      String actionMsg="String_Node_Str" + (String)dataMap.get(XsltTriggerService.EXPORT_FORMAT) + "String_Node_Str"+ currentStudy.getName()+ "String_Node_Str"+ datasetBean.getName()+ "String_Node_Str";
      auditEventDAO.createRowForExtractDataJobSuccess(triggerBean,actionMsg);
    }
 catch (    OpenClinicaSystemException ose) {
      logger.info("String_Node_Str" + ose.getMessage());
      logger.error("String_Node_Str" + ose.getMessage());
    }
    logger.info("String_Node_Str" + alertEmail + "String_Node_Str"+ EmailEngine.getAdminEmail());
    if (successMsg == null)     successMsg="String_Node_Str";
    postSuccessMessage(successMsg,context);
    logMe(emailBuffer.toString());
  }
 catch (  TransformerConfigurationException e) {
    sendErrorEmail(e.getMessage(),context,alertEmail);
    postErrorMessage(e.getMessage(),context);
    e.printStackTrace();
    logger.error(e.getStackTrace().toString());
    exceptions=true;
  }
catch (  FileNotFoundException e) {
    sendErrorEmail(e.getMessage(),context,alertEmail);
    postErrorMessage(e.getMessage(),context);
    e.printStackTrace();
    logger.error(e.getStackTrace().toString());
    exceptions=true;
  }
catch (  TransformerFactoryConfigurationError e) {
    sendErrorEmail(e.getMessage(),context,alertEmail);
    postErrorMessage(e.getMessage(),context);
    e.printStackTrace();
    logger.error(e.getStackTrace().toString());
    exceptions=true;
  }
catch (  TransformerException e) {
    sendErrorEmail(e.getMessage(),context,alertEmail);
    postErrorMessage(e.getMessage(),context);
    e.printStackTrace();
    logger.error(e.getStackTrace().toString());
    exceptions=true;
  }
catch (  Exception ee) {
    sendErrorEmail(ee.getMessage(),context,alertEmail);
    postErrorMessage(ee.getMessage(),context);
    ee.printStackTrace();
    logger.error(ee.getStackTrace().toString());
    exceptions=true;
    TriggerBean triggerBean=new TriggerBean();
    triggerBean.setUserAccount(userBean);
    triggerBean.setFullName((String)dataMap.get(XsltTriggerService.JOB_NAME));
    auditEventDAO.createRowForExtractDataJobFailure(triggerBean);
  }
 finally {
    if (in != null)     try {
      in.close();
    }
 catch (    IOException e) {
      e.printStackTrace();
    }
    if (endFileStream != null)     try {
      endFileStream.close();
    }
 catch (    IOException e) {
      e.printStackTrace();
    }
    if (exceptions) {
      logger.debug("String_Node_Str");
      String generalFileDir=dataMap.getString(XML_FILE_PATH);
      File oldFilesPath=new File(generalFileDir);
      String endFile="String_Node_Str";
      ExtractPropertyBean epBean=(ExtractPropertyBean)dataMap.get(EP_BEAN);
      endFile=dataMap.getString(POST_FILE_PATH) + File.separator + dataMap.getString(POST_FILE_NAME);
      if (oldFilesPath.isDirectory()) {
        markForDelete=Arrays.asList(oldFilesPath.listFiles());
      }
      logger.debug("String_Node_Str");
      if (deleteOld) {
        deleteIntermFiles(markForDelete,endFile,doNotDeleteUntilExtract);
      }
    }
    if (datasetBean != null)     resetArchiveDataset(datasetBean.getId());
  }
}