Esempio n. 1
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);
  }
Esempio n. 2
0
 public File getLogoFile() {
   File logosDir = RepoxContextUtil.getRepoxManager().getConfiguration().getLogosDir();
   if (logo != null && !logo.isEmpty() && new File(logosDir, logo).exists()) {
     return new File(logosDir, logo);
   } else {
     return null;
   }
 }
Esempio n. 3
0
 /**
  * Signals that a harvest of a Data Source finished. RepoxManager will store synchronization dates
  *
  * @param date
  * @throws Exception
  */
 public void signalSynchronizationFinished(Date date) throws IOException {
   File dataSourceSyncDateFile = getSyncDateFile();
   RepoxConfiguration configuration = RepoxContextUtil.getRepoxManager().getConfiguration();
   File syncDateFile =
       new File(configuration.getRepositoryPath(), "synchronization-date-global.txt");
   String dateAsString = DateUtil.date2String(date, TimeUtil.SHORT_DATE_FORMAT);
   FileUtil.writeToFile(dataSourceSyncDateFile, dateAsString);
   FileUtil.writeToFile(syncDateFile, dateAsString);
 }
Esempio n. 4
0
  protected boolean emptyRecords() throws IOException {
    boolean successfulDeletion = true;

    // Delete records indexes
    for (AccessPoint accessPoint : this.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);
        successfulDeletion = false;
      }
    }

    // Remove from Record Counts cache
    RepoxContextUtil.getRepoxManager().getRecordCountManager().removeDataSourceCounts(id);

    return successfulDeletion;
  }
Esempio n. 5
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());
  }
Esempio n. 6
0
  public static void main(String[] args) throws Exception {
    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: ";

    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", "OK");
    map.put("id", "1111");

    JavaMailSenderImpl mail = new JavaMailSenderImpl();
    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", "false");
    mail.setJavaMailProperties(props);

    emailSender.setMailSender(mail);
    emailSender.sendEmail(
        recipientsEmail, fromEmail, subject, map, "C:\\Users\\GPedrosa\\Desktop\\indexSec.txt");
  }
Esempio n. 7
0
  private static int generateNumberSufix(String basename) throws DocumentException, IOException {
    int currentNumber = 0;
    String currentFullId = basename + currentNumber;

    while (RepoxContextUtil.getRepoxManager()
            .getDataProviderManager()
            .getDataProvider(currentFullId)
        != null) {
      currentNumber++;
      currentFullId = basename + currentNumber;
    }

    return currentNumber;
  }
Esempio n. 8
0
  /**
   * Add MDRecord to database
   *
   * @param request
   * @param ingestedRecords
   */
  protected void addMdRecord2Database(Request request, List<RecordRepox> ingestedRecords) {
    try {
      Repox2Sip repox2Sip = RepoxContextUtil.getRepoxManager().getDataManager().getRepox2sip();
      List<MetadataRecord> allMetadataRecords = new ArrayList<MetadataRecord>();
      for (RecordRepox rp : ingestedRecords) {
        allMetadataRecords.add(rp.createRecordSip());
        // rp.addRecord2DataBase(request.getId(), repox2Sip);
      }
      repox2Sip.addMetadataRecords(request.getId(), allMetadataRecords);

    } catch (Repox2SipException e) {
      log.error("Could not add MetadataRecord to Data Base", e);
      e.printStackTrace();
    }
  }
