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