Enable specifying target type when created using DMF API (#1472)

Extension of DMF API with possibility of setting target
type name when creating target. If a target type with the
provided name is found (was created beforehand) then it
is associated with the new target.

Signed-off-by: Ondrej Charvat <ondrej.charvat@proton.me>
This commit is contained in:
charvadzo
2024-01-22 14:01:00 +01:00
committed by GitHub
parent af56b71d53
commit 49a5509e89
8 changed files with 236 additions and 24 deletions

View File

@@ -231,14 +231,18 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
final URI amqpUri = IpUtil.createAmqpUri(virtualHost, replyTo);
final Target target;
if (isOptionalMessageBodyEmpty(message)) {
LOG.debug("Received \"THING_CREATED\" AMQP message for thing \"{}\" without body.", thingId);
target = controllerManagement.findOrRegisterTargetIfItDoesNotExist(thingId, amqpUri);
} else {
checkContentTypeJson(message);
final DmfCreateThing thingCreateBody = convertMessage(message, DmfCreateThing.class);
final DmfAttributeUpdate thingAttributeUpdateBody = thingCreateBody.getAttributeUpdate();
LOG.debug("Received \"THING_CREATED\" AMQP message for thing \"{}\" with target name \"{}\" and type " +
"\"{}\".", thingId, thingCreateBody.getName(), thingCreateBody.getType());
target = controllerManagement.findOrRegisterTargetIfItDoesNotExist(thingId, amqpUri,
thingCreateBody.getName());
thingCreateBody.getName(), thingCreateBody.getType());
if (thingAttributeUpdateBody != null) {
controllerManagement.updateControllerAttributes(thingId, thingAttributeUpdateBody.getAttributes(),