Esempio n. 9
0
  protected void checkRequest(boolean addedNewRecords, Request newRequest) {
    try {
      if (!addedNewRecords) {
        Repox2Sip repox2sip = RepoxContextUtil.getRepoxManager().getDataManager().getRepox2sip();
        List<Request> requestList = repox2sip.getDataSetRequests(this.getIdDb());

        Collections.sort(requestList, new DateSorter());
        for (Request request : requestList) {
          if (request.getStatus().equals(RequestStatus.IMPORT_COMPLETED)) {
            Long myId = request.getId();
            repox2sip.addMetadataRecords(
                newRequest.getId(), repox2sip.getRequestMetadataRecords(myId));
            break;
          }
        }
      }
    } catch (Repox2SipException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
  }
Esempio n. 10
0
 public File getDataSourceDir(String dataSourceId) {
   RepoxConfiguration configuration = RepoxContextUtil.getRepoxManager().getConfiguration();
   File dataSourceDir = new File(configuration.getRepositoryPath(), dataSourceId);
   dataSourceDir.mkdir();
   return dataSourceDir;
 }
Esempio n. 11
0
 public File getOutputDir() {
   File outputDir =
       new File(RepoxContextUtil.getRepoxManager().getConfiguration().getRepositoryPath(), id);
   outputDir.mkdir();
   return outputDir;
 }
Esempio n. 12
0
 public int getNumberRecords() throws IOException, DocumentException, SQLException {
   RecordCount dataSourceCount =
       RepoxContextUtil.getRepoxManager().getRecordCountManager().getRecordCount(id);
   return (dataSourceCount == null ? 0 : dataSourceCount.getCount());
 }
Esempio n. 13
0
  public Task.Status startIngest(String taskId, boolean fullIngest) {
    Repox2Sip repox2sip = RepoxContextUtil.getRepoxManager().getDataManager().getRepox2sip();
    Request request = new Request();
    File logFile = getLogFile(taskId);
    Task.Status exitStatus = Task.Status.OK;

    try {
      if (RepoxContextUtil.getRepoxManager()
          .getConfiguration()
          .getUseSipDataBase()
          .equals("true")) {
        // REPOX2SIP Create request
        DataSet dataSet = repox2sip.getDataSet(this.getIdDb());
        request.setDataSet(dataSet);
        request.setStatus(RequestStatus.UNDER_CONSTRUCTION);
        request.setCreationDate(new Date());
        request = setRequestName(request);
        repox2sip.addRequest(request);
      }

      stopExecution = false;

      StringUtil.simpleLog(
          "Starting to import from Data Source with id " + id, this.getClass(), logFile);
      lastUpdate = getSynchronizationDate();
      Date now = new Date();

      exitStatus = ingestRecords(request, logFile, fullIngest);

      if (RepoxContextUtil.getRepoxManager()
          .getConfiguration()
          .getUseSipDataBase()
          .equals("true")) {
        // REPOX2SIP Change request status
        request.setStatus(getCorrespondentRequestStatus(exitStatus));
        repox2sip.updateRequest(request);
      }

      lastUpdate = now;
      if (exitStatus.isSuccessful()) {
        signalSynchronizationFinished(lastUpdate);
      }

      StringUtil.simpleLog(
          "Finished importing from Data Source with id "
              + id
              + ". Exit status: "
              + exitStatus.toString(),
          this.getClass(),
          logFile);
      sendEmail(exitStatus, logFile);
      request.setStatus(RequestStatus.IMPORT_COMPLETED);
    } catch (TemplateException e) {
      log.error(e.getMessage(), e);
      StringUtil.simpleLog(
          "TemplateException: ERROR importing from Data Source with id "
              + id
              + ": "
              + e.getMessage(),
          this.getClass(),
          logFile);
      request.setStatus(RequestStatus.ABORTED);
    } catch (Repox2SipException e) {
      log.error(e.getMessage(), e);
      StringUtil.simpleLog(
          "Repox2SipException: ERROR importing from Data Source with id "
              + id
              + ": "
              + e.getMessage(),
          this.getClass(),
          logFile);
      request.setStatus(RequestStatus.ABORTED);
    } catch (MessagingException e) {
      log.error(e.getMessage(), e);
      StringUtil.simpleLog(
          "MessagingException: ERROR importing from Data Source with id "
              + id
              + ": "
              + e.getMessage(),
          this.getClass(),
          logFile);
      request.setStatus(RequestStatus.ABORTED);
    } catch (IOException e) {
      log.error(e.getMessage(), e);
      StringUtil.simpleLog(
          "IOException: ERROR importing from Data Source with id " + id + ": " + e.getMessage(),
          this.getClass(),
          logFile);
      request.setStatus(RequestStatus.ABORTED);
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      StringUtil.simpleLog(
          "ERROR importing from Data Source with id " + id + ": " + e.getMessage(),
          this.getClass(),
          logFile);
      request.setStatus(RequestStatus.ABORTED);
    }

    return exitStatus;
  }