DXL filter using if else loop - ibm-doors

I am using Door 9.6 and trying to create a generic filter which can be used for multiple documents in my project.
The project documents have an attribute "Requirement Type". This attribute can have value as "Functional", "Non Functional", "Information" etc.
The documents are not uniform and some of the documents have "Requirement Type" as "Functional", "Information" .
I am trying to use attributeValue() to find out this variation but somehow couldn't figure out the issue in the code.
-E- DXL: <Line:16> incorrect arguments for (||)
-E- DXL: <Line:16> incorrect arguments for (||)
-E- DXL: <Line:16> undeclared variable (f1)
-E- DXL: <Line:16> incorrect arguments for (=)
Here is the code
Module m = current
load view("default view")
AttrDef ad = find(current Module, "Requirement Type")
if (attributeValue(ad, "Non functional")){
Filter f1 = contains(attribute "Requirement Type", "Non Functional", false)
}
else {
Filter f1= contains(attribute "Requirement Type", "Functional", false)
}
Filter f2= contains(attribute "Requirement Type", "Information", false)
Filter f3= contains(attribute "Requirement Type", "Functional", false)
Filter set_f = f1 || f2 || f3
set(current Module, set_f)

When a variable is declared inside { brackets }, the variable will not be visible from the outside. Declare it outside the brackets, but set them inside.
Module m = current
load view("default view")
AttrDef ad = find(current Module, "Requirement Type")
Filter f1
if (attributeValue(ad, "Non functional")){
f1 = contains(attribute "Requirement Type", "Non Functional", false)
}
else {
f1= contains(attribute "Requirement Type", "Functional", false)
}
Filter f2= contains(attribute "Requirement Type", "Information", false)
Filter f3= contains(attribute "Requirement Type", "Functional", false)
Filter set_f = f1 || f2 || f3
set(current Module, set_f)

Related

How to lookup value from another table in Power Query?

I want to transform the strategy code number in my Strategy Code column (Data table) into strategy name based on the dim_strategy table. My Challenge is there can be more than 1 strategy code appear in each row and hence I want to use + as the delimiter to combine different strategy name in Data table.
This is the desired output in Data table:
This query will achieve that for you. You will need to change the source for whatever your table source is but the rest of the steps should be exactly the same.
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"No.", Int64.Type}, {"Strategy Code", type text}}),
#"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Strategy Code", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Strategy Code"),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Strategy Code", Int64.Type}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type1", {"Strategy Code"}, dim_strategy, {"Strategy Code"}, "dim_strategy", JoinKind.LeftOuter),
#"Expanded dim_strategy" = Table.ExpandTableColumn(#"Merged Queries", "dim_strategy", {"Strategy"}, {"Strategy"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded dim_strategy",{"Strategy Code"}),
#"Grouped Rows" = Table.Group(#"Removed Columns", {"No."}, {{"Stretagy Name", each Text.Combine([Strategy], " + "), type nullable text}})
in
#"Grouped Rows"
Or you could add a column
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Strategy Name", each Text.Combine(
List.Transform(Text.Split([Strategy Code],","), each
dim_strategy[Strategy]{List.PositionOf(dim_strategy[Strategy Code],Number.From(_))}
),", "))
in #"Added Custom"
It converts the Strategy Code to a list, then to numerical list, finds the position of that in the dim_strategy Strategy Code column, then pulls the corresponding Strategy column and recombines the list into text
List.Buffer dim_strategy2[Strategy Code] as an earlier step if dataset is large

Alert Creation for All VMs under same subscription in Azure using Terraform

**I am trying to deploy below terraform alert for all VMs under my subscription, and subscription id I've kept it in variables file. But its throwing below error.
Also how can I define type as MultipleResourceMultipleMetricCriteria for this below template as in ARM templates we can define this type as odata.type but when I try odata_type in terraform its not accepting it.
also is there any way I can grab subscription id at runtime using query instead of passing subscription id in variables file. Is there any quickstart template site for the terraform for reference.
Error: **Can not parse "scopes.0" as a resource id: Cannot parse Azure ID: parse "{subscription_id is getting printed here}":** invalid URI for request**
on metric.tf line 1, in resource "azurerm_monitor_metric_alert" "example":
1: resource "azurerm_monitor_metric_alert" "example" {
terraform.tf file
resource "azurerm_monitor_metric_alert" "example" {
name = "example-metricalert"
resource_group_name = "MyTemp"
scopes = ["${var.subscription_id}"]
description = "Action will be triggered when Transactions count is greater than 50."
target_resource_type = "Microsoft.Compute/virtualMachines"
criteria {
metric_namespace = "Microsoft.Compute/virtualMachines"
metric_name = "Percentage CPU"
aggregation = "Total"
operator = "GreaterThan"
threshold = 50
}
action {
action_group_id = "/subscriptions/xxxxxxxx/resourceGroups/xxxxx/providers/Microsoft.Insights/actionGroups/xxxxx"
}
}
You can use Data Source: azurerm_subscription to access information about an existing Subscription.
terraform.tf file will look like this:
data "azurerm_subscription" "current" {
subscription_id = var.subscription_id
}
resource "azurerm_monitor_metric_alert" "example" {
name = "example-metricalert"
resource_group_name = "MyTemp"
scopes = [data.azurerm_subscription.current.id]
description = "Action will be triggered when Transactions count is greater than 50."
target_resource_type = "Microsoft.Compute/virtualMachines"
criteria {
metric_namespace = "Microsoft.Compute/virtualMachines"
metric_name = "Percentage CPU"
aggregation = "Total"
operator = "GreaterThan"
threshold = 50
}
action {
action_group_id = "/subscriptions/xxxxxxxx/resourceGroups/xxxxx/providers/Microsoft.Insights/actionGroups/xxxxx"
}
}

How can I find the first indirect parent

So imagine the following:
Company A is owned by Company B { intermediate = true }
which is owned by Company C { intermediate = false }
which is owned by Company D { intermediate = false }
Given that I'm at "Company A" I want to get to "Company C" without returning "Company D"
(I want the first Company that isn't a intermediate.)
There's also the following scenario:
Company Foo is owned by Company Bar { intermediate = false }
Company Foo is owned by Company Baz { intermediate = true }
Company Baz is owned by Company Das { intermediate = false }
In this case, it should return both "Company Bar" and "Company Das" because they're both owners of "Company Foo".
This should work:
MATCH p = (:Company {name: "Foo"})-[:IS_OWNED_BY*]->(first:Company {intermediate: false})
WHERE NONE(n IN NODES(p)[1..-1] WHERE NOT n.intermediate)
RETURN first
The WHERE clause tests that none of the nodes in between the start and end nodes have a false intermediate value.
Note: If there can be many long IS_OWNED_BY paths, you should consider putting a reasonable upper bound on the variable-length relationship pattern to avoid taking too long or running out of memory. For example, [:IS_OWNED_BY*..6].

Deserialize Lua table with NLua

I have searched the web and particularly this:
Table Serialiazation
and none of them work.
I am trying the simplest of tables as follows:
THIS IS THE INPUT.LUA FILE
{
["customers"] =
{
["name"] = "John Smith",
["age"] = 45
},
{
["name"] = "Susan Jones",
["age"] = 34
},
}
Where x = input.lua
And I have in my Lua an:-
if(type (x) == "table" then
dostuff()
else
return "this is not a table"
end
And all I get with all the deserializers is the "this is not a table".
I am now writing my own deserializer, which will have to handle all the escaping characters, and the beginning of tables, and the tracking of nested tables and the typing of values - why????
Am I a moron - which part of the table serialiazion routines did I misunderstand??

parsing a text file into groups using Scala

I have a CSV file that is really a set of many CSV files in one. Something like this:
"First Part"
"Some", "data", "in", "here"
"More", "stuff", "over", "here"
"Another Part"
"This", "section", "is", "not", "the", "same", "as", "the", "first"
"blah", "blah", "blah", "blah", "blah", "blah", "blah", "blah", "blah"
"Yet another section"
"And", "this", "is", "yet", "another"
"blah", "blah", "blah", "blah", "blah"
I'd like to break it into separate components. Given I know the header for each section, it'd be nice if I could do some kind of groupBy or something where I pass in a set of regexp's representing header patterns and return a Seq[Seq[String]] or something similar.
You could do the following:
val groups = List("\"First Part\"", "\"Another Part\"", "\"Yet another section\"")
val accumulator = List[List[String]]()
val result = input.split("\n").foldLeft(accumulator)((acc,e) => {
if (groups.contains(e)) {
// Make new group when we encounter a string matching one of the groups
Nil :: acc
} else {
// Grab current group and modify it
val newHead = e :: acc.head
newHead :: acc.tail
}
})
Each list in result now represent a group. If you want to use regex to find your matches then just replace the groups.contains(e) with a match test. There are some subtleties here that might deserve a mention:
The algorithm will fail if the input does not start with a heading
If a heading is present several times each time it is present will generate a new group
Groups will contain the lines in the input in reverse.
Empty lines will also be included in the result.
EDIT this is similar to the other solution that was posted at the same time. A similar thing for the sections headings could be done instead of my quick hack of size==1. This solution has the added benefit of including the secion name so ordering doesn't matter.
val file: List[String] = """
heading
1,2,3
4,5
heading2
5,6
""".split("\n").toList
val splitFile = file
.map(_.split(",").toList)
.filterNot(_ == List(""))
.foldLeft(List[(String, List[List[String]])]()){
case (h::t,l) => {if(l.size==1) (l(0),List()):: h :: t else (h._1, l :: h._2) :: t};
case (Nil, l)=> if(l.size==1) List((l(0),List())) else List() }
.reverse
produces
splitFile: List[(String, List[List[String]])] = List((heading,List(List(4, 5), List(1, 2, 3))), (heading2,List(List(5, 6))))

Resources