コード例 #1
0
  @DELETE
  @Path("{id}")
  public Response deleteResourceType(
      @PathParam("id") Long id, @Context HttpServletRequest request) {

    if (!AuthenticationUtils.isAdmin(request.getSession()))
      return Response.status(Response.Status.UNAUTHORIZED).build();

    final ResourceTypeService resourceTypeService = new ResourceTypeServiceImpl();
    final ResourceType resourceType = resourceTypeService.find(id);

    if (resourceType == null) {
      return Response.status(Response.Status.BAD_REQUEST).build();
    }
    try {
      resourceTypeService.delete(resourceType);
    } catch (RollbackException cve) {
      return Response.status(Response.Status.CONFLICT)
          .entity(
              "You can't delete a resource type because one resource is linked to a reservation")
          .build();
    }

    return Response.status(Response.Status.OK)
        .entity("ResourceType " + resourceType.getName() + " has been successfully deleted.")
        .build();
  }
コード例 #2
0
  @PUT
  public Response createResourceType(
      @FormParam("name") final String name, @Context HttpServletRequest request) {

    if (!AuthenticationUtils.isAdmin(request.getSession()))
      return Response.status(Response.Status.UNAUTHORIZED).build();

    ResourceTypeService resourceTypeService = new ResourceTypeServiceImpl();

    final ResourceType resourceType = new ResourceType(name);

    resourceTypeService.create(resourceType);
    return Response.status(Response.Status.OK)
        .entity("ResourceType " + resourceType.getName() + " has been successfully created.")
        .build();
  }
コード例 #3
0
  @POST
  public Response editResourceType(
      @FormParam("id") final Long id,
      @FormParam("name") final String name,
      @Context HttpServletRequest request) {

    if (!AuthenticationUtils.isAdmin(request.getSession()))
      return Response.status(Response.Status.UNAUTHORIZED).build();

    final ResourceTypeService resourceTypeService = new ResourceTypeServiceImpl();
    final ResourceType resourceType = resourceTypeService.find(id);

    if (resourceType == null) {
      return Response.status(Response.Status.BAD_REQUEST).build();
    }

    resourceType.setName(name);

    resourceTypeService.update(resourceType);
    return Response.status(Response.Status.OK)
        .entity("ResourceType " + resourceType.getName() + " has been successfully edited.")
        .build();
  }