public static Result upload() {
    MultipartFormData body = request().body().asMultipartFormData();
    FilePart input = body.getFile("inputFile");

    if (input != null) {
      String fileName = input.getFilename();
      String contentType = input.getContentType();
      File file = input.getFile();
      SeqFile seq = new SeqFile(file);
      return redirect(routes.Application.results(true));
    } else {
      flash("error", "Missing file");
      return redirect(routes.Application.results(false));
    }
  }
Beispiel #2
0
 public static Result registerNewUser() {
   Form<Register> regForm = Form.form(Register.class).bindFromRequest();
   if (regForm.hasErrors()) {
     return badRequest(register.render(regForm));
   } else {
     return redirect(routes.Application.login());
   }
 }
 public static Result newTask() {
   Form<Task> filledForm = taskForm.bindFromRequest();
   if (filledForm.hasErrors()) return badRequest(views.html.task.render(Task.all(), filledForm));
   else {
     Task.createTask(filledForm.get());
     return redirect(routes.Application.getTasks());
   }
 }
Beispiel #4
0
 public static Result authenticate() {
   Form<Login> loginForm = Form.form(Login.class).bindFromRequest();
   if (loginForm.hasErrors()) {
     return badRequest(login.render(loginForm));
   } else {
     session().clear();
     session("email", loginForm.get().email);
     return redirect(routes.Application.start());
   }
 }
  public static Result enter() {
    Map<String, String[]> params;
    params = request().body().asFormUrlEncoded();

    String email = params.get("email")[0];
    User user = User.find.byId(email);
    if (user == null) {
      return redirect(routes.Application.login());
    } else {
      session("email", email);
      return redirect(routes.Chats.allChats());
    }
  }
Beispiel #6
0
  /**
   * Start the workflow run asynchronously.
   *
   * @param name The name of the workflow
   * @return json response containing id
   */
  @Security.Authenticated(Secured.class)
  public Result runWorkflow(String name) {
    FormDefinition form = formDefinitionForWorkflow(name);

    // Process file upload first if present in form data
    Http.MultipartFormData body = request().body().asMultipartFormData();

    for (Object obj : body.getFiles()) {
      Http.MultipartFormData.FilePart filePart = (Http.MultipartFormData.FilePart) obj;
      UserUpload userUpload = uploadFile(filePart);

      BasicField fileInputField = form.getField(filePart.getKey());
      fileInputField.setValue(userUpload);
    }

    //  Set the form definition field values from the request data
    Map<String, String[]> data = body.asFormUrlEncoded();
    for (String key : data.keySet()) {
      BasicField field = form.getField(key);
      field.setValue(data.get(key));
    }

    // Transfer form field data to workflow settings map
    Map<String, Object> settings = new HashMap<>();

    for (BasicField field : form.fields) {
      settings.put(field.name, field.value());
    }

    settings.putAll(settingsFromConfig(form));

    // Update the workflow model object and persist to the db
    Workflow workflow = Workflow.find.where().eq("name", form.name).findUnique();

    if (workflow == null) {
      workflow = new Workflow();
    }

    workflow.name = form.name;
    workflow.title = form.title;
    workflow.yamlFile = form.yamlFile;

    workflow.save();

    // Run the workflow
    ObjectNode response = runYamlWorkflow(form.yamlFile, workflow, settings);

    return redirect(routes.Application.index());
  }
  public static Result createNewUser() {
    Form<User> nu = userForm.bindFromRequest();

    ObjectNode jsonData = Json.newObject();
    String userName = null;

    try {
      userName =
          nu.field("firstName").value()
              + " "
              + (nu.field("middleInitial")).value()
              + " "
              + (nu.field("lastName")).value();
      jsonData.put("userName", userName);
      jsonData.put("firstName", nu.get().getFirstName());
      jsonData.put("middleInitial", nu.get().getMiddleInitial());
      jsonData.put("lastName", nu.get().getLastName());
      jsonData.put("password", nu.get().getPassword());
      jsonData.put("affiliation", nu.get().getAffiliation());
      jsonData.put("title", nu.get().getTitle());
      jsonData.put("email", nu.get().getEmail());
      jsonData.put("mailingAddress", nu.get().getMailingAddress());
      jsonData.put("phoneNumber", nu.get().getPhoneNumber());
      jsonData.put("faxNumber", nu.get().getFaxNumber());
      jsonData.put("researchFields", nu.get().getResearchFields());
      jsonData.put("highestDegree", nu.get().getHighestDegree());

      JsonNode response =
          RESTfulCalls.postAPI(
              Constants.URL_HOST + Constants.CMU_BACKEND_PORT + Constants.ADD_USER, jsonData);

      // flash the response message
      Application.flashMsg(response);
      return redirect(routes.Application.createSuccess());

    } catch (IllegalStateException e) {
      e.printStackTrace();
      Application.flashMsg(RESTfulCalls.createResponse(ResponseType.CONVERSIONERROR));
    } catch (Exception e) {
      e.printStackTrace();
      Application.flashMsg(RESTfulCalls.createResponse(ResponseType.UNKNOWN));
    }
    return ok(signup.render(nu));
  }
Beispiel #8
0
  @Security.Authenticated(Secured.class)
  public static Result viewMyConversation(Long id) {
    Student s = Student.find.byId(request().username());
    Conversation c = Conversation.find.byId(id.toString());

    if (!c.getParticipants().contains(s)) { // unauthorized access!
      return redirect(routes.Application.viewMyConversations());
    } else {
      // mark all read
      for (Message m : c.messages) {
        if (!m.sender.email.equals(s.email)) {
          m.setRead();
          m.save();
        }
      }

      return ok(viewConversation.render(s, c, form(MessageForm.class)));
    }
  }
Beispiel #9
0
  @Security.Authenticated(Secured.class)
  public static Result addNewMessageForm(Long id) {
    Form<MessageForm> mesForm = Form.form(MessageForm.class).bindFromRequest();
    if (mesForm.hasErrors()) {
      return badRequest(postNewMessage.render(mesForm, id));
    } else {

      Message m =
          new Message(
              mesForm.field("text").value().toString(), Student.find.byId(request().username()));

      Conversation c = null;

      c = Conversation.find.byId(id.toString());
      c.messages.add(m);
      c.save();

      return redirect(routes.Application.viewMyConversation(id));
    }
  }
Beispiel #10
0
 public static Result deleteTask(Long id) {
   Task.delete(id);
   return redirect(routes.Application.tasks());
 }
Beispiel #11
0
 public static Result index() {
   return redirect(routes.Application.tasks());
 }
Beispiel #12
0
 public static Result logout() {
   session().clear();
   flash("success", "You've been logged out");
   return redirect(routes.Application.login());
 }
Beispiel #13
0
 @Security.Authenticated(Secured.class)
 public static Result addNewMessage(Long id) {
   return redirect(
       //                postNewMessage.render(form(MessageForm.class), id)
       routes.Application.viewMyConversation(id));
 }