Package com.skyline.user.model

Examples of com.skyline.user.model.User


   *            相册ID
   * @param request
   * */
  @RequestMapping(value = "/uploadok/{albumId}", method = RequestMethod.GET)
  public ModelAndView uploadOk(@PathVariable("albumId") Long albumId) {
    User user = (User) WebHelper.getSessionAttribute(null, Constant.SESSION_USER);
    if (user == null) {
      throw new NotLoginException("上传照片必须登录");
    }
    long userId = user.getId();
    Album album = albumService.getAlbumForChange(albumId, userId);

    ModelAndView mav = new ModelAndView(ViewPaths.ALBUM_UPLOADOK);
    mav.addObject("album", album);

View Full Code Here


   * */
  @RequestMapping(value = "/uploadok/{albumId}", method = RequestMethod.POST)
  public ModelAndView uploadOk(@PathVariable("albumId") Long albumId, String cover, String ext,
      @RequestParam("description") List<String> descriptions,
      @RequestParam("id") List<Long> ids, String submitToken) {
    User user = (User) WebHelper.getSessionAttribute(null, Constant.SESSION_USER);
    if (user == null) {
      throw new NotLoginException("上传照片必须登录");
    }

    ModelAndView returnMav = null;
    String errMsg = validateForm("uploadOkForm", submitToken);
    if (errMsg != null) {
      returnMav = uploadOk(albumId);
      return processValidationErrors("errMsg", errMsg, returnMav);
    }

    int size = Math.min(ids.size(), descriptions.size());
    StringBuilder errMsgBuilder = new StringBuilder();
    for (int i = 0; i < size; i++) {
      if (ids.get(i) == null) {
        LOGGER.warn("上传后修改图片信息操作失败,ID为:" + albumId + "的相册提交的第" + i + "张图片的ID为空");
        continue;
      }
      errMsg = validateForm("descriptionOnlyForm", descriptions.get(i));
      if (errMsg != null) {
        if (returnMav == null) {
          returnMav = uploadOk(albumId);
        }
        errMsgBuilder.append("第").append(i + 1).append("张图片的").append(errMsg);
        return processValidationErrors("errMsg", errMsgBuilder.toString(), returnMav);
      }
    }

    albumService.changePhotosDescription(albumId, ids, descriptions);
    albumService.changeAlbumCover(user.getId(), albumId, cover, ext);

    WebHelper.removeSessionAttribute(null, Constant.SESSION_UPLOAD_OK_FILES);
    String url = buildRecirectPath(URL_PREFIX + "/view/" + albumId);

    ModelAndView mav = new ModelAndView(new RedirectView(url));
View Full Code Here

    return mav;
  }

  @RequestMapping(value = "/delphoto/{photoId}", method = { RequestMethod.POST, RequestMethod.GET })
  public ModelAndView deletePhoto(@PathVariable("photoId") long photoId) {
    User user = (User) WebHelper.getSessionAttribute(null, Constant.SESSION_USER);
    long userId = 0;
    if (user != null) {
      userId = user.getId();
    }

    Long albumId = albumService.deletePhoto(userId, photoId);
    String url = buildRecirectPath(URL_PREFIX + "/view/" + albumId);
View Full Code Here

    return mav;
  }

  @RequestMapping(value = "/editphoto/{photoId}", method = RequestMethod.GET)
  public ModelAndView editPhoto(@PathVariable("photoId") long photoId) {
    User user = (User) WebHelper.getSessionAttribute(null, Constant.SESSION_USER);
    if (user == null) {
      throw new NotLoginException("编辑照片信息必须登录");
    }
    long userId = user.getId();

    List<Album> albums = albumService.listAlbumNamesOfUser(userId);
    Photo photo = albumService.getPhotoForChange(userId, photoId);

    ModelAndView mav = new ModelAndView(ViewPaths.ALBUM_EDITPHOTO);
View Full Code Here

  }

  @RequestMapping(value = "/editphoto/{photoId}", method = RequestMethod.POST)
  public ModelAndView editPhoto(@PathVariable("photoId") long photoId, String setCover,
      String toAlbumId, @RequestParam("description") String description, String submitToken) {
    User user = (User) WebHelper.getSessionAttribute(null, Constant.SESSION_USER);
    if (user == null) {
      throw new NotLoginException("编辑照片信息必须登录");
    }

    Long toAlbum = NumberUtils.toLong(toAlbumId);

    Map<String, String> formData = new HashMap<String, String>();
    formData.put("submitToken", submitToken);
    formData.put("description", description);
    String errMsg = validateForm("editPhotoForm", formData);
    if (errMsg != null) {
      ModelAndView returnMav = editPhoto(photoId);
      return processValidationErrors("errMsg", errMsg, returnMav);
    }

    long userId = user.getId();
    Photo photo = albumService.getPhotoForChange(userId, photoId);
    Album origAlbum = albumService.getAlbumForChange(photo.getAlbumId(), userId);
    if (setCover == null) {
      if (!photo.getAlbumId().equals(toAlbum)) {
        albumService.changePhotoAlbum(userId, photoId, photo.getAlbumId(), toAlbum);
View Full Code Here

  @RequestMapping(value = "/changephotodesc/{photoId}", method = RequestMethod.POST)
  public @ResponseBody
  Map<String, Object> changePhotoDescription(@PathVariable("photoId") long photoId,
      @RequestParam("description") String description) {
    Map<String, Object> result = new HashMap<String, Object>();
    User user = (User) WebHelper.getSessionAttribute(null, Constant.SESSION_USER);
    if (user == null) {
      result.put("success", Boolean.FALSE);
      result.put("errmsg", "修改照片描述必须登录");
      result.put("logined", Boolean.FALSE);
      return result;
    }
    result.put("logined", Boolean.TRUE);

    Errors errors = ValidationUtils.validateForm("descriptionOnlyForm", description);
    String[] errorMsgs = ValidationUtils.getAllErrorMessages(errors);
    if (errorMsgs.length > 0) {
      result.put("success", Boolean.FALSE);
      result.put("errmsg", errorMsgs[0]);
      return result;
    }

    try {
      Photo photo = albumService.getPhotoForChange(user.getId(), photoId);
      String oldDesc = CommonUtils.nullStringToEmpty(photo.getDescription());
      if (!oldDesc.equals(description)) {
        albumService.changePhotoDescription(photo.getAlbumId(), photoId, description);
      }
      result.put("success", Boolean.TRUE);
View Full Code Here

  @RequestMapping(value = "/setcover/{photoId}", method = RequestMethod.POST)
  public @ResponseBody
  Map<String, Object> changePhotoCover(@PathVariable("photoId") long photoId) {
    Map<String, Object> result = new HashMap<String, Object>();
    User user = (User) WebHelper.getSessionAttribute(null, Constant.SESSION_USER);
    if (user == null) {
      result.put("success", Boolean.FALSE);
      result.put("errmsg", "设置相册封面必须登录");
      result.put("logined", Boolean.FALSE);
      return result;
    }
    result.put("logined", Boolean.TRUE);

    try {
      Photo photo = albumService.getPhotoForChange(user.getId(), photoId);
      albumService.changeAlbumCover(user.getId(), photo.getAlbumId(), photo.getSmallFile(),
          photo.getExt());
      result.put("success", Boolean.TRUE);
      result.put("errmsg", "设置相册封面成功");
      return result;
    } catch (Exception e) {
View Full Code Here

  @RequestMapping(value = "/viewphoto/{photoId}", method = RequestMethod.POST)
  public @ResponseBody
  Map<String, Object> viewPhoto(@PathVariable("photoId") long photoId) {
    Map<String, Object> result = new HashMap<String, Object>();
    try {
      User user = (User) WebHelper.getSessionAttribute(null, Constant.SESSION_USER);
      long viewerId = 0;
      boolean addVisitCount = false;
      if (user != null) {
        viewerId = user.getId();
        // FIXME 判断是否需要增加访问量
      }
      int authority = AuthorityUtil.getAuthority(null, viewerId);
      Photo photo = albumService.getPhotoDetailById(photoId, viewerId, addVisitCount);
      // 判断权限
View Full Code Here

  @RequestMapping(value = "/setportrait/{photoId}", method = RequestMethod.POST)
  public @ResponseBody
  Map<String, Object> changeAsUserPortrait(@PathVariable("photoId") long photoId) {
    Map<String, Object> result = new HashMap<String, Object>();
    User user = (User) WebHelper.getSessionAttribute(null, Constant.SESSION_USER);
    if (user == null) {
      result.put("success", Boolean.FALSE);
      result.put("errmsg", "设置头像必须登录");
      result.put("logined", Boolean.FALSE);
      return result;
    }
    result.put("logined", Boolean.TRUE);

    try {
      Long ownerId = user.getId();
      Photo photo = albumService.getPhotoForChange(ownerId, photoId);
      Album portraitAlbum = albumService.getUserPortraitAlbum(ownerId);
      Long albumId = portraitAlbum.getId();
      String photoExt = photo.getExt();
      String remoteFileKey = photo.getSmallFile() + '.' + photoExt;
      if (SkylineImagineUtils.isExtMultiFrame(photoExt)) {// 如果是动态图,需要压缩成单帧图
        remoteFileKey = photo.getMiddleFile() + '.' + photoExt;
        String filename = FilenameUtils.getName(remoteFileKey);
        String fileKey = SkylineImagineUtils.generateFileKey(ownerId.toString(),
            albumId.toString(), filename);
        String localFile = SkylineImagineUtils.generateFilePath(localStorePath, ownerId,
            albumId, fileKey + '.' + photoExt);
        File destFile = new File(localFile);

        File dir = destFile.getParentFile();
        if (!dir.exists()) {
          boolean success = dir.mkdirs();
          if (!success && !dir.exists()) {
            LOGGER.warn("mkdirs :" + dir + " failed");
          }
        }
        // 保存服务器上的图片到本地目标文件
        if (fileOperator == null) {
          String srcFile = localStorePath + '/' + remoteFileKey;
          FileUtils.copyFile(new File(srcFile), destFile);
        } else {
          fileOperator.downloadFile(remoteFileKey, localFile);
        }
        // 压缩该目标图片
        LocalImageResizeTask task = new LocalImageResizeTask(localFile, baseSizes);
        task.setAlbumId(albumId);
        task.setUserId(ownerId);
        task.setSupportMulitFrame(false);
        ImageResizeResult resizeResult = imagine.processSingleImage(localStorePath, task);
        Photo portrait = albumService
            .createPortraitPhoto(user, portraitAlbum, resizeResult);
        remoteFileKey = portrait.getSmallFile() + '.' + portrait.getExt();
      } else {
        albumService.copyPhotoToPortraitAlbum(portraitAlbum, photo);
      }

      SkylineImageCropTask cropTask = new SkylineImageCropTask(remoteFileKey, portraitSize);
      cropTask.setAlbumId(albumId);
      cropTask.setUserId(ownerId);
      ImageCropResult cropResult = crop.processImage(localStorePath, cropTask);
      String portraitFile = cropResult.getFileKey();

      personalInfoService.changeUserPortrait(ownerId, portraitFile);
      user.setPortrait(portraitFile);
      WebHelper.setSessionAttribute(null, Constant.SESSION_USER, user);

      result.put("success", Boolean.TRUE);
      result.put("errmsg", "设置头像成功");
      return result;
View Full Code Here

   *
   * @returnzise
   */
  @RequestMapping(value = "/discovery", method = RequestMethod.GET)
  public ModelAndView discoverySpotrequest() {
    User user = (User) WebHelper.getSessionAttribute(null, Constant.SESSION_USER);
    ModelAndView v = new ModelAndView();
    if (user == null) {
      v.setViewName(ViewPaths.USER_LOGIN);
      return v;
    }
View Full Code Here

TOP

Related Classes of com.skyline.user.model.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.