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

Proper naming.

parent aa9bb283
No related branches found
No related tags found
1 merge request!5Proper naming.
Pipeline #4206 passed
Showing
with 72 additions and 72 deletions
...@@ -22,7 +22,7 @@ aspect MachineLearning { ...@@ -22,7 +22,7 @@ aspect MachineLearning {
//--- currentActivity --- //--- currentActivity ---
syn java.util.Optional<Activity> Root.currentActivity() { syn java.util.Optional<Activity> Root.currentActivity() {
return resolveActivity((int) getOpenHAB2Model().getActivityItem().getState()); return resolveActivity((int) getSmartHomeEntityModel().getActivityItem().getState());
} }
private int Root.extractActivityIdentifier(List<ItemPreference> preferences) { private int Root.extractActivityIdentifier(List<ItemPreference> preferences) {
if (preferences.isEmpty()) { if (preferences.isEmpty()) {
...@@ -72,7 +72,7 @@ aspect MachineLearning { ...@@ -72,7 +72,7 @@ aspect MachineLearning {
public void DummyMachineLearningModel.connectItems(List<String> itemNames) { public void DummyMachineLearningModel.connectItems(List<String> itemNames) {
logger.info("Storing items to connect"); logger.info("Storing items to connect");
for (String itemName : itemNames) { for (String itemName : itemNames) {
JavaUtils.ifPresentOrElse(getRoot().getOpenHAB2Model().resolveItem(itemName), JavaUtils.ifPresentOrElse(getRoot().getSmartHomeEntityModel().resolveItem(itemName),
this::addItem, this::addItem,
() -> logger.warn("Could not resolve item '{}'", itemName)); () -> logger.warn("Could not resolve item '{}'", itemName));
} }
......
aspect ModelStatistics { aspect ModelStatistics {
//--- numChannels --- //--- numChannels ---
syn int OpenHAB2Model.numChannels() { syn int SmartHomeEntityModel.numChannels() {
int sum = 0; int sum = 0;
for (Thing thing : getThingList()) { for (Thing thing : getThingList()) {
sum += thing.getNumChannel(); sum += thing.getNumChannel();
...@@ -10,7 +10,7 @@ aspect ModelStatistics { ...@@ -10,7 +10,7 @@ aspect ModelStatistics {
} }
//--- description --- //--- description ---
syn String OpenHAB2Model.description() = "[" syn String SmartHomeEntityModel.description() = "["
+ this.getNumThingType() + " thing type(s), " + this.getNumThingType() + " thing type(s), "
+ this.getNumChannelType() + " channel type(s), " + this.getNumChannelType() + " channel type(s), "
+ this.numChannels() + " channel(s), " + this.numChannels() + " channel(s), "
......
aspect Navigation { aspect Navigation {
syn Comparator<ModelElement> OpenHAB2Model.modelElementComparator() { syn Comparator<ModelElement> SmartHomeEntityModel.modelElementComparator() {
return (e1, e2) -> (e1.getID().compareTo(e2.getID())); return (e1, e2) -> (e1.getID().compareTo(e2.getID()));
} }
//--- items --- //--- items ---
syn java.util.List<Item> OpenHAB2Model.items() { syn java.util.List<Item> SmartHomeEntityModel.items() {
java.util.List<Item> result = new java.util.ArrayList<>(); java.util.List<Item> result = new java.util.ArrayList<>();
addItems(result, getGroupList()); addItems(result, getGroupList());
return result; return result;
} }
private void OpenHAB2Model.addItems(java.util.List<Item> result, JastAddList<Group> groups) { private void SmartHomeEntityModel.addItems(java.util.List<Item> result, JastAddList<Group> groups) {
groups.forEach(group -> group.getItemList().forEach(item -> result.add(item))); groups.forEach(group -> group.getItemList().forEach(item -> result.add(item)));
} }
//--- parameters --- //--- parameters ---
syn java.util.Set<Parameter> OpenHAB2Model.parameters() { syn java.util.Set<Parameter> SmartHomeEntityModel.parameters() {
java.util.Set<Parameter> result = new java.util.TreeSet<>(modelElementComparator()); java.util.Set<Parameter> result = new java.util.TreeSet<>(modelElementComparator());
getThingTypeList().forEach(tt -> tt.getParameterList().forEach(parameter -> result.add(parameter))); getThingTypeList().forEach(tt -> tt.getParameterList().forEach(parameter -> result.add(parameter)));
return result; return result;
} }
//--- channels --- //--- channels ---
syn java.util.Set<Channel> OpenHAB2Model.channels() { syn java.util.Set<Channel> SmartHomeEntityModel.channels() {
java.util.Set<Channel> result = new java.util.TreeSet<>(modelElementComparator()); java.util.Set<Channel> result = new java.util.TreeSet<>(modelElementComparator());
getThingList().forEach(thing -> thing.getChannelList().forEach(channel -> result.add(channel))); getThingList().forEach(thing -> thing.getChannelList().forEach(channel -> result.add(channel)));
return result; return result;
} }
//--- resolveThingType --- //--- resolveThingType ---
syn java.util.Optional<ThingType> OpenHAB2Model.resolveThingType(String thingTypeId) { syn java.util.Optional<ThingType> SmartHomeEntityModel.resolveThingType(String thingTypeId) {
for (ThingType thingType : this.getThingTypeList()) { for (ThingType thingType : this.getThingTypeList()) {
if (thingType.getID().equals(thingTypeId)) { if (thingType.getID().equals(thingTypeId)) {
return java.util.Optional.of(thingType); return java.util.Optional.of(thingType);
...@@ -40,7 +40,7 @@ aspect Navigation { ...@@ -40,7 +40,7 @@ aspect Navigation {
} }
//--- resolveChannel --- //--- resolveChannel ---
syn java.util.Optional<Channel> OpenHAB2Model.resolveChannel(String channelId) { syn java.util.Optional<Channel> SmartHomeEntityModel.resolveChannel(String channelId) {
for (Thing thing : this.getThingList()) { for (Thing thing : this.getThingList()) {
for (Channel channel : thing.getChannelList()) { for (Channel channel : thing.getChannelList()) {
if (channel.getID().equals(channelId)) { if (channel.getID().equals(channelId)) {
...@@ -52,7 +52,7 @@ aspect Navigation { ...@@ -52,7 +52,7 @@ aspect Navigation {
} }
//--- resolveChannelType --- //--- resolveChannelType ---
syn java.util.Optional<ChannelType> OpenHAB2Model.resolveChannelType(String channelTypeId) { syn java.util.Optional<ChannelType> SmartHomeEntityModel.resolveChannelType(String channelTypeId) {
for (ChannelType channelType : this.getChannelTypeList()) { for (ChannelType channelType : this.getChannelTypeList()) {
if (channelType.getID().equals(channelTypeId)) { if (channelType.getID().equals(channelTypeId)) {
return java.util.Optional.of(channelType); return java.util.Optional.of(channelType);
...@@ -62,7 +62,7 @@ aspect Navigation { ...@@ -62,7 +62,7 @@ aspect Navigation {
} }
//--- resolveItem --- //--- resolveItem ---
syn java.util.Optional<Item> OpenHAB2Model.resolveItem(String itemId) { syn java.util.Optional<Item> SmartHomeEntityModel.resolveItem(String itemId) {
if ("activity".equals(itemId)) { if ("activity".equals(itemId)) {
return Optional.of(getActivityItem()); return Optional.of(getActivityItem());
} }
...@@ -75,7 +75,7 @@ aspect Navigation { ...@@ -75,7 +75,7 @@ aspect Navigation {
} }
//--- resolveGroup --- //--- resolveGroup ---
syn java.util.Optional<Group> OpenHAB2Model.resolveGroup(String groupId) { syn java.util.Optional<Group> SmartHomeEntityModel.resolveGroup(String groupId) {
for (Group group : this.getGroupList()) { for (Group group : this.getGroupList()) {
if (group.getID().equals(groupId)) { if (group.getID().equals(groupId)) {
return java.util.Optional.of(group); return java.util.Optional.of(group);
...@@ -90,7 +90,7 @@ aspect Navigation { ...@@ -90,7 +90,7 @@ aspect Navigation {
} }
//--- resolveItemCategory --- //--- resolveItemCategory ---
syn java.util.Optional<ItemCategory> OpenHAB2Model.resolveItemCategory(String categoryName) { syn java.util.Optional<ItemCategory> SmartHomeEntityModel.resolveItemCategory(String categoryName) {
for (ItemCategory category : getItemCategoryList()) { for (ItemCategory category : getItemCategoryList()) {
if (category.getName().equals(categoryName)) { if (category.getName().equals(categoryName)) {
return java.util.Optional.of(category); return java.util.Optional.of(category);
...@@ -139,7 +139,7 @@ aspect Navigation { ...@@ -139,7 +139,7 @@ aspect Navigation {
//--- getRoot --- //--- getRoot ---
inh Root ASTNode.getRoot(); inh Root ASTNode.getRoot();
eq Root.getOpenHAB2Model().getRoot() = this; eq Root.getSmartHomeEntityModel().getRoot() = this;
eq Root.getMqttRoot().getRoot() = this; eq Root.getMqttRoot().getRoot() = this;
eq Root.getInfluxRoot().getRoot() = this; eq Root.getInfluxRoot().getRoot() = this;
eq Root.getMachineLearningRoot().getRoot() = this; eq Root.getMachineLearningRoot().getRoot() = this;
......
...@@ -100,7 +100,7 @@ aspect NeuralNetwork { ...@@ -100,7 +100,7 @@ aspect NeuralNetwork {
} }
String itemName = itemNames.get(i); String itemName = itemNames.get(i);
InputNeuron neuron = getInputNeuron(i); InputNeuron neuron = getInputNeuron(i);
JavaUtils.ifPresentOrElse(getRoot().getOpenHAB2Model().resolveItem(itemName), JavaUtils.ifPresentOrElse(getRoot().getSmartHomeEntityModel().resolveItem(itemName),
neuron::setItem, neuron::setItem,
() -> logger.warn("Could not resolve item '{}'", itemName)); () -> logger.warn("Could not resolve item '{}'", itemName));
} }
......
...@@ -5,15 +5,15 @@ aspect Printing { ...@@ -5,15 +5,15 @@ aspect Printing {
syn String Root.prettyPrint() { syn String Root.prettyPrint() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(getOpenHAB2Model().prettyPrint()); sb.append(getSmartHomeEntityModel().prettyPrint());
sb.append(getMqttRoot().prettyPrint()); sb.append(getMqttRoot().prettyPrint());
sb.append(getInfluxRoot().prettyPrint()); sb.append(getInfluxRoot().prettyPrint());
sb.append(getMachineLearningRoot().prettyPrint()); sb.append(getMachineLearningRoot().prettyPrint());
return sb.toString(); return sb.toString();
} }
//--- OpenHAB2Model.prettyPrint() --- //--- SmartHomeEntityModel.prettyPrint() ---
syn String OpenHAB2Model.prettyPrint() { syn String SmartHomeEntityModel.prettyPrint() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Thing t : getThingList()) { for (Thing t : getThingList()) {
sb.append(t.prettyPrint()); sb.append(t.prettyPrint());
......
...@@ -28,7 +28,7 @@ aspect Util { ...@@ -28,7 +28,7 @@ aspect Util {
public static Root Root.createEmptyRoot() { public static Root Root.createEmptyRoot() {
Root model = new Root(); Root model = new Root();
model.setOpenHAB2Model(new OpenHAB2Model()); model.setSmartHomeEntityModel(new SmartHomeEntityModel());
model.setMqttRoot(new MqttRoot()); model.setMqttRoot(new MqttRoot());
model.setInfluxRoot(InfluxRoot.createDefault()); model.setInfluxRoot(InfluxRoot.createDefault());
model.setMachineLearningRoot(new MachineLearningRoot()); model.setMachineLearningRoot(new MachineLearningRoot());
......
...@@ -28,12 +28,12 @@ import java.util.HashMap; ...@@ -28,12 +28,12 @@ import java.util.HashMap;
%goal logical_expression; %goal logical_expression;
Root goal = Root goal =
thing.t goal.r {: insertZero(r.getOpenHAB2Model().getThingList(), t); return r; :} thing.t goal.r {: insertZero(r.getSmartHomeEntityModel().getThingList(), t); return r; :}
| item.i goal.r {: return r; :} | item.i goal.r {: return r; :}
| group.g goal.r {: insertZero(r.getOpenHAB2Model().getGroupList(), g); return r; :} | group.g goal.r {: insertZero(r.getSmartHomeEntityModel().getGroupList(), g); return r; :}
| thing_type.tt goal.r {: insertZero(r.getOpenHAB2Model().getThingTypeList(), tt); return r; :} | thing_type.tt goal.r {: insertZero(r.getSmartHomeEntityModel().getThingTypeList(), tt); return r; :}
| parameter goal.r {: return r; :} | parameter goal.r {: return r; :}
| channel_type.ct goal.r {: insertZero(r.getOpenHAB2Model().getChannelTypeList(), ct); return r; :} | channel_type.ct goal.r {: insertZero(r.getSmartHomeEntityModel().getChannelTypeList(), ct); return r; :}
| channel.c goal.r {: return r; :} | channel.c goal.r {: return r; :}
| mqtt_root.mr goal.r {: r.setMqttRoot(mr); return r; :} | mqtt_root.mr goal.r {: r.setMqttRoot(mr); return r; :}
| influx_root.ir goal.r {: r.setInfluxRoot(ir); return r; :} | influx_root.ir goal.r {: r.setInfluxRoot(ir); return r; :}
......
// ---------------- Main ------------------------------ // ---------------- Main ------------------------------
Root ::= OpenHAB2Model User* MqttRoot InfluxRoot MachineLearningRoot Rule* Location* ; Root ::= SmartHomeEntityModel User* MqttRoot InfluxRoot MachineLearningRoot Rule* Location* ;
// ---------------- Users ------------------------------ // ---------------- Users ------------------------------
User : LabelledModelElement ; User : LabelledModelElement ;
......
...@@ -74,7 +74,7 @@ aspect MQTT { ...@@ -74,7 +74,7 @@ aspect MQTT {
getMqttRoot().getMqttSender().publish(getOutgoingTopic(), message); getMqttRoot().getMqttSender().publish(getOutgoingTopic(), message);
} }
refine OpenHAB2 public void OpenHAB2Model.addNewItem(Item item) { refine SmartHomeEntityModel public void SmartHomeEntityModel.addNewItem(Item item) {
refined(item); refined(item);
// update mqtt-topic to new mqtt-root // update mqtt-topic to new mqtt-root
JavaUtils.ifPresentOrElse( JavaUtils.ifPresentOrElse(
......
aspect OpenHAB2 { aspect SmartHomeEntityModel {
syn ActivityItem OpenHAB2Model.getActivityItem() { syn ActivityItem SmartHomeEntityModel.getActivityItem() {
return new ActivityItem(); return new ActivityItem();
} }
public void OpenHAB2Model.addNewItem(Item item) { public void SmartHomeEntityModel.addNewItem(Item item) {
JavaUtils.ifPresentOrElse( JavaUtils.ifPresentOrElse(
resolveGroup(de.tudresden.inf.st.eraser.util.ParserUtils.UNKNOWN_GROUP_NAME), resolveGroup(de.tudresden.inf.st.eraser.util.ParserUtils.UNKNOWN_GROUP_NAME),
group -> group.addItem(item), group -> group.addItem(item),
......
// ---------------- openHAB ------------------------------ // ---------------- openHAB ------------------------------
OpenHAB2Model ::= Thing* Group* ThingType* ChannelType* ChannelCategory* ItemCategory* /ActivityItem:Item/ ; SmartHomeEntityModel ::= Thing* Group* ThingType* ChannelType* ChannelCategory* ItemCategory* /ActivityItem:Item/ ;
abstract ModelElement ::= <ID:String> ; abstract ModelElement ::= <ID:String> ;
abstract LabelledModelElement : ModelElement ::= <Label:String> ; abstract LabelledModelElement : ModelElement ::= <Label:String> ;
......
...@@ -39,7 +39,7 @@ public class Main { ...@@ -39,7 +39,7 @@ public class Main {
private static void testPrinterWith(Root model) { private static void testPrinterWith(Root model) {
model.flushTreeCache(); model.flushTreeCache();
System.out.println("Got model: " + model.getOpenHAB2Model().description()); System.out.println("Got model: " + model.getSmartHomeEntityModel().description());
System.out.println("PrettyPrinted:"); System.out.println("PrettyPrinted:");
System.out.println(model.prettyPrint()); System.out.println(model.prettyPrint());
} }
...@@ -48,7 +48,7 @@ public class Main { ...@@ -48,7 +48,7 @@ public class Main {
Root model; Root model;
// model = importFromOpenHab(); // model = importFromOpenHab();
model = importFromFile(); model = importFromFile();
System.out.println("Got model: " + model.getOpenHAB2Model().description()); System.out.println("Got model: " + model.getSmartHomeEntityModel().description());
// JsonSerializer.write(model, "openhab2-data.json"); // JsonSerializer.write(model, "openhab2-data.json");
testUpdaterWith(model); testUpdaterWith(model);
} }
......
...@@ -48,17 +48,17 @@ public class ASTNodeDeserializer extends StdDeserializer<ASTNode> { ...@@ -48,17 +48,17 @@ public class ASTNodeDeserializer extends StdDeserializer<ASTNode> {
r.put(c.getName(), ((node, model) -> f.apply(model, termValue(node, terminalName)))); r.put(c.getName(), ((node, model) -> f.apply(model, termValue(node, terminalName))));
} }
private void addResolverForOpenHAB2Model(Map<String, ResolveAstNodeForOpenHAB2Model> r, Class<?> c, BiFunction<OpenHAB2Model, String, Optional<? extends ASTNode>> f, String terminalName) { private void addResolverForSmartHomeEntityModel(Map<String, ResolveAstNodeForSmartHomeEntityModel> r, Class<?> c, BiFunction<SmartHomeEntityModel, String, Optional<? extends ASTNode>> f, String terminalName) {
r.put(c.getName(), ((node, model) -> f.apply(model, termValue(node, terminalName)))); r.put(c.getName(), ((node, model) -> f.apply(model, termValue(node, terminalName))));
} }
private Map<String, ResolveAstNode> resolvers = new HashMap<>(); private Map<String, ResolveAstNode> resolvers = new HashMap<>();
private Map<String, ResolveAstNodeForOpenHAB2Model> resolversForOpenHAB2Model = new HashMap<>(); private Map<String, ResolveAstNodeForSmartHomeEntityModel> resolversForSmartHomeEntityModel = new HashMap<>();
private void initResolvers() { private void initResolvers() {
addResolverForOpenHAB2Model(resolversForOpenHAB2Model, ThingType.class, OpenHAB2Model::resolveThingType, "ID"); addResolverForSmartHomeEntityModel(resolversForSmartHomeEntityModel, ThingType.class, SmartHomeEntityModel::resolveThingType, "ID");
addResolverForOpenHAB2Model(resolversForOpenHAB2Model, ChannelType.class, OpenHAB2Model::resolveChannelType, "ID"); addResolverForSmartHomeEntityModel(resolversForSmartHomeEntityModel, ChannelType.class, SmartHomeEntityModel::resolveChannelType, "ID");
addResolverForOpenHAB2Model(resolversForOpenHAB2Model, Item.class, OpenHAB2Model::resolveItem, "ID"); addResolverForSmartHomeEntityModel(resolversForSmartHomeEntityModel, Item.class, SmartHomeEntityModel::resolveItem, "ID");
addResolver(resolvers, MqttTopic.class, Root::resolveMqttTopic, "IncomingTopic"); addResolver(resolvers, MqttTopic.class, Root::resolveMqttTopic, "IncomingTopic");
} }
...@@ -373,8 +373,8 @@ interface ResolveAstNode { ...@@ -373,8 +373,8 @@ interface ResolveAstNode {
} }
interface ResolveAstNodeForOpenHAB2Model { interface ResolveAstNodeForSmartHomeEntityModel {
Optional<? extends ASTNode> resolve(JsonNode node, OpenHAB2Model model) throws IOException; Optional<? extends ASTNode> resolve(JsonNode node, SmartHomeEntityModel model) throws IOException;
} }
class ResolveLater { class ResolveLater {
......
...@@ -42,7 +42,7 @@ public class OpenHab2Importer { ...@@ -42,7 +42,7 @@ public class OpenHab2Importer {
nonDefaultChannelCategories = new HashSet<>(); nonDefaultChannelCategories = new HashSet<>();
} }
public OpenHAB2Model importFrom(String host, int port) { public SmartHomeEntityModel importFrom(String host, int port) {
/* /*
Plan: Plan:
- requesting: thing-types, channel-types, things, items, links - requesting: thing-types, channel-types, things, items, links
...@@ -59,7 +59,7 @@ public class OpenHab2Importer { ...@@ -59,7 +59,7 @@ public class OpenHab2Importer {
try { try {
Root root = Root.createEmptyRoot(); Root root = Root.createEmptyRoot();
OpenHAB2Model model = root.getOpenHAB2Model(); SmartHomeEntityModel model = root.getSmartHomeEntityModel();
ThingTypeData[] thingTypeList = mapper.readValue(makeURL(thingTypesUrl, hostAndPort), ThingTypeData[].class); ThingTypeData[] thingTypeList = mapper.readValue(makeURL(thingTypesUrl, hostAndPort), ThingTypeData[].class);
logger.info("Read a total of {} thing type(s).", thingTypeList.length); logger.info("Read a total of {} thing type(s).", thingTypeList.length);
update(model, thingTypeList); update(model, thingTypeList);
...@@ -100,7 +100,7 @@ public class OpenHab2Importer { ...@@ -100,7 +100,7 @@ public class OpenHab2Importer {
return URI.create(String.format(formatUrlString, hostAndPort, id)).toURL(); return URI.create(String.format(formatUrlString, hostAndPort, id)).toURL();
} }
private void update(OpenHAB2Model model, ThingTypeData[] thingTypeList) { private void update(SmartHomeEntityModel model, ThingTypeData[] thingTypeList) {
for (ThingTypeData thingTypeData : thingTypeList) { for (ThingTypeData thingTypeData : thingTypeList) {
ThingType thingType = new ThingType(); ThingType thingType = new ThingType();
thingType.setID(thingTypeData.UID); thingType.setID(thingTypeData.UID);
...@@ -110,7 +110,7 @@ public class OpenHab2Importer { ...@@ -110,7 +110,7 @@ public class OpenHab2Importer {
} }
} }
private void update(OpenHAB2Model model, ChannelTypeData[] channelTypeList) { private void update(SmartHomeEntityModel model, ChannelTypeData[] channelTypeList) {
for (ChannelTypeData channelTypeData : channelTypeList) { for (ChannelTypeData channelTypeData : channelTypeList) {
ChannelType channelType = new ChannelType(); ChannelType channelType = new ChannelType();
channelType.setID(channelTypeData.UID); channelType.setID(channelTypeData.UID);
...@@ -163,7 +163,7 @@ public class OpenHab2Importer { ...@@ -163,7 +163,7 @@ public class OpenHab2Importer {
} }
} }
private void update(OpenHAB2Model model, ThingData[] thingList) { private void update(SmartHomeEntityModel model, ThingData[] thingList) {
for (ThingData thingData : thingList) { for (ThingData thingData : thingList) {
Thing thing = new Thing(); Thing thing = new Thing();
thing.setID(thingData.UID); thing.setID(thingData.UID);
...@@ -182,7 +182,7 @@ public class OpenHab2Importer { ...@@ -182,7 +182,7 @@ public class OpenHab2Importer {
} }
} }
private void update(OpenHAB2Model model, AbstractItemData[] itemList) { private void update(SmartHomeEntityModel model, AbstractItemData[] itemList) {
List<Tuple<Group, GroupItemData>> groupsWithMembers = new ArrayList<>(); List<Tuple<Group, GroupItemData>> groupsWithMembers = new ArrayList<>();
List<Tuple<Group, GroupItemData>> groupsInGroups = new ArrayList<>(); List<Tuple<Group, GroupItemData>> groupsInGroups = new ArrayList<>();
List<Tuple<Item, AbstractItemData>> itemsInGroups = new ArrayList<>(); List<Tuple<Item, AbstractItemData>> itemsInGroups = new ArrayList<>();
...@@ -299,7 +299,7 @@ public class OpenHab2Importer { ...@@ -299,7 +299,7 @@ public class OpenHab2Importer {
} }
} }
private void update(OpenHAB2Model model, LinkData[] linkList) { private void update(SmartHomeEntityModel model, LinkData[] linkList) {
for (LinkData linkData : linkList) { for (LinkData linkData : linkList) {
ifPresent(model.resolveChannel(linkData.channelUID), "Channel", linkData, ifPresent(model.resolveChannel(linkData.channelUID), "Channel", linkData,
channel -> ifPresent(model.resolveItem(linkData.itemName), "Item", linkData, channel::addLinkedItem)); channel -> ifPresent(model.resolveItem(linkData.itemName), "Item", linkData, channel::addLinkedItem));
...@@ -341,7 +341,7 @@ public class OpenHab2Importer { ...@@ -341,7 +341,7 @@ public class OpenHab2Importer {
} }
} }
public OpenHAB2Model importFrom(URL baseUrl) { public SmartHomeEntityModel importFrom(URL baseUrl) {
return importFrom(baseUrl.getHost(), return importFrom(baseUrl.getHost(),
baseUrl.getPort() == -1 ? baseUrl.getDefaultPort() : baseUrl.getPort()); baseUrl.getPort() == -1 ? baseUrl.getDefaultPort() : baseUrl.getPort());
} }
......
...@@ -80,7 +80,7 @@ public class EraserParserHelper { ...@@ -80,7 +80,7 @@ public class EraserParserHelper {
resolve(channelTypeMap, missingChannelTypeMap, Channel::setType); resolve(channelTypeMap, missingChannelTypeMap, Channel::setType);
if (itemMap == null || itemMap.isEmpty()) { if (itemMap == null || itemMap.isEmpty()) {
missingItemForDesignator.forEach((designator, itemName) -> missingItemForDesignator.forEach((designator, itemName) ->
JavaUtils.ifPresentOrElse(root.getOpenHAB2Model().resolveItem(itemName), JavaUtils.ifPresentOrElse(root.getSmartHomeEntityModel().resolveItem(itemName),
designator::setItem, designator::setItem,
() -> logger.warn("Could not resolve item {} for {}", itemName, designator))); () -> logger.warn("Could not resolve item {} for {}", itemName, designator)));
} else { } else {
...@@ -132,13 +132,13 @@ public class EraserParserHelper { ...@@ -132,13 +132,13 @@ public class EraserParserHelper {
sortedDanglingItems.add(item); sortedDanglingItems.add(item);
} }
} }
ParserUtils.createUnknownGroup(this.root.getOpenHAB2Model(), sortedDanglingItems); ParserUtils.createUnknownGroup(this.root.getSmartHomeEntityModel(), sortedDanglingItems);
} }
} }
private void createChannelCategories() { private void createChannelCategories() {
channelCategoryMap.values().stream().sorted(Comparator.comparing(this::ident)).forEach( channelCategoryMap.values().stream().sorted(Comparator.comparing(this::ident)).forEach(
cc -> root.getOpenHAB2Model().addChannelCategory(cc)); cc -> root.getSmartHomeEntityModel().addChannelCategory(cc));
channelCategoryMap.clear(); channelCategoryMap.clear();
} }
...@@ -146,7 +146,7 @@ public class EraserParserHelper { ...@@ -146,7 +146,7 @@ public class EraserParserHelper {
Map<String, ItemCategory> newCategories = new HashMap<>(); Map<String, ItemCategory> newCategories = new HashMap<>();
missingItemCategoryMap.forEach((item, category) -> missingItemCategoryMap.forEach((item, category) ->
item.setCategory(newCategories.computeIfAbsent(category, ItemCategory::new))); item.setCategory(newCategories.computeIfAbsent(category, ItemCategory::new)));
newCategories.values().forEach(node -> root.getOpenHAB2Model().addItemCategory(node)); newCategories.values().forEach(node -> root.getSmartHomeEntityModel().addItemCategory(node));
} }
private void checkUnusedElements() { private void checkUnusedElements() {
...@@ -425,25 +425,25 @@ public class EraserParserHelper { ...@@ -425,25 +425,25 @@ public class EraserParserHelper {
public Root createRoot(Thing t) { public Root createRoot(Thing t) {
Root result = createRoot(); Root result = createRoot();
result.getOpenHAB2Model().addThing(t); result.getSmartHomeEntityModel().addThing(t);
return result; return result;
} }
public Root createRoot(Group g) { public Root createRoot(Group g) {
Root result = createRoot(); Root result = createRoot();
result.getOpenHAB2Model().addGroup(g); result.getSmartHomeEntityModel().addGroup(g);
return result; return result;
} }
public Root createRoot(ThingType tt) { public Root createRoot(ThingType tt) {
Root result = createRoot(); Root result = createRoot();
result.getOpenHAB2Model().addThingType(tt); result.getSmartHomeEntityModel().addThingType(tt);
return result; return result;
} }
public Root createRoot(ChannelType ct) { public Root createRoot(ChannelType ct) {
Root result = createRoot(); Root result = createRoot();
result.getOpenHAB2Model().addChannelType(ct); result.getSmartHomeEntityModel().addChannelType(ct);
return result; return result;
} }
......
...@@ -171,7 +171,7 @@ public class ParserUtils { ...@@ -171,7 +171,7 @@ public class ParserUtils {
* @param model The model to operate on * @param model The model to operate on
* @param danglingItems A list of items to add to the new group * @param danglingItems A list of items to add to the new group
*/ */
public static void createUnknownGroup(OpenHAB2Model model, Collection<Item> danglingItems) { public static void createUnknownGroup(SmartHomeEntityModel model, Collection<Item> danglingItems) {
Group unknownGroup = new Group(); Group unknownGroup = new Group();
unknownGroup.setID(UNKNOWN_GROUP_NAME); unknownGroup.setID(UNKNOWN_GROUP_NAME);
model.addGroup(unknownGroup); model.addGroup(unknownGroup);
...@@ -243,14 +243,14 @@ public class ParserUtils { ...@@ -243,14 +243,14 @@ public class ParserUtils {
Root root = (Root) parser.parse(scanner); Root root = (Root) parser.parse(scanner);
parser.resolveReferences(); parser.resolveReferences();
reader.close(); reader.close();
int size = root.getOpenHAB2Model().items().size(); int size = root.getSmartHomeEntityModel().items().size();
if (size == 0) { if (size == 0) {
throw new IllegalArgumentException("Model does not contain any items!"); throw new IllegalArgumentException("Model does not contain any items!");
} }
if (size > 1) { if (size > 1) {
logger.warn("Model does contain {} items, ignoring all but the first.", size); logger.warn("Model does contain {} items, ignoring all but the first.", size);
} }
return root.getOpenHAB2Model().items().get(0); return root.getSmartHomeEntityModel().items().get(0);
} }
} }
...@@ -10,9 +10,9 @@ import de.tudresden.inf.st.eraser.jastadd.model.*; ...@@ -10,9 +10,9 @@ import de.tudresden.inf.st.eraser.jastadd.model.*;
public class TestUtils { public class TestUtils {
public static class ModelAndItem { public static class ModelAndItem {
public OpenHAB2Model model; public SmartHomeEntityModel model;
public NumberItem item; public NumberItem item;
static ModelAndItem of(OpenHAB2Model model, NumberItem item) { static ModelAndItem of(SmartHomeEntityModel model, NumberItem item) {
ModelAndItem result = new ModelAndItem(); ModelAndItem result = new ModelAndItem();
result.model = model; result.model = model;
result.item = item; result.item = item;
...@@ -27,19 +27,19 @@ public class TestUtils { ...@@ -27,19 +27,19 @@ public class TestUtils {
public static ModelAndItem createModelAndItem(double initialValue, boolean useUpdatingItem) { public static ModelAndItem createModelAndItem(double initialValue, boolean useUpdatingItem) {
Root root = Root.createEmptyRoot(); Root root = Root.createEmptyRoot();
Group g = new Group(); Group g = new Group();
root.getOpenHAB2Model().addGroup(g); root.getSmartHomeEntityModel().addGroup(g);
g.setID("group1"); g.setID("group1");
NumberItem item = addItemTo(g, initialValue, useUpdatingItem); NumberItem item = addItemTo(g, initialValue, useUpdatingItem);
return ModelAndItem.of(root.getOpenHAB2Model(), item); return ModelAndItem.of(root.getSmartHomeEntityModel(), item);
} }
public static NumberItem addItemTo(OpenHAB2Model model, double initialValue) { public static NumberItem addItemTo(SmartHomeEntityModel model, double initialValue) {
return addItemTo(model, initialValue, false); return addItemTo(model, initialValue, false);
} }
public static NumberItem addItemTo(OpenHAB2Model model, double initialValue, boolean useUpdatingItem) { public static NumberItem addItemTo(SmartHomeEntityModel model, double initialValue, boolean useUpdatingItem) {
return addItemTo(getDefaultGroup(model), initialValue, useUpdatingItem); return addItemTo(getDefaultGroup(model), initialValue, useUpdatingItem);
} }
...@@ -56,7 +56,7 @@ public class TestUtils { ...@@ -56,7 +56,7 @@ public class TestUtils {
return item; return item;
} }
public static Group getDefaultGroup(OpenHAB2Model model) { public static Group getDefaultGroup(SmartHomeEntityModel model) {
// use first found group // use first found group
return model.getGroup(0); return model.getGroup(0);
} }
......
...@@ -58,7 +58,7 @@ public class ControllingItemTest { ...@@ -58,7 +58,7 @@ public class ControllingItemTest {
@Test @Test
public void testManyToOneColor() { public void testManyToOneColor() {
ModelAndItem mai = TestUtils.createModelAndItem(0); ModelAndItem mai = TestUtils.createModelAndItem(0);
OpenHAB2Model model = mai.model; SmartHomeEntityModel model = mai.model;
NumberItem numberItem = mai.item; NumberItem numberItem = mai.item;
Group g = TestUtils.getDefaultGroup(model); Group g = TestUtils.getDefaultGroup(model);
......
...@@ -163,7 +163,7 @@ public class MqttTests { ...@@ -163,7 +163,7 @@ public class MqttTests {
private ModelItemAndTwoTopics createAB() { private ModelItemAndTwoTopics createAB() {
TestUtils.ModelAndItem mai = TestUtils.createModelAndItem(0, true); TestUtils.ModelAndItem mai = TestUtils.createModelAndItem(0, true);
OpenHAB2Model model = mai.model; SmartHomeEntityModel model = mai.model;
MqttRoot mqttRoot = new MqttRoot(); MqttRoot mqttRoot = new MqttRoot();
mqttRoot.setIncomingPrefix("inc"); mqttRoot.setIncomingPrefix("inc");
mqttRoot.setOutgoingPrefix(outgoingPrefix); mqttRoot.setOutgoingPrefix(outgoingPrefix);
...@@ -183,11 +183,11 @@ public class MqttTests { ...@@ -183,11 +183,11 @@ public class MqttTests {
} }
static class ModelItemAndTwoTopics { static class ModelItemAndTwoTopics {
OpenHAB2Model model; SmartHomeEntityModel model;
NumberItem item; NumberItem item;
MqttTopic firstTopic; MqttTopic firstTopic;
MqttTopic secondTopic; MqttTopic secondTopic;
static ModelItemAndTwoTopics of(OpenHAB2Model model, NumberItem item, MqttTopic firstTopic, MqttTopic secondTopic) { static ModelItemAndTwoTopics of(SmartHomeEntityModel model, NumberItem item, MqttTopic firstTopic, MqttTopic secondTopic) {
ModelItemAndTwoTopics result = new ModelItemAndTwoTopics(); ModelItemAndTwoTopics result = new ModelItemAndTwoTopics();
result.model = model; result.model = model;
result.item = item; result.item = item;
......
package de.tudresden.inf.st.eraser; package de.tudresden.inf.st.eraser;
import de.tudresden.inf.st.eraser.jastadd.model.OpenHAB2Model; import de.tudresden.inf.st.eraser.jastadd.model.SmartHomeEntityModel;
import de.tudresden.inf.st.eraser.jastadd.model.Root; import de.tudresden.inf.st.eraser.jastadd.model.Root;
import de.tudresden.inf.st.eraser.jastadd_test.core.*; import de.tudresden.inf.st.eraser.jastadd_test.core.*;
import de.tudresden.inf.st.eraser.openhab2.OpenHab2Importer; import de.tudresden.inf.st.eraser.openhab2.OpenHab2Importer;
...@@ -71,7 +71,7 @@ public class OpenHabImporterTest { ...@@ -71,7 +71,7 @@ public class OpenHabImporterTest {
// call the modified importer, with the static host name, and an arbitrary chosen port // call the modified importer, with the static host name, and an arbitrary chosen port
// port will not be used during the test // port will not be used during the test
OpenHAB2Model model = importer.importFrom(HOST, 80); SmartHomeEntityModel model = importer.importFrom(HOST, 80);
if (model == null) { if (model == null) {
if (expected == Result.PARSE_FAILED) return; if (expected == Result.PARSE_FAILED) return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment