Freemarker insert String into Javascript code - freemarker

I would like to know how can I insert a string into a javascript code like in the example below:
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "Restaurant",
"name": "Dave's Steak House",
"address": {
"#type": "PostalAddress",
"streetAddress": "148 W 51st St",
"addressLocality": "New York",
"addressRegion": "NY",
"postalCode": "10019",
"addressCountry": "US"
}
}
</script>
The problem is that when I try to insert the String between js it appears interpreted as HTML code with %, &20 etc. I have tried with ?html, escape, no escape, ?string, ?js_string, etc.
That's the String:
{
"#context": "http://schema.org",
"#type": "Restaurant",
"name": "Dave's Steak House",
"address": {
"#type": "PostalAddress",
"streetAddress": "148 W 51st St",
"addressLocality": "New York",
"addressRegion": "NY",
"postalCode": "10019",
"addressCountry": "US"
}
}
And the code:
${myString}

Related

Nifi - Route the JSON based on the Array Name

I am new to Nifi, i hv a requirement where we get multiple JSON inputs with different Header Names. I have to parse the JSON and insert into different tables based on the Header value.
Not sure how to use RouteonContent processor or EvaluateJSON Path processor
Input 1
{
"Location": [
{
"country": "US",
"division": "Central",
"region": "Big South",
"locationID": 1015,
"location_name": "Hattiesburg, MS (XF)",
"location_type": "RETAIL",
"location_sub_type": "COS",
"store_type": "",
"planned_open_date": "",
"planned_close_date": "",
"actual_open_date": "2017-07-26",
"actual_close_date": "",
"new_store_flag": "",
"address1": "2100 Lincoln Road",
"address2": "",
"city": "Hattiesburg",
"state": "MS",
"zip": 39402,
"include_for_planning": "Y"
},
{
"country": "US",
"division": "Central",
"region": "Big South",
"locationID": 1028,
"location_name": "Laurel, MS",
"location_type": "RETAIL",
"location_sub_type": "COS",
"store_type": "",
"planned_open_date": "",
"planned_close_date": "",
"actual_open_date": "",
"actual_close_date": "",
"new_store_flag": "",
"address1": "1225 5th street",
"address2": "",
"city": "Laurel",
"state": "MS",
"zip": 39440,
"include_for_planning": "Y"
}
]
Input 2
{
"Item": [
{
"npi_code": "NEW",
"cifa_category": "XM",
"o9_category": "Accessories"
},
{
"npi_code": "NEW",
"cifa_category": "XM0",
"o9_category": "Accessories"
}
]
Use the website https://jsonpath.com/ to figure out the proper JSON expression. But what you could potentially do is use: if the array contains either $.npi_code then do X and if it contains $. country, then do Y

API Platform 3 does not return null data in response body

In API Platform 2.7 the response body contained fields that had a null value, after upgrading to API Platform 3 the response body does not contain fields that have a null value. Is this deliberate or due to a configuration change I need to make.
I executed the same call from the api/docs page for 2.7 and 3.0 I expected the results to be the same.
API Platform 2.7 response for class Patient
{
"#context": "/api/contexts/Patient",
"#id": "/api/patients/8110",
"#type": "Patient",
"account": "/api/accounts/8110",
"accountId": 8110,
"isDependent": false,
"isGuardian": false,
"organization": "/api/organizations/765",
"email": null,
"title": null,
"firstName": "CA",
"middleInitial": "A",
"lastName": "Patient",
"suffix": null,
"photoMedia": null,
"sex": "male",
"birthDate": "2000-01-01T00:00:00+00:00",
"addressLineOne": "5759 Witting Corners",
"addressLineTwo": null,
"city": "Marvintown",
"zipCode": "35507",
"state": {
"#id": "/api/states/681",
"#type": "State",
"abbreviation": "CA"
},
"phoneNumber": "617-491-0000",
"mobileNumber": null,
"workNumber": null
}
API Platform 3.0 response for class Patient
{
"#context": "/api/contexts/Patient",
"#id": "/api/patients/8110",
"#type": "Patient",
"account": "/api/accounts/8110",
"accountId": 8110,
"isDependent": false,
"isGuardian": false,
"organization": "/api/organizations/765",
"firstName": "CA",
"middleInitial": "A",
"lastName": "Patient",
"sex": "male",
"birthDate": "2000-01-01T00:00:00+00:00",
"addressLineOne": "5759 Witting Corners",
"city": "Marvintown",
"zipCode": "35507",
"state": {
"#id": "/api/states/681",
"#type": "State",
"abbreviation": "CA"
},
"phoneNumber": "617-491-0000",
}
Relates to this question
You only need to set skip_null_values to false in your normalization_context, because starting 3.0.0 beta 1 they decided it would become true by default.
If you need it to be false for all resources, you can set the default in your config/packages/api_platform.yaml:
api_platform:
...
defaults:
normalization_context:
skip_null_values: false

Actionable Message (Message Card) Input Value Substitution not working in Microsoft Teams

I have a problem where I am unable to retrieve values from the message card text input in Microsoft Teams, but the same JSON template actually works on Message Card Playground.
A brief overview of my Microsoft Card implementation. I have to use MessageCard as I am using connectors (incoming webhook) to send a card to Microsoft Teams. Thus, the input value substitution syntax is referred from Message Card Reference - {{<id of input>.value}}. I am not getting any value using this syntax in my Message Card when I am in TEAMS. E.g. User filled in a textbox, and the value is not being captured or cannot be retrieved with this syntax.
The card that I used is as followed:
{
"#type": "MessageCard",
"#context": "http://schema.org/extensions",
"themeColor": "0076D7",
"summary": "{{ctx.monitor.name}}",
"sections": [
{
"activityTitle": "![TestImage](https://47a92947.ngrok.io/Content/Images/default.png){{ctx.monitor.name}}",
"activitySubtitle": "Alert",
"activityImage": "https://teamsnodesample.azurewebsites.net/static/img/image5.png",
"facts": [
{
"name": "Assigned to",
"value": "Sam"
}
],
"markdown": true
}
],
"potentialAction": [
{
"#type": "ActionCard",
"name": "Add a comment",
"inputs": [
{
"#type": "TextInput",
"id": "comment",
"title": "Enter your comment",
"isMultiline": true
}
],
"actions": [
{
"#type": "HttpPOST",
"name": "OK",
"target": "https://webhook.site/ab592c11-4590-438d-90c2-57bc4bb4aa8a?serviceToken=d2l0cy1zYW06MXFhekBXU1g%3D",
"body": "{{comment.value}}"
}
]
}
]
}
Note: You can see there is "summary": "{{ctx.monitor.name}}", it is a property from Kibana (a data visualization tool). This value works, but it is not our focus right here. My problem is I cannot get any value from {{comment.value}}, it is an empty string.
My questions are:
Is this the limitation coming from MSFT Teams itself?
#csamleong could you please replace the "body": "comment ={{comment.value}}" so you will receive the comment value:
card json:
{
"summary": "Card \"Test card\"",
"themeColor": "0078D7",
"#type": "MessageCard",
"#context": "http://schema.org/extensions",
"themeColor": "0076D7",
"summary": "{{ctx.monitor.name}}",
"sections": [
{
"activityTitle": "![TestImage](https://47a92947.ngrok.io/Content/Images/default.png){{ctx.monitor.name}}",
"activitySubtitle": "Alert",
"activityImage": "https://teamsnodesample.azurewebsites.net/static/img/image5.png",
"facts": [
{
"name": "Assigned to",
"value": "Sam"
}
],
"markdown": true
}
],
"potentialAction": [
{
"#type": "ActionCard",
"name": "Add a comment",
"inputs": [
{
"#type": "TextInput",
"id": "comment",
"title": "Enter your comment",
"isMultiline": true
}
],
"actions": [
{
"#type": "HttpPOST",
"name": "OK",
"target": "https://daf47bb241c6.ngrok.io//weatherforecast/Configure/Comment",
"body": "comment={{comment.value}}"
}
]
}
]
}
Post Method:
[HttpPost]
[Route("Configure/Comment")]
public async Task<ActionResult> Comment()
{
string bodyStr;
using (var reader = new StreamReader(this.Request.Body, Encoding.UTF8, true, 1024, true))
{
bodyStr = await reader.ReadToEndAsync();
}
string comment = string.IsNullOrWhiteSpace(bodyStr) ? string.Empty : bodyStr.Split('=')[1];
Response.Headers.Add("CARD-UPDATE-IN-BODY", "true");
return null;
}
You will receive value in the comment varable.

Add event from gmail to google calendar

I want to automatically create an calendar event from gmail.
I order to test the same I am using the URL (https://script.google.com) to test the same but the code is not working.
The code is as follows:
File name - Code.js
function testSchemas() {
var htmlBody = HtmlService.createHtmlOutputFromFile('mail_template').getContent();
MailApp.sendEmail({
to: Session.getActiveUser().getEmail(),
subject: 'Test Email - ' + new Date(),
htmlBody: htmlBody,
});
}
File name - mail_template.html
<html>
<body>
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "EventReservation",
"reservationNumber": "IO12345",
"underName": {
"#type": "Person",
"name": "Rahul Kumar"
},
"reservationFor": {
"#type": "Event",
"name": "Google I/O 2013",
"startDate": "2017-01-05T08:30:00-08:00",
"location": {
"#type": "Place",
"name": "Moscone Center",
"address": {
"#type": "PostalAddress",
"streetAddress": "800 Howard St.",
"addressLocality": "San Francisco",
"addressRegion": "CA",
"postalCode": "94103",
"addressCountry": "US"
}
}
}
}
</script>
<p>
Dear Rahul, thanks for booking your Google I/O ticket with us.
</p>
<p>
BOOKING DETAILS<br/>
Reservation number: IO12345<br/>
Order for: Rahul Kumar<br/>
Event: Google I/O 2013<br/>
Start time: Jan 5th 2017 8:00am PST<br/>
Venue: Moscone Center, 800 Howard St., San Francisco, CA 94103<br/>
</p>
</body>
</html>

How to I read a line, modify it slightly and write it back using awk/sed?

I have a json file of the following format:
[
{
"organization": "ABC",
"type": "School",
"contact": "Joe Schmo",
"contact_title": "Principal",
"mailing_address": "123 Main Street, Anytown, MA",
"phone": "214-555-5430",
"fax": "214-555-5444"
},
{
"organization": "XYZ",
"type": "School",
"contact": "John Doe",
"contact_title": "Asst Principal",
"mailing_address": "123 Main Street, Anycity, TX",
"phone": "512-555-5430",
"fax": "512-555-5444"
},
.
.
.
.
]
I want to duplicate the line starting with "organization" and then add it back to the file twice after replacing "organization" with "company" and "long name". I want to keep the original line too.
The output I want is:
[
{
"organization": "ABC",
"company": "ABC",
"long name": "ABC",
"type": "School",
"contact": "Joe Schmo",
"contact_title": "Principal",
"mailing_address": "123 Main Street, Anytown, MA",
"phone": "214-555-5430",
"fax": "214-555-5444"
},
{
"organization": "XYZ",
"company": "XYZ",
"name": "XYZ",
"type": "School",
"contact": "John Doe",
"contact_title": "Asst Principal",
"mailing_address": "123 Main Street, Anycity, TX",
"phone": "512-555-5430",
"fax": "512-555-5444"
},
.
.
.
.
]
awk or sed solutions preferred.
Here is one way:
sed '/organization/p;s/organization/company/p;s/company/long name/' file
Here is another:
awk '$1~/organization/{print $0;sub(/organization/,"company");print $0;sub(/company/,"long name")}1' file

Resources