@Override
 @Transactional
 public void writeItems(List<Object> items) throws Exception {
   try (PrintWriter archive =
       new PrintWriter(
           new BufferedWriter(
               new FileWriter(
                   new File(
                       jobContext.getProperties().getProperty(ARCHIVE_DIRECTORY)
                           + "/archive_"
                           + jobContext.getJobName()
                           + "_"
                           + jobContext.getInstanceId()
                           + ".csv"),
                   true)))) {
     for (Object item : items) {
       HandlingEventRegistrationAttempt attempt = (HandlingEventRegistrationAttempt) item;
       applicationEvents.receivedHandlingEventRegistrationAttempt(attempt);
       archive.println(
           attempt.getRegistrationTime()
               + ","
               + attempt.getCompletionTime()
               + ","
               + attempt.getTrackingId()
               + ","
               + attempt.getVoyageNumber()
               + ","
               + attempt.getUnLocode()
               + ","
               + attempt.getType());
     }
   }
 }
  @Override
  public String process() throws Exception {

    Properties properties = JobCtx.getProperties();
    String foo = properties.getProperty("foo");

    JobCtx.setExitStatus(foo);

    return GOOD_EXIT_STATUS;
  }
 private void appendToJobContext(String exitStatus) {
   String es = jobCtx.getExitStatus();
   if (es == null) {
     logger.fine("First addition to Job ExitStatus = " + es);
     jobCtx.setExitStatus(exitStatus);
   } else {
     String newExitStatus = es.concat(",").concat(exitStatus);
     logger.fine("Existing Job ExitStatus = " + es + " ; Updating to : " + newExitStatus);
     jobCtx.setExitStatus(newExitStatus);
   }
 }
  @Override
  public void open(Serializable checkpoint) throws Exception {
    File archiveDirectory = new File(jobContext.getProperties().getProperty(ARCHIVE_DIRECTORY));

    if (!archiveDirectory.exists()) {
      archiveDirectory.mkdirs();
    }
  }
예제 #5
0
 public void open(Serializable e) throws Exception {
   Properties jobParameters =
       BatchRuntime.getJobOperator().getParameters(jobContext.getExecutionId());
   ConcurrentSkipListMap<Integer, PayrollInputRecord> records =
       dataBean.getPayrollInputRecords((String) jobParameters.get("monthYear"));
   Integer fromKey = (Integer) jobParameters.get("startEmpID");
   Integer toKey = (Integer) jobParameters.get("endEmpID");
   payrollInputRecords = records.subMap(fromKey, true, toKey, false).values().iterator();
 }
  @Override
  public String process() throws Exception {
    logger.fine(sourceClass + ".process()");

    // Do something a bit "compute-intensive".
    Random r = new Random();
    int x = r.nextInt();
    int y = r.nextInt();
    for (int i = 0; i < 10; i++) {
      x = (y * x) % 3469;
      y = (x * y) % 3491;
    }

    // This is the ongoing appending to the JOB exit status
    String exitStatus = null;
    try {
      exitStatus = contributeToExitStatus();
      appendToJobContext(exitStatus);
    } catch (FailViaException e) {
      logger.fine(sourceClass + ".process(); Exiting with exitStatus = " + exitStatus);
      String errorAppend = (String) jobCtx.getTransientUserData();
      appendToJobContext(errorAppend);
      throw new RuntimeException("Throwing exception on purpose");
    }

    logger.fine(sourceClass + ".process(); exitStatus = " + exitStatus);

    // Now we're going to switch gears and consider the step exit Status
    if (exitStatus.startsWith("s")) {
      logger.fine(
          "For step exitStatus for step: "
              + stepCtx.getStepName()
              + " , return: "
              + JSL_STOP_TRANSITION);
      return JSL_STOP_TRANSITION;
    } else if (exitStatus.startsWith("f")) {
      logger.fine(
          "For step exitStatus for step: "
              + stepCtx.getStepName()
              + " , return: "
              + JSL_FAIL_TRANSITION);
      return JSL_FAIL_TRANSITION;
    } else {
      logger.fine(
          "For step exitStatus for step: " + stepCtx.getStepName() + " , don't return value");
      return null;
    }
  }
 // Write a custom Exit status
 @Override
 public void onWriteError(List<Object> items, Exception ex) throws Exception {
   log.info("Exception detected. Setting exit status");
   jobContext.setExitStatus("Error : " + ex.getMessage());
 }