Search in sources :

Example 6 with PersistenceService

use of org.openremote.container.persistence.PersistenceService in project openremote by openremote.

the class RulesService method init.

@Override
public void init(Container container) throws Exception {
    executorService = container.getExecutorService();
    timerService = container.getService(TimerService.class);
    persistenceService = container.getService(PersistenceService.class);
    rulesetStorageService = container.getService(RulesetStorageService.class);
    identityService = container.getService(ManagerIdentityService.class);
    notificationService = container.getService(NotificationService.class);
    assetStorageService = container.getService(AssetStorageService.class);
    assetProcessingService = container.getService(AssetProcessingService.class);
    assetDatapointService = container.getService(AssetDatapointService.class);
    assetPredictedDatapointService = container.getService(AssetPredictedDatapointService.class);
    clientEventService = container.getService(ClientEventService.class);
    gatewayService = container.getService(GatewayService.class);
    if (initDone) {
        return;
    }
    clientEventService.addSubscriptionAuthorizer((realm, auth, subscription) -> {
        if (subscription.isEventType(RulesEngineStatusEvent.class) || subscription.isEventType(RulesetChangedEvent.class)) {
            if (auth == null) {
                return false;
            }
            if (auth.isSuperUser()) {
                return true;
            }
            // Regular user must have role
            if (!auth.hasResourceRole(ClientRole.READ_ASSETS.getValue(), auth.getClientId())) {
                return false;
            }
            boolean isRestrictedUser = identityService.getIdentityProvider().isRestrictedUser(auth);
            return !isRestrictedUser;
        }
        return false;
    });
    ServiceLoader.load(GeofenceAssetAdapter.class).forEach(geofenceAssetAdapter -> {
        LOG.fine("Adding GeofenceAssetAdapter: " + geofenceAssetAdapter.getClass().getName());
        geofenceAssetAdapters.add(geofenceAssetAdapter);
    });
    geofenceAssetAdapters.addAll(container.getServices(GeofenceAssetAdapter.class));
    geofenceAssetAdapters.sort(Comparator.comparingInt(GeofenceAssetAdapter::getPriority));
    container.getService(MessageBrokerService.class).getContext().addRoutes(this);
    configEventExpires = getString(container.getConfig(), RULE_EVENT_EXPIRES, RULE_EVENT_EXPIRES_DEFAULT);
    container.getService(ManagerWebService.class).addApiSingleton(new FlowResourceImpl(container.getService(TimerService.class), container.getService(ManagerIdentityService.class)));
    initDone = true;
}
Also used : AssetStorageService(org.openremote.manager.asset.AssetStorageService) AssetPredictedDatapointService(org.openremote.manager.datapoint.AssetPredictedDatapointService) AssetProcessingService(org.openremote.manager.asset.AssetProcessingService) GeofenceAssetAdapter(org.openremote.manager.rules.geofence.GeofenceAssetAdapter) NotificationService(org.openremote.manager.notification.NotificationService) TimerService(org.openremote.container.timer.TimerService) GatewayService(org.openremote.manager.gateway.GatewayService) PersistenceService(org.openremote.container.persistence.PersistenceService) ManagerIdentityService(org.openremote.manager.security.ManagerIdentityService) AssetDatapointService(org.openremote.manager.datapoint.AssetDatapointService) ManagerWebService(org.openremote.manager.web.ManagerWebService) ClientEventService(org.openremote.manager.event.ClientEventService) FlowResourceImpl(org.openremote.manager.rules.flow.FlowResourceImpl)

Aggregations

PersistenceService (org.openremote.container.persistence.PersistenceService)6 TimerService (org.openremote.container.timer.TimerService)4 ClientEventService (org.openremote.manager.event.ClientEventService)4 ManagerIdentityService (org.openremote.manager.security.ManagerIdentityService)4 ManagerWebService (org.openremote.manager.web.ManagerWebService)4 AssetStorageService (org.openremote.manager.asset.AssetStorageService)2 AssetDatapointService (org.openremote.manager.datapoint.AssetDatapointService)2 GatewayService (org.openremote.manager.gateway.GatewayService)2 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 TypedQuery (javax.persistence.TypedQuery)1 MessageBrokerService (org.openremote.container.message.MessageBrokerService)1 AuthContext (org.openremote.container.security.AuthContext)1 IdentityProvider (org.openremote.container.security.IdentityProvider)1 AgentService (org.openremote.manager.agent.AgentService)1 AssetProcessingService (org.openremote.manager.asset.AssetProcessingService)1 AssetStorageService.buildMatchFilter (org.openremote.manager.asset.AssetStorageService.buildMatchFilter)1 ConsoleResourceImpl (org.openremote.manager.asset.console.ConsoleResourceImpl)1 AssetPredictedDatapointService (org.openremote.manager.datapoint.AssetPredictedDatapointService)1