I'll try to provide as much information as I think might be relevant. I'm using NodeJS, MongoDB, .rest, and Render, though in this case I'm just trying to get things working locally first. Here are some of the files.
//swagger.js
const swaggerAutogen = require('swagger-autogen')();
const doc = {
info: {
title: 'My API',
description: 'Welcome to my fumbling mess',
},
host: 'localhost:3000',
schemes: ['http'],
};
const outputFile = './swagger-output.json';
const endpointsFiles = ['routes/index.js'];
swaggerAutogen(outputFile, endpointsFiles, doc);
//routes/index.js
const routes = require('express').Router();
routes.use('/characters', require('./characters'));
routes.use('/', require('./swagger-route'));
module.exports = routes;
//routes/swagger-route.js
const router = require('express').Router();
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('../swagger-output.json');
router.use('/api-docs', swaggerUi.serve);
router.use('/api-docs', swaggerUi.setup(swaggerDocument));
module.exports = router;
//swagger.output.json
{
"swagger": "2.0",
"info": {
"title": "My API",
"description": "Welcome to my fumbling mess",
"version": "1.0.0"
},
"host": "localhost:3000",
"basePath": "/",
"schemes": [
"http"
],
"paths": {
"/characters/": {
"get": {
"description": "",
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "OK"
},
"500": {
"description": "Internal Server Error"
}
}
},
"post": {
"description": "",
"parameters": [
{
"name": "body",
"in": "body",
"schema": {
"type": "object",
"properties": {
"characterName": {
"example": "any"
},
"playerName": {
"example": "any"
},
"race": {
"example": "any"
},
"class": {
"example": "any"
},
"level": {
"example": "any"
},
"alignment": {
"example": "any"
},
"stats": {
"example": "any"
}
}
}
}
],
"responses": {
"201": {
"description": "Created"
},
"400": {
"description": "Bad Request"
}
}
}
},
"/characters/{id}": {
"get": {
"description": "",
"produces": [
"application/json"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK"
},
"500": {
"description": "Internal Server Error"
}
}
},
"put": {
"description": "",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"schema": {
"type": "object",
"properties": {
"characterName": {
"example": "any"
},
"playerName": {
"example": "any"
},
"race": {
"example": "any"
},
"class": {
"example": "any"
},
"level": {
"example": "any"
},
"alignment": {
"example": "any"
},
"stats": {
"example": "any"
}
}
}
}
],
"responses": {
"204": {
"description": "No Content"
},
"404": {
"description": "Not Found"
},
"500": {
"description": "Internal Server Error"
}
}
},
"delete": {
"description": "",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK"
},
"404": {
"description": "Not Found"
},
"500": {
"description": "Internal Server Error"
}
}
}
}
}
}
And finally, running http://localhost:3000/api-docs/ doesn't result in the actual frontend of the Swagger UI like it should. Instead I get this is raw html in the attached image.
Any ideas of what I could be doing wrong?
I tried in swagger-route.js to change the 5th line from router.get() to router.use()
I tried forgetting about localhost and changing the host paths to my Render web service but that just caused the same thing to happen on Render.
I have a collection called dish-category which contains many dishes, and a dish collection that contains many dish-options (another collection).
the list of dishes from each dish-category is available in the API but the nested collection of dish options from each dish is not available on strapi.
the following are the settings for my models:
dish-category.settings.json:
{
"kind": "collectionType",
"collectionName": "dish_categories",
"info": {
"name": "DishCategory",
"description": ""
},
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"Name": {
"type": "string"
},
"Description": {
"type": "text"
},
"dishes": {
"collection": "dish",
"via": "dish_category"
}
}
}
dish.settings.json:
{
"kind": "collectionType",
"collectionName": "dishes",
"info": {
"name": "Dish",
"description": ""
},
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"Name": {
"type": "string"
},
"Description": {
"type": "text"
},
"Total": {
"type": "decimal",
"min": 0,
"required": false,
"default": 0
},
"dish_categories": {
"collection": "dish-category"
},
"dish_options": {
"collection": "dish-option",
"via": "dish"
},
"dish_category": {
"via": "dishes",
"model": "dish-category"
}
}
}
dish-option.settings.json:
{
"kind": "collectionType",
"collectionName": "dish_options",
"info": {
"name": "DishOption",
"description": ""
},
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"Name": {
"type": "string"
},
"Price": {
"type": "decimal",
"min": 0,
"default": 0
},
"dish": {
"via": "dish_options",
"model": "dish"
}
}
}
on the dish-category/controllers/dish-category.js file I tried populating the attribute:
'use strict';
/**
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-controllers)
* to customize this controller
*/
module.exports = {
async find(params, populate){
return strapi.query('dish-category').find(params, ["dishes","dish.dish_options"]);
}
};
I am having trouble displaying nested relations with multiple values, I have tried looking up solutions online, I came across this thread https://forum.strapi.io/t/simple-nested-array-issue/1045/4 but the solution doesn't work for me and it seems like the link to the example is no longer available.
I'm new to Actions on Google and Node.js, but this seems like it should be straightforward and I'm not sure why it's not working. I just want to send a GET request within the code that handles a specific intent. At the moment, I'm not even looking for a return value; I just want to fire off the request. I'm using the Blaze tier of Firebase, which is supposed to allow outgoing HTTPS requests. Indeed, I can get the Action to play an audio file from my server in SSML. But when I put in a GET request to a PHP page that increments a value in a database, it isn't being executed successfully.
My code is taken directly from Google's CodeLabs tutorials for Actions. Below is the only function I'm modifying. This code runs, but the GET request is never received.
// Handle the Dialogflow intent named 'favorite color'.
// The intent collects a parameter named 'color'.
app.intent('favorite color', (conv, {color}) => {
const luckyNumber = color.length;
const audioSound = 'https://my.server.tld/path/to/sound.mp3';
// These two lines don't seem to do what I'm expecting them to.
var https = require("https");
https.get('https://my.server.tld/path/to/file.php?value=1');
conv.ask(`<speak>Your lucky number is ${luckyNumber}.` +
`<audio src="${audioSound}"></audio>` +
`Would you like to hear some fake colors?</speak>`);
});
There's nothing that jumps out at me as unusual in the Firebase logs (excerpted below). There doesn't seem to be any mention of the GET call I'm trying to make.
4:19:11.631 PM dialogflowFirebaseFulfillment Function execution took 569 ms, finished with status code: 200
4:19:11.543 PM dialogflowFirebaseFulfillment Response { "status": 200, "headers": { "content-type": "application/json; charset=utf-8" }, "body": { "payload": { "google": { "expectUserResponse": true, "richResponse": { "items": [ { "simpleResponse": { "textToSpeech": "<speak>Three. Your lucky number is 4.<audio src=\"https://actions.google.com/sounds/v1/cartoon/clang_and_wobble.ogg\"></audio>Would you like to hear some fake colors?</speak>" } } ] }, "userStorage": "{\"data\":{}}" } }, "outputContexts": [ { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/_actions_on_google", "lifespanCount": 99, "parameters": { "data": "{}" } } ] } }
4:19:11.434 PM dialogflowFirebaseFulfillment Conversation { "responses": [], "expectUserResponse": true, "digested": false, "noInputs": [], "_responded": false, "request": "[Excluded]", "headers": "[Excluded]", "sandbox": true, "input": { "raw": "blue", "type": "KEYBOARD" }, "surface": { "capabilities": { "list": [ { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.MEDIA_RESPONSE_AUDIO" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] } }, "available": { "surfaces": { "list": [ { "capabilities": { "list": [ { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] } } ], "capabilities": { "surfaces": [ { "capabilities": { "list": [ { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] } } ] } } }, "user": { "raw": { "userStorage": "{\"data\":{}}", "lastSeen": "2018-09-26T23:19:06Z", "locale": "en-US", "userId": "ABwppHHp5yhn_VrB_SIGG93tCzMx9o0A_W9bIDlbCClkqcV85LrVbJ42vLQ7hWXfe3UOd7pASDIm6v_q" }, "storage": {}, "_id": "ABwppHHp5yhn_VrB_SIGG93tCzMx9o0A_W9bIDlbCClkqcV85LrVbJ42vLQ7hWXfe3UOd7pASDIm6v_q", "locale": "en-US", "permissions": [], "last": { "seen": "2018-09-26T23:19:06.000Z" }, "name": {}, "entitlements": [], "access": {}, "profile": {} }, "arguments": { "parsed": { "input": { "text": "blue" }, "list": [ "blue" ] }, "status": { "input": {}, "list": [ null ] }, "raw": { "list": [ { "rawText": "blue", "textValue": "blue", "name": "text" } ], "input": { "text": { "rawText": "blue", "textValue": "blue", "name": "text" } } } }, "device": {}, "id": "ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh", "type": "ACTIVE", "screen": true, "body": "[Excluded]", "version": 2, "action": "", "intent": "favorite color", "parameters": { "color": "blue" }, "contexts": { "_session": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh", "input": { "actions_capability_screen_output": { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_screen_output", "parameters": { "color": "blue", "color.original": "blue" } }, "actions_capability_audio_output": { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_audio_output", "parameters": { "color": "blue", "color.original": "blue" } }, "google_assistant_input_type_keyboard": { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/google_assistant_input_type_keyboard", "parameters": { "color": "blue", "color.original": "blue" } }, "actions_capability_web_browser": { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_web_browser", "parameters": { "color": "blue", "color.original": "blue" } }, "actions_capability_media_response_audio": { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_media_response_audio", "parameters": { "color": "blue", "color.original": "blue" } } }, "output": {} }, "incoming": { "parsed": [ "" ] }, "query": "blue", "data": {} }
4:19:11.346 PM dialogflowFirebaseFulfillment Headers { "host": "us-central1-actions-rwag.cloudfunctions.net", "user-agent": "Apache-HttpClient/4.5.4 (Java/1.8.0_181)", "transfer-encoding": "chunked", "accept": "text/plain, */*", "accept-charset": "big5, big5-hkscs, cesu-8, euc-jp, euc-kr, gb18030, gb2312, gbk, ibm-thai, ibm00858, ibm01140, ibm01141, ibm01142, ibm01143, ibm01144, ibm01145, ibm01146, ibm01147, ibm01148, ibm01149, ibm037, ibm1026, ibm1047, ibm273, ibm277, ibm278, ibm280, ibm284, ibm285, ibm290, ibm297, ibm420, ibm424, ibm437, ibm500, ibm775, ibm850, ibm852, ibm855, ibm857, ibm860, ibm861, ibm862, ibm863, ibm864, ibm865, ibm866, ibm868, ibm869, ibm870, ibm871, ibm918, iso-2022-cn, iso-2022-jp, iso-2022-jp-2, iso-2022-kr, iso-8859-1, iso-8859-13, iso-8859-15, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-9, jis_x0201, jis_x0212-1990, koi8-r, koi8-u, shift_jis, tis-620, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-32be, utf-32le, utf-8, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, windows-31j, x-big5-hkscs-2001, x-big5-solaris, x-compound_text, x-euc-jp-linux, x-euc-tw, x-eucjp-open, x-ibm1006, x-ibm1025, x-ibm1046, x-ibm1097, x-ibm1098, x-ibm1112, x-ibm1122, x-ibm1123, x-ibm1124, x-ibm1166, x-ibm1364, x-ibm1381, x-ibm1383, x-ibm300, x-ibm33722, x-ibm737, x-ibm833, x-ibm834, x-ibm856, x-ibm874, x-ibm875, x-ibm921, x-ibm922, x-ibm930, x-ibm933, x-ibm935, x-ibm937, x-ibm939, x-ibm942, x-ibm942c, x-ibm943, x-ibm943c, x-ibm948, x-ibm949, x-ibm949c, x-ibm950, x-ibm964, x-ibm970, x-iscii91, x-iso-2022-cn-cns, x-iso-2022-cn-gb, x-iso-8859-11, x-jis0208, x-jisautodetect, x-johab, x-macarabic, x-maccentraleurope, x-maccroatian, x-maccyrillic, x-macdingbat, x-macgreek, x-machebrew, x-maciceland, x-macroman, x-macromania, x-macsymbol, x-macthai, x-macturkish, x-macukraine, x-ms932_0213, x-ms950-hkscs, x-ms950-hkscs-xp, x-mswin-936, x-pck, x-sjis_0213, x-utf-16le-bom, x-utf-32be-bom, x-utf-32le-bom, x-windows-50220, x-windows-50221, x-windows-874, x-windows-949, x-windows-950, x-windows-iso2022jp", "content-type": "application/json; charset=UTF-8", "function-execution-id": "gjnwrdpyi1ax", "x-appengine-api-ticket": "e212b331d87bdb3c", "x-appengine-city": "?", "x-appengine-citylatlong": "0.000000,0.000000", "x-appengine-country": "US", "x-appengine-default-version-hostname": "l9ec7ba250478215b-tp.appspot.com", "x-appengine-https": "on", "x-appengine-region": "?", "x-appengine-request-log-id": "5bac13ef00ff00ffe3280c8cb3550001737e6c396563376261323530343738323135622d7470000139303866373866633530636138623435363966303164656633393333393136383a3233000100", "x-appengine-user-ip": "35.239.85.110", "x-cloud-trace-context": "0109e1b3b7dc8fbbefd2664dbcbd5d0a/2770932151653705781;o=1", "x-forwarded-for": "35.239.85.110, 35.239.85.110", "x-forwarded-proto": "https", "accept-encoding": "gzip" }
4:19:11.339 PM dialogflowFirebaseFulfillment Request { "responseId": "c7b55f8a-502d-431a-8056-258dec82268f", "queryResult": { "queryText": "blue", "parameters": { "color": "blue" }, "allRequiredParamsPresent": true, "fulfillmentMessages": [ { "text": { "text": [ "" ] } } ], "outputContexts": [ { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_screen_output", "parameters": { "color": "blue", "color.original": "blue" } }, { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_audio_output", "parameters": { "color": "blue", "color.original": "blue" } }, { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/google_assistant_input_type_keyboard", "parameters": { "color": "blue", "color.original": "blue" } }, { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_web_browser", "parameters": { "color": "blue", "color.original": "blue" } }, { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_media_response_audio", "parameters": { "color": "blue", "color.original": "blue" } } ], "intent": { "name": "projects/actions-rwag/agent/intents/8524ede6-72a2-467b-9b34-67a8f1d3a121", "displayName": "favorite color" }, "intentDetectionConfidence": 1, "languageCode": "en-us" }, "originalDetectIntentRequest": { "source": "google", "version": "2", "payload": { "isInSandbox": true, "surface": { "capabilities": [ { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.MEDIA_RESPONSE_AUDIO" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] }, "requestType": "SIMULATOR", "inputs": [ { "rawInputs": [ { "query": "blue", "inputType": "KEYBOARD" } ], "arguments": [ { "rawText": "blue", "textValue": "blue", "name": "text" } ], "intent": "actions.intent.TEXT" } ], "user": { "userStorage": "{\"data\":{}}", "lastSeen": "2018-09-26T23:19:06Z", "locale": "en-US", "userId": "ABwppHHp5yhn_VrB_SIGG93tCzMx9o0A_W9bIDlbCClkqcV85LrVbJ42vLQ7hWXfe3UOd7pASDIm6v_q" }, "conversation": { "conversationId": "ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh", "type": "ACTIVE", "conversationToken": "[]" }, "availableSurfaces": [ { "capabilities": [ { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] } ] } }, "session": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh" }
4:19:11.063 PM dialogflowFirebaseFulfillment Function execution started
I think I've discovered why I was running into this problem, and why I couldn't explain it based on research into Actions on Google or Node.js. It looks like the page on my server that I was requesting returns a 301 "Permanently Moved" response. When I request the page through a web browser, it ignores(?) this response and serves the page anyway, but when I make the request in my AoG intent fulfillment, it silently recognizes the 301 and doesn't ever hit the PHP on the server. Anyway, it appears this is a problem with my server configuration and not my AoG code.
Hot tip to new AoG programmers: console.log() commands in the fulfillment will appear in the Firebase Cloud Functions log, which is what eventually allowed me to see the 301 code being returned. Thanks to anyone how tried to puzzle this out with me!
I would like to fetch only specific objects from the below JSON such as only those JSON objects which have a classDefinition = "com.sap.bpm.wfs.UserTask". Please suggest on how to do this:
var metadata = {
"contents": {
"83eaead8-cfae-459b-9bdd-8b12e32d6715": {
"classDefinition": "com.sap.bpm.wfs.StartEvent",
"id": "startevent1",
"name": "StartEvent1"
},
"13583ac9-596d-4375-b9e1-e5f6f21e829f": {
"classDefinition": "com.sap.bpm.wfs.EndEvent",
"id": "endevent1",
"name": "EndEvent1"
},
"6c2b0935-444b-4299-ac8e-92973ce93558": {
"classDefinition": "com.sap.bpm.wfs.UserTask",
"subject": "Upload document",
"description": "{context.description}",
"priority": "MEDIUM",
"isHiddenInLogForParticipant": false,
"userInterface": "sapui5://html5apps/saptest/com.sap.test",
"recipientUsers": "I311520, I310811",
"id": "usertask1",
"name": "UserTask1"
},
"6728bf81-3d4e-4ae3-a428-1700a2096d34": {
"classDefinition": "com.sap.bpm.wfs.SequenceFlow",
"id": "sequenceflow1",
"name": "SequenceFlow1",
"sourceRef": "83eaead8-cfae-459b-9bdd-8b12e32d6715",
"targetRef": "6c2b0935-444b-4299-ac8e-92973ce93558"
},
"aa99931e-2523-44c3-86b3-d522acdbde10": {
"classDefinition": "com.sap.bpm.wfs.ui.Diagram",
"symbols": {
"760f0725-3400-4d48-b082-5c69ad79d697": {},
"aa9a0d10-63be-4af8-9ac2-4d2b648a18fc": {},
"7fbd11bb-cf82-4a27-97d7-e80dda2014ee": {},
"20c66c48-6058-465e-b500-d69d6e54c028": {},
"2e8f324c-5361-4512-a09a-fc7693f206ba": {}
}
}
}
};
First, metadata.contents property should rather be an array.
If you really cannot change it to an array, then use Object.keys(metadata.contents)
For example:
Object.keys(metadata.contents)
.map(x => metadata.contents[x])
.filter(x => x.classDefinition == 'com.sap.bpm.wfs.UserTask')
var metadata = {
"contents": {
"83eaead8-cfae-459b-9bdd-8b12e32d6715": {
"classDefinition": "com.sap.bpm.wfs.StartEvent",
},
"13583ac9-596d-4375-b9e1-e5f6f21e829f": {
"classDefinition": "com.sap.bpm.wfs.EndEvent",
},
"6c2b0935-444b-4299-ac8e-92973ce93558": {
"classDefinition": "com.sap.bpm.wfs.UserTask",
"subject": "Upload document",
"description": "{context.description}",
"priority": "MEDIUM",
"isHiddenInLogForParticipant": false,
"userInterface": "sapui5://html5apps/saptest/com.sap.test",
"recipientUsers": "I311520, I310811",
"id": "usertask1",
"name": "UserTask1"
},
"6728bf81-3d4e-4ae3-a428-1700a2096d34": {
"classDefinition": "com.sap.bpm.wfs.SequenceFlow",
},
"aa99931e-2523-44c3-86b3-d522acdbde10": {
"classDefinition": "com.sap.bpm.wfs.ui.Diagram",
}
}
}
var filtered = Object.keys(metadata.contents)
.map(x => metadata.contents[x])
.filter(x => x.classDefinition == 'com.sap.bpm.wfs.UserTask')
console.log(filtered)
A simple for loop can be used to get the desired fields:
var temp = [];
for (var index in metadata.contents) {
if (metadata.contents[index].classDefinition == "com.sap.bpm.wfs.UserTask") {
temp.push(metadata.contents[index]);
}
}
Or you can do one by one
var metadata = {
"contents": {
"83eaead8-cfae-459b-9bdd-8b12e32d6715": {
"classDefinition": "com.sap.bpm.wfs.StartEvent",
"id": "startevent1",
"name": "StartEvent1"
},
"13583ac9-596d-4375-b9e1-e5f6f21e829f": {
"classDefinition": "com.sap.bpm.wfs.EndEvent",
"id": "endevent1",
"name": "EndEvent1"
},
"6c2b0935-444b-4299-ac8e-92973ce93558": {
"classDefinition": "com.sap.bpm.wfs.UserTask",
"subject": "Upload document",
"description": "{context.description}",
"priority": "MEDIUM",
"isHiddenInLogForParticipant": false,
"userInterface": "sapui5://html5apps/saptest/com.sap.test",
"recipientUsers": "I311520, I310811",
"id": "usertask1",
"name": "UserTask1"
},
"6728bf81-3d4e-4ae3-a428-1700a2096d34": {
"classDefinition": "com.sap.bpm.wfs.SequenceFlow",
"id": "sequenceflow1",
"name": "SequenceFlow1",
"sourceRef": "83eaead8-cfae-459b-9bdd-8b12e32d6715",
"targetRef": "6c2b0935-444b-4299-ac8e-92973ce93558"
},
"aa99931e-2523-44c3-86b3-d522acdbde10": {
"classDefinition": "com.sap.bpm.wfs.ui.Diagram",
"symbols": {
"760f0725-3400-4d48-b082-5c69ad79d697": {},
"aa9a0d10-63be-4af8-9ac2-4d2b648a18fc": {},
"7fbd11bb-cf82-4a27-97d7-e80dda2014ee": {},
"20c66c48-6058-465e-b500-d69d6e54c028": {},
"2e8f324c-5361-4512-a09a-fc7693f206ba": {}
}
}
}
}
var content = metadata["contents"];
var subContent = content["6c2b0935-444b-4299-ac8e-92973ce93558"];
var classDef = subContent["classDefinition"];
alert(classDef);