예제 #1
0
  public static List<String> createFiles(MultipartFormData body, String folder)
      throws IOException, FileTooLargeException {
    // TODO Auto-generated method stub
    int index = -1;
    List<String> files = new ArrayList<>();
    while (true) {

      FilePart picture = body.getFile("picture" + (index == -1 ? "" : index));
      if (picture != null) {
        String fileName = picture.getFilename();
        String contentType = picture.getContentType();
        File file = picture.getFile();
        int size = (int) (file.length() / 1024 / 1024);
        if (size > 1) {
          throw new FileTooLargeException(size + " " + 1);
        }

        File fileToSave = new File("public/images/" + folder + fileName);
        if (file.exists()) {
          fileToSave = new File("public/images/" + folder + "img_" + Math.random() + fileName);
        }
        FileUtils.moveFile(file, fileToSave);
        //	Files.copy(file, fileToSave);

        files.add(fileToSave.getPath().toString());
        index++;
      } else break;
    }
    if (files.size() > 0) {
      return files;
    }

    return null;
  }
예제 #2
0
 public Result editHeli() {
   log.debug("Edit Heli");
   Form<HeliForm> heliForm = Form.form(HeliForm.class).bindFromRequest();
   if (heliForm.hasErrors()) {
     log.debug("Edit heli error form:");
     return badRequest(editheli.render("RC Helicopter Edit", heliForm));
   }
   MultipartFormData data = request().body().asMultipartFormData();
   HeliModel model = new HeliModel();
   model.setVersion(heliForm.data().get("version"));
   if (data.getFile("photo") != null) {
     model.setPhoto(heliForm.get().getPhotoBytes(data.getFile("photo").getFile()));
   }
   model.setMake(heliForm.data().get("make"));
   model.setModel(heliForm.data().get("model"));
   model.setModelNumber(heliForm.data().get("modelNumber"));
   heliService.updateHeli(model);
   return redirect(routes.Heli.helis());
 }
  public static Result create_save() {
    Form<CustomerForm> filledForm = customerForm.bindFromRequest();

    if (filledForm.hasErrors()) {
      System.out.println("in error");
      return badRequest(create.render(filledForm));
    }

    CustomerForm customerForm = filledForm.get();
    if (customerForm == null) {
      System.out.println("in form");
      return badRequest(create.render(filledForm));
    }

    Customer customer = new Customer();
    formToModel(customer, customerForm);
    MultipartFormData body = request().body().asMultipartFormData();
    FilePart picture1 = body.getFile("signatureOne");
    FilePart picture2 = body.getFile("signatureTwo");
    if (picture1 != null && picture2 != null) {
      File file1 = picture1.getFile();
      File file2 = picture2.getFile();
      String path = "public/signatureimages/" + customer.accountNumber;
      File f = new File(path);
      f.mkdir();
      file1.renameTo(new File(path, customer.signatureOne));
      file2.renameTo(new File(path, customer.signatureTwo));
      System.out.println("File uploaded successfully...");
    } else {
      filledForm.reject("file", "Please select the image to uplaod");
    }

    String inputFile =
        "public/signatureimages/" + customer.accountNumber + "/" + customer.signatureOne;
    String smoothfilename =
        "public/signatureimages/" + customer.accountNumber + "/signatureOne_smooth.jpg";
    String binaryfilename =
        "public/signatureimages/" + customer.accountNumber + "/signatureOne_binary.jpg";
    String sizeNormalizeFileName =
        "public/signatureimages/" + customer.accountNumber + "/signatureOne_normalize.jpg";
    SigImgProcessingController.smoothing(inputFile, smoothfilename);
    SigImgProcessingController.binarization(smoothfilename, binaryfilename);
    SigImgProcessingController.sizeNormalization(binaryfilename, sizeNormalizeFileName);
    float[] sig1 = SigImgProcessingController.calculateAngles(sizeNormalizeFileName);
    StringBuffer angels = new StringBuffer();

    for (int i = 0; i < sig1.length; i++) {
      angels.append(sig1[i] + "|");
    }
    System.out.println("Angles: " + angels);
    customer.signOneAngles = angels.toString();

    customer.save();
    return redirect(controllers.routes.CustomerController.index());
  }
