Introduce interface to be used by dto mappers with Instant fields

This commit is contained in:
René Pfeuffer
2018-09-14 15:00:09 +02:00
parent 188d2d8cef
commit 45359742ca
5 changed files with 13 additions and 10 deletions

View File

@@ -3,14 +3,8 @@ package sonia.scm.api.v2.resources;
import de.otto.edison.hal.HalRepresentation;
import org.mapstruct.Mapping;
import java.time.Instant;
public abstract class BaseMapper<T, D extends HalRepresentation> {
public abstract class BaseMapper<T, D extends HalRepresentation> implements InstantAttributeMapper {
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
public abstract D map(T modelObject);
protected Instant mapTime(Long epochMilli) {
return epochMilli == null? null: Instant.ofEpochMilli(epochMilli);
}
}

View File

@@ -0,0 +1,9 @@
package sonia.scm.api.v2.resources;
import java.time.Instant;
public interface InstantAttributeMapper {
default Instant mapTime(Long epochMilli) {
return epochMilli == null? null: Instant.ofEpochMilli(epochMilli);
}
}

View File

@@ -23,7 +23,7 @@ import static de.otto.edison.hal.Link.link;
import static de.otto.edison.hal.Links.linkingTo;
@Mapper
public abstract class ChangesetToChangesetDtoMapper extends BaseMapper<Changeset, ChangesetDto> {
public abstract class ChangesetToChangesetDtoMapper implements InstantAttributeMapper {
@Inject
private RepositoryServiceFactory serviceFactory;

View File

@@ -16,7 +16,7 @@ import static de.otto.edison.hal.Link.link;
import static de.otto.edison.hal.Links.linkingTo;
@Mapper
public abstract class ChangesetToParentDtoMapper extends BaseMapper<Changeset, ParentChangesetDto> {
public abstract class ChangesetToParentDtoMapper {
@Inject
private ResourceLinks resourceLinks;

View File

@@ -14,7 +14,7 @@ import javax.inject.Inject;
import static de.otto.edison.hal.Link.link;
@Mapper
public abstract class FileObjectToFileObjectDtoMapper extends BaseMapper<FileObject, FileObjectDto> {
public abstract class FileObjectToFileObjectDtoMapper implements InstantAttributeMapper {
@Inject
private ResourceLinks resourceLinks;