-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utils class for Oracle, Order, IO, JSON, String and DateUtil
- Loading branch information
dolfinus
committed
Dec 27, 2018
1 parent
9a78333
commit 08e46b2
Showing
8 changed files
with
190 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.camunda.latera.bss.utils | ||
import java.util.Base64 | ||
|
||
class Base64Converter { | ||
static String to(byte[] bytes) { | ||
return Base64.getEncoder().encodeToString(bytes) | ||
} | ||
|
||
static byte[] from(String str) { | ||
return Base64.getDecoder().decode(str) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.camunda.latera.bss.utils | ||
|
||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
import groovy.time.TimeCategory | ||
|
||
class DateTimeUtil { | ||
static DateTimeFormatter ISOFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME | ||
static DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern('dd.MM.yyyy') | ||
static DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern('yyyy-MM-dd HH:mm:ss') | ||
static DateTimeFormatter simpleDateTimeFormat = DateTimeFormatter.ofPattern('dd.MM.yyyy HH:mm:ss') | ||
|
||
static def now() { | ||
return LocalDateTime.now() | ||
} | ||
|
||
static def parse( | ||
String dt, | ||
def format = this.simpleDateTimeFormat | ||
) { | ||
return LocalDateTime.parse(dt, format) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.camunda.latera.bss.utils | ||
|
||
import java.io.ByteArrayOutputStream | ||
import java.io.InputStreamReader | ||
|
||
class IO { | ||
static def getBytes( | ||
InputStreamReader input | ||
) { | ||
|
||
ByteArrayOutputStream buffer = new ByteArrayOutputStream() | ||
int nRead; | ||
byte[] data = new byte[1024] | ||
while ((nRead = input.read(data, 0, data.length)) != -1) { | ||
buffer.write(data, 0, nRead) | ||
} | ||
|
||
buffer.flush() | ||
byte[] byteArray = buffer.toByteArray() | ||
return byteArray | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.camunda.latera.bss.utils | ||
import groovy.json.JsonSlurper | ||
import groovy.json.JsonOutput | ||
|
||
class JSON { | ||
static String to(Object obj) { | ||
return JsonOutput.toJson(obj) | ||
} | ||
|
||
static Object from(String json) { | ||
return new JsonSlurper().parseText(json) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.camunda.latera.bss.utils | ||
|
||
class Oracle { | ||
static Object encodeNull(value) { | ||
if (value != 'NULL' && value != null) { | ||
return value | ||
} else { | ||
return 'NULL' | ||
} | ||
} | ||
|
||
static Object decodeNull(value) { | ||
if (encodeNull(value) == 'NULL') { | ||
return null | ||
} | ||
return value | ||
} | ||
|
||
static Object encodeBool(value) { | ||
Object result = encodeNull(value) | ||
if (result != 'NULL') { | ||
return value ? 'Y' : 'N' | ||
} else { | ||
return result | ||
} | ||
} | ||
|
||
static Boolean decodeBool(value) { | ||
return value == 'Y' | ||
} | ||
|
||
static Object nvl(nullable, replacement, args = []) { | ||
Boolean result = decodeNull(nullable) | ||
if (result != null) { | ||
return result | ||
} else { | ||
if (replacement.metaClass.respondsTo(replacement, 'call')) { | ||
return replacement.call(*args) | ||
} else { | ||
return replacement | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.camunda.latera.bss.utils | ||
import org.camunda.bpm.engine.delegate.DelegateExecution | ||
|
||
class Order { | ||
static LinkedHashMap getData(DelegateExecution execution) { | ||
LinkedHashMap data = [:] | ||
for (e in execution.getVariables()) { | ||
if (e.key =~ /^homsOrderData/) { | ||
String dataKey = e.key.replaceFirst(/^homsOrderData/, "") | ||
dataKey = (dataKey.getAt(0).toLowerCase() + dataKey.substring(1)).toString() | ||
data[dataKey] = e.value | ||
} | ||
} | ||
return data | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.camunda.latera.bss.utils | ||
import java.nio.charset.Charset | ||
|
||
class StringUtil { | ||
static byte[] unicodeToVarchar(String input) { | ||
if (input) { | ||
return input.getBytes(Charset.forName("ISO-8859-1")) | ||
} | ||
return null | ||
} | ||
|
||
static String varcharToUnicode(String input) { | ||
if (input) { | ||
return new String(input.getBytes(Charset.forName("ISO-8859-1")), "UTF-8") | ||
} | ||
return null | ||
} | ||
|
||
static byte[] unicodeToCP1251(String input) { | ||
if (input) { | ||
return input.getBytes(Charset.forName("CP1251")) | ||
} | ||
return null | ||
} | ||
|
||
static String cp1251ToUnicode(String input) { | ||
if (input) { | ||
return new String(input.getBytes(Charset.forName("CP1251")), "UTF-8") | ||
} | ||
return null | ||
} | ||
|
||
static Boolean notEmpty(String input) { | ||
if (input) { | ||
return (input?.trim() as boolean) | ||
} | ||
return false | ||
} | ||
|
||
static Boolean isEmpty(String input) { | ||
return !notEmpty(input) | ||
} | ||
|
||
static Boolean isString(def input) { | ||
return (input instanceof CharSequence) | ||
} | ||
|
||
static Boolean isByteArray(def input) { | ||
return (input instanceof byte[]) | ||
} | ||
} | ||
|