From b836d3492984e8c751f00b200d24eb07da792c75 Mon Sep 17 00:00:00 2001 From: Tomasz Golabek Date: Tue, 11 Jun 2019 13:41:48 +0200 Subject: BeanUtils upgrade to 1.9.x Transitive dependency to beanutils 1.8.3 removed. Refactor of existing usage of beanutils proposed. Change-Id: I6614a5794979225376338c778b25f71911ae9c50 Issue-ID: SDC-2269 Signed-off-by: Tomasz Golabek --- .../org/openecomp/sdc/common/utils/CommonUtil.java | 37 +++------------------- 1 file changed, 5 insertions(+), 32 deletions(-) (limited to 'openecomp-be/lib') diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java index 7d37a55388..fcb668f393 100644 --- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java @@ -12,14 +12,15 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.common.utils; -import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Multimap; -import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -176,27 +177,7 @@ public class CommonUtil { public static Optional createObjectUsingSetters(Object objectCandidate, Class classToCreate) throws Exception { - if (Objects.isNull(objectCandidate)) { - return Optional.empty(); - } - - Map objectAsMap = getObjectAsMap(objectCandidate); - T result = classToCreate.newInstance(); - - Field[] declaredFields = classToCreate.getDeclaredFields(); - for( Field field : declaredFields){ - if(isComplexClass(field)){ - Optional objectUsingSetters = - createObjectUsingSetters(objectAsMap.get(field.getName()), field.getType()); - if( objectUsingSetters.isPresent()){ - objectAsMap.remove(field.getName()); - objectAsMap.put(field.getName(), objectUsingSetters.get()); - } - } - } - BeanUtils.populate(result, objectAsMap); - - return Optional.of(result); + return org.onap.sdc.tosca.services.CommonUtil.createObjectUsingSetters(objectCandidate, classToCreate); } private static boolean isComplexClass(Field field) { @@ -211,15 +192,7 @@ public class CommonUtil { } public static Map getObjectAsMap(Object obj) { - Map objectAsMap = obj instanceof Map ? (Map) obj - : new ObjectMapper().convertValue(obj, Map.class); - - if (objectAsMap.containsKey(DEFAULT)) { - Object defaultValue = objectAsMap.get(DEFAULT); - objectAsMap.remove(DEFAULT); - objectAsMap.put(_DEFAULT, defaultValue); - } - return objectAsMap; + return org.onap.sdc.tosca.services.CommonUtil.getObjectAsMap(obj); } public static boolean isMultimapEmpty(Multimap obj) { -- cgit 1.2.3-korg