Search in sources :

Example 11 with QualifiedName

use of com.prosysopc.ua.stack.builtintypes.QualifiedName in project FAAAST-Service by FraunhoferIOSB.

the class AasServiceNodeManager method setRangeValueAndType.

/**
 * Adds the min and max properties to the UA range object and sets the values
 *
 * @param aasRange The AAS range object
 * @param range The corresponding UA range object
 * @param submodel The corresponding submodel
 * @param rangeRef The AAS reference to the Range
 */
@SuppressWarnings("java:S125")
private void setRangeValueAndType(Range aasRange, AASRangeType range, Submodel submodel, Reference rangeRef) {
    try {
        String minValue = aasRange.getMin();
        String maxValue = aasRange.getMax();
        NodeId myPropertyIdMin = new NodeId(getNamespaceIndex(), range.getNodeId().getValue().toString() + "." + AASRangeType.MIN);
        NodeId myPropertyIdMax = new NodeId(getNamespaceIndex(), range.getNodeId().getValue().toString() + "." + AASRangeType.MAX);
        String valueType = aasRange.getValueType();
        QualifiedName browseNameMin = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASRangeType.getNamespaceUri(), AASRangeType.MIN).toQualifiedName(getNamespaceTable());
        LocalizedText displayNameMin = LocalizedText.english(AASRangeType.MIN);
        QualifiedName browseNameMax = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASRangeType.getNamespaceUri(), AASRangeType.MAX).toQualifiedName(getNamespaceTable());
        LocalizedText displayNameMax = LocalizedText.english(AASRangeType.MAX);
        submodelElementAasMap.put(myPropertyIdMin, new SubmodelElementData(aasRange, submodel, SubmodelElementData.Type.RANGE_MIN, rangeRef));
        submodelElementAasMap.put(myPropertyIdMax, new SubmodelElementData(aasRange, submodel, SubmodelElementData.Type.RANGE_MAX, rangeRef));
        submodelElementOpcUAMap.put(rangeRef, range);
        TypedValue<?> minTypedValue = TypedValueFactory.create(valueType, minValue);
        TypedValue<?> maxTypedValue = TypedValueFactory.create(valueType, maxValue);
        AASValueTypeDataType valueDataType;
        if (minTypedValue != null) {
            valueDataType = ValueConverter.datatypeToValueType(minTypedValue.getDataType());
        } else {
            valueDataType = ValueConverter.stringToValueType(valueType);
        }
        range.setValueType(valueDataType);
        switch(valueDataType) {
            // 
            case Boolean:
                if (minValue != null) {
                    PlainProperty<Boolean> myBoolProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myBoolProperty.setDataTypeId(Identifiers.Boolean);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        myBoolProperty.setValue(minTypedValue.getValue());
                    }
                    myBoolProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myBoolProperty);
                }
                if (maxValue != null) {
                    PlainProperty<Boolean> myBoolProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myBoolProperty.setDataTypeId(Identifiers.Boolean);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        myBoolProperty.setValue(maxTypedValue.getValue());
                    }
                    myBoolProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myBoolProperty);
                }
                break;
            // break;
            case Int32:
                if (minValue != null) {
                    PlainProperty<Integer> myIntProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myIntProperty.setDataTypeId(Identifiers.Int32);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        myIntProperty.setValue(minTypedValue.getValue());
                    }
                    myIntProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myIntProperty);
                }
                if (maxValue != null) {
                    PlainProperty<Integer> myIntProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myIntProperty.setDataTypeId(Identifiers.Int32);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        myIntProperty.setValue(maxTypedValue.getValue());
                    }
                    myIntProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myIntProperty);
                }
                break;
            case Int64:
                if (minValue != null) {
                    PlainProperty<Long> myLongProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myLongProperty.setDataTypeId(Identifiers.Int64);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        Object obj = minTypedValue.getValue();
                        if (!(obj instanceof Long)) {
                            obj = Long.parseLong(obj.toString());
                        }
                        myLongProperty.setValue(obj);
                    }
                    myLongProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myLongProperty);
                }
                if (maxValue != null) {
                    PlainProperty<Long> myLongProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myLongProperty.setDataTypeId(Identifiers.Int64);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        Object obj = maxTypedValue.getValue();
                        if (!(obj instanceof Long)) {
                            obj = Long.parseLong(obj.toString());
                        }
                        myLongProperty.setValue(obj);
                    }
                    myLongProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myLongProperty);
                }
                break;
            case Int16:
                if (minValue != null) {
                    PlainProperty<Short> myInt16Property = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myInt16Property.setDataTypeId(Identifiers.Int16);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        myInt16Property.setValue(minTypedValue.getValue());
                    }
                    myInt16Property.setDescription(new LocalizedText("", ""));
                    range.addProperty(myInt16Property);
                }
                if (maxValue != null) {
                    PlainProperty<Short> myInt16Property = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myInt16Property.setDataTypeId(Identifiers.Int16);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        myInt16Property.setValue(maxTypedValue.getValue());
                    }
                    myInt16Property.setDescription(new LocalizedText("", ""));
                    range.addProperty(myInt16Property);
                }
                break;
            case SByte:
                if (minValue != null) {
                    PlainProperty<Byte> mySByteProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    mySByteProperty.setDataTypeId(Identifiers.SByte);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        mySByteProperty.setValue(minTypedValue.getValue());
                    }
                    mySByteProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(mySByteProperty);
                }
                if (maxValue != null) {
                    PlainProperty<Byte> mySByteProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    mySByteProperty.setDataTypeId(Identifiers.SByte);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        mySByteProperty.setValue(maxTypedValue.getValue());
                    }
                    mySByteProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(mySByteProperty);
                }
                break;
            // 
            case Double:
                if (minValue != null) {
                    PlainProperty<Double> myDoubleProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myDoubleProperty.setDataTypeId(Identifiers.Double);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        myDoubleProperty.setValue(minTypedValue.getValue());
                    }
                    myDoubleProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myDoubleProperty);
                }
                if (maxValue != null) {
                    PlainProperty<Double> myDoubleProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myDoubleProperty.setDataTypeId(Identifiers.Double);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        myDoubleProperty.setValue(maxTypedValue.getValue());
                    }
                    myDoubleProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myDoubleProperty);
                }
                break;
            case Float:
                if (minValue != null) {
                    PlainProperty<Float> myFloatProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myFloatProperty.setDataTypeId(Identifiers.Float);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        myFloatProperty.setValue(minTypedValue.getValue());
                    }
                    myFloatProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myFloatProperty);
                }
                if (maxValue != null) {
                    PlainProperty<Float> myFloatProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myFloatProperty.setDataTypeId(Identifiers.Float);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        myFloatProperty.setValue(maxTypedValue.getValue());
                    }
                    myFloatProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myFloatProperty);
                }
                break;
            // 
            case String:
                if (minValue != null) {
                    PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myStringProperty.setDataTypeId(Identifiers.String);
                    if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
                        myStringProperty.setValue(minTypedValue.getValue());
                    }
                    myStringProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myStringProperty);
                }
                if (maxValue != null) {
                    PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myStringProperty.setDataTypeId(Identifiers.String);
                    if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
                        myStringProperty.setValue(maxTypedValue.getValue());
                    }
                    myStringProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myStringProperty);
                }
                break;
            // break;
            default:
                LOG.warn("setRangeValueAndType: Range {}: Unknown type: {}; use string as default", range.getBrowseName().getName(), valueType);
                if (minValue != null) {
                    PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
                    myStringProperty.setDataTypeId(Identifiers.String);
                    myStringProperty.setValue(minValue);
                    myStringProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myStringProperty);
                }
                if (maxValue != null) {
                    PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
                    myStringProperty.setDataTypeId(Identifiers.String);
                    myStringProperty.setValue(maxValue);
                    myStringProperty.setDescription(new LocalizedText("", ""));
                    range.addProperty(myStringProperty);
                }
                break;
        }
    } catch (Exception ex) {
        LOG.error("setRangeValueAndType Exception", ex);
    }
}
Also used : ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText) AASValueTypeDataType(opc.i4aas.AASValueTypeDataType) PlainProperty(com.prosysopc.ua.server.nodes.PlainProperty) UaQualifiedName(com.prosysopc.ua.UaQualifiedName) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ServiceResultException(com.prosysopc.ua.stack.common.ServiceResultException) StatusException(com.prosysopc.ua.StatusException) MessageBusException(de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException) ServiceException(com.prosysopc.ua.ServiceException) UaNodeFactoryException(com.prosysopc.ua.nodes.UaNodeFactoryException) AddressSpaceException(com.prosysopc.ua.client.AddressSpaceException) UnsignedInteger(com.prosysopc.ua.stack.builtintypes.UnsignedInteger) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) UaObject(com.prosysopc.ua.nodes.UaObject) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Example 12 with QualifiedName

use of com.prosysopc.ua.stack.builtintypes.QualifiedName in project FAAAST-Service by FraunhoferIOSB.

the class AasServiceNodeManager method addAasCapability.

/**
 * Adds an AAS Capability to the given node.
 *
 * @param node The desired UA node
 * @param aasCapability The corresponding AAS Capability to add
 * @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 capability should be added ordered
 *            (true) or unordered (false)
 * @throws StatusException If the operation fails
 */
private void addAasCapability(UaNode node, Capability aasCapability, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException {
    try {
        if ((node != null) && (aasCapability != null)) {
            String name = aasCapability.getIdShort();
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASCapabilityType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            AASCapabilityType capabilityNode = createInstance(AASCapabilityType.class, nid, browseName, LocalizedText.english(name));
            addSubmodelElementBaseData(capabilityNode, aasCapability);
            if (ordered) {
                node.addReference(capabilityNode, Identifiers.HasOrderedComponent, false);
            } else {
                node.addComponent(capabilityNode);
            }
            Reference capabilityRef = AasUtils.toReference(parentRef, aasCapability);
            referableMap.put(capabilityRef, new ObjectData(aasCapability, capabilityNode, submodel));
        }
    } catch (Exception ex) {
        LOG.error("addAasCapability Exception", ex);
        throw ex;
    }
}
Also used : Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) UaQualifiedName(com.prosysopc.ua.UaQualifiedName) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ObjectData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) AASCapabilityType(opc.i4aas.AASCapabilityType) ServiceResultException(com.prosysopc.ua.stack.common.ServiceResultException) StatusException(com.prosysopc.ua.StatusException) MessageBusException(de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException) ServiceException(com.prosysopc.ua.ServiceException) UaNodeFactoryException(com.prosysopc.ua.nodes.UaNodeFactoryException) AddressSpaceException(com.prosysopc.ua.client.AddressSpaceException)

Example 13 with QualifiedName

use of com.prosysopc.ua.stack.builtintypes.QualifiedName 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();
}
Also used : DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) ArrayList(java.util.ArrayList) DefaultRelationshipElement(io.adminshell.aas.v3.model.impl.DefaultRelationshipElement) DefaultSubmodel(io.adminshell.aas.v3.model.impl.DefaultSubmodel) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) ElementUpdateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) 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) AASKeyDataType(opc.i4aas.AASKeyDataType) UaClient(com.prosysopc.ua.client.UaClient) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) Test(org.junit.Test)

Example 14 with QualifiedName

use of com.prosysopc.ua.stack.builtintypes.QualifiedName in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointFullTest method testWriteSubmodelElementCollectionValue2.

/**
 * Test method for writing a Value of a SubmodelElementCollection. Writes the property in the OPC UA
 * Server and checks the new value in the server.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws InterruptedException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
@Test
public void testWriteSubmodelElementCollectionValue2() throws SecureIdentityException, IOException, ServiceException, StatusException, InterruptedException, ServiceResultException {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    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_6_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, TestDefines.FULL_SMEC_RANGE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.RANGE_MIN_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testWriteSubmodelElementCollectionValue2 Browse Result Null", bpres);
    Assert.assertEquals("testWriteSubmodelElementCollectionValue2 Browse Result: size doesn't match", 1, bpres.length);
    Assert.assertTrue("testWriteSubmodelElementCollectionValue2 Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWriteSubmodelElementCollectionValue2 ValueType Null", targets);
    Assert.assertTrue("testWriteSubmodelElementCollectionValue2 ValueType empty", targets.length > 0);
    NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    TestUtils.writeNewValueIntern(client, writeNode, 0, 4);
    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) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) UaClient(com.prosysopc.ua.client.UaClient) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) Test(org.junit.Test)

Example 15 with QualifiedName

use of com.prosysopc.ua.stack.builtintypes.QualifiedName in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointFullTest method testOrderedSubmodelElementCollection.

/**
 * Test method for an OrderedSubmodelElementCollection.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws ServiceResultException If the operation fails
 * @throws AddressSpaceException If the operation fails
 */
@Test
public void testOrderedSubmodelElementCollection() throws SecureIdentityException, IOException, ServiceException, ServiceResultException, AddressSpaceException {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    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_6_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SM_ELEM_COLL_O_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testOrderedSubmodelElementCollection Browse Result Null", bpres);
    Assert.assertEquals("testOrderedSubmodelElementCollection Browse Result: size doesn't match", 1, bpres.length);
    Assert.assertTrue("testOrderedSubmodelElementCollection Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testOrderedSubmodelElementCollection ValueType Null", targets);
    Assert.assertTrue("testOrderedSubmodelElementCollection ValueType empty", targets.length > 0);
    NodeId smNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    Assert.assertNotNull("testOrderedSubmodelElementCollection Node Null", smNode);
    TestUtils.checkType(client, smNode, new NodeId(aasns, TestDefines.AAS_OREDER_SM_ELEM_COLL_TYPE_ID));
    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) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) UaClient(com.prosysopc.ua.client.UaClient) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) Test(org.junit.Test)

Aggregations

QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)74 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)60 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)46 ArrayList (java.util.ArrayList)46 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)45 RelativePath (com.prosysopc.ua.stack.core.RelativePath)45 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)40 StatusException (com.prosysopc.ua.StatusException)29 ServiceException (com.prosysopc.ua.ServiceException)28 AddressSpaceException (com.prosysopc.ua.client.AddressSpaceException)28 ServiceResultException (com.prosysopc.ua.stack.common.ServiceResultException)28 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)27 UaNodeFactoryException (com.prosysopc.ua.nodes.UaNodeFactoryException)27 MessageBusException (de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException)27 LangString (io.adminshell.aas.v3.model.LangString)27 UaClient (com.prosysopc.ua.client.UaClient)26 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)26 Test (org.junit.Test)26 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)24 Reference (io.adminshell.aas.v3.model.Reference)19