예제 #4
0
 public Result addHeli() {
   log.debug("Add Heli");
   Form<HeliForm> heli = Form.form(HeliForm.class).bindFromRequest();
   log.debug("Add heli form: {}", heli);
   if (heli.hasErrors()) {
     return badRequest(addheli.render("RC Helicopter", heli));
   }
   MultipartFormData data = request().body().asMultipartFormData();
   log.debug("Add heli data: {}", data);
   HeliModel model = new com.HeliModel();
   model.setModel(heli.data().get("model"));
   if (data.getFile("photo") != null) {
     model.setPhoto(heli.get().getPhotoBytes(data.getFile("photo").getFile()));
   }
   model.setMake(heli.data().get("make"));
   model.setModelNumber(heli.data().get("modelNumber"));
   model.setVersion(heli.data().get("version"));
   log.debug("Add heli model: {}", model);
   heliService.createHeli(model);
   return redirect(routes.Heli.helis());
 }
예제 #5
0
  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));
    }
  }
예제 #6
0
  public static List<String> createThumbnails(MultipartFormData body, String folder)
      throws IOException, FileTooLargeException {
    // TODO Auto-generated method stub
    int index = -1;
    List<String> files = new ArrayList<>();
    while (true) {

      FilePart picture = body.getFile("picture" + (index == -1 ? "" : index));
      if (picture != null) {
        String fileName = picture.getFilename();
        File file = picture.getFile();

        System.out.println(file.length());

        BufferedImage image = ImageIO.read(file);

        BufferedImage thumb = ImageUtils.resizeImage(image);

        Logger.error(
            "size: " + file.length() + "   name: " + fileName + "  " + fileName.lastIndexOf('.'));

        fileName = fileName.substring(0, fileName.lastIndexOf('.'));

        Logger.error(
            "size: " + file.length() + "   name: " + fileName + "  " + fileName.lastIndexOf('.'));

        int size = (int) (file.length() / 1024 / 1024);
        if (size > 1) {
          throw new FileTooLargeException(size + " " + 1);
        }

        File fileToSave = generateFileName(fileName, 0, folder);

        fileToSave.createNewFile();
        ImageIO.write(thumb, "png", fileToSave);
        files.add(fileToSave.getPath().toString());
        index++;
      } else break;
    }
    if (files.size() > 0) {
      return files;
    }

    return null;
  }
  public static Result upload_image(String accountNo) {
    Form<ImageUploadForm> filledForm = imageForm.bindFromRequest();
    MultipartFormData body = request().body().asMultipartFormData();
    FilePart picture1 = body.getFile("image");
    if (picture1 != null) {
      File file1 = picture1.getFile();
      String pathToDelete = "public/signatureimages/" + accountNo + "/" + accountNo + "_verify.jpg";

      File f = new File(pathToDelete);
      boolean b = f.delete();
      System.out.println("file deleted" + b);
      String path = "public/signatureimages/" + accountNo;
      System.out.println("path:" + path);
      file1.renameTo(new File(path, accountNo + "_verify.jpg"));
      System.out.println("File uploaded for compare successfully...");
    } else {
      filledForm.reject("file", "Please select the image to uplaod");
    }
    response().setHeader("Cache-Control", "no-cache");
    return ok(verify.render(imageForm, accountNo));
  }
예제 #8
0
  public Result upload() {
    String databaseName = "";
    System.out.println("upload function call");

    MultipartFormData body = request().body().asMultipartFormData();
    FilePart filePart1 = body.getFile("filePart1");
    String[] searchTag = body.asFormUrlEncoded().get("db");
    String[] uploadDBName = body.asFormUrlEncoded().get("db_upload");

    databaseName = uploadDBName[0];
    System.out.println("FILE SEND!!");
    if (filePart1 != null) {
      // System.out.println("ifin ici");

    }
    File newFile1 = filePart1.getFile();
    InputStream isFile1;
    try {
      isFile1 = new FileInputStream(newFile1);
    } catch (FileNotFoundException e1) {
      isFile1 = null;
    }

    byte[] byteFile1;

    try {
      byteFile1 = IOUtils.toByteArray(isFile1);
    } catch (IOException e2) {
      byteFile1 = null;
    }
    BufferedReader reader;
    String line;
    StringBuilder stringBuilder;
    String ls;
    try {
      reader = new BufferedReader(new FileReader(newFile1));
      line = null;
      stringBuilder = new StringBuilder();
      ls = System.getProperty("line.separator");
    } catch (FileNotFoundException e1) {
      reader = null;
      line = null;
      stringBuilder = null;
      ls = null;
    }
    // System.out.println(reader);
    String[] parts;
    try {
      while ((line = reader.readLine()) != null) {
        String[] a_line_list = line.split("\t");
        String tweet = a_line_list[2];
        String id = a_line_list[0];
        String owner = a_line_list[1];
        String label = "-2";
        DataAccess.addDocument(databaseName, "tweets_unlabelled", id, owner, tweet, label, "0");
      }
    } catch (IOException e) {

    }
    try {
      FileUtils.writeByteArrayToFile(newFile1, byteFile1);
      isFile1.close();
    } catch (IOException e3) {

    }
    try {
      Thread.sleep(1000); // thread sleep for concurrent operations on ES
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    TweetDTO tweet = DataAccess.getNextTweet(databaseName);
    System.out.println(tweet.getId() + " " + tweet.getOwner() + " " + tweet.getLabel());
    return ok(labelling.render(tweet, databaseName));
  }
예제 #9
0
파일: Feed.java 프로젝트: virgilio/mupi-dev
  @Dynamic("editor")
  public static Result promote() {
    models.User u = Mupi.getLocalUser(session());
    MultipartFormData body = request().body().asMultipartFormData();
    FilePart picture = body.getFile("picture");
    String picturePath = BLANK_EVT;

    DynamicForm bindedForm = form().bindFromRequest();
    Long i = getInterest(bindedForm.get("interest"));
    Long l = getLocation(bindedForm.get("location"));
    models.Interest iObj = null;
    models.Location lObj = null;
    if (i != null) iObj = models.Interest.find.byId(i);
    if (l != null) lObj = models.Location.find.byId(l);

    final Form<models.Promotion> filledForm = form(models.Promotion.class).bindFromRequest();
    final models.Profile p = Mupi.getLocalUser(session()).profile;

    try {
      if (picture != null) {
        String fileName = picture.getFilename();
        File file = picture.getFile();
        int index = (fileName.toLowerCase()).lastIndexOf('.');
        String extension = "png";

        if (index > 0 && index < fileName.length() - 1) {
          extension = fileName.substring(index + 1).toLowerCase();
        }

        String hashTime = getMD5(System.currentTimeMillis());
        String hashCommunity = getMD5(iObj.toString() + lObj.toString());

        File destinationFile =
            new File(
                MupiParams.EVENT_ROOT
                    + MupiParams.PIC_ROOT
                    + "//"
                    + hashCommunity
                    + "//"
                    + hashTime
                    + fileName);
        FileUtils.copyFile(file, destinationFile);
        picturePath = "/" + hashCommunity + "/" + hashTime + fileName;

        File medium =
            new File(
                MupiParams.EVENT_ROOT
                    + MupiParams.PIC_MEDIUM
                    + "//"
                    + hashCommunity
                    + "//"
                    + hashTime
                    + fileName);
        medium.mkdirs();

        BufferedImage bi = ImageHandler.createSmallInterest(destinationFile);
        bi = ImageHandler.createMediumPromotion(destinationFile);
        ImageIO.write(bi, extension, medium);
      } else {
        picturePath = BLANK_EVT;
      }

      String safeDesc = Jsoup.clean(filledForm.get().getDescription(), Whitelist.simpleText());

      Promotion pr =
          models.Promotion.create(
              p,
              lObj,
              iObj,
              filledForm.get().getTitle(),
              filledForm.get().getAddress(),
              filledForm.get().getDate(),
              filledForm.get().getTime(),
              safeDesc,
              filledForm.get().getLink(),
              picturePath,
              PubType.EVENT,
              new Integer(0),
              new Integer(0),
              new Double(0.0));

      flash(Mupi.FLASH_MESSAGE_KEY, Messages.get("mupi.promotion.created"));

      List<UserEmail> l_ue = models.Profile.emailsFromPublication(pr.getPublication());
      for (UserEmail ue : l_ue) {
        if (u.getEmail().equalsIgnoreCase(ue.getEmail()))
          System.out.println("Commenter: " + ue.getEmail());
        else System.out.println(ue.getEmail());
      }

      return redirect(routes.Feed.feed());
    } catch (Exception e) {
      flash(
          Mupi.FLASH_ERROR_KEY,
          "Erro ao divulgar evento, por favor contate-nos para que possamos resolver este problema.");
      // System.out.println(e.getMessage());
      e.printStackTrace();
      return redirect(routes.Feed.feed());
    }
  }