PAN-48 Created the AccountController and created the copyNonNullProperties method

This commit is contained in:
2019-02-24 19:14:17 -07:00
parent 8c9f2bbd9c
commit b77a750c30
4 changed files with 189 additions and 6 deletions
@@ -18,6 +18,7 @@ repositories {
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile fileTree(dir: 'lib', include: '**/*.jar')
testCompile group: 'junit', name: 'junit', version: '4.12'
}
@@ -0,0 +1,27 @@
package edu.msudenver.tsp.utilities;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import java.beans.FeatureDescriptor;
import java.util.stream.Stream;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public abstract class PersistenceUtilities {
private static String[] getNullPropertyNames(final Object source) {
final BeanWrapper wrappedSource = new BeanWrapperImpl(source);
return Stream.of(wrappedSource.getPropertyDescriptors())
.map(FeatureDescriptor::getName)
.filter(propertyName -> wrappedSource.getPropertyValue(propertyName) == null
|| propertyName.equals("id"))
.toArray(String[]::new);
}
public static void copyNonNullProperties(final Object source, final Object target) {
BeanUtils.copyProperties(source, target, getNullPropertyNames(source));
}
}