public boolean handleFTPEvent(FTPConnector.FTPEvent event, FTPClient client) {
   switch (event) {
     case FileWriteSuccess:
       for (CarrierAppointmentDataBean bean : this.carrierAppointments) {
         bean.setForwarded(true);
         bean.setUpdatedOn(new GregorianCalendar());
       }
       this.status = FTPFileWriter.WriterStatus.SUCCESS;
       return true;
     default:
       return super.handleFTPEvent(event, client);
   }
 }
  public void process(TaskStatus arg0) throws RemoteException {
    if (LOG.isLoggable(Level.FINER))
      LOG.entering(CarrierAppointmentForwardEJB.class.getName(), "process", new Object[] {arg0});
    try {

      Object[] keys = null;
      StringBuffer query = new StringBuffer("select ca from CarrierAppointmentDataBean ca");
      keys = JpqlUtils.addQueryArgument(query, keys, false, "ca.forwarded");
      List<CarrierAppointmentDataBean> results =
          (List<CarrierAppointmentDataBean>) EntityUtils.list(query.toString(), keys);

      if (Utils.hasContent(results)) {
        ArrayList<CarrierAppointmentDataBean> carriers =
            new ArrayList<CarrierAppointmentDataBean>();
        FacilityService fs = ServiceLocator.getInstance().getService(FacilityService.class);

        FacilityGroup lookup = fs.findSingleFacilityGroup(null, FACILITY_GROUP_NAME, null);
        if (lookup == null || lookup.getFacilities() == null || lookup.getFacilities().length == 0)
          throw new ApplicationException(
              "Facility information was not found for type [" + FACILITY_GROUP_NAME + "]");

        List<String> errors = new ArrayList<String>();
        for (CarrierAppointmentDataBean bean : results) {
          boolean validFacility = false;
          boolean validAddress = false;
          for (Facility<FacilityAddress<?, Address>> fac : lookup.getFacilities()) {
            if (bean.getFacilityId().equals(fac.getId())) {
              validFacility = true;
              bean.setFacilityName(fac.getName());
              for (FacilityAddress<?, Address> fa : fac.getFacilityAddresses()) {
                if (fa.getAddress() != null
                    && fa.getAddress().getId().equals(bean.getAddressId())) {
                  bean.setFacilityAddress(fa.getAddress().getLine1());
                  validAddress = true;
                  break;
                }
              }
              if (!validAddress)
                errors.add(
                    "No address lookup error: addressId["
                        + bean.getAddressId()
                        + "] for facilityId ["
                        + bean.getFacilityId()
                        + "] in group ["
                        + FACILITY_GROUP_NAME
                        + "]");
              break;
            }
          }
          if (!validFacility)
            errors.add(
                "No facility was found with Id ["
                    + bean.getFacilityId()
                    + "] in group ["
                    + FACILITY_GROUP_NAME
                    + "]");
          else if (validAddress) carriers.add(bean);
        }
        if (Utils.hasContent(carriers)) {
          CarrierFTPWriter writer = new CarrierFTPWriter(carriers);
          FTPConnector conn = new FTPConnector();
          String url = PropertyManager.getEnvironmentProperty("carrierFTPUrl");
          if (url != null) {
            conn.setConnectionURL(url);
            conn.setInitialDirectory(PropertyManager.getEnvironmentProperty("carrierFtpDirectory"));
            conn.createAndSendFile(writer);
          }
          if (writer.getStatus().equals(FTPFileWriter.WriterStatus.SUCCESS)) {
            for (CarrierAppointmentDataBean carrier : carriers) {
              try {
                // CarrierFTPWriter class updates forwarded to true if successful.
                carrier.setForwarded(true);
                EntityUtils.update(carrier);
              } catch (Throwable th) {
                LOG.severe("Error updating Carrier record with ID [" + carrier.getId() + "]");
              }
            }
          }
        }
      }
    } catch (Throwable th) {
      String msg = th.getMessage();
      if (!Utils.hasContent(msg)) {
        msg = "Unknown error.";
      } else LOG.severe(msg);
    }

    if (LOG.isLoggable(Level.FINER)) {
      LOG.exiting(CarrierAppointmentForwardEJB.class.getName(), "process");
    }
  }