Esempio n. 1
0
  /**
   * fix the size of the image true, chenged the image size false, not change
   *
   * @param avatar
   */
  private void checkImageSize(Avatar avatar) {
    int maxWidth = this.config.getInt(ConfigKeys.AVATAR_MAX_WIDTH);
    int maxHeight = this.config.getInt(ConfigKeys.AVATAR_MAX_HEIGHT);
    int minWidth = this.config.getInt(ConfigKeys.AVATAR_MIN_WIDTH);
    int minHeight = this.config.getInt(ConfigKeys.AVATAR_MIN_HEIGHT);

    int height = avatar.getHeight();
    int width = avatar.getWidth();

    if (height < minHeight || height > maxHeight || width < minWidth || width > maxWidth) {
      throw new ValidationException("This image size is not allowed!");
    }
  }
Esempio n. 2
0
  /**
   * Updates a existing avatar
   *
   * @param avatar
   * @param image
   */
  public void update(Avatar avatar, UploadedFile uploadedFile) {
    this.isAllowed(avatar);

    if (avatar.getId() == 0) {
      throw new ValidationException("update() expects a avatar with an existing id");
    }

    Avatar current = this.repository.get(avatar.getId());
    avatar.setAvatarType(current.getAvatarType());

    // upload the img and get the upload img info
    String imageDiskName = this.processImageUpload(avatar, uploadedFile);

    if (imageDiskName != null) {
      this.deleteImage(current);

      current.setFileName(imageDiskName);
      current.setHeight(avatar.getHeight());
      current.setWidth(avatar.getWidth());
    }

    this.repository.update(current);
  }