From 84aef051409676ff2b7d83b12cbb416fc9cf0972 Mon Sep 17 00:00:00 2001 From: Daniel Krueger Date: Fri, 6 Dec 2024 14:03:52 +0100 Subject: [PATCH 1/3] removed metadata --- .../fieldmapping/FieldMappingModel.java | 25 ++----- .../factories/WritingServiceFactory.java | 7 +- .../factories/WritingServiceProvider.java | 10 ++- .../fieldmapping/FieldMappingEntity.java | 23 ++---- .../adapter/fieldmapping/MetadataEntity.java | 70 ------------------- .../mappings/fieldmapping/FieldMapping.java | 14 +--- .../topicfilter/TopicFilterPersistence.java | 4 +- .../TopicFilterPersistenceImpl.java | 2 +- 8 files changed, 29 insertions(+), 126 deletions(-) delete mode 100644 hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/fieldmapping/MetadataEntity.java diff --git a/hivemq-edge/src/main/java/com/hivemq/api/model/mappings/fieldmapping/FieldMappingModel.java b/hivemq-edge/src/main/java/com/hivemq/api/model/mappings/fieldmapping/FieldMappingModel.java index 14f98723a5..f1ca43561f 100644 --- a/hivemq-edge/src/main/java/com/hivemq/api/model/mappings/fieldmapping/FieldMappingModel.java +++ b/hivemq-edge/src/main/java/com/hivemq/api/model/mappings/fieldmapping/FieldMappingModel.java @@ -30,32 +30,19 @@ public class FieldMappingModel { @Schema(description = "List of instructions to be applied to incoming data") private final @NotNull List instructions; - @JsonProperty(value = "metadata", required = true) - @Schema(description = "Metadata for the whole mapping") - private final @NotNull MetadataModel metadata; - public FieldMappingModel( - @JsonProperty(value = "instructions", required = true) final @NotNull List instructions, - @JsonProperty(value = "metadata", required = true) final @NotNull MetadataModel metadata) { + @JsonProperty(value = "instructions", required = true) final @NotNull List instructions) { this.instructions = instructions; - this.metadata = metadata; } public @NotNull List getInstructions() { return instructions; } - public @NotNull MetadataModel getMetadata() { - return metadata; - } - - public static FieldMappingModel from(final FieldMapping fieldMapping) { - if(fieldMapping == null) { - return null; - } - return new FieldMappingModel( - fieldMapping.getInstructions().stream().map(InstructionModel::from) - .collect(Collectors.toList()), - MetadataModel.from(fieldMapping.getMetaData())); + public static @NotNull FieldMappingModel from(final @NotNull FieldMapping fieldMapping) { + return new FieldMappingModel(fieldMapping.getInstructions() + .stream() + .map(InstructionModel::from) + .collect(Collectors.toList())); } } diff --git a/hivemq-edge/src/main/java/com/hivemq/bootstrap/factories/WritingServiceFactory.java b/hivemq-edge/src/main/java/com/hivemq/bootstrap/factories/WritingServiceFactory.java index 9964132493..5f5c47029e 100644 --- a/hivemq-edge/src/main/java/com/hivemq/bootstrap/factories/WritingServiceFactory.java +++ b/hivemq-edge/src/main/java/com/hivemq/bootstrap/factories/WritingServiceFactory.java @@ -16,6 +16,7 @@ package com.hivemq.bootstrap.factories; import com.fasterxml.jackson.databind.ObjectMapper; +import com.hivemq.persistence.topicfilter.TopicFilterPersistence; import org.jetbrains.annotations.NotNull; import com.hivemq.mqtt.topic.tree.LocalTopicTree; import com.hivemq.persistence.SingleWriterService; @@ -24,9 +25,9 @@ public interface WritingServiceFactory { - @NotNull - InternalProtocolAdapterWritingService build( + @NotNull InternalProtocolAdapterWritingService build( @NotNull ObjectMapper objectMapper, @NotNull LocalTopicTree localTopicTree, - @NotNull SingleWriterService singleWriterService); + @NotNull SingleWriterService singleWriterService, + @NotNull TopicFilterPersistence topicFilterPersistence); } diff --git a/hivemq-edge/src/main/java/com/hivemq/bootstrap/factories/WritingServiceProvider.java b/hivemq-edge/src/main/java/com/hivemq/bootstrap/factories/WritingServiceProvider.java index ca9fbf1210..c29a7593f5 100644 --- a/hivemq-edge/src/main/java/com/hivemq/bootstrap/factories/WritingServiceProvider.java +++ b/hivemq-edge/src/main/java/com/hivemq/bootstrap/factories/WritingServiceProvider.java @@ -19,6 +19,7 @@ import com.hivemq.adapter.sdk.api.services.ProtocolAdapterMetricsService; import com.hivemq.adapter.sdk.api.writing.WritingProtocolAdapter; import com.hivemq.bootstrap.services.EdgeCoreFactoryService; +import com.hivemq.persistence.topicfilter.TopicFilterPersistence; import org.jetbrains.annotations.NotNull; import com.hivemq.mqtt.topic.tree.LocalTopicTree; import com.hivemq.persistence.SingleWriterService; @@ -39,17 +40,20 @@ public class WritingServiceProvider { private final @NotNull ObjectMapper objectMapper; private final @NotNull LocalTopicTree localTopicTree; private final @NotNull SingleWriterService singleWriterService; + private final @NotNull TopicFilterPersistence topicFilterPersistence; @Inject public WritingServiceProvider( final @NotNull EdgeCoreFactoryService edgeCoreFactoryService, final @NotNull ObjectMapper objectMapper, final @NotNull LocalTopicTree localTopicTree, - final @NotNull SingleWriterService singleWriterService) { + final @NotNull SingleWriterService singleWriterService, + final @NotNull TopicFilterPersistence topicFilterPersistence) { this.edgeCoreFactoryService = edgeCoreFactoryService; this.objectMapper = objectMapper; this.localTopicTree = localTopicTree; this.singleWriterService = singleWriterService; + this.topicFilterPersistence = topicFilterPersistence; } public @NotNull InternalProtocolAdapterWritingService get() { @@ -59,7 +63,9 @@ public WritingServiceProvider( } return writingServiceFactory.build(objectMapper, localTopicTree, - singleWriterService); + singleWriterService, + topicFilterPersistence + ); } diff --git a/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/fieldmapping/FieldMappingEntity.java b/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/fieldmapping/FieldMappingEntity.java index 7dc702f2ef..72757a84b0 100644 --- a/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/fieldmapping/FieldMappingEntity.java +++ b/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/fieldmapping/FieldMappingEntity.java @@ -16,9 +16,9 @@ package com.hivemq.configuration.entity.adapter.fieldmapping; import com.fasterxml.jackson.databind.ObjectMapper; -import org.jetbrains.annotations.NotNull; import com.hivemq.persistence.mappings.fieldmapping.FieldMapping; import com.hivemq.persistence.mappings.fieldmapping.Instruction; +import org.jetbrains.annotations.NotNull; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; @@ -33,45 +33,32 @@ public class FieldMappingEntity { @XmlElement(name = "instruction") private final @NotNull List instructions; - @XmlElement(name = "metadata") - private final @NotNull MetadataEntity metaData; - //no arg constructor for JaxB - public FieldMappingEntity() {; + public FieldMappingEntity() { instructions = new ArrayList<>(); - metaData = new MetadataEntity(); } public FieldMappingEntity( - final @NotNull List instructions, - final @NotNull MetadataEntity metaData) { + final @NotNull List instructions) { this.instructions = instructions; - this.metaData = metaData; } public @NotNull List getInstructions() { return instructions; } - public @NotNull MetadataEntity getMetaData() { - return metaData; - } - public static @NotNull FieldMappingEntity from(final @NotNull FieldMapping model) { if (model == null) { return null; } final List fieldMappingEntityList = model.getInstructions().stream().map(InstructionEntity::from).collect(Collectors.toList()); - return new FieldMappingEntity(fieldMappingEntityList, - MetadataEntity.from(model.getMetaData())); + return new FieldMappingEntity(fieldMappingEntityList); } public @NotNull FieldMapping to(final @NotNull ObjectMapper mapper) { final List instructions = getInstructions().stream().map(InstructionEntity::to).collect(Collectors.toList()); - return new FieldMapping( - instructions, - getMetaData().to(mapper)); + return new FieldMapping(instructions); } } diff --git a/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/fieldmapping/MetadataEntity.java b/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/fieldmapping/MetadataEntity.java deleted file mode 100644 index a41510b57a..0000000000 --- a/hivemq-edge/src/main/java/com/hivemq/configuration/entity/adapter/fieldmapping/MetadataEntity.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2019-present HiveMQ GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.hivemq.configuration.entity.adapter.fieldmapping; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.jetbrains.annotations.NotNull; -import com.hivemq.persistence.mappings.fieldmapping.Metadata; - -import javax.xml.bind.annotation.XmlElement; - -public class MetadataEntity { - - @XmlElement(name = "sourceSchema") - private final @NotNull String sourceJsonSchema; - - @XmlElement(name = "destinationSchema") - private final @NotNull String destinationJsonSchema; - - // no-arg for JaxB - MetadataEntity() { - sourceJsonSchema = "{}"; - destinationJsonSchema = "{}"; - } - - public MetadataEntity( - final @NotNull String sourceJsonSchema, - final @NotNull String destinationJsonSchema) { - this.sourceJsonSchema = sourceJsonSchema; - this.destinationJsonSchema = destinationJsonSchema; - } - - public @NotNull String getDestinationJsonSchema() { - return destinationJsonSchema; - } - - public @NotNull String getSourceJsonSchema() { - return sourceJsonSchema; - } - - public static @NotNull MetadataEntity from( - final @NotNull Metadata model) { - return new MetadataEntity(model.getSourceJsonSchema().toString(), - model.getDestinationJsonSchema().toString()); - } - - public @NotNull Metadata to(ObjectMapper mapper) { - final Metadata metadata; - try { - metadata = - new Metadata(mapper.readTree(getSourceJsonSchema()), mapper.readTree(getDestinationJsonSchema())); - return metadata; - } catch (JsonProcessingException e) { - throw new RuntimeException(e); //TODO nicer! - } - } -} diff --git a/hivemq-edge/src/main/java/com/hivemq/persistence/mappings/fieldmapping/FieldMapping.java b/hivemq-edge/src/main/java/com/hivemq/persistence/mappings/fieldmapping/FieldMapping.java index d70795acfd..8bdbd0ddaa 100644 --- a/hivemq-edge/src/main/java/com/hivemq/persistence/mappings/fieldmapping/FieldMapping.java +++ b/hivemq-edge/src/main/java/com/hivemq/persistence/mappings/fieldmapping/FieldMapping.java @@ -25,25 +25,15 @@ public class FieldMapping { private final @NotNull List instructions; - private final @NotNull Metadata metadata; - - - public FieldMapping(final List instructions, final Metadata metadata) { + public FieldMapping(final @NotNull List instructions) { this.instructions = instructions; - this.metadata = metadata; } public @NotNull List getInstructions() { return instructions; } - public Metadata getMetaData() { - return metadata; - } - public static @NotNull FieldMapping fromModel(final @NotNull FieldMappingModel model) { - return new FieldMapping( - model.getInstructions().stream().map(Instruction::from).collect(Collectors.toList()), - Metadata.from(model.getMetadata())); + return new FieldMapping(model.getInstructions().stream().map(Instruction::from).collect(Collectors.toList())); } } diff --git a/hivemq-edge/src/main/java/com/hivemq/persistence/topicfilter/TopicFilterPersistence.java b/hivemq-edge/src/main/java/com/hivemq/persistence/topicfilter/TopicFilterPersistence.java index 7dcc374c9f..382c6f6a9a 100644 --- a/hivemq-edge/src/main/java/com/hivemq/persistence/topicfilter/TopicFilterPersistence.java +++ b/hivemq-edge/src/main/java/com/hivemq/persistence/topicfilter/TopicFilterPersistence.java @@ -16,6 +16,7 @@ package com.hivemq.persistence.topicfilter; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -38,5 +39,6 @@ public interface TopicFilterPersistence { @NotNull List getTopicFilters(); - @NotNull TopicFilter getTag(@NotNull String filter); + @Nullable + TopicFilter getTopicFilter(@NotNull String filter); } diff --git a/hivemq-edge/src/main/java/com/hivemq/persistence/topicfilter/TopicFilterPersistenceImpl.java b/hivemq-edge/src/main/java/com/hivemq/persistence/topicfilter/TopicFilterPersistenceImpl.java index 6912360741..eaff323a49 100644 --- a/hivemq-edge/src/main/java/com/hivemq/persistence/topicfilter/TopicFilterPersistenceImpl.java +++ b/hivemq-edge/src/main/java/com/hivemq/persistence/topicfilter/TopicFilterPersistenceImpl.java @@ -113,7 +113,7 @@ private void loadPersistence() { } @Override - public @NotNull TopicFilter getTag(final @NotNull String filter) { + public @NotNull TopicFilter getTopicFilter(final @NotNull String filter) { final TopicFilter topicFilter = filterToTopicFilter.get(filter); if (topicFilter == null) { throw new TagNotFoundException("TopicFilter for filter '" + filter + "' was not found in the persistence."); From 11439bcc6871d02179920bec00aa85f5e573a5f0 Mon Sep 17 00:00:00 2001 From: Daniel Krueger Date: Fri, 6 Dec 2024 23:19:18 +0100 Subject: [PATCH 2/3] fix opcua tests --- .../persistence/topicfilter/TopicFilterPersistenceImpl.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/hivemq-edge/src/main/java/com/hivemq/persistence/topicfilter/TopicFilterPersistenceImpl.java b/hivemq-edge/src/main/java/com/hivemq/persistence/topicfilter/TopicFilterPersistenceImpl.java index eaff323a49..4214c996dd 100644 --- a/hivemq-edge/src/main/java/com/hivemq/persistence/topicfilter/TopicFilterPersistenceImpl.java +++ b/hivemq-edge/src/main/java/com/hivemq/persistence/topicfilter/TopicFilterPersistenceImpl.java @@ -114,10 +114,6 @@ private void loadPersistence() { @Override public @NotNull TopicFilter getTopicFilter(final @NotNull String filter) { - final TopicFilter topicFilter = filterToTopicFilter.get(filter); - if (topicFilter == null) { - throw new TagNotFoundException("TopicFilter for filter '" + filter + "' was not found in the persistence."); - } - return topicFilter; + return filterToTopicFilter.get(filter); } } From 193bf967953d09737390742afe11b41e765cdaf5 Mon Sep 17 00:00:00 2001 From: Daniel Krueger Date: Mon, 9 Dec 2024 08:35:35 +0100 Subject: [PATCH 3/3] update OpenAPI --- ext/hivemq-edge-openapi-2024.8-SNAPSHOT.yaml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/ext/hivemq-edge-openapi-2024.8-SNAPSHOT.yaml b/ext/hivemq-edge-openapi-2024.8-SNAPSHOT.yaml index 37268abbd2..8696c0c205 100644 --- a/ext/hivemq-edge-openapi-2024.8-SNAPSHOT.yaml +++ b/ext/hivemq-edge-openapi-2024.8-SNAPSHOT.yaml @@ -5090,11 +5090,8 @@ components: description: List of instructions to be applied to incoming data items: $ref: '#/components/schemas/Instruction' - metadata: - $ref: '#/components/schemas/Metadata' required: - instructions - - metadata FirstUseInformation: type: object description: Information relating to the firstuse experience @@ -5383,17 +5380,6 @@ components: - destination - filters - maxQoS - Metadata: - type: object - description: Metadata for the whole mapping - properties: - destination: - $ref: '#/components/schemas/JsonNode' - source: - $ref: '#/components/schemas/JsonNode' - required: - - destination - - source Metric: type: object description: List of result items that are returned by this endpoint