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

fix ItemPerformance resolving and attribute relevantItemPerformance

parent ee3a6325
No related branches found
No related tags found
2 merge requests!12Resolve "Cleanup parser",!11Resolve "Add processing frequency option for items"
Pipeline #9769 passed
......@@ -11,34 +11,48 @@ aspect Navigation {
return result;
}
//--- enclosingGroup ---
inh Group Group.enclosingGroup();
inh Group Item.enclosingGroup();
eq Group.getItem().enclosingGroup() = this;
eq Group.getGroup().enclosingGroup() = this;
eq SmartHomeEntityModel.getGroup().enclosingGroup() = null;
eq SmartHomeEntityModel.getActivityItem().enclosingGroup() = null;
inh ItemPerformance Item.relevantItemPerformance();
inh ItemPerformance Group.relevantItemPerformance();
eq Group.getItem(int index).relevantItemPerformance() {
Item item = getItem(index);
// first, use value defined on item itself, if any
if (item.hasItemPerformance()) {
return item.getItemPerformance();
}
// then on this group, if defined
//--- relevantItemPerformance ---
syn ItemPerformance Group.relevantItemPerformance() {
// first, use value defined on group itself, if any
if (this.hasItemPerformance()) {
return this.getItemPerformance();
}
// recursively use enclosing group and use value from there, if any
Group parent = enclosingGroup();
if (parent != null) {
return parent.relevantItemPerformance();
}
// if top-level group without ItemPerformance
return null;
}
syn ItemPerformance Item.relevantItemPerformance() {
// first, use value defined on item itself, if any
if (this.hasItemPerformance()) {
return this.getItemPerformance();
}
inh Group Group.enclosingGroup();
inh Group Item.enclosingGroup();
// use enclosing group and use value from there, if any
Group parent = enclosingGroup();
if (parent != null) {
return parent.relevantItemPerformance();
}
// if top-level item without ItemPerformance
return null;
}
//--- addItems ---
private void SmartHomeEntityModel.addItems(java.util.List<Item> result, JastAddList<Group> groups) {
groups.forEach(group -> group.getItemList().forEach(item -> result.add(item)));
}
......@@ -84,4 +98,5 @@ aspect Navigation {
eq Root.getRule().getRoot() = this;
eq Root.getUser().getRoot() = this;
eq Root.getLocation().getRoot() = this;
eq Root.getItemPerformance().getRoot() = this;
}
......@@ -98,9 +98,22 @@ aspect Resolving {
return java.util.Optional.empty();
}
syn java.util.Optional<ItemPerformance> Root.resolveItemPerformance(String performanceId) {
for (ItemPerformance performance : getItemPerformanceList()) {
if (performance.getLabel().equals(performanceId)) {
return java.util.Optional.of(performance);
}
}
return java.util.Optional.empty();
}
// implementing resolving for relations
refine RefResolverStubs eq StateSyncGroup.resolveTargetItemByToken(String id, int position) {
return getRoot().getSmartHomeEntityModel().resolveItem(id).orElseThrow(() -> new RuntimeException("Item '" + id + "' not found!"));
}
refine RefResolverStubs eq ASTNode.globallyResolveItemPerformanceByToken(String id) {
return getRoot().resolveItemPerformance(id).orElseThrow(() -> new RuntimeException("ItemPerformance '" + id + "' not found!"));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment