Ejemplo n.º 1
0
  @POST
  @Path("type/{type}/owner/{owningObjectId}/avatar")
  public Response createAvatarFromTemporary(
      final @PathParam("type") String avatarType,
      final @PathParam("owningObjectId") String owningObjectId,
      final AvatarCroppingBean croppingInstructions) {
    try {
      final Avatar.Type avatarsType = Avatar.Type.getByName(avatarType);
      if (null == avatarsType) {
        throw new NoSuchElementException("avatarType");
      }
      final ApplicationUser remoteUser = authContext.getUser();

      final AvatarBean avatarFromTemporary =
          avatarTemporaryHelper.createAvatarFromTemporary(
              remoteUser, avatarsType, owningObjectId, croppingInstructions);

      return Response.status(Response.Status.CREATED)
          .entity(avatarFromTemporary)
          .cacheControl(never())
          .build();
    } catch (NoSuchElementException x) {
      return Response.status(Response.Status.NOT_FOUND).entity(x.getMessage()).build();
    }
  }
Ejemplo n.º 2
0
  /**
   * Creates temporary avatar
   *
   * @param avatarType Type of entity where to change avatar
   * @param owningObjectId Entity id where to change avatar
   * @param filename name of file being uploaded
   * @param size size of file
   * @param request servlet request
   * @return temporary avatar cropping instructions
   * @since v5.0
   */
  @POST
  @Consumes(MediaType.WILDCARD)
  @RequiresXsrfCheck
  @Path("type/{type}/owner/{owningObjectId}/temp")
  public Response storeTemporaryAvatar(
      final @PathParam("type") String avatarType,
      final @PathParam("owningObjectId") String owningObjectId,
      final @QueryParam("filename") String filename,
      final @QueryParam("size") Long size,
      final @Context HttpServletRequest request) {
    try {
      final Avatar.Type avatarsType = Avatar.Type.getByName(avatarType);
      if (null == avatarsType) {
        throw new NoSuchElementException("avatarType");
      }

      final ApplicationUser remoteUser = authContext.getUser();

      // get from paramter!!
      Avatar.Size avatarTargetSize = Avatar.Size.LARGE;
      final Response storeTemporaryAvatarResponse =
          avatarTemporaryHelper.storeTemporaryAvatar(
              remoteUser, avatarsType, owningObjectId, avatarTargetSize, filename, size, request);

      return storeTemporaryAvatarResponse;
    } catch (NoSuchElementException x) {
      return Response.status(Response.Status.NOT_FOUND).entity(x.getMessage()).build();
    }
  }
Ejemplo n.º 3
0
  @POST
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  @RequiresXsrfCheck
  @Path("type/{type}/owner/{owningObjectId}/temp")
  @Produces({MediaType.TEXT_HTML})
  public Response storeTemporaryAvatarUsingMultiPart(
      final @PathParam("type") String avatarType,
      final @PathParam("owningObjectId") String owningObjectId,
      final @MultipartFormParam("avatar") FilePart filePart,
      final @Context HttpServletRequest request) {
    try {
      try {
        final Avatar.Type avatarsType = Avatar.Type.getByName(avatarType);
        if (null == avatarsType) {
          throw new NoSuchElementException("avatarType");
        }

        final ApplicationUser remoteUser = authContext.getUser();

        // get from paramter!!
        Avatar.Size avatarTargetSize = Avatar.Size.LARGE;
        final Response storeTemporaryAvatarResponse =
            avatarTemporaryHelper.storeTemporaryAvatar(
                remoteUser, avatarsType, owningObjectId, avatarTargetSize, filePart, request);

        return storeTemporaryAvatarResponse;
      } catch (NoSuchElementException x) {
        return Response.status(Response.Status.NOT_FOUND).entity(x.getMessage()).build();
      }
    } catch (RESTException x) {
      String errorMsgs = x.toString();
      String sep = "";

      return Response.status(Response.Status.OK)
          .entity(
              "<html><body>"
                  + "<textarea>"
                  + "{"
                  + "\"errorMessages\": ["
                  + errorMsgs
                  + "]"
                  + "}"
                  + "</textarea>"
                  + "</body></html>")
          .cacheControl(never())
          .build();
    }
  }
Ejemplo n.º 4
0
  /**
   * Deletes avatar
   *
   * @param avatarType Project id or project key
   * @param id database id for avatar
   * @return temporary avatar cropping instructions
   * @since v5.0
   */
  @DELETE
  @Path("type/{type}/owner/{owningObjectId}/avatar/{id}")
  public Response deleteAvatar(
      final @PathParam("type") String avatarType,
      final @PathParam("owningObjectId") String owningObjectId,
      @PathParam("id") final Long id) {
    final Avatar.Type avatarsType = Avatar.Type.getByName(avatarType);
    final TypeAvatarService avatarsForType = universalAvatars.getAvatars(avatarsType);

    if (null == avatarsForType) {
      return Response.status(Response.Status.NOT_FOUND).build();
    }
    if (!avatarsForType.canUserCreateAvatar(authContext.getUser(), owningObjectId)) {
      return Response.status(Response.Status.FORBIDDEN).build();
    }

    final Response avatarFromTemporaryResponse = avatarResourceHelper.deleteAvatar(id);
    return avatarFromTemporaryResponse;
  }
Ejemplo n.º 5
0
  /** @since v6.3 */
  @GET
  @Path("type/{type}/owner/{owningObjectId}")
  public Response getAvatars(
      final @PathParam("type") String avatarType,
      final @PathParam("owningObjectId") String owningObjectId) {
    final Avatar.Type avatarsType = Avatar.Type.getByName(avatarType);
    final TypeAvatarService avatarsForType = universalAvatars.getAvatars(avatarsType);
    if (null == avatarsForType) {
      return Response.status(Response.Status.NOT_FOUND).entity("avatarType").build();
    }
    final AvatarImageResolver uriResolver = universalAvatars.getImages(avatarsType);
    if (null == uriResolver) {
      return Response.status(Response.Status.NOT_FOUND).entity("avatarType").build();
    }

    final SystemAndCustomAvatars allAvatars =
        avatarsForType.getAvatars(authContext.getUser(), owningObjectId);

    Map<String, List<AvatarBean>> result = sytemAndCustomAvatarsToBeanMap(uriResolver, allAvatars);

    return Response.ok(result).build();
  }