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:
René Pfeuffer
2018-07-03 09:38:56 +02:00
parent 54776548ea
commit ad60bae74e
5 changed files with 7 additions and 20 deletions

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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;