1313 * <p>
1414 * <b>Resource Name Handling:</b>
1515 * <ul>
16- * <li>Extracts taskId from parent resource name (format: "tasks/{task_id}")</li>
17- * <li>Fallback: Extracts from config.name if parent is blank</li>
18- * <li>Overrides PushNotificationConfig.id with config_id from request</li>
16+ * <li>Extracts taskId from parent resource name (format: "tasks/{task_id}")</li>
17+ * <li>Fallback: Extracts from config.name if parent is blank</li>
18+ * <li>Overrides PushNotificationConfig.id with config_id from request</li>
1919 * </ul>
2020 * <p>
2121 * <b>Compile-Time Safety:</b> If the proto changes fields, MapStruct will fail to compile.
@@ -38,7 +38,7 @@ public interface SetTaskPushNotificationConfigMapper {
3838 @ Mapping (target = "pushNotificationConfig" , expression = "java(mapPushNotificationConfigWithId(request))" )
3939 TaskPushNotificationConfig fromProto (SetTaskPushNotificationConfigRequest request );
4040
41- /**
41+ /**
4242 * Converts SetTaskPushNotificationConfigRequest to domain TaskPushNotificationConfig.
4343 * <p>
4444 * Extracts taskId from parent resource name and maps PushNotificationConfig with
@@ -48,9 +48,10 @@ public interface SetTaskPushNotificationConfigMapper {
4848 * @return proto SetTaskPushNotificationConfigRequest
4949 */
5050 @ Mapping (target = "parent" , expression = "java(ResourceNameParser.defineTaskName(config.taskId()))" )
51- @ Mapping (target = "configId" , expression = "java(config.pushNotificationConfig().id( ))" )
51+ @ Mapping (target = "configId" , expression = "java(extractConfigId(config ))" )
5252 @ Mapping (target = "config" , expression = "java(mapPushNotificationConfig(config))" )
5353 SetTaskPushNotificationConfigRequest toProto (TaskPushNotificationConfig config );
54+
5455 /**
5556 * Extracts the task ID from the parent resource name.
5657 * <p>
@@ -72,6 +73,19 @@ default String extractTaskId(SetTaskPushNotificationConfigRequest request) {
7273 return ResourceNameParser .extractParentId (parent );
7374 }
7475
76+ /**
77+ * Extracts the config ID from the configuration. If it is not defined, the task ID is used.
78+ *
79+ * @param config the TaskPushNotificationConfig
80+ * @return the extracted config ID
81+ */
82+ default String extractConfigId (TaskPushNotificationConfig config ) {
83+ if (config .pushNotificationConfig () != null && config .pushNotificationConfig ().id () != null && !config .pushNotificationConfig ().id ().isBlank ()) {
84+ return config .pushNotificationConfig ().id ();
85+ }
86+ return config .taskId ();
87+ }
88+
7589 /**
7690 * Maps the protobuf PushNotificationConfig to domain, injecting config_id from request.
7791 * <p>
@@ -82,26 +96,26 @@ default String extractTaskId(SetTaskPushNotificationConfigRequest request) {
8296 */
8397 default PushNotificationConfig mapPushNotificationConfigWithId (SetTaskPushNotificationConfigRequest request ) {
8498 // Check if config and push_notification_config exist
85- if (!request .hasConfig () ||
86- !request .getConfig ().hasPushNotificationConfig () ||
87- request .getConfig ().getPushNotificationConfig ()
88- .equals (io .a2a .grpc .PushNotificationConfig .getDefaultInstance ())) {
99+ if (!request .hasConfig ()
100+ || !request .getConfig ().hasPushNotificationConfig ()
101+ || request .getConfig ().getPushNotificationConfig ()
102+ .equals (io .a2a .grpc .PushNotificationConfig .getDefaultInstance ())) {
89103 return null ;
90104 }
91105
92106 // Map the proto PushNotificationConfig
93107 PushNotificationConfig result = PushNotificationConfigMapper .INSTANCE .fromProto (
94- request .getConfig ().getPushNotificationConfig ()
108+ request .getConfig ().getPushNotificationConfig ()
95109 );
96110
97111 // Override ID with config_id from request
98112 String configId = request .getConfigId ();
99113 if (configId != null && !configId .isEmpty () && !configId .equals (result .id ())) {
100114 return new PushNotificationConfig (
101- result .url (),
102- result .token (),
103- result .authentication (),
104- configId
115+ result .url (),
116+ result .token (),
117+ result .authentication (),
118+ configId
105119 );
106120 }
107121
0 commit comments