private void createTags() throws Exception {
IgnitionGateway context = IgnitionGateway.get();
GatewayTagManager tagManager = context.getTagManager();
TagProvider provider = tagManager.getTagProvider("default");
List<TagConfiguration> newTagConfigs = new ArrayList<>();
TagPath levelOneFolderA = TagPathParser.parse("LevelOne_FolderA");
TagConfiguration tagConfig = BasicTagConfiguration.createNew(levelOneFolderA);
tagConfig.setType(TagObjectType.Folder);
newTagConfigs.add(tagConfig);
TagPath memoryTag0 = TagPathParser.parse("MemoryTag0");
tagConfig = BasicTagConfiguration.createNew(memoryTag0);
tagConfig.setType(TagObjectType.AtomicTag);
tagConfig.set(WellKnownTagProps.ValueSource, WellKnownTagProps.MEMORY_TAG_TYPE);
tagConfig.set(WellKnownTagProps.DataType, DataType.Int4);
tagConfig.set(WellKnownTagProps.Value, new BasicQualifiedValue(42));
newTagConfigs.add(tagConfig);
TagPath memoryTag1 = TagPathParser.parse("LevelOne_FolderA/MemoryTag1");
tagConfig = BasicTagConfiguration.createNew(memoryTag1);
tagConfig.setType(TagObjectType.AtomicTag);
tagConfig.set(WellKnownTagProps.ValueSource, WellKnownTagProps.MEMORY_TAG_TYPE);
tagConfig.set(WellKnownTagProps.DataType, DataType.Int4);
tagConfig.set(WellKnownTagProps.Value, new BasicQualifiedValue(1));
tagConfig.set(WellKnownTagProps.Documentation, "This is MemoryTag1");
tagConfig.set(WellKnownTagProps.Tooltip, "MemoryTag1 tooltip");
AlarmConfiguration alarmConfig = new BasicAlarmConfiguration();
AlarmDefinition alarmOneDefinition = new BasicAlarmDefinition();
alarmOneDefinition.setName("HighValue");
alarmOneDefinition.set(AlarmModeProperties.Mode, AlarmMode.AboveValue);
alarmOneDefinition.set(AlarmModeProperties.SetpointA, 5.0d);
alarmConfig.add(alarmOneDefinition);
AlarmDefinition alarmTwoDefinition = new BasicAlarmDefinition();
alarmTwoDefinition.setName("LowValue");
alarmTwoDefinition.set(AlarmModeProperties.Mode, AlarmMode.BelowValue);
alarmTwoDefinition.set(AlarmModeProperties.SetpointA, 1.0d);
alarmConfig.add(alarmTwoDefinition);
tagConfig.set(WellKnownTagProps.Alarms, alarmConfig);
Map<ZoneRole, Boolean> permissionsMap = new HashMap<>();
TagPermissionsModel.ZoneRole zoneRole = new TagPermissionsModel.ZoneRole();
zoneRole.setRole("Administrator");
zoneRole.setZone("default");
permissionsMap.put(zoneRole, true);
BasicTagPermissions permissions = new BasicTagPermissions(permissionsMap);
tagConfig.set(WellKnownTagProps.PermissionModel, permissions);
TagEventScripts scripts = new BasicTagEventScripts();
scripts.set("onValueChange", "print 'Hello World'");
tagConfig.set(WellKnownTagProps.EventScripts, scripts);
Property<String> strProp = new BasicProperty<>("customStr", String.class);
tagConfig.set(strProp, "Hello world");
Property<Integer> intProp = new BasicProperty<>("customInt", Integer.class);
tagConfig.set(intProp, 42);
Property<Double> doubleProp = new BasicProperty<>("customDbl", Double.class);
tagConfig.set(doubleProp, 3.1415d);
newTagConfigs.add(tagConfig);
TagPath expressionTag0 = TagPathParser.parse("ExpressionTag0");
tagConfig = BasicTagConfiguration.createNew(expressionTag0);
tagConfig.setType(TagObjectType.AtomicTag);
tagConfig.set(WellKnownTagProps.DataType, DataType.DateTime);
tagConfig.set(WellKnownTagProps.FormatString, "yyyy-MM-dd h:mm:ss aa");
tagConfig.set(WellKnownTagProps.ValueSource, ExpressionTypeProperties.TAG_TYPE);
tagConfig.set(ExpressionTypeProperties.Expression, "now(1000)");
TagPath queryTag0 = TagPathParser.parse("QueryTag0");
tagConfig = BasicTagConfiguration.createNew(queryTag0);
tagConfig.setType(TagObjectType.AtomicTag);
tagConfig.set(WellKnownTagProps.DataType, DataType.DateTime);
tagConfig.set(WellKnownTagProps.FormatString, "yyyy-MM-dd h:mm:ss aa");
tagConfig.set(WellKnownTagProps.ValueSource, DBTagTypeProperties.TAG_TYPE);
tagConfig.set(WellKnownTagProps.ExecutionMode, TagExecutionMode.TagGroupRate);
tagConfig.set(DBTagTypeProperties.QueryType, SQLQueryType.Select);
tagConfig.set(DBTagTypeProperties.QueryDatasource, "my_datasource");
tagConfig.set(DBTagTypeProperties.Query, "select now()");
TagPath opcTag0 = TagPathParser.parse("OpcTag0");
tagConfig = BasicTagConfiguration.createNew(opcTag0);
tagConfig.setType(TagObjectType.AtomicTag);
tagConfig.set(WellKnownTagProps.DataType, DataType.Float4);
tagConfig.set(WellKnownTagProps.ValueSource, OpcTagTypeProperties.TAG_TYPE);
tagConfig.set(OpcTagTypeProperties.OPCServer, "Ignition OPC UA Server");
tagConfig.set(OpcTagTypeProperties.OPCItemPath, "ns=1;s=[GenericSimulator]_Meta:Writeable/WriteableFloat1");
TagPath tinyUdtDef = TagPathParser.parse("_types_/TinyUdtDef");
tagConfig = BasicTagConfiguration.createNew(tinyUdtDef);
tagConfig.setType(TagObjectType.UdtType);
newTagConfigs.add(tagConfig);
TagPath udtDefMember = TagPathParser.parse("_types_/TinyUdtDef/MemoryTagMember");
tagConfig = BasicTagConfiguration.createNew(udtDefMember);
tagConfig.setType(TagObjectType.AtomicTag);
tagConfig.set(WellKnownTagProps.DataType, DataType.Int4);
tagConfig.set(WellKnownTagProps.Value, new BasicQualifiedValue(1));
newTagConfigs.add(tagConfig);
TagPath udtInstance = TagPathParser.parse("TinyUdt_Instance");
tagConfig = BasicTagConfiguration.createNew(udtInstance);
tagConfig.setType(TagObjectType.UdtInstance);
tagConfig.set(WellKnownTagProps.TypeId, "TinyUdtDef");
newTagConfigs.add(tagConfig);
CompletableFuture<List<QualityCode>> future =
provider.saveTagConfigsAsync(newTagConfigs, CollisionPolicy.Abort);
List<QualityCode> results = future.get(30, TimeUnit.SECONDS);
for (int i = 0; i < results.size(); i++) {
QualityCode result = results.get(i);
if (result.isNotGood()) {
throw new Exception(String.format("Add tag operation returned bad result for tag '%s'", newTagConfigs.get(i).getName()));
}
}
newTagConfigs.clear();
TagPath udtOverrideInstance = TagPathParser.parse("TinyUdt_OverrideInstance");
tagConfig = BasicTagConfiguration.createNew(udtOverrideInstance);
tagConfig.setType(TagObjectType.UdtInstance);
tagConfig.set(WellKnownTagProps.TypeId, "TinyUdtDef");
newTagConfigs.add(tagConfig);
TagPath udtOverrideMember = TagPathParser.parse("TinyUdt_OverrideInstance/MemoryTagMember");
tagConfig = BasicTagConfiguration.createNew(udtOverrideMember);
tagConfig.set(WellKnownTagProps.Value, new BasicQualifiedValue(2));
newTagConfigs.add(tagConfig);
future =
provider.saveTagConfigsAsync(newTagConfigs, CollisionPolicy.Abort);
future.get(30, TimeUnit.SECONDS);
for (int i = 0; i < results.size(); i++) {
QualityCode result = results.get(i);
if (result.isNotGood()) {
throw new Exception(String.format("Add tag operation returned bad result for tag '%s'", newTagConfigs.get(i).getName()));
}
}
}