Use constructor injection

This commit is contained in:
Philipp Czora
2018-06-25 14:10:36 +02:00
parent 0985f76a8a
commit a85961ee57
2 changed files with 19 additions and 12 deletions

View File

@@ -19,9 +19,16 @@ import static sonia.scm.api.v2.resources.ResourceLinks.user;
@Mapper
public abstract class GroupToGroupDtoMapper extends BaseMapper<Group, GroupDto> {
@Inject
private UriInfoStore uriInfoStore;
GroupToGroupDtoMapper() {
}
@Inject
public GroupToGroupDtoMapper(UriInfoStore uriInfoStore) {
this.uriInfoStore = uriInfoStore;
}
@AfterMapping
void appendLinks(Group group, @MappingTarget GroupDto target) {
Links.Builder linksBuilder = linkingTo().self(group(uriInfoStore.get()).self(target.getName()));

View File

@@ -1,11 +1,7 @@
package sonia.scm.api.v2.resources;
import org.apache.shiro.authc.credential.PasswordService;
import org.mapstruct.Context;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.*;
import sonia.scm.user.User;
import javax.inject.Inject;
@@ -15,9 +11,16 @@ import static sonia.scm.api.rest.resources.UserResource.DUMMY_PASSWORT;
@Mapper
public abstract class UserDtoToUserMapper {
@Inject
private PasswordService passwordService;
UserDtoToUserMapper() {
}
@Inject
public UserDtoToUserMapper(PasswordService passwordService) {
this.passwordService = passwordService;
}
@Mappings({
@Mapping(source = "password", target = "password", qualifiedByName = "encrypt"),
@Mapping(target = "creationDate", ignore = true),
@@ -28,12 +31,9 @@ public abstract class UserDtoToUserMapper {
@Named("encrypt")
String encrypt(String password, @Context String originalPassword) {
if (DUMMY_PASSWORT.equals(password))
{
if (DUMMY_PASSWORT.equals(password)) {
return originalPassword;
}
else
{
} else {
return passwordService.encryptPassword(password);
}
}