diff --git a/Annotations/src/main/java/com/christophecvb/touchportal/annotations/Category.java b/Annotations/src/main/java/com/christophecvb/touchportal/annotations/Category.java index 43c843f..e6b622b 100644 --- a/Annotations/src/main/java/com/christophecvb/touchportal/annotations/Category.java +++ b/Annotations/src/main/java/com/christophecvb/touchportal/annotations/Category.java @@ -33,7 +33,7 @@ * * @see TP Documentation: Categories */ -@Retention(RetentionPolicy.SOURCE) +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Category { /** diff --git a/Helpers/src/main/java/com/christophecvb/touchportal/helpers/CategoryHelper.java b/Helpers/src/main/java/com/christophecvb/touchportal/helpers/CategoryHelper.java index 42e7bb6..c4eba79 100644 --- a/Helpers/src/main/java/com/christophecvb/touchportal/helpers/CategoryHelper.java +++ b/Helpers/src/main/java/com/christophecvb/touchportal/helpers/CategoryHelper.java @@ -23,6 +23,7 @@ import com.christophecvb.touchportal.annotations.Category; import javax.lang.model.element.Element; +import java.lang.reflect.Field; /** * Touch Portal Plugin Category Helper @@ -48,6 +49,17 @@ public static String getCategoryId(Element pluginElement, Element categoryElemen return CategoryHelper._getCategoryId(PluginHelper.getPluginId(pluginElement), category.id().isEmpty() ? categoryElement.getSimpleName().toString() : category.id()); } + /** + * Get Category Short ID + * + * @param categoryField {@link Field} + * @param category {@link Category} + * @return String categoryId + */ + public static String getCategoryShortId(Field categoryField, Category category) { + return category.id().isEmpty() ? categoryField.getName() : category.id(); + } + /** * Get the generated Category Name * @@ -59,6 +71,17 @@ public static String getCategoryName(Element categoryElement, Category category) return category.name().isEmpty() ? categoryElement.getSimpleName().toString() : category.name(); } + /** + * Get the generated Category Name + * + * @param categoryField {@link Field} + * @param category {@link Category} + * @return String categoryName + */ + public static String getCategoryName(Field categoryField, Category category) { + return category.name().isEmpty() ? categoryField.getName() : category.name(); + } + /** * Get the generated Category ID * diff --git a/Helpers/src/main/java/com/christophecvb/touchportal/helpers/PluginHelper.java b/Helpers/src/main/java/com/christophecvb/touchportal/helpers/PluginHelper.java index 0c615b3..b4706d6 100644 --- a/Helpers/src/main/java/com/christophecvb/touchportal/helpers/PluginHelper.java +++ b/Helpers/src/main/java/com/christophecvb/touchportal/helpers/PluginHelper.java @@ -43,7 +43,7 @@ public class PluginHelper { /** * Touch Portal Plugin System version */ - public static final int TOUCH_PORTAL_PLUGIN_VERSION = 5; + public static final int TOUCH_PORTAL_PLUGIN_VERSION = 6; /** * Argument passed to the jar to start the plugin */ diff --git a/Helpers/src/main/java/com/christophecvb/touchportal/helpers/SentMessageHelper.java b/Helpers/src/main/java/com/christophecvb/touchportal/helpers/SentMessageHelper.java index a5a8d2c..a852b12 100644 --- a/Helpers/src/main/java/com/christophecvb/touchportal/helpers/SentMessageHelper.java +++ b/Helpers/src/main/java/com/christophecvb/touchportal/helpers/SentMessageHelper.java @@ -47,5 +47,6 @@ public class SentMessageHelper { public static final String OPTIONS = "options"; public static final String CONNECTOR_ID = "connectorId"; public static final String SHORT_ID = "shortId"; + public static final String PARENT_GROUP = "parentGroup"; } \ No newline at end of file diff --git a/Library/src/main/java/com/christophecvb/touchportal/TouchPortalPlugin.java b/Library/src/main/java/com/christophecvb/touchportal/TouchPortalPlugin.java index ae58cf0..37865d0 100644 --- a/Library/src/main/java/com/christophecvb/touchportal/TouchPortalPlugin.java +++ b/Library/src/main/java/com/christophecvb/touchportal/TouchPortalPlugin.java @@ -712,7 +712,21 @@ public boolean sendStateUpdate(String stateId, Object value, boolean allowEmptyV * @return boolean stateUpdateMessageSent */ public boolean sendCreateState(String categoryId, String stateId, String description, Object value) { - return this.sendCreateState(categoryId, stateId, description, value, false, false); + return this.sendCreateState(categoryId, stateId, null, description, value, false, false); + } + + /** + * Send a Create a State Message to the Touch Portal Plugin System not allowing empty value + * + * @param categoryId String + * @param stateId String + * @param parentGroup String + * @param description String + * @param value Object + * @return boolean stateUpdateMessageSent + */ + public boolean sendCreateState(String categoryId, String stateId, String parentGroup, String description, Object value) { + return this.sendCreateState(categoryId, stateId, parentGroup, description, value, false, false); } /** @@ -727,6 +741,22 @@ public boolean sendCreateState(String categoryId, String stateId, String descrip * @return boolean stateCreateSent */ public boolean sendCreateState(String categoryId, String stateId, String description, Object value, boolean allowEmptyValue, boolean forceUpdate) { + return this.sendCreateState(categoryId, stateId, null, description, value, allowEmptyValue, forceUpdate); + } + + /** + * Send a Create a State Message to the Touch Portal Plugin System + * + * @param categoryId String + * @param stateId String + * @param parentGroup String + * @param description String + * @param value Object + * @param allowEmptyValue boolean + * @param forceUpdate boolean + * @return boolean stateCreateSent + */ + public boolean sendCreateState(String categoryId, String stateId, String parentGroup, String description, Object value, boolean allowEmptyValue, boolean forceUpdate) { boolean sent = false; String valueStr = value != null ? String.valueOf(value) : null; if (categoryId != null && !categoryId.isEmpty() && stateId != null && !stateId.isEmpty() && description != null && !description.isEmpty() && valueStr != null && (allowEmptyValue || !valueStr.isEmpty())) { @@ -737,6 +767,24 @@ public boolean sendCreateState(String categoryId, String stateId, String descrip createStateMessage.addProperty(SentMessageHelper.ID, stateId); createStateMessage.addProperty(SentMessageHelper.DESCRIPTION, description); createStateMessage.addProperty(SentMessageHelper.DEFAULT_VALUE, valueStr); + if (parentGroup == null || parentGroup.isEmpty()) { + classLoop: + for (Class subClass : this.pluginClass.getDeclaredClasses()) { + for (Field subClassField : subClass.getDeclaredFields()) { + if (subClassField.isAnnotationPresent(Category.class)) { + Category category = subClassField.getAnnotation(Category.class); + + if(categoryId.equals(CategoryHelper.getCategoryShortId(subClassField, category))) { + createStateMessage.addProperty(SentMessageHelper.PARENT_GROUP, CategoryHelper.getCategoryName(subClassField, category)); + break classLoop; + } + } + } + } + } else { + createStateMessage.addProperty(SentMessageHelper.PARENT_GROUP, parentGroup); + } + sent = this.send(createStateMessage); if (sent) { this.currentStates.put(stateId, valueStr); diff --git a/Library/src/test/java/com/christophecvb/touchportal/test/LibraryTests.java b/Library/src/test/java/com/christophecvb/touchportal/test/LibraryTests.java index db68892..2f85477 100644 --- a/Library/src/test/java/com/christophecvb/touchportal/test/LibraryTests.java +++ b/Library/src/test/java/com/christophecvb/touchportal/test/LibraryTests.java @@ -321,37 +321,43 @@ public void testDynamicStates() { assertFalse(this.touchPortalPluginTest.sendCreateState(null, null, null, "")); assertFalse(this.touchPortalPluginTest.sendCreateState("", "", "", "")); - assertFalse(this.touchPortalPluginTest.sendCreateState("CategoryId", null, null, null)); - assertFalse(this.touchPortalPluginTest.sendCreateState("CategoryId", "", null, null)); - assertFalse(this.touchPortalPluginTest.sendCreateState("CategoryId", null, "", null)); - assertFalse(this.touchPortalPluginTest.sendCreateState("CategoryId", null, null, "")); - assertFalse(this.touchPortalPluginTest.sendCreateState("CategoryId", "", "", "")); + assertFalse(this.touchPortalPluginTest.sendCreateState("BaseCategory", null, null, null)); + assertFalse(this.touchPortalPluginTest.sendCreateState("BaseCategory", "", null, null)); + assertFalse(this.touchPortalPluginTest.sendCreateState("BaseCategory", null, "", null)); + assertFalse(this.touchPortalPluginTest.sendCreateState("BaseCategory", null, null, "")); + assertFalse(this.touchPortalPluginTest.sendCreateState("BaseCategory", "", "", "")); - assertFalse(this.touchPortalPluginTest.sendCreateState("CategoryId", "SateId", null, null)); - assertFalse(this.touchPortalPluginTest.sendCreateState("CategoryId", "SateId", "", null)); - assertFalse(this.touchPortalPluginTest.sendCreateState("CategoryId", "SateId", null, "")); - assertFalse(this.touchPortalPluginTest.sendCreateState("CategoryId", "SateId", "", "")); + assertFalse(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", null, null)); + assertFalse(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", "", null)); + assertFalse(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", null, "")); + assertFalse(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", "", "")); - assertFalse(this.touchPortalPluginTest.sendCreateState("CategoryId", "SateId", "Dynamically Created State", null)); - assertFalse(this.touchPortalPluginTest.sendCreateState("CategoryId", "SateId", "Dynamically Created State", "")); + assertFalse(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", "Dynamically Created State", null)); + assertFalse(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", "Dynamically Created State", "")); - assertFalse(this.touchPortalPluginTest.sendCreateState("CategoryId", "StateId", "Dynamically Created State", null, true, false)); - assertTrue(this.touchPortalPluginTest.sendCreateState("CategoryId", "StateId", "Dynamically Created State", "", true, false)); - assertFalse(this.touchPortalPluginTest.sendCreateState("CategoryId", "StateId", "Dynamically Created State", "", true, false)); - assertTrue(this.touchPortalPluginTest.sendCreateState("CategoryId", "StateId", "Dynamically Created State", "", true, true)); + assertFalse(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", "Dynamically Created State", null, true, false)); + assertTrue(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", "Dynamically Created State", "", true, false)); + assertFalse(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", "Dynamically Created State", "", true, false)); + assertTrue(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", "Dynamically Created State", "", true, true)); + + assertTrue(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", "Dynamically Created State", "Default Value 01")); + assertFalse(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", "Dynamically Created State", "Default Value 01")); + assertTrue(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", "Dynamically Created State", "Default Value 02")); + + assertTrue(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", "Parent", "Dynamically Created State", "Default Value 01")); + assertTrue(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", "", "Dynamically Created State", "Default Value 02")); + assertTrue(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", null, "Dynamically Created State", "Default Value 03")); + assertTrue(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", "Parent", "Dynamically Created State", "Default Value 04", true, false)); - assertTrue(this.touchPortalPluginTest.sendCreateState("CategoryId", "SateId", "Dynamically Created State", "Default Value 01")); - assertFalse(this.touchPortalPluginTest.sendCreateState("CategoryId", "SateId", "Dynamically Created State", "Default Value 01")); - assertTrue(this.touchPortalPluginTest.sendCreateState("CategoryId", "SateId", "Dynamically Created State", "Default Value 02")); assertFalse(this.touchPortalPluginTest.sendRemoveState(null, null)); assertFalse(this.touchPortalPluginTest.sendRemoveState("", null)); assertFalse(this.touchPortalPluginTest.sendRemoveState(null, "")); assertFalse(this.touchPortalPluginTest.sendRemoveState("", "")); - assertFalse(this.touchPortalPluginTest.sendRemoveState("CategoryId", null)); - assertFalse(this.touchPortalPluginTest.sendRemoveState("CategoryId", "")); + assertFalse(this.touchPortalPluginTest.sendRemoveState("BaseCategory", null)); + assertFalse(this.touchPortalPluginTest.sendRemoveState("BaseCategory", "")); - assertTrue(this.touchPortalPluginTest.sendRemoveState("CategoryId", "SateId")); + assertTrue(this.touchPortalPluginTest.sendRemoveState("BaseCategory", "StateId")); } @Test @@ -360,8 +366,8 @@ public void testSendFail() { assertFalse(this.touchPortalPluginTest.sendStateUpdate(TouchPortalPluginTestConstants.BaseCategory.States.CustomState.ID, "New Value")); assertFalse(this.touchPortalPluginTest.sendChoiceUpdate("listId", null, true)); assertFalse(this.touchPortalPluginTest.sendSpecificChoiceUpdate("listId", "instanceId", null, true)); - assertFalse(this.touchPortalPluginTest.sendCreateState("CategoryId", "SateId", "Dynamically Created State", "Default Value 01")); - assertFalse(this.touchPortalPluginTest.sendRemoveState("CategoryId", "SateId")); + assertFalse(this.touchPortalPluginTest.sendCreateState("BaseCategory", "StateId", "Dynamically Created State", "Default Value 01")); + assertFalse(this.touchPortalPluginTest.sendRemoveState("BaseCategory", "StateId")); } @Test diff --git a/build.gradle b/build.gradle index 03f26fb..0af9408 100644 --- a/build.gradle +++ b/build.gradle @@ -5,8 +5,8 @@ allprojects { } ext.versionMajor = 8 -ext.versionMinor = 1 -ext.versionPatch = 2 +ext.versionMinor = 2 +ext.versionPatch = 0 ext.isRelease = System.getenv('IS_RELEASE') == 'YES'