├── ax ├── backup_swamp.dist ├── swamp │ ├── config.bog │ ├── alarm │ │ └── alarm.adb │ ├── gator │ │ └── gatorList.txt │ ├── history │ │ └── station │ │ │ ├── seg3 │ │ │ └── GatorTracker.hdb │ │ │ ├── seg4 │ │ │ └── LogHistory.hdb │ │ │ └── seg7 │ │ │ └── AuditHistory.hdb │ └── console.txt └── nola │ ├── module.palette │ ├── module-include.xml │ ├── module.lexicon │ ├── build.xml │ └── src │ └── com │ └── niagarasummit │ └── nola │ ├── BGator.java │ ├── ui │ └── BGatorTrackerView.java │ └── BGatorTracker.java ├── n4 ├── demo │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── nola │ │ ├── nola-rt │ │ │ ├── moduleTest-include.xml │ │ │ ├── module-include.xml │ │ │ ├── module.palette │ │ │ ├── nola-rt.gradle │ │ │ ├── module.lexicon │ │ │ └── src │ │ │ │ └── com │ │ │ │ └── niagarasummit │ │ │ │ └── nola │ │ │ │ ├── BGator.java │ │ │ │ └── BGatorTracker.java │ │ └── nola-wb │ │ │ ├── moduleTest-include.xml │ │ │ ├── module-include.xml │ │ │ ├── nola-wb.gradle │ │ │ └── src │ │ │ └── com │ │ │ └── niagarasummit │ │ │ └── nola │ │ │ └── ui │ │ │ └── BGatorTrackerView.java │ ├── vendor.gradle │ ├── environment.gradle │ ├── build.gradle │ ├── settings.gradle │ ├── gradlew.bat │ └── gradlew └── final │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── nola │ ├── nola-wb │ │ ├── moduleTest-include.xml │ │ ├── module-include.xml │ │ ├── nola-wb.gradle │ │ └── src │ │ │ └── com │ │ │ └── niagarasummit │ │ │ └── nola │ │ │ └── ui │ │ │ └── BGatorTrackerView.java │ └── nola-rt │ │ ├── module-include.xml │ │ ├── module.palette │ │ ├── moduleTest-include.xml │ │ ├── nola-rt.gradle │ │ ├── module.lexicon │ │ ├── srcTest │ │ └── test │ │ │ └── com │ │ │ └── niagarasummit │ │ │ └── nola │ │ │ └── BTrackGatorTest.java │ │ └── src │ │ └── com │ │ └── niagarasummit │ │ └── nola │ │ ├── BGator.java │ │ └── BGatorTracker.java │ ├── vendor.gradle │ ├── environment.gradle │ ├── build.gradle │ ├── settings.gradle │ ├── gradlew.bat │ └── gradlew ├── LICENSE └── README.md /ax/backup_swamp.dist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tridium/summit16-migrating-from-ax-to-n4/HEAD/ax/backup_swamp.dist -------------------------------------------------------------------------------- /ax/swamp/config.bog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tridium/summit16-migrating-from-ax-to-n4/HEAD/ax/swamp/config.bog -------------------------------------------------------------------------------- /ax/swamp/alarm/alarm.adb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tridium/summit16-migrating-from-ax-to-n4/HEAD/ax/swamp/alarm/alarm.adb -------------------------------------------------------------------------------- /ax/swamp/gator/gatorList.txt: -------------------------------------------------------------------------------- 1 | Gator List 2 | Gator Name: FatsDomino Length: 13.00 Weight: 871.00 3 | Gator Name: BuddyBolden Length: 14.00 Weight: 1064.00 4 | -------------------------------------------------------------------------------- /n4/demo/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tridium/summit16-migrating-from-ax-to-n4/HEAD/n4/demo/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /n4/final/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tridium/summit16-migrating-from-ax-to-n4/HEAD/n4/final/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /ax/swamp/history/station/seg3/GatorTracker.hdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tridium/summit16-migrating-from-ax-to-n4/HEAD/ax/swamp/history/station/seg3/GatorTracker.hdb -------------------------------------------------------------------------------- /ax/swamp/history/station/seg4/LogHistory.hdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tridium/summit16-migrating-from-ax-to-n4/HEAD/ax/swamp/history/station/seg4/LogHistory.hdb -------------------------------------------------------------------------------- /ax/swamp/history/station/seg7/AuditHistory.hdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tridium/summit16-migrating-from-ax-to-n4/HEAD/ax/swamp/history/station/seg7/AuditHistory.hdb -------------------------------------------------------------------------------- /n4/demo/nola/nola-rt/moduleTest-include.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /n4/demo/nola/nola-wb/moduleTest-include.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /n4/final/nola/nola-wb/moduleTest-include.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /ax/nola/module.palette: -------------------------------------------------------------------------------- 1 | 2 | 3 |

4 |

5 |

6 |
7 | -------------------------------------------------------------------------------- /n4/demo/vendor.gradle: -------------------------------------------------------------------------------- 1 | /* Vendor Configuration File */ 2 | group = 'niagarasummit' 3 | 4 | def moduleVersion = '4.0' 5 | def moduleVersionPatch = [:] 6 | version = "${moduleVersion}${moduleVersionPatch.get(project.name, '')}" 7 | -------------------------------------------------------------------------------- /n4/final/vendor.gradle: -------------------------------------------------------------------------------- 1 | /* Vendor Configuration File */ 2 | group = 'niagarasummit' 3 | 4 | def moduleVersion = '4.0' 5 | def moduleVersionPatch = [:] 6 | version = "${moduleVersion}${moduleVersionPatch.get(project.name, '')}" 7 | -------------------------------------------------------------------------------- /n4/demo/nola/nola-rt/module-include.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /n4/demo/nola/nola-rt/module.palette: -------------------------------------------------------------------------------- 1 | 2 | 3 |

4 |

5 |

6 |
7 | -------------------------------------------------------------------------------- /n4/final/nola/nola-rt/module-include.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /n4/final/nola/nola-rt/module.palette: -------------------------------------------------------------------------------- 1 | 2 | 3 |

4 |

5 |

6 |
7 | -------------------------------------------------------------------------------- /n4/final/nola/nola-rt/moduleTest-include.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /n4/demo/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue May 10 15:03:45 EDT 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip 7 | -------------------------------------------------------------------------------- /n4/demo/nola/nola-wb/module-include.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /n4/final/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue May 10 15:17:45 EDT 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip 7 | -------------------------------------------------------------------------------- /n4/final/nola/nola-wb/module-include.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ax/nola/module-include.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /n4/demo/environment.gradle: -------------------------------------------------------------------------------- 1 | /* Environment Configuration File */ 2 | 3 | // (Autogenerated header) 4 | // DO NOT MODIFY THIS FILE 5 | // 6 | // Its contents are auto-generated and your changes may be erased 7 | 8 | // If copying and using this directly, you will need to modify this to the correct 9 | // versions and locations of your Niagara installation. 10 | gradle.ext.niagara_dev_home = "C:/ns2016/devmig/n4/demo" 11 | gradle.ext.niagara_home = "C:/niagara/niagara-4.2.36.16" 12 | gradle.ext.niagara_user_home = "C:/Users/Craig/Niagara4.2/tridium" 13 | -------------------------------------------------------------------------------- /n4/final/environment.gradle: -------------------------------------------------------------------------------- 1 | /* Environment Configuration File */ 2 | 3 | // (Autogenerated header) 4 | // DO NOT MODIFY THIS FILE 5 | // 6 | // Its contents are auto-generated and your changes may be erased 7 | 8 | // If copying and using this directly, you will need to modify this to the correct 9 | // versions and locations of your Niagara installation. 10 | gradle.ext.niagara_dev_home = "C:/ns2016/devmig/n4/nolademo" 11 | gradle.ext.niagara_home = "C:/niagara/niagara-4.2.36.16" 12 | gradle.ext.niagara_user_home = "C:/Users/Craig/Niagara4.2/tridium" 13 | -------------------------------------------------------------------------------- /n4/demo/nola/nola-rt/nola-rt.gradle: -------------------------------------------------------------------------------- 1 | /* Module Build File */ 2 | 3 | description = "New Orleans Module Migration demo" 4 | ext { 5 | } 6 | niagaraModule { 7 | moduleName = "nola" 8 | preferredSymbol = "nola" 9 | runtimeProfile = "rt" 10 | } 11 | 12 | dependencies { 13 | compile "Tridium:nre:4.3" 14 | compile "Tridium:baja:4.3" 15 | compile "Tridium:alarm-rt:4.3" 16 | compile "Tridium:bql-rt:4.3" 17 | compile "Tridium:control-rt:4.3" 18 | compile "Tridium:file-rt:4.3" 19 | compile "Tridium:history-rt:4.3" 20 | } 21 | 22 | moduleTestJar { 23 | from('srcTest') { 24 | } 25 | } -------------------------------------------------------------------------------- /n4/final/nola/nola-rt/nola-rt.gradle: -------------------------------------------------------------------------------- 1 | /* Module Build File */ 2 | 3 | description = "New Orleans Module Migration demo" 4 | ext { 5 | } 6 | niagaraModule { 7 | moduleName = "nola" 8 | preferredSymbol = "nola" 9 | runtimeProfile = "rt" 10 | } 11 | 12 | dependencies { 13 | compile "Tridium:nre:4.3" 14 | compile "Tridium:baja:4.3" 15 | compile "Tridium:alarm-rt:4.3" 16 | compile "Tridium:bql-rt:4.3" 17 | compile "Tridium:control-rt:4.3" 18 | compile "Tridium:file-rt:4.3" 19 | compile "Tridium:gx-rt:4.3" 20 | compile "Tridium:history-rt:4.3" 21 | } 22 | 23 | //moduleTestJar { 24 | // from('srcTest') { 25 | // } 26 | //} 27 | -------------------------------------------------------------------------------- /n4/final/nola/nola-wb/nola-wb.gradle: -------------------------------------------------------------------------------- 1 | /* Module Build File */ 2 | 3 | description = "New Orleans Module Migration demo" 4 | ext { 5 | } 6 | niagaraModule { 7 | moduleName = "nola" 8 | preferredSymbol = "nola" 9 | runtimeProfile = "wb" 10 | } 11 | 12 | dependencies { 13 | compile "Tridium:nre:4.3" 14 | compile "Tridium:baja:4.3" 15 | compile "Tridium:alarm-rt:4.3" 16 | compile "Tridium:bajaui-wb:4.3" 17 | compile "Tridium:bql-rt:4.3" 18 | compile "Tridium:control-rt:4.3" 19 | compile "Tridium:file-rt:4.3" 20 | compile "Tridium:gx-rt:4.3" 21 | compile "Tridium:history-rt:4.3" 22 | compile "Tridium:workbench-wb:4.3" 23 | compile project(":nola-rt") 24 | } 25 | 26 | moduleTestJar { 27 | from('srcTest') { 28 | } 29 | } -------------------------------------------------------------------------------- /n4/demo/nola/nola-wb/nola-wb.gradle: -------------------------------------------------------------------------------- 1 | /* Module Build File */ 2 | 3 | description = "New Orleans Module Migration demo" 4 | ext { 5 | } 6 | niagaraModule { 7 | moduleName = "nola" 8 | preferredSymbol = "nola" 9 | runtimeProfile = "wb" 10 | } 11 | 12 | dependencies { 13 | compile "Tridium:nre:4.3" 14 | compile "Tridium:baja:4.3" 15 | compile "Tridium:alarm-rt:4.3" 16 | compile "Tridium:bajaui-wb:4.3" 17 | compile "Tridium:bql-rt:4.3" 18 | compile "Tridium:control-rt:4.3" 19 | compile "Tridium:file-rt:4.3" 20 | compile "Tridium:gx-rt:4.3" 21 | compile "Tridium:history-rt:4.3" 22 | compile "Tridium:workbench-wb:4.3" 23 | compile project(":nola-rt") 24 | } 25 | 26 | moduleTestJar { 27 | from('srcTest') { 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ax/nola/module.lexicon: -------------------------------------------------------------------------------- 1 | # 2 | # Lexicon for the nola module. 3 | # 4 | 5 | gatorTracker.couldNotAck=Could not ack alarm: {0} 6 | gatorTracker.couldNotQuery=Could not query {0} 7 | gatorTracker.queryByUuid.result=Alarm for UUID {0}: {1} 8 | gatorTracker.displayNames.result.elem={0}: {1} 9 | gatorTracker.displayNames.result=\nDisplay Names Table\n{0} 10 | gatorTracker.writeList.error=Error writing gator list to file: {0} 11 | gatorTracker.recordGators.msg=Finding record-breaking gators... 12 | gatorTracker.gatorStats=Gator Name: {0} Length: {1} Weight: {2} 13 | gatorTracker.gatorList.title=Gator List 14 | 15 | gators.col.time=Time 16 | gators.col.name=Name 17 | gators.col.length=Length 18 | gators.col.weight=Weight 19 | 20 | gatorView.add.label=Add 21 | gatorView.add.description=Track a Gator 22 | gatorView.add.icon=module://icons/x16/add.png 23 | gatorView.add.title=Add Tracked Gator 24 | gatorView.remove.label=Remove 25 | gatorView.remove.description=Remove Gator 26 | gatorView.remove.icon=module://icons/x16/delete.png 27 | -------------------------------------------------------------------------------- /n4/demo/nola/nola-rt/module.lexicon: -------------------------------------------------------------------------------- 1 | # 2 | # Lexicon for the nola module. 3 | # 4 | 5 | gatorTracker.couldNotAck=Could not ack alarm: {0} 6 | gatorTracker.couldNotQuery=Could not query {0} 7 | gatorTracker.queryByUuid.result=Alarm for UUID {0}: {1} 8 | gatorTracker.displayNames.result.elem={0}: {1} 9 | gatorTracker.displayNames.result=\nDisplay Names Table\n{0} 10 | gatorTracker.writeList.error=Error writing gator list to file: {0} 11 | gatorTracker.recordGators.msg=Finding record-breaking gators... 12 | gatorTracker.gatorStats=Gator Name: {0} Length: {1} Weight: {2} 13 | gatorTracker.gatorList.title=Gator List 14 | 15 | gators.col.time=Time 16 | gators.col.name=Name 17 | gators.col.length=Length 18 | gators.col.weight=Weight 19 | 20 | gatorView.add.label=Add 21 | gatorView.add.description=Track a Gator 22 | gatorView.add.icon=module://icons/x16/add.png 23 | gatorView.add.title=Add Tracked Gator 24 | gatorView.remove.label=Remove 25 | gatorView.remove.description=Remove Gator 26 | gatorView.remove.icon=module://icons/x16/delete.png 27 | -------------------------------------------------------------------------------- /n4/final/nola/nola-rt/module.lexicon: -------------------------------------------------------------------------------- 1 | # 2 | # Lexicon for the nola module. 3 | # 4 | 5 | gatorTracker.couldNotAck=Could not ack alarm: {0} 6 | gatorTracker.couldNotQuery=Could not query {0} 7 | gatorTracker.queryByUuid.result=Alarm for UUID {0}: {1} 8 | gatorTracker.displayNames.result.elem={0}: {1} 9 | gatorTracker.displayNames.result=\nDisplay Names Table\n{0} 10 | gatorTracker.writeList.error=Error writing gator list to file: {0} 11 | gatorTracker.recordGators.msg=Finding record-breaking gators... 12 | gatorTracker.gatorStats=Gator Name: {0} Length: {1} Weight: {2} 13 | gatorTracker.gatorList.title=Gator List 14 | 15 | gators.col.time=Time 16 | gators.col.name=Name 17 | gators.col.length=Length 18 | gators.col.weight=Weight 19 | 20 | gatorView.add.label=Add 21 | gatorView.add.description=Track a Gator 22 | gatorView.add.icon=module://icons/x16/add.png 23 | gatorView.add.title=Add Tracked Gator 24 | gatorView.remove.label=Remove 25 | gatorView.remove.description=Remove Gator 26 | gatorView.remove.icon=module://icons/x16/delete.png 27 | -------------------------------------------------------------------------------- /ax/nola/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /n4/final/build.gradle: -------------------------------------------------------------------------------- 1 | def getGradleProperty(String propName) { 2 | if (gradle.hasProperty(propName)) { 3 | gradle.getProperty(propName) 4 | } else { 5 | // Get system property, or, failing that, fall back to environment variable 6 | // This allows setting, e.g., -Pniagara_home=blah 7 | System.getProperty(propName) ?: System.getenv(propName) 8 | } 9 | } 10 | 11 | ext.niagara_home = getGradleProperty('niagara_home') 12 | ext.niagara_dev_home = getGradleProperty('niagara_dev_home') 13 | ext.niagara_user_home = getGradleProperty('niagara_user_home') 14 | 15 | apply from: "${rootProject.ext.niagara_home}/etc/gradle/eclipse.gradle" 16 | apply from: "${rootProject.ext.niagara_home}/etc/gradle/idea.gradle" 17 | 18 | gradle.beforeProject { p -> 19 | configure(p) { 20 | def vendorSettings = file("${rootDir}/vendor.gradle") 21 | if (vendorSettings.exists()) { 22 | apply from: vendorSettings 23 | } 24 | apply from: "${rootProject.ext.niagara_home}/etc/gradle/niagara.gradle" 25 | } 26 | } 27 | 28 | tasks.addRule(""" 29 | Pattern: [jar[Test]|clean|]/[path]: Run a Gradle task against a set of modules rooted at path. 30 | """) { String taskName -> 31 | def matcher = taskName =~ /(.*?)(Test)?\/(.*)/ 32 | if (matcher) { 33 | def command = matcher.group(1) 34 | def includeTestModules = matcher.group(2) == 'Test' 35 | def path = file("${projectDir}/${matcher.group(3)}").toPath() 36 | 37 | assert path.toFile().exists() 38 | def targetProjects = subprojects.findAll { it.projectDir.toPath().startsWith(path) } 39 | 40 | // default is build command and build is an alias for Gradle's jar task 41 | if (command.isEmpty() || command == 'build') { command = 'jar' } 42 | 43 | // Create task for subproject 44 | task(taskName, dependsOn: targetProjects.tasks[command]) 45 | if (includeTestModules && command == 'jar') { 46 | tasks[taskName].dependsOn targetProjects.moduleTestJar 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /n4/demo/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | def getGradleProperty(String propName) { 3 | if (gradle.hasProperty(propName)) { 4 | gradle.getProperty(propName) 5 | } else { 6 | // Get system property, or, failing that, fall back to environment variable 7 | // This allows setting, e.g., -Pniagara_home=blah 8 | System.getProperty(propName) ?: System.getenv(propName) 9 | } 10 | } 11 | 12 | ext.niagara_home = getGradleProperty('niagara_home') 13 | ext.niagara_dev_home = getGradleProperty('niagara_dev_home') 14 | ext.niagara_user_home = getGradleProperty('niagara_user_home') 15 | 16 | apply from: "${rootProject.ext.niagara_home}/etc/gradle/eclipse.gradle" 17 | apply from: "${rootProject.ext.niagara_home}/etc/gradle/idea.gradle" 18 | 19 | gradle.beforeProject { p -> 20 | configure(p) { 21 | def vendorSettings = file("${rootDir}/vendor.gradle") 22 | if (vendorSettings.exists()) { 23 | apply from: vendorSettings 24 | } 25 | apply from: "${rootProject.ext.niagara_home}/etc/gradle/niagara.gradle" 26 | } 27 | } 28 | 29 | tasks.addRule(""" 30 | Pattern: [jar[Test]|clean|]/[path]: Run a Gradle task against a set of modules rooted at path. 31 | """) { String taskName -> 32 | def matcher = taskName =~ /(.*?)(Test)?\/(.*)/ 33 | if (matcher) { 34 | def command = matcher.group(1) 35 | def includeTestModules = matcher.group(2) == 'Test' 36 | def path = file("${projectDir}/${matcher.group(3)}").toPath() 37 | 38 | assert path.toFile().exists() 39 | def targetProjects = subprojects.findAll { it.projectDir.toPath().startsWith(path) } 40 | 41 | // default is build command and build is an alias for Gradle's jar task 42 | if (command.isEmpty() || command == 'build') { command = 'jar' } 43 | 44 | // Create task for subproject 45 | task(taskName, dependsOn: targetProjects.tasks[command]) 46 | if (includeTestModules && command == 'jar') { 47 | tasks[taskName].dependsOn targetProjects.moduleTestJar 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /n4/demo/settings.gradle: -------------------------------------------------------------------------------- 1 | import groovy.io.FileVisitResult 2 | import groovy.io.FileType 3 | 4 | 5 | def discoveredProjects = [:] as Map 6 | 7 | ext { 8 | // CONFIGURE your sub-project folders here. 9 | // This will include ALL sub-folders as sub-projects. 10 | niagaraRoots = ['.'] 11 | // To explicitly define sub-project folders, name them in the array like this 12 | //niagaraRoots = ['componentLinks', 'envCtrlDriver'] 13 | 14 | // CONFIGURE any directories to exclude from search for nested sub-projects 15 | excludeDirs = ['.hg', 'build', 'out', 'src', 'srcTest'] 16 | } 17 | 18 | // OR set the 'userRepos' gradle property. 19 | // 20 | if (hasProperty('userRepos')) { 21 | settings.ext.niagaraRoots += userRepos.split(",").collect() 22 | } 23 | 24 | // my-settings.gradle. 25 | // 26 | def mySettings = file('my-settings.gradle') 27 | if (mySettings.exists()) { 28 | apply from: mySettings 29 | } 30 | 31 | def environment = file('environment.gradle') 32 | if (environment.exists()) { 33 | apply from: environment 34 | } 35 | 36 | // DO NOT MODIFY the niagaraRoots configuration 37 | niagaraRoots.collect({ file(it) }).findAll({ it.exists() }).each { File projectRoot -> 38 | projectRoot.traverse( 39 | type: FileType.DIRECTORIES, 40 | preRoot: true, 41 | preDir: { File projectDir -> 42 | def projectName = projectDir.name 43 | if (excludeDirs.contains(projectName)) { 44 | return FileVisitResult.SKIP_SUBTREE 45 | } 46 | 47 | File buildScript = new File(projectDir, "${projectName}.gradle") 48 | if (buildScript.exists()) { 49 | discoveredProjects[projectName] = projectDir 50 | include projectName 51 | return FileVisitResult.SKIP_SUBTREE 52 | } 53 | } 54 | ) 55 | } 56 | 57 | // Set rootProject.name for your project 58 | rootProject.name = 'niagara' 59 | rootProject.children.each { project -> 60 | project.projectDir = discoveredProjects[project.name] 61 | project.buildFileName = "${project.name}.gradle" 62 | assert project.projectDir.isDirectory() 63 | assert project.buildFile.isFile() 64 | } 65 | -------------------------------------------------------------------------------- /n4/final/settings.gradle: -------------------------------------------------------------------------------- 1 | import groovy.io.FileVisitResult 2 | import groovy.io.FileType 3 | 4 | 5 | def discoveredProjects = [:] as Map 6 | 7 | ext { 8 | // CONFIGURE your sub-project folders here. 9 | // This will include ALL sub-folders as sub-projects. 10 | niagaraRoots = ['.'] 11 | // To explicitly define sub-project folders, name them in the array like this 12 | //niagaraRoots = ['componentLinks', 'envCtrlDriver'] 13 | 14 | // CONFIGURE any directories to exclude from search for nested sub-projects 15 | excludeDirs = ['.hg', 'build', 'out', 'src', 'srcTest'] 16 | } 17 | 18 | // OR set the 'userRepos' gradle property. 19 | // 20 | if (hasProperty('userRepos')) { 21 | settings.ext.niagaraRoots += userRepos.split(",").collect() 22 | } 23 | 24 | // my-settings.gradle. 25 | // 26 | def mySettings = file('my-settings.gradle') 27 | if (mySettings.exists()) { 28 | apply from: mySettings 29 | } 30 | 31 | def environment = file('environment.gradle') 32 | if (environment.exists()) { 33 | apply from: environment 34 | } 35 | 36 | // DO NOT MODIFY the niagaraRoots configuration 37 | niagaraRoots.collect({ file(it) }).findAll({ it.exists() }).each { File projectRoot -> 38 | projectRoot.traverse( 39 | type: FileType.DIRECTORIES, 40 | preRoot: true, 41 | preDir: { File projectDir -> 42 | def projectName = projectDir.name 43 | if (excludeDirs.contains(projectName)) { 44 | return FileVisitResult.SKIP_SUBTREE 45 | } 46 | 47 | File buildScript = new File(projectDir, "${projectName}.gradle") 48 | if (buildScript.exists()) { 49 | discoveredProjects[projectName] = projectDir 50 | include projectName 51 | return FileVisitResult.SKIP_SUBTREE 52 | } 53 | } 54 | ) 55 | } 56 | 57 | // Set rootProject.name for your project 58 | rootProject.name = 'niagara' 59 | rootProject.children.each { project -> 60 | project.projectDir = discoveredProjects[project.name] 61 | project.buildFileName = "${project.name}.gradle" 62 | assert project.projectDir.isDirectory() 63 | assert project.buildFile.isFile() 64 | } 65 | -------------------------------------------------------------------------------- /n4/demo/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /n4/final/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /ax/swamp/console.txt: -------------------------------------------------------------------------------- 1 | WARNING [15:11:58 11-May-16 EDT][timezone] No niagara.timezone in !/lib/system.properties, set one using the Platform Administrator 2 | MESSAGE [15:11:58 11-May-16 EDT][sys.registry] Up-to-date [15ms] 3 | MESSAGE [15:11:58 11-May-16 EDT][sys.registry] Loaded [32ms] 4 | MESSAGE [15:11:58 11-May-16 EDT][sys] Baja runtime booted ("d:\niagara\niagara-3.8.41") on Win-CE9A-87C6-1526-58EF 5 | MESSAGE [15:11:58 11-May-16 EDT][sys] Loading "d:\niagara\niagara-3.8.41\stations\swamp\config.bog"... 6 | MESSAGE [15:11:59 11-May-16 EDT][sys] Loaded (468ms) 7 | MESSAGE [15:11:59 11-May-16 EDT][alarm.database] Loading... 8 | MESSAGE [15:11:59 11-May-16 EDT][alarm.database] Loaded [0ms, 2 alarms, 8 pages] 9 | MESSAGE [15:11:59 11-May-16 EDT][sys] Services Initialized (78ms) 10 | MESSAGE [15:11:59 11-May-16 EDT][sys.mixin] Updated [0ms] 11 | MESSAGE [15:11:59 11-May-16 EDT][sys.mixin] Updated [0ms] 12 | MESSAGE [15:12:00 11-May-16 EDT][sys] Niagara Runtime Environment: 3.8.41 13 | MESSAGE [15:12:00 11-May-16 EDT][sys] *** Station Started (437ms) [1881ms total] *** 14 | niagara>WARNING [15:12:00 11-May-16 EDT][crypto] cert chain for tridium has an out of date certificate 15 | WARNING [15:12:00 11-May-16 EDT][crypto] cert chain for tridium has an out of date certificate 16 | MESSAGE [15:12:00 11-May-16 EDT][web.server] HTTPS server started on port [443] 17 | MESSAGE [15:12:00 11-May-16 EDT][fox] FOXS server started on port [4911] 18 | MESSAGE [15:12:01 11-May-16 EDT][history.db] Starting async warmup of history config index... 19 | MESSAGE [15:12:01 11-May-16 EDT][history.db] Async history config index warmup completed in 15 ms. 20 | WARNING [15:12:02 11-May-16 EDT][fox] Closing session [0: Server 127.0.0.1:45741 doesn't match opened session [null] 21 | MESSAGE [15:12:04 11-May-16 EDT][fox] Opened: 1 <- 1 :: Workbench @ VA51LT5MKCM32 22 | MESSAGE [15:12:29 11-May-16 EDT][sys] Saving station... 23 | MESSAGE [15:12:29 11-May-16 EDT][sys] Saved d:\niagara\niagara-3.8.41\stations\swamp\config.bog (172ms) 24 | MESSAGE [15:12:29 11-May-16 EDT][backup] Backup starting... 25 | MESSAGE [15:12:31 11-May-16 EDT][backup] Finished backup, 105 files [1941ms] 26 | MESSAGE [15:12:44 11-May-16 EDT][console] Quit 27 | MESSAGE [15:12:44 11-May-16 EDT][sys] Saving station... 28 | MESSAGE [15:12:44 11-May-16 EDT][sys] Saved d:\niagara\niagara-3.8.41\stations\swamp\config.bog (156ms) 29 | MESSAGE [15:12:44 11-May-16 EDT][fox] Closed: 1 <- 1 :: Workbench @ VA51LT5MKCM32 30 | MESSAGE [15:12:44 11-May-16 EDT][sys] Station stopped 31 | MESSAGE [15:12:44 11-May-16 EDT][fox] Service stopped 32 | MESSAGE [15:12:44 11-May-16 EDT][fox] FOXS server stopped on port [4911] 33 | WARNING [15:12:44 11-May-16 EDT][web.server] Server accept exception: socket closed 34 | MESSAGE [15:12:44 11-May-16 EDT][web.server] HTTPS server stopped on port [443] 35 | MESSAGE [15:12:44 11-May-16 EDT][sys] Services stopped 36 | MESSAGE [15:12:44 11-May-16 EDT][sys] *** Station shutdown *** 37 | 38 | 39 | g station... 40 | MESSAGE [15:12:29 11-May-16 EDT][sys] Saved d:\niagara\niagara-3.8.41\stations\swamp\config.bog (172ms) 41 | MESSAGE [15:12:29 11-May-16 EDT][backup] Backup starting... 42 | MESSAGE [15:12:31 11-May-16 EDT][backup] Finished -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Tridium Open Source License 2 | =========================== 3 | 4 | Copyright (c) 2014, Tridium, Inc. 5 | 6 | All rights reserved. 7 | 8 | 1. Definitions. 9 | 10 | "You" shall mean any person or entity who uses, modifies and/or distributes 11 | the Work in any manner and thus is bound by this License. 12 | 13 | "Work" shall mean the work of authorship, whether in Source or Object form, 14 | made available under this License. 15 | 16 | "Derivative Works" shall mean any modification of the Work, whether in source 17 | or object form. 18 | 19 | "Licensor" shall mean Tridium, Inc. 20 | 21 | 2. Licensor hereby grants to You a license to use the Work and/or redistribute 22 | the Work, in source and/or binary forms, without modification, provided that 23 | all of the following conditions are met: 24 | 25 | a) Redistributions of the Work by You of source code must retain the above 26 | copyright notice, the list of conditions in this License and the 27 | disclaimer set forth in Section 3 below; 28 | b) Redistributions of the Work by You in binary form must reproduce the 29 | above copyright notice, the list of conditions in this License and the 30 | disclaimer set forth in Section 3 below in all documentation and materials 31 | provided with the distribution; and 32 | c) You may not charge third parties to redistribute the Work. 33 | 34 | 3. THIS SOFTWARE IS PROVIDED BY LICENSOR, THE COPYRIGHT HOLDERS AND 35 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 36 | NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 37 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 38 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 39 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 40 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 41 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 42 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 43 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 44 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | 46 | 4. Licensor hereby grants to You a license to use a Derivative Work and 47 | distribute a Derivative Work, in source and/or binary forms, provided that 48 | all of the following conditions are met: 49 | 50 | a) You must clearly mark the Derivative Work as having been modified by You; 51 | b) You must distribute the Derivative Work under the terms of this License 52 | including the disclaimer set forth in Section 3 above; and 53 | c) The names of the Licensor, copyright holder or contributors of the Work 54 | may not be used in any manner to endorse or promote a Derivative Work. 55 | 56 | 5. This License shall terminate automatically and You may no longer exercise 57 | any of the rights granted to You by this License as of the date You (or any 58 | person or company affiliated with You) commence an action, including a 59 | cross-claim or counterclaim, against Licensor, any affiliated company of 60 | Licensor or any licensee of the Work alleging that the Work infringes a 61 | patent. 62 | 63 | -------------------------------------------------------------------------------- /n4/final/nola/nola-rt/srcTest/test/com/niagarasummit/nola/BTrackGatorTest.java: -------------------------------------------------------------------------------- 1 | package test.com.niagarasummit.nola; 2 | 3 | import javax.baja.nre.annotations.NiagaraType; 4 | import javax.baja.sys.BComponent; 5 | import javax.baja.sys.BStation; 6 | import javax.baja.sys.BString; 7 | import javax.baja.sys.BValue; 8 | import javax.baja.sys.Sys; 9 | import javax.baja.sys.Type; 10 | import javax.baja.test.BTestNg; 11 | import com.niagarasummit.nola.BGator; 12 | import com.niagarasummit.nola.BGatorTracker; 13 | import org.testng.Assert; 14 | import org.testng.annotations.AfterTest; 15 | import org.testng.annotations.BeforeTest; 16 | import org.testng.annotations.Test; 17 | 18 | /** 19 | * BTrackGatorTest 20 | * Unit tests to make sure the Gator Tracker behaves correctly. 21 | */ 22 | @NiagaraType 23 | public class BTrackGatorTest 24 | extends BTestNg 25 | { 26 | /*+ ------------ BEGIN BAJA AUTO GENERATED CODE ------------ +*/ 27 | /*@ $test.com.niagarasummit.nola.BTrackGatorTest(2979906276)1.0$ @*/ 28 | /* Generated Tue May 10 15:18:05 EDT 2016 by Slot-o-Matic (c) Tridium, Inc. 2012 */ 29 | 30 | //////////////////////////////////////////////////////////////// 31 | // Type 32 | //////////////////////////////////////////////////////////////// 33 | 34 | @Override 35 | public Type getType() { return TYPE; } 36 | public static final Type TYPE = Sys.loadType(BTrackGatorTest.class); 37 | 38 | /*+ ------------ END BAJA AUTO GENERATED CODE -------------- +*/ 39 | private BGatorTracker gatorTracker; 40 | 41 | /** 42 | * Before the tests, we need to start a station with the gator tracker in it to ensure 43 | * that the tracker is running in the proper environment. 44 | */ 45 | @BeforeTest 46 | @Override 47 | public void setup() throws Exception 48 | { 49 | // Create a test station handler 50 | if (stationHandler == null) 51 | { 52 | stationHandler = createTestStation(); 53 | } 54 | 55 | // Configure it with the necessary services. 56 | BStation station = stationHandler.getStation(); 57 | configureTestStation(station, testStationName); 58 | 59 | // Start the test station 60 | stationHandler.startStation(); 61 | 62 | // Add the gator tracker. 63 | // Ensure no alarms or history records are generated for this test. 64 | gatorTracker = new BGatorTracker(); 65 | gatorTracker.setRecordLength(100); 66 | gatorTracker.getGatorLogger().setEnabled(false); 67 | station.add(null, gatorTracker); 68 | 69 | } 70 | 71 | /** 72 | * Make sure to clean up the station resources we started. 73 | */ 74 | @AfterTest 75 | @Override 76 | public void cleanup() 77 | { 78 | // Clean up the handler 79 | if (stationHandler != null) 80 | { 81 | // First, stop the test station 82 | stationHandler.stopStation(); 83 | 84 | // Then release its resources 85 | stationHandler.releaseStation(); 86 | stationHandler = null; 87 | } 88 | 89 | // Also clear the gator tracker reference 90 | gatorTracker = null; 91 | } 92 | 93 | @Test 94 | /** 95 | * Ensure that the new gator addition works. 96 | */ 97 | public void addGator() 98 | { 99 | BGator[] gators = gatorTracker.getChildren(BGator.class); 100 | int beforeLen = gators.length; 101 | 102 | gatorTracker.doTrackGator(BString.make("Allie")); 103 | 104 | gators = gatorTracker.getChildren(BGator.class); 105 | int afterLen = gators.length; 106 | 107 | // Should be one more gator than before 108 | Assert.assertEquals(afterLen, beforeLen + 1, "after should have one more gator than before"); 109 | 110 | // Should be able to find a child named "Allie" of Type BGator 111 | BValue gator = gatorTracker.get("Allie"); 112 | Assert.assertNotNull(gator, "'Allie' property of gatorTracker should not be null"); 113 | Assert.assertTrue(gator instanceof BGator, "gator should be an instance of BGator"); 114 | } 115 | 116 | 117 | //////////////////////////////////////////////////////////////// 118 | // Support 119 | //////////////////////////////////////////////////////////////// 120 | 121 | /** 122 | * Here we need to add any services the GatorTracker expects to interact with. 123 | * @param station reference to station root 124 | * @param stationName station name 125 | * @throws Exception 126 | */ 127 | private void configureTestStation(BStation station, String stationName) 128 | throws Exception 129 | { 130 | BComponent services = station.getServices(); 131 | services.add(ALARM_SERVICE, newInstance("alarm:AlarmService")); 132 | 133 | station.setStationName(stationName); 134 | } 135 | 136 | /** 137 | * Convenience method for adding new instance of a specified {@link Type}. 138 | * @param type typespec to be created 139 | * @return a new instance of that Type 140 | * @throws Exception 141 | */ 142 | public BComponent newInstance(String type) throws Exception 143 | { 144 | return (BComponent) Sys.getType(type).getInstance(); 145 | } 146 | 147 | 148 | //////////////////////////////////////////////////////////////// 149 | // Attributes 150 | //////////////////////////////////////////////////////////////// 151 | 152 | protected static final String ALARM_SERVICE = "AlarmService"; 153 | protected static final String HISTORY_SERVICE = "HistoryService"; 154 | protected static String testStationName = "nolaTest"; 155 | 156 | private TestStationHandler stationHandler; 157 | } 158 | -------------------------------------------------------------------------------- /n4/demo/nola/nola-rt/src/com/niagarasummit/nola/BGator.java: -------------------------------------------------------------------------------- 1 | package com.niagarasummit.nola; 2 | 3 | import javax.baja.sys.BAbsTime; 4 | import javax.baja.sys.BFacets; 5 | import javax.baja.sys.BStruct; 6 | import javax.baja.sys.Flags; 7 | import javax.baja.sys.Property; 8 | import javax.baja.sys.Sys; 9 | import javax.baja.sys.Type; 10 | import javax.baja.units.BUnit; 11 | import javax.baja.nre.annotations.NiagaraProperty; 12 | import javax.baja.nre.annotations.NiagaraType; 13 | import javax.baja.nre.annotations.Facet; 14 | 15 | /** 16 | * Simple class to represent vital statistics of an alligator tracked by the 17 | * GatorTracker application. 18 | */ 19 | @NiagaraType 20 | /** 21 | * Time of creation 22 | */ 23 | @NiagaraProperty( 24 | name = "spawnTime", 25 | type = "BAbsTime", 26 | defaultValue = "BAbsTime.make()", 27 | flags = Flags.READONLY 28 | ) 29 | /** 30 | * Gator length 31 | */ 32 | @NiagaraProperty( 33 | name = "length", 34 | type = "int", 35 | defaultValue = "0", 36 | flags = Flags.READONLY, 37 | facets = @Facet("BFacets.make(BFacets.UNITS, BUnit.getUnit(\"foot\"))") 38 | ) 39 | /** 40 | * Gator weight 41 | */ 42 | @NiagaraProperty( 43 | name = "weight", 44 | type = "int", 45 | defaultValue = "0", 46 | flags = Flags.READONLY, 47 | facets = @Facet("BFacets.make(BFacets.UNITS, BUnit.getUnit(\"pound\"))") 48 | ) 49 | /** 50 | * Is this a record? 51 | */ 52 | @NiagaraProperty( 53 | name = "isRecord", 54 | type = "boolean", 55 | defaultValue = "false", 56 | flags = Flags.READONLY 57 | ) 58 | public class BGator extends BStruct 59 | { 60 | 61 | 62 | /*+ ------------ BEGIN BAJA AUTO GENERATED CODE ------------ +*/ 63 | /*@ $com.niagarasummit.nola.BGator(1045536858)1.0$ @*/ 64 | /* Generated Wed May 11 16:11:28 EDT 2016 by Slot-o-Matic (c) Tridium, Inc. 2012 */ 65 | 66 | //////////////////////////////////////////////////////////////// 67 | // Property "spawnTime" 68 | //////////////////////////////////////////////////////////////// 69 | 70 | /** 71 | * Slot for the {@code spawnTime} property. 72 | * Time of creation 73 | * @see #getSpawnTime 74 | * @see #setSpawnTime 75 | */ 76 | public static final Property spawnTime = newProperty(Flags.READONLY, BAbsTime.make(), null); 77 | 78 | /** 79 | * Get the {@code spawnTime} property. 80 | * Time of creation 81 | * @see #spawnTime 82 | */ 83 | public BAbsTime getSpawnTime() { return (BAbsTime)get(spawnTime); } 84 | 85 | /** 86 | * Set the {@code spawnTime} property. 87 | * Time of creation 88 | * @see #spawnTime 89 | */ 90 | public void setSpawnTime(BAbsTime v) { set(spawnTime, v, null); } 91 | 92 | //////////////////////////////////////////////////////////////// 93 | // Property "length" 94 | //////////////////////////////////////////////////////////////// 95 | 96 | /** 97 | * Slot for the {@code length} property. 98 | * Gator length 99 | * @see #getLength 100 | * @see #setLength 101 | */ 102 | public static final Property length = newProperty(Flags.READONLY, 0, BFacets.make(BFacets.UNITS, BUnit.getUnit("foot"))); 103 | 104 | /** 105 | * Get the {@code length} property. 106 | * Gator length 107 | * @see #length 108 | */ 109 | public int getLength() { return getInt(length); } 110 | 111 | /** 112 | * Set the {@code length} property. 113 | * Gator length 114 | * @see #length 115 | */ 116 | public void setLength(int v) { setInt(length, v, null); } 117 | 118 | //////////////////////////////////////////////////////////////// 119 | // Property "weight" 120 | //////////////////////////////////////////////////////////////// 121 | 122 | /** 123 | * Slot for the {@code weight} property. 124 | * Gator weight 125 | * @see #getWeight 126 | * @see #setWeight 127 | */ 128 | public static final Property weight = newProperty(Flags.READONLY, 0, BFacets.make(BFacets.UNITS, BUnit.getUnit("pound"))); 129 | 130 | /** 131 | * Get the {@code weight} property. 132 | * Gator weight 133 | * @see #weight 134 | */ 135 | public int getWeight() { return getInt(weight); } 136 | 137 | /** 138 | * Set the {@code weight} property. 139 | * Gator weight 140 | * @see #weight 141 | */ 142 | public void setWeight(int v) { setInt(weight, v, null); } 143 | 144 | //////////////////////////////////////////////////////////////// 145 | // Property "isRecord" 146 | //////////////////////////////////////////////////////////////// 147 | 148 | /** 149 | * Slot for the {@code isRecord} property. 150 | * Is this a record? 151 | * @see #getIsRecord 152 | * @see #setIsRecord 153 | */ 154 | public static final Property isRecord = newProperty(Flags.READONLY, false, null); 155 | 156 | /** 157 | * Get the {@code isRecord} property. 158 | * Is this a record? 159 | * @see #isRecord 160 | */ 161 | public boolean getIsRecord() { return getBoolean(isRecord); } 162 | 163 | /** 164 | * Set the {@code isRecord} property. 165 | * Is this a record? 166 | * @see #isRecord 167 | */ 168 | public void setIsRecord(boolean v) { setBoolean(isRecord, v, null); } 169 | 170 | //////////////////////////////////////////////////////////////// 171 | // Type 172 | //////////////////////////////////////////////////////////////// 173 | 174 | @Override 175 | public Type getType() { return TYPE; } 176 | public static final Type TYPE = Sys.loadType(BGator.class); 177 | 178 | /*+ ------------ END BAJA AUTO GENERATED CODE -------------- +*/ 179 | 180 | public BGator() {} 181 | 182 | public BGator(int l, int w) 183 | { 184 | setLength(l); 185 | setWeight(w); 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /n4/final/nola/nola-rt/src/com/niagarasummit/nola/BGator.java: -------------------------------------------------------------------------------- 1 | package com.niagarasummit.nola; 2 | 3 | import javax.baja.sys.BAbsTime; 4 | import javax.baja.sys.BFacets; 5 | import javax.baja.sys.BStruct; 6 | import javax.baja.sys.Flags; 7 | import javax.baja.sys.Property; 8 | import javax.baja.sys.Sys; 9 | import javax.baja.sys.Type; 10 | import javax.baja.units.BUnit; 11 | import javax.baja.nre.annotations.NiagaraProperty; 12 | import javax.baja.nre.annotations.NiagaraType; 13 | import javax.baja.nre.annotations.Facet; 14 | 15 | /** 16 | * Simple class to represent vital statistics of an alligator tracked by the 17 | * GatorTracker application. 18 | */ 19 | @NiagaraType 20 | /** 21 | * Time of creation 22 | */ 23 | @NiagaraProperty( 24 | name = "spawnTime", 25 | type = "BAbsTime", 26 | defaultValue = "BAbsTime.make()", 27 | flags = Flags.READONLY 28 | ) 29 | /** 30 | * Gator length 31 | */ 32 | @NiagaraProperty( 33 | name = "length", 34 | type = "int", 35 | defaultValue = "0", 36 | flags = Flags.READONLY, 37 | facets = @Facet("BFacets.make(BFacets.UNITS, BUnit.getUnit(\"foot\"))") 38 | ) 39 | /** 40 | * Gator weight 41 | */ 42 | @NiagaraProperty( 43 | name = "weight", 44 | type = "int", 45 | defaultValue = "0", 46 | flags = Flags.READONLY, 47 | facets = @Facet("BFacets.make(BFacets.UNITS, BUnit.getUnit(\"pound\"))") 48 | ) 49 | /** 50 | * Is this a record? 51 | */ 52 | @NiagaraProperty( 53 | name = "isRecord", 54 | type = "boolean", 55 | defaultValue = "false", 56 | flags = Flags.READONLY 57 | ) 58 | public class BGator extends BStruct 59 | { 60 | 61 | 62 | /*+ ------------ BEGIN BAJA AUTO GENERATED CODE ------------ +*/ 63 | /*@ $com.niagarasummit.nola.BGator(1045536858)1.0$ @*/ 64 | /* Generated Wed May 11 16:12:23 EDT 2016 by Slot-o-Matic (c) Tridium, Inc. 2012 */ 65 | 66 | //////////////////////////////////////////////////////////////// 67 | // Property "spawnTime" 68 | //////////////////////////////////////////////////////////////// 69 | 70 | /** 71 | * Slot for the {@code spawnTime} property. 72 | * Time of creation 73 | * @see #getSpawnTime 74 | * @see #setSpawnTime 75 | */ 76 | public static final Property spawnTime = newProperty(Flags.READONLY, BAbsTime.make(), null); 77 | 78 | /** 79 | * Get the {@code spawnTime} property. 80 | * Time of creation 81 | * @see #spawnTime 82 | */ 83 | public BAbsTime getSpawnTime() { return (BAbsTime)get(spawnTime); } 84 | 85 | /** 86 | * Set the {@code spawnTime} property. 87 | * Time of creation 88 | * @see #spawnTime 89 | */ 90 | public void setSpawnTime(BAbsTime v) { set(spawnTime, v, null); } 91 | 92 | //////////////////////////////////////////////////////////////// 93 | // Property "length" 94 | //////////////////////////////////////////////////////////////// 95 | 96 | /** 97 | * Slot for the {@code length} property. 98 | * Gator length 99 | * @see #getLength 100 | * @see #setLength 101 | */ 102 | public static final Property length = newProperty(Flags.READONLY, 0, BFacets.make(BFacets.UNITS, BUnit.getUnit("foot"))); 103 | 104 | /** 105 | * Get the {@code length} property. 106 | * Gator length 107 | * @see #length 108 | */ 109 | public int getLength() { return getInt(length); } 110 | 111 | /** 112 | * Set the {@code length} property. 113 | * Gator length 114 | * @see #length 115 | */ 116 | public void setLength(int v) { setInt(length, v, null); } 117 | 118 | //////////////////////////////////////////////////////////////// 119 | // Property "weight" 120 | //////////////////////////////////////////////////////////////// 121 | 122 | /** 123 | * Slot for the {@code weight} property. 124 | * Gator weight 125 | * @see #getWeight 126 | * @see #setWeight 127 | */ 128 | public static final Property weight = newProperty(Flags.READONLY, 0, BFacets.make(BFacets.UNITS, BUnit.getUnit("pound"))); 129 | 130 | /** 131 | * Get the {@code weight} property. 132 | * Gator weight 133 | * @see #weight 134 | */ 135 | public int getWeight() { return getInt(weight); } 136 | 137 | /** 138 | * Set the {@code weight} property. 139 | * Gator weight 140 | * @see #weight 141 | */ 142 | public void setWeight(int v) { setInt(weight, v, null); } 143 | 144 | //////////////////////////////////////////////////////////////// 145 | // Property "isRecord" 146 | //////////////////////////////////////////////////////////////// 147 | 148 | /** 149 | * Slot for the {@code isRecord} property. 150 | * Is this a record? 151 | * @see #getIsRecord 152 | * @see #setIsRecord 153 | */ 154 | public static final Property isRecord = newProperty(Flags.READONLY, false, null); 155 | 156 | /** 157 | * Get the {@code isRecord} property. 158 | * Is this a record? 159 | * @see #isRecord 160 | */ 161 | public boolean getIsRecord() { return getBoolean(isRecord); } 162 | 163 | /** 164 | * Set the {@code isRecord} property. 165 | * Is this a record? 166 | * @see #isRecord 167 | */ 168 | public void setIsRecord(boolean v) { setBoolean(isRecord, v, null); } 169 | 170 | //////////////////////////////////////////////////////////////// 171 | // Type 172 | //////////////////////////////////////////////////////////////// 173 | 174 | @Override 175 | public Type getType() { return TYPE; } 176 | public static final Type TYPE = Sys.loadType(BGator.class); 177 | 178 | /*+ ------------ END BAJA AUTO GENERATED CODE -------------- +*/ 179 | 180 | public BGator() {} 181 | 182 | public BGator(int l, int w) 183 | { 184 | setLength(l); 185 | setWeight(w); 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /n4/demo/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /n4/final/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /ax/nola/src/com/niagarasummit/nola/BGator.java: -------------------------------------------------------------------------------- 1 | package com.niagarasummit.nola; 2 | 3 | import javax.baja.sys.BAbsTime; 4 | import javax.baja.sys.BFacets; 5 | import javax.baja.sys.BStruct; 6 | import javax.baja.sys.Flags; 7 | import javax.baja.sys.Property; 8 | import javax.baja.sys.Sys; 9 | import javax.baja.sys.Type; 10 | import javax.baja.units.BUnit; 11 | 12 | /** 13 | * Simple class to represent vital statistics of an alligator tracked by the 14 | * GatorTracker application. 15 | */ 16 | public class BGator extends BStruct 17 | { 18 | /*- 19 | class BGator 20 | { 21 | properties 22 | { 23 | spawnTime: BAbsTime 24 | -- Time of creation 25 | flags { readonly } 26 | default {[ BAbsTime.make() ]} 27 | length: int 28 | -- Gator length 29 | flags { readonly } 30 | default {[ 0 ]} 31 | slotfacets {[ BFacets.make(BFacets.UNITS, BUnit.getUnit("foot")) ]} 32 | weight: int 33 | -- Gator weight 34 | flags { readonly } 35 | default {[ 0 ]} 36 | slotfacets {[ BFacets.make(BFacets.UNITS, BUnit.getUnit("pound")) ]} 37 | isRecord: boolean 38 | -- Is this a record? 39 | flags { readonly } 40 | default {[ false ]} 41 | } 42 | } 43 | -*/ 44 | /*+ ------------ BEGIN BAJA AUTO GENERATED CODE ------------ +*/ 45 | /*@ $com.niagarasummit.nola.BGator(3543631432)1.0$ @*/ 46 | /* Generated Wed May 11 14:31:30 EDT 2016 by Slot-o-Matic 2000 (c) Tridium, Inc. 2000 */ 47 | 48 | //////////////////////////////////////////////////////////////// 49 | // Property "spawnTime" 50 | //////////////////////////////////////////////////////////////// 51 | 52 | /** 53 | * Slot for the spawnTime property. 54 | * Time of creation 55 | * @see com.niagarasummit.nola.BGator#getSpawnTime 56 | * @see com.niagarasummit.nola.BGator#setSpawnTime 57 | */ 58 | public static final Property spawnTime = newProperty(Flags.READONLY, BAbsTime.make(),null); 59 | 60 | /** 61 | * Get the spawnTime property. 62 | * Time of creation 63 | * @see com.niagarasummit.nola.BGator#spawnTime 64 | */ 65 | public BAbsTime getSpawnTime() { return (BAbsTime)get(spawnTime); } 66 | 67 | /** 68 | * Set the spawnTime property. 69 | * Time of creation 70 | * @see com.niagarasummit.nola.BGator#spawnTime 71 | */ 72 | public void setSpawnTime(BAbsTime v) { set(spawnTime,v,null); } 73 | 74 | //////////////////////////////////////////////////////////////// 75 | // Property "length" 76 | //////////////////////////////////////////////////////////////// 77 | 78 | /** 79 | * Slot for the length property. 80 | * Gator length 81 | * @see com.niagarasummit.nola.BGator#getLength 82 | * @see com.niagarasummit.nola.BGator#setLength 83 | */ 84 | public static final Property length = newProperty(Flags.READONLY, 0,BFacets.make(BFacets.UNITS, BUnit.getUnit("foot"))); 85 | 86 | /** 87 | * Get the length property. 88 | * Gator length 89 | * @see com.niagarasummit.nola.BGator#length 90 | */ 91 | public int getLength() { return getInt(length); } 92 | 93 | /** 94 | * Set the length property. 95 | * Gator length 96 | * @see com.niagarasummit.nola.BGator#length 97 | */ 98 | public void setLength(int v) { setInt(length,v,null); } 99 | 100 | //////////////////////////////////////////////////////////////// 101 | // Property "weight" 102 | //////////////////////////////////////////////////////////////// 103 | 104 | /** 105 | * Slot for the weight property. 106 | * Gator weight 107 | * @see com.niagarasummit.nola.BGator#getWeight 108 | * @see com.niagarasummit.nola.BGator#setWeight 109 | */ 110 | public static final Property weight = newProperty(Flags.READONLY, 0,BFacets.make(BFacets.UNITS, BUnit.getUnit("pound"))); 111 | 112 | /** 113 | * Get the weight property. 114 | * Gator weight 115 | * @see com.niagarasummit.nola.BGator#weight 116 | */ 117 | public int getWeight() { return getInt(weight); } 118 | 119 | /** 120 | * Set the weight property. 121 | * Gator weight 122 | * @see com.niagarasummit.nola.BGator#weight 123 | */ 124 | public void setWeight(int v) { setInt(weight,v,null); } 125 | 126 | //////////////////////////////////////////////////////////////// 127 | // Property "isRecord" 128 | //////////////////////////////////////////////////////////////// 129 | 130 | /** 131 | * Slot for the isRecord property. 132 | * Is this a record? 133 | * @see com.niagarasummit.nola.BGator#getIsRecord 134 | * @see com.niagarasummit.nola.BGator#setIsRecord 135 | */ 136 | public static final Property isRecord = newProperty(Flags.READONLY, false,null); 137 | 138 | /** 139 | * Get the isRecord property. 140 | * Is this a record? 141 | * @see com.niagarasummit.nola.BGator#isRecord 142 | */ 143 | public boolean getIsRecord() { return getBoolean(isRecord); } 144 | 145 | /** 146 | * Set the isRecord property. 147 | * Is this a record? 148 | * @see com.niagarasummit.nola.BGator#isRecord 149 | */ 150 | public void setIsRecord(boolean v) { setBoolean(isRecord,v,null); } 151 | 152 | //////////////////////////////////////////////////////////////// 153 | // Type 154 | //////////////////////////////////////////////////////////////// 155 | 156 | public Type getType() { return TYPE; } 157 | public static final Type TYPE = Sys.loadType(BGator.class); 158 | 159 | /*+ ------------ END BAJA AUTO GENERATED CODE -------------- +*/ 160 | 161 | public BGator() {} 162 | 163 | public BGator(int l, int w) 164 | { 165 | setLength(l); 166 | setWeight(w); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /ax/nola/src/com/niagarasummit/nola/ui/BGatorTrackerView.java: -------------------------------------------------------------------------------- 1 | package com.niagarasummit.nola.ui; 2 | 3 | import javax.baja.gx.BInsets; 4 | import javax.baja.sys.BComponentEvent; 5 | import javax.baja.sys.BObject; 6 | import javax.baja.sys.BString; 7 | import javax.baja.sys.Clock; 8 | import javax.baja.sys.Context; 9 | import javax.baja.sys.Sys; 10 | import javax.baja.sys.Type; 11 | import javax.baja.ui.BAbstractButton; 12 | import javax.baja.ui.BDialog; 13 | import javax.baja.ui.BWidget; 14 | import javax.baja.ui.Command; 15 | import javax.baja.ui.CommandArtifact; 16 | import javax.baja.ui.pane.BBorderPane; 17 | import javax.baja.ui.pane.BEdgePane; 18 | import javax.baja.ui.pane.BGridPane; 19 | import javax.baja.ui.table.BTable; 20 | import javax.baja.ui.table.DefaultTableModel; 21 | import javax.baja.util.Lexicon; 22 | import javax.baja.workbench.view.BWbComponentView; 23 | 24 | import com.niagarasummit.nola.BGator; 25 | import com.niagarasummit.nola.BGatorTracker; 26 | 27 | /** 28 | * Simple view for listing the alligators that have been tracked. 29 | */ 30 | public class BGatorTrackerView extends BWbComponentView 31 | { 32 | /*- 33 | class BGatorTrackerView 34 | { 35 | } 36 | -*/ 37 | /*+ ------------ BEGIN BAJA AUTO GENERATED CODE ------------ +*/ 38 | /*@ $com.niagarasummit.nola.ui.BGatorTrackerView(1209840226)1.0$ @*/ 39 | /* Generated Mon Apr 25 14:13:20 EDT 2016 by Slot-o-Matic 2000 (c) Tridium, Inc. 2000 */ 40 | 41 | //////////////////////////////////////////////////////////////// 42 | // Type 43 | //////////////////////////////////////////////////////////////// 44 | 45 | public Type getType() { return TYPE; } 46 | public static final Type TYPE = Sys.loadType(BGatorTrackerView.class); 47 | 48 | /*+ ------------ END BAJA AUTO GENERATED CODE -------------- +*/ 49 | 50 | /** 51 | * Constructor. 52 | * Build the table and buttons. 53 | */ 54 | public BGatorTrackerView() 55 | { 56 | BEdgePane content = new BEdgePane(); 57 | 58 | model = new DefaultTableModel(colNames); 59 | table = new BTable(model); 60 | 61 | BGridPane buttons = makeButtonPane(); 62 | 63 | content.setCenter(table); 64 | content.setBottom(new BBorderPane(buttons, 5, 5, 5, 5)); 65 | setContent(content); 66 | } 67 | 68 | /** 69 | * Initialization hook from BWbEditor. 70 | * Load the information into the ui widgets and set initial state of ui 71 | * activation components like buttons. 72 | */ 73 | public void doLoadValue(BObject value, Context context) 74 | { 75 | tracker = (BGatorTracker)value; 76 | loadGators(); 77 | enableButtons(); 78 | } 79 | 80 | /** 81 | * Load the list of record-breaking alligators from the alarm db query. 82 | */ 83 | private void loadGators() 84 | { 85 | BGator[] list = (BGator[])tracker.getChildren(BGator.class); 86 | for (int i=0; i New Module. 19 | 2. Select a folder under which to place the new module, by clicking the folder button and selecting the parent folder for the module, or by specifying it directly in the text field. We will assume you will select the 'nolademo' folder underneath the _n4_ folder inside this module. 20 | 3. Set the module name, preferred symbol, version, description, and vendor name: 21 | * module name = nola 22 | * preferred symbol = nola 23 | * version = 4.0 24 | * description = New Orleans Module Migration demo 25 | * vendor = niagarasummit 26 | 4. Select RUNTIME and WB module parts to create. 27 | 5. Ensure the lexicon and palette boxes are unchecked. 28 | 6. Click Next. 29 | 30 | #### NMW Step 2 31 | 32 | 1. Specify the dependencies for the N4 module. Open the build.xml from the AX Module in a text editor to see what modules to select. 33 | 2. Click Add to select modules. 34 | 3. The nre and baja modules are preselected for you. You will also need to select 35 | * alarm-rt 36 | * bajaui-wb 37 | * bql-rt 38 | * control-rt 39 | * file-rt 40 | * gx-wb (NOTE: this one is __incorrect__) 41 | * history-rt 42 | * workbench-wb 43 | 4. Click Next. 44 | 45 | #### NMW Step 3 46 | 47 | There is nothing to do here but notice the way the ui package was created in the __wb__ module part, whereas the regular nola package was created in the __rt__ module part. Click Finish. 48 | 49 | Close the Workbench. 50 | 51 | ### New Module Wizard (Using Niagara 4.2 or earlier) 52 | To use the New Module Wizard in Niagara 4.2 or earlier, you have to do a few things differently. 53 | #### Execute Wizard twice 54 | - You need to set the NIAGARA_HOME environment variable manually, as this is not done by the tool. __NOTE:__ You'll need to do this through the system properties, not just by using the "set" command at the console prompt, so that IntelliJ will be able to recognize it. 55 | - You will need to run the New Module Wizard twice, once for each module part. 56 | - Make sure to choose the same parent folder both times 57 | - Select the following dependencies: 58 | - rt module part: alarm-rt, bql-rt, control-rt, file-rt, history-rt 59 | - wb module part: bajaui-wb, gx-wb (__incorrect__), workbench-wb 60 | #### Copy gradle files 61 | Copy the *.gradle files from the 'demo' section of the repository. You will need: 62 | - build.gradle 63 | - environment.gradle 64 | - settings.gradle 65 | - vendor.gradle 66 | #### Fix environment.gradle 67 | Open environment.gradle in a text editor and make the following changes to suit your specific installation: 68 | 69 | gradle.ext.niagara_dev_home = "C:/ns2016/devmig/n4/demo" // location of your nola project 70 | gradle.ext.niagara_home = "C:/niagara/niagara-4.2.36.16" // Niagara System Home location 71 | gradle.ext.niagara_user_home = "C:/Users/Craig/Niagara4.2/tridium" // Niagara Workbench User Home location 72 | #### Copy and fix module part gradle build files 73 | Copy n4/demo/nola-rt.gradle into the nola-rt folder, and n4/demo/nola-wb.gradle into the nola-wb folder. 74 | __REMOVE__ the build.gradle from both nola-rt and nola-wb folders. 75 | 76 | Now you can continue with the file copy and IDE import! 77 | 78 | ### Copy Files 79 | 80 | Now as a starting point we need to copy the files over from the AX source location to the N4 source location. 81 | 1. Copy ax/nola/src/com/niagarasummit/nola/* 82 | into n4/nolademo/nola/nola-rt/src/com/niagarasummit/nola 83 | 2. Copy ax/nola/src/com/niagarasummit/nola/ui/* 84 | into n4/nolademo/nola/nola-wb/src/com/niagarasummit/nola/ui 85 | 3. Copy ax/nola/module.lexicon and module.palette 86 | into n4/nolademo/nola/nola-rt 87 | 4. Copy ax/nola/module-include.xml into __BOTH__ 88 | n4/nolademo/nola/nola-rt __AND__ n4/nolademo/nola/nola-wb 89 | 90 | ### Import into IDE 91 | 92 | You can do this using Eclipse or IntelliJ IDEA. These instructions are for importing into IntelliJ IDEA 2016.1.2. 93 | 94 | 1. Open IntelliJ. Select File > Open... to open the dialog for opening a project. 95 | 2. Navigate to the build.gradle created by the New Module Wizard. It should be at n4/nolademo/build.gradle. Click OK. 96 | 3. Select to 'Use gradle wrapper task configuration'. Click OK. 97 | 4. After a brief pause, you will have a dialog saying 'Gradle Project Data To Import'. Ensure all three choices are selected and click OK. 98 | 5. After this, you should have the IntelliJ workbench open, with the nola-rt, nola-wb, and nolademo parts available in the Project view on the left. 99 | 100 | ### Migrate the Code 101 | 102 | #### Migrate Slot Code 103 | 104 | The slot tool migration serves two purposes in this demo. 105 | 1. We need to get the type definitions into the correct module part locations, as they must only be specified in a single module-include.xml. 106 | 2. It converts the old-style AX syntax to the new N4 annotation syntax - not strictly necessary, but strongly recommended. 107 | 108 | Open the Gradle projects window, and execute the task 109 | niagara > niagara (root) > niagara > migrateSlotomatic. 110 | This is equivalent to executing the console command 111 | gradlew slotomatic -Dslotomatic.migrateBeforeRecompile 112 | 113 | #### Apply N4 Code Changes 114 | 115 | Now you need to fix the code to use the new Niagara 4 APIs. You can identify these by running the Gradle task from the Gradle projects window: 116 | niagara > niagara (root) > build > build 117 | Or, from the command line: 118 | gradlew build 119 | Or, you can open the files BGatorTracker and BGatorTrackerView and identify the items highlighted in red. 120 | 121 | * BGatorTracker.java: 122 | - Remove the import of the (nonexistent) javax.baja.collection.BICollection 123 | - In doDisplayNamesQuery(): 124 | + Remove or comment the Niagara AX code and uncomment the Niagara 4 code. This is indicated with a line comment before the code in each place. For example: 125 | ```java 126 | // Niagara AX 127 | BICollection result = (BICollection)BOrd.make("bql:select displayName").get(this); 128 | BITable table = result.toTable(); 129 | // // Niagara 4 130 | // BITable table = (BITable)BOrd.make("bql:select displayName").get(this); 131 | ``` 132 | + Make sure to add the necessary import for BObject - note, this will be highlighted for you as soon as it is uncommented, and you can use Alt+ENTER to automatically import it. 133 | - In getAlarmService() _and_ doFindRecordGators(): 134 | + Remove or comment the Niagara AX code and uncomment the Niagara 4 code. 135 | + Remember to add the import for AlarmDbConnection. 136 | * BGatorTrackerView.java: 137 | - Open this and observe BInsets is not found. 138 | - Open nola-wb.gradle. 139 | - In the dependencies section, change the dependency on gx-wb to gx-rt. 140 | - Click the refresh projects button in the Gradle projects window - it is the very first icon in the toolbar. 141 | - Observe that BInsets is now found. 142 | 143 | ### Build the module 144 | 145 | Build the module using the gradle task. Again, you can build it from the IDE or the command line. 146 | 147 | ## Station Migration 148 | Remember to migrate your AX station as well. You can use the `n4mig` executable to do this from the N4 console. 149 | -------------------------------------------------------------------------------- /n4/demo/nola/nola-rt/src/com/niagarasummit/nola/BGatorTracker.java: -------------------------------------------------------------------------------- 1 | package com.niagarasummit.nola; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.OutputStream; 5 | import java.io.OutputStreamWriter; 6 | import java.text.MessageFormat; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | import java.util.Random; 10 | 11 | import javax.baja.alarm.AlarmDbConnection; 12 | import javax.baja.alarm.BAckState; 13 | import javax.baja.alarm.BAlarmRecord; 14 | import javax.baja.alarm.BAlarmService; 15 | import javax.baja.alarm.BIAlarmSource; 16 | import javax.baja.collection.BITable; 17 | import javax.baja.control.BNumericPoint; 18 | import javax.baja.file.BIFile; 19 | import javax.baja.history.ext.BHistoryExt; 20 | import javax.baja.history.ext.BNumericCovHistoryExt; 21 | import javax.baja.log.Log; 22 | import javax.baja.naming.BOrd; 23 | import javax.baja.naming.BOrdList; 24 | import javax.baja.status.BStatus; 25 | import javax.baja.status.BStatusNumeric; 26 | import javax.baja.status.BStatusValue; 27 | import javax.baja.sys.Action; 28 | import javax.baja.sys.BBoolean; 29 | import javax.baja.sys.BComponent; 30 | import javax.baja.sys.BDouble; 31 | import javax.baja.sys.BFacets; 32 | import javax.baja.sys.BObject; 33 | import javax.baja.sys.BString; 34 | import javax.baja.sys.BValue; 35 | import javax.baja.sys.Clock; 36 | import javax.baja.sys.Context; 37 | import javax.baja.sys.Cursor; 38 | import javax.baja.sys.Flags; 39 | import javax.baja.sys.Property; 40 | import javax.baja.sys.Sys; 41 | import javax.baja.sys.Topic; 42 | import javax.baja.sys.Type; 43 | import javax.baja.units.BUnit; 44 | import javax.baja.util.Lexicon; 45 | import javax.baja.nre.annotations.NiagaraProperty; 46 | import javax.baja.nre.annotations.NiagaraAction; 47 | import javax.baja.nre.annotations.NiagaraType; 48 | import javax.baja.nre.annotations.Facet; 49 | import javax.baja.nre.annotations.NiagaraTopic; 50 | 51 | /** 52 | * Demonstration Class for Migrating a Niagara AX module to Niagara 4. 53 | * Used for Niagara Summit 2016 Developer Day. 54 | * 55 | */ 56 | @NiagaraType 57 | /** 58 | * Name of most recently spawned alligator 59 | */ 60 | @NiagaraProperty( 61 | name = "gatorName", 62 | type = "String", 63 | defaultValue = "Allie", 64 | flags = Flags.SUMMARY 65 | ) 66 | /** 67 | * Length of most recently spawned alligator 68 | */ 69 | @NiagaraProperty( 70 | name = "gatorLength", 71 | type = "BStatusNumeric", 72 | defaultValue = "new BStatusNumeric(0, BStatus.nullStatus)", 73 | flags = Flags.SUMMARY, 74 | facets = @Facet("BFacets.make(BFacets.UNITS, BUnit.getUnit(\"foot\"))") 75 | ) 76 | /** 77 | * Weight of most recently spawned alligator 78 | */ 79 | @NiagaraProperty( 80 | name = "gatorWeight", 81 | type = "BStatusNumeric", 82 | defaultValue = "new BStatusNumeric(0, BStatus.nullStatus)", 83 | flags = Flags.SUMMARY, 84 | facets = @Facet("BFacets.make(BFacets.UNITS, BUnit.getUnit(\"pound\"))") 85 | ) 86 | /** 87 | * Current record for longest alligator 88 | */ 89 | @NiagaraProperty( 90 | name = "recordLength", 91 | type = "double", 92 | defaultValue = "0", 93 | facets = @Facet("BFacets.make(BFacets.UNITS, BUnit.getUnit(\"foot\"))") 94 | ) 95 | /** 96 | * Logs all the alligators we've tracked 97 | */ 98 | @NiagaraProperty( 99 | name = "gatorLogger", 100 | type = "BHistoryExt", 101 | defaultValue = "makeEnabledHistoryExt()" 102 | ) 103 | /** 104 | * Generate a new Gator and track it. 105 | */ 106 | @NiagaraAction( 107 | name = "trackGator", 108 | parameterType = "BString", 109 | defaultValue = "BString.make(\"Allie\")" 110 | ) 111 | /** 112 | * Query the alarm database for the record-breaking gators. 113 | */ 114 | @NiagaraAction( 115 | name = "findRecordGators", 116 | returnType = "BComponent" 117 | ) 118 | /** 119 | * Write the list of gators to a file. 120 | */ 121 | @NiagaraAction( 122 | name = "writeGatorList" 123 | ) 124 | /** 125 | * Acknowledge the alarm from this ack request 126 | */ 127 | @NiagaraAction( 128 | name = "ackAlarm", 129 | parameterType = "BAlarmRecord", 130 | defaultValue = "new BAlarmRecord()", 131 | returnType = "BBoolean", 132 | flags = Flags.HIDDEN 133 | ) 134 | /** 135 | * Query for display names of child components 136 | */ 137 | @NiagaraAction( 138 | name = "displayNamesQuery" 139 | ) 140 | @NiagaraTopic( 141 | name = "newGator" 142 | ) 143 | public class BGatorTracker 144 | extends BNumericPoint 145 | implements BIAlarmSource 146 | { 147 | 148 | /** 149 | * Make a history ext that's already enabled and ready to go. 150 | */ 151 | private static BHistoryExt makeEnabledHistoryExt() 152 | { 153 | BHistoryExt ext = new BNumericCovHistoryExt(); 154 | ext.setFlags(BHistoryExt.enabled, (ext.getFlags(BHistoryExt.enabled) & ~Flags.DEFAULT_ON_CLONE)); 155 | ext.setEnabled(true); 156 | return ext; 157 | } 158 | 159 | /*+ ------------ BEGIN BAJA AUTO GENERATED CODE ------------ +*/ 160 | /*@ $com.niagarasummit.nola.BGatorTracker(1352060645)1.0$ @*/ 161 | /* Generated Wed May 11 16:11:28 EDT 2016 by Slot-o-Matic (c) Tridium, Inc. 2012 */ 162 | 163 | //////////////////////////////////////////////////////////////// 164 | // Property "gatorName" 165 | //////////////////////////////////////////////////////////////// 166 | 167 | /** 168 | * Slot for the {@code gatorName} property. 169 | * Name of most recently spawned alligator 170 | * @see #getGatorName 171 | * @see #setGatorName 172 | */ 173 | public static final Property gatorName = newProperty(Flags.SUMMARY, "Allie", null); 174 | 175 | /** 176 | * Get the {@code gatorName} property. 177 | * Name of most recently spawned alligator 178 | * @see #gatorName 179 | */ 180 | public String getGatorName() { return getString(gatorName); } 181 | 182 | /** 183 | * Set the {@code gatorName} property. 184 | * Name of most recently spawned alligator 185 | * @see #gatorName 186 | */ 187 | public void setGatorName(String v) { setString(gatorName, v, null); } 188 | 189 | //////////////////////////////////////////////////////////////// 190 | // Property "gatorLength" 191 | //////////////////////////////////////////////////////////////// 192 | 193 | /** 194 | * Slot for the {@code gatorLength} property. 195 | * Length of most recently spawned alligator 196 | * @see #getGatorLength 197 | * @see #setGatorLength 198 | */ 199 | public static final Property gatorLength = newProperty(Flags.SUMMARY, new BStatusNumeric(0, BStatus.nullStatus), BFacets.make(BFacets.UNITS, BUnit.getUnit("foot"))); 200 | 201 | /** 202 | * Get the {@code gatorLength} property. 203 | * Length of most recently spawned alligator 204 | * @see #gatorLength 205 | */ 206 | public BStatusNumeric getGatorLength() { return (BStatusNumeric)get(gatorLength); } 207 | 208 | /** 209 | * Set the {@code gatorLength} property. 210 | * Length of most recently spawned alligator 211 | * @see #gatorLength 212 | */ 213 | public void setGatorLength(BStatusNumeric v) { set(gatorLength, v, null); } 214 | 215 | //////////////////////////////////////////////////////////////// 216 | // Property "gatorWeight" 217 | //////////////////////////////////////////////////////////////// 218 | 219 | /** 220 | * Slot for the {@code gatorWeight} property. 221 | * Weight of most recently spawned alligator 222 | * @see #getGatorWeight 223 | * @see #setGatorWeight 224 | */ 225 | public static final Property gatorWeight = newProperty(Flags.SUMMARY, new BStatusNumeric(0, BStatus.nullStatus), BFacets.make(BFacets.UNITS, BUnit.getUnit("pound"))); 226 | 227 | /** 228 | * Get the {@code gatorWeight} property. 229 | * Weight of most recently spawned alligator 230 | * @see #gatorWeight 231 | */ 232 | public BStatusNumeric getGatorWeight() { return (BStatusNumeric)get(gatorWeight); } 233 | 234 | /** 235 | * Set the {@code gatorWeight} property. 236 | * Weight of most recently spawned alligator 237 | * @see #gatorWeight 238 | */ 239 | public void setGatorWeight(BStatusNumeric v) { set(gatorWeight, v, null); } 240 | 241 | //////////////////////////////////////////////////////////////// 242 | // Property "recordLength" 243 | //////////////////////////////////////////////////////////////// 244 | 245 | /** 246 | * Slot for the {@code recordLength} property. 247 | * Current record for longest alligator 248 | * @see #getRecordLength 249 | * @see #setRecordLength 250 | */ 251 | public static final Property recordLength = newProperty(0, 0, BFacets.make(BFacets.UNITS, BUnit.getUnit("foot"))); 252 | 253 | /** 254 | * Get the {@code recordLength} property. 255 | * Current record for longest alligator 256 | * @see #recordLength 257 | */ 258 | public double getRecordLength() { return getDouble(recordLength); } 259 | 260 | /** 261 | * Set the {@code recordLength} property. 262 | * Current record for longest alligator 263 | * @see #recordLength 264 | */ 265 | public void setRecordLength(double v) { setDouble(recordLength, v, null); } 266 | 267 | //////////////////////////////////////////////////////////////// 268 | // Property "gatorLogger" 269 | //////////////////////////////////////////////////////////////// 270 | 271 | /** 272 | * Slot for the {@code gatorLogger} property. 273 | * Logs all the alligators we've tracked 274 | * @see #getGatorLogger 275 | * @see #setGatorLogger 276 | */ 277 | public static final Property gatorLogger = newProperty(0, makeEnabledHistoryExt(), null); 278 | 279 | /** 280 | * Get the {@code gatorLogger} property. 281 | * Logs all the alligators we've tracked 282 | * @see #gatorLogger 283 | */ 284 | public BHistoryExt getGatorLogger() { return (BHistoryExt)get(gatorLogger); } 285 | 286 | /** 287 | * Set the {@code gatorLogger} property. 288 | * Logs all the alligators we've tracked 289 | * @see #gatorLogger 290 | */ 291 | public void setGatorLogger(BHistoryExt v) { set(gatorLogger, v, null); } 292 | 293 | //////////////////////////////////////////////////////////////// 294 | // Action "trackGator" 295 | //////////////////////////////////////////////////////////////// 296 | 297 | /** 298 | * Slot for the {@code trackGator} action. 299 | * Generate a new Gator and track it. 300 | * @see #trackGator(BString parameter) 301 | */ 302 | public static final Action trackGator = newAction(0, BString.make("Allie"), null); 303 | 304 | /** 305 | * Invoke the {@code trackGator} action. 306 | * Generate a new Gator and track it. 307 | * @see #trackGator 308 | */ 309 | public void trackGator(BString parameter) { invoke(trackGator, parameter, null); } 310 | 311 | //////////////////////////////////////////////////////////////// 312 | // Action "findRecordGators" 313 | //////////////////////////////////////////////////////////////// 314 | 315 | /** 316 | * Slot for the {@code findRecordGators} action. 317 | * Query the alarm database for the record-breaking gators. 318 | * @see #findRecordGators() 319 | */ 320 | public static final Action findRecordGators = newAction(0, null); 321 | 322 | /** 323 | * Invoke the {@code findRecordGators} action. 324 | * Query the alarm database for the record-breaking gators. 325 | * @see #findRecordGators 326 | */ 327 | public BComponent findRecordGators() { return (BComponent)invoke(findRecordGators, null, null); } 328 | 329 | //////////////////////////////////////////////////////////////// 330 | // Action "writeGatorList" 331 | //////////////////////////////////////////////////////////////// 332 | 333 | /** 334 | * Slot for the {@code writeGatorList} action. 335 | * Write the list of gators to a file. 336 | * @see #writeGatorList() 337 | */ 338 | public static final Action writeGatorList = newAction(0, null); 339 | 340 | /** 341 | * Invoke the {@code writeGatorList} action. 342 | * Write the list of gators to a file. 343 | * @see #writeGatorList 344 | */ 345 | public void writeGatorList() { invoke(writeGatorList, null, null); } 346 | 347 | //////////////////////////////////////////////////////////////// 348 | // Action "ackAlarm" 349 | //////////////////////////////////////////////////////////////// 350 | 351 | /** 352 | * Slot for the {@code ackAlarm} action. 353 | * Acknowledge the alarm from this ack request 354 | * @see #ackAlarm(BAlarmRecord parameter) 355 | */ 356 | public static final Action ackAlarm = newAction(Flags.HIDDEN, new BAlarmRecord(), null); 357 | 358 | /** 359 | * Invoke the {@code ackAlarm} action. 360 | * Acknowledge the alarm from this ack request 361 | * @see #ackAlarm 362 | */ 363 | public BBoolean ackAlarm(BAlarmRecord parameter) { return (BBoolean)invoke(ackAlarm, parameter, null); } 364 | 365 | //////////////////////////////////////////////////////////////// 366 | // Action "displayNamesQuery" 367 | //////////////////////////////////////////////////////////////// 368 | 369 | /** 370 | * Slot for the {@code displayNamesQuery} action. 371 | * Query for display names of child components 372 | * @see #displayNamesQuery() 373 | */ 374 | public static final Action displayNamesQuery = newAction(0, null); 375 | 376 | /** 377 | * Invoke the {@code displayNamesQuery} action. 378 | * Query for display names of child components 379 | * @see #displayNamesQuery 380 | */ 381 | public void displayNamesQuery() { invoke(displayNamesQuery, null, null); } 382 | 383 | //////////////////////////////////////////////////////////////// 384 | // Topic "newGator" 385 | //////////////////////////////////////////////////////////////// 386 | 387 | /** 388 | * Slot for the {@code newGator} topic. 389 | * @see #fireNewGator 390 | */ 391 | public static final Topic newGator = newTopic(0, null); 392 | 393 | /** 394 | * Fire an event for the {@code newGator} topic. 395 | * @see #newGator 396 | */ 397 | public void fireNewGator(BValue event) { fire(newGator, event, null); } 398 | 399 | //////////////////////////////////////////////////////////////// 400 | // Type 401 | //////////////////////////////////////////////////////////////// 402 | 403 | @Override 404 | public Type getType() { return TYPE; } 405 | public static final Type TYPE = Sys.loadType(BGatorTracker.class); 406 | 407 | /*+ ------------ END BAJA AUTO GENERATED CODE -------------- +*/ 408 | 409 | 410 | //////////////////////////////////////////////////////////////// 411 | // BComponent Overrides 412 | //////////////////////////////////////////////////////////////// 413 | 414 | /** 415 | * Initialize the Gator Tracker. 416 | */ 417 | public void started() throws Exception 418 | { 419 | super.started(); 420 | random = new Random(); 421 | } 422 | 423 | /** 424 | * Override of BNumericPoint execution. 425 | */ 426 | public void onExecute(BStatusValue out, Context cx) 427 | { 428 | out.copyFrom(getGatorLength()); 429 | } 430 | 431 | 432 | //////////////////////////////////////////////////////////////// 433 | // Actions 434 | //////////////////////////////////////////////////////////////// 435 | 436 | /** 437 | * Track a new alligator. 438 | */ 439 | public void doTrackGator(BString gatorName) 440 | { 441 | // Create a gator 442 | BGator gator = createGator(); 443 | 444 | // Add it to the family 445 | add(gatorName.getString(), gator); 446 | BStatusNumeric sn = new BStatusNumeric(gator.getLength()); 447 | setGatorLength(sn); 448 | sn = new BStatusNumeric(gator.getWeight()); 449 | setGatorWeight(sn); 450 | setGatorName(gatorName.toString()); 451 | 452 | // Check if it's a new record 453 | double gatorLen = gator.getLength(); 454 | if (gatorLen > getRecordLength()) 455 | { 456 | // Generate alarm 457 | Map alarmData = new HashMap(); 458 | alarmData.put(GATOR_NAME, gatorName); 459 | alarmData.put(GATOR_LENGTH, getGatorLength().getValueValue()); 460 | alarmData.put(GATOR_WEIGHT, getGatorWeight().getValueValue()); 461 | alarmData.put(OLD_RECORD, (BDouble)get(recordLength)); 462 | alarmData.put(NEW_RECORD, getGatorLength().getValueValue()); 463 | BAlarmRecord rec = new BAlarmRecord(); 464 | rec.setAlarmData(BFacets.make(alarmData)); 465 | rec.setSource(BOrdList.make(getNavOrd())); 466 | getAlarmService().routeAlarm(rec); 467 | 468 | // Update the record 469 | setRecordLength(gatorLen); 470 | gator.setIsRecord(true); 471 | } 472 | 473 | // The frozen history extension automatically logs the new addition... 474 | execute(); 475 | 476 | // Fire a topic so interested parties can take action 477 | fireNewGator(null); 478 | } 479 | 480 | 481 | //////////////////////////////////////////////////////////////// 482 | // BIAlarmSource 483 | //////////////////////////////////////////////////////////////// 484 | 485 | public BBoolean doAckAlarm(BAlarmRecord rec) 486 | { 487 | if (!isRunning()) return BBoolean.FALSE; 488 | 489 | // Acknowledge the alarm 490 | rec.setAckTime(Clock.time()); 491 | rec.setAckState(BAckState.acked); 492 | rec.setAckRequired(false); 493 | 494 | try 495 | { 496 | getAlarmService().routeAlarm(rec); 497 | } 498 | catch (Exception e) 499 | { 500 | log.error(MessageFormat.format(lex.getText("gatorTracker.couldNotAck"), 501 | new Object[] { rec })); 502 | } 503 | 504 | return BBoolean.TRUE; 505 | } 506 | 507 | 508 | //////////////////////////////////////////////////////////////// 509 | // Alarm API Usage 510 | //////////////////////////////////////////////////////////////// 511 | 512 | /** 513 | * Find all the alarms (new gator length records) 514 | * See Developer Doc topic at module://docDeveloper/doc/alarm.html 515 | */ 516 | public BComponent doFindRecordGators() 517 | { 518 | BComponent gatorList = new BComponent(); 519 | try 520 | { 521 | log.message(lex.getText("gatorTracker.recordGators.msg")); 522 | BOrdList source = BOrdList.make(getNavOrd()); 523 | BAlarmService alarmService = getAlarmService(); 524 | 525 | // // Niagara AX 526 | // Cursor cursor = alarmService.getAlarmDb().getAlarmsForSource(source); 527 | // Niagara 4 528 | Cursor cursor; 529 | try (AlarmDbConnection conn = alarmService.getAlarmDb().getDbConnection(null)) 530 | { 531 | cursor = conn.getAlarmsForSource(source); 532 | int count = 0; 533 | while (cursor.next() & (++count < 10)) 534 | { 535 | BAlarmRecord rec = (BAlarmRecord)cursor.get(); 536 | BFacets alarmData = rec.getAlarmData(); 537 | log.message(MessageFormat.format( 538 | lex.getText("gatorTracker.gatorStats"), 539 | new Object[] { alarmData.get(GATOR_LENGTH) })); 540 | gatorList.add(alarmData.gets(GATOR_NAME, null), 541 | new BGator(alarmData.geti(GATOR_LENGTH, 0), alarmData.geti(GATOR_WEIGHT, 0))); 542 | } 543 | } 544 | } 545 | catch (Exception e) 546 | { 547 | log.error(MessageFormat.format( 548 | lex.getText("gatorTracker.couldNotQuery"), 549 | new Object[] { "record gators" })); 550 | 551 | } 552 | return gatorList; 553 | } 554 | 555 | 556 | //////////////////////////////////////////////////////////////// 557 | // Collections Usage 558 | //////////////////////////////////////////////////////////////// 559 | 560 | /** 561 | * Query for display names: demonstration of Collections API changes 562 | * See Developer Doc topic at module://docDeveloper/doc/collections.html 563 | */ 564 | public void doDisplayNamesQuery() 565 | { 566 | try 567 | { 568 | // // Niagara AX 569 | // BICollection result = (BICollection)BOrd.make("bql:select displayName").get(this); 570 | // BITable table = result.toTable(); 571 | // Niagara 4 572 | BITable table = (BITable)BOrd.make("bql:select displayName").get(this); 573 | 574 | StringBuffer sb = new StringBuffer(); 575 | 576 | // // Niagara AX 577 | // for (int i=0; i cursor = table.cursor(); 580 | while (cursor.next()) 581 | 582 | { 583 | sb.append(MessageFormat.format( 584 | lex.getText("gatorTracker.displayNames.result.elem"), 585 | 586 | // // Niagara AX 587 | // new Object[] { table.get(i), table.get(i).getType() })).append('\n'); 588 | // Niagara 4 589 | new Object[] { cursor.get(), cursor.get().getType() })).append('\n'); 590 | } 591 | log.message(MessageFormat.format( 592 | lex.getText("gatorTracker.displayNames.result"), 593 | new Object[] { sb.toString() })); 594 | } 595 | catch (Exception e) 596 | { 597 | log.error(MessageFormat.format( 598 | lex.getText("gatorTracker.couldNotQuery"), 599 | new Object[] { "display names" })); 600 | } 601 | } 602 | 603 | 604 | //////////////////////////////////////////////////////////////// 605 | // File write 606 | //////////////////////////////////////////////////////////////// 607 | 608 | /** 609 | * Query the alarm database for all of the record-breaking gators, 610 | * and write them to the gator list file. 611 | * This is a demonstration of the file writes. Note that the caret (^) 612 | * symbol, referred to "Station Home" in Niagara AX as the folder with 613 | * the station's name. In Niagara 4, it refers to "Station Home", but this 614 | * is now the folder called "shared" underneath of the folder with the station's 615 | * name. The folder with the station's name is now called "Protected Station Home", 616 | * and is not generally accessible by user code. 617 | */ 618 | public void doWriteGatorList() 619 | { 620 | try 621 | { 622 | BIFile file = (BIFile)BOrd.make("file:^gator/gatorList.txt").get(); 623 | OutputStream out = file.getOutputStream(); 624 | BufferedWriter w = new BufferedWriter(new OutputStreamWriter(out)); 625 | w.write(lex.getText("gatorTracker.gatorList.title") + '\n'); 626 | 627 | log.message(lex.getText("gatorTracker.recordGators.msg")); 628 | BOrdList source = BOrdList.make(getNavOrd()); 629 | BAlarmService alarmService = getAlarmService(); 630 | 631 | // // Niagara AX 632 | // Cursor cursor = alarmService.getAlarmDb().getAlarmsForSource(source); 633 | // Niagara 4 634 | Cursor cursor; 635 | try (AlarmDbConnection conn = alarmService.getAlarmDb().getDbConnection(null)) 636 | { 637 | cursor = conn.getAlarmsForSource(source); 638 | int count = 0; 639 | while (cursor.next() & (++count < 10)) 640 | { 641 | BAlarmRecord rec = (BAlarmRecord)cursor.get(); 642 | BFacets alarmData = rec.getAlarmData(); 643 | w.write(MessageFormat.format( 644 | lex.getText("gatorTracker.gatorStats"), 645 | new Object[] { alarmData.get(GATOR_NAME), alarmData.get(GATOR_LENGTH), alarmData.get(GATOR_WEIGHT) })); 646 | w.write('\n'); 647 | } 648 | } 649 | 650 | w.flush(); 651 | w.close(); 652 | } 653 | catch (Exception e) 654 | { 655 | log.error(MessageFormat.format( 656 | lex.getText("gatorTracker.writeList.error"), 657 | new Object[] { e })); 658 | } 659 | } 660 | 661 | 662 | //////////////////////////////////////////////////////////////// 663 | // Private Utility 664 | //////////////////////////////////////////////////////////////// 665 | 666 | /** 667 | * Get a reference to the station's {@code BAlarmService}. 668 | * Only valid in a running station. 669 | * @return the alarm service. 670 | */ 671 | private BAlarmService getAlarmService() 672 | { 673 | return (BAlarmService) BOrd.make("service:alarm:AlarmService").get(); 674 | } 675 | 676 | 677 | //////////////////////////////////////////////////////////////// 678 | // Gator Creation 679 | //////////////////////////////////////////////////////////////// 680 | 681 | private BGator createGator() 682 | { 683 | int gLen = random.nextInt(MAX_GATOR_LENGTH); 684 | int weightPerFoot = random.nextInt(GATOR_WEIGHT_RANGE) + BASE_GATOR_WEIGHT_PER_FOOT; 685 | int gWt = gLen * weightPerFoot; 686 | BGator g = new BGator(gLen, gWt); 687 | return g; 688 | } 689 | 690 | Random random; 691 | public static final int MAX_GATOR_LENGTH = 16; 692 | public static final int GATOR_WEIGHT_RANGE = 20; 693 | public static final int BASE_GATOR_WEIGHT_PER_FOOT = 60; 694 | 695 | 696 | //////////////////////////////////////////////////////////////// 697 | // Constants and Instance Fields 698 | //////////////////////////////////////////////////////////////// 699 | 700 | private static Lexicon lex = Lexicon.make("nola"); 701 | private static Log log = Log.getLog("nola"); 702 | 703 | public static final String GATOR_NAME = "GatorName"; 704 | public static final String GATOR_LENGTH = "GatorLength"; 705 | public static final String GATOR_WEIGHT = "GatorWeight"; 706 | public static final String OLD_RECORD = "OldRecord"; 707 | public static final String NEW_RECORD = "NewRecord"; 708 | 709 | } 710 | -------------------------------------------------------------------------------- /n4/final/nola/nola-rt/src/com/niagarasummit/nola/BGatorTracker.java: -------------------------------------------------------------------------------- 1 | package com.niagarasummit.nola; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.OutputStream; 5 | import java.io.OutputStreamWriter; 6 | import java.text.MessageFormat; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | import java.util.Random; 10 | import java.util.logging.Logger; 11 | import javax.baja.alarm.AlarmDbConnection; 12 | import javax.baja.alarm.BAckState; 13 | import javax.baja.alarm.BAlarmRecord; 14 | import javax.baja.alarm.BAlarmService; 15 | import javax.baja.alarm.BIAlarmSource; 16 | import javax.baja.collection.BITable; 17 | import javax.baja.control.BNumericPoint; 18 | import javax.baja.data.BIDataValue; 19 | import javax.baja.file.BIFile; 20 | import javax.baja.history.ext.BHistoryExt; 21 | import javax.baja.history.ext.BNumericCovHistoryExt; 22 | import javax.baja.naming.BOrd; 23 | import javax.baja.naming.BOrdList; 24 | import javax.baja.nre.annotations.Facet; 25 | import javax.baja.nre.annotations.NiagaraAction; 26 | import javax.baja.nre.annotations.NiagaraProperty; 27 | import javax.baja.nre.annotations.NiagaraTopic; 28 | import javax.baja.nre.annotations.NiagaraType; 29 | import javax.baja.status.BStatus; 30 | import javax.baja.status.BStatusNumeric; 31 | import javax.baja.status.BStatusValue; 32 | import javax.baja.sys.Action; 33 | import javax.baja.sys.BBoolean; 34 | import javax.baja.sys.BComponent; 35 | import javax.baja.sys.BFacets; 36 | import javax.baja.sys.BObject; 37 | import javax.baja.sys.BString; 38 | import javax.baja.sys.BValue; 39 | import javax.baja.sys.Clock; 40 | import javax.baja.sys.Context; 41 | import javax.baja.sys.Cursor; 42 | import javax.baja.sys.Flags; 43 | import javax.baja.sys.Property; 44 | import javax.baja.sys.Sys; 45 | import javax.baja.sys.Topic; 46 | import javax.baja.sys.Type; 47 | import javax.baja.units.BUnit; 48 | import javax.baja.util.Lexicon; 49 | 50 | /** 51 | * Demonstration Class for Migrating a Niagara AX module to Niagara 4. 52 | * Used for Niagara Summit 2016 Developer Day. 53 | */ 54 | // Warnings for missing '@Override' annotations are suppressed because the slotomatic tool does not 55 | // currently generate them. 56 | @SuppressWarnings("override") 57 | 58 | @NiagaraType 59 | /** 60 | * Name of most recently spawned alligator 61 | */ 62 | @NiagaraProperty( 63 | name = "gatorName", 64 | type = "String", 65 | defaultValue = "Allie", 66 | flags = Flags.SUMMARY 67 | ) 68 | /** 69 | * Length of most recently spawned alligator 70 | */ 71 | @NiagaraProperty( 72 | name = "gatorLength", 73 | type = "BStatusNumeric", 74 | defaultValue = "new BStatusNumeric(0, BStatus.nullStatus)", 75 | flags = Flags.SUMMARY, 76 | facets = @Facet("BFacets.make(BFacets.UNITS, BUnit.getUnit(\"foot\"))") 77 | ) 78 | /** 79 | * Weight of most recently spawned alligator 80 | */ 81 | @NiagaraProperty( 82 | name = "gatorWeight", 83 | type = "BStatusNumeric", 84 | defaultValue = "new BStatusNumeric(0, BStatus.nullStatus)", 85 | flags = Flags.SUMMARY, 86 | facets = @Facet("BFacets.make(BFacets.UNITS, BUnit.getUnit(\"pound\"))") 87 | ) 88 | /** 89 | * Current record for longest alligator 90 | */ 91 | @NiagaraProperty( 92 | name = "recordLength", 93 | type = "double", 94 | defaultValue = "0", 95 | facets = @Facet("BFacets.make(BFacets.UNITS, BUnit.getUnit(\"foot\"))") 96 | ) 97 | /** 98 | * Logs all the alligators we've tracked 99 | */ 100 | @NiagaraProperty( 101 | name = "gatorLogger", 102 | type = "BHistoryExt", 103 | defaultValue = "makeEnabledHistoryExt()" 104 | ) 105 | /** 106 | * Generate a new Gator and track it. 107 | */ 108 | @NiagaraAction( 109 | name = "trackGator", 110 | parameterType = "BString", 111 | defaultValue = "BString.make(\"Allie\")" 112 | ) 113 | /** 114 | * Query the alarm database for the record-breaking gators. 115 | */ 116 | @NiagaraAction( 117 | name = "findRecordGators", 118 | returnType = "BComponent" 119 | ) 120 | /** 121 | * Write the list of gators to a file. 122 | */ 123 | @NiagaraAction( 124 | name = "writeGatorList" 125 | ) 126 | /** 127 | * Acknowledge the alarm from this ack request 128 | */ 129 | @NiagaraAction( 130 | name = "ackAlarm", 131 | parameterType = "BAlarmRecord", 132 | defaultValue = "new BAlarmRecord()", 133 | returnType = "BBoolean", 134 | flags = Flags.HIDDEN 135 | ) 136 | /** 137 | * Query for display names of child components 138 | */ 139 | @NiagaraAction( 140 | name = "displayNamesQuery" 141 | ) 142 | @NiagaraTopic( 143 | name = "newGator" 144 | ) 145 | public class BGatorTracker 146 | extends BNumericPoint 147 | implements BIAlarmSource 148 | { 149 | 150 | /** 151 | * Make a history ext that's already enabled and ready to go. 152 | */ 153 | private static BHistoryExt makeEnabledHistoryExt() 154 | { 155 | BHistoryExt ext = new BNumericCovHistoryExt(); 156 | ext.setFlags(BHistoryExt.enabled, ext.getFlags(BHistoryExt.enabled) & ~Flags.DEFAULT_ON_CLONE); 157 | ext.setEnabled(true); 158 | return ext; 159 | } 160 | 161 | /*+ ------------ BEGIN BAJA AUTO GENERATED CODE ------------ +*/ 162 | /*@ $com.niagarasummit.nola.BGatorTracker(1352060645)1.0$ @*/ 163 | /* Generated Tue May 10 15:18:43 EDT 2016 by Slot-o-Matic (c) Tridium, Inc. 2012 */ 164 | 165 | //////////////////////////////////////////////////////////////// 166 | // Property "gatorName" 167 | //////////////////////////////////////////////////////////////// 168 | 169 | /** 170 | * Slot for the {@code gatorName} property. 171 | * Name of most recently spawned alligator 172 | * @see #getGatorName 173 | * @see #setGatorName 174 | */ 175 | public static final Property gatorName = newProperty(Flags.SUMMARY, "Allie", null); 176 | 177 | /** 178 | * Get the {@code gatorName} property. 179 | * Name of most recently spawned alligator 180 | * @see #gatorName 181 | */ 182 | public String getGatorName() { return getString(gatorName); } 183 | 184 | /** 185 | * Set the {@code gatorName} property. 186 | * Name of most recently spawned alligator 187 | * @see #gatorName 188 | */ 189 | public void setGatorName(String v) { setString(gatorName, v, null); } 190 | 191 | //////////////////////////////////////////////////////////////// 192 | // Property "gatorLength" 193 | //////////////////////////////////////////////////////////////// 194 | 195 | /** 196 | * Slot for the {@code gatorLength} property. 197 | * Length of most recently spawned alligator 198 | * @see #getGatorLength 199 | * @see #setGatorLength 200 | */ 201 | public static final Property gatorLength = newProperty(Flags.SUMMARY, new BStatusNumeric(0, BStatus.nullStatus), BFacets.make(BFacets.UNITS, BUnit.getUnit("foot"))); 202 | 203 | /** 204 | * Get the {@code gatorLength} property. 205 | * Length of most recently spawned alligator 206 | * @see #gatorLength 207 | */ 208 | public BStatusNumeric getGatorLength() { return (BStatusNumeric)get(gatorLength); } 209 | 210 | /** 211 | * Set the {@code gatorLength} property. 212 | * Length of most recently spawned alligator 213 | * @see #gatorLength 214 | */ 215 | public void setGatorLength(BStatusNumeric v) { set(gatorLength, v, null); } 216 | 217 | //////////////////////////////////////////////////////////////// 218 | // Property "gatorWeight" 219 | //////////////////////////////////////////////////////////////// 220 | 221 | /** 222 | * Slot for the {@code gatorWeight} property. 223 | * Weight of most recently spawned alligator 224 | * @see #getGatorWeight 225 | * @see #setGatorWeight 226 | */ 227 | public static final Property gatorWeight = newProperty(Flags.SUMMARY, new BStatusNumeric(0, BStatus.nullStatus), BFacets.make(BFacets.UNITS, BUnit.getUnit("pound"))); 228 | 229 | /** 230 | * Get the {@code gatorWeight} property. 231 | * Weight of most recently spawned alligator 232 | * @see #gatorWeight 233 | */ 234 | public BStatusNumeric getGatorWeight() { return (BStatusNumeric)get(gatorWeight); } 235 | 236 | /** 237 | * Set the {@code gatorWeight} property. 238 | * Weight of most recently spawned alligator 239 | * @see #gatorWeight 240 | */ 241 | public void setGatorWeight(BStatusNumeric v) { set(gatorWeight, v, null); } 242 | 243 | //////////////////////////////////////////////////////////////// 244 | // Property "recordLength" 245 | //////////////////////////////////////////////////////////////// 246 | 247 | /** 248 | * Slot for the {@code recordLength} property. 249 | * Current record for longest alligator 250 | * @see #getRecordLength 251 | * @see #setRecordLength 252 | */ 253 | public static final Property recordLength = newProperty(0, 0, BFacets.make(BFacets.UNITS, BUnit.getUnit("foot"))); 254 | 255 | /** 256 | * Get the {@code recordLength} property. 257 | * Current record for longest alligator 258 | * @see #recordLength 259 | */ 260 | public double getRecordLength() { return getDouble(recordLength); } 261 | 262 | /** 263 | * Set the {@code recordLength} property. 264 | * Current record for longest alligator 265 | * @see #recordLength 266 | */ 267 | public void setRecordLength(double v) { setDouble(recordLength, v, null); } 268 | 269 | //////////////////////////////////////////////////////////////// 270 | // Property "gatorLogger" 271 | //////////////////////////////////////////////////////////////// 272 | 273 | /** 274 | * Slot for the {@code gatorLogger} property. 275 | * Logs all the alligators we've tracked 276 | * @see #getGatorLogger 277 | * @see #setGatorLogger 278 | */ 279 | public static final Property gatorLogger = newProperty(0, makeEnabledHistoryExt(), null); 280 | 281 | /** 282 | * Get the {@code gatorLogger} property. 283 | * Logs all the alligators we've tracked 284 | * @see #gatorLogger 285 | */ 286 | public BHistoryExt getGatorLogger() { return (BHistoryExt)get(gatorLogger); } 287 | 288 | /** 289 | * Set the {@code gatorLogger} property. 290 | * Logs all the alligators we've tracked 291 | * @see #gatorLogger 292 | */ 293 | public void setGatorLogger(BHistoryExt v) { set(gatorLogger, v, null); } 294 | 295 | //////////////////////////////////////////////////////////////// 296 | // Action "trackGator" 297 | //////////////////////////////////////////////////////////////// 298 | 299 | /** 300 | * Slot for the {@code trackGator} action. 301 | * Generate a new Gator and track it. 302 | * @see #trackGator(BString parameter) 303 | */ 304 | public static final Action trackGator = newAction(0, BString.make("Allie"), null); 305 | 306 | /** 307 | * Invoke the {@code trackGator} action. 308 | * Generate a new Gator and track it. 309 | * @see #trackGator 310 | */ 311 | public void trackGator(BString parameter) { invoke(trackGator, parameter, null); } 312 | 313 | //////////////////////////////////////////////////////////////// 314 | // Action "findRecordGators" 315 | //////////////////////////////////////////////////////////////// 316 | 317 | /** 318 | * Slot for the {@code findRecordGators} action. 319 | * Query the alarm database for the record-breaking gators. 320 | * @see #findRecordGators() 321 | */ 322 | public static final Action findRecordGators = newAction(0, null); 323 | 324 | /** 325 | * Invoke the {@code findRecordGators} action. 326 | * Query the alarm database for the record-breaking gators. 327 | * @see #findRecordGators 328 | */ 329 | public BComponent findRecordGators() { return (BComponent)invoke(findRecordGators, null, null); } 330 | 331 | //////////////////////////////////////////////////////////////// 332 | // Action "writeGatorList" 333 | //////////////////////////////////////////////////////////////// 334 | 335 | /** 336 | * Slot for the {@code writeGatorList} action. 337 | * Write the list of gators to a file. 338 | * @see #writeGatorList() 339 | */ 340 | public static final Action writeGatorList = newAction(0, null); 341 | 342 | /** 343 | * Invoke the {@code writeGatorList} action. 344 | * Write the list of gators to a file. 345 | * @see #writeGatorList 346 | */ 347 | public void writeGatorList() { invoke(writeGatorList, null, null); } 348 | 349 | //////////////////////////////////////////////////////////////// 350 | // Action "ackAlarm" 351 | //////////////////////////////////////////////////////////////// 352 | 353 | /** 354 | * Slot for the {@code ackAlarm} action. 355 | * Acknowledge the alarm from this ack request 356 | * @see #ackAlarm(BAlarmRecord parameter) 357 | */ 358 | public static final Action ackAlarm = newAction(Flags.HIDDEN, new BAlarmRecord(), null); 359 | 360 | /** 361 | * Invoke the {@code ackAlarm} action. 362 | * Acknowledge the alarm from this ack request 363 | * @see #ackAlarm 364 | */ 365 | public BBoolean ackAlarm(BAlarmRecord parameter) { return (BBoolean)invoke(ackAlarm, parameter, null); } 366 | 367 | //////////////////////////////////////////////////////////////// 368 | // Action "displayNamesQuery" 369 | //////////////////////////////////////////////////////////////// 370 | 371 | /** 372 | * Slot for the {@code displayNamesQuery} action. 373 | * Query for display names of child components 374 | * @see #displayNamesQuery() 375 | */ 376 | public static final Action displayNamesQuery = newAction(0, null); 377 | 378 | /** 379 | * Invoke the {@code displayNamesQuery} action. 380 | * Query for display names of child components 381 | * @see #displayNamesQuery 382 | */ 383 | public void displayNamesQuery() { invoke(displayNamesQuery, null, null); } 384 | 385 | //////////////////////////////////////////////////////////////// 386 | // Topic "newGator" 387 | //////////////////////////////////////////////////////////////// 388 | 389 | /** 390 | * Slot for the {@code newGator} topic. 391 | * @see #fireNewGator 392 | */ 393 | public static final Topic newGator = newTopic(0, null); 394 | 395 | /** 396 | * Fire an event for the {@code newGator} topic. 397 | * @see #newGator 398 | */ 399 | public void fireNewGator(BValue event) { fire(newGator, event, null); } 400 | 401 | //////////////////////////////////////////////////////////////// 402 | // Type 403 | //////////////////////////////////////////////////////////////// 404 | 405 | @Override 406 | public Type getType() { return TYPE; } 407 | public static final Type TYPE = Sys.loadType(BGatorTracker.class); 408 | 409 | /*+ ------------ END BAJA AUTO GENERATED CODE -------------- +*/ 410 | 411 | 412 | //////////////////////////////////////////////////////////////// 413 | // BComponent Overrides 414 | //////////////////////////////////////////////////////////////// 415 | 416 | /** 417 | * Initialize the Gator Tracker. 418 | */ 419 | @Override 420 | public void started() throws Exception 421 | { 422 | super.started(); 423 | random = new Random(); 424 | } 425 | 426 | /** 427 | * Override of BNumericPoint execution. 428 | */ 429 | @Override 430 | public void onExecute(BStatusValue out, Context cx) 431 | { 432 | out.copyFrom(getGatorLength()); 433 | } 434 | 435 | 436 | //////////////////////////////////////////////////////////////// 437 | // Actions 438 | //////////////////////////////////////////////////////////////// 439 | 440 | /** 441 | * Track a new alligator. 442 | */ 443 | public void doTrackGator(BString gatorName) 444 | { 445 | // Create a gator 446 | BGator gator = createGator(); 447 | 448 | // Add it to the family 449 | add(gatorName.getString(), gator); 450 | BStatusNumeric sn = new BStatusNumeric(gator.getLength()); 451 | setGatorLength(sn); 452 | sn = new BStatusNumeric(gator.getWeight()); 453 | setGatorWeight(sn); 454 | setGatorName(gatorName.toString()); 455 | 456 | // Check if it's a new record 457 | double gatorLen = gator.getLength(); 458 | if (gatorLen > getRecordLength()) 459 | { 460 | // Generate alarm 461 | Map alarmData = new HashMap<>(); 462 | alarmData.put(GATOR_NAME, gatorName); 463 | alarmData.put(GATOR_LENGTH, getGatorLength().getValueValue().toDataValue()); 464 | alarmData.put(GATOR_WEIGHT, getGatorWeight().getValueValue().toDataValue()); 465 | alarmData.put(OLD_RECORD, (BIDataValue)get(recordLength)); 466 | alarmData.put(NEW_RECORD, getGatorLength().getValueValue().toDataValue()); 467 | BAlarmRecord rec = new BAlarmRecord(); 468 | rec.setAlarmData(BFacets.make(alarmData)); 469 | rec.setSource(BOrdList.make(getNavOrd())); 470 | getAlarmService().routeAlarm(rec); 471 | 472 | // Update the record 473 | setRecordLength(gatorLen); 474 | gator.setIsRecord(true); 475 | } 476 | 477 | // The frozen history extension automatically logs the new addition... 478 | execute(); 479 | 480 | // Fire a topic so interested parties can take action 481 | fireNewGator(null); 482 | } 483 | 484 | 485 | //////////////////////////////////////////////////////////////// 486 | // BIAlarmSource 487 | //////////////////////////////////////////////////////////////// 488 | 489 | public BBoolean doAckAlarm(BAlarmRecord rec) 490 | { 491 | if (!isRunning()) return BBoolean.FALSE; 492 | 493 | // Acknowledge the alarm 494 | rec.setAckTime(Clock.time()); 495 | rec.setAckState(BAckState.acked); 496 | rec.setAckRequired(false); 497 | 498 | try 499 | { 500 | getAlarmService().routeAlarm(rec); 501 | } 502 | catch (Exception e) 503 | { 504 | log.severe(MessageFormat.format(lex.getText("gatorTracker.couldNotAck"), 505 | new Object[] { rec })); 506 | } 507 | 508 | return BBoolean.TRUE; 509 | } 510 | 511 | 512 | //////////////////////////////////////////////////////////////// 513 | // Alarm API Usage 514 | //////////////////////////////////////////////////////////////// 515 | 516 | /** 517 | * Find all the alarms (new gator length records) 518 | * See Developer Doc topic at module://docDeveloper/doc/alarm.html 519 | */ 520 | public BComponent doFindRecordGators() 521 | { 522 | BComponent gatorList = new BComponent(); 523 | try 524 | { 525 | log.info(lex.getText("gatorTracker.recordGators.msg")); 526 | BOrdList source = BOrdList.make(getNavOrd()); 527 | BAlarmService alarmService = getAlarmService(); 528 | Cursor cursor; 529 | try (AlarmDbConnection conn = alarmService.getAlarmDb().getDbConnection(null)) 530 | { 531 | cursor = conn.getAlarmsForSource(source); 532 | int count = 0; 533 | while (cursor.next() & (++count < 10)) 534 | { 535 | BAlarmRecord rec = cursor.get(); 536 | BFacets alarmData = rec.getAlarmData(); 537 | log.info(MessageFormat.format( 538 | lex.getText("gatorTracker.gatorStats"), 539 | new Object[] { alarmData.get(GATOR_LENGTH) })); 540 | gatorList.add(alarmData.gets(GATOR_NAME, null), 541 | new BGator(alarmData.geti(GATOR_LENGTH, 0), alarmData.geti(GATOR_WEIGHT, 0))); 542 | } 543 | } 544 | } 545 | catch (Exception e) 546 | { 547 | log.severe(MessageFormat.format( 548 | lex.getText("gatorTracker.couldNotQuery"), 549 | new Object[] { "record gators" })); 550 | 551 | } 552 | return gatorList; 553 | } 554 | 555 | 556 | //////////////////////////////////////////////////////////////// 557 | // Collections Usage 558 | //////////////////////////////////////////////////////////////// 559 | 560 | /** 561 | * Query for display names: demonstration of Collections API changes 562 | * See Developer Doc topic at module://docDeveloper/doc/collections.html 563 | */ 564 | public void doDisplayNamesQuery() 565 | { 566 | try 567 | { 568 | // We suppress the warning about unchecked cast to BITable because in this case, we 569 | // know that the result of the BQL query will be a BITable of BObjects, and the API 570 | // returns only a BITable. 571 | @SuppressWarnings("unchecked") 572 | BITable table = (BITable)BOrd.make("bql:select displayName").get(this); 573 | 574 | StringBuilder sb = new StringBuilder(); 575 | Cursor cursor = table.cursor(); 576 | while (cursor.next()) 577 | { 578 | sb.append(MessageFormat.format( 579 | lex.getText("gatorTracker.displayNames.result.elem"), 580 | new Object[] { cursor.get(), cursor.get().getType() })).append('\n'); 581 | } 582 | log.info(MessageFormat.format( 583 | lex.getText("gatorTracker.displayNames.result"), 584 | new Object[] { sb.toString() })); 585 | } 586 | catch (Exception e) 587 | { 588 | log.severe(MessageFormat.format( 589 | lex.getText("gatorTracker.couldNotQuery"), 590 | new Object[] { "display names" })); 591 | } 592 | } 593 | 594 | 595 | //////////////////////////////////////////////////////////////// 596 | // File write 597 | //////////////////////////////////////////////////////////////// 598 | 599 | /** 600 | * Query the alarm database for all of the record-breaking gators, 601 | * and write them to the gator list file. 602 | * This is a demonstration of the file writes. Note that the caret (^) 603 | * symbol, referred to "Station Home" in Niagara AX as the folder with 604 | * the station's name. In Niagara 4, it refers to "Station Home", but this 605 | * is now the folder called "shared" underneath of the folder with the station's 606 | * name. The folder with the station's name is now called "Protected Station Home", 607 | * and is not generally accessible by user code. 608 | */ 609 | public void doWriteGatorList() 610 | { 611 | try 612 | { 613 | BIFile file = (BIFile)BOrd.make("file:^gator/gatorList.txt").get(); 614 | try (OutputStream out = file.getOutputStream()) 615 | { 616 | BufferedWriter w = new BufferedWriter(new OutputStreamWriter(out)); 617 | w.write(lex.getText("gatorTracker.gatorList.title") + '\n'); 618 | 619 | log.info(lex.getText("gatorTracker.recordGators.msg")); 620 | BOrdList source = BOrdList.make(getNavOrd()); 621 | BAlarmService alarmService = getAlarmService(); 622 | 623 | Cursor cursor; 624 | try (AlarmDbConnection conn = alarmService.getAlarmDb().getDbConnection(null)) 625 | { 626 | cursor = conn.getAlarmsForSource(source); 627 | int count = 0; 628 | while (cursor.next() & (++count < 10)) 629 | { 630 | BAlarmRecord rec = cursor.get(); 631 | BFacets alarmData = rec.getAlarmData(); 632 | w.write(MessageFormat.format( 633 | lex.getText("gatorTracker.gatorStats"), 634 | new Object[] { alarmData.get(GATOR_NAME), alarmData.get(GATOR_LENGTH), alarmData.get(GATOR_WEIGHT) })); 635 | w.write('\n'); 636 | } 637 | } 638 | 639 | w.flush(); 640 | w.close(); 641 | } 642 | // Exception writing to file 643 | catch (Exception e) 644 | { 645 | log.severe(MessageFormat.format( 646 | lex.getText("gatorTracker.writeList.error"), 647 | new Object[] { e })); 648 | } 649 | } 650 | // Exception resolving file ord 651 | catch (Exception e) 652 | { 653 | log.severe(MessageFormat.format( 654 | lex.getText("gatorTracker.writeList.error"), 655 | new Object[] { e })); 656 | } 657 | } 658 | 659 | 660 | //////////////////////////////////////////////////////////////// 661 | // Private Utility 662 | //////////////////////////////////////////////////////////////// 663 | 664 | /** 665 | * Get a reference to the station's {@code BAlarmService}. 666 | * Only valid in a running station. 667 | * @return the alarm service. 668 | */ 669 | private static BAlarmService getAlarmService() 670 | { 671 | return (BAlarmService) BOrd.make("service:alarm:AlarmService").get(); 672 | } 673 | 674 | 675 | //////////////////////////////////////////////////////////////// 676 | // Gator Creation 677 | //////////////////////////////////////////////////////////////// 678 | 679 | private BGator createGator() 680 | { 681 | int gLen = random.nextInt(MAX_GATOR_LENGTH); 682 | int weightPerFoot = random.nextInt(GATOR_WEIGHT_RANGE) + BASE_GATOR_WEIGHT_PER_FOOT; 683 | int gWt = gLen * weightPerFoot; 684 | BGator g = new BGator(gLen, gWt); 685 | return g; 686 | } 687 | 688 | Random random; 689 | public static final int MAX_GATOR_LENGTH = 16; 690 | public static final int GATOR_WEIGHT_RANGE = 20; 691 | public static final int BASE_GATOR_WEIGHT_PER_FOOT = 60; 692 | 693 | 694 | //////////////////////////////////////////////////////////////// 695 | // Constants and Instance Fields 696 | //////////////////////////////////////////////////////////////// 697 | 698 | private static final Lexicon lex = Lexicon.make("nola"); 699 | private static final Logger log = Logger.getLogger("nola"); 700 | 701 | public static final String GATOR_NAME = "GatorName"; 702 | public static final String GATOR_LENGTH = "GatorLength"; 703 | public static final String GATOR_WEIGHT = "GatorWeight"; 704 | public static final String OLD_RECORD = "OldRecord"; 705 | public static final String NEW_RECORD = "NewRecord"; 706 | 707 | } 708 | -------------------------------------------------------------------------------- /ax/nola/src/com/niagarasummit/nola/BGatorTracker.java: -------------------------------------------------------------------------------- 1 | package com.niagarasummit.nola; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.OutputStream; 5 | import java.io.OutputStreamWriter; 6 | import java.text.MessageFormat; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | import java.util.Random; 10 | 11 | import javax.baja.alarm.BAckState; 12 | import javax.baja.alarm.BAlarmRecord; 13 | import javax.baja.alarm.BAlarmService; 14 | import javax.baja.alarm.BIAlarmSource; 15 | import javax.baja.collection.BICollection; 16 | import javax.baja.collection.BITable; 17 | import javax.baja.control.BNumericPoint; 18 | import javax.baja.file.BIFile; 19 | import javax.baja.history.ext.BHistoryExt; 20 | import javax.baja.history.ext.BNumericCovHistoryExt; 21 | import javax.baja.log.Log; 22 | import javax.baja.naming.BOrd; 23 | import javax.baja.naming.BOrdList; 24 | import javax.baja.status.BStatus; 25 | import javax.baja.status.BStatusNumeric; 26 | import javax.baja.status.BStatusValue; 27 | import javax.baja.sys.Action; 28 | import javax.baja.sys.BBoolean; 29 | import javax.baja.sys.BComponent; 30 | import javax.baja.sys.BDouble; 31 | import javax.baja.sys.BFacets; 32 | import javax.baja.sys.BString; 33 | import javax.baja.sys.BValue; 34 | import javax.baja.sys.Clock; 35 | import javax.baja.sys.Context; 36 | import javax.baja.sys.Cursor; 37 | import javax.baja.sys.Flags; 38 | import javax.baja.sys.Property; 39 | import javax.baja.sys.Sys; 40 | import javax.baja.sys.Topic; 41 | import javax.baja.sys.Type; 42 | import javax.baja.units.BUnit; 43 | import javax.baja.util.Lexicon; 44 | 45 | /** 46 | * Demonstration Class for Migrating a Niagara AX module to Niagara 4. 47 | * Used for Niagara Summit 2016 Developer Day. 48 | * 49 | */ 50 | public class BGatorTracker 51 | extends BNumericPoint 52 | implements BIAlarmSource 53 | { 54 | 55 | /** 56 | * Make a history ext that's already enabled and ready to go. 57 | */ 58 | private static BHistoryExt makeEnabledHistoryExt() 59 | { 60 | BHistoryExt ext = new BNumericCovHistoryExt(); 61 | ext.setFlags(BHistoryExt.enabled, (ext.getFlags(BHistoryExt.enabled) & ~Flags.DEFAULT_ON_CLONE)); 62 | ext.setEnabled(true); 63 | return ext; 64 | } 65 | /*- 66 | class BGatorTracker 67 | { 68 | properties 69 | { 70 | gatorName: String 71 | -- Name of most recently spawned alligator 72 | flags { summary } 73 | default {[ "Allie" ]} 74 | 75 | gatorLength: BStatusNumeric 76 | -- Length of most recently spawned alligator 77 | flags { summary } 78 | default {[ new BStatusNumeric(0, BStatus.nullStatus) ]} 79 | slotfacets {[ BFacets.make(BFacets.UNITS, BUnit.getUnit("foot")) ]} 80 | 81 | gatorWeight: BStatusNumeric 82 | -- Weight of most recently spawned alligator 83 | flags { summary } 84 | default {[ new BStatusNumeric(0, BStatus.nullStatus) ]} 85 | slotfacets {[ BFacets.make(BFacets.UNITS, BUnit.getUnit("pound")) ]} 86 | 87 | recordLength: double 88 | -- Current record for longest alligator 89 | default {[ 0 ]} 90 | slotfacets {[ BFacets.make(BFacets.UNITS, BUnit.getUnit("foot")) ]} 91 | 92 | gatorLogger: BHistoryExt 93 | -- Logs all the alligators we've tracked 94 | default {[ makeEnabledHistoryExt() ]} 95 | } 96 | actions 97 | { 98 | trackGator(gatorName: BString) 99 | -- Generate a new Gator and track it. 100 | default {[ BString.make("Allie") ]} 101 | 102 | findRecordGators() : BComponent 103 | -- Query the alarm database for the record-breaking gators. 104 | 105 | writeGatorList() 106 | -- Write the list of gators to a file. 107 | 108 | ackAlarm(ackRequest: BAlarmRecord) : BBoolean 109 | -- Acknowledge the alarm from this ack request 110 | flags { hidden } 111 | default {[ new BAlarmRecord() ]} 112 | 113 | displayNamesQuery() 114 | -- Query for display names of child components 115 | } 116 | topics 117 | { 118 | newGator 119 | } 120 | } 121 | -*/ 122 | /*+ ------------ BEGIN BAJA AUTO GENERATED CODE ------------ +*/ 123 | /*@ $com.niagarasummit.nola.BGatorTracker(1222283827)1.0$ @*/ 124 | /* Generated Tue May 10 14:43:48 EDT 2016 by Slot-o-Matic 2000 (c) Tridium, Inc. 2000 */ 125 | 126 | //////////////////////////////////////////////////////////////// 127 | // Property "gatorName" 128 | //////////////////////////////////////////////////////////////// 129 | 130 | /** 131 | * Slot for the gatorName property. 132 | * Name of most recently spawned alligator 133 | * @see com.niagarasummit.nola.BGatorTracker#getGatorName 134 | * @see com.niagarasummit.nola.BGatorTracker#setGatorName 135 | */ 136 | public static final Property gatorName = newProperty(Flags.SUMMARY, "Allie",null); 137 | 138 | /** 139 | * Get the gatorName property. 140 | * Name of most recently spawned alligator 141 | * @see com.niagarasummit.nola.BGatorTracker#gatorName 142 | */ 143 | public String getGatorName() { return getString(gatorName); } 144 | 145 | /** 146 | * Set the gatorName property. 147 | * Name of most recently spawned alligator 148 | * @see com.niagarasummit.nola.BGatorTracker#gatorName 149 | */ 150 | public void setGatorName(String v) { setString(gatorName,v,null); } 151 | 152 | //////////////////////////////////////////////////////////////// 153 | // Property "gatorLength" 154 | //////////////////////////////////////////////////////////////// 155 | 156 | /** 157 | * Slot for the gatorLength property. 158 | * Length of most recently spawned alligator 159 | * @see com.niagarasummit.nola.BGatorTracker#getGatorLength 160 | * @see com.niagarasummit.nola.BGatorTracker#setGatorLength 161 | */ 162 | public static final Property gatorLength = newProperty(Flags.SUMMARY, new BStatusNumeric(0, BStatus.nullStatus),BFacets.make(BFacets.UNITS, BUnit.getUnit("foot"))); 163 | 164 | /** 165 | * Get the gatorLength property. 166 | * Length of most recently spawned alligator 167 | * @see com.niagarasummit.nola.BGatorTracker#gatorLength 168 | */ 169 | public BStatusNumeric getGatorLength() { return (BStatusNumeric)get(gatorLength); } 170 | 171 | /** 172 | * Set the gatorLength property. 173 | * Length of most recently spawned alligator 174 | * @see com.niagarasummit.nola.BGatorTracker#gatorLength 175 | */ 176 | public void setGatorLength(BStatusNumeric v) { set(gatorLength,v,null); } 177 | 178 | //////////////////////////////////////////////////////////////// 179 | // Property "gatorWeight" 180 | //////////////////////////////////////////////////////////////// 181 | 182 | /** 183 | * Slot for the gatorWeight property. 184 | * Weight of most recently spawned alligator 185 | * @see com.niagarasummit.nola.BGatorTracker#getGatorWeight 186 | * @see com.niagarasummit.nola.BGatorTracker#setGatorWeight 187 | */ 188 | public static final Property gatorWeight = newProperty(Flags.SUMMARY, new BStatusNumeric(0, BStatus.nullStatus),BFacets.make(BFacets.UNITS, BUnit.getUnit("pound"))); 189 | 190 | /** 191 | * Get the gatorWeight property. 192 | * Weight of most recently spawned alligator 193 | * @see com.niagarasummit.nola.BGatorTracker#gatorWeight 194 | */ 195 | public BStatusNumeric getGatorWeight() { return (BStatusNumeric)get(gatorWeight); } 196 | 197 | /** 198 | * Set the gatorWeight property. 199 | * Weight of most recently spawned alligator 200 | * @see com.niagarasummit.nola.BGatorTracker#gatorWeight 201 | */ 202 | public void setGatorWeight(BStatusNumeric v) { set(gatorWeight,v,null); } 203 | 204 | //////////////////////////////////////////////////////////////// 205 | // Property "recordLength" 206 | //////////////////////////////////////////////////////////////// 207 | 208 | /** 209 | * Slot for the recordLength property. 210 | * Current record for longest alligator 211 | * @see com.niagarasummit.nola.BGatorTracker#getRecordLength 212 | * @see com.niagarasummit.nola.BGatorTracker#setRecordLength 213 | */ 214 | public static final Property recordLength = newProperty(0, 0,BFacets.make(BFacets.UNITS, BUnit.getUnit("foot"))); 215 | 216 | /** 217 | * Get the recordLength property. 218 | * Current record for longest alligator 219 | * @see com.niagarasummit.nola.BGatorTracker#recordLength 220 | */ 221 | public double getRecordLength() { return getDouble(recordLength); } 222 | 223 | /** 224 | * Set the recordLength property. 225 | * Current record for longest alligator 226 | * @see com.niagarasummit.nola.BGatorTracker#recordLength 227 | */ 228 | public void setRecordLength(double v) { setDouble(recordLength,v,null); } 229 | 230 | //////////////////////////////////////////////////////////////// 231 | // Property "gatorLogger" 232 | //////////////////////////////////////////////////////////////// 233 | 234 | /** 235 | * Slot for the gatorLogger property. 236 | * Logs all the alligators we've tracked 237 | * @see com.niagarasummit.nola.BGatorTracker#getGatorLogger 238 | * @see com.niagarasummit.nola.BGatorTracker#setGatorLogger 239 | */ 240 | public static final Property gatorLogger = newProperty(0, makeEnabledHistoryExt(),null); 241 | 242 | /** 243 | * Get the gatorLogger property. 244 | * Logs all the alligators we've tracked 245 | * @see com.niagarasummit.nola.BGatorTracker#gatorLogger 246 | */ 247 | public BHistoryExt getGatorLogger() { return (BHistoryExt)get(gatorLogger); } 248 | 249 | /** 250 | * Set the gatorLogger property. 251 | * Logs all the alligators we've tracked 252 | * @see com.niagarasummit.nola.BGatorTracker#gatorLogger 253 | */ 254 | public void setGatorLogger(BHistoryExt v) { set(gatorLogger,v,null); } 255 | 256 | //////////////////////////////////////////////////////////////// 257 | // Action "trackGator" 258 | //////////////////////////////////////////////////////////////// 259 | 260 | /** 261 | * Slot for the trackGator action. 262 | * Generate a new Gator and track it. 263 | * @see com.niagarasummit.nola.BGatorTracker#trackGator() 264 | */ 265 | public static final Action trackGator = newAction(0,BString.make("Allie"),null); 266 | 267 | /** 268 | * Invoke the trackGator action. 269 | * Generate a new Gator and track it. 270 | * @see com.niagarasummit.nola.BGatorTracker#trackGator 271 | */ 272 | public void trackGator(BString gatorName) { invoke(trackGator,gatorName,null); } 273 | 274 | //////////////////////////////////////////////////////////////// 275 | // Action "findRecordGators" 276 | //////////////////////////////////////////////////////////////// 277 | 278 | /** 279 | * Slot for the findRecordGators action. 280 | * Query the alarm database for the record-breaking gators. 281 | * @see com.niagarasummit.nola.BGatorTracker#findRecordGators() 282 | */ 283 | public static final Action findRecordGators = newAction(0,null); 284 | 285 | /** 286 | * Invoke the findRecordGators action. 287 | * Query the alarm database for the record-breaking gators. 288 | * @see com.niagarasummit.nola.BGatorTracker#findRecordGators 289 | */ 290 | public BComponent findRecordGators() { return (BComponent)invoke(findRecordGators,null,null); } 291 | 292 | //////////////////////////////////////////////////////////////// 293 | // Action "writeGatorList" 294 | //////////////////////////////////////////////////////////////// 295 | 296 | /** 297 | * Slot for the writeGatorList action. 298 | * Write the list of gators to a file. 299 | * @see com.niagarasummit.nola.BGatorTracker#writeGatorList() 300 | */ 301 | public static final Action writeGatorList = newAction(0,null); 302 | 303 | /** 304 | * Invoke the writeGatorList action. 305 | * Write the list of gators to a file. 306 | * @see com.niagarasummit.nola.BGatorTracker#writeGatorList 307 | */ 308 | public void writeGatorList() { invoke(writeGatorList,null,null); } 309 | 310 | //////////////////////////////////////////////////////////////// 311 | // Action "ackAlarm" 312 | //////////////////////////////////////////////////////////////// 313 | 314 | /** 315 | * Slot for the ackAlarm action. 316 | * Acknowledge the alarm from this ack request 317 | * @see com.niagarasummit.nola.BGatorTracker#ackAlarm() 318 | */ 319 | public static final Action ackAlarm = newAction(Flags.HIDDEN,new BAlarmRecord(),null); 320 | 321 | /** 322 | * Invoke the ackAlarm action. 323 | * Acknowledge the alarm from this ack request 324 | * @see com.niagarasummit.nola.BGatorTracker#ackAlarm 325 | */ 326 | public BBoolean ackAlarm(BAlarmRecord ackRequest) { return (BBoolean)invoke(ackAlarm,ackRequest,null); } 327 | 328 | //////////////////////////////////////////////////////////////// 329 | // Action "displayNamesQuery" 330 | //////////////////////////////////////////////////////////////// 331 | 332 | /** 333 | * Slot for the displayNamesQuery action. 334 | * Query for display names of child components 335 | * @see com.niagarasummit.nola.BGatorTracker#displayNamesQuery() 336 | */ 337 | public static final Action displayNamesQuery = newAction(0,null); 338 | 339 | /** 340 | * Invoke the displayNamesQuery action. 341 | * Query for display names of child components 342 | * @see com.niagarasummit.nola.BGatorTracker#displayNamesQuery 343 | */ 344 | public void displayNamesQuery() { invoke(displayNamesQuery,null,null); } 345 | 346 | //////////////////////////////////////////////////////////////// 347 | // Topic "newGator" 348 | //////////////////////////////////////////////////////////////// 349 | 350 | /** 351 | * Slot for the newGator topic. 352 | * @see com.niagarasummit.nola.BGatorTracker#fireNewGator 353 | */ 354 | public static final Topic newGator = newTopic(0,null); 355 | 356 | /** 357 | * Fire an event for the newGator topic. 358 | * @see com.niagarasummit.nola.BGatorTracker#newGator 359 | */ 360 | public void fireNewGator(BValue event) { fire(newGator, event, null); } 361 | 362 | //////////////////////////////////////////////////////////////// 363 | // Type 364 | //////////////////////////////////////////////////////////////// 365 | 366 | public Type getType() { return TYPE; } 367 | public static final Type TYPE = Sys.loadType(BGatorTracker.class); 368 | 369 | /*+ ------------ END BAJA AUTO GENERATED CODE -------------- +*/ 370 | 371 | 372 | //////////////////////////////////////////////////////////////// 373 | // BComponent Overrides 374 | //////////////////////////////////////////////////////////////// 375 | 376 | /** 377 | * Initialize the Gator Tracker. 378 | */ 379 | public void started() throws Exception 380 | { 381 | super.started(); 382 | random = new Random(); 383 | } 384 | 385 | /** 386 | * Override of BNumericPoint execution. 387 | */ 388 | public void onExecute(BStatusValue out, Context cx) 389 | { 390 | out.copyFrom(getGatorLength()); 391 | } 392 | 393 | 394 | //////////////////////////////////////////////////////////////// 395 | // Actions 396 | //////////////////////////////////////////////////////////////// 397 | 398 | /** 399 | * Track a new alligator. 400 | */ 401 | public void doTrackGator(BString gatorName) 402 | { 403 | // Create a gator 404 | BGator gator = createGator(); 405 | 406 | // Add it to the family 407 | add(gatorName.getString(), gator); 408 | BStatusNumeric sn = new BStatusNumeric(gator.getLength()); 409 | setGatorLength(sn); 410 | sn = new BStatusNumeric(gator.getWeight()); 411 | setGatorWeight(sn); 412 | setGatorName(gatorName.toString()); 413 | 414 | // Check if it's a new record 415 | double gatorLen = gator.getLength(); 416 | if (gatorLen > getRecordLength()) 417 | { 418 | // Generate alarm 419 | Map alarmData = new HashMap(); 420 | alarmData.put(GATOR_NAME, gatorName); 421 | alarmData.put(GATOR_LENGTH, getGatorLength().getValueValue()); 422 | alarmData.put(GATOR_WEIGHT, getGatorWeight().getValueValue()); 423 | alarmData.put(OLD_RECORD, (BDouble)get(recordLength)); 424 | alarmData.put(NEW_RECORD, getGatorLength().getValueValue()); 425 | BAlarmRecord rec = new BAlarmRecord(); 426 | rec.setAlarmData(BFacets.make(alarmData)); 427 | rec.setSource(BOrdList.make(getNavOrd())); 428 | getAlarmService().routeAlarm(rec); 429 | 430 | // Update the record 431 | setRecordLength(gatorLen); 432 | gator.setIsRecord(true); 433 | } 434 | 435 | // The frozen history extension automatically logs the new addition... 436 | execute(); 437 | 438 | // Fire a topic so interested parties can take action 439 | fireNewGator(null); 440 | } 441 | 442 | 443 | //////////////////////////////////////////////////////////////// 444 | // BIAlarmSource 445 | //////////////////////////////////////////////////////////////// 446 | 447 | public BBoolean doAckAlarm(BAlarmRecord rec) 448 | { 449 | if (!isRunning()) return BBoolean.FALSE; 450 | 451 | // Acknowledge the alarm 452 | rec.setAckTime(Clock.time()); 453 | rec.setAckState(BAckState.acked); 454 | rec.setAckRequired(false); 455 | 456 | try 457 | { 458 | getAlarmService().routeAlarm(rec); 459 | } 460 | catch (Exception e) 461 | { 462 | log.error(MessageFormat.format(lex.getText("gatorTracker.couldNotAck"), 463 | new Object[] { rec })); 464 | } 465 | 466 | return BBoolean.TRUE; 467 | } 468 | 469 | 470 | //////////////////////////////////////////////////////////////// 471 | // Alarm API Usage 472 | //////////////////////////////////////////////////////////////// 473 | 474 | /** 475 | * Find all the alarms (new gator length records) 476 | * See Developer Doc topic at module://docDeveloper/doc/alarm.html 477 | */ 478 | public BComponent doFindRecordGators() 479 | { 480 | BComponent gatorList = new BComponent(); 481 | try 482 | { 483 | log.message(lex.getText("gatorTracker.recordGators.msg")); 484 | BOrdList source = BOrdList.make(getNavOrd()); 485 | BAlarmService alarmService = getAlarmService(); 486 | 487 | // Niagara AX 488 | Cursor cursor = alarmService.getAlarmDb().getAlarmsForSource(source); 489 | // // Niagara 4 490 | // Cursor cursor; 491 | // try (AlarmDbConnection conn = alarmService.getAlarmDb().getDbConnection(null)) 492 | // { 493 | // cursor = conn.getAlarmsForSource(source); 494 | int count = 0; 495 | while (cursor.next() & (++count < 10)) 496 | { 497 | BAlarmRecord rec = (BAlarmRecord)cursor.get(); 498 | BFacets alarmData = rec.getAlarmData(); 499 | log.message(MessageFormat.format( 500 | lex.getText("gatorTracker.gatorStats"), 501 | new Object[] { alarmData.get(GATOR_LENGTH) })); 502 | gatorList.add(alarmData.gets(GATOR_NAME, null), 503 | new BGator(alarmData.geti(GATOR_LENGTH, 0), alarmData.geti(GATOR_WEIGHT, 0))); 504 | } 505 | // } 506 | } 507 | catch (Exception e) 508 | { 509 | log.error(MessageFormat.format( 510 | lex.getText("gatorTracker.couldNotQuery"), 511 | new Object[] { "record gators" })); 512 | 513 | } 514 | return gatorList; 515 | } 516 | 517 | 518 | //////////////////////////////////////////////////////////////// 519 | // Collections Usage 520 | //////////////////////////////////////////////////////////////// 521 | 522 | /** 523 | * Query for display names: demonstration of Collections API changes 524 | * See Developer Doc topic at module://docDeveloper/doc/collections.html 525 | */ 526 | public void doDisplayNamesQuery() 527 | { 528 | try 529 | { 530 | // Niagara AX 531 | BICollection result = (BICollection)BOrd.make("bql:select displayName").get(this); 532 | BITable table = result.toTable(); 533 | // // Niagara 4 534 | // BITable table = (BITable)BOrd.make("bql:select displayName").get(this); 535 | 536 | StringBuffer sb = new StringBuffer(); 537 | 538 | // Niagara AX 539 | for (int i=0; i cursor = table.cursor(); 542 | // while (cursor.next()) 543 | 544 | { 545 | sb.append(MessageFormat.format( 546 | lex.getText("gatorTracker.displayNames.result.elem"), 547 | 548 | // Niagara AX 549 | new Object[] { table.get(i), table.get(i).getType() })).append('\n'); 550 | // // Niagara 4 551 | // new Object[] { cursor.get(), cursor.get().getType() })).append('\n'); 552 | } 553 | log.message(MessageFormat.format( 554 | lex.getText("gatorTracker.displayNames.result"), 555 | new Object[] { sb.toString() })); 556 | } 557 | catch (Exception e) 558 | { 559 | log.error(MessageFormat.format( 560 | lex.getText("gatorTracker.couldNotQuery"), 561 | new Object[] { "display names" })); 562 | } 563 | } 564 | 565 | 566 | //////////////////////////////////////////////////////////////// 567 | // File write 568 | //////////////////////////////////////////////////////////////// 569 | 570 | /** 571 | * Query the alarm database for all of the record-breaking gators, 572 | * and write them to the gator list file. 573 | * This is a demonstration of the file writes. Note that the caret (^) 574 | * symbol, referred to "Station Home" in Niagara AX as the folder with 575 | * the station's name. In Niagara 4, it refers to "Station Home", but this 576 | * is now the folder called "shared" underneath of the folder with the station's 577 | * name. The folder with the station's name is now called "Protected Station Home", 578 | * and is not generally accessible by user code. 579 | */ 580 | public void doWriteGatorList() 581 | { 582 | try 583 | { 584 | BIFile file = (BIFile)BOrd.make("file:^gator/gatorList.txt").get(); 585 | OutputStream out = file.getOutputStream(); 586 | BufferedWriter w = new BufferedWriter(new OutputStreamWriter(out)); 587 | w.write(lex.getText("gatorTracker.gatorList.title") + '\n'); 588 | 589 | log.message(lex.getText("gatorTracker.recordGators.msg")); 590 | BOrdList source = BOrdList.make(getNavOrd()); 591 | BAlarmService alarmService = getAlarmService(); 592 | 593 | // Niagara AX 594 | Cursor cursor = alarmService.getAlarmDb().getAlarmsForSource(source); 595 | // // Niagara 4 596 | // Cursor cursor; 597 | // try (AlarmDbConnection conn = alarmService.getAlarmDb().getDbConnection(null)) 598 | // { 599 | // cursor = conn.getAlarmsForSource(source); 600 | int count = 0; 601 | while (cursor.next() & (++count < 10)) 602 | { 603 | BAlarmRecord rec = (BAlarmRecord)cursor.get(); 604 | BFacets alarmData = rec.getAlarmData(); 605 | w.write(MessageFormat.format( 606 | lex.getText("gatorTracker.gatorStats"), 607 | new Object[] { alarmData.get(GATOR_NAME), alarmData.get(GATOR_LENGTH), alarmData.get(GATOR_WEIGHT) })); 608 | w.write('\n'); 609 | } 610 | // } 611 | 612 | w.flush(); 613 | w.close(); 614 | } 615 | catch (Exception e) 616 | { 617 | log.error(MessageFormat.format( 618 | lex.getText("gatorTracker.writeList.error"), 619 | new Object[] { e })); 620 | } 621 | } 622 | 623 | 624 | //////////////////////////////////////////////////////////////// 625 | // Private Utility 626 | //////////////////////////////////////////////////////////////// 627 | 628 | /** 629 | * Get a reference to the station's {@code BAlarmService}. 630 | * Only valid in a running station. 631 | * @return the alarm service. 632 | */ 633 | private BAlarmService getAlarmService() 634 | { 635 | return (BAlarmService) BOrd.make("service:alarm:AlarmService").get(); 636 | } 637 | 638 | 639 | //////////////////////////////////////////////////////////////// 640 | // Gator Creation 641 | //////////////////////////////////////////////////////////////// 642 | 643 | private BGator createGator() 644 | { 645 | int gLen = random.nextInt(MAX_GATOR_LENGTH); 646 | int weightPerFoot = random.nextInt(GATOR_WEIGHT_RANGE) + BASE_GATOR_WEIGHT_PER_FOOT; 647 | int gWt = gLen * weightPerFoot; 648 | BGator g = new BGator(gLen, gWt); 649 | return g; 650 | } 651 | 652 | Random random; 653 | public static final int MAX_GATOR_LENGTH = 16; 654 | public static final int GATOR_WEIGHT_RANGE = 20; 655 | public static final int BASE_GATOR_WEIGHT_PER_FOOT = 60; 656 | 657 | 658 | //////////////////////////////////////////////////////////////// 659 | // Constants and Instance Fields 660 | //////////////////////////////////////////////////////////////// 661 | 662 | private static Lexicon lex = Lexicon.make("nola"); 663 | private static Log log = Log.getLog("nola"); 664 | 665 | public static final String GATOR_NAME = "GatorName"; 666 | public static final String GATOR_LENGTH = "GatorLength"; 667 | public static final String GATOR_WEIGHT = "GatorWeight"; 668 | public static final String OLD_RECORD = "OldRecord"; 669 | public static final String NEW_RECORD = "NewRecord"; 670 | 671 | } 672 | --------------------------------------------------------------------------------