Search in sources :

Example 1 with ElementReadEventMessage

use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.access.ElementReadEventMessage in project FAAAST-Service by FraunhoferIOSB.

the class RequestHandler method publishElementReadEventMessage.

/**
 * Publish a ElementReadEventMessage to the message bus
 *
 * @param reference of the element
 * @param referable the instance
 */
public void publishElementReadEventMessage(Reference reference, Referable referable) {
    ElementReadEventMessage eventMessage = new ElementReadEventMessage();
    eventMessage.setElement(reference);
    eventMessage.setValue(referable);
    try {
        this.messageBus.publish(eventMessage);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ElementReadEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.access.ElementReadEventMessage) AssetConnectionException(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Example 2 with ElementReadEventMessage

use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.access.ElementReadEventMessage in project FAAAST-Service by FraunhoferIOSB.

the class Util method setUpEventCheck.

public static void setUpEventCheck(Referable expected, Class<? extends EventMessage> clazz, Supplier<?> call) {
    AtomicBoolean fired = new AtomicBoolean(false);
    SubscriptionId subscriptionId = IntegrationTestHttpEndpoint.messageBus.subscribe(SubscriptionInfo.create(clazz, x -> {
        if (ElementReadEventMessage.class.isAssignableFrom(x.getClass())) {
            Assert.assertEquals(expected, ((ElementReadEventMessage) x).getValue());
            fired.set(true);
        }
        if (ElementCreateEventMessage.class.isAssignableFrom(x.getClass())) {
            Assert.assertEquals(expected, ((ElementCreateEventMessage) x).getValue());
            fired.set(true);
        }
        if (ElementUpdateEventMessage.class.isAssignableFrom(x.getClass())) {
            Assert.assertEquals(expected, ((ElementUpdateEventMessage) x).getValue());
            fired.set(true);
        }
        if (ElementDeleteEventMessage.class.isAssignableFrom(x.getClass())) {
            Assert.assertEquals(expected, ((ElementDeleteEventMessage) x).getValue());
            fired.set(true);
        }
    }));
    call.get();
    Assert.assertTrue(fired.get());
    IntegrationTestHttpEndpoint.messageBus.unsubscribe(subscriptionId);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) ElementReadEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.access.ElementReadEventMessage) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) Supplier(java.util.function.Supplier) EntityUtils(org.apache.http.util.EntityUtils) HttpDelete(org.apache.http.client.methods.HttpDelete) SubscriptionInfo(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionInfo) Referable(io.adminshell.aas.v3.model.Referable) ByteArrayInputStream(java.io.ByteArrayInputStream) ElementDeleteEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage) DeserializationException(io.adminshell.aas.v3.dataformat.DeserializationException) IOException(java.io.IOException) SubscriptionId(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionId) JsonDeserializer(io.adminshell.aas.v3.dataformat.json.JsonDeserializer) JsonSerializer(io.adminshell.aas.v3.dataformat.json.JsonSerializer) ElementCreateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage) StandardCharsets(java.nio.charset.StandardCharsets) EventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.EventMessage) List(java.util.List) HttpPut(org.apache.http.client.methods.HttpPut) HttpGet(org.apache.http.client.methods.HttpGet) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) HttpResponse(org.apache.http.HttpResponse) ElementUpdateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) Assert(org.junit.Assert) SerializationException(io.adminshell.aas.v3.dataformat.SerializationException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SubscriptionId(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionId) ElementCreateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage) ElementReadEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.access.ElementReadEventMessage) ElementDeleteEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage) ElementUpdateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage)

Aggregations

ElementReadEventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.access.ElementReadEventMessage)2 AssetConnectionException (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionException)1 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)1 EventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.EventMessage)1 SubscriptionId (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionId)1 SubscriptionInfo (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionInfo)1 ElementCreateEventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage)1 ElementDeleteEventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage)1 ElementUpdateEventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage)1 DeserializationException (io.adminshell.aas.v3.dataformat.DeserializationException)1 SerializationException (io.adminshell.aas.v3.dataformat.SerializationException)1 JsonDeserializer (io.adminshell.aas.v3.dataformat.json.JsonDeserializer)1 JsonSerializer (io.adminshell.aas.v3.dataformat.json.JsonSerializer)1 Referable (io.adminshell.aas.v3.model.Referable)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Supplier (java.util.function.Supplier)1