mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
Mob review: base class for mapper
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
package sonia.scm.api.v2.resources;
|
||||||
|
|
||||||
|
import sonia.scm.util.AssertUtil;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
class BaseMapper {
|
||||||
|
|
||||||
|
Instant mapTime(Long epochMilli) {
|
||||||
|
AssertUtil.assertIsNotNull(epochMilli);
|
||||||
|
return Instant.ofEpochMilli(epochMilli);
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<Instant> mapOptionalTime(Long epochMilli) {
|
||||||
|
return Optional
|
||||||
|
.ofNullable(epochMilli)
|
||||||
|
.map(Instant::ofEpochMilli);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,23 +4,19 @@ import de.otto.edison.hal.Links;
|
|||||||
import org.mapstruct.AfterMapping;
|
import org.mapstruct.AfterMapping;
|
||||||
import org.mapstruct.Context;
|
import org.mapstruct.Context;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.Mapping;
|
|
||||||
import org.mapstruct.MappingTarget;
|
import org.mapstruct.MappingTarget;
|
||||||
import sonia.scm.group.Group;
|
import sonia.scm.group.Group;
|
||||||
import sonia.scm.group.GroupPermissions;
|
import sonia.scm.group.GroupPermissions;
|
||||||
import sonia.scm.util.AssertUtil;
|
|
||||||
|
|
||||||
import javax.ws.rs.core.UriInfo;
|
import javax.ws.rs.core.UriInfo;
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static de.otto.edison.hal.Link.link;
|
import static de.otto.edison.hal.Link.link;
|
||||||
import static de.otto.edison.hal.Links.linkingTo;
|
import static de.otto.edison.hal.Links.linkingTo;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public abstract class GroupToGroupDtoMapper {
|
public abstract class GroupToGroupDtoMapper extends BaseMapper {
|
||||||
|
|
||||||
public abstract GroupDto map(Group group, @Context UriInfo uriInfo);
|
public abstract GroupDto map(Group group, @Context UriInfo uriInfo);
|
||||||
|
|
||||||
@@ -55,17 +51,4 @@ public abstract class GroupToGroupDtoMapper {
|
|||||||
memberDto.add(linksBuilder.build());
|
memberDto.add(linksBuilder.build());
|
||||||
return memberDto;
|
return memberDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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)
|
|
||||||
.map(Instant::ofEpochMilli);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,17 +8,14 @@ import org.mapstruct.MappingTarget;
|
|||||||
import sonia.scm.api.rest.resources.UserResource;
|
import sonia.scm.api.rest.resources.UserResource;
|
||||||
import sonia.scm.user.User;
|
import sonia.scm.user.User;
|
||||||
import sonia.scm.user.UserPermissions;
|
import sonia.scm.user.UserPermissions;
|
||||||
import sonia.scm.util.AssertUtil;
|
|
||||||
|
|
||||||
import javax.ws.rs.core.UriInfo;
|
import javax.ws.rs.core.UriInfo;
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static de.otto.edison.hal.Link.link;
|
import static de.otto.edison.hal.Link.link;
|
||||||
import static de.otto.edison.hal.Links.linkingTo;
|
import static de.otto.edison.hal.Links.linkingTo;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public abstract class UserToUserDtoMapper {
|
public abstract class UserToUserDtoMapper extends BaseMapper {
|
||||||
|
|
||||||
public abstract UserDto map(User user, @Context UriInfo uriInfo);
|
public abstract UserDto map(User user, @Context UriInfo uriInfo);
|
||||||
|
|
||||||
@@ -44,15 +41,4 @@ public abstract class UserToUserDtoMapper {
|
|||||||
target.add(
|
target.add(
|
||||||
linksBuilder.build());
|
linksBuilder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
Instant mapTime(Long epochMilli) {
|
|
||||||
AssertUtil.assertIsNotNull(epochMilli);
|
|
||||||
return Instant.ofEpochMilli(epochMilli);
|
|
||||||
}
|
|
||||||
|
|
||||||
Optional<Instant> mapOptionalTime(Long epochMilli) {
|
|
||||||
return Optional
|
|
||||||
.ofNullable(epochMilli)
|
|
||||||
.map(Instant::ofEpochMilli);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user