Skip to content

Commit

Permalink
Merge pull request #46 from ChristopheCVB/develop
Browse files Browse the repository at this point in the history
v8.1.2
  • Loading branch information
ChristopheCVB authored Jan 22, 2022
2 parents 1748585 + a0baa53 commit e536310
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -887,26 +887,50 @@ public boolean sendConnectorUpdate(String pluginId, String connectorId, Integer
private boolean sendConnectorUpdate(String constructedConnectorId, Integer value) {
boolean sent = false;
if (constructedConnectorId != null && !constructedConnectorId.isEmpty() && value != null && value >= 0 && value <= 100 && !value.equals(this.currentConnectorValues.get(constructedConnectorId))) {
JsonObject showNotificationMessage = new JsonObject();
showNotificationMessage.addProperty(SentMessageHelper.TYPE, SentMessageHelper.TYPE_CONNECTOR_UPDATE);
if (this.connectorIdsMapping.containsKey(constructedConnectorId)) {
showNotificationMessage.addProperty(SentMessageHelper.SHORT_ID, this.connectorIdsMapping.get(constructedConnectorId));
JsonObject connectorUpdateMessage = new JsonObject();
connectorUpdateMessage.addProperty(SentMessageHelper.TYPE, SentMessageHelper.TYPE_CONNECTOR_UPDATE);
String shortId = this.getConnectorShortId(constructedConnectorId);
if (shortId != null) {
connectorUpdateMessage.addProperty(SentMessageHelper.SHORT_ID, shortId);
}
else {
showNotificationMessage.addProperty(SentMessageHelper.CONNECTOR_ID, constructedConnectorId);
else if (constructedConnectorId.length() <= 200){
connectorUpdateMessage.addProperty(SentMessageHelper.CONNECTOR_ID, constructedConnectorId);
}
showNotificationMessage.addProperty(SentMessageHelper.VALUE, value);
connectorUpdateMessage.addProperty(SentMessageHelper.VALUE, value);

sent = this.send(showNotificationMessage);
if (connectorUpdateMessage.has(SentMessageHelper.SHORT_ID) || connectorUpdateMessage.has(SentMessageHelper.CONNECTOR_ID)) {
sent = this.send(connectorUpdateMessage);
}
if (sent) {
this.currentConnectorValues.put(constructedConnectorId, value);
}
TouchPortalPlugin.LOGGER.log(Level.INFO, "Connector Update [" + constructedConnectorId + "] Sent [" + sent + "]");
if (shortId != null || constructedConnectorId.length() <= 200) {
TouchPortalPlugin.LOGGER.log(Level.INFO, "Connector Update [" + constructedConnectorId + "] Sent [" + sent + "]");
}
}

return sent;
}

private String getConnectorShortId(String constructedConnectorId) {
String shortId = null;
HashMap<String, String> deconstructedConnectorId = this.deconstructConnectorId(constructedConnectorId);
for (String mappedConnectorId : this.connectorIdsMapping.keySet()) {
HashMap<String, String> deconstructedMappedConnectorId = this.deconstructConnectorId(mappedConnectorId);
if (deconstructedConnectorId.equals(deconstructedMappedConnectorId)) {
shortId = this.connectorIdsMapping.get(mappedConnectorId);
break;
}
}
return shortId;
}

private HashMap<String, String> deconstructConnectorId(String constructedConnectorId) {
HashMap<String, String> deconstructedConnectorId = new HashMap<>();
Arrays.stream(constructedConnectorId.split("\\|")).map(elem -> elem.split("=")).forEach(pair -> deconstructedConnectorId.put(pair[0], pair.length > 1 ? pair[1] : null));
return deconstructedConnectorId;
}

/**
* Is the Plugin connected to the Touch Portal Plugin System
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.*;

Expand Down Expand Up @@ -423,10 +424,15 @@ public void testReceiveConnectorEmptyId() throws IOException, InterruptedExcepti

@Test
public void testReceiveShortConnectorIdNotification() throws IOException, InterruptedException {
Map<String, Object> dataReceived = new HashMap<>();
dataReceived.put(TouchPortalPluginTestConstants.BaseCategory.Connectors.ConnectorForSliderWithData.Text.ID + "0", "Text0!");
dataReceived.put(TouchPortalPluginTestConstants.BaseCategory.Connectors.ConnectorForSliderWithData.Text.ID, "Text!");
dataReceived.put(TouchPortalPluginTestConstants.BaseCategory.Connectors.ConnectorForSliderWithData.Text.ID + "2", "Text2!");

JsonObject jsonMessage = new JsonObject();
jsonMessage.addProperty(ReceivedMessageHelper.PLUGIN_ID, TouchPortalPluginTestConstants.ID);
jsonMessage.addProperty(ReceivedMessageHelper.TYPE, ReceivedMessageHelper.TYPE_SHORT_CONNECTOR_ID_NOTIFICATION);
jsonMessage.addProperty(ReceivedMessageHelper.CONNECTOR_ID, "pc_VERY_LONG_CONSTRUCTED_ID");
jsonMessage.addProperty(ReceivedMessageHelper.CONNECTOR_ID, ConnectorHelper.getConstructedId(TouchPortalPluginTestConstants.ID, TouchPortalPluginTestConstants.BaseCategory.Connectors.ConnectorForSliderWithData.ID, 0, dataReceived));
jsonMessage.addProperty(ReceivedMessageHelper.SHORT_ID, "SHORT_ID");
PrintWriter out = new PrintWriter(this.serverSocketClient.getOutputStream(), true);
out.println(jsonMessage);
Expand All @@ -435,6 +441,12 @@ public void testReceiveShortConnectorIdNotification() throws IOException, Interr

assertTrue(this.touchPortalPluginTest.isConnected());
assertTrue(this.touchPortalPluginTest.isListening());

Map<String, Object> dataSent = new HashMap<>();
dataSent.put(TouchPortalPluginTestConstants.BaseCategory.Connectors.ConnectorForSliderWithData.Text.ID + "2", "Text2!");
dataSent.put(TouchPortalPluginTestConstants.BaseCategory.Connectors.ConnectorForSliderWithData.Text.ID, "Text!");
dataSent.put(TouchPortalPluginTestConstants.BaseCategory.Connectors.ConnectorForSliderWithData.Text.ID + "0", "Text0!");
assertTrue(this.touchPortalPluginTest.sendConnectorUpdate(TouchPortalPluginTestConstants.ID, TouchPortalPluginTestConstants.BaseCategory.Connectors.ConnectorForSliderWithData.ID, 10, dataSent));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#TouchPortalPluginTest
#Thu Jan 13 12:05:41 CET 2022
#Fri Jan 21 19:02:31 CET 2022
samplekey=Sample Value
plugin.version=1
2 changes: 1 addition & 1 deletion Packager/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {

group 'com.christophecvb.touchportal'
def localArchiveBaseName = 'plugin-packager'
version versionName
version versionName + (isRelease ? '' : '-' + System.currentTimeMillis())

pluginBundle {
website = 'https://github.com/ChristopheCVB/TouchPortalPluginSDK'
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ allprojects {

ext.versionMajor = 8
ext.versionMinor = 1
ext.versionPatch = 0
ext.versionPatch = 2

ext.isRelease = System.getenv('IS_RELEASE') == 'YES'

Expand Down

0 comments on commit e536310

Please sign in to comment.