Search in sources :

Example 1 with ElementCreateEventMessage

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

the class RequestHandler method publishElementCreateEventMessage.

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

Example 2 with ElementCreateEventMessage

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

the class OpcUaEndpointTest method testAddProperty.

/**
 * Test method for adding a new property to an existing submodel.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws Exception If the operation fails
 */
@Test
public void testAddProperty() throws SecureIdentityException, IOException, ServiceException, Exception {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("testAddProperty: client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    String propName = "NewProperty99";
    // make sure the element doesn't exist yet
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.SUBMODEL_TECH_DATA_NODE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, propName)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testAddProperty Browse Result Null", bpres);
    Assert.assertTrue("testAddProperty Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testAddProperty Browse Result Bad", bpres[0].getStatusCode().isBad());
    // Send event to MessageBus
    ElementCreateEventMessage msg = new ElementCreateEventMessage();
    msg.setElement(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value("http://i40.customer.com/type/1/1/7A7104BDAB57E184").build()).build());
    msg.setValue(new DefaultProperty.Builder().kind(ModelingKind.INSTANCE).idShort(propName).category("Variable").value("AZF45").valueType("string").build());
    service.getMessageBus().publish(msg);
    Thread.sleep(DEFAULT_TIMEOUT);
    // check that the element is there now
    bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testAddProperty Browse Result Null", bpres);
    Assert.assertTrue("testAddProperty Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testAddProperty Browse Result Good", bpres[0].getStatusCode().isGood());
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) UaClient(com.prosysopc.ua.client.UaClient) ElementCreateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) Test(org.junit.Test)

Example 3 with ElementCreateEventMessage

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

the class OpcUaEndpointFullTest method testAddProperty.

/**
 * Test method for adding a new property to an existing SubmodelElementCollection.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws Exception If the operation fails
 */
@Test
public void testAddProperty() throws SecureIdentityException, IOException, ServiceException, Exception {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("testAddProperty: client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    String propName = "NewProperty789";
    // make sure the element doesn't exist yet
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SUBMODEL_3_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SM_ELEM_COLL_O_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, propName)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testAddProperty Browse Result Null", bpres);
    Assert.assertTrue("testAddProperty Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testAddProperty Browse Result Bad", bpres[0].getStatusCode().isBad());
    // Send event to MessageBus
    ElementCreateEventMessage msg = new ElementCreateEventMessage();
    msg.setElement(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value("https://acplt.org/Test_Submodel3").build()).key(new DefaultKey.Builder().idType(KeyType.ID_SHORT).type(KeyElements.SUBMODEL_ELEMENT_COLLECTION).value(TestDefines.FULL_SM_ELEM_COLL_O_NAME).build()).build());
    msg.setValue(new DefaultProperty.Builder().kind(ModelingKind.INSTANCE).idShort(propName).category("Variable").value("3465").valueType("int").build());
    service.getMessageBus().publish(msg);
    Thread.sleep(DEFAULT_TIMEOUT);
    // check that the element is there now
    bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testAddProperty Browse Result Null", bpres);
    Assert.assertTrue("testAddProperty Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testAddProperty Browse Result Good", bpres[0].getStatusCode().isGood());
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) UaClient(com.prosysopc.ua.client.UaClient) ElementCreateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) Test(org.junit.Test)

Example 4 with ElementCreateEventMessage

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

the class OpcUaEndpointTest method testAddSubmodel.

/**
 * Test method for adding a complete submodel to an AAS.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws Exception If the operation fails
 */
@Test
public void testAddSubmodel() throws SecureIdentityException, IOException, ServiceException, Exception {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("testAddProperty: client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    String submodelName = "NewSubmodelTest1";
    // make sure the element doesn't exist yet
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, submodelName)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_REL_ELEMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, AASRelationshipElementType.SECOND)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.KEYS_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testAddSubmodel Browse Result Null", bpres);
    Assert.assertTrue("testAddSubmodel Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testAddSubmodel Browse Result Bad", bpres[0].getStatusCode().isBad());
    // Send event to MessageBus
    ElementCreateEventMessage msg = new ElementCreateEventMessage();
    msg.setElement(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.ASSET_ADMINISTRATION_SHELL).value("http://customer.com/aas/9175_7013_7091_9168").build()).build());
    msg.setValue(new DefaultSubmodel.Builder().idShort(submodelName).identification(new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier("https://acplt.org/NewSubmodelTest1").build()).administration(new DefaultAdministrativeInformation.Builder().version("0.9").revision("0").build()).kind(ModelingKind.INSTANCE).submodelElement(new DefaultRelationshipElement.Builder().idShort("ExampleRelationshipElement").category("Parameter").description(new LangString("Example RelationshipElement object", "en-us")).description(new LangString("Beispiel RelationshipElement Element", "de")).semanticId(new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.GLOBAL_REFERENCE).value("http://acplt.org/RelationshipElements/ExampleRelationshipElement").idType(KeyType.IRI).build()).build()).first(new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.SUBMODEL).value("https://acplt.org/Test_Submodel").idType(KeyType.IRI).build()).key(new DefaultKey.Builder().type(KeyElements.SUBMODEL_ELEMENT_COLLECTION).value("ExampleSubmodelCollectionOrdered").idType(KeyType.ID_SHORT).build()).key(new DefaultKey.Builder().type(KeyElements.PROPERTY).value("ExampleProperty").idType(KeyType.ID_SHORT).build()).build()).second(new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.SUBMODEL).value("http://acplt.org/Submodels/Assets/TestAsset/BillOfMaterial").idType(KeyType.IRI).build()).key(new DefaultKey.Builder().type(KeyElements.ENTITY).value("ExampleEntity").idType(KeyType.ID_SHORT).build()).key(new DefaultKey.Builder().type(KeyElements.PROPERTY).value("ExampleProperty2").idType(KeyType.ID_SHORT).build()).build()).build()).build());
    service.getMessageBus().publish(msg);
    Thread.sleep(DEFAULT_TIMEOUT);
    // check that the element is there now
    bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testAddSubmodel Browse Result Null", bpres);
    Assert.assertTrue("testAddSubmodel Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testAddSubmodel Browse Result Good", bpres[0].getStatusCode().isGood());
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) LangString(io.adminshell.aas.v3.model.LangString) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) DefaultRelationshipElement(io.adminshell.aas.v3.model.impl.DefaultRelationshipElement) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) UaClient(com.prosysopc.ua.client.UaClient) DefaultSubmodel(io.adminshell.aas.v3.model.impl.DefaultSubmodel) ElementCreateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) Test(org.junit.Test)

Example 5 with ElementCreateEventMessage

use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage 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

ElementCreateEventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage)5 UaClient (com.prosysopc.ua.client.UaClient)3 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)3 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)3 RelativePath (com.prosysopc.ua.stack.core.RelativePath)3 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)3 DefaultKey (io.adminshell.aas.v3.model.impl.DefaultKey)3 ArrayList (java.util.ArrayList)3 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)2 LangString (io.adminshell.aas.v3.model.LangString)2 DefaultProperty (io.adminshell.aas.v3.model.impl.DefaultProperty)2 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)2 Test (org.junit.Test)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 ElementReadEventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.access.ElementReadEventMessage)1 ElementDeleteEventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage)1