How to sort JSONArray with condition in Java [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 days ago.
Improve this question
I have a JSONArray like this
[
{
"title": "ljkjkadjkfj",
"nodeType": "LABEL",
"ID": "id1222012-1",
"children": [
{
"title": "content",
"nodeType": "LABEL",
"ID": "id1222012-3",
"children": [],
"element": "1-0"
},
{
"title": "1-3",
"nodeType": "LABEL",
"ID": "id1222012-7",
"children": [
{
"title": "1-3-1",
"nodeType": "LABEL",
"ID": "id1222012-8",
"children": [
{
"nodeType": "LABEL",
"ID": "id1222012-9",
"children": [
{
"nodeType": "Type1",
"title": "Node Extension 2",
"ID": "id1222012-12",
"children": [
{
}
],
"element": "node-extension"
},
{
"nodeType": "Type2",
"title": "Node Extension 2",
"ID": "id1222012-11",
"children": [
{
}
],
"element": "node-extension"
}
],
"element": "1-3-1-1"
}
],
"element": "1-3-1"
}
],
"element": "1-3"
}
],
"element": "1"
}
],
"element": "m1"
}
]
I would like to sort this JSONArray by ID, if the element is "node-extension". In this JSONArray, the result should be the same, except we swap the position of "id1222012-11" and "id1222012-11".
I searched and only find the way to sort by one condition, like ID.
How could we do this. Please help me.

Related

How to retrieve user entered input in adaptive card in java

Attached the JSON of adaptive card I sent in teams.
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "Publish Adaptive Card schema",
"weight": "bolder",
"size": "medium"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "Image",
"url": "https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg",
"size": "medium",
"style": "person"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Matt Hidinger",
"weight": "bolder",
"wrap": true
},
{
"type": "TextBlock",
"spacing": "none",
"text": "Created Tuesday, Feb 14, 2017",
"isSubtle": true,
"wrap": true
}
]
}
]
}
]
},
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "Now that we have defined the main rules and features of the format, we need to produce a schema and publish it to GitHub. The schema will be the starting point of our reference documentation.",
"wrap": true
},
{
"type": "FactSet",
"facts": [
{
"title": "Board:",
"value": "Adaptive Card"
},
{
"title": "List:",
"value": "Backlog"
},
{
"title": "Assigned to:",
"value": "Matt Hidinger"
},
{
"title": "Due date:",
"value": "Not set"
}
]
}
]
}
],
"actions": [
{
"type": "Action.ShowCard",
"title": "Set due date",
"card": {
"version": "1.0",
"type": "AdaptiveCard",
"body": [
{
"type": "Input.Date",
"id": "dueDate",
"title": "Select due date"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "OK"
}
]
}
},
{
"type": "Action.ShowCard",
"title": "Comment",
"card": {
"version": "1.0",
"type": "AdaptiveCard",
"body": [
{
"type": "Input.Text",
"id": "comment",
"isMultiline": true,
"placeholder": "Enter your comment"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "OK"
}
]
}
},
{
"type": "Action.OpenUrl",
"title": "View",
"url": "http://adaptivecards.io"
}
]
}
After User entered values and click ok, reply from bot is "Echo:"
How can i display the entered value as reply from bot.
I have implemented this to get activity, but this method is not called when use click ok.

Do I need to make a recyclerview inside a recyclerview for this?

This question is in link with my previously asked question here:
How to group api response in android
I didn't get any efficient way of doing this, so I have changed my api to this:
{
"Cricket": {
"2017": {
"id": "1",
"Name": "Karan",
"age": "25"
},
"2015": {
"id": "2",
"Name": "Suman",
"age": "24"
}
},
"Badminton": {
"2016": {
"id": "1",
"Name": "Kiran",
"age": "25"
},
"2015": {
"id": "2",
"Name": "Shikhar",
"age": "26"
}
}
}
Will this help, if yes, can someone guide me how?

How to form post request body where resource contained multi reference resources from Java to FHIR api

