Source project for the draft article
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package com.baeldung.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author sasam0320
|
||||
* @date 4/18/2020
|
||||
*/
|
||||
public class User {
|
||||
|
||||
private String userId;
|
||||
private String userName;
|
||||
private String email;
|
||||
private String contactNumber;
|
||||
private String userType;
|
||||
|
||||
// Standard constructors, getters and setters
|
||||
|
||||
public User(){}
|
||||
|
||||
public User(String userId, String userName, String email, String contactNumber, String userType) {
|
||||
this.userId = userId;
|
||||
this.userName = userName;
|
||||
this.email = email;
|
||||
this.contactNumber = contactNumber;
|
||||
this.userType = userType;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getContactNumber() {
|
||||
return contactNumber;
|
||||
}
|
||||
|
||||
public void setContactNumber(String contactNumber) {
|
||||
this.contactNumber = contactNumber;
|
||||
}
|
||||
|
||||
public String getUserType() {
|
||||
return userType;
|
||||
}
|
||||
|
||||
public void setUserType(String userType) {
|
||||
this.userType = userType;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.baeldung.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author sasam0320
|
||||
* @date 4/18/2020
|
||||
*/
|
||||
public class UserDTO {
|
||||
|
||||
private String userId;
|
||||
private String userName;
|
||||
private String email;
|
||||
private List<String> usernames;
|
||||
|
||||
// getters and setters
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public List<String> getUsernames() {
|
||||
return usernames;
|
||||
}
|
||||
|
||||
public void setUsernames(List<String> usernames) {
|
||||
this.usernames = usernames;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.model;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author sasam0320
|
||||
* @date 4/18/2020
|
||||
*/
|
||||
|
||||
public class UserList {
|
||||
|
||||
private Collection<User> users;
|
||||
|
||||
public Collection<User> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUsers(Collection<User> users) {
|
||||
this.users = users;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.baeldung.util;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.modelmapper.convention.MatchingStrategies;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author sasam0320
|
||||
* @date 4/18/2020
|
||||
*/
|
||||
public class MapperUtil {
|
||||
|
||||
|
||||
private static ModelMapper modelMapper = new ModelMapper();
|
||||
|
||||
|
||||
static {
|
||||
|
||||
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
|
||||
|
||||
}
|
||||
|
||||
private MapperUtil() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static <S, T> T mapTo(final S source, final Class<T> target) {
|
||||
|
||||
return modelMapper.map(source, target);
|
||||
}
|
||||
|
||||
public static <S, T> List<T> mapList(final List<S> sourceList, final Class<T> target) {
|
||||
|
||||
List<T> targetList = new ArrayList<T>();
|
||||
|
||||
for (S source : sourceList) {
|
||||
|
||||
targetList.add(modelMapper.map(source, target));
|
||||
}
|
||||
|
||||
return targetList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.baeldung.util;
|
||||
|
||||
import com.baeldung.model.User;
|
||||
import com.baeldung.model.UserDTO;
|
||||
import com.baeldung.model.UserList;
|
||||
import org.modelmapper.AbstractConverter;
|
||||
import org.modelmapper.Converter;
|
||||
import org.modelmapper.PropertyMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author sasam0320
|
||||
* @date 4/18/2020
|
||||
*/
|
||||
|
||||
public class UserPropertyMap extends PropertyMap<UserList, UserDTO> {
|
||||
|
||||
|
||||
Converter<List<User>, List<String>> converter = new AbstractConverter<List<User>, List<String>>() {
|
||||
|
||||
List<String> usernames = new ArrayList<>();
|
||||
|
||||
protected List<String> convert(List<User> users) {
|
||||
|
||||
users.forEach(user -> usernames.add(user.getUserName()));
|
||||
return usernames;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
using(converter).map(source.getUsers(), destination.getUsernames());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user