Search in sources :

Example 1 with RequestSimulatorState

use of org.openremote.model.simulator.RequestSimulatorState in project openremote by openremote.

the class SimulatorService method configure.

@Override
public void configure() throws Exception {
    from(CLIENT_EVENT_TOPIC).routeId("FromClientSimulatorRequests").filter(body().isInstanceOf(RequestSimulatorState.class)).process(exchange -> {
        RequestSimulatorState event = exchange.getIn().getBody(RequestSimulatorState.class);
        LOG.fine("Handling from client: " + event);
        String sessionKey = getSessionKey(exchange);
        AuthContext authContext = exchange.getIn().getHeader(Constants.AUTH_CONTEXT, AuthContext.class);
        // Superuser can get all
        if (!authContext.isSuperUser())
            return;
        for (AttributeRef protocolConfiguration : event.getConfigurations()) {
            publishSimulatorState(sessionKey, protocolConfiguration);
        }
    });
    from(CLIENT_EVENT_TOPIC).routeId("FromClientSimulatorState").filter(body().isInstanceOf(SimulatorState.class)).process(exchange -> {
        SimulatorState event = exchange.getIn().getBody(SimulatorState.class);
        LOG.fine("Handling from client: " + event);
        AuthContext authContext = exchange.getIn().getHeader(Constants.AUTH_CONTEXT, AuthContext.class);
        // Superuser can get all
        if (!authContext.isSuperUser())
            return;
        // TODO Should realm admins be able to work with simulators in their tenant?
        simulatorProtocol.updateSimulatorState(event);
    });
}
Also used : AttributeRef(org.openremote.model.attribute.AttributeRef) SimulatorState(org.openremote.model.simulator.SimulatorState) RequestSimulatorState(org.openremote.model.simulator.RequestSimulatorState) AuthContext(org.openremote.container.security.AuthContext) RequestSimulatorState(org.openremote.model.simulator.RequestSimulatorState)

Example 2 with RequestSimulatorState

use of org.openremote.model.simulator.RequestSimulatorState in project openremote by openremote.

the class Simulator method createSimulator.

protected void createSimulator() {
    eventRegistration = environment.getEventBus().register(SimulatorState.class, simulatorState -> {
        if (!simulatorState.getProtocolConfigurationRef().equals(protocolConfiguration))
            return;
        this.simulatorState = simulatorState;
        writeView();
    });
    environment.getEventService().dispatch(new RequestSimulatorState(protocolConfiguration));
    onCreate.run();
}
Also used : Browser(elemental.client.Browser) EventRegistration(org.openremote.model.event.bus.EventRegistration) Consumer(org.openremote.model.interop.Consumer) SimulatorState(org.openremote.model.simulator.SimulatorState) java.util(java.util) ValueType(org.openremote.model.value.ValueType) Environment(org.openremote.app.client.Environment) AttributeRef(org.openremote.model.attribute.AttributeRef) ValidationFailure(org.openremote.model.ValidationFailure) org.openremote.app.client.widget(org.openremote.app.client.widget) AttributeViewImpl(org.openremote.app.client.assets.attributes.AttributeViewImpl) RequestSimulatorState(org.openremote.model.simulator.RequestSimulatorState) ShowSuccessEvent(org.openremote.app.client.event.ShowSuccessEvent) AttributeValidationResult(org.openremote.model.attribute.AttributeValidationResult) Value(org.openremote.model.value.Value) SimulatorElement(org.openremote.model.simulator.SimulatorElement) AbstractAttributeViewExtension(org.openremote.app.client.assets.attributes.AbstractAttributeViewExtension) IsWidget(com.google.gwt.user.client.ui.IsWidget) AssetAttribute(org.openremote.model.asset.AssetAttribute) AttributeView(org.openremote.app.client.assets.attributes.AttributeView) SimulatorState(org.openremote.model.simulator.SimulatorState) RequestSimulatorState(org.openremote.model.simulator.RequestSimulatorState) RequestSimulatorState(org.openremote.model.simulator.RequestSimulatorState)

Aggregations

AttributeRef (org.openremote.model.attribute.AttributeRef)2 RequestSimulatorState (org.openremote.model.simulator.RequestSimulatorState)2 SimulatorState (org.openremote.model.simulator.SimulatorState)2 IsWidget (com.google.gwt.user.client.ui.IsWidget)1 Browser (elemental.client.Browser)1 java.util (java.util)1 Environment (org.openremote.app.client.Environment)1 AbstractAttributeViewExtension (org.openremote.app.client.assets.attributes.AbstractAttributeViewExtension)1 AttributeView (org.openremote.app.client.assets.attributes.AttributeView)1 AttributeViewImpl (org.openremote.app.client.assets.attributes.AttributeViewImpl)1 ShowSuccessEvent (org.openremote.app.client.event.ShowSuccessEvent)1 org.openremote.app.client.widget (org.openremote.app.client.widget)1 AuthContext (org.openremote.container.security.AuthContext)1 ValidationFailure (org.openremote.model.ValidationFailure)1 AssetAttribute (org.openremote.model.asset.AssetAttribute)1 AttributeValidationResult (org.openremote.model.attribute.AttributeValidationResult)1 EventRegistration (org.openremote.model.event.bus.EventRegistration)1 Consumer (org.openremote.model.interop.Consumer)1 SimulatorElement (org.openremote.model.simulator.SimulatorElement)1 Value (org.openremote.model.value.Value)1