I have to send request body as org.hl7.fhir.r4.model.CoverageEligibilityRequest which is contained Patient, Practitioner, Organization as below. This API will return Bundle response. I am using Java and Generic client from Hapi Fire library. There is provision to pass search parameter but the here I am having multilevel hierarchy of resource and input is big than usual. Can any one help me to handle this request in FHIR API.
Request Body as below,
{
"resourceType": "CoverageEligibilityRequest",
"contained": [
{
"resourceType": "Patient",
"id": "1",
"name": [
{
"family": "abcFamily",
"given": [
"abcGiven"
]
}
],
"birthDate": "1962-08-06"
},
{
"resourceType": "Practitioner",
"id": "2",
"identifier": [
{
"type": {
"coding": [
{
"code": "NPI"
}
]
},
"value": "123456789"
}
],
"name": [
{
"family": "pqrFamily",
"given": [
"pqrGiven"
]
}
]
},
{
"resourceType": "Organization",
"id": "3",
"identifier": [
{
"value": "12345"
}
],
"name": ""
},
{
"resourceType": "Coverage",
"id": "3",
"status": "active",
"subscriberId": "",
"class": [
{
"type": {
"coding": [
{
"code": "group"
}
]
},
"value": ""
}
]
}
],
"extension": [
{
"url": "searchOption",
"valueString": "NameDateOfBirth"
}
],
"status": "active",
"purpose": [
"benefits"
],
"patient": {
"reference": "#1"
},
"provider": {
"reference": "#2"
},
"insurer": {
"reference": "#3"
}
}

How to retrieve an element value from json using java?

Here is the json string from which i have to retrieve the element value
{ "search": { "entry": [
{ "d": "op=example.com",
"at": [
{ "name": "id", "value": [ "786786876" ] },
{ "name": "name", "value": [ "usaduas" ] }]
},
{ "d": "op=example.com",
"at": [
{ "name": "id", "value": [ "786876876" ] },
{ "name": "call", "value": [ "gyudyusg" ] }]
},
{ "d": "op=example.com",
"at": [
{ "name": "call", "value": [ "hsadkjhsakjdh" ] },
{ "name": "id", "value": [ "768768768" ] }]
}
I want to retrieve the text from attribute or node "name" : "call". I want to retrieve this value using jsonPath.
Thanks in advance.
please try one of these as per your understanding. These two are most convenient and highly used API to Serialize or Deserialize the JSONObject google gson API tutorial-convert-java-object-to-from-json
OR
Google Json simple API example-read-and-write-json

Precondition on data pipeline

I did some set of activities on json script. Need to add precondition on it.
how to use precondition on json script.
In precondition, i need to check the mysql db field. once flag as 'Y',
start execution else should be stop the execution.
You can use a ShellCommandPrecondition for this which will let you write a custom precondition.
{
"objects": [
{
"schedule": {
"ref": "DefaultSchedule"
},
"resourceRole": "DataPipelineDefaultResourceRole",
"role": "DataPipelineDefaultRole",
"name": "DefaultResource1",
"id": "ResourceId_dWoZ0",
"type": "Ec2Resource",
"terminateAfter": "1 Hour"
},
{
"name": "DefaultPrecondition1",
"id": "PreconditionId_yA2rV",
"type": "ShellCommandPrecondition",
"command": "<Script to check mysql field>"
},
{
"occurrences": "1",
"period": "1 Day",
"name": "RunOnce",
"id": "DefaultSchedule",
"type": "Schedule",
"startAt": "FIRST_ACTIVATION_DATE_TIME"
},
{
"failureAndRerunMode": "CASCADE",
"schedule": {
"ref": "DefaultSchedule"
},
"resourceRole": "DataPipelineDefaultResourceRole",
"role": "DataPipelineDefaultRole",
"pipelineLogUri": "s3://<mybucket>",
"scheduleType": "cron",
"name": "Default",
"id": "Default"
},
{
"schedule": {
"ref": "DefaultSchedule"
},
"name": "DefaultActivity1",
"runsOn": {
"ref": "ResourceId_dWoZ0"
},
"precondition": {
"ref": "PreconditionId_yA2rV"
},
"id": "ActivityId_gmQ0W",
"type": "ShellCommandActivity",
"command": "echo 'Hello world'"
}
],
"parameters": []
}

Categories