Implement update

This commit is contained in:
René Pfeuffer
2018-05-28 14:55:22 +02:00
parent cf6353dcbf
commit 0583fd2210
6 changed files with 38 additions and 100 deletions

View File

@@ -202,14 +202,13 @@ public abstract class AbstractManagerResource<T extends ModelObject,
*
*
*
* @param uriInfo
* @param name
* @param item
*
*
* @return
*/
public Response update(UriInfo uriInfo, String name, T item)
public Response update(String name, T item)
{
Response response = null;

View File

@@ -41,34 +41,17 @@ import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.ResponseHeader;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import com.webcohesion.enunciate.metadata.rs.TypeHint;
import org.apache.shiro.SecurityUtils;
import sonia.scm.group.Group;
import sonia.scm.group.GroupException;
import sonia.scm.group.GroupManager;
import sonia.scm.security.Role;
//~--- JDK imports ------------------------------------------------------------
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import java.util.Collection;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
//~--- JDK imports ------------------------------------------------------------
/**
* RESTful Web Service Resource to manage groups and their members.
@@ -150,7 +133,6 @@ public class GroupResource
/**
* Modifies the given group. <strong>Note:</strong> This method requires admin privileges.
*
* @param uriInfo current uri informations
* @param name name of the group to be modified
* @param group group object to modify
*
@@ -166,10 +148,9 @@ public class GroupResource
@TypeHint(TypeHint.NO_CONTENT.class)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Override
public Response update(@Context UriInfo uriInfo,
@PathParam("id") String name, Group group)
public Response update(@PathParam("id") String name, Group group)
{
return super.update(uriInfo, name, group);
return super.update(name, group);
}
//~--- get methods ----------------------------------------------------------

View File

@@ -42,66 +42,26 @@ import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.ResponseHeader;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import com.webcohesion.enunciate.metadata.rs.TypeHint;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.AuthorizationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.repository.BlameResult;
import sonia.scm.repository.Branches;
import sonia.scm.repository.BrowserResult;
import sonia.scm.repository.Changeset;
import sonia.scm.repository.ChangesetPagingResult;
import sonia.scm.repository.HealthChecker;
import sonia.scm.repository.Permission;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryException;
import sonia.scm.repository.RepositoryIsNotArchivedException;
import sonia.scm.repository.RepositoryManager;
import sonia.scm.repository.RepositoryNotFoundException;
import sonia.scm.repository.Tags;
import sonia.scm.repository.api.BlameCommandBuilder;
import sonia.scm.repository.api.BrowseCommandBuilder;
import sonia.scm.repository.api.CatCommandBuilder;
import sonia.scm.repository.api.CommandNotSupportedException;
import sonia.scm.repository.api.DiffCommandBuilder;
import sonia.scm.repository.api.DiffFormat;
import sonia.scm.repository.api.LogCommandBuilder;
import sonia.scm.repository.api.RepositoryService;
import sonia.scm.repository.api.RepositoryServiceFactory;
import sonia.scm.repository.*;
import sonia.scm.repository.api.*;
import sonia.scm.util.AssertUtil;
import sonia.scm.util.HttpUtil;
import sonia.scm.util.IOUtil;
import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import javax.ws.rs.core.Response.Status;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.StreamingOutput;
import javax.ws.rs.core.UriInfo;
import org.apache.shiro.authz.AuthorizationException;
//~--- JDK imports ------------------------------------------------------------
/**
* Repository related RESTful Web Service Endpoint.
@@ -273,7 +233,6 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
/**
* Modifies the given repository. <strong>Note:</strong> This method requires owner privileges.
*
* @param uriInfo current uri informations
* @param id id of the repository to be modified
* @param repository repository object to modify
*
@@ -290,9 +249,9 @@ public class RepositoryResource extends AbstractManagerResource<Repository, Repo
@TypeHint(TypeHint.NO_CONTENT.class)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Override
public Response update(@Context UriInfo uriInfo, @PathParam("id") String id, Repository repository)
public Response update(@PathParam("id") String id, Repository repository)
{
return super.update(uriInfo, id, repository);
return super.update(id, repository);
}
//~--- get methods ----------------------------------------------------------

View File

@@ -17,6 +17,8 @@ public abstract class UserMapper {
abstract public UserDto userToUserDto(User user, @Context UriInfo uriInfo);
abstract public User userDtoToUser(UserDto user, @Context UriInfo uriInfo);
@AfterMapping
public void appendLinks(User source, @MappingTarget UserDto target, @Context UriInfo uriInfo) {
Map<String, Link> links = new LinkedHashMap<>();

View File

@@ -97,4 +97,20 @@ public class UserNewResource extends AbstractManagerResource<User, UserException
items.stream().map(user -> UserMapper.INSTANCE.userToUserDto(user, uriInfo)).collect(Collectors.toList());
return Response.ok(new GenericEntity<Collection<User>>(items) {}).build();
}
@PUT
@Path("{id}")
@StatusCodes({
@ResponseCode(code = 204, condition = "update success"),
@ResponseCode(code = 403, condition = "forbidden, the current user has no admin privileges"),
@ResponseCode(code = 500, condition = "internal server error")
})
@TypeHint(TypeHint.NO_CONTENT.class)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response update(@Context UriInfo uriInfo,
@PathParam("id") String name, UserDto userDto)
{
User user = UserMapper.INSTANCE.userDtoToUser(userDto, uriInfo);
return super.update(name, user);
}
}

View File

@@ -41,10 +41,8 @@ import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.ResponseHeader;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import com.webcohesion.enunciate.metadata.rs.TypeHint;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.credential.PasswordService;
import sonia.scm.security.Role;
import sonia.scm.user.User;
import sonia.scm.user.UserException;
@@ -52,26 +50,11 @@ import sonia.scm.user.UserManager;
import sonia.scm.util.AssertUtil;
import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import java.util.Collection;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
//~--- JDK imports ------------------------------------------------------------
/**
* RESTful Web Service Resource to manage users.
@@ -155,7 +138,6 @@ public class UserResource extends AbstractManagerResource<User, UserException>
/**
* Modifies the given user. <strong>Note:</strong> This method requires admin privileges.
*
* @param uriInfo current uri informations
* @param name name of the user to be modified
* @param user user object to modify
*
@@ -171,10 +153,9 @@ public class UserResource extends AbstractManagerResource<User, UserException>
@TypeHint(TypeHint.NO_CONTENT.class)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Override
public Response update(@Context UriInfo uriInfo,
@PathParam("id") String name, User user)
public Response update(@PathParam("id") String name, User user)
{
return super.update(uriInfo, name, user);
return super.update(name, user);
}
//~--- get methods ----------------------------------------------------------