Skip to content
Snippets Groups Projects
Commit b0941a67 authored by René Schöne's avatar René Schöne
Browse files

WIP working towards incremental eraser version with ragconnect.

- use new local version of ragconnect with fixed inheritance
- rework item parsing (fill item in place instead of using an NTA)
- remove unknownGroup NTA (replace with singleton-like method)
-
parent 1cfbb9a0
No related branches found
No related tags found
1 merge request!21Draft: Replace mqtt handling with RagConnect
Pipeline #15554 failed
Showing
with 158 additions and 61 deletions
......@@ -54,7 +54,7 @@ String[] ragconnectArguments = [
'--o=src/gen/jastadd',
'--logReads',
'--logWrites',
'--logIncremental',
// '--logIncremental',
// '--verbose',
'--rootNode=Root',
'--experimental-jastadd-329',
......
No preview for this file type
......@@ -330,10 +330,6 @@ aspect ItemHandling {
return getStateAsString();
}
syn KeyValuePair Item.getFoo() {
return new KeyValuePair().setKey("State").setValue(getStateAsString());
}
//--- sendState ---
protected void Item.sendState() throws Exception {
for (MachineLearningModel model : getRelevantInMachineLearningModels()) {
......
aspect JastAddFixes {
refine ASTNode public void Opt.init$Children() {
state().enterConstruction();
//getChild_handler = new ASTNode$DepGraphNode[4];
state().exitConstruction();
if (getChild_handler == null) {
//getChild_handler = new ASTNode$DepGraphNode[4];
setChild(null, 0);
}
}
refine ASTNode public void JastAddList.init$Children() {
state().enterConstruction();
state().exitConstruction();
if (getChild_handler == null) {
//addChild(null);
//removeChild(0);
children = new ASTNode[4];
getChild_handler = new ASTNode$DepGraphNode[4];
}
}
}
......@@ -8,7 +8,6 @@ aspect Navigation {
syn java.util.List<Item> SmartHomeEntityModel.items() {
java.util.List<Item> result = new java.util.ArrayList<>();
getGroupList().forEach(group -> result.addAll(group.items()));
result.addAll(unknownGroup().items());
return result;
}
syn java.util.List<Item> Group.items() {
......@@ -36,10 +35,16 @@ aspect Navigation {
inh Group Item.enclosingGroup();
eq Group.getItem().enclosingGroup() = this;
eq Group.getGroup().enclosingGroup() = this;
eq SmartHomeEntityModel.unknownGroup().enclosingGroup() = null;
eq SmartHomeEntityModel.getGroup().enclosingGroup() = null;
eq SmartHomeEntityModel.getActivityItem().enclosingGroup() = null;
inh int Item.myIndexInGroupList();
eq Group.getItem(int index).myIndexInGroupList() = index;
eq SmartHomeEntityModel.getActivityItem().myIndexInGroupList() = -1;
syn boolean Item.isItemPrototype() = false;
eq ItemPrototype.isItemPrototype() = true;
//--- containingSmartHomeEntityModel ---
inh SmartHomeEntityModel Thing.containingSmartHomeEntityModel();
inh SmartHomeEntityModel Group.containingSmartHomeEntityModel();
......
......@@ -24,10 +24,9 @@ aspect Printing {
sb.append(i.prettyPrint());
}
for (Group g : groups()) {
sb.append(g.prettyPrint());
}
if (unknownGroup().getNumItem() > 0 ) {
sb.append(unknownGroup().prettyPrint());
if (!g.isUnknownGroup() || g.getNumItem() > 0) {
sb.append(g.prettyPrint());
}
}
for (ThingType tt : getThingTypeList()) {
sb.append(tt.prettyPrint());
......@@ -153,7 +152,7 @@ aspect Printing {
.addNonDefault("description", getDescription())
.addOptional("type", getType() != null, () -> getType().toString())
.addNonDefault("context", getContext())
.addOptional("default", hasDefaultValue(), () -> getDefaultValue().getValue())
.addOptional("default", hasDefaultValue() && getDefaultValue() != null, () -> getDefaultValue().getValue())
.addFlag("required", getRequired())
.build();
}
......
......@@ -53,18 +53,29 @@ import java.util.HashMap;
root.doSafeFullTraversal();
// resolve ItemPlaceHolders
java.util.Map<Item, Item> toReplace = new HashMap<>();
for (Group g : root.getSmartHomeEntityModel().groups()) {
JastAddList<Item> items = g.getItemList();
for (int i = 0; i < g.getNumItem(); i++) {
Item item = items.getChild(i);
Item realItem = item.realItem();
if (item != realItem) {
realItem.removeSelf();
item.removeSelf();
items.insertChild(realItem, i);
toReplace.put(item, realItem);
}
}
}
for (Map.Entry<Item, Item> entry : toReplace.entrySet()) {
Item placeholder = entry.getKey();
Item realItem = entry.getValue();
if (realItem.isActivityItem() && placeholder.myIndexInGroupList() == -1) {
// can not move activity item
System.err.println("Can not put activity item in a group");
} else {
realItem.removeSelf();
placeholder.enclosingGroup().setItem(realItem, placeholder.myIndexInGroupList());
}
}
// resolve GroupPlaceHolders
for (Group g : root.getSmartHomeEntityModel().groups()) {
JastAddList<Group> groups = g.getGroupList();
......@@ -116,7 +127,7 @@ import java.util.HashMap;
Root root =
thing.t root.r {: insertZero(r.getSmartHomeEntityModel().getThingList(), t); return r; :}
| item.i root.r {: insertZero(r.getSmartHomeEntityModel().unknownGroup().getItemList(), i); return r; :}
| item.i root.r {: insertZero(r.getSmartHomeEntityModel().getUnknownGroup().getItemList(), i); return r; :}
| group.g root.r {: insertZero(r.getSmartHomeEntityModel().getGroupList(), g); return r; :}
| state_sync_group.ss root.r {: r.addRule(ss); return r; :}
| thing_type.tt root.r {: insertZero(r.getSmartHomeEntityModel().getThingTypeList(), tt); return r; :}
......@@ -190,19 +201,19 @@ Thing thing_body =
;
Item item =
COLOR ITEM COLON item_body.ib SEMICOLON {: ib.setItemWithCorrectType(new ColorItem()); return ib; :}
| CONTACT ITEM COLON item_body.ib SEMICOLON {: ib.setItemWithCorrectType(new ContactItem()); return ib; :}
| DATE_TIME ITEM COLON item_body.ib SEMICOLON {: ib.setItemWithCorrectType(new DateTimeItem()); return ib; :}
| DIMMER ITEM COLON item_body.ib SEMICOLON {: ib.setItemWithCorrectType(new DimmerItem()); return ib; :}
| IMAGE ITEM COLON item_body.ib SEMICOLON {: ib.setItemWithCorrectType(new ImageItem()); return ib; :}
| LOCATION ITEM COLON item_body.ib SEMICOLON {: ib.setItemWithCorrectType(new LocationItem()); return ib; :}
| NUMBER ITEM COLON item_body.ib SEMICOLON {: ib.setItemWithCorrectType(new NumberItem()); return ib; :}
| PLAYER ITEM COLON item_body.ib SEMICOLON {: ib.setItemWithCorrectType(new PlayerItem()); return ib; :}
| ROLLER_SHUTTER ITEM COLON item_body.ib SEMICOLON {: ib.setItemWithCorrectType(new RollerShutterItem()); return ib; :}
| STRING ITEM COLON item_body.ib SEMICOLON {: ib.setItemWithCorrectType(new StringItem()); return ib; :}
| SWITCH ITEM COLON item_body.ib SEMICOLON {: ib.setItemWithCorrectType(new SwitchItem()); return ib; :}
| ACTIVITY ITEM COLON item_body.ib SEMICOLON {: ib.setItemWithCorrectType(new ActivityItem()); return ib; :}
| ITEM COLON item_body.ib SEMICOLON {: ib.setItemWithCorrectType(new DefaultItem()); return ib; :}
COLOR ITEM COLON item_body.ib SEMICOLON {: return new ColorItem().fillFromPrototype(ib); :}
| CONTACT ITEM COLON item_body.ib SEMICOLON {: return new ContactItem().fillFromPrototype(ib); :}
| DATE_TIME ITEM COLON item_body.ib SEMICOLON {: return new DateTimeItem().fillFromPrototype(ib); :}
| DIMMER ITEM COLON item_body.ib SEMICOLON {: return new DimmerItem().fillFromPrototype(ib); :}
| IMAGE ITEM COLON item_body.ib SEMICOLON {: return new ImageItem().fillFromPrototype(ib); :}
| LOCATION ITEM COLON item_body.ib SEMICOLON {: return new LocationItem().fillFromPrototype(ib); :}
| NUMBER ITEM COLON item_body.ib SEMICOLON {: return new NumberItem().fillFromPrototype(ib); :}
| PLAYER ITEM COLON item_body.ib SEMICOLON {: return new PlayerItem().fillFromPrototype(ib); :}
| ROLLER_SHUTTER ITEM COLON item_body.ib SEMICOLON {: return new RollerShutterItem().fillFromPrototype(ib); :}
| STRING ITEM COLON item_body.ib SEMICOLON {: return new StringItem().fillFromPrototype(ib); :}
| SWITCH ITEM COLON item_body.ib SEMICOLON {: return new SwitchItem().fillFromPrototype(ib); :}
| ACTIVITY ITEM COLON item_body.ib SEMICOLON {: return new ActivityItem().fillFromPrototype(ib); :}
| ITEM COLON item_body.ib SEMICOLON {: return new DefaultItem().fillFromPrototype(ib); :}
;
// ITEM_TYPE Item: id="" label="" state="" category="" topic="" performance="" metaData={"key":"value"} ;
......@@ -211,7 +222,7 @@ ItemPrototype item_body =
| LABEL EQUALS TEXT.n item_body.i {: i.setLabel(n); return i; :}
| STATE EQUALS TEXT.n item_body.i {: i.setStateFromString(n); return i; :}
| TOPIC EQUALS TEXT.n item_body.i {: i.setTopicString(n); return i; :}
| CATEGORY EQUALS TEXT.n item_body.i {: i.setCategory(ItemCategory.createRef(n)); return i; :}
| CATEGORY EQUALS TEXT.n item_body.i {: i.setCategoryText(n); return i; :}
| PERFORMANCE EQUALS TEXT.n item_body.i {: i.setFrequencySetting(FrequencySetting.createRef(n)); return i; :}
| META_DATA EQUALS meta_data.md item_body.i {: i.setMetaData(md); return i; :}
| {: ItemPrototype result = new ItemPrototype();
......
......@@ -44,8 +44,7 @@ aspect MQTT {
}
success &= connectReceive.apply(prefix + mqttRoot.getIncomingPrefix() + suffix) &
item.connectTriggerStateUpdated("java://localhost/" + suffix, true) &
item.connectTriggerStateUpdated("mqtt://localhost/trigger/" + suffix, true) &
item.connectFoo("mqtt://localhost/foo/" + suffix, true)
item.connectTriggerStateUpdated("mqtt://localhost/trigger/" + suffix, true)
;
}
return success;
......
......@@ -9,8 +9,6 @@ receive ItemWithStringState._state ;
send Item.triggerStateUpdated(String);
send Item.Foo;
// Mappings
StringToDouble maps String s to double {:
return Double.parseDouble(s);
......
......@@ -4,7 +4,7 @@ aspect SmartHomeEntityModel {
}
public void SmartHomeEntityModel.addNewItem(Item item) {
unknownGroup().addItem(item);
getUnknownGroup().addItem(item);
}
public MetaData MetaData.add(String key, String value) {
......@@ -12,9 +12,22 @@ aspect SmartHomeEntityModel {
return this;
}
syn nta Group SmartHomeEntityModel.unknownGroup() {
return new Group().setID("Unknown");
// syn nta Group SmartHomeEntityModel.unknownGroup() {
// return new Group().setID("Unknown").setAggregationFunction(null);
// }
static final String Group.UnknownGroupName = "Unknown";
public Group SmartHomeEntityModel.getUnknownGroup() {
for (Group group : getGroupList()) {
if (group.getID().equals(Group.UnknownGroupName)) {
return group;
}
}
Group newUnknownGroup = new Group().setID(Group.UnknownGroupName).setAggregationFunction(null);
addGroup(newUnknownGroup);
return newUnknownGroup;
}
syn boolean Group.isUnknownGroup() = getID().equals(Group.UnknownGroupName);
syn nta JastAddList<DefaultChannelCategory> SmartHomeEntityModel.defaultChannelCategoryList() {
JastAddList<DefaultChannelCategory> result = new JastAddList<>();
......@@ -22,28 +35,29 @@ aspect SmartHomeEntityModel {
return result;
}
rewrite ItemPrototype {
to Item {
Item result = getItemWithCorrectType();
result.setID(this.getID());
result.setLabel(this.getLabel());
result.setMetaData(this.getMetaData());
result.setTopicString(this.getTopicString());
if (this.hasCategory()) {
result.setCategory(this.getCategory());
}
if (!result.isActivityItem()) {
String state = this.getStateAsString();
result.disableSendState();
if (state.isEmpty()) {
result.setStateToDefault();
} else {
result.setStateFromString(state);
}
result.enableSendState();
public Item Item.fillFromPrototype(ItemPrototype prototype) {
this.setID(prototype.getID());
this.setLabel(prototype.getLabel());
//if (prototype.hasMetaData()) {
this.setMetaData(prototype.getMetaData());
//} else {
// this.setMetaData(null);
//}
this.setTopicString(prototype.getTopicString());
if (!prototype.getCategoryText().isEmpty()) {
this.setCategory(ItemCategory.createRef(prototype.getCategoryText()));
}
if (!this.isActivityItem()) {
String state = prototype.getStateAsString();
this.disableSendState();
if (state.isEmpty()) {
this.setStateToDefault();
} else {
this.setStateFromString(state);
}
return result;
this.enableSendState();
}
return this;
}
// PlaceHolders
......
......@@ -29,7 +29,7 @@ rel Channel.LinkedItem* <-> Item.Channel? ;
Parameter : DescribableModelElement ::= <Type:ParameterValueType> [DefaultValue:ParameterDefaultValue] <Context:String> <Required:boolean> ;
ParameterDefaultValue ::= <Value:String> ;
abstract Item : LabelledModelElement ::= <_fetched_data:boolean> <TopicString> [MetaData] /ItemObserver/ /LastChanged/ /Foo:KeyValuePair/;
abstract Item : LabelledModelElement ::= <_fetched_data:boolean> <TopicString> [MetaData] /ItemObserver/ /LastChanged/ ;
rel Item.Category? <-> ItemCategory.Items* ;
rel Item.FrequencySetting? -> FrequencySetting ;
......@@ -61,7 +61,7 @@ StringItem : ItemWithStringState ;
SwitchItem : ItemWithBooleanState ;
DefaultItem : ItemWithStringState ;
ActivityItem : ItemWithDoubleState ;
ItemPrototype : ItemWithStringState ::= ItemWithCorrectType:Item ; // only used for parsing
ItemPrototype : ItemWithStringState ::= <CategoryText> ; // only used for parsing
ItemPlaceHolder : ItemWithStringState ; // only used for parsing
TupleHSB ::= <Hue:int> <Saturation:int> <Brightness:int> ;
......@@ -81,4 +81,3 @@ abstract GroupAggregationFunction ;
SimpleGroupAggregationFunction : GroupAggregationFunction ::= <FunctionName:SimpleGroupAggregationFunctionName> ;
ParameterizedGroupAggregationFunction : GroupAggregationFunction ::= <FunctionName:ParameterizedGroupAggregationFunctionName>
<Param1:String> <Param2:String> ;
......@@ -174,7 +174,7 @@ public class ParserUtils {
* @param danglingItems A list of items to add to the new group
*/
public static void addToUnknownGroup(SmartHomeEntityModel model, Collection<Item> danglingItems) {
Group unknownGroup = model.unknownGroup();
Group unknownGroup = model.getUnknownGroup();
danglingItems.forEach(unknownGroup::addItem);
logger.info("Updated unknown group {}", unknownGroup.prettyPrint().trim());
}
......
package de.tudresden.inf.st.eraser;
import de.tudresden.inf.st.eraser.jastadd.model.ColorItem;
import de.tudresden.inf.st.eraser.jastadd.model.Group;
import de.tudresden.inf.st.eraser.jastadd.model.ItemPlaceHolder;
import de.tudresden.inf.st.eraser.jastadd.model.Root;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* Some special corner case with enabled incremental evaluation.
*
* @author rschoene - Initial contribution
*/
public class IncrementalTests {
@Test
public void unknownGroupPrettyPrint() {
Root root = Root.createEmptyRoot();
String output = root.getSmartHomeEntityModel().getUnknownGroup().prettyPrint();
assertNotNull(output);
}
@Test
public void newGroupPrettyPrint() {
String output = new Group().setID("group2").setAggregationFunction(null).prettyPrint();
assertNotNull(output);
}
@Test
public void itemPlaceHolderPrettyPrint() {
ItemPlaceHolder placeholder = new ItemPlaceHolder().setID("placeholder");
placeholder.setMetaData(null);
String output = placeholder.prettyPrint();
assertNotNull(output);
}
@Test
public void colorItemPrettyPrint() {
ColorItem item = new ColorItem().setID("colored");
item.setStateFromString("100,100,100");
item.setMetaData(null);
String output = item.prettyPrint();
assertNotNull(output);
}
}
result=OUTPUT_PASS
Group: id="g" items=["datetime1", "default1"] ;
DateTime Item : id="datetime1" label="a DateTime Item" state="1543415826";
Item : id="default1" label="a Default Item";
DateTime Item: id="datetime1" label="a DateTime Item" state="1970-01-18T20:43:35.826Z" ;
Item: id="default1" label="a Default Item" state="" ;
Group: id="g" items=["datetime1", "default1"] ;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment