Пример #1
0
  /** 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));
    }
  }
Пример #2
0
  public static Result postGenerate(String handler_json) {

    String oper = "";

    RequestBody body = request().body();
    if (body == null) {
      return ok(completeAnnotation.render("Error processing form: form appears to be empty."));
    }

    String textBody = body.asText();
    Properties p = new Properties();
    try {
      p.load(new StringReader(textBody));
    } catch (Exception e) {
      e.printStackTrace();
      return ok(completeAnnotation.render("Error processing form: form appears to be empty."));
    }

    System.out.println("Selection: " + p.getProperty("submitButton"));
    if (p.getProperty("submitButton") != null) oper = p.getProperty("submitButton");

    if (oper.equals(OPER_FINISH)) {
      return ok(completeAnnotation.render("Annotation operation finished."));
    }

    NameSpaces ns = NameSpaces.getInstance();
    String preamble = FRAG_START_PREAMBLE;
    preamble += ns.printNameSpaceList();
    preamble += "\n";

    /*
     * Insert KB
     */

    preamble += FRAG_KB_PART1;
    preamble += Play.application().configuration().getString("hadatac.console.kb");
    preamble += FRAG_KB_PART2;

    try {
      handler_json = URLDecoder.decode(handler_json, "UTF-8");
    } catch (Exception e) {
      e.printStackTrace();
    }
    System.out.println(handler_json);

    ObjectMapper mapper = new ObjectMapper();
    CSVAnnotationHandler handler = null;
    try {
      handler = mapper.readValue(handler_json, CSVAnnotationHandler.class);

      /*
       * Insert Data Set
       */

      preamble += "<" + DataFactory.getNextURI(DataFactory.DATASET_ABBREV) + ">";
      preamble += FRAG_DATASET;
      preamble += handler.getDataCollectionUri() + ">; ";

      int i = 0;
      int timeStampIndex = -1;
      ArrayList<Integer> mt = new ArrayList<Integer>();
      for (String str : handler.getFields()) {
        // System.out.println(str);
        // System.out.println("get " + i + "-characteristic: [" + p.getProperty(i +
        // "-characteristic") + "]");
        // System.out.println("get " + i + "-unit:           [" + p.getProperty(i + "-unit") + "]");
        if ((p.getProperty(i + "-characteristic") != null)
            && (!p.getProperty(i + "-characteristic").equals(""))
            && (p.getProperty(i + "-unit") != null)
            && (!p.getProperty(i + "-unit").equals(""))) {
          if (p.getProperty(i + "-unit").equals(FRAG_IN_DATE_TIME)) {
            timeStampIndex = i;
          } else {
            mt.add(i);
          }
        }
        i++;
      }

      preamble += FRAG_HAS_MEASUREMENT_TYPE;
      int aux = 0;
      for (Integer mt_count : mt) {
        preamble += FRAG_MT + aux++ + "> ";
      }
      preamble += ".\n\n";

      /*
       * Insert measurement types
       */

      aux = 0;
      for (Integer mt_count : mt) {
        preamble += FRAG_MT + aux;
        preamble += FRAG_MEASUREMENT_TYPE_PART1;
        if (timeStampIndex != -1) {
          preamble += FRAG_IN_DATE_TIME;
          preamble += FRAG_IN_DATE_TIME_SUFFIX;
        }
        preamble += FRAG_MEASUREMENT_TYPE_PART2;
        preamble += mt_count;
        preamble += FRAG_MEASUREMENT_TYPE_PART3;
        preamble += "<" + p.getProperty(mt_count + "-characteristic") + ">";
        preamble += FRAG_MEASUREMENT_TYPE_PART4;
        preamble += "<" + p.getProperty(mt_count + "-unit") + ">";
        preamble += " .\n";
      }

      if (timeStampIndex != -1) {
        preamble += "\n";
        preamble += FRAG_IN_DATE_TIME_STATEMENT + " " + timeStampIndex + "  . \n";
      }

      if (textBody == null) {
        badRequest("Expecting text/plain request body");
      }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return ok(completeAnnotation.render("Error processing form. Please restart form."));
    }

    preamble += FRAG_END_PREAMBLE;

    if (oper.equals(OPER_PREAMBLE)) {
      return ok(preamble).as("text/turtle");
    }

    if (oper.equals(OPER_CCSV)) {
      File newFile = new File(handler.getDatasetName());
      try {
        preamble += FileUtils.readFileToString(newFile, "UTF-8");
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return ok(completeAnnotation.render("Error reading cached CSV file. Please restart form."));
      }
      return ok(preamble).as("text/turtle");
    }

    if (oper.equals(OPER_UPLOAD)) {}

    return ok(completeAnnotation.render("Error processing form: unspecified download operation."));
  }