Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions demo-setup/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
apply plugin: "java-library"
apply plugin: "maven-publish"
apply plugin: "signing"

base {
archivesName = "openremote-${project.name}"
}

dependencies {
api "io.openremote:openremote-manager:$openremoteVersion"

implementation project(":energy")
}

jar {
from sourceSets.main.allJava
}

javadoc {
failOnError = false
}

java {
withJavadocJar()
withSourcesJar()
}

publishing {
publications {
maven(MavenPublication) {
group = "io.openremote.extension"
artifactId = "openremote-${project.name}"
from components.java
pom {
name = 'OpenRemote Demo setup'
description = 'Adds the OpenRemote Demo setup'
url = 'https://github.com/openremote/extensions'
licenses {
license {
name = 'GNU Affero General Public License v3.0'
url = 'https://www.gnu.org/licenses/agpl-3.0.en.html'
}
}
developers {
developer {
id = 'developers'
name = 'Developers'
email = 'developers@openremote.io'
organization = 'OpenRemote'
organizationUrl = 'https://openremote.io'
}
}
scm {
connection = 'scm:git:git://github.com/openremote/extensions.git'
developerConnection = 'scm:git:ssh://github.com:openremote/extensions.git'
url = 'https://github.com/openremote/extensions/tree/main'
}
}
}
}

repositories {
maven {
if (!version.endsWith('-LOCAL')) {
credentials {
username = findProperty("publishUsername")
password = findProperty("publishPassword")
}
}
url = version.endsWith('-LOCAL') ? layout.buildDirectory.dir('repo') : version.endsWith('-SNAPSHOT') ? findProperty("snapshotsRepoUrl") : findProperty("releasesRepoUrl")
}
}
}

