aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/utils
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-12-23 09:44:11 +0200
committerIttay Stern <ittay.stern@att.com>2019-12-23 13:12:14 +0200
commitb909d1e85f13431436808e6880a1e857addb449c (patch)
tree5af7160bc5c14fa89fa3881821965cc3866f3016 /vid-app-common/src/main/java/org/onap/vid/utils
parent879ed7a6358e920595010f8c915e0df8fd2dba0e (diff)
Add request-summary field to ServiceInfo
Issue-ID: VID-724 Change-Id: Ifdf39a0c21e7a96065f88aa2aa4a5560e0559564 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/utils')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/utils/DaoUtils.java51
1 files changed, 47 insertions, 4 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/DaoUtils.java b/vid-app-common/src/main/java/org/onap/vid/utils/DaoUtils.java
index 7d3b926ea..7fb03aea8 100644
--- a/vid-app-common/src/main/java/org/onap/vid/utils/DaoUtils.java
+++ b/vid-app-common/src/main/java/org/onap/vid/utils/DaoUtils.java
@@ -20,14 +20,21 @@
package org.onap.vid.utils;
+import static java.util.Objects.isNull;
+import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+import javax.persistence.AttributeConverter;
+import org.apache.commons.lang3.exception.ExceptionUtils;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
-import org.onap.vid.exceptions.GenericUncheckedException;
import org.onap.portalsdk.core.domain.FusionObject;
-
-import java.util.HashMap;
-import java.util.function.Function;
+import org.onap.vid.exceptions.GenericUncheckedException;
public class DaoUtils {
@@ -70,4 +77,40 @@ public class DaoUtils {
props.put(FusionObject.Parameters.PARAM_USERID, 0);
return props;
}
+
+ public static class StringToLongMapAttributeConverter extends JsonAttributeConverter<Map<String, Long>> {
+
+ private final TypeReference<Map<String, Long>> typeReference =
+ new TypeReference<Map<String, Long>>() {};
+
+ @Override
+ public TypeReference<Map<String, Long>> getTypeReference() {
+ return typeReference;
+ }
+ }
+
+ private static abstract class JsonAttributeConverter<T> implements AttributeConverter<T, String> {
+
+ abstract public TypeReference<T> getTypeReference();
+
+ @Override
+ public String convertToDatabaseColumn(T attribute) {
+ try {
+ return isNull(attribute) ? null
+ : JACKSON_OBJECT_MAPPER.writeValueAsString(attribute);
+ } catch (JsonProcessingException e) {
+ return ExceptionUtils.rethrow(e);
+ }
+ }
+
+ @Override
+ public T convertToEntityAttribute(String dbData) {
+ try {
+ return isNull(dbData) ? null
+ : JACKSON_OBJECT_MAPPER.readValue(dbData, getTypeReference());
+ } catch (JsonProcessingException e) {
+ return ExceptionUtils.rethrow(e);
+ }
+ }
+ }
}