Skip to content

Commit bfb7087

Browse files
Made changes for Incoming Call Event in event parser. (Azure#43943)
* Made changes for Incoming Call Event in event parser. * added live test for incoming call event * recorded the live tests. * Updated assest.json * Removed incoming call live test and reverted resources back to main. * Reverted assets.json to commit 7454d11. * Reverted assets.json back to main. * Added proper IncomingCall event parsing. * Added Javadoc comments to Incoming Call fields. * Added JsonSerializability to CustomCallingContext model. Removed correlationId and serverCallId fields in IncomingCall.java (handled in super class). * Removed public visibility of ChoiceResult.java --------- Co-authored-by: v-saasomani <[email protected]>
1 parent 5d93bf3 commit bfb7087

File tree

6 files changed

+211
-6
lines changed

6 files changed

+211
-6
lines changed

sdk/communication/azure-communication-callautomation/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"AssetsRepoPrefixPath": "java",
44
"TagPrefix": "java/communication/azure-communication-callautomation",
55
"Tag": "java/communication/azure-communication-callautomation_9339e7fc0c"
6-
}
6+
}

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/CallAutomationEventParser.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@
3636
import com.azure.communication.callautomation.models.events.HoldAudioResumed;
3737
import com.azure.communication.callautomation.models.events.HoldAudioStarted;
3838
import com.azure.communication.callautomation.models.events.HoldFailed;
39+
import com.azure.communication.callautomation.models.events.IncomingCall;
3940
import com.azure.communication.callautomation.models.events.MediaStreamingFailed;
4041
import com.azure.communication.callautomation.models.events.MediaStreamingStarted;
4142
import com.azure.communication.callautomation.models.events.MediaStreamingStopped;
4243
import com.azure.communication.callautomation.models.events.ParticipantsUpdated;
4344
import com.azure.communication.callautomation.models.events.PlayCanceled;
4445
import com.azure.communication.callautomation.models.events.PlayCompleted;
46+
import com.azure.communication.callautomation.models.events.PlayFailed;
4547
import com.azure.communication.callautomation.models.events.PlayPaused;
4648
import com.azure.communication.callautomation.models.events.PlayResumed;
47-
import com.azure.communication.callautomation.models.events.PlayFailed;
4849
import com.azure.communication.callautomation.models.events.PlayStarted;
4950
import com.azure.communication.callautomation.models.events.RecognizeCanceled;
5051
import com.azure.communication.callautomation.models.events.RecognizeCompleted;
@@ -122,6 +123,8 @@ private static CallAutomationEventBase parseSingleCloudEvent(String data, String
122123
ret = CallConnected.fromJson(jsonReader);
123124
} else if (Objects.equals(eventType, "Microsoft.Communication.CallDisconnected")) {
124125
ret = CallDisconnected.fromJson(jsonReader);
126+
} else if (Objects.equals(eventType, "Microsoft.Communication.IncomingCall")) {
127+
ret = IncomingCall.fromJson(jsonReader);
125128
} else if (Objects.equals(eventType, "Microsoft.Communication.AddParticipantFailed")) {
126129
ret = AddParticipantFailed.fromJson(jsonReader);
127130
} else if (Objects.equals(eventType, "Microsoft.Communication.AddParticipantSucceeded")) {

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/models/ChoiceResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public final class ChoiceResult extends RecognizeResult {
2828
/**
2929
* Creates an instance of {@link ChoiceResult}.
3030
*/
31-
public ChoiceResult() {
31+
ChoiceResult() {
3232
}
3333

3434
/**

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/models/CustomCallingContext.java

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,30 @@
66

77
import com.azure.core.annotation.Fluent;
88
import com.azure.core.util.logging.ClientLogger;
9+
import com.azure.json.JsonReader;
10+
import com.azure.json.JsonSerializable;
11+
import com.azure.json.JsonToken;
12+
import com.azure.json.JsonWriter;
913

14+
import java.io.IOException;
1015
import java.util.Map;
1116

1217
/**
1318
* Custom calling context details.
1419
*/
1520
@Fluent
16-
public final class CustomCallingContext {
17-
private final Map<String, String> sipHeaders;
18-
private final Map<String, String> voipHeaders;
21+
public final class CustomCallingContext implements JsonSerializable<CustomCallingContext> {
22+
private Map<String, String> sipHeaders;
23+
private Map<String, String> voipHeaders;
1924
private final ClientLogger logger;
2025

26+
/**
27+
* Creates an instance of CustomCallingContext class.
28+
*/
29+
public CustomCallingContext() {
30+
this.logger = new ClientLogger(CustomCallingContext.class);
31+
}
32+
2133
/**
2234
* Create a CustomCallingContext object with SIP and VOIP headers
2335
*
@@ -88,4 +100,45 @@ public void addVoip(String key, String value) {
88100
}
89101
voipHeaders.put(key, value);
90102
}
103+
104+
/**
105+
* {@inheritDoc}
106+
*/
107+
@Override
108+
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
109+
jsonWriter.writeStartObject();
110+
jsonWriter.writeMapField("voipHeaders", this.voipHeaders, (writer, element) -> writer.writeString(element));
111+
jsonWriter.writeMapField("sipHeaders", this.sipHeaders, (writer, element) -> writer.writeString(element));
112+
return jsonWriter.writeEndObject();
113+
}
114+
115+
/**
116+
* Reads an instance of CustomCallingContext from the JsonReader.
117+
*
118+
* @param jsonReader The JsonReader being read.
119+
* @return An instance of CustomCallingContext if the JsonReader was pointing to an instance of it, or null if it
120+
* was pointing to JSON null.
121+
* @throws IOException If an error occurs while reading the CustomCallingContext.
122+
*/
123+
public static CustomCallingContext fromJson(JsonReader jsonReader) throws IOException {
124+
return jsonReader.readObject(reader -> {
125+
CustomCallingContext deserializedCustomCallingContext = new CustomCallingContext();
126+
while (reader.nextToken() != JsonToken.END_OBJECT) {
127+
String fieldName = reader.getFieldName();
128+
reader.nextToken();
129+
130+
if ("voipHeaders".equals(fieldName)) {
131+
Map<String, String> voipHeaders = reader.readMap(reader1 -> reader1.getString());
132+
deserializedCustomCallingContext.voipHeaders = voipHeaders;
133+
} else if ("sipHeaders".equals(fieldName)) {
134+
Map<String, String> sipHeaders = reader.readMap(reader1 -> reader1.getString());
135+
deserializedCustomCallingContext.sipHeaders = sipHeaders;
136+
} else {
137+
reader.skipChildren();
138+
}
139+
}
140+
141+
return deserializedCustomCallingContext;
142+
});
143+
}
91144
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.communication.callautomation.models.events;
5+
6+
import java.io.IOException;
7+
8+
import com.azure.communication.common.CommunicationIdentifier;
9+
import com.azure.communication.callautomation.models.CustomCallingContext;
10+
import com.azure.communication.callautomation.implementation.models.CommunicationIdentifierModel;
11+
import com.azure.communication.callautomation.implementation.converters.CommunicationIdentifierConverter;
12+
import com.azure.core.annotation.Immutable;
13+
import com.azure.json.JsonReader;
14+
import com.azure.json.JsonToken;
15+
import com.azure.json.JsonWriter;
16+
17+
/** The IncomingCall model. */
18+
@Immutable
19+
public final class IncomingCall extends CallAutomationEventBase {
20+
private CommunicationIdentifier to;
21+
private CommunicationIdentifier from;
22+
private String callerDisplayName;
23+
private CustomCallingContext customContext;
24+
private String incomingCallContext;
25+
private CommunicationIdentifier onBehalfOfCallee;
26+
27+
private IncomingCall() {
28+
}
29+
30+
private IncomingCall(CommunicationIdentifier to, CommunicationIdentifier from, String callerDisplayName,
31+
CustomCallingContext customContext, String incomingCallContext, CommunicationIdentifier onBehalfOfCallee,
32+
String correlationId, String serverCallId) {
33+
this.to = to;
34+
this.from = from;
35+
this.callerDisplayName = callerDisplayName;
36+
this.customContext = customContext;
37+
this.incomingCallContext = incomingCallContext;
38+
this.onBehalfOfCallee = onBehalfOfCallee;
39+
}
40+
41+
/**
42+
* Get the to property: The communication identifier of the target user.
43+
*
44+
* @return the to value.
45+
*/
46+
public CommunicationIdentifier getTo() {
47+
return this.to;
48+
}
49+
50+
/**
51+
* Get the from property: The communication identifier of the user who initiated the call.
52+
*
53+
* @return the from value.
54+
*/
55+
public CommunicationIdentifier getFrom() {
56+
return this.from;
57+
}
58+
59+
/**
60+
* Get the callerDisplayName property: Display name of caller.
61+
*
62+
* @return the callerDisplayName value.
63+
*/
64+
public String getCallerDisplayName() {
65+
return this.callerDisplayName;
66+
}
67+
68+
/**
69+
* Get the customContext property: Custom Context of Incoming Call.
70+
*
71+
* @return the customContext value
72+
*/
73+
public CustomCallingContext getCustomContext() {
74+
return this.customContext;
75+
}
76+
77+
/**
78+
* Get the incomingCallContext property: Incoming call context.
79+
*
80+
* @return the incomingCallContext value.
81+
*/
82+
public String getIncomingCallContext() {
83+
return this.incomingCallContext;
84+
}
85+
86+
/**
87+
* Get the onBehalfOfCallee property: The communication identifier of the user who is being called on behalf of.
88+
*
89+
* @return the onBehalfOfCallee value.
90+
*/
91+
public CommunicationIdentifier getOnBehalfOfCallee() {
92+
return this.onBehalfOfCallee;
93+
}
94+
95+
/**
96+
* {@inheritDoc}
97+
*/
98+
@Override
99+
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
100+
jsonWriter.writeStartObject();
101+
jsonWriter.writeJsonField("to", CommunicationIdentifierConverter.convert(to));
102+
jsonWriter.writeJsonField("from", CommunicationIdentifierConverter.convert(from));
103+
jsonWriter.writeStringField("callerDisplayName", callerDisplayName);
104+
jsonWriter.writeJsonField("customContext", customContext);
105+
jsonWriter.writeStringField("incomingCallContext", incomingCallContext);
106+
jsonWriter.writeJsonField("onBehalfOfCallee", CommunicationIdentifierConverter.convert(onBehalfOfCallee));
107+
super.writeFields(jsonWriter);
108+
return jsonWriter.writeEndObject();
109+
}
110+
111+
/**
112+
* Reads an instance of IncomingCall from the JsonReader.
113+
*
114+
* @param jsonReader The JsonReader being read.
115+
* @return An instance of IncomingCall if the JsonReader was pointing to an instance of it, or null
116+
* if it was pointing to JSON null.
117+
* @throws IOException If an error occurs while reading the IncomingCall.
118+
*/
119+
public static IncomingCall fromJson(JsonReader jsonReader) throws IOException {
120+
return jsonReader.readObject(reader -> {
121+
final IncomingCall event = new IncomingCall();
122+
while (jsonReader.nextToken() != JsonToken.END_OBJECT) {
123+
String fieldName = reader.getFieldName();
124+
reader.nextToken();
125+
if ("to".equals(fieldName)) {
126+
event.to = CommunicationIdentifierConverter.convert(CommunicationIdentifierModel.fromJson(reader));
127+
} else if ("from".equals(fieldName)) {
128+
event.from
129+
= CommunicationIdentifierConverter.convert(CommunicationIdentifierModel.fromJson(reader));
130+
} else if ("callerDisplayName".equals(fieldName)) {
131+
event.callerDisplayName = reader.getString();
132+
} else if ("customContext".equals(fieldName)) {
133+
event.customContext = CustomCallingContext.fromJson(reader);
134+
} else if ("incomingCallContext".equals(fieldName)) {
135+
event.incomingCallContext = reader.getString();
136+
} else if ("onBehalfOfCallee".equals(fieldName)) {
137+
event.onBehalfOfCallee
138+
= CommunicationIdentifierConverter.convert(CommunicationIdentifierModel.fromJson(reader));
139+
} else {
140+
if (!event.readField(fieldName, reader)) {
141+
reader.skipChildren();
142+
}
143+
}
144+
}
145+
return event;
146+
});
147+
}
148+
}

sdk/communication/azure-communication-callautomation/swagger/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ directive:
277277
- remove-model: HoldAudioPaused
278278
- remove-model: PlayPaused
279279
- remove-model: PlayResumed
280+
- remove-model: IncomingCall
280281

281282
```
282283

0 commit comments

Comments
 (0)