signing {
def signingKey = findProperty("signingKey")
def signingPassword = findProperty("signingPassword")
if (signingKey && signingPassword) {
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.maven
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2017, OpenRemote Inc.
*
* See the CONTRIBUTORS.txt file in the distribution for a
* full listing of individual contributors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.openremote.extension.demosetup;

import org.openremote.model.Container;
import org.openremote.model.setup.Setup;
import org.openremote.model.setup.SetupTasks;

import java.util.Arrays;
import java.util.List;

/**
* Demo setup tasks.
*/
public class DemoSetupTasks implements SetupTasks {

public static final String DEMO_SETUP_TYPE = "demo";

@Override
public List<Setup> createTasks(Container container, String setupType, boolean keycloakEnabled) {

if (DEMO_SETUP_TYPE.equals(setupType)) {
return Arrays.asList(
new KeycloakDemoSetup(container),
new ManagerDemoSetup(container),
new RulesDemoSetup(container),
new ManagerDemoAgentSetup(container),
new ManagerDemoDashboardSetup(container)
);
}

// Do nothing otherwise
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2020, OpenRemote Inc.
*
* See the CONTRIBUTORS.txt file in the distribution for a
* full listing of individual contributors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.openremote.extension.demosetup;

import org.openremote.manager.setup.AbstractKeycloakSetup;
import org.openremote.model.Constants;
import org.openremote.model.Container;
import org.openremote.model.security.ClientRole;
import org.openremote.model.security.Realm;
import org.openremote.model.security.User;

import java.util.Arrays;
import java.util.logging.Logger;

/**
* We have the following demo users:
* <ul>
* <li><code>admin</code> - The superuser in the "master" realm with all access</li>
* <li><code>smartcity</code> - (Password: smartcity) A user in the "smartcity" realm with read access</li>
* <li><code>manufacturer</code> - (Password: manufacturer) A user in the "manufacturer" realm with read access</li>
* <li><code>manufacturer - customer</code> - (Password: customer) A user in the "manufacturer" realm with restricted access to his assets</li>
*
* </ul>
*/
public class KeycloakDemoSetup extends AbstractKeycloakSetup {

private static final Logger LOG = Logger.getLogger(KeycloakDemoSetup.class.getName());

public String smartCityUserId;
public static String manufacturerUserId;
public static String customerUserId;
public Realm realmMaster;
public Realm realmCity;
public static Realm realmManufacturer;

public KeycloakDemoSetup(Container container) {
super(container);
}

@Override
public void onStart() throws Exception {
super.onStart();

// Realms
realmMaster = identityService.getIdentityProvider().getRealm(Constants.MASTER_REALM);
realmCity = createRealm("smartcity", "Smart City", true);
realmManufacturer = createRealm("manufacturer", "Manufacturer", true);
removeManageAccount("smartcity");
removeManageAccount("manufacturer");

// Don't allow demo users to write assets
ClientRole[] demoUserRoles = Arrays.stream(AbstractKeycloakSetup.REGULAR_USER_ROLES)
.filter(clientRole -> clientRole != ClientRole.WRITE_ASSETS)
.toArray(ClientRole[]::new);

// Users
User smartCityUser = createUser(realmCity.getName(), "smartcity", "smartcity", "Smart", "City", null, true, demoUserRoles);
this.smartCityUserId = smartCityUser.getId();
keycloakProvider.updateUserClientRoles(realmCity.getName(), smartCityUserId, "account"); // Remove all roles for account client
User manufacturerUser = createUser(realmManufacturer.getName(), "manufacturer", "manufacturer", "Agri", "Tech", null, true, demoUserRoles);
manufacturerUserId = manufacturerUser.getId();
keycloakProvider.updateUserClientRoles(realmManufacturer.getName(), manufacturerUserId, "account"); // Remove all roles for account client
User customerUser = createUser(realmManufacturer.getName(), "customer", "customer", "Bert", "Frederiks", null, true, demoUserRoles);
customerUserId = customerUser.getId();
keycloakProvider.updateUserClientRoles(realmManufacturer.getName(), customerUserId, "account"); // Remove all roles for account client
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright 2020, OpenRemote Inc.
*
* See the CONTRIBUTORS.txt file in the distribution for a
* full listing of individual contributors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.openremote.extension.demosetup;

import org.openremote.agent.protocol.knx.KNXAgent;
import org.openremote.agent.protocol.velbus.VelbusTCPAgent;
import org.openremote.model.util.MapAccess;
import org.openremote.manager.setup.ManagerSetup;
import org.openremote.model.Container;
import org.openremote.model.security.Realm;

import java.util.logging.Logger;

public class ManagerDemoAgentSetup extends ManagerSetup {

private static final Logger LOG = Logger.getLogger(ManagerDemoAgentSetup.class.getName());

public static final String OR_SETUP_IMPORT_DEMO_AGENT_KNX = "OR_SETUP_IMPORT_DEMO_AGENT_KNX";
public static final String OR_SETUP_IMPORT_DEMO_AGENT_KNX_GATEWAY_IP = "OR_SETUP_IMPORT_DEMO_AGENT_KNX_GATEWAY_IP";
public static final String OR_SETUP_IMPORT_DEMO_AGENT_KNX_LOCAL_IP = "OR_SETUP_IMPORT_DEMO_AGENT_KNX_LOCAL_IP";

public static final String OR_SETUP_IMPORT_DEMO_AGENT_VELBUS = "OR_SETUP_IMPORT_DEMO_AGENT_VELBUS";
public static final String OR_SETUP_IMPORT_DEMO_AGENT_VELBUS_HOST = "OR_SETUP_IMPORT_DEMO_AGENT_VELBUS_HOST";
public static final String OR_SETUP_IMPORT_DEMO_AGENT_VELBUS_PORT = "OR_SETUP_IMPORT_DEMO_AGENT_VELBUS_PORT";

public String realmMasterName;

final protected boolean knx;
final protected String knxGatewayIp;
final protected String knxLocalIp;

final protected boolean velbus;
final protected String velbusHost;
final protected Integer velbusPort;

public ManagerDemoAgentSetup(Container container) {
super(container);

this.knx = MapAccess.getBoolean(container.getConfig(), OR_SETUP_IMPORT_DEMO_AGENT_KNX, false);
this.knxGatewayIp = MapAccess.getString(container.getConfig(), OR_SETUP_IMPORT_DEMO_AGENT_KNX_GATEWAY_IP, "localhost");
this.knxLocalIp = MapAccess.getString(container.getConfig(), OR_SETUP_IMPORT_DEMO_AGENT_KNX_LOCAL_IP, "localhost");

this.velbus = MapAccess.getBoolean(container.getConfig(), OR_SETUP_IMPORT_DEMO_AGENT_VELBUS, false);
this.velbusHost = MapAccess.getString(container.getConfig(), OR_SETUP_IMPORT_DEMO_AGENT_VELBUS_HOST, "localhost");
this.velbusPort = MapAccess.getInteger(container.getConfig(), OR_SETUP_IMPORT_DEMO_AGENT_VELBUS_PORT, 6000);
}

@Override
public void onStart() throws Exception {
super.onStart();

KeycloakDemoSetup keycloakDemoSetup = setupService.getTaskOfType(KeycloakDemoSetup.class);
Realm realmMaster = keycloakDemoSetup.realmMaster;
realmMasterName = realmMaster.getName();

if (knx) {
LOG.info("Enable KNX demo agent, gateway/local IP: " + knxGatewayIp + "/" + knxLocalIp);

KNXAgent agent = new KNXAgent("Demo KNX agent")
.setRealm(realmMasterName)
.setHost(knxGatewayIp)
.setBindHost(knxLocalIp);

agent = assetStorageService.merge(agent);
}

if (velbus) {
LOG.info("Enable Velbus demo agent, host/port: " + velbusHost + "/" + velbusPort);

VelbusTCPAgent agent = new VelbusTCPAgent("Demo VELBUS agent")
.setRealm(realmMasterName)
.setHost(velbusHost)
.setPort(velbusPort);

agent = assetStorageService.merge(agent);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2024, OpenRemote Inc.
*
* See the CONTRIBUTORS.txt file in the distribution for a
* full listing of individual contributors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.openremote.extension.demosetup;

import org.openremote.manager.dashboard.DashboardStorageService;
import org.openremote.manager.setup.ManagerSetup;
import org.openremote.model.Container;
import org.openremote.model.dashboard.Dashboard;
import org.openremote.model.util.ValueUtil;

import java.io.InputStream;

public class ManagerDemoDashboardSetup extends ManagerSetup {

protected final DashboardStorageService dashboardStorageService;

public ManagerDemoDashboardSetup(Container container) {
super(container);
this.dashboardStorageService = container.getService(DashboardStorageService.class);
}

@Override
public void onStart() throws Exception {
super.onStart();

// SmartCity
try (InputStream inputStream = ManagerDemoDashboardSetup.class.getResourceAsStream("/demo/dashboards/smartcity/parking.json")) {
Dashboard dashboard = ValueUtil.JSON.readValue(inputStream, Dashboard.class);
dashboardStorageService.createNew(dashboard);
}

// Manufacturer
try (InputStream inputStream = ManagerDemoDashboardSetup.class.getResourceAsStream("/demo/dashboards/manufacturer/harvesting.json")) {
Dashboard dashboard = ValueUtil.JSON.readValue(inputStream, Dashboard.class);
dashboardStorageService.createNew(dashboard);
}

}
}
Loading
Loading