-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes string values not working with V3 (#282)
* Fixes string values not working with V3 Signed-off-by: Mohammad Ghazanfar Ali Danish <[email protected]> * Address review remarks Signed-off-by: Mohammad Ghazanfar Ali Danish <[email protected]> --------- Signed-off-by: Mohammad Ghazanfar Ali Danish <[email protected]>
- Loading branch information
Showing
8 changed files
with
186 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...aas/src/main/java/org/eclipse/digitaltwin/basyx/databridge/aas/util/AASComponentUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/******************************************************************************* | ||
* Copyright (C) 2024 the Eclipse BaSyx Authors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
* SPDX-License-Identifier: MIT | ||
******************************************************************************/ | ||
|
||
package org.eclipse.digitaltwin.basyx.databridge.aas.util; | ||
|
||
/** | ||
* An utility class for the AAS Component | ||
* | ||
* @author danish | ||
*/ | ||
public class AASComponentUtil { | ||
|
||
private AASComponentUtil() { | ||
throw new IllegalStateException("Utility class"); | ||
} | ||
|
||
/** | ||
* A convenient method to wrap the content as String | ||
* | ||
* e.g., | ||
* | ||
* <pre> | ||
* 72 -> "72" | ||
* 56.23 -> "56.23" | ||
* "example" -> "example" | ||
* "example -> RuntimeException (Malformed from the right) | ||
* example" -> RuntimeException (Malformed from the left) | ||
* | ||
* </pre> | ||
* | ||
* @param content | ||
* @return | ||
*/ | ||
public static String wrapContent(String content) { | ||
|
||
if (content == null || content.isEmpty()) | ||
return ""; | ||
|
||
if (isAlreadyWrapped(content)) | ||
return content; | ||
|
||
throwExceptionIfMalformedWrapping(content); | ||
|
||
return wrapStringValue(content); | ||
} | ||
|
||
/** | ||
* Checks whether the provided string value is already wrapped in quotes ("") or not | ||
* | ||
* e.g., | ||
* | ||
* <pre> | ||
* 56.23 -> false | ||
* "example" -> true | ||
* example -> false | ||
* | ||
* </pre> | ||
* | ||
* @param content | ||
* @return | ||
*/ | ||
public static boolean isAlreadyWrapped(String content) { | ||
return content.startsWith("\"") && content.endsWith("\""); | ||
} | ||
|
||
private static String wrapStringValue(String content) { | ||
if (content.isEmpty()) | ||
return content; | ||
|
||
return "\"" + content + "\""; | ||
} | ||
|
||
private static void throwExceptionIfMalformedWrapping(String content) { | ||
|
||
if (isRightMalformed(content) || isLeftMalformed(content)) | ||
throw new RuntimeException("The content's: " + content + " formatting is malformed."); | ||
} | ||
|
||
private static boolean isLeftMalformed(String content) { | ||
return !content.startsWith("\"") && content.endsWith("\""); | ||
} | ||
|
||
private static boolean isRightMalformed(String content) { | ||
return content.startsWith("\"") && !content.endsWith("\""); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 7 additions & 1 deletion
8
databridge.examples/databridge.examples.dot-aas-v3-api/src/main/resources/mqttconsumer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
[ | ||
{ | ||
"uniqueId": "mqttSource", | ||
"uniqueId": "mqttSource1", | ||
"serverUrl": "localhost", | ||
"serverPort": 1884, | ||
"topic": "DotAASV3ConformantProperty" | ||
}, | ||
{ | ||
"uniqueId": "mqttSource2", | ||
"serverUrl": "localhost", | ||
"serverPort": 1884, | ||
"topic": "DotAASV3ConformantPropertyStringValue" | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
...bridge.examples/databridge.examples.dot-aas-v3-api/src/main/resources/productName.jsonata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Account.Order[0].Product[0].'Product Name' |
8 changes: 7 additions & 1 deletion
8
databridge.examples/databridge.examples.dot-aas-v3-api/src/main/resources/routes.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
[ | ||
{ | ||
"datasource": "mqttSource", | ||
"datasource": "mqttSource1", | ||
"transformers": ["weight"], | ||
"datasinks": ["ConnectedTestSubmodel/DotAASV3ConformantApiProperty"], | ||
"trigger": "event" | ||
}, | ||
{ | ||
"datasource": "mqttSource2", | ||
"transformers": ["productName"], | ||
"datasinks": ["ConnectedTestSubmodel/DotAASV3ConformantApiStringProperty"], | ||
"trigger": "event" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters