| /******************************************************************************* |
| * Copyright (c) 2020 DFKI. |
| * |
| * This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * DFKI - Volkan Gezer <volkan.gezer@dfki.de> |
| * |
| *******************************************************************************/ |
| package org.eclipse.aas.basyx.codegen.util.test; |
| |
| import java.util.LinkedHashMap; |
| |
| import org.eclipse.aas.basyx.codegen.util.Project; |
| import org.eclipse.aas.basyx.codegen.util.submodel.SubModel; |
| import org.eclipse.aas.basyx.codegen.util.submodel.SubModelCreator; |
| |
| public class Test { |
| |
| public static void main(String[] args) { |
| // Set project settings |
| |
| |
| SubModel docModel = new SubModel("Documentation"); // Sub model name: Documentation |
| |
| // Add properties for the first sub model |
| docModel.addProperty("DownloadLink", "http://example.org/documentation"); |
| docModel.addProperty("version","1"); |
| docModel.addProperty("version","2"); |
| |
| // Create another sub model with the name "TestSubModel" |
| SubModel subModel2 = new SubModel("TestSubModel"); |
| // Add an operation for second sub model |
| subModel2.addOperation("Operation1"); |
| // Add another operation with a custom code |
| subModel2.addOperation("Operation1", " try {\r\n" + |
| "\r\n" + |
| " if (connectedDevice.online == true) {\r\n" + |
| " //connectedDevice.callOperationByConfig(\"Operation2\", new Object[] { String.valueOf(\"Floor\") });\r\n" + |
| "\r\n" + |
| " // TODO: Implement the operation behavior here\r\n" + |
| " System.out.println(\"Received arguments from operation call: \" + arguments[0]);\r\n" + |
| " }\r\n" + |
| "\r\n" + |
| " else {\r\n" + |
| " System.out.println(\"Device not connected\");\r\n" + |
| " }\r\n" + |
| "\r\n" + |
| " }\r\n" + |
| "\r\n" + |
| " catch (Exception e) {\r\n" + |
| " e.printStackTrace();\r\n" + |
| " }\r\n" + |
| "\r\n" + |
| " return null;"); |
| // Add Operation1 to SubModelElementCollection |
| subModel2.addOperationToSubModelElementCollection("Operation1", "SubSubCollection"); |
| |
| // Add a new SubModelElementCollection to group (v) members |
| subModel2.addSubModelElementCollection("Collection"); // with name Collection |
| |
| subModel2.addSubModelElementCollection("SubSubCollection"); |
| |
| subModel2.addCollectionIntoSubModelElementCollection("SubSubCollection", "Collection"); |
| |
| // Add inputs for Operation1 |
| // Requires a LinkedHashMap<String, String>. |
| LinkedHashMap<String, String> inputlist = new LinkedHashMap<String, String>(); |
| inputlist.put("Operation1In1", "String"); |
| subModel2.addInputVariables("Operation1", inputlist); |
| |
| // Alternatively, one can add single variables as following: |
| // Similarly, for Output and InOutput... |
| subModel2.addInputVariable("Operation1", "Operation1In2", "String"); |
| |
| |
| // Add outputs for Operation1 |
| LinkedHashMap<String, String> testOp1OutVars = new LinkedHashMap<String, String>(); |
| testOp1OutVars.put("Operation1Out1", "String"); |
| subModel2.addOutputVariables("Operation1", testOp1OutVars); |
| |
| // Add another operation for second sub model |
| subModel2.addOperation("Operation2"); |
| |
| // Add inputs for Operation2 |
| LinkedHashMap<String, String> inputVariables = new LinkedHashMap<String, String>(); |
| inputVariables.put("Operation2In1", "String"); |
| inputVariables.put("Operation2In2", "String"); |
| subModel2.addInputVariables("Operation2", inputVariables); |
| |
| // Add outputs for Operation2 |
| LinkedHashMap<String, String> outputVariables = new LinkedHashMap<String, String>(); |
| outputVariables.put("Operation2Out1", "String"); |
| outputVariables.put("Operation2Out2", "String"); |
| subModel2.addOutputVariables("Operation2", outputVariables); |
| |
| // Add inout variables for Operation2 |
| LinkedHashMap<String, String> inoutputVariables = new LinkedHashMap<String, String>(); |
| inoutputVariables.put("Operation2TestInout1", "String"); |
| inoutputVariables.put("Operation2TestInout2", "String"); |
| subModel2.addInOutputVariables("Operation2", inoutputVariables); |
| |
| |
| // Add properties for second sub model |
| subModel2.addProperty("Property1", "Value1"); // Set Property1 value as Value1 |
| subModel2.addProperty("Property2"); // Set Property2 value as "Undefined" |
| subModel2.addProperty("Property2", "Undefined", "Integer"); // Set Property2 value as "Undefined" |
| |
| subModel2.addPropertyToSubModelElementCollection("Property2", "Collection2"); // Non-existent to add to top-level |
| |
| // Add File path to Collection SubModelElementCollection |
| subModel2.addFilePath("test/path", "Collection"); |
| |
| // Define sub model creator |
| SubModelCreator mc = new SubModelCreator(); |
| |
| // Add created sub models into sub model creator |
| mc.addSubModel(subModel2); |
| mc.addSubModel(docModel); |
| |
| |
| // Create project files |
| Project testAAS = new Project("urn:2123", |
| "localhost", "1995", mc, "opc.tcp://IP"); |
| // Currently only OPC-UA connection with the devices are possible |
| |
| // If below is commented out, it creates project files in the working folder. |
| testAAS.setProjectName("test2"); // The asset name as well as the project name |
| testAAS.setNamespaceFromProjectName(); // Creates project structure in Eclipse automatically based on project name |
| // testAAS.setNamespace("eu.dfki.canvaas.project"); // Instead, it is possible to use explicit namespacing. |
| testAAS.setProjectFolder("C:\\Users\\volka\\git\\gel\\"); |
| testAAS.setExternalClassFolder("C:\\Users\\volka\\basyfloor\\CanvAAS\\extClasses"); |
| |
| testAAS.linkAAS(testAAS); |
| |
| // Create the runnable project |
| testAAS.createProject(); |
| |
| } |
| |
| } |