// for /metadata HTTP GET requests
  @Restrict(@Group(AuthApplication.DATA_OWNER_ROLE))
  public static Result index(String deployment_uri) {

    DeploymentForm depForm = new DeploymentForm();
    Deployment dep = null;

    try {
      if (deployment_uri != null) {
        deployment_uri = URLDecoder.decode(deployment_uri, "UTF-8");
      } else {
        deployment_uri = "";
      }
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }

    if (!deployment_uri.equals("")) {

      dep = Deployment.find(deployment_uri);
      /*
       *  Add deployment information into handler
       */
      depForm.setPlatform(dep.platform.getLabel());
      depForm.setInstrument(dep.instrument.getLabel());
      if (dep.detectors != null) {
        Iterator detectors = dep.detectors.iterator();
        while (detectors.hasNext()) {
          depForm.addDetector(((Detector) detectors.next()).getLabel());
        }
      }
      depForm.setStartDateTime(dep.getStartedAt());

      System.out.println("delete deployment");
      return ok(deleteDeployment.render(deployment_uri, depForm));
    }
    return ok(deleteDeployment.render(deployment_uri, depForm));
  } // /index()
  @Restrict(@Group(AuthApplication.DATA_OWNER_ROLE))
  public static Result processForm(String deployment_uri) {
    Deployment dep = null;

    try {
      if (deployment_uri != null) {
        deployment_uri = URLDecoder.decode(deployment_uri, "UTF-8");
      } else {
        deployment_uri = "";
      }
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
    }

    if (!deployment_uri.equals("")) {
      dep = Deployment.find(deployment_uri);
    }

    Form<DeploymentForm> form = Form.form(DeploymentForm.class).bindFromRequest();
    DeploymentForm data = form.get();

    data.setPlatform(dep.platform.getLabel());
    data.setInstrument(dep.instrument.getLabel());
    if (dep.detectors != null) {
      Iterator detectors = dep.detectors.iterator();
      while (detectors.hasNext()) {
        data.addDetector(((Detector) detectors.next()).getLabel());
      }
    }
    data.setStartDateTime(dep.getStartedAt());
    data.setEndDateTime(dep.getEndedAt());

    dep.delete();

    // Deployment deployment = DataFactory.closeDeployment(deploymentUri, endDateString);
    if (form.hasErrors()) {
      System.out.println("HAS ERRORS");
      return badRequest(closeDeployment.render(deployment_uri, data));
    } else {
      return ok(deploymentConfirm.render("Delete Deployment", data));
    }
  }
  /** 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));
    }
  }