use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandler method publishElementUpdateEventMessage.
/**
* Publish a ElementUpdateEventMessage to the message bus
*
* @param reference of the element
* @param referable the instance
*/
public void publishElementUpdateEventMessage(Reference reference, Referable referable) {
ElementUpdateEventMessage eventMessage = new ElementUpdateEventMessage();
eventMessage.setElement(reference);
eventMessage.setValue(referable);
try {
this.messageBus.publish(eventMessage);
} catch (Exception e) {
e.printStackTrace();
}
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpoint2Test method testUpdateSubmodel.
/**
* Test method for updating a complete submodel (Operational Data).
*
* @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 testUpdateSubmodel() throws SecureIdentityException, IOException, ServiceException, Exception {
UaClient client = new UaClient(ENDPOINT_URL);
client.setSecurityMode(SecurityMode.NONE);
TestUtils.initialize(client);
client.connect();
System.out.println("testUpdateSubmodel: client connected");
int aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
// make sure one of the old elements exists, the new element exists not 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_OPER_DATA_NODE_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.TEST_RANGE_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.RANGE_MAX_NAME)));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
browsePath.clear();
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_OPER_DATA_NODE_NAME)));
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("testUpdateSubmodel Browse Result Null", bpres);
Assert.assertTrue("testUpdateSubmodel Browse 1 Result: size doesn't match", bpres.length == 2);
Assert.assertTrue("testUpdateSubmodel Browse 1 Result 1 Good", bpres[0].getStatusCode().isGood());
Assert.assertTrue("testUpdateSubmodel Browse 1 Result 2 Bad", bpres[1].getStatusCode().isBad());
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("testUpdateSubmodel RangeMax Null", targets);
Assert.assertTrue("testUpdateSubmodel RangeMax empty", targets.length > 0);
// update submodel
// Send update event to MessageBus
ElementUpdateEventMessage msg = new ElementUpdateEventMessage();
msg.setElement(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value(AASSimple.SUBMODEL_OPERATIONAL_DATA_ID).build()).build());
msg.setValue(new DefaultSubmodel.Builder().idShort(TestDefines.SUBMODEL_OPER_DATA_NODE_NAME).identification(new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier("https://acplt.org/NewOperationalData").build()).administration(new DefaultAdministrativeInformation.Builder().version("1.1").revision("5").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 old element is not there anymore, but the new element
bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("testUpdateSubmodel Browse Result old Null", bpres);
Assert.assertTrue("testUpdateSubmodel Browse 2 Result: size doesn't match", bpres.length == 2);
Assert.assertTrue("testUpdateSubmodel Browse 2 Result 1 Bad", bpres[0].getStatusCode().isBad());
Assert.assertTrue("testUpdateSubmodel Browse 2 Result 2 Good", bpres[1].getStatusCode().isGood());
// read a value of the new SubmodelElement
targets = bpres[1].getTargets();
Assert.assertNotNull("testUpdateSubmodel RelationshipElement Null", targets);
Assert.assertTrue("testUpdateSubmodel RelationshipElement empty", targets.length > 0);
List<AASKeyDataType> smeValue = new ArrayList<>();
smeValue.add(new AASKeyDataType(AASKeyElementsDataType.Submodel, "http://acplt.org/Submodels/Assets/TestAsset/BillOfMaterial", AASKeyTypeDataType.IRI));
smeValue.add(new AASKeyDataType(AASKeyElementsDataType.Entity, "ExampleEntity", AASKeyTypeDataType.IdShort));
smeValue.add(new AASKeyDataType(AASKeyElementsDataType.Property, "ExampleProperty2", AASKeyTypeDataType.IdShort));
DataValue value = client.readValue(client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId()));
Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
Assert.assertArrayEquals("new SubmodelElement value not equal", smeValue.toArray(AASKeyDataType[]::new), (AASKeyDataType[]) value.getValue().getValue());
System.out.println("disconnect client");
client.disconnect();
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpoint2Test method testUpdateSubmodelElement.
/**
* Test method for updating a SubmodelElement.
*
* @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 testUpdateSubmodelElement() throws SecureIdentityException, IOException, ServiceException, Exception {
UaClient client = new UaClient(ENDPOINT_URL);
client.setSecurityMode(SecurityMode.NONE);
TestUtils.initialize(client);
client.connect();
System.out.println("testUpdateSubmodelElement: client connected");
int aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
// make sure one of the old elements exists, the new element exists not 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_DOC_NODE_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.OPERATING_MANUAL_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.SUBMODEL_DOC_PROPERTY_TITLE_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_NAME)));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
browsePath.clear();
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_DOC_NODE_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.OPERATING_MANUAL_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.SUBMODEL_DOC_FILE_NAME)));
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("testUpdateSubmodelElement Browse Result Null", bpres);
Assert.assertTrue("testUpdateSubmodelElement Browse 1 Result: size doesn't match", bpres.length == 2);
Assert.assertTrue("testUpdateSubmodelElement Browse 1 Result 1 Good", bpres[0].getStatusCode().isGood());
Assert.assertTrue("testUpdateSubmodelElement Browse 1 Result 2 Good", bpres[1].getStatusCode().isGood());
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("testUpdateSubmodelElement Property Value Null", targets);
Assert.assertTrue("testUpdateSubmodelElement Property Value empty", targets.length > 0);
// read the (old) value of the SubmodelElement
DataValue value = client.readValue(client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId()));
Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
Assert.assertEquals("old SubmodelElement value not equal", "OperatingManual", value.getValue().toString());
String newValue = "New Test Value";
// update SubmodelElement
// Send update event to MessageBus
ElementUpdateEventMessage msg = new ElementUpdateEventMessage();
msg.setElement(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value(TestDefines.SUBMODEL_DOC_NAME).build()).key(new DefaultKey.Builder().idType(KeyType.ID_SHORT).type(KeyElements.SUBMODEL_ELEMENT_COLLECTION).value(TestDefines.OPERATING_MANUAL_NAME).build()).build());
msg.setValue(new DefaultSubmodelElementCollection.Builder().kind(ModelingKind.INSTANCE).idShort("OperatingManual").value(new DefaultProperty.Builder().kind(ModelingKind.INSTANCE).idShort("Title").value(newValue).valueType("string").build()).ordered(false).allowDuplicates(false).build());
service.getMessageBus().publish(msg);
Thread.sleep(DEFAULT_TIMEOUT);
bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("testUpdateSubmodelElement Browse 2 Result Null", bpres);
Assert.assertTrue("testUpdateSubmodelElement Browse 2 Result: size doesn't match", bpres.length == 2);
Assert.assertTrue("testUpdateSubmodelElement Browse 2 Result 1 Good", bpres[0].getStatusCode().isGood());
Assert.assertTrue("testUpdateSubmodelElement Browse 2 Result 2 Bad", bpres[1].getStatusCode().isBad());
// read the (new) value of the SubmodelElement
targets = bpres[0].getTargets();
Assert.assertNotNull("testUpdateSubmodelElement Property New Value Null", targets);
Assert.assertTrue("testUpdateSubmodelElement Property New Value empty", targets.length > 0);
NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
value = client.readValue(writeNode);
System.out.println("testUpdateSubmodelElement: writeNode: " + writeNode.toString());
Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
Assert.assertEquals("new SubmodelElement value not equal", newValue, value.getValue().toString());
System.out.println("disconnect client");
client.disconnect();
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage 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);
}
Aggregations