Why is my API not showing up on deployment? - google-app-engine

I suspect this is caused by the following bug in Endpoints (if valid) but I'm also sure there's a workaround somewhere.
https://code.google.com/p/googleappengine/issues/detail?id=9050&can=4&colspec=ID%20Type%20Component%20Status%20Stars%20Summary%20Language%20Priority%20Owner%20Log
Steps to reproduce:
Change a method name, API name of a method, or parameter list in an Endpoints class.
Run the endpoints.sh script to generate the API files.
Inspect the API files locally and witness the changes being there. So far so good.
Deploy to the default version of the app on the server.
Check the logs for the call to /_ah/spi/BackendService.getApiConfigs. There are no errors!
Go to API Explorer and clear the browser cache. Inspect the API. The change is not there.
Request the API file directly in the browser, eg. https://[app-id].appspot.com/_ah/api/discovery/v1/apis/[api-name]/v1/rpc The change is not there.
Frustrated with the above, I decided to start completely from scratch on a new app ID. I still see no API in the API Explorer and get a 404 on the URL in step 7 above!
Here's my endpoint class:
#Api(name = "ditto", version = "v1")
public class CategoryEndpoint extends BaseEndpoint {
#SuppressWarnings("unused")
private static final Logger log = Logger.getLogger(CategoryEndpoint.class.getName());
#ApiMethod(name = "category.list")
public WireCategory list() {
Category root = categoryDao.getRoot();
WireCategory wireRootCategory = new WireCategory(root);
return wireRootCategory;
}
}
And here's the generated .api file:
{
"extends" : "thirdParty.api",
"abstract" : false,
"root" : "https://1.eliot-dev-uk-ditto-do.appspot.com/_ah/api",
"name" : "ditto",
"version" : "v1",
"defaultVersion" : false,
"adapter" : {
"bns" : "https://1.eliot-dev-uk-ditto-do.appspot.com/_ah/spi",
"deadline" : 10.0,
"type" : "lily"
},
"auth" : {
"allowCookieAuth" : false
},
"frontendLimits" : {
"unregisteredUserQps" : -1,
"unregisteredQps" : -1,
"unregisteredDaily" : -1,
"rules" : [ ]
},
"cacheControl" : {
"type" : "no-cache",
"maxAge" : 0
},
"methods" : {
"ditto.category.list" : {
"path" : "list",
"httpMethod" : "GET",
"scopes" : [ ],
"audiences" : [ ],
"clientIds" : [ ],
"rosyMethod" : "ditto.api.CategoryEndpoint.list",
"request" : {
"body" : "empty"
},
"response" : {
"body" : "autoTemplate(backendResponse)"
}
}
},
"descriptor" : {
"schemas" : {
"WireCategory" : {
"id" : "WireCategory",
"type" : "object",
"properties" : {
"webSafePath" : {
"type" : "string"
},
"prettyPath" : {
"type" : "string"
},
"children" : {
"type" : "array",
"items" : {
"$ref" : "WireCategory"
}
},
"path" : {
"type" : "array",
"items" : {
"type" : "string"
}
},
"name" : {
"type" : "string"
},
"id" : {
"type" : "string",
"format" : "int64"
}
}
}
},
"methods" : {
"ditto.api.CategoryEndpoint.list" : {
"response" : {
"$ref" : "WireCategory"
}
}
}
}
}
This URL gives me a 404 where I expect to see my API JSON:
https://eliot-dev-uk-ditto-do.appspot.com/_ah/api/discovery/v1/apis/ditto/v1
This is killing me!
EDIT:
Here's a diff I just spotted between the .api file generated by App Engine 1.7.5 and 1.7.6. Not sure why the URLs have changed.
ditto-v1.api from 1.7.6:
{
"extends" : "thirdParty.api",
"abstract" : false,
"root" : "https://1.eliot-dev-uk-ditto-do.appspot.com/_ah/api",
"name" : "ditto",
"version" : "v1",
"defaultVersion" : false,
"adapter" : {
"bns" : "https://1.eliot-dev-uk-ditto-do.appspot.com/_ah/spi",
"deadline" : 10.0,
"type" : "lily"
}
...
ditto-v1.api from 1.7.5:
{
"extends" : "thirdParty.api",
"abstract" : false,
"root" : "https://eliot-dev-uk-ditto-do.appspot.com/_ah/api",
"name" : "ditto",
"version" : "v1",
"defaultVersion" : false,
"adapter" : {
"bns" : "http://eliot-dev-uk-ditto-do.appspot.com/_ah/spi",
"deadline" : 10.0,
"type" : "lily"
}
...

As you already pointed out, it was due to an weird issue in SDK 1.7.6, which adds that 1. at the beginning of the endpoint root url in the .api files...
I've tried the new SDK 1.7.7 and it seems to be solved...

Related

Query to update an array field by using another array field of same document in mongodb

Scenario
I've the following document from Chat collection with an array of messages and members in the chat.
And for each message, there will be status field which will store the delivered and read timestamp with respect to users.
{
"_id" : ObjectId("60679797b4365465745065b2"),
"members" : [
ObjectId("604e02033f4fc07b6b82771c"),
ObjectId("6056ef4630d7b103d8043abd"),
ObjectId("6031e3dce8934f11f8c9a79c")
],
"isGroup" : true,
"createdAt" : 1617401743720.0,
"updatedAt" : 1617436504453.0,
"messages" : [
{
"createdAt" : 1617401743719.0,
"updatedAt" : 1617401743719.0,
"_id" : ObjectId("60679797b4365465745065b3"),
"body" : "This is test message",
"senderId" : ObjectId("6031e3dce8934f11f8c9a79c"),
"status" : []
}
]
}
So, I want to insert the following data, into messages.status array, to know when the message is received/read by the member.
{
receiverId: <member of chat>
deliveredAt: <timestamp>
readAt: <timestamp>
}
Question
How to write a query to insert the above json for each member (except the sender) in the status array by using the data from existing field?
So that, after query, the document should look like this:
{
"_id" : ObjectId("60679797b4365465745065b2"),
"members" : [
ObjectId("604e02033f4fc07b6b82771c"),
ObjectId("6056ef4630d7b103d8043abd"),
ObjectId("6031e3dce8934f11f8c9a79c")
],
"isGroup" : true,
"createdAt" : 1617401743720.0,
"updatedAt" : 1617436504453.0,
"messages" : [
{
"createdAt" : 1617401743719.0,
"updatedAt" : 1617401743719.0,
"_id" : ObjectId("60679797b4365465745065b3"),
"body" : "This is test message",
"senderId" : ObjectId("6031e3dce8934f11f8c9a79c"),
"status" : [{
"receiverId": ObjectId("604e02033f4fc07b6b82771c")
"deliveredAt": <timestamp>
"readAt": <timestamp>
}, {
"receiverId": ObjectId("6056ef4630d7b103d8043abd")
"deliveredAt": <timestamp>
"readAt": <timestamp>
}]
}
]
}
Edit
I'm able to do this for static data.
Link: https://mongoplayground.net/p/LgVPfRoXL5p
For easy understanding: I've to map the members array and insert it into the status field of the messages
MongoDB Version: 4.0.5
You can use the $function operator to define custom functions to implement behavior not supported by the MongoDB Query Language. So along with updates-with-aggregate-pipeline and $function you can update messages.status array with only receiver's details as shown below:
NOTE: Works only with MongoDB version >= 4.4.
Try this:
let messageId = ObjectId("60679797b4365465745065b3");
db.chats.update(
{ "messages._id": messageId },
[
{
$set: {
"messages": {
$map: {
input: "$messages",
as: "message",
in: {
$cond: {
if: { $eq: ["$$message._id", messageId] },
then: {
$function: {
body: function (message, members) {
message.status = [];
for (let i = 0; i < members.length; i++) {
if (message.senderId.valueOf() != members[i].valueOf()) {
message.status.push({
receiverId: members[i],
deliveredAt: new Date().getTime(),
readAt: new Date().getTime()
})
}
}
return message;
},
args: ["$$message", "$members"],
lang: "js"
}
},
else: "$$message"
}
}
}
}
}
}
]
);
Output:
{
"_id" : ObjectId("60679797b4365465745065b2"),
"members" : [
ObjectId("604e02033f4fc07b6b82771c"),
ObjectId("6056ef4630d7b103d8043abd"),
ObjectId("6031e3dce8934f11f8c9a79c")
],
"isGroup" : true,
"createdAt" : 1617401743720,
"updatedAt" : 1617436504453,
"messages" : [
{
"_id" : ObjectId("60679797b4365465745065b3"),
"createdAt" : 1617401743719,
"updatedAt" : 1617401743719,
"body" : "This is test message",
"senderId" : ObjectId("6031e3dce8934f11f8c9a79c"),
"status" : [
{
"receiverId" : ObjectId("604e02033f4fc07b6b82771c"),
"deliveredAt" : 1617625735318,
"readAt" : 1617625735318
},
{
"receiverId" : ObjectId("6056ef4630d7b103d8043abd"),
"deliveredAt" : 1617625735318,
"readAt" : 1617625735318
}
]
},
{
"_id" : ObjectId("60679797b4365465745065b4"),
"createdAt" : 1617401743719,
"updatedAt" : 1617401743719,
"body" : "This is test message",
"senderId" : ObjectId("6031e3dce8934f11f8c9a79d"),
"status" : [ ]
}
]
}
Demo - https://mongoplayground.net/p/FoOvxXp6nji
https://docs.mongodb.com/manual/reference/operator/update/positional-filtered/
The filtered positional operator $[] identifies the array elements that match the arrayFilters conditions for an update operation, e.g.
db.collection.update({
"messages.senderId": "6031e3dce8934f11f8c9a79c" // query
},
{
"$push": {
"messages.$[m].status": [ // push into the matching element of arrayFilters
{
"receiverId": ObjectId("604e02033f4fc07b6b82771c")
},
{
"receiverId": ObjectId("6056ef4630d7b103d8043abd")
}
]
}
},
{
arrayFilters: [
{
"m.senderId": "6031e3dce8934f11f8c9a79c" // matches array element where senderId is 6031e3dce8934f11f8c9a79c
}
]
})
Note- add index to messages.senderId for performance

Mongodb - fetching subdocument in Array

My document has the following structure:
{
"exp" : "2020-01-27",
"session" : [
{
"parameters" : {
"run" : "2020-01-27-23-01-32_experiment"
},
"session" : "2eb2e35a-69ea-11ea-b7b6-005056b146e8",
"stage" : "intro",
"is_finished" : false,
"last_modified" : "2020-03-19 15:01:51"
},
{
"parameters" : {
"run" : "2020-01-27-23-01-32_experiment"
},
"session" : "32edb74c-69ea-11ea-b7b6-005056b146e8",
"stage" : "experiment",
"is_finished" : true,
"last_modified" : "2020-03-19 15:02:22"
},
{
"session" : "ffe003e2-69ed-11ea-b7b6-005056b146e8",
"parameters" : {
"run" : "2020-01-27-23-01-32_experiment"
},
"stage" : "intro",
"is_finished" : true,
"last_modified" : "2020-03-19 15:29:19"
}
]
}
I like to receive all sub documents where is_finished = true. I tried:
db.getCollection.sess.find(
{
"session.is_finished" : true
},
{
"session.$.session" : 1
}
);
But I just receive the first element that equals the criteria and not both sub documents.
How can I get all sub documents where is_finished = true?
You can take advantage of aggregation:
db.aggregate([{$unwind: '$session'},
{$match: {'session.is_finished': true}])

How to do mandatory fields in prismic.io CMS?

I'm using Prismic.io as a headless CMS and bringing content into my React front end. How do I set up a content type so that fields are mandatory?
Here's what I have so far...
{
"Main" : {
"uid" : {
"type" : "UID",
"config" : {
"placeholder" : "UID"
}
},
"image" : {
"type" : "Image"
},
"title" : {
"type" : "StructuredText",
"config" : {
"single" : "heading1",
"placeholder" : "Title..."
}
},
"description" : {
"type" : "StructuredText",
"config" : {
"multi" : "paragraph,em,strong,hyperlink",
"placeholder" : "Description..."
}
}
}
}
as for now, prismic.io CMS doesn't allow required fields. The only required field is the native "UID" field. They recommend using the in-website preview for publishers to preview the result before shipping content rather than adding constraints in the editor.

Why I can't get the full document form array?

I have this document in stored in my collection:
{ "_id" : ObjectId("5707b95b8415b224a48a0b2d"),
"companyId" : ObjectId("570269639caabe24e4e4043e"),
"descriptions" : [
{ "id" : ObjectId("5707b95b8415b224a48a0b2a"), "description" : "test" },
{ "id" : ObjectId("570cd8164fff3a20f88c0dc9"), "description" : "test1" },
{ "id" : ObjectId("570ce6ba4fff3a052c8c570f"), "description" : "etr" },
{ "id" : ObjectId("570cf1b64fff3a1a14d71716"), "description" : "43" },
{ "id" : ObjectId("570cf1b64fff3a1a14d71717"), "description" : "43" },
{ "id" : ObjectId("570cf1b64fff3a1a14d71719"), "description" : "345" }
],
"options" : [
{ "descriptionId" : ObjectId("5707b95b8415b224a48a0b2a"), "description" : "test" },
{ "descriptionId" : ObjectId("5707b95b8415b224a48a0b2a"), "description" : "test1" }
]
}
Now I'm trying to get the objects from the options array that are matching the descriptionId and here is how I'm doing it
db.CustomFields.find({companyId: ObjectId("570269639caabe24e4e4043e")},{"options.descriptionId": ObjectId("5707b95b8415b224a48a0b2a")})
But the result contains only the descriptionId - the description property is missing.
here is how the result looks like:
{ "_id" : ObjectId("5707b95b8415b224a48a0b2d"),
"options" : [
{ "descriptionId" : ObjectId("5707b95b8415b224a48a0b2a") },
{ "descriptionId" : ObjectId("5707b95b8415b224a48a0b2a") }
]
}
Why my query is not returning the full document from the array, but only a part of it? Can you give me a push?
EDIT
This is what I'm expecting to get from the query
{ "_id" : ObjectId("5707b95b8415b224a48a0b2d"),
"options" : [
{ "descriptionId" : ObjectId("5707b95b8415b224a48a0b2a", "description" : "test") },
{ "descriptionId" : ObjectId("5707b95b8415b224a48a0b2a", "description" : "test1") }
]
}
You need to include the other query with "options.descriptionId" together with the companyId query and use projection to return just the array you want.
The following shows this:
db.customFields.find(
{
"companyId": ObjectId("570269639caabe24e4e4043e"),
"options.descriptionId": ObjectId("5707b95b8415b224a48a0b2a")
},
{ "options": 1 }
);
Output
{
"_id" : ObjectId("5707b95b8415b224a48a0b2d"),
"options" : [
{
"descriptionId" : ObjectId("5707b95b8415b224a48a0b2a"),
"description" : "test"
},
{
"descriptionId" : ObjectId("5707b95b8415b224a48a0b2a"),
"description" : "test1"
}
]
}
Try this
db.CustomFields.find({companyId: ObjectId("570269639caabe24e4e4043e"),"options.descriptionId": ObjectId("5707b95b8415b224a48a0b2a")})

How to query the firebase database to fetch specific data?

{
"todo" : {
"Kujbghnkj04t56-" : {
"id" : 1,
"tags" : [ {
"name" : "Italy"
}, {
"name" : "Australia"
} ],
"username" : "ABC"
},
"oPikoieew9oR-" : {
"id" : 2,
"tags" : [ {
"name" : "Switzerland"
} ],
"username" : "XYZ"
}
}
}
I am trying to search in Firebase according to tags name. My code is:
var tagRef = new Firebase(FURL+'/todo');
var tagCollection = $firebaseArray(tagRef);
tagCollection.$ref().orderByChild("tags").equalTo("Australia").once("value", function(dataSnapshot){
// code
});`
How can I get the snapshot of all data containing tag name as "Australia"

Resources