Search in sources :

Example 1 with ServerAsset

use of org.openremote.manager.asset.ServerAsset in project openremote by openremote.

the class AgentResourceImpl method persistAssets.

protected void persistAssets(Asset[] assets, Asset parentAsset, String realmId) {
    if (assets == null || assets.length == 0) {
        LOG.info("No assets to import");
        return;
    }
    for (int i = 0; i < assets.length; i++) {
        Asset asset = assets[i];
        asset.setId(null);
        asset.setParent(parentAsset);
        asset.setRealmId(realmId);
        ServerAsset serverAsset = ServerAsset.map(asset, new ServerAsset());
        assets[i] = assetStorageService.merge(serverAsset);
    }
}
Also used : ServerAsset(org.openremote.manager.asset.ServerAsset) ServerAsset(org.openremote.manager.asset.ServerAsset) Asset(org.openremote.model.asset.Asset)

Example 2 with ServerAsset

use of org.openremote.manager.asset.ServerAsset in project openremote by openremote.

the class UsersFacade method query.

@Override
public Users.RestrictedQuery query() {
    Users.RestrictedQuery query = new Users.RestrictedQuery() {

        @Override
        public Users.RestrictedQuery tenant(UserQuery.TenantPredicate tenantPredicate) {
            if (GlobalRuleset.class.isAssignableFrom(rulesEngineId.getScope()))
                return super.tenant(tenantPredicate);
            throw new IllegalArgumentException("Overriding query restriction is not allowed in this rules scope");
        }

        @Override
        public Users.RestrictedQuery asset(UserQuery.AssetPredicate assetPredicate) {
            if (GlobalRuleset.class.isAssignableFrom(rulesEngineId.getScope()))
                return super.asset(assetPredicate);
            if (TenantRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
                return super.asset(assetPredicate);
            // TODO: should only be allowed if asset belongs to tenant
            }
            if (AssetRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
                return super.asset(assetPredicate);
            // TODO: should only be allowed if restricted asset is descendant of scope's asset
            }
            throw new IllegalArgumentException("Overriding query restriction is not allowed in this rules scope");
        }

        @Override
        public List<String> getResults() {
            return notificationService.findAllUsersWithToken(this);
        }

        @Override
        public void applyResults(Consumer<List<String>> usersIdListConsumer) {
            usersIdListConsumer.accept(getResults());
        }
    };
    if (TenantRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
        query.tenantPredicate = new UserQuery.TenantPredicate(rulesEngineId.getRealmId().orElseThrow(() -> new IllegalArgumentException("Realm ID missing: " + rulesEngineId)));
    }
    if (AssetRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
        String assetId = rulesEngineId.getAssetId().orElseThrow(() -> new IllegalStateException("Asset ID missing: " + rulesEngineId));
        ServerAsset restrictedAsset = assetStorageService.find(assetId, true);
        if (restrictedAsset == null) {
            // deployment is removed and the problem resolved.
            throw new IllegalStateException("Asset is no longer available: " + rulesEngineId);
        }
        query.assetPredicate = new UserQuery.AssetPredicate(assetId);
    }
    return query;
}
Also used : ServerAsset(org.openremote.manager.asset.ServerAsset) Consumer(java.util.function.Consumer) UserQuery(org.openremote.model.user.UserQuery)

Example 3 with ServerAsset

use of org.openremote.manager.asset.ServerAsset in project openremote by openremote.

the class AbstractManagerSetup method createDemoApartmentRoom.

protected ServerAsset createDemoApartmentRoom(ServerAsset apartment, String name) {
    ServerAsset room = new ServerAsset(name, ROOM, apartment);
    room.setLocation(apartment.getLocation());
    return room;
}
Also used : ServerAsset(org.openremote.manager.asset.ServerAsset)

Example 4 with ServerAsset

use of org.openremote.manager.asset.ServerAsset in project openremote by openremote.

the class AbstractManagerSetup method createDemoApartment.

// ################################ Demo apartment with complex scenes ###################################
protected ServerAsset createDemoApartment(ServerAsset parent, String name) {
    ServerAsset apartment = new ServerAsset(name, RESIDENCE, parent);
    apartment.setLocation(parent.getLocation());
    apartment.setAttributes(new AssetAttribute("alarmEnabled", AttributeType.BOOLEAN).setMeta(new Meta(new MetaItem(LABEL, Values.create("Alarm enabled")), new MetaItem(DESCRIPTION, Values.create("Send notifications when presence is detected")), new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)), new MetaItem(ACCESS_RESTRICTED_WRITE, Values.create(true)), new MetaItem(RULE_STATE, Values.create(true)), new MetaItem(SHOW_ON_DASHBOARD, Values.create(true)))), new AssetAttribute("presenceDetected", AttributeType.BOOLEAN).setMeta(new Meta(new MetaItem(LABEL, Values.create("Presence detected")), new MetaItem(DESCRIPTION, Values.create("Presence detected in any room")), new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)), new MetaItem(READ_ONLY, Values.create(true)), new MetaItem(RULE_STATE, Values.create(true)), new MetaItem(STORE_DATA_POINTS, Values.create(true)), new MetaItem(SHOW_ON_DASHBOARD, Values.create(true)))), new AssetAttribute("vacationUntil", TIMESTAMP_MILLIS).setMeta(new Meta(new MetaItem(LABEL, Values.create("Vacation until")), new MetaItem(DESCRIPTION, Values.create("Vacation mode enabled until")), new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)), new MetaItem(ACCESS_RESTRICTED_WRITE, Values.create(true)), new MetaItem(RULE_STATE, Values.create(true)))), new AssetAttribute("lastExecutedScene", AttributeType.STRING).setMeta(new MetaItem(LABEL, Values.create("Last executed scene")), new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true)), new MetaItem(READ_ONLY, Values.create(true)), new MetaItem(RULE_STATE, Values.create(true)), new MetaItem(SHOW_ON_DASHBOARD, Values.create(true))));
    return apartment;
}
Also used : AssetMeta(org.openremote.model.asset.AssetMeta) ServerAsset(org.openremote.manager.asset.ServerAsset) AssetAttribute(org.openremote.model.asset.AssetAttribute)

Example 5 with ServerAsset

use of org.openremote.manager.asset.ServerAsset in project openremote by openremote.

the class ManagerDemoAgentSetup method onStart.

@Override
public void onStart() throws Exception {
    KeycloakDemoSetup keycloakDemoSetup = setupService.getTaskOfType(KeycloakDemoSetup.class);
    Tenant masterTenant = keycloakDemoSetup.masterTenant;
    masterRealmId = masterTenant.getId();
    ServerAsset agent = new ServerAsset("Demo Agent", AGENT);
    agent.setRealmId(masterRealmId);
    agent = assetStorageService.merge(agent);
    if (knx) {
        LOG.info("Enable KNX demo protocol configuration, gateway/local IP: " + knxGatewayIp + "/" + knxLocalIp);
        agent.addAttributes(initProtocolConfiguration(new AssetAttribute("knxConfig"), KNXProtocol.PROTOCOL_NAME).addMeta(new MetaItem(KNXProtocol.META_KNX_GATEWAY_IP, Values.create(knxGatewayIp)), new MetaItem(KNXProtocol.META_KNX_LOCAL_IP, Values.create(knxLocalIp))));
        ServerAsset knxDevices = new ServerAsset("KNX Devices", THING, agent, masterRealmId);
        knxDevices = assetStorageService.merge(knxDevices);
    }
    if (velbus) {
        LOG.info("Enable Velbus demo protocol configuration, COM port: " + velbusComPort);
        agent.addAttributes(initProtocolConfiguration(new AssetAttribute("velbusConfig"), VelbusSerialProtocol.PROTOCOL_NAME).addMeta(new MetaItem(VelbusSerialProtocol.META_VELBUS_SERIAL_PORT, Values.create(velbusComPort))));
        ServerAsset velbusDevices = new ServerAsset("VELBUS Devices", THING, agent, masterRealmId);
        velbusDevices = assetStorageService.merge(velbusDevices);
    }
    if (upnp) {
        LOG.info("Enable UPnP demo protocol configuration");
        ServerAsset upnpDevices = new ServerAsset("UPnP Devices", THING, agent, masterRealmId);
        upnpDevices = assetStorageService.merge(upnpDevices);
        agent.addAttributes(initProtocolConfiguration(new AssetAttribute("upnpConfig"), UpnpProtocol.PROTOCOL_NAME).addMeta(// TODO Protocols should create these grouping assets automatically and import assets underneath for each protocol configuration
        new MetaItem(UpnpProtocol.GROUP_ASSET_ID, Values.create(upnpDevices.getId()))));
    }
    agent = assetStorageService.merge(agent);
}
Also used : Tenant(org.openremote.model.security.Tenant) MetaItem(org.openremote.model.attribute.MetaItem) ServerAsset(org.openremote.manager.asset.ServerAsset) AssetAttribute(org.openremote.model.asset.AssetAttribute)

Aggregations

ServerAsset (org.openremote.manager.asset.ServerAsset)9 AssetAttribute (org.openremote.model.asset.AssetAttribute)4 Asset (org.openremote.model.asset.Asset)2 AssetMeta (org.openremote.model.asset.AssetMeta)2 Tenant (org.openremote.model.security.Tenant)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 ZonedDateTime (java.time.ZonedDateTime)1 Consumer (java.util.function.Consumer)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 PathPredicate (org.openremote.model.asset.AssetQuery.PathPredicate)1 TenantPredicate (org.openremote.model.asset.AssetQuery.TenantPredicate)1 UserAsset (org.openremote.model.asset.UserAsset)1 MetaItem (org.openremote.model.attribute.MetaItem)1 UserQuery (org.openremote.model.user.UserQuery)1