Search in sources :

Example 1 with Ruleset

use of org.openremote.model.rules.Ruleset in project openremote by openremote.

the class RulesDemoSetup method onStart.

@Override
public void onStart() throws Exception {
    KeycloakDemoSetup keycloakDemoSetup = setupService.getTaskOfType(KeycloakDemoSetup.class);
    ManagerDemoSetup managerDemoSetup = setupService.getTaskOfType(ManagerDemoSetup.class);
    LOG.info("Importing demo rulesets");
    // Apartment 1
    try (InputStream inputStream = RulesDemoSetup.class.getResourceAsStream("/demo/rules/DemoResidencePresenceDetection.groovy")) {
        String rules = IOUtils.toString(inputStream, Charset.forName("utf-8"));
        Ruleset ruleset = new AssetRuleset("Demo Residence - Presence Detection with motion and CO2 sensors", managerDemoSetup.apartment1Id, rules, Ruleset.Lang.GROOVY);
        apartmentActionsRulesetId = rulesetStorageService.merge(ruleset).getId();
    }
    try (InputStream inputStream = RulesDemoSetup.class.getResourceAsStream("/demo/rules/DemoResidenceVacationMode.groovy")) {
        String rules = IOUtils.toString(inputStream, Charset.forName("utf-8"));
        Ruleset ruleset = new AssetRuleset("Demo Residence - Vacation Mode", managerDemoSetup.apartment1Id, rules, Ruleset.Lang.GROOVY);
        apartmentActionsRulesetId = rulesetStorageService.merge(ruleset).getId();
    }
    try (InputStream inputStream = RulesDemoSetup.class.getResourceAsStream("/demo/rules/DemoResidenceAutoVentilation.groovy")) {
        String rules = IOUtils.toString(inputStream, Charset.forName("utf-8"));
        Ruleset ruleset = new AssetRuleset("Demo Residence - Auto Ventilation", managerDemoSetup.apartment1Id, rules, Ruleset.Lang.GROOVY);
        apartmentActionsRulesetId = rulesetStorageService.merge(ruleset).getId();
    }
    try (InputStream inputStream = RulesDemoSetup.class.getResourceAsStream("/demo/rules/DemoResidenceNotifyAlarmTrigger.groovy")) {
        String rules = IOUtils.toString(inputStream, Charset.forName("utf-8"));
        Ruleset ruleset = new AssetRuleset("Demo Residence - Notify Alarm Trigger", managerDemoSetup.apartment1Id, rules, Ruleset.Lang.GROOVY);
        apartmentActionsRulesetId = rulesetStorageService.merge(ruleset).getId();
    }
    try (InputStream inputStream = RulesDemoSetup.class.getResourceAsStream("/demo/rules/DemoResidenceSmartSwitch.groovy")) {
        String rules = IOUtils.toString(inputStream, Charset.forName("utf-8"));
        Ruleset ruleset = new AssetRuleset("Demo Residence - Smart Start Switch", managerDemoSetup.apartment1Id, rules, Ruleset.Lang.GROOVY);
        apartmentActionsRulesetId = rulesetStorageService.merge(ruleset).getId();
    }
    // Apartment 2
    try (InputStream inputStream = RulesDemoSetup.class.getResourceAsStream("/demo/rules/DemoResidenceAllLightsOff.js")) {
        String rules = IOUtils.toString(inputStream, Charset.forName("utf-8"));
        Ruleset ruleset = new AssetRuleset("Demo Residence - All Lights Off", managerDemoSetup.apartment2Id, rules, Ruleset.Lang.JAVASCRIPT);
        apartmentActionsRulesetId = rulesetStorageService.merge(ruleset).getId();
    }
}
Also used : Ruleset(org.openremote.model.rules.Ruleset) AssetRuleset(org.openremote.model.rules.AssetRuleset) AssetRuleset(org.openremote.model.rules.AssetRuleset) InputStream(java.io.InputStream)

Aggregations

InputStream (java.io.InputStream)1 AssetRuleset (org.openremote.model.rules.AssetRuleset)1 Ruleset (org.openremote.model.rules.Ruleset)1