Пример #1
0
  public String displayRoomDetail(int id) {
    try {
      Accommodation accom = accommodationFacade.find(id);
      if (accom != null) {
        curAccom = new Accommodation();
        curAccom.setAccomName(accom.getAccomName());
        curAccom.setDescription(accom.getDescription());
        curAccom.setPrice(accom.getPrice());
        curAccom.setAccomId(id);
        curAccom.setNoOfBed(accom.getNoOfBed());
        curAccom.setNoOfPersons(accom.getNoOfPersons());
        curAccom.setNoOfToilet(accom.getNoOfToilet());
        curAccom.setCustId(customerFacade.find(1));

        List<Comments> commentsCount =
            commentsFacade.findCommentsByAccomId(
                id); // != null ? commentsFacade.findCommentsByAccomId(id).size() : 0;
        Gson gson = new Gson();
        RoomImage roomImage = gson.fromJson(accom.getImages(), RoomImage.class);
        // curAccom.setImages(accom.getImages());
        slider1 = roomImage.getSlider1();
        slider2 = roomImage.getSlider2();
        slider3 = roomImage.getSlider3();

        List<Rating> ratings = ratingFacade.findByAccRoomId(id);
        int sumRateScore = 0;
        for (Rating rate : ratings) {
          sumRateScore += rate.getScore();
        }
        displayRate = ratings.size() > 0 ? sumRateScore / ratings.size() : 0;
      }
    } catch (Exception ex) {
      printStackTrace();
    }
    return "roomdetail";
  }
Пример #2
0
  public String createRoom() {
    try {
      //             log.info("call upload...");
      //        log.log(Level.INFO, "content-type:{0}", file.getContentType());
      //        log.log(Level.INFO, "filename:{0}", file.getName());
      //        log.log(Level.INFO, "submitted filename:{0}", file.getSubmittedFileName());

      Date date = new Date();
      DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
      roomImageFileNames = new ArrayList<>();
      List<Part> files = new ArrayList<Part>();

      files.add(thumbnail);

      files.add(file1);

      files.add(file2);

      files.add(file3);
      // Uploading room image
      for (Part itemFile : files) {

        if (itemFile == null) {

          continue;
        }

        InputStream inputStream = itemFile.getInputStream();
        String fileName = dateFormat.format(date) + getFilename(itemFile);
        roomImageFileNames.add(fileName);
        File file = new File("C:/room4u/images/" + fileName);
        FileOutputStream outputStream = new FileOutputStream(file);

        if (!file.exists()) {
          file.createNewFile();
        }

        byte[] buffer = new byte[6096];
        int bytesRead = 0;
        while (true) {
          bytesRead = inputStream.read(buffer);
          if (bytesRead > 0) {
            outputStream.write(buffer, 0, bytesRead);
          } else {
            break;
          }
        }
        outputStream.close();
        inputStream.close();
      }
      //            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Room is
      // created!"));

      room.setAccomId(1);
      Customer cust = customerFacade.find(1);
      room.setCustId(cust);
      room.setAddress(houseNumber + " " + street + " " + ward + " " + district + " " + city);
      room.setCreatedDate(date);

      room.setCreatedBy("Can");

      // Store Image File name as json string.
      RoomImage roomImage = new RoomImage();

      roomImage.setThumbnail(roomImageFileNames.get(0));
      roomImage.setSlider1(roomImageFileNames.get(1));
      roomImage.setSlider2(roomImageFileNames.get(2));
      roomImage.setSlider3(roomImageFileNames.get(3));

      Gson gson = new Gson();
      String jsonImage = gson.toJson(roomImage);
      room.setImages(jsonImage);

      accommodationFacade.create(room);
      // RequestContext.getCurrentInstance().execute("alert('peek-a-boo');");

    } catch (Exception ex) {
      printStackTrace();
    }

    return "index";
  }