Search in sources :

Example 6 with LangString

use of io.adminshell.aas.v3.model.LangString 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)

Aggregations

LangString (io.adminshell.aas.v3.model.LangString)6 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)3 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)3 UaClient (com.prosysopc.ua.client.UaClient)2 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)2 LocalizedText (com.prosysopc.ua.stack.builtintypes.LocalizedText)2 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)2 RelativePath (com.prosysopc.ua.stack.core.RelativePath)2 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)2 DefaultIdentifier (io.adminshell.aas.v3.model.impl.DefaultIdentifier)2 DefaultKey (io.adminshell.aas.v3.model.impl.DefaultKey)2 DefaultRelationshipElement (io.adminshell.aas.v3.model.impl.DefaultRelationshipElement)2 DefaultSubmodel (io.adminshell.aas.v3.model.impl.DefaultSubmodel)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)1 DataValue (com.prosysopc.ua.stack.builtintypes.DataValue)1 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)1 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)1 ObjectData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData)1