How do I get the full URI (i.e. not "streamwrapped") for a Drupal node field in a single request to the Services module? - rest

Preface
I'm building a Drupal site that doubles as a content-serving endpoint for a mobile app written in Flex. The CMS is responsible for storing a number of items that have, among other fields, a field for an image that represents the node (like a movie cover or small product shot). I'm using the Services module and the REST service to serve this content to the mobile app as JSON.
Problem
I've noticed that Drupal (or perhaps Services itself) restricts the amount of data that comes back with each request, seemingly based on the granularity of the request. For example, a node index request returns only fields that are more or less the same for every node: nid, title, status, etc. While a request for a single node additionally returns custom fields, including my image field.
My issue is that the URI value for the image field is, "streamwrapped" (or so I've seen it referred to in researching this issue) so that it is simply listed as public://images/node_image.jpg. In order to get the full URI, I have to make a request for the file. This means that for the index page in the mobile app, I have to make 1 + (n * 2) requests just to get the full data about a given node, plus n requests to get the images for each node display. At most n will be 8 for a given page of nodes, so that means I could be making up to 25 requests to the server per page of nodes.
Is this common/accepted or is there an easier/faster/less heavy-handed way to get access to this data in fewer requests?
Side note: One thing I did notice is that the file request comes back with the image data base64-encoded. I could certainly use that to display an image, but I'd prefer to just request the binary image from the server.
Example
/end-point/node.json
[
{
nid: "6",
vid: "6",
type: "page",
language: "und",
title: "Node 6 Title",
...snip...
uri: "http://example.com/end-point/node/6"
},
{
nid: "5",
vid: "5",
type: "game",
language: "und",
title: "Node 5 Title",
...snip...
uri: "http://example.com/end-point/node/5"
},
...snip...
]
/end-point/node/5.json
{
vid: "5",
uid: "1",
title: "Node 5 Title",
...snip...
body: {
und: [{
value: "Lorem ipsum dolor sit amet.",
summary: "Lorem ipsum...",
format: "filtered_html",
safe_value: "<p>Lorem ipsum dolor sit amet.</p>",
safe_summary: "<p>Lorem ipsum...</p>"
}]
},
field_artwork: {
und: [{
fid: "8",
alt: "",
title: "",
width: "252",
height: "272",
uid: "1",
filename: "node_image.jpg",
uri: "public://images/node_image.jpg",
filemime: "image/jpeg",
filesize: "32653",
status: "1",
timestamp: "1329839925",
rdf_mapping: []
}]
},
...snip...
}
/end-point/file/8.json
{
fid: "8",
uid: "1",
filename: "node_image.jpg",
uri: "public://node_image.jpg",
filemime: "image/jpeg",
filesize: "32653",
status: "1",
timestamp: "1329839925",
rdf_mapping: [ ],
uri_full: "http://example.com/sites/default/files/images/node_image.jpg",
target_uri: "images/node_image.jpg",
file: "..snip base64-encoded image data...",
image_styles: [ ]
}

Since got no answer, I made it by myself.
The new module, Full URL file information, will fill the info you are looking for.
More details in my blog post - "Drupal file information, filling the URL information for Services".

Related

Docsearch on subpath '/docs' not scraping side navigation

A Docusaurus documentation website: https://slovakia-atmo-plan.marvintest.vito.be/docs/ is rendered in Docs only mode.
The Algolia Docsearch scraper is not scraping root level pages, instead it logs Ignored: from start url. This issue only seems to arise when the Docusaurus build is nested under {baseUrl}/docs.
Why is this being ignored? This is my docsearch config:
{
"index_name": "atmoplan-documentation",
"start_urls": ["https://slovakia-atmo-plan.marvintest.vito.be/docs"],
"sitemap_urls": ["https://slovakia-atmo-plan.marvintest.vito.be/docs/sitemap.xml"],
"sitemap_alternate_links": true,
"stop_urls": ["/tests"],
"selectors": {
"lvl0": {
"selector": "(//ul[contains(#class,'menu__list')]//a[contains(#class, 'menu__link menu__link--sublist menu__link--active')]/text() | //nav[contains(#class, 'navbar')]//a[contains(#class, 'navbar__link--active')]/text())[last()]",
"type": "xpath",
"global": true,
"default_value": "Documentation"
},
"lvl1": "header h1",
"lvl2": "article h2",
"lvl3": "article h3",
"lvl4": "article h4",
"lvl5": "article h5, article td:first-child",
"lvl6": "article h6",
"text": "article p, article li, article td:last-child"
},
"strip_chars": " .,;:#",
"custom_settings": {
"separatorsToIndex": "_",
"attributesForFaceting": ["language", "version", "type", "docusaurus_tag"],
"attributesToRetrieve": ["hierarchy", "content", "anchor", "url", "url_without_anchor", "type"]
},
"conversation_id": ["833762294"],
"nb_hits": 46250
}
Inside your docusaurus.config.js you should set the url parameter with the actual website where you will be hosting your docs. Something like:
module.exports = {
url: 'https://slovakia-atmo-plan.marvintest.vito.be/docs',
[…]
}
This will be used by your docusaurus to generate the sitemap.xml, used by algolia to locate your pages.
REFERENCE: https://docusaurus.io/docs/docusaurus.config.js/#url
DISCLAIMER
I noted something strange inside your sitemap.xml. For example the first link was https://www.vito.be/docs/markdown-page, but defined URL for Algolia is https://slovakia-atmo-plan.marvintest.vito.be/docs.

Keycloak RestAPI: Assign client role to group

I have trying this:
url="https://{localhost}/auth/admin/realms/{realm_name}/groups/{group_id}/role-mappings"
payload=[{"id":"role_id","name":"Role_name","composite":"false","clientRole":"true","containerId":"client_id"}]
But, it doesnt work, i think it may be related to the wrong payload
Any ideas pls
We can use the python-keycloak lib: https://pypi.org/project/python-keycloak/
there is a function: assign_group_client_roles
The format is correct but you make sure the client has available payloaded role.
This is example for, "Hr" group added "RomoteApp" client the "tile limit" role.
In Keycloak UI, # Client > RemoteApp > Roles
Role name
time limit
Groups > hr
Client Roles: RemoteApp
Available Roles: time limit
Assigned Roles: not yet include "time limit"
POST commend by Postman - I am not yet can attache image due to low level of stan overflow
http://127.0.0.1:8080/auth/admin/realms/Test-realm/groups/9efef6bf-7edb-496e-bc0d-a8d4f5f4e3a9/role-mappings/clients/60a19179-f244-42f8-9950-04f2119a4e5b?client=RemoteApp&id=60a19179-f244-42f8-9950-04f2119a4e5b&realm=Test-realm
in body of postman with row JSON option ( Content-Type : application/json )
[
{
"id": "e17f9f7f-62dc-4998-b058-49b845ff5cef",
"name": "time limit",
"description": "time limit",
"composite": false,
"clientRole": true,
"containerId": "60a19179-f244-42f8-9950-04f2119a4e5b"
}
]
group list
{
"id": "9efef6bf-7edb-496e-bc0d-a8d4f5f4e3a9",
"name": "hr",
"path": "/hr",
"subGroups": []
}
client list
{
"id": "60a19179-f244-42f8-9950-04f2119a4e5b",
"clientId": "RemoteApp",
...
}
also don't remember the access token called by token endpoint w/ grant_type is password
http://127.0.0.1:8080/auth/realms/Test-realm/protocol/openid-connect/token

"The agent returned an empty TTS" when action is not opened separately to asking an intent

When I invoke the skill with 'okay Google, ask {skillname} to {utterance}' I get the response 'The agent returned an empty tts" and the conversation closes. It doesn't even seem to hit my backend - I've tried hosting the backend code on both a local server and on AWS and the same issue happens in both cases. There's no log of the request being made either on Stackdriver on Google or on CloudWatch on AWS. The only response I get is the following in the debug tab:
{
"response": "The agent returned an empty TTS.",
"expectUserResponse": false,
"conversationToken": "EosDS2o4d0...",
"audioResponse": "",
"ssmlMarkList": [],
"debugInfo": {
"sharedDebugInfoList": [
{
"name": "Response Validation",
"debugInfo": "The agent returned an empty TTS.",
"subDebugEntryList": []
}
],
"conversationBuilderExecutionEventsList": []
},
"visualResponse": {
"visualElementsList": [
{
"displayText": {
"content": "The agent returned an empty TTS."
}
}
],
"suggestionsList": [],
"agentLogoUrl": ""
},
"clientError": 0,
"is3pResponse": true,
"clientOperationList": [],
"projectName": "",
"renderedHtml": ""
}
Nothing in any of the other tabs. When I try invoking the phrases in the same way on my phone, I just see a loading symbol and again nothing in the logs to say it's even hitting the backend.
Weirdly, this doesn't happen when I say 'okay Google, talk to {skillname} {utterance}' - this works absolutely fine.
All the intents work perfectly well when I've opened my action first, and then invoke them. I've built this using Jovo and published on Alexa also and the problem is only happening on Google.

Using my Rails app API for iPhone App

I'm learning iOS Development with the Treehouse Library. Building an app that gets information from a json API.
In the Treehouse API page all the posts are under a parent called "Posts" (http://blog.teamtreehouse.com/api/get_recent_summary/)
posts: [
{
id: 22198,
url: "http://blog.teamtreehouse.com/using-github-pages-to-host-your-website",
title: "Using GitHub Pages To Host Your Website",
date: "2013-08-16 09:30:20",
author: "Matt West",
thumbnail: "http://blog.teamtreehouse.com/wp-content/uploads/2013/08/github-pages-feature-150x150.jpg"
},
{
id: 22196,
url: "http://blog.teamtreehouse.com/running-tests-in-ruby-on-rails-treehouse-quick-tip",
title: "Running Tests in Ruby on Rails – Treehouse Quick Tip",
date: "2013-08-15 14:30:48",
author: "Jason Seifer",
thumbnail: null
},
The API from my Rails app doesnt have a Parent (http://www.soleresource.com/releases.json)
[
{
shoe_name: "Air Jordan 4 "Green Glow"",
release_date: "2013-08-17T00:00:00.000Z",
shoe_colorway: "Dark-Grey/Green-Glow",
shoe_price: "160",
url: "http://www.soleresource.com/releases/8.json"
},
{
shoe_name: "Nike Barkley Posite",
release_date: "2013-08-17T00:00:00.000Z",
shoe_colorway: "Gamma-Green/Black",
shoe_price: "235",
url: "http://www.soleresource.com/releases/17.json"
},
In order to get the app to work I have to call the Parent (posts), like this:
self.upcomingReleases = [dataDictionary objectForKey:#"posts"];
How can I "wrap" my API under a Parent? (My model is called "Releases")
IMHO, if you are using your rails app as a REST API, you should definitely use ActiveModel::Serializer. It will let you specify everything for your JSON responses, like metadata or roots
Here is a RailsCast for it: http://railscasts.com/episodes/409-active-model-serializers

MongoDB, add new { field : value } in existing embedded document with multiple level dot notation?

What I am trying to do is add a new {field:value} for a blog post. So for example, if I wanted to start tracking impressions on websites.blog_posts.url: 'http://www.example.com/01.html' how can I add that impressions attribute for that blog post?
My current document structure:
{
email_address: 'webmaster#example.com',
password: 'random_password',
first_name: 'John',
last_name: 'Doe',
user_type: 'WEBMASTER',
newsletter: 'NO',
websites: [{
main_title: 'My Blog Website',
main_url: 'http://www.example.com',
blog_posts: [{
url: 'http://www.example.com/01.html',
title:'My first blog post',
description: 'My first description.'
}, {
url: 'http://www.example.com/02.html',
title: 'My second blog post',
description: 'My second description.'
}, {
url: 'http://www.example.com/03.html',
title: 'My third blog post',
description: 'My third description.'
}, {
url: 'http://www.example.com/04.html',
title: 'My fourth blog post',
description: 'My fourth description.'
}]
}]
}
Here is what I thought would work using update and making upsert TRUE.
db.my_collection.update( {'websites.blog_posts.url': 'http://www.example.com/01.html' }, {'$set': {'websites.blog_posts.impressions': 549}}, true )
The error that I received is:
*can't append to array using string field name [blog_posts]*
Maybe "$set" is not correct for this or maybe I can not reference that deep with dot notation? I just started using MongoDB yesterday, any help would be great.
Thank you!
What you're trying to do is not possible given your schema. Dot-notation can be multi level but if there's more than one level that is an array it can no longer be addressed using the positional operator '$'.
E.g. you'd need to do :
db.my_collection.update(
{'websites.blog_posts.url': 'http://www.example.com/01.html' },
{'$set': {'websites.$.blog_posts.$.impressions': 549}},
true );
But having two position operators in the update is not possible since MongoDB can only determine the position of an element in the first array.
Your only option is to redesign your schema to have a dedicated collection of user websites (which is better for other reasons too in this case).