use of io.adminshell.aas.v3.model.RelationshipElement in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasRelationshipElement.
/**
* Adds an AAS Relationship Element to the given node.
*
* @param node The desired UA node
* @param aasRelElem The corresponding AAS Relationship Element
* @param submodel The corresponding Submodel as parent object of the data element
* @param parentRef The AAS reference to the parent object
* @param ordered Specifies whether the entity should be added ordered
* (true) or unordered (false)
* @throws StatusException If the operation fails
* @throws ServiceException If the operation fails
* @throws AddressSpaceException If the operation fails
* @throws ServiceResultException If the operation fails
*/
private void addAasRelationshipElement(UaNode node, RelationshipElement aasRelElem, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
try {
if ((node != null) && (aasRelElem != null)) {
Reference relElemRef = AasUtils.toReference(parentRef, aasRelElem);
String name = aasRelElem.getIdShort();
AASRelationshipElementType relElemNode;
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASRelationshipElementType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
if (aasRelElem instanceof AnnotatedRelationshipElement) {
relElemNode = createAnnotatedRelationshipElement((AnnotatedRelationshipElement) aasRelElem, submodel, relElemRef, nid);
} else {
relElemNode = createInstance(AASRelationshipElementType.class, nid, browseName, LocalizedText.english(name));
}
if (relElemNode != null) {
addSubmodelElementBaseData(relElemNode, aasRelElem);
setAasReferenceData(aasRelElem.getFirst(), relElemNode.getFirstNode(), false);
setAasReferenceData(aasRelElem.getSecond(), relElemNode.getSecondNode(), false);
submodelElementAasMap.put(relElemNode.getFirstNode().getKeysNode().getNodeId(), new SubmodelElementData(aasRelElem, submodel, SubmodelElementData.Type.RELATIONSHIP_ELEMENT_FIRST, relElemRef));
submodelElementAasMap.put(relElemNode.getSecondNode().getKeysNode().getNodeId(), new SubmodelElementData(aasRelElem, submodel, SubmodelElementData.Type.RELATIONSHIP_ELEMENT_SECOND, relElemRef));
submodelElementOpcUAMap.put(relElemRef, relElemNode);
if (ordered) {
node.addReference(relElemNode, Identifiers.HasOrderedComponent, false);
} else {
node.addComponent(relElemNode);
}
referableMap.put(relElemRef, new ObjectData(aasRelElem, relElemNode, submodel));
}
}
} catch (Throwable ex) {
logger.error("addAasRelationshipElement Exception", ex);
throw ex;
}
}
use of io.adminshell.aas.v3.model.RelationshipElement in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method setRelationshipValue.
/**
* Sets the values for the given RelationshipElement.
*
* @param aasElement The desired RelationshipElement.
* @param value The new value.
* @throws StatusException If the operation fails
*/
private void setRelationshipValue(AASRelationshipElementType aasElement, RelationshipElementValue value) throws StatusException {
if (aasElement == null) {
throw new IllegalArgumentException("aasElement is null");
} else if (value == null) {
throw new IllegalArgumentException("value is null");
}
try {
Reference ref = new DefaultReference.Builder().keys(value.getFirst()).build();
setAasReferenceData(ref, aasElement.getFirstNode(), false);
ref = new DefaultReference.Builder().keys(value.getSecond()).build();
setAasReferenceData(ref, aasElement.getSecondNode(), false);
if ((aasElement instanceof AASAnnotatedRelationshipElementType) && (value instanceof AnnotatedRelationshipElementValue)) {
AASAnnotatedRelationshipElementType annotatedElement = (AASAnnotatedRelationshipElementType) aasElement;
AnnotatedRelationshipElementValue annotatedValue = (AnnotatedRelationshipElementValue) value;
UaNode[] annotationNodes = annotatedElement.getAnnotationNode().getComponents();
Map<String, DataElementValue> valueMap = annotatedValue.getAnnotations();
if (annotationNodes.length != valueMap.size()) {
logger.warn("Size of Value (" + valueMap.size() + ") doesn't match the number of AnnotationNodes (" + annotationNodes.length + ")");
throw new IllegalArgumentException("Size of Value doesn't match the number of AnnotationNodes");
}
// The Key of the Map is the IDShort of the DataElement (in our case the BrowseName)
for (UaNode annotationNode : annotationNodes) {
if (valueMap.containsKey(annotationNode.getBrowseName().getName())) {
setDataElementValue(annotationNode, valueMap.get(annotationNode.getBrowseName().getName()));
}
}
} else {
logger.info("setRelationshipValue: No AnnotatedRelationshipElement " + aasElement.getBrowseName().getName());
}
} catch (Throwable ex) {
logger.error("setAnnotatedRelationshipValue Exception", ex);
throw ex;
}
}
use of io.adminshell.aas.v3.model.RelationshipElement 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 io.adminshell.aas.v3.model.RelationshipElement 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();
}
Aggregations