/** Handles the form submission. */
  @Restrict(@Group(AuthApplication.DATA_OWNER_ROLE))
  public static Result processForm() {
    final SysUser user = AuthApplication.getLocalUser(session());
    Form<DeploymentForm> form = Form.form(DeploymentForm.class).bindFromRequest();
    DeploymentForm data = form.get();

    String dateStringFromJs = data.getStartDateTime();
    String dateString = "";
    DateFormat jsFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm a");
    Date dateFromJs;
    try {
      dateFromJs = jsFormat.parse(dateStringFromJs);
      DateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
      dateString = isoFormat.format(dateFromJs);
    } catch (ParseException e) {
      e.printStackTrace();
    }

    int triggeringEvent;
    String insert = "";
    String deploymentUri = DataFactory.getNextURI(DataFactory.DEPLOYMENT_ABBREV);
    String dataCollectionUri = DataFactory.getNextURI(DataFactory.DATA_COLLECTION_ABBREV);
    if (data.getType().equalsIgnoreCase("LEGACY")) {
      triggeringEvent = TriggeringEvent.LEGACY_DEPLOYMENT;
    } else {
      triggeringEvent = TriggeringEvent.INITIAL_DEPLOYMENT;
    }

    System.out.println("new deployment: size of detector's array : " + data.getDetector().size());
    if (data.getDetector().size() > 0) {
      for (String detector : data.getDetector()) {
        System.out.println("   -- det uri: " + detector);
      }
    }

    Deployment deployment =
        DataFactory.createDeployment(
            deploymentUri,
            data.getPlatform(),
            data.getInstrument(),
            data.getDetector(),
            dateString,
            data.getType());
    DataAcquisition dataCollection =
        DataFactory.createDataAcquisition(
            dataCollectionUri,
            deploymentUri,
            triggeringEvent,
            UserManagement.getUriByEmail(user.email));
    if (form.hasErrors()) {
      System.out.println("HAS ERRORS");
      return badRequest(
          newDeployment.render(
              form, Platform.find(), Instrument.find(), Detector.find(), data.getType()));
    } else {
      return ok(deploymentConfirm.render("New Deployment", data));
    }
  }
 // for /metadata HTTP POST requests
 @Restrict(@Group(AuthApplication.DATA_OWNER_ROLE))
 public static Result postIndex(String type) {
   return ok(
       newDeployment.render(
           Form.form(DeploymentForm.class),
           Platform.find(),
           Instrument.findAvailable(),
           Detector.findAvailable(),
           type));
 } // /postIndex()