Esempio n. 1
0
  public void activate() {
    triggerManager = new RuleTriggerManager();

    if (!isEnabled()) {
      logger.info("Rule engine is disabled.");
      return;
    }

    logger.debug("Started rule engine");

    // read all rule files
    Iterable<String> ruleModelNames = modelRepository.getAllModelNamesOfType("rules");
    ArrayList<String> clonedList = Lists.newArrayList(ruleModelNames);
    for (String ruleModelName : clonedList) {
      EObject model = modelRepository.getModel(ruleModelName);
      if (model instanceof RuleModel) {
        RuleModel ruleModel = (RuleModel) model;
        triggerManager.addRuleModel(ruleModel);
      }
    }

    // register us on all items which are already available in the registry
    for (Item item : itemRegistry.getItems()) {
      internalItemAdded(item);
    }
    runStartupRules();
  }
  private List<ItemConfigBean> getItemConfigBeanList() {
    List<ItemConfigBean> beanList = new ArrayList<ItemConfigBean>();

    ModelRepository repo = HABminApplication.getModelRepository();
    if (repo == null) return null;

    File folder = new File("configurations/items/");
    File[] listOfFiles = folder.listFiles();

    if (listOfFiles == null) return null;

    ItemModelHelper modelHelper = new ItemModelHelper();

    for (int i = 0; i < listOfFiles.length; i++) {
      if (listOfFiles[i].isFile() & listOfFiles[i].getName().endsWith(".items")) {
        ItemModel items = (ItemModel) repo.getModel(listOfFiles[i].getName());
        List<ItemConfigBean> beans =
            modelHelper.readItemModel(
                items,
                listOfFiles[i].getName().substring(0, listOfFiles[i].getName().indexOf('.')));
        if (beans != null) beanList.addAll(beans);
      }
    }

    return beanList;
  }
Esempio n. 3
0
 public static Sitemap getSitemap(String sitemapname) {
   ModelRepository repo = RESTApplication.getModelRepository();
   if (repo != null) {
     Sitemap sitemap = (Sitemap) repo.getModel(sitemapname + SITEMAP_FILEEXT);
     return sitemap;
   }
   return null;
 }
Esempio n. 4
0
 public Collection<SitemapBean> getSitemapBeans(URI uri) {
   Collection<SitemapBean> beans = new LinkedList<SitemapBean>();
   logger.debug(
       "Received HTTP GET request at '{}'.", UriBuilder.fromUri(uri).build().toASCIIString());
   ModelRepository modelRepository = RESTApplication.getModelRepository();
   for (String modelName : modelRepository.getAllModelNamesOfType("sitemap")) {
     Sitemap sitemap = (Sitemap) modelRepository.getModel(modelName);
     if (sitemap != null) {
       SitemapBean bean = new SitemapBean();
       bean.name = StringUtils.removeEnd(modelName, SITEMAP_FILEEXT);
       bean.link = UriBuilder.fromUri(uri).path(bean.name).build().toASCIIString();
       bean.homepage = new PageBean();
       bean.homepage.link = bean.link + "/" + sitemap.getName();
       beans.add(bean);
     }
   }
   return beans;
 }
Esempio n. 5
0
  public void modelChanged(String modelName, org.openhab.model.core.EventType type) {
    if (triggerManager != null) {
      if (isEnabled() && modelName.endsWith("rules")) {
        RuleModel model = (RuleModel) modelRepository.getModel(modelName);

        // remove the rules from the trigger sets
        if (type == org.openhab.model.core.EventType.REMOVED
            || type == org.openhab.model.core.EventType.MODIFIED) {
          triggerManager.removeRuleModel(model);
        }

        // add new and modified rules to the trigger sets
        if (model != null
            && (type == org.openhab.model.core.EventType.ADDED
                || type == org.openhab.model.core.EventType.MODIFIED)) {
          triggerManager.addRuleModel(model);
          // now execute all rules that are meant to trigger at startup
          runStartupRules();
        }
      }
    }
  }
Esempio n. 6
0
 public void unsetModelRepository(ModelRepository modelRepository) {
   modelRepository.removeModelRepositoryChangeListener(this);
   this.modelRepository = null;
 }
Esempio n. 7
0
 public void setModelRepository(ModelRepository modelRepository) {
   this.modelRepository = modelRepository;
   modelRepository.addModelRepositoryChangeListener(this);
 }