Linq2Dynamodb run expression string on Table - asp.net

I have an ASP.NET Web API site which records all objects in AWS DynamoDb. I took a quick look at linq2Dynamodb. It seems that the common way to use it is like:
var moviesTable = ctx.GetTable<Movie>();
var inceptionMovie = moviesTable
.Where(m => m.Genre == "Thriller" && m.Title == "Inception")
.Single();
But I want some API like:
moviesTable.Execute(string querystring);
The reason is that from the Web API, I usually get some query like:
http://host/service.svc/Orders?$filter=ShipCountry eq 'France'
I'd like to pass the filter string "ShipCountry eq 'France'" here. Do anyone know if there is a way for me to do this? Thanks.

With Linq2DynamoDb you can expose your DynamoDb tables as OData resources. Please, see the doc here.
As soon as you have an OData resource, you can query it with OData queries of any valid kind.
And you can use any OData client library for that. E.g. with System.Data.Services.Client you would say something like:
var entities = myContext.Execute<MyEntityType>(new Uri("<here goes URI with valid OData query string>"), "GET", true);
or just construct a LINQ query on the client side.
The drawback is that you will need to host your OData service somewhere (DynamoDb itself doesn't support OData, so that's the reason).
The advantages are:
you will be able to cache your data in ElastiCache.
you will be able to implement custom authentication inside your service.
Sorry for a bit late answer.

Related

GMB - Removal of LocationState object in Business Information API

Google deprecated the old GMB API v4.9 account.locations.get endpoint, and replaced it with Business Information API v1 locations.get.
Code change that affects me is:
Removal of LocationState object. The existing fields have been moved into Metadata.
The new Metadata object does not return the attributes LocationState object contained before. The ones I'm interested in are:
isVerified
isPublished
isSuspended
isDisabled
isDisconnected
etc...
My question is:
How could I get this data without using deprecated endpoints?
Try Verification API getVoiceOfMerchantState
isVerified (verify),
isPublished (hasVoiceOfMerchant=true AND hasBusinessAuthority=true),
isSuspended (complyWithGuidelines),
isDuplicate (resolveOwnershipConflict).
isDisabled & isDisconnected have no equivalent in new API
As far as I can see, based on the link you have sent it is written:
Endpoint URL:
Endpoints for all business information, attributes, categories, chains and locations search are accessible at https://mybusinessbusinessinformation.googleapis.com/v1/ instead of https://mybusiness.googleapis.com/v4/
The path name for locations endpoints has changed from
accounts/accountId/locations/locationId to locations/locationId
Maybe it was better if you could provide the request uri in the previous version so we could help you more precisely. Anyhow, what I tested in the google playground is as follows:
open [https://developers.google.com/oauthplayground]
after setting your clientId and Authorisation stuff, in the Request URI write
https://mybusinessbusinessinformation.googleapis.com/v1/locations/XXXXX?readMask=storeCode,metadata,profile,serviceArea,labels,adWordsLocationExtensions
instead of XXXXX, write your locationId
you can write different readMask fields, The possible fields for readMask are:
play with different fields to check if you have your desired one or not readMask="storeCode,regularHours,name,languageCode,title,phoneNumbers,categories,storefrontAddress,websiteUri,regularHours,specialHours,serviceArea,labels,adWordsLocationExtensions,latlng,openInfo,metadata,profile,relationshipData,moreHours";
If above does not help you, in the link below I see that all metadata attribute of a location might be:
Click [here] (https://developers.google.com/my-business/reference/businessinformation/rest/v1/accounts.locations#Location.Metadata)

querying across application insights resource with REST API

I have data which are stored in 3 different application insights resources, thanks to query across resource feature added last year (https://azure.microsoft.com/en-us/blog/query-across-resources/) was possible to query those 3 application insights at once with app identifier.
I'm trying to execute this query through app insights REST API : https://dev.applicationinsights.io (app insights REST API) for a very basic need from a static HTML page (no backend)
but without luck
I do suspect that app identifier isn't supported, it is actually the case ? any workaround for my use case (no backend).
Here is an example with the query in the body. My queries are quite complex and have a lot of let statements and therefore passing the query in the body is easier. There are some PowerShell quirks in the example below, but I'll update with a C# example tomorrow.
The let statement in the example below is pretty pointless, it's mostly there to show that you can do complex queries with let expressions etc.
AppId is the Application Insights resource ID - and NOT the instrumentation key. The API key is just a long string and you can create up to 10 of them AFAIK.
You will find both the id and keys under API Access (I've added a screenshot as it's easy to get them confused). When you use the app() function use the app id.
$app1Id = "GUID"
$app2Id = "GUID"
$app1Key = "string"
$app2Key = "string"
# EXAMPLE: "X-Api-Key" = "key1:GUID1,key2:GUID2"
$headers = #{ "X-Api-Key" = "${app1Key}:$app1Id,${app2Key}:$app2Id"; "Content-Type" = "application/json" }
# EXAMPLE: "query" = "union app('GUID1').something, app('GUID2').something | limit 5"
$query = #{"query" = "let days=1d;union app('$app1Id').exceptions,app('$app2Id').exceptions | where timestamp > ago(days)"}
$body = ConvertTo-Json $query | % { [regex]::Unescape($_) }
$result = Invoke-RestMethod "https://api.applicationinsights.io/v1/apps/$app1Id/query" -H $headers -Body $body -Method POST
The query above will return all the exceptions for the two Application insights resources for the last day. You can do a query across 10 resources at the time of writing, 200 requests per 30 seconds or a max of 86,400 requests per day (UTC). Other limits apply if you use ADD.
NOTE: the extra {} in the header is a PowerShell quirk in regards to variables and the use of the colon char, and as you can see in the example you should not bracket the keys in the header :)
Checked with the dev team that owns that service:
You should be able to put the api key in as apiKey1:appId1,apiKey2:appId2 in the api key box and this should work.
the [object ProgressEvent] response is a bug in the explorer that should have really showed you an error.
And as a workaround, you could always do the queries inside the azure portal itself in workbooks for any of the AI resources, or hypothetically also from the analytics portal for any of the AI resources, and those wouldn't require the API key at all, if all you needed was to see the data.

Meteor Publish/Subscribe passing object with string parameter issue

I am trying to pass a object { key:value} and send it to meteor publish so i can query to database.
My Mongo db database has (relevant datas only) for products:
products : {
categs:['Ladies Top','Gents'],
name : Apple
}
In meteor Publish i have the following:
Meteor.publish('product', (query) =>{
return Clothings.find(query);
})
In client i use the following to subscribe:
let query = {categs:'/ladies top/i'}; // please notice the case is lower
let subscribe = Meteor.subscribe('product',query);
if (subscribe.ready()){
clothings = Products.find(query).fetch().reverse();
let count = Products.find(query).fetch().reverse().length; // just for test
}
The issue is, when i send the query from client to server, it is automatically encoded eg:
{categs:'/ladies%top/i'}
This query doesnot seem to work at all. There are like total of more than 20,000 products and fetching all is not an option. So i am trying to fetch based on the category (roughly around 100 products each).
I am new to ,meteor and mongo db and was trying to follow existing code, however this doesnot seem to be correct. Is there a better way to improve the code and achieve the same ?
Any suggestion or idea is highly appreciated.
I did go through meteor docs but they dont seem to have examples for my scenario so i hope someone out there can help me :) Cheers !
Firstly, you are trying to send a regex as a parameter. That's why it's being encoded. Meteor doesn't know how to pass functions or regexes as parameters afaict.
For this specific publication, I recommend sending over the string you want to search for and building the regex on the server:
client:
let categorySearch = 'ladies top';
let obj = { categorySearch }; // and any other things you want to query on.
Meteor.subscribe('productCategory',obj);
server:
Meteor.publish('productCategory',function(obj){
check(obj,Object);
let query = {};
if (obj.categorySearch) query.category = { $regex: `/${obj.categorySearch}/i` };
// add any other search parameters to the query object here
return Products.find(query);
});
Secondly, sending an entire query objet to a publication (or Method) is not at all secure since an attacker can then send any query. Perhaps it doesn't matter with your Products collection.

Set Apects via REST API Call in Alfresco

What is the JSON Format to set aspects to some folder or documents in alfresco via REST API.
You need to send POST request by the following url (Alfresco 4.1.5):
your_host/alfresco/s/slingshot/doclib/action/aspects/node/workspace/SpacesStore/{nodeUUID}
for Alfresco 5:
your_host/alfresco/s/slingshot/doclib/action/aspects/node/workspace/SpacesStore/{nodeUUID}
with the following body:
{
"added":["abc:doc"],
"removed":[]
}
The preferred approach is to use CMIS rather than the internal slingshot web script. Using CMIS you can add an aspect in a standard way, and you can do it via the browser binding (JSON), the Atom Pub binding (XML), or Web Services.
You can use a CMIS client, such as one of the ones available from http://chemistry.apache.org, or you can do it using the raw binding directly over HTTP.
In CMIS 1.1 you add an aspect by adding its ID to the multi-value property named cmis:secondaryObjectTypeIds.
Here's a gist that shows what this looks like in Java: https://gist.github.com/jpotts/7242070
You need to make one custom webscript.The code of webscript will be like below.In case of webscript you can use below link for learning purpose.
https://wiki.alfresco.com/wiki/Web_Scripts
var props = new Array(1);
props["cm:template"] = document.nodeRef;
document.addAspect("cm:templatable", props);
props = new Array(1);
props["cm:lockIsDeep"] = true;
document.addAspect("cm:lockable", props);
props = new Array(1);
props["cm:hits"] = 1;
document.addAspect("cm:countable", props);

Returning ItemStats from Tridion UGC

I was wondering if anyone can offer any pointers on this one. I'm trying to return ItemStats from the Tridion UGC web service but I'm getting the following error when trying to bind the results:-
The closed type TridionWebUGC.CDS.ItemStat does not have a corresponding LastRatedDate settable property.
An example of code is:-
WebServiceClient ugcCall2 = new WebServiceClient();
Uri uri = new Uri("http://new.ugc.service/odata.svc");
CDS.ContentDeliveryService cds = new CDS.ContentDeliveryService(uri);
var myItemStats = cds.ItemStats.Where(p => p.PublicationId == 68 && p.Id == 17792 && p.Type==16);
I can get comments and ratings with no problem. E.g.
var myComments = cds.Comments.Where(p => p.ItemId == 17805).OrderBy(p => p.CreationDate);
It's just ItemStats that are giving me an issue. Anybody any ideas?
Thanks
John
Unfortunately, the metadata of the UGC WebService is not correct in regards to the ItemsStats. For you it means that the webservice metadata does not expose the fact that the ItemStat entity contains the LastRatedDate property. This makes your .NET proxies not to be aware of this property and makes your query fail.
To work-around this defect you have two option:
Add to your service the following property: cds.IgnoreMissingProperties = true;. Advantage of this approach is that you're done with it in 2 sec. Disadvantage is that you will not be able to access that property (in case you actually use it);
Modify the proxies generated by Visual Studio and manually add that property to the ItemStat class. Advantage of this approach is that you will be able to access the property from your project. Disadvantage is that it's totally not manageable from the coding point of view, you need to be careful when you upgrade or regenerate the proxies and it's easy to make a mistake while manually adding the property.
Note 1: to access the metadata of your webServer from the browser your can go to /odata.svc/$metadata.
Note 2: on a closer look there are 2 properties missing from the webService metadata: LastRatedDate and LastCommentedDate.
Hope this helps.

Resources