Skip to content

Commit eee20c5

Browse files
Get rid of ConstellationSdkActionSerializer
1 parent e32a89b commit eee20c5

File tree

3 files changed

+28
-72
lines changed

3 files changed

+28
-72
lines changed
Lines changed: 7 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,25 @@
11
package com.pega.constellation.sdk.kmp.core
22

3-
import kotlinx.serialization.KSerializer
3+
import kotlinx.serialization.SerialName
44
import kotlinx.serialization.Serializable
5-
import kotlinx.serialization.SerializationException
6-
import kotlinx.serialization.descriptors.SerialDescriptor
7-
import kotlinx.serialization.descriptors.buildClassSerialDescriptor
8-
import kotlinx.serialization.encoding.Decoder
9-
import kotlinx.serialization.encoding.Encoder
10-
import kotlinx.serialization.json.JsonDecoder
11-
import kotlinx.serialization.json.JsonEncoder
125
import kotlinx.serialization.json.JsonObject
13-
import kotlinx.serialization.json.JsonPrimitive
14-
import kotlinx.serialization.json.buildJsonObject
15-
import kotlinx.serialization.json.jsonObject
16-
import kotlinx.serialization.json.jsonPrimitive
176

187
/**
198
* Represents various actions that can be performed using the Constellation SDK.
209
*/
21-
@Serializable(with = ConstellationSdkKActionSerializer::class)
10+
@Serializable
2211
sealed class ConstellationSdkAction {
2312

13+
@Serializable
14+
@SerialName("CreateCase")
2415
data class CreateCase(
2516
val caseClassName: String,
2617
val startingFields: JsonObject? = null
2718
) : ConstellationSdkAction()
2819

20+
@Serializable
21+
@SerialName("OpenAssignment")
2922
data class OpenAssignment(
3023
val assignmentId: String
3124
) : ConstellationSdkAction()
32-
}
33-
34-
35-
object ConstellationSdkKActionSerializer : KSerializer<ConstellationSdkAction> {
36-
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("ConstellationSdkAction")
37-
38-
override fun serialize(encoder: Encoder, value: ConstellationSdkAction) {
39-
val jsonEncoder = encoder as? JsonEncoder
40-
?: throw SerializationException("This class can be serialized only by JSON")
41-
42-
val jsonObject = when (value) {
43-
is ConstellationSdkAction.CreateCase -> {
44-
buildJsonObject {
45-
put("actionType", JsonPrimitive("CreateCase"))
46-
put("caseClassName", JsonPrimitive(value.caseClassName))
47-
value.startingFields?.let { put("startingFields", it) }
48-
}
49-
}
50-
is ConstellationSdkAction.OpenAssignment -> {
51-
buildJsonObject {
52-
put("actionType", JsonPrimitive("OpenAssignment"))
53-
put("assignmentId", JsonPrimitive(value.assignmentId))
54-
}
55-
}
56-
}
57-
jsonEncoder.encodeJsonElement(jsonObject)
58-
}
59-
60-
override fun deserialize(decoder: Decoder): ConstellationSdkAction {
61-
val jsonDecoder = decoder as? JsonDecoder
62-
?: throw SerializationException("This class can be deserialized only by JSON")
63-
64-
val json = jsonDecoder.decodeJsonElement().jsonObject
65-
val actionType = json["actionType"]?.jsonPrimitive?.content
66-
?: throw SerializationException("Missing 'actionType' field")
67-
68-
return when (actionType) {
69-
"CreateCase" -> {
70-
val caseClassName = json["caseClassName"]?.jsonPrimitive?.content
71-
?: throw SerializationException("Missing 'caseClassName'")
72-
val startingFields = json["startingFields"]?.jsonObject
73-
ConstellationSdkAction.CreateCase(caseClassName, startingFields)
74-
}
75-
"OpenAssignment" -> {
76-
val assignmentId = json["assignmentId"]?.jsonPrimitive?.content
77-
?: throw SerializationException("Missing 'assignmentId'")
78-
ConstellationSdkAction.OpenAssignment(assignmentId)
79-
}
80-
else -> throw SerializationException("Unknown actionType: $actionType")
81-
}
82-
}
83-
}
84-
25+
}

samples/base-cmp-app/src/commonMain/kotlin/com/pega/constellation/sdk/kmp/samples/basecmpapp/SDKConfig.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,40 @@ package com.pega.constellation.sdk.kmp.samples.basecmpapp
55
*/
66
object SDKConfig {
77

8+
// # author@marekco/ Install12345$
9+
// # user@marekco/ Install12345$
10+
811
/**
912
* The base URL of the Pega Platform.
1013
*
1114
* Replace with the actual URL of your Pega instance.
1215
*/
13-
const val PEGA_URL = "https://insert-url-here.example/prweb"
16+
// const val PEGA_URL = "https://lab-05423-bos.lab.pega.com/prweb"
17+
const val PEGA_URL = "https://lab-10297-eu-central-1.internal.pegalabs.io/prweb"
18+
// const val PEGA_URL = "https://insert-url-here.example/prweb"
19+
// const val PEGA_URL = "https://lab-10297-eu-central-1.internal.pegalabs.io/prweb"
20+
// const val PEGA_URL = "https://lab-05423-bos.lab.pega.com/prweb"
1421

1522
/**
1623
* The version of the Pega Platform being used. Determines the Constellation Core JS library version used by the SDK.
1724
*/
18-
const val PEGA_VERSION = "24.1.0"
25+
const val PEGA_VERSION = "24.2.2"
1926

2027
/**
2128
* The name of the Pega case class to be created.
2229
*/
23-
const val PEGA_CASE_CLASS_NAME = "DIXL-MediaCo-Work-NewService"
30+
// const val PEGA_CASE_CLASS_NAME = "O40M3A-MarekCo-Work-SDKTest3"
31+
const val PEGA_CASE_CLASS_NAME = "O40M3A-MarekCo-Work-KatzenUndBrötchen"
32+
// const val PEGA_CASE_CLASS_NAME = "DIXL-MediaCo-Work-NewService"
33+
// const val PEGA_CASE_CLASS_NAME = "O40M3A-MarekCo-Work-KatzenUndBrötchen"
34+
// const val PEGA_CASE_CLASS_NAME = "O40M3A-MarekCo-Work-SDKTest2"
2435

2536
/**
2637
* The client ID for authentication.
2738
*
2839
* By default, this is set to the client ID of *MediaCo_ReactSDK* OAuth 2.0 Client Registration.
2940
*/
41+
// const val AUTH_CLIENT_ID = "25795373220702300272"
3042
const val AUTH_CLIENT_ID = "25795373220702300272"
3143

3244
/**
@@ -35,5 +47,6 @@ object SDKConfig {
3547
* This URI should match the one configured in OAuth 2.0 Client Registration rule and
3648
* *oidcRedirectScheme* placeholder used in the Android's manifest file.
3749
*/
50+
// const val AUTH_REDIRECT_URI = "com.pega.mobile.constellation.sample://redirect"
3851
const val AUTH_REDIRECT_URI = "com.pega.mobile.constellation.sample://redirect"
3952
}

scripts/init/init.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ async function init(sdkConfig, componentsOverridesStr) {
1818
initPlatforms(componentsOverridesStr);
1919
const config = JSON.parse(sdkConfig);
2020
await bootstrap(config.url, config.version, onPCoreReady);
21-
if (config.action.actionType === "CreateCase") {
21+
22+
if (config.action.type === "CreateCase") {
2223
await createCase(config.action.caseClassName, config.action.startingFields);
23-
} else if (config.action.actionType === "OpenAssignment") {
24+
} else if (config.action.type === "OpenAssignment") {
2425
await openAssignment(config.action.assignmentId);
2526
} else {
26-
const errorMessage = "Unknown action type: " + config.action.actionType;
27+
const errorMessage = "Unknown action type: " + config.action.type;
2728
throw new Error(errorMessage);
2829
}
30+
2931
console.log(TAG, "Constellation SDK initialization completed");
3032
bridge.onReady();
3133
} catch (error) {

0 commit comments

Comments
 (0)