mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
Mob review
This commit is contained in:
@@ -37,10 +37,8 @@ package sonia.scm.api.rest.resources;
|
||||
|
||||
import org.apache.commons.beanutils.BeanComparator;
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.LastModifiedAware;
|
||||
import sonia.scm.Manager;
|
||||
import sonia.scm.ModelObject;
|
||||
@@ -50,12 +48,6 @@ import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
import javax.ws.rs.core.EntityTag;
|
||||
import javax.ws.rs.core.GenericEntity;
|
||||
@@ -63,6 +55,11 @@ import javax.ws.rs.core.Request;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.Links;
|
||||
import org.mapstruct.*;
|
||||
import org.mapstruct.AfterMapping;
|
||||
import org.mapstruct.Context;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import sonia.scm.api.rest.resources.UserResource;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserPermissions;
|
||||
@@ -17,7 +20,7 @@ import static de.otto.edison.hal.Links.linkingTo;
|
||||
@Mapper
|
||||
public abstract class User2UserDtoMapper {
|
||||
|
||||
public abstract UserDto userToUserDto(User user, @Context UriInfo uriInfo);
|
||||
public abstract UserDto map(User user, @Context UriInfo uriInfo);
|
||||
|
||||
@AfterMapping
|
||||
void removePassword(@MappingTarget UserDto target) {
|
||||
@@ -42,13 +45,11 @@ public abstract class User2UserDtoMapper {
|
||||
linksBuilder.build());
|
||||
}
|
||||
|
||||
@Mapping(target = "creationDate")
|
||||
Instant mapTime(Long epochMilli) {
|
||||
AssertUtil.assertIsNotNull(epochMilli);
|
||||
return Instant.ofEpochMilli(epochMilli);
|
||||
}
|
||||
|
||||
@Mapping(target = "lastModified")
|
||||
Optional<Instant> mapOptionalTime(Long epochMilli) {
|
||||
return Optional
|
||||
.ofNullable(epochMilli)
|
||||
|
||||
@@ -29,9 +29,9 @@ public class UserCollection2DtoMapper {
|
||||
this.userToDtoMapper = userToDtoMapper;
|
||||
}
|
||||
|
||||
public UserCollectionDto userCollectionToDto(UriInfo uriInfo, int pageNumber, int pageSize, PageResult<User> pageResult) {
|
||||
public UserCollectionDto map(UriInfo uriInfo, int pageNumber, int pageSize, PageResult<User> pageResult) {
|
||||
NumberedPaging paging = zeroBasedNumberedPaging(pageNumber, pageSize, pageResult.hasMore());
|
||||
List<UserDto> dtos = pageResult.getEntities().stream().map(user -> userToDtoMapper.userToUserDto(user, uriInfo)).collect(Collectors.toList());
|
||||
List<UserDto> dtos = pageResult.getEntities().stream().map(user -> userToDtoMapper.map(user, uriInfo)).collect(Collectors.toList());
|
||||
|
||||
UserCollectionDto userCollectionDto = new UserCollectionDto(
|
||||
createLinks(uriInfo, paging),
|
||||
|
||||
@@ -66,7 +66,7 @@ public class UserCollectionResource extends AbstractManagerResource<User, UserEx
|
||||
@QueryParam("desc") boolean desc) {
|
||||
PageResult<User> pageResult = fetchPage(sortby, desc, page, pageSize);
|
||||
|
||||
return Response.ok(new UserCollection2DtoMapper(userToDtoMapper).userCollectionToDto(uriInfo, page, pageSize, pageResult)).build();
|
||||
return Response.ok(new UserCollection2DtoMapper(userToDtoMapper).map(uriInfo, page, pageSize, pageResult)).build();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ public class UserCollectionResource extends AbstractManagerResource<User, UserEx
|
||||
})
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
public Response create(@Context UriInfo uriInfo, UserDto userDto) throws IOException, UserException {
|
||||
User user = dtoToUserMapper.userDtoToUser(userDto, "");
|
||||
User user = dtoToUserMapper.map(userDto, "");
|
||||
manager.create(user);
|
||||
|
||||
LinkBuilder builder = new LinkBuilder(uriInfo, UserV2Resource.class, UserSubResource.class);
|
||||
|
||||
@@ -22,7 +22,7 @@ public abstract class UserDto2UserMapper {
|
||||
@Mapping(target = "creationDate", ignore = true),
|
||||
@Mapping(target = "lastModified", ignore = true)
|
||||
})
|
||||
public abstract User userDtoToUser(UserDto userDto, @Context String originalPassword);
|
||||
public abstract User map(UserDto userDto, @Context String originalPassword);
|
||||
|
||||
@Named("encrypt")
|
||||
String encrypt(String password, @Context String originalPassword) {
|
||||
|
||||
@@ -52,7 +52,7 @@ public class UserSubResource extends AbstractManagerResource<User, UserException
|
||||
if (SecurityUtils.getSubject().hasRole(Role.ADMIN))
|
||||
{
|
||||
User user = manager.get(id);
|
||||
UserDto userDto = userToDtoMapper.userToUserDto(user, uriInfo);
|
||||
UserDto userDto = userToDtoMapper.map(user, uriInfo);
|
||||
return Response.ok(userDto).build();
|
||||
}
|
||||
else
|
||||
@@ -73,7 +73,7 @@ public class UserSubResource extends AbstractManagerResource<User, UserException
|
||||
@PathParam("id") String name, UserDto userDto)
|
||||
{
|
||||
String originalPassword = manager.get(name).getPassword();
|
||||
User user = dtoToUserMapper.userDtoToUser(userDto, originalPassword);
|
||||
User user = dtoToUserMapper.map(userDto, originalPassword);
|
||||
return update(name, user);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user