Skip to content

Commit 742b887

Browse files
Project updated.
1 parent ce6a942 commit 742b887

File tree

4 files changed

+356
-150
lines changed

4 files changed

+356
-150
lines changed

src/main/scala/de/kp/works/witsml/WitsmlObjects.scala

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ package de.kp.works.witsml
2020

2121
import com.fasterxml.jackson.databind.ObjectMapper
2222
import com.fasterxml.jackson.module.scala.DefaultScalaModule
23+
import com.hashmapinc.tempus.WitsmlObjects.Util.WitsmlVersionTransformer
2324
import com.hashmapinc.tempus.witsml.api.WitsmlVersion
24-
import com.hashmapinc.tempus.witsml.client.Client
25+
import com.hashmapinc.tempus.witsml.client.{Client, WitsmlQuery}
26+
import org.apache.spark.sql.DataFrame
2527
import org.slf4j.{Logger, LoggerFactory}
2628

2729
abstract class WitsmlObjects(
@@ -47,5 +49,57 @@ abstract class WitsmlObjects(
4749
client.setVersion(version)
4850

4951
client.connect()
52+
/**
53+
* This transformer is usually part of the Witsml Client.
54+
* It is externalized here to enable message processing
55+
* that is compliant with Jackson v2.6.x
56+
*/
57+
protected val transform:WitsmlVersionTransformer =
58+
try {
59+
new WitsmlVersionTransformer()
60+
} catch {
61+
case t: Throwable => null
62+
}
63+
64+
/**
65+
* This method is a copy of the respective method
66+
* with the Witsml Client; it is required for v1311
67+
* response only
68+
*/
69+
protected def convertVersion(original: String):String = {
70+
71+
try {
72+
val converted = transform.convertVersion(original)
73+
if (converted.isEmpty) null else converted
74+
75+
} catch {
76+
case t:Throwable => null
77+
}
78+
79+
}
80+
81+
protected def extract1311[T](witsmlQuery:WitsmlQuery, witsmlClass:Class[T]):T = {
82+
83+
val data = client.getObjectData(witsmlQuery)
84+
val xml = data.getXmlOut
85+
86+
val xml1411 = convertVersion(xml)
87+
witsmlMarshaller.deserialize(xml1411, classOf[T])
88+
89+
}
90+
91+
protected def extract1411[T](witsmlQuery:WitsmlQuery, witsmlClass:Class[T]):T = {
92+
93+
val data = client.getObjectData(witsmlQuery)
94+
val xml = data.getXmlOut
95+
96+
witsmlMarshaller.deserialize(xml, classOf[T])
97+
98+
}
99+
100+
protected def nested(deserialized:AnyRef):DataFrame = {
101+
val json = mapper.writeValueAsString(deserialized)
102+
WitsmlTransformer.transform(json)
103+
}
50104

51105
}

0 commit comments

Comments
 (0)