use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpointFullTest method testCallOperationArgsMissing.
/**
* Test method for calling an operation with not enough arguments.
*
* @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 MethodCallStatusException If the operation fails
*/
@Test
public void testCallOperationArgsMissing() throws SecureIdentityException, IOException, ServiceException, ServiceResultException, MethodCallStatusException {
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());
int serverns = client.getAddressSpace().getNamespaceTable().getIndex(AasServiceNodeManager.NAMESPACE_URI);
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_OPERATION_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.FULL_SUBMODEL_3_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_OPERATION_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(serverns, TestDefines.FULL_OPERATION_NAME)));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("testCallOperationArgsMissing Browse Result Null", bpres);
Assert.assertEquals("testCallOperationArgsMissing Browse Result: size doesn't match", 2, bpres.length);
Assert.assertTrue("testCallOperationArgsMissing Browse Result Good", bpres[0].getStatusCode().isGood());
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("testCallOperationArgsMissing Object Targets Null", targets);
Assert.assertTrue("testCallOperationArgsMissing Object Targets empty", targets.length > 0);
NodeId objectNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
Assert.assertNotNull("testCallOperationArgsMissing objectNode Null", objectNode);
targets = bpres[1].getTargets();
Assert.assertNotNull("testCallOperationArgsMissing Method Targets Null", targets);
Assert.assertTrue("testCallOperationArgsMissing Method Targets empty", targets.length > 0);
NodeId methodNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
Assert.assertNotNull("testCallOperationArgsMissing methodNode Null", methodNode);
Variant[] inputArguments = new Variant[0];
StatusException exception = Assert.assertThrows(StatusException.class, () -> {
client.call(objectNode, methodNode, inputArguments);
});
Assert.assertEquals(StatusCodes.Bad_ArgumentsMissing, exception.getStatusCode().getValue());
System.out.println("disconnect client");
client.disconnect();
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class ValueConverter method setOutputArguments.
/**
* Sets the output arguments for an operation from the given output variables.
*
* @param outputVariables The desired output variables
* @param outputArguments The desired output arguments
* @throws StatusException If the operation fails
*/
public static void setOutputArguments(List<OperationVariable> outputVariables, Variant[] outputArguments) throws StatusException {
if (outputArguments.length != outputVariables.size()) {
throw new StatusException(StatusCodes.Bad_InvalidArgument);
} else {
for (int i = 0; i < outputVariables.size(); i++) {
SubmodelElement smelem = outputVariables.get(i).getValue();
SubmodelElementData.Type type;
if (smelem instanceof Property) {
type = SubmodelElementData.Type.PROPERTY_VALUE;
} else {
throw new StatusException(StatusCodes.Bad_InvalidArgument);
}
outputArguments[i] = getSubmodelElementValue(smelem, type);
}
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addEmbeddedDataSpecifications.
/**
* Adds the references to the given Embedded Data Specifications.
*
* @param submodelElementNode The desired object where the
* DataSpecifications should be added
* @param list The list of the desired Data Specifications
* @throws StatusException If the operation fails
*/
private void addEmbeddedDataSpecifications(AASSubmodelElementType submodelElementNode, List<EmbeddedDataSpecification> list) throws StatusException {
try {
if ((list != null) && (!list.isEmpty())) {
List<Reference> refList = new ArrayList<>();
for (EmbeddedDataSpecification eds : list) {
refList.add(eds.getDataSpecification());
}
AASReferenceList listNode = submodelElementNode.getDataSpecificationNode();
if (listNode == null) {
addAasReferenceList(submodelElementNode, refList, AASSubmodelElementType.DATA_SPECIFICATION);
} else {
addEmbeddedDataSpecificationsReferences(listNode, refList);
}
}
} catch (Exception ex) {
LOG.error(ADD_EMBED_DS_EXC, ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAsset.
/**
* Adds an Asset to the given Node.
*
* @param node The UA node in which the Asset should be created
* @param asset The desired Asset
* @throws StatusException If the operation fails
*/
private void addAsset(UaNode node, Asset asset) throws StatusException {
if (node == null) {
throw new IllegalArgumentException(NODE_NULL);
} else if (asset == null) {
throw new IllegalArgumentException("asset = null");
}
try {
String name = asset.getIdShort();
String displayName = "Asset:" + name;
LOG.info("addAsset {}; to Node: {}", name, node);
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASAssetType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = createNodeId(node, browseName);
AASAssetType assetNode = createInstance(AASAssetType.class, nid, browseName, LocalizedText.english(displayName));
addIdentifiable(assetNode, asset.getIdentification(), asset.getAdministration(), asset.getCategory());
// DataSpecifications
addEmbeddedDataSpecifications(assetNode, asset.getEmbeddedDataSpecifications());
node.addComponent(assetNode);
referableMap.put(AasUtils.toReference(asset), new ObjectData(asset, assetNode));
} catch (Exception ex) {
LOG.error("addAsset Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasSubmodelElementCollection.
/**
* Adds a SubmodelElementCollection to the given node.
*
* @param node The desired UA node
* @param aasColl The corresponding SubmodelElementCollection 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 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 addAasSubmodelElementCollection(UaNode node, SubmodelElementCollection aasColl, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
try {
if ((node != null) && (aasColl != null)) {
String name = aasColl.getIdShort();
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASSubmodelElementCollectionType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
AASSubmodelElementCollectionType collNode;
if (aasColl.getOrdered()) {
collNode = createAasOrderedSubmodelElementCollection(name, nid);
} else {
collNode = createInstance(AASSubmodelElementCollectionType.class, nid, browseName, LocalizedText.english(name));
}
addSubmodelElementBaseData(collNode, aasColl);
// AllowDuplicates
if (collNode.getAllowDuplicatesNode() == null) {
NodeId myPropertyId = new NodeId(getNamespaceIndex(), collNode.getNodeId().getValue().toString() + "." + AASSubmodelElementCollectionType.ALLOW_DUPLICATES);
PlainProperty<Boolean> myProperty = new PlainProperty<>(this, myPropertyId, UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASSubmodelElementCollectionType.getNamespaceUri(), AASSubmodelElementCollectionType.ALLOW_DUPLICATES).toQualifiedName(getNamespaceTable()), LocalizedText.english(AASSubmodelElementCollectionType.ALLOW_DUPLICATES));
myProperty.setDataTypeId(Identifiers.Boolean);
myProperty.setDescription(new LocalizedText("", ""));
if (VALUES_READ_ONLY) {
myProperty.setAccessLevel(AccessLevelType.CurrentRead);
}
collNode.addProperty(myProperty);
}
collNode.setAllowDuplicates(aasColl.getAllowDuplicates());
Reference collRef = AasUtils.toReference(parentRef, aasColl);
// SubmodelElements
addSubmodelElements(collNode, aasColl.getValues(), submodel, collRef, aasColl.getOrdered());
if (ordered) {
node.addReference(collNode, Identifiers.HasOrderedComponent, false);
} else {
node.addComponent(collNode);
}
referableMap.put(collRef, new ObjectData(aasColl, collNode, submodel));
}
} catch (Exception ex) {
LOG.error("createAasSubmodelElementCollection Exception", ex);
throw ex;
}
}
Aggregations