Mail merge template : local variable not getting value in if..else - mailmerge

{ MERGEFIELD TableStart:Test}{ SET PLAN {MERGEFIELD Name}="XYZ" "1" "0"}}
{ MERGEFIELD TableEnd:Test }
{ IF { REF PLAN } = "1" "Pass" "Fail"}
In this example always getting result Fail, whether Name is "XYZ" or not.
can anyone suggest further ?

In your case in the SET field you should use IF field to evaluate condition. Please see the following field codes:
{ SET PLAN { IF {MERGEFIELD Name} = XYZ "1" "0"} }
{ IF { REF PLAN } = "1" "Pass" "Fail" }
After executing simple mail merge using the following code:
Document doc = new Document(#"C:\Temp\in.docx");
doc.MailMerge.Execute(new string[] { "Name" }, new string[] { "XYZ" });
doc.Save(#"C:\Temp\out.docx");
The resulting document has the following field codes:
{ SET PLAN XYZ = XYZ "1" "0"} }
{ IF { REF PLAN } = "1" "Pass" "Fail" }
which is properly evaluated with "Pass" text.
Also in MS Word document field whitespaces matters. See the screenshot from MS Word document on my side

Related

does anyone know how to transform this query from mongo to mongo template?

what i want to do is first transform this query to mongo template
db.project.aggregate([
{
$project: {
boos:1,
"errors":{
$cond: {
if: { $eq : [ 3,"$error.status" ] },
then: '$$REMOVE',
else: "$error"
}
}
}
}
])
the goal is to bring all the projects and errors, however to show the errors as null or blank if their status is 3
If you just want to find all the projects whose status is 3:
Query query = new Query();
query.addCriteria(Criteria.where("status").is(3));
List<Project> projects = mongoTemplate.find(query, "project");

How does GraphQL support AND-OR query conditions?

I'm new to GraphQL. There is a requirement that query all the qualified data from CUSTOMERS table, which meets condition: GENDER == 'MALE' or 'AGE' >= 20. What GQL should looks like for it?
Someone proposed a similar thing before but it is rejected. That means GraphQL does not support it natively and you have to roll it out by yourself.
Several ways to do it based on what I see :
(1) Define your own query language such as what stackoverflow or Shopify does :
type Query{
customers (query:String) : [Customer]
}
The query becomes :
{
customers (query : "GENDER == 'MALE' or 'AGE' >= 20"){
id
name
}
}
(2) Define your own input object models that can cover all the required searching requirement.Prisma try to define one in OpenCRUD specification .You may take a look on it for the idea . For example , you can define an input model like :
input CustomerFilter {
AND : [CustomerFilter]
OR : [CustomerFilter]
# Define the fields that you support to search
gender : String
gender_not : String
....
....
...
...
age : Int
age_gte : Int
}
type Query{
customers (filter:CustomerFilter) : [Customer]
}
And the query becomes :
{
customers (filter : {
OR: [
{ gender : 'MALE' } ,
{ age_gte: 20 }
]
}){
id
name
}
}
This is another filter model for reference. The idea is to tailor-made it such that it is just enough to handle all your application requirements without introducing any unnecessary filtering complexity.
Also , you most probably need to consider something like pagination if it potentially will return many data. It means you have to add an offset and limit to the input arguments for each query to somehow limit the number of record returned if you are doing offset-based pagination or take a look on Relay Specification if you want to do it in the cursor-based pagination style.
You need to define query, schema and resolver. Your Query will be like :
type Query {
nameItAsPerUsecase: Customer
}
Schema will be like these :
type Customer{
name : String
age: Int
.. add more fields as per as your need
}
Your resolver will be like this: -
#Component
public class CustomerQuery implements GraphQLQueryResolver {
#Autowired
private CustomerRepository customerRepository ;
public Customer getNameItAsPerUsecase() {
return customerRepository.findByGenderAndAgeGreaterThanEqual(String gender, int age);
}
}
Nested logic with the same and/or conjunction can be simplified into a single list.
For example, the following complex query:
or: [
{ or: [ { foo: { eq: "A" } }, { bar: { eq: "B" } } ] },
{ or: [ { baz: { eq: "C" } }, { quz: { eq: "D" } } ] }
]
} ) { ... }
Moreover, can be simplified into the following simplified query syntax:
queryPost(filter: {
or: [
{ foo: { eq: "A" } },
{ bar: { eq: "B" } },
{ baz: { eq: "C" } },
{ quz: { eq: "D" } }
]
} ) { ... }

What kind of Java type to pass into Criteria.all()?

I am trying to find a document with an array of tags which match a list of values,
using the MongoDB's $all function through Spring Data MongoDB API for all().
Tag is a embedded document with two fields: type and value.
I am not sure what kind of Java type to pass in to the method as it accepts an array of Objects, tried to pass in an array of Criteria objects into the the function but the output is below:
Query: { "tags" : { "$all" : [ { "$java" : org.springframework.data.mongodb.core.query.Criteria#5542c4fe }, { "$java" : org.springframework.data.mongodb.core.query.Criteria#5542c4fe } ] } }, Fields: { }, Sort: { }
How should I proceed?
I want to achieve the following:
db.template.find( { tags: { $all: [ {type:"tagOne", value: "valueOne"}, {type:"tagTwo", value: "valueTwo"} ] } } )
Edited for clarity:
The code which I used is similar to:
Query query = new Query(baseCriteria.and("tags").all( criteriaList.toArray()))
The criteria list is formed by:
Criteria criteria = new Criteria();
criteria.and("type").is(tag.getType()).and("value").is(tag.getValue());
criteriaList.add(criteria);
OK, I've just found out, the Java type required is org.bson.Document, which you can get using:
criteria.getCriteriaObject()

Terraform 0.12 nested for loops

I am trying to implement nested for loops using Terraform 0.12's new features in order to loop through AWS IAM users, each of which can have one or more policies attached. The variable used to represent this list is of type map(list(string)) and looks something like this:
{
"user 1" = [ "policy1", "policy2" ],
"user 2" = [ "policy1" ]
}
Getting the list of users to create is easy enough via keys(), but since there is currently no mechanism for nesting looped resource creation in Terraform, the policy attachments have to happen as a singular loop independent of each user. So, I am attempting to construct a list of user:policy associations from the map input that would look something like this based on the example above:
[
[ "user1", "policy1" ],
[ "user1", "policy2" ],
[ "user2", "policy1" ]
]
I am attempting construct that list and store it in a local variable like so, where var.iam-user-policy-map is the input map:
locals {
...
association-list = [
for user in keys(var.iam-user-policy-map):
[
for policy in var.iam-user-policy-map[user]:
[user, policy]
]
]
...
}
However, I am getting errors when attempting to access the values in that nested list. I am trying to access the user portion of the association with the reference local.association-list[count.index][0] and the policy with local.association-list[count.index][1], but on running terraform plan it errors out:
Error: Incorrect attribute value type
on main.tf line 27, in resource "aws_iam_user_policy_attachment" "test-attach":
27: user = local.association-list[count.index][0]
Inappropriate value for attribute "user": string required.
Error: Incorrect attribute value type
on main.tf line 27, in resource "aws_iam_user_policy_attachment" "test-attach":
27: user = local.association-list[count.index][0]
Inappropriate value for attribute "user": string required.
Error: Invalid index
on main.tf line 28, in resource "aws_iam_user_policy_attachment" "test-attach":
28: policy_arn = "arn:aws-us-gov:iam::aws:policy/${local.association-list[count.index][1]}"
|----------------
| count.index is 0
| local.association-list is tuple with 2 elements
The given key does not identify an element in this collection value.
Error: Invalid template interpolation value
on main.tf line 28, in resource "aws_iam_user_policy_attachment" "test-attach":
28: policy_arn = "arn:aws-us-gov:iam::aws:policy/${local.association-list[count.index][1]}"
|----------------
| count.index is 1
| local.association-list is tuple with 2 elements
Cannot include the given value in a string template: string required.
What am I doing wrong?
The for expression in your local value association-list is producing a list of list of lists of strings, but your references to it are treating it as a list of lists of strings.
To get the flattened representation you wanted, you can use the flatten function, but because it would otherwise group everything into a single flat list I'd recommend making the innermost value an object instead. (That will also make the references to it clearer.)
locals {
association-list = flatten([
for user in keys(var.iam-user-policy-map) : [
for policy in var.iam-user-policy-map[user] : {
user = user
policy = policy
}
]
])
}
The result of this expression will have the following shape:
[
{ user = "user1", policy = "policy1" },
{ user = "user1", policy = "policy2" },
{ user = "user2", policy = "policy2" },
]
Your references to it can then be in the following form:
user = local.association-list[count.index].user
policy_arn = "arn:aws-us-gov:iam::aws:policy/${local.association-list[count.index].policy}"
If you need a map for 'for_each', 'merge' is convenient.
variable "iam-user-policy-map" {
default = {
"user 1" = ["policy1", "policy2"],
"user 2" = ["policy1"]
}
}
locals {
association-map = merge([
for user, policies in var.iam-user-policy-map : {
for policy in policies :
"${user}-${policy}" => {
"user" = user
"policy" = policy
}
}
]...)
}
output "association-map" {
value = local.association-map
}
Outputs:
association-map = {
"user 1-policy1" = {
"policy" = "policy1"
"user" = "user 1"
}
"user 1-policy2" = {
"policy" = "policy2"
"user" = "user 1"
}
"user 2-policy1" = {
"policy" = "policy1"
"user" = "user 2"
}
}
Example for_each usage:
resource "null_resource" "echo" {
for_each = local.association-map
provisioner "local-exec" {
command = "echo 'policy - ${each.value.policy}, user - ${each.value.user}'"
}
}
https://github.com/hashicorp/terraform/issues/22263#issuecomment-969549347
I am not sure where I got this answer from, but this one worked for me.
locals {
schemas = [
"PRIVATE",
"PUBLIC",
"MY_SCHEMA",
]
privileges = [
"CREATE TABLE",
"CREATE VIEW",
"USAGE",
]
# Nested loop over both lists, and flatten the result.
schema_privileges = distinct(flatten([
for schema in local.schemas : [
for privilege in local.privileges : {
privilege = privilege
schema = schema
}
]
]))
}
resource "snowflake_schema_grant" "write_permissions" {
# We need a map to use for_each, so we convert our list into a map by adding a unique key:
for_each = { for entry in local.schema_privileges: "${entry.schema}.${entry.privilege}" => entry }
database_name = "MY_DATABASE"
privilege = each.value.privilege
roles = "DAVE"
schema_name = each.value.schema
}

NEST (ElasticSearch) matching Highlights to documents

I'm using C# NEST with ElasticSearch. I'm able to query an index of Products and look in their Name and CategoryName fields for matches. I can also extend the query using Highlights.
Now in my IQueryResponse response I have two collections: (1) .Documents and (2) .Highlights.
e.g.: Consider the search for: "cat" which has 3 document results:
{
{ Name: "Cat product", CategoryName: "Category1" },
{ Name: "Some product", CategoryName: "Category2" },
{ Name: "Some product2", CategoryName: "Category3" }
}
But now I have 4 highlight results:
{
{ Field: "name", Highlights: ['"<u>Cat</u> product"'] },
{ Field: "categoryName", Highlights: ['"<u>Cat</u>egory1"'] },
{ Field: "categoryName", Highlights: ['"<u>Cat</u>egory2"'] },
{ Field: "categoryName", Highlights: ['"<u>Cat</u>egory3"'] }
}
They seem to be in no way related to each other. How do I know which Highlight item belongs to which Document item?
IQueryResponse also exposes .DocumentsWithMetaData of type IEnumerable<IHit<T>> where T is the type of your document
This is basically the unwrapped view of the results as return by elasticsearch IHit<T> has many useful properties such as the Highlights.
I've added a DocumentId result to the highlight class Highlight so that no matter how you get to the highlight you can relate it back easily to the hit.
So use .DocumentsWithMetaData for now, the next release will have a more logical API for highlights.
here is an updated answer for version 7.x. You receive two collections as before, .Documents and .Hits .
Within .Hits each one has an .Id that matches the _id of the index in elasticsearch. Note: if you request more than one highlighting .NumberofFragments in your query, you will just keep overwriting the result.title and result.content in the code below, so take this as a loose example to indicate how you can match the highlight result to the correct document result, and then overwrite the document field with the one containing the highlighting.
if (response.Documents.Count > 0)
{
foreach (MyResultClass result in response.Documents) //cycle through your results
{
foreach (var hit in response.Hits) // cycle through your hits to look for match
{
if (hit.Id == result.id) //you found the hit that matches your document
{
foreach (var highlightField in hit.Highlight)
{
if (highlightField.Key == "title")
{
foreach (var highlight in highlightField.Value)
{
result.title = highlight.ToString();
}
}
else if (highlightField.Key == "content")
{
foreach (var highlight in highlightField.Value)
{
result.content = highlight.ToString();
}
}
}
}
}
}

Resources