Skip to content

Commit

Permalink
Merge pull request #86 from SoftwareAG/feature-backport-c8y-1018
Browse files Browse the repository at this point in the history
Feature backport c8y 1018
  • Loading branch information
ck-c8y authored Mar 12, 2024
2 parents 7c97932 + a2d7178 commit 919dbf5
Show file tree
Hide file tree
Showing 125 changed files with 3,965 additions and 2,930 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/check-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Check push requests

on:
workflow_dispatch:
push:
# Sequence of patterns matched against refs/tags
# tags:
# - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
branches:
- '*'

permissions:
contents: write
issues: write
pull-requests: write

jobs:
typos:
name: Spell Check with Typos
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4

- name: Check spelling
uses: crate-ci/typos@master
14 changes: 10 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ target/
logs/
bin/
attic/*
dist/

dynamic-mapping-ui/node_modules/*
dynamic-mapping-extension/.factorypath
dynamic-mapping-interface/.factorypath
dynamic-mapping-service/.factorypath

.factorypath
set.sh
dynamic-mapping-ui/.env

**/.flattened-pom.xml
node_modules
.angular
dynamic-mapping-ui/cypress.env.js
dynamic-mapping-ui/cypress/videos
dynamic-mapping-ui/cypress/screenshots
dynamic-mapping-ui/cypress/fixtures/mqttConnectionPostRequest.json
12 changes: 12 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[default.extend-words]
mosquitto = "mosquitto"
serie = "serie"
inferrable = "inferrable"
Strack = "Strack"
Witschel = "Witschel"
mor = "mor"
MOR = "MOR"
ser = "ser"

[files]
extend-exclude = ["**/mappings**.json", "**/*Mappings**.json"]
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Follow the steps from the point above to assign the plugin to your Administratio
Make sure that [Docker](https://www.docker.com/), [Apache Maven](https://maven.apache.org/) and [Node.js](https://nodejs.org/) are installed and running on your computer.

### Backend - Microservice
Run `mvn clean package` in folder `dyanmic-mapping-service` to build the Microservice which will create a ZIP archive you can upload to Cumulocity.
Run `mvn clean package` in folder `dynamic-mapping-service` to build the Microservice which will create a ZIP archive you can upload to Cumulocity.
Just deploy the ZIP to the Cumulocity Tenant like described [here](https://cumulocity.com/guides/users-guide/administration/#uploading-microservices).

### Frontend - Plugin
Expand Down Expand Up @@ -214,7 +214,7 @@ The table of configured connectors to different brokers can be:
</p>
<br/>

Furthermore, new connectors can be added. The UI is shown on the following screenshot. In the modal dialog you have to select first the type of connector: MQTT, MQTT Connect, Kafka, ... Then the input is dynamically adapted to the configuration paramaeter for the choosen connector type:
Furthermore, new connectors can be added. The UI is shown on the following screenshot. In the modal dialog you have to select first the type of connector: MQTT, MQTT Connect, Kafka, ... Then the input is dynamically adapted to the configuration paramaeter for the chosen connector type:

<p align="center">
<img src="resources/image/Generic_Mapping_Connector_Edit.png" style="width: 70%;" />
Expand Down Expand Up @@ -314,7 +314,7 @@ $parseInteger($string("0x"&$substring(message,0,2)),"0")&" C"
___

1. Define the properties of the topic and API to be used
2. Define the templates for the source and target, in JSON format. The soure payload can be in any custom JSON format. the target format has to follow the schemsa for Alarm, Events, Measurements or Inventory, [see Cumulocity OpenAPI](https://cumulocity.com/api/).
2. Define the templates for the source and target, in JSON format. The source payload can be in any custom JSON format. the target format has to follow the schemsa for Alarm, Events, Measurements or Inventory, [see Cumulocity OpenAPI](https://cumulocity.com/api/).
3. Test the mapping by applying the transformation and send the result to a test device.

##### Define topic properties
Expand All @@ -329,7 +329,7 @@ For the mappings we differentiate between a **subscription topic** and a **templ

For outbound mappings the properties are slightly different. Most important are the properties:
1. `filterOutbound`: The Filter Outbound can contain one fragment name to associate a
mapping to a Cumulocity MEAO. If the Cumulocity MEAO contains this fragment, the maping is
mapping to a Cumulocity MEAO. If the Cumulocity MEAO contains this fragment, the mapping is
applied.
2. `publishTopic`: MQTT topic to publish outbound messages to.

Expand Down Expand Up @@ -368,7 +368,7 @@ The levels of the Template Topic are split and added to the payload:
]
```
The entries in the ```_TOPIC_LEVEL_``` can be used to resolve the external device identifier to the internal Cumulocity Id.
The additinal property ```_TOPIC_LEVEL_``` is added to the source template shown in the next wizard step. It must not be deleted when editing the JSON source template.
The additional property ```_TOPIC_LEVEL_``` is added to the source template shown in the next wizard step. It must not be deleted when editing the JSON source template.

##### Snooping payloads on source topic

Expand All @@ -378,7 +378,7 @@ In order to record JSON payloads on the defined topic a subscription records the

The snooping process goes through the steps **ENABLED** -> **STARTED** -> **STOPPED**.

If a payload is found the status moves to **STARTED**. This is indicated in the last column of the mappping table, where the number of payloads snooped so far is shown.
If a payload is found the status moves to **STARTED**. This is indicated in the last column of the mapping table, where the number of payloads snooped so far is shown.

##### Enable snooping payloads on source topic

Expand All @@ -392,7 +392,7 @@ To enable snooping select ```ENABLED``` in the drop down as shown in the screens

##### Map Device Identifier

Connected devices send their data using an external device identifier, e.g. IMEI, serial number, ... In this case the external id has to be used for looking to the device id used by Cumulocity. To achieve this the entries in the ```_TOPIC_LEVEL_``` can be used to resolve the external device identifier to an internal Cumulocity id. When a payload from this device arrives at runtime the external id is used to lookup the corresponding internal Cumulocity id with the help of a external id tpye.
Connected devices send their data using an external device identifier, e.g. IMEI, serial number, ... In this case the external id has to be used for looking to the device id used by Cumulocity. To achieve this the entries in the ```_TOPIC_LEVEL_``` can be used to resolve the external device identifier to an internal Cumulocity id. When a payload from this device arrives at runtime the external id is used to lookup the corresponding internal Cumulocity id with the help of a external id type.


##### Define templates and substitutions for source and target payload
Expand Down Expand Up @@ -445,10 +445,10 @@ To define a new substitution the following steps have to be performed:

>**_NOTE:_** When adding a new substitution the following two consistency rules are checked:
>1. Does another substitution for the same target property exist? If so, a modal dialog appears and asks the user for confirmation to overwrite the existing substitution.
>2. If the new substitution defines the device identifier, it is checked if another substitution already withe the same proprty exists. If so, a modal dialog appears and asks for confirmation to overwrite the existing substitution.
>2. If the new substitution defines the device identifier, it is checked if another substitution already withe the same property exists. If so, a modal dialog appears and asks for confirmation to overwrite the existing substitution.

To avoid inconsistent JSON being sent to the Cumulocity API the defined target tmeplate are validated with schemas. These are defined for all target payloads (Measurement, Event, Alarm, Inventory). The schemas validate if reqiured properties are defined and if the time is in the correct format.
To avoid inconsistent JSON being sent to the Cumulocity API the defined target tmeplate are validated with schemas. These are defined for all target payloads (Measurement, Event, Alarm, Inventory). The schemas validate if required properties are defined and if the time is in the correct format.

In the sample below, e.g. a warning is shown since the required property ```source.id``` is missing in the payload.

Expand All @@ -462,7 +462,7 @@ In the sample below, e.g. a warning is shown since the required property ```sour
When you define an expression or a path in the source payload for a substitution the result can be one of the following cases:
1. **if** the result is a scalar value, e.g. ```10.4``` for a single value **and**
* **if** only one device is identified in the payload \
**then** only one Cumulocity MEA-resquest is generated from this payload.\
**then** only one Cumulocity MEA-request is generated from this payload.\
This is a **single-device-single-value** mapping.
* **if** multiple devices are identified, e.g. ```["device_101023", "device_101024"]``` in the payload \
**then** multiple Cumulocity MEA-requests or inventory requests - depending on the used targetAPI in the mapping - are generated from this payload. This only makes sense for creating multiple devices.\
Expand Down Expand Up @@ -507,7 +507,7 @@ ___
#### Test transformation from source to target format

To test the defined transformation, press the button ```Transform test message```. The result of the transformation and any errors are displayed.
On test transformation can result in multiple Cumulocity reqests, e.g. when a measurement is created for a device that is implicitly created, then two requests result from this transformation.
On test transformation can result in multiple Cumulocity requests, e.g. when a measurement is created for a device that is implicitly created, then two requests result from this transformation.
To iterate and show all results press the button ```Show Next Test Result```.


Expand Down Expand Up @@ -594,7 +594,7 @@ Using the tab ```Processor Extension``` you can upload your own processor extens
</p>
<br/>

The following guide lays out hte steps to create and use a processor extension:
The following guide lays out the steps to create and use a processor extension:

<p align="center">
<img src="resources/image/Generic_Mapping_ProcessorExtensionInbound_Guide.png" style="width: 70%;" />
Expand All @@ -613,7 +613,7 @@ On the monitoring tab ```Monitoring``` you can see how a specific MQTT mapping p
</p>
<br/>

A chart shows a summary with numbers of all sucessfully processed messages and those raising errors.
A chart shows a summary with numbers of all successfully processed messages and those raising errors.

<p align="center">
<img src="resources/image/Generic_Mapping_MonitoringChart.png" style="width: 70%;" />
Expand Down Expand Up @@ -642,8 +642,8 @@ The mapping microservice provides endpoints to control the lifecycle and manage
6. ```.../monitoring/tree```: all mappings are organised in a tree for efficient processing and resolving the mappings at runtime. This tree can be retrieved for debugging purposes.
7. ```.../monitoring/subscriptions```: retrieve all active subscriptions.
8. ```.../mapping```: retrieve, create, delete, update mappings
9. ```.../test/{method}?topic=URL_ENCODED_TOPIC```: this endpoint allows testing of a payload. The send parameter (boolean) indicates if the transformed payload should be sent to Cumulocity after processing. The call return a list of ```ProcessingConext``` to record which mapping processed the payload and the outcome of the mapping process as well as error
10. ```.../extension/```: endpoint to retieve a list of all extensions
9. ```.../test/{method}?topic=URL_ENCODED_TOPIC```: this endpoint allows testing of a payload. The send parameter (boolean) indicates if the transformed payload should be sent to Cumulocity after processing. The call return a list of ```ProcessingContext``` to record which mapping processed the payload and the outcome of the mapping process as well as error
10. ```.../extension/```: endpoint to retrieve a list of all extensions
11. ```.../extension/{extension-name}```: endpoint to retrieve/delete a specific extension

## Tests & Sample Data
Expand Down
5 changes: 1 addition & 4 deletions dynamic-mapping-interface/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@
<groupId>com.ibm.jsonata4java</groupId>
<artifactId>JSONata4Java</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand All @@ -67,6 +63,7 @@
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
Expand Down
15 changes: 8 additions & 7 deletions dynamic-mapping-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
</properties>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
Expand Down Expand Up @@ -72,8 +73,8 @@
<artifactId>JSONata4Java</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down Expand Up @@ -113,7 +114,7 @@
<plugin>
<groupId>com.nsn.cumulocity.clients-java</groupId>
<artifactId>microservice-package-maven-plugin</artifactId>
<version>1018.0.220</version>
<version>1020.73.0</version>
<executions>
<execution>
<id>package</id>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package dynamic.mapping.connector.core.callback;

import javax.validation.constraints.NotNull;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
public class ConnectorMessage {
byte[] payload;
String[] headers;
String tenant;
String topic;
String connectorIdent;
boolean sendPayload;
private byte[] payload;

private String[] headers;

@NotNull
private String tenant;

private String topic;

@NotNull
private String connectorIdent;

private boolean sendPayload;
}
Loading

0 comments on commit 919dbf5

Please sign in to comment.