tock / ai.tock.shared

Package ai.tock.shared

Shared utility classes and extensions

Types

Dice

Manage random things.

object Dice

Executor

Manage async tasks.

interface Executor

FontLoader

Load and register fonts.

object FontLoader

ImageFormat

Supported generation format.

enum class ImageFormat

ImageGenerator

Generates an image from a svg template.

class ImageGenerator<T : Any>

ImageParametersExtractor

Provides a data instance from specified parameters.

interface ImageParametersExtractor<T : Any>

Level

Http requests/response log level.

enum class Level

Loader

Helper methods to deal with ServiceLoader.

object Loader

SvgGenerator

Generates an image from a svg file.

abstract class SvgGenerator<T : Any>

SvgToPngConverter

Convert a svg image to png image.

class SvgToPngConverter

Annotations

ThreadSafe

A class annotated with ThreadSafe is supposed to be thread safe (surprisingly).

annotation class ThreadSafe

Extensions for External Classes

com.github.salomonbrys.kodein.KodeinInjector

com.mongodb.client.FindIterable

com.mongodb.client.MongoCollection

com.mongodb.reactivestreams.client.MongoCollection

java.util.Enumeration

kotlin.collections.Iterable

kotlin.collections.Iterator

kotlin.String

mu.KLogger

retrofit2.Retrofit

retrofit2.Retrofit.Builder

Properties

DEFAULT_APP_NAMESPACE

The default app namespace.

const val DEFAULT_APP_NAMESPACE: String

defaultLocale

The default Tock Locale. Use property "tock_default_locale" and default value "en".

val defaultLocale: Locale

defaultNamespace

The Tock app namespace.

val defaultNamespace: String

defaultZoneId

The default ZoneId used by Tock.

val defaultZoneId: ZoneId

devEnvironment

Return true is the current environment is a dev environment. Use "tock_env" property to know the environment - if not set or if the value is "dev", this is a dev environment.

val devEnvironment: Boolean

injector

Main Tock injector.

val injector: KodeinInjector

internalDefaultZoneId

The internal defaultZoneId for Tock - var only for tests. property "tock_default_zone" with default value UTC is used.

var internalDefaultZoneId: ZoneId

sharedModule

IOC of shared module.

val sharedModule: Module

supportedLanguages

The languages supported by Tock.

val supportedLanguages: Map<String, Locale>

TOCK_BOT_DATABASE

Tock bot database name property

const val TOCK_BOT_DATABASE: String

TOCK_CACHE_DATABASE

Tock cache database name property

const val TOCK_CACHE_DATABASE: String

TOCK_FRONT_DATABASE

Tock front database name property

const val TOCK_FRONT_DATABASE: String

TOCK_MODEL_DATABASE

Tock model database name property

const val TOCK_MODEL_DATABASE: String

TOCK_NAMESPACE

The Tock namespace.

const val TOCK_NAMESPACE: String

tockAppDefaultNamespace

The internal app namespace - var only for tests. Use property "tock_default_namespace" and as default value DEFAULT_APP_NAMESPACE.

var tockAppDefaultNamespace: String

tockInternalInjector

Internal injector - reset only for tests.

var tockInternalInjector: KodeinInjector

Functions

basicAuthInterceptor

Create a basic auth interceptor.

fun basicAuthInterceptor(login: String, password: String): Interceptor

basicCredentialsHeader

Encode basic credential header.

fun basicCredentialsHeader(login: String, password: String): String

booleanProperty

Return an env or system Boolean property.

fun booleanProperty(name: String, defaultValue: Boolean): Boolean

checkMaxLengthAllowed

Checks that the text has no more than 50000 chars. Else cuts the String.

fun checkMaxLengthAllowed(text: String): String

concat

Concat two strings and manage intermediate punctuation.

fun concat(s1: String?, s2: String?): String

getAsyncDatabase

Return the async database specified in the databaseNameProperty. if the env or system property is not found, use the databaseNameProperty as database name (remove "_mongo_db" string is present).

fun getAsyncDatabase(databaseNameProperty: String): MongoDatabase

getDatabase

Return the sync database specified in the databaseNameProperty. if the env or system property is not found, use the databaseNameProperty as database name (remove "_mongo_db" string is present).

fun getDatabase(databaseNameProperty: String): MongoDatabase

intProperty

Return an env or system Int property.

fun intProperty(name: String, defaultValue: Int): Int

isDocumentDB

fun isDocumentDB(): Boolean

listProperty

Return an env or system List property.

fun listProperty(name: String, defaultValue: List<String>, separator: String = ","): List<String>

loadProperties

Load a Properties for classpath.

fun loadProperties(fileInClasspath: String): Properties

longProperty

Return an env or system Long property.

fun longProperty(name: String, defaultValue: Long): Long

mapListProperty

Return an env or system Map of List property.

fun mapListProperty(name: String, defaultValue: Map<String, List<String>>, entrySeparator: String = "|", keyValueSeparator: String = "=", listSeparator: String = ","): Map<String, List<String>>

mapNotNullValues

Return a map with only not null values.

fun <K, V> mapNotNullValues(vararg pairs: Pair<K, V?>): Map<K, V>

mapProperty

Return an env or system Map property.

fun mapProperty(name: String, defaultValue: Map<String, String>, entrySeparator: String = "|", keyValueSeparator: String = "="): Map<String, String>

pingMongoDatabase

fun pingMongoDatabase(databaseName: String): Boolean

property

Return an env or system String property.

fun property(name: String, defaultValue: String): String

propertyExists

Is this env or system property exists?

fun propertyExists(name: String): Boolean

propertyOrNull

Return an env or system String property or null if not found

fun propertyOrNull(name: String): String?

resource

Get a resource url from the classpath.

fun resource(path: String): URL

resourceAsStream

Get a resource InputStream from the classpath.

fun resourceAsStream(path: String): InputStream

resourceAsString

Get a text content of a resource from the classpath.

fun resourceAsString(path: String): String

retrofitBuilderWithTimeoutAndLogger

Init a Retrofit.Builder with specified timeout, logger and interceptors.

fun retrofitBuilderWithTimeoutAndLogger(ms: Long, logger: KLogger = KotlinLogging.logger {}, level: Level = Level.BODY, interceptors: List<Interceptor> = emptyList(), requestGZipEncoding: Boolean = false, circuitBreaker: Boolean = false, proxy: Proxy? = null): Builder

tokenAuthenticationInterceptor

Create a token authentication interceptor.

fun tokenAuthenticationInterceptor(token: String): Interceptor

tryToFindLocalIp

Best attempt to guess local ip.

fun tryToFindLocalIp(): String