mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
Do not use Optional for modification date
First, Optionals should not be used for fields, second this does not provide any benefits
This commit is contained in:
@@ -3,25 +3,15 @@ package sonia.scm.api.v2.resources;
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import org.mapstruct.Mapping;
|
||||
import sonia.scm.ModelObject;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
abstract class BaseMapper<T extends ModelObject, D extends HalRepresentation> {
|
||||
|
||||
|
||||
@Mapping(target = "attributes", ignore = true) // We do not map HAL attributes
|
||||
public abstract D map(T user);
|
||||
|
||||
Instant mapTime(Long epochMilli) {
|
||||
AssertUtil.assertIsNotNull(epochMilli);
|
||||
return Instant.ofEpochMilli(epochMilli);
|
||||
}
|
||||
|
||||
Optional<Instant> mapOptionalTime(Long epochMilli) {
|
||||
return Optional
|
||||
.ofNullable(epochMilli)
|
||||
.map(Instant::ofEpochMilli);
|
||||
return epochMilli == null? null: Instant.ofEpochMilli(epochMilli);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,15 +10,14 @@ import lombok.Setter;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Getter @Setter @NoArgsConstructor
|
||||
public class GroupDto extends HalRepresentation {
|
||||
|
||||
private Instant creationDate;
|
||||
private String description;
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
private Optional<Instant> lastModified;
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Instant lastModified;
|
||||
private String name;
|
||||
private String type;
|
||||
private Map<String, String> properties;
|
||||
|
||||
@@ -9,7 +9,6 @@ import lombok.Setter;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@NoArgsConstructor @Getter @Setter
|
||||
public class UserDto extends HalRepresentation {
|
||||
@@ -17,8 +16,8 @@ public class UserDto extends HalRepresentation {
|
||||
private boolean admin;
|
||||
private Instant creationDate;
|
||||
private String displayName;
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
private Optional<Instant> lastModified;
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Instant lastModified;
|
||||
private String mail;
|
||||
private String name;
|
||||
private String password;
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.mockito.Mock;
|
||||
import sonia.scm.user.User;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -47,7 +46,7 @@ public class UserDtoToUserMapperTest {
|
||||
UserDto dto = new UserDto();
|
||||
dto.setName("abc");
|
||||
dto.setCreationDate(Instant.now());
|
||||
dto.setLastModified(Optional.empty());
|
||||
dto.setLastModified(null);
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +122,6 @@ public class UserToUserDtoMapperTest {
|
||||
UserDto userDto = mapper.map(user);
|
||||
|
||||
assertEquals(expectedCreationDate, userDto.getCreationDate());
|
||||
assertEquals(expectedModificationDate, userDto.getLastModified().get());
|
||||
assertEquals(expectedModificationDate, userDto.getLastModified());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user