Exemple #1
0
 public void renameDataSourceDir(String oldDataSourceId, String newDataSourceId)
     throws FileNotFoundException, IOException {
   File dataSourceDir = getDataSourceDir(oldDataSourceId);
   if (dataSourceDir.exists()) {
     dataSourceDir.renameTo(getDataSourceDir(newDataSourceId));
   }
 }
Exemple #2
0
  /**
   * Empty repository directory, record count and specific Data Source temporary files and
   * directories.
   *
   * @throws Exception
   */
  public void cleanUp() throws IOException {
    // Delete records indexes
    for (AccessPoint accessPoint : getAccessPoints().values()) {
      try {
        RepoxContextUtil.getRepoxManager().getAccessPointsManager().emptyIndex(this, accessPoint);
        log.info("Emptied AccessPoint with id " + accessPoint.getId());
      } catch (Exception e) {
        log.error("Unable to empty Table from Database: " + accessPoint.getId(), e);
      }
    }

    File dataSourceDir = getDataSourceDir();

    boolean deletedDir = true;
    if (dataSourceDir.exists()) {
      deletedDir = FileUtil.deleteDir(dataSourceDir);
      dataSourceDir.mkdir();
    }

    if (!deletedDir) {
      log.error("Unable to delete Data Source dir from Data Source with id " + id);
    } else {
      log.info("Deleted Data Source dir with success from Data Source with id " + id);
    }

    RepoxContextUtil.getRepoxManager().getRecordCountManager().removeDataSourceCounts(id);
  }
Exemple #3
0
 public String getSynchronizationDateString() throws FileNotFoundException, IOException {
   File syncDateFile = getSyncDateFile();
   if (!syncDateFile.exists()) {
     return null;
   }
   String syncDate = FileUtil.readFileToString(syncDateFile);
   return syncDate;
 }
Exemple #4
0
 private File getLogFile(String taskId) {
   String yearMonthString =
       Calendar.getInstance().get(Calendar.YEAR)
           + "-"
           + (Calendar.getInstance().get(Calendar.MONTH) + 1);
   File logsMonthDir = new File(getLogsDir(), yearMonthString);
   logsMonthDir.mkdir();
   File logFile =
       new File(
           logsMonthDir,
           taskId
               + "_"
               + DateFormatUtils.format(new Date(), TimeUtil.LONG_DATE_FORMAT_COMPACT)
               + ".log");
   return logFile;
 }
Exemple #5
0
  protected int getLastTaskId() throws IOException {
    int lastId = 0;

    File lastTaskFile = new File(getTasksDir(), LAST_TASK_FILENAME);
    if (lastTaskFile.exists()) {
      BufferedReader reader =
          new BufferedReader(new InputStreamReader(new FileInputStream(lastTaskFile)));
      String currentLine;
      if ((currentLine = reader.readLine()) != null) {
        try {
          lastId = Integer.parseInt(currentLine);
        } catch (NumberFormatException e) {
          log.error("Trying to parse as int: " + currentLine, e);
        }
      }
    }

    return lastId;
  }
Exemple #6
0
  protected void setLastTaskId(int taskId) throws IOException {
    File lastTaskFile = new File(getTasksDir(), LAST_TASK_FILENAME);
    if (lastTaskFile.exists()) {
      File backupFile = new File(lastTaskFile.getParent(), lastTaskFile.getName() + ".bkp");
      FileUtil.copyFile(lastTaskFile, backupFile);
    }

    BufferedWriter writer = null;
    try {
      writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(lastTaskFile)));
      writer.write(new Integer(taskId).toString());
      writer.newLine();
    } catch (IOException e) {
      log.error("Error writing last task file", e);
    } finally {
      if (writer != null) {
        writer.close();
      }
    }
  }
Exemple #7
0
  public List<String> getLogFilenames() {
    File logDir = getLogsDir();
    List<File> logDirnames = Arrays.asList(logDir.listFiles());
    List<String> logFilenames = new ArrayList<String>();

    for (File logMonthDir : logDirnames) {
      if (logMonthDir.isDirectory() && logMonthDir.listFiles().length > 0) {
        for (File logFile : logMonthDir.listFiles()) {
          if (logFile.getName().endsWith(".log")) {
            logFilenames.add(logMonthDir.getName() + File.separator + logFile.getName());
          }
        }
      }
    }

    Collections.sort(logFilenames, new LogFilenameComparator());
    Collections.reverse(logFilenames);

    return logFilenames;
  }
Exemple #8
0
  private void sendEmail(Task.Status exitStatus, File logFile)
      throws IOException, MessagingException, TemplateException {
    String smtpServer = RepoxContextUtil.getRepoxManager().getConfiguration().getSmtpServer();
    if (smtpServer == null || smtpServer.isEmpty()) {
      return;
    }

    String fromEmail = RepoxContextUtil.getRepoxManager().getConfiguration().getDefaultEmail();
    String recipientsEmail =
        RepoxContextUtil.getRepoxManager().getConfiguration().getAdministratorEmail();
    String adminMailPass = RepoxContextUtil.getRepoxManager().getConfiguration().getMailPassword();
    String subject = "REPOX Data Source ingesting finished. Exit status: " + exitStatus.toString();

    EmailSender emailSender = new EmailSender();
    String pathIngestFile =
        URLDecoder.decode(
            Thread.currentThread().getContextClassLoader().getResource("ingest.html.ftl").getFile(),
            "ISO-8859-1");
    emailSender.setTemplate(
        pathIngestFile.substring(0, pathIngestFile.lastIndexOf("/")) + "/ingest");

    HashMap map = new HashMap<String, String>();
    map.put("exitStatus", exitStatus.toString());
    map.put("id", id);

    JavaMailSenderImpl mail = new JavaMailSenderImpl();
    // mail.setUsername(fromEmail);
    mail.setUsername(recipientsEmail);

    mail.setPassword(adminMailPass);

    mail.setPort(25);

    Properties props = System.getProperties();

    props.put("mail.smtp.host", smtpServer);
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.auth", "true");
    mail.setJavaMailProperties(props);

    emailSender.setMailSender(mail);
    emailSender.sendEmail(recipientsEmail, fromEmail, subject, map, logFile.getAbsolutePath());
  }
Exemple #9
0
 public File getDataSourceLogsDir(String dataSourceId) {
   File logDir = new File(getDataSourceDir(dataSourceId), "logs");
   logDir.mkdir();
   return logDir;
 }
Exemple #10
0
 public File getDataSourceDir(String dataSourceId) {
   RepoxConfiguration configuration = RepoxContextUtil.getRepoxManager().getConfiguration();
   File dataSourceDir = new File(configuration.getRepositoryPath(), dataSourceId);
   dataSourceDir.mkdir();
   return dataSourceDir;
 }
Exemple #11
0
 public File getTasksDir() {
   File tasksDir = new File(getOutputDir(), "tasks");
   tasksDir.mkdir();
   return tasksDir;
 }
Exemple #12
0
 public File getLogsDir() {
   File logDir = new File(getOutputDir(), "logs");
   logDir.mkdir();
   return logDir;
 }
Exemple #13
0
 public File getOutputDir() {
   File outputDir =
       new File(RepoxContextUtil.getRepoxManager().getConfiguration().getRepositoryPath(), id);
   outputDir.mkdir();
   return outputDir;
 }