Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 2952946

Browse files
authored
ENGCOM-3805: Add support for topic schema defined as ServiceName:methodName #23
2 parents 4c99249 + 525cc72 commit 2952946

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

app/code/Magento/WebapiAsync/Code/Generator/Config/RemoteServiceReader/Communication.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public function read($scope = null)
6767
CommunicationConfig::HANDLER_TYPE => $serviceClass,
6868
CommunicationConfig::HANDLER_METHOD => $serviceMethod,
6969
],
70-
]
70+
],
71+
false
7172
);
7273
$rewriteTopicParams = [
7374
CommunicationConfig::TOPIC_IS_SYNCHRONOUS => false,

lib/internal/Magento/Framework/Communication/Config/Reader/XmlReader/Converter.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,22 @@ protected function extractTopics($config)
124124
$requestSchema,
125125
$responseSchema
126126
);
127+
$isSynchronous = $this->extractTopicIsSynchronous($topicNode);
127128
if ($serviceMethod) {
128129
$output[$topicName] = $this->reflectionGenerator->generateTopicConfigForServiceMethod(
129130
$topicName,
130131
$serviceMethod[ConfigParser::TYPE_NAME],
131132
$serviceMethod[ConfigParser::METHOD_NAME],
132-
$handlers
133+
$handlers,
134+
$isSynchronous
133135
);
134136
} elseif ($requestSchema && $responseSchema) {
135137
$output[$topicName] = [
136138
Config::TOPIC_NAME => $topicName,
137-
Config::TOPIC_IS_SYNCHRONOUS => true,
139+
Config::TOPIC_IS_SYNCHRONOUS => $isSynchronous,
138140
Config::TOPIC_REQUEST => $requestSchema,
139141
Config::TOPIC_REQUEST_TYPE => Config::TOPIC_REQUEST_TYPE_CLASS,
140-
Config::TOPIC_RESPONSE => $responseSchema,
142+
Config::TOPIC_RESPONSE => ($isSynchronous) ? $responseSchema: null,
141143
Config::TOPIC_HANDLERS => $handlers
142144
];
143145
} elseif ($requestSchema) {
@@ -258,4 +260,20 @@ protected function parseServiceMethod($serviceMethod, $topicName)
258260
);
259261
return $parsedServiceMethod;
260262
}
263+
264+
/**
265+
* Extract is_synchronous topic value.
266+
*
267+
* @param \DOMNode $topicNode
268+
* @return bool
269+
*/
270+
private function extractTopicIsSynchronous($topicNode): bool
271+
{
272+
$attributeName = Config::TOPIC_IS_SYNCHRONOUS;
273+
$topicAttributes = $topicNode->attributes;
274+
if (!$topicAttributes->getNamedItem($attributeName)) {
275+
return true;
276+
}
277+
return $this->booleanUtils->toBoolean($topicAttributes->getNamedItem($attributeName)->nodeValue);
278+
}
261279
}

lib/internal/Magento/Framework/Communication/Config/ReflectionGenerator.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ public function extractMethodMetadata($className, $methodName)
4242
$result = [
4343
Config::SCHEMA_METHOD_PARAMS => [],
4444
Config::SCHEMA_METHOD_RETURN_TYPE => $this->methodsMap->getMethodReturnType($className, $methodName),
45-
Config::SCHEMA_METHOD_HANDLER => [Config::HANDLER_TYPE => $className, Config::HANDLER_METHOD => $methodName]
45+
Config::SCHEMA_METHOD_HANDLER => [
46+
Config::HANDLER_TYPE => $className,
47+
Config::HANDLER_METHOD => $methodName
48+
]
4649
];
4750
$paramsMeta = $this->methodsMap->getMethodParams($className, $methodName);
4851
foreach ($paramsMeta as $paramPosition => $paramMeta) {
@@ -63,16 +66,27 @@ public function extractMethodMetadata($className, $methodName)
6366
* @param string $serviceType
6467
* @param string $serviceMethod
6568
* @param array|null $handlers
69+
* @param bool|null $isSynchronous
6670
* @return array
6771
*/
68-
public function generateTopicConfigForServiceMethod($topicName, $serviceType, $serviceMethod, $handlers = [])
69-
{
72+
public function generateTopicConfigForServiceMethod(
73+
$topicName,
74+
$serviceType,
75+
$serviceMethod,
76+
$handlers = [],
77+
$isSynchronous = null
78+
) {
7079
$methodMetadata = $this->extractMethodMetadata($serviceType, $serviceMethod);
7180
$returnType = $methodMetadata[Config::SCHEMA_METHOD_RETURN_TYPE];
7281
$returnType = ($returnType != 'void' && $returnType != 'null') ? $returnType : null;
82+
if (!isset($isSynchronous)) {
83+
$isSynchronous = $returnType ? true : false;
84+
} else {
85+
$returnType = ($isSynchronous) ? $returnType : null;
86+
}
7387
return [
7488
Config::TOPIC_NAME => $topicName,
75-
Config::TOPIC_IS_SYNCHRONOUS => $returnType ? true : false,
89+
Config::TOPIC_IS_SYNCHRONOUS => $isSynchronous,
7690
Config::TOPIC_REQUEST => $methodMetadata[Config::SCHEMA_METHOD_PARAMS],
7791
Config::TOPIC_REQUEST_TYPE => Config::TOPIC_REQUEST_TYPE_METHOD,
7892
Config::TOPIC_RESPONSE => $returnType,
@@ -85,7 +99,8 @@ public function generateTopicConfigForServiceMethod($topicName, $serviceType, $s
8599
* Generate topic name based on service type and method name.
86100
*
87101
* Perform the following conversion:
88-
* \Magento\Customer\Api\RepositoryInterface + getById => magento.customer.api.repositoryInterface.getById
102+
* \Magento\Customer\Api\RepositoryInterface + getById =>
103+
* magento.customer.api.repositoryInterface.getById
89104
*
90105
* @param string $typeName
91106
* @param string $methodName

lib/internal/Magento/Framework/Communication/etc/communication.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<xs:attribute type="schemaType" name="schema" use="optional"/>
4141
<xs:attribute type="xs:string" name="request" use="optional"/>
4242
<xs:attribute type="xs:string" name="response" use="optional"/>
43+
<xs:attribute type="xs:boolean" name="is_synchronous" use="optional"/>
4344
</xs:complexType>
4445
<xs:complexType name="handlerType">
4546
<xs:attribute type="xs:string" name="name" use="required"/>

0 commit comments

Comments
 (0)