This is an automated email from the ASF dual-hosted git repository.

yasith pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata.git


The following commit(s) were added to refs/heads/master by this push:
     new 26e84af386 fix bug in dozer mapper
26e84af386 is described below

commit 26e84af386390f9f6e3a4a323464042339026e50
Author: yasithdev <[email protected]>
AuthorDate: Mon Jul 14 06:59:09 2025 -0500

    fix bug in dozer mapper
---
 .../utils/DozerConverter/CsvStringConverter.java   | 11 +--
 .../registry/core/utils/ObjectMapperSingleton.java | 84 +++++-----------------
 2 files changed, 24 insertions(+), 71 deletions(-)

diff --git 
a/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/DozerConverter/CsvStringConverter.java
 
b/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/DozerConverter/CsvStringConverter.java
index 10d7271b44..5a4a5a0fdd 100644
--- 
a/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/DozerConverter/CsvStringConverter.java
+++ 
b/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/DozerConverter/CsvStringConverter.java
@@ -26,15 +26,16 @@ import java.util.List;
 /**
  * CsvStringConverter
  */
-public class CsvStringConverter extends DozerConverter<String, List> {
+public class CsvStringConverter extends DozerConverter<String, List<String>> {
 
+    @SuppressWarnings("unchecked")
     public CsvStringConverter() {
-        super(String.class, List.class);
+        super(String.class, (Class<List<String>>) (Class<?>) List.class);
     }
 
     @Override
-    public List convertTo(String source, List destination) {
-        if (source == null || source.length() == 0) {
+    public List<String> convertTo(String source, List<String> destination) {
+        if (source == null || source.isEmpty()) {
             return null;
         } else {
             return Arrays.asList(source.split(","));
@@ -42,7 +43,7 @@ public class CsvStringConverter extends 
DozerConverter<String, List> {
     }
 
     @Override
-    public String convertFrom(List source, String destination) {
+    public String convertFrom(List<String> source, String destination) {
         if (source == null || source.isEmpty()) {
             return null;
         } else {
diff --git 
a/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/ObjectMapperSingleton.java
 
b/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/ObjectMapperSingleton.java
index 4099d40ecd..d53995c50b 100644
--- 
a/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/ObjectMapperSingleton.java
+++ 
b/airavata-api/src/main/java/org/apache/airavata/registry/core/utils/ObjectMapperSingleton.java
@@ -1,37 +1,28 @@
 /**
-*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, 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.
-*/
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, 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.
+ */
 package org.apache.airavata.registry.core.utils;
 
-import com.github.dozermapper.core.CustomFieldMapper;
 import com.github.dozermapper.core.DozerBeanMapperBuilder;
 import com.github.dozermapper.core.Mapper;
-import com.github.dozermapper.core.classmap.ClassMap;
-import com.github.dozermapper.core.fieldmap.FieldMap;
-import org.apache.commons.lang3.ClassUtils;
-import org.apache.thrift.TBase;
-import org.apache.thrift.TFieldIdEnum;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class ObjectMapperSingleton {
-    private static final Logger logger = 
LoggerFactory.getLogger(ObjectMapperSingleton.class);
 
     private static Mapper mapper;
 
@@ -41,47 +32,8 @@ public class ObjectMapperSingleton {
         if (mapper == null) {
             mapper = DozerBeanMapperBuilder.create()
                     .withMappingFiles("dozer_mapping.xml")
-                    .withCustomFieldMapper(new SkipUnsetPrimitiveFieldMapper())
                     .build();
         }
         return mapper;
     }
-
-    private static class SkipUnsetPrimitiveFieldMapper implements 
CustomFieldMapper {
-        @Override
-        public boolean mapField(
-                Object source, Object destination, Object sourceFieldValue, 
ClassMap classMap, FieldMap fieldMap) {
-            // Just skipping mapping field if not set on Thrift source model 
and the field's value is primitive
-            if (isSourceUnsetThriftField(source, fieldMap)
-                    && sourceFieldValue != null
-                    && 
ClassUtils.isPrimitiveOrWrapper(sourceFieldValue.getClass())) {
-                logger.debug("Skipping field " + fieldMap.getSrcFieldName()
-                        + " since it is unset thrift field and is primitive");
-                return true;
-            }
-            return false;
-        }
-
-        private boolean isSourceUnsetThriftField(Object source, FieldMap 
fieldMap) {
-            if (source instanceof TBase) {
-                TBase thriftSource = (TBase) source;
-                try {
-                    Class<?> thriftFieldsEnum =
-                            Class.forName(thriftSource.getClass().getName() + 
"$$_Fields");
-                    TFieldIdEnum srcField = (TFieldIdEnum) thriftFieldsEnum
-                            .getMethod("findByName", String.class)
-                            .invoke(null, fieldMap.getSrcFieldName());
-                    // FIXME: Dozer can handle case insensitive field 
matching, for example, "gatewayID" maps to
-                    // "gatewayId" but this method of looking up field by name 
is case sensitive. For example,
-                    // it fails to find "gatewayID" on GatewayResourceProfile.
-                    if (srcField != null && !thriftSource.isSet(srcField)) {
-                        return true;
-                    }
-                } catch (Exception e) {
-                    throw new RuntimeException("Thrift model class has no 
_Fields enum", e);
-                }
-            }
-            return false;
-        }
-    }
 }

Reply via email to