Why does HasNext() return false, when - rets

I am using libRets for .NET, and querying http://retsgw.flexmls.com/rets2_1/, using a valid user account. From C#, after calling Search() I check the count using GetCount() and I get 6300 results, but when I call HasNext() the first time returns false.
Checking the XML response, it looks like the results are empty () even though the result count provides a number.
So... where did the results go?
The exact query is the following:
http://retsgw.flexmls.com/rets2_1/Search?Class=OpenHouse&Count=1&QueryType=DMQL2&SearchType=OpenHouse&Select=ListingID&StandardNames=1
Here is the request:
SearchRequest request = client.CreateSearchRequest("OpenHouse", "OpenHouse", "");
request.SetStandardNames(true);
request.SetSelect("ListingID");
Here is how the request is made:
SearchResultSet result = client.Search(request);
Here is how the result is handled:
while (result.HasNext()) {
// Do something
}

So, it looks like the FlexMLS Support was able to help (rather quickly).
I needed to add &Format=COMPACT-DECODED to the query string.
So, in the code it would look like this:
request.SetFormatType(SearchRequest.FormatType.COMPACT_DECODED);

1) You are setting StandardNames to true AND then setting a selection. That selection may not exist in StandardNames. (You're reviewed the metadata returned by the server, right?) Its possible the server doesn't take the select into account when doing the count, but does on a full query, therefor it doesn't have any information to send back because it doesn't have a Table matching what you selected. What happens when you don't set the Select?
2) Have you done a packet trace or set libRETS to log the network traffic to a file? (I can't tell if that's what you mean by "Checking the XML response, it looks like the results are empty () even though the result count provides a number.") If you haven't, do that and see if the server is passing back any information.
If the server is passing pack information, you might have discovered a bug in libRETS and I invite you to join the libRETS-users mailing list and share this data (and that network trace) there.
If the server is passing back 0 results, you'll may need to contact your MLS and/or FlexMLS to see if you don't have permissions to view the results. Some RETS servers have fine grained results where you could get the count, but not get the data.

Related

Cakephp 3.x Table Beforefind, unable to stop event

Per the documentation on the website of CakePHP: (https://book.cakephp.org/3/en/orm/table-objects.html#beforefind) stopping the event or supplying a return value should stop the find operation.
I'm using the following code in the Beforefind:
$event->stopPropagation();
return false;
But this doesn't seem to have any effect.
The docs need some fixing there, as there's various things wrong with it, returning data won't make any difference, as the return value is never used, also you can't really use the beforeFind event for configuring caching, it's limited to the point of it not being useful, as the event is only being triggered for non-cached queries, and for those it's triggered after the cache is being checked.
That being said, stopping the find operation is possible by providing custom results, not by returning data, but by setting it via Query::setResult(), which expects an instance of \Cake\Datasource\ResultSetInterface.
An example would be:
$results = [];
$resultSet = new \Cake\Datasource\ResultSetDecorator($results);
$query->setResult($results);
$event->stopPropagation();
That would make the query return an empty result set (ResultSetDecorator is just a collection that implements ResultSetInterface), which is the closest you can come to "stopping" the query.

Fhir client against hapi server never returns more than 2000 records

I'm using the .NET Fhir client against a Smile (hapi) CDR Fhir server. I have 3235 patients that I'm trying to retrieve using the code below, but never get more than 2000 exactly. I have tried adding headers using and not using the no-cache option. I know the server has more records because I issue a Patient/?_summary=count that gives me the total number of records I'm expecting (3235).
I've disabled server cache, refreshed indexes, but always get exactly 2000 records. I've also tried different methods of retrieving patients by using Get() verses Search() methods, but both come up with the same result. Can anyone suggest another way to get the correct number of patients back or hints as to what I may be doing wrong?
var patients = new List<Patient>();
var bundle = (Bundle)client.Get("Patient");
while (bundle != null)
{
patients.AddRange(bundle.Entry.Select(e => e.Resource as Patient));
bundle = client.Continue(bundle);
}
I've tried using several variations of including the cache control header but counts remain the same.
client.OnBeforeRequest += (object sender, BeforeRequestEventArgs e) =>
{
e.RawRequest.Headers.Clear();
e.RawRequest.Headers.Add("Accept", "application/fhir+json;fhirVersion=4.0");
e.RawRequest.Headers.Add("Cache-Control", "no-cache");
};
The server has the right to impose an upper limit of data it will return in a single call, regardless of how many records are requested by the client. The only way to retrieve more data is to page through it using the 'next' link, as defined in the FHIR spec.

How exactly does the fetchAllIfNeeded differ from fetchAll in the JS SDK?

I never quite understood the if needed part of the description.
.fetchAll()
Fetches the given list of Parse.Object.
.fetchAllIfNeeded()
Fetches the given list of Parse.Object if needed.
What is the situation where I might use this and what exactly determines the need? I feel like it's something super elementary but I haven't been able to find a satisfactory and clear definition.
In the example in the API, I notice that the fetchAllIfNeeded() has:
// Objects were fetched and updated.
In the success while the fetchAll only has:
// All the objects were fetched.
So does the fetchAllIfNeeded() also save stuff too? Very confused here.
UPDATES
TEST 1
Going on some of the hints #danh left in the comments I tried the following things.
var todos = [];
var x = new Todo({content:'Test A'}); // Parse.Object
todos.push(x);
x.save();
// So now we have a todo saved to parse and x has an id. Async assumed.
x.set({content:'Test B'});
Parse.Object.fetchAllIfNeeded(todos);
So in this scenario, my client x is different than the server. But the x.hasChanged() is false since we used the set function and the change event is triggered. fetchAllIfNeeded returns no results. So it isn't that it's trying to compare this outright to what is on the server to sync and fetch.
I notice that in the request payload, running the fetchAllIfNeeded is sending the following interesting thing.
{where: {objectId: {$in: []}}, _method: "GET",…}
So it seems that on the clientside something determines whether an object isNeeded
Test 2
So now, based on the comments I tried manipulating the changed state of the object by setting with silent.
x.set({content:'Test C'}, {silent:true});
x.hasChanged(); // true
Parse.Object.fetchAllIfNeeded(todos);
Still nothing interesting. Clearly the server state ("Test A") is different than clientside ("Test C"). and I still results [] and the request payload is:
{where: {objectId: {$in: []}}, _method: "GET",…}
UPDATE 2
Figured it out by looking at the Parse source. See answer.
After many manipulations, then taking a look at the source - I figured this out. Basically fetchAllIfNeeded will fetch models in an array that have no data, meaning there are no attribute properties and values.
So the use case would be you have lets say a parent object with an array of nested Parse Objects. When you fetch the parent object, the nested child objects in the array will not be included (unless you have the include query constraint set). Instead, the pointers are sent back to clientside and in your client, those pointers are translated into 'empty' models with no data, basically just blank Parse.Objects with ids.
Specifically, the Parse.Object has an internal Boolean property called _hasData which seems to be toggled true any time stuff like set, or fetch, or whatever gives that model attributes.
So, lets say you need to fetch those child objects. You can just do something like
var childObjects = parent.get('children'); // Array
Parse.Object.fetchAllIfNeeded(childObjects);
And it will search for those children who are currently only represented as empty Objects with id.
It's useful as opposed to fetchAll in that you might go through the children array and lazily load one at a time as needed, then at a later time need to "get the rest". fetchAllIfNeeded essentially just filters "the rest" and sends a whereIn query that limits fetching to those child objects that have no data.
In the Parse documentation, they have a comment in the callback response to fetchAllIfNeeded as:
// Objects were fetched and UPDATED.
I think they mean the clientside objects were updated. fetchAllIfNeeded is definitely sending GET calls so I doubt anything updates on the serverside. So this isn't some sync function. This really confused me as I instantly thought of serverside updating when they really mean:
// Client objects were fetched and updated.

Handling Exchange Web Services (EWS) missing properties

I'm relatively comfortable with EWS programming and Exchange schemas, but running into an interesting problem to handle.
I have a propertyset, asking for:
ItemClass
DateTimeReceived
LastModifiedTime
Size
Every Item in the AllItems folder at the root.
I get the result set, and then attempt Linq queries against the set, particular to the DateTimeReceived. All Items don't have a DateTimeReceived returned by the server, and they except. I'm trying a...
long msgCount = (from msg in allItems
where !msg.DateTimeReceived.Equals(null)
select msg).Count();
... which (IMO) should return the count of allItems that have a DateTimeReceived. However, the property isn't null; it's just not there, throwing an exception.
I'm trying to avoid iterating through the set one by one, trying each record. Anyone have a thought or experience?
Thanks TTY for the input that definitely lead to the following code that returns what I need. (Still in final testing)
List<EWS.Item> noReceivedProperty = inputlist.Where(m => (m.GetType().GetProperty("DateTimeReceived") != null)).ToList<EWS.Item>();
Then of course, take noReceivedProperty.Count or such as needed.

Request for several responses

I would like to create a web application.
There are cases, when a user's request would result in refreshing the content in 2-3 or sometimes even more containers. The cleanest way would be to run the requests one after the other in a sequence and handle the results one by one. I would like to have only one request if it is possible, and collecting all the results for the responses.
Eg.: let's say, there is a main container (M), and some other (smaller) containers (A, B, C, etc.)
The simple way would be:
request main function from server for M, show it in M container
fetch some other content from server dedicated for A_container, show it in A_container
fetch some other content from server dedicated for B_container, show it in B_container
fetch some other content from server dedicated for C_container, show it in C_container
Depending on the main function requested by the user, just some of the containers have to refresh it's content, not all of them.
I would like to minimise the number of requests. Actually minimise it to one. Of course, it could be done by Json, or XML.
I would like to collect all the responses from the server, encapsulate them (A_container:"this is content for A_container", C_container: "Other content for C_container"), and send it back to the client, where the client would unpack it, and regarding to the content, it would delegate each of them to the appropriate container.
My question is, that how would you do it, when you know, that the returned data is very variable: in some cases it might contain even html elements, quotes, double quotes, etc. If I am not mistaken, in some special cases this could screw up Json and xml as well.
My idea was to divide the different contents by special separators (for now just for an easy example let's use xxx, and yyy). It is a very uggly solution, but you cannot screw up the content for sure, if the separators are unique enough.
The previous Json-like solution would look like this:
"A_containeryyythis is content for A_containerxxxC_containeryyyOther content for C_container"
Then on the client side split the code first by xxx, which would result in this case in two array elements (strings), what are going to be split again by yyy. The first element would give the container's id, the second one the content for it. After this the last step would be walking through the new arrays, and display the result in the appropriate containers.
Is there anybody who would suggest a nicer way for this, or who could show a safe way to do it in Json, or XML, etc?
The previous Json-like solution would look like this: "A_containeryyythis is content for A_containerxxxC_containeryyyOther content for C_container"
THat woul seem more like a "text/plain" response from the server that you would handle via a javascript split. What you would really want to do is return a json object from the server, e.g.
object = {'A container content','etc','etc','etc'}
Then evaluate that using javascript from the client side using eval(object). From there I would populate each one of your "containers".
Format your request using XML:
<response>
<m>Content</m>
<a>Content</a>
<b>Content</b>
<c>Content</c>
</response>
Then parse the XML in your XMLHttpRequest callback:
var xmldoc = req.responseXML;
var root = xmldoc.getElementsByTagName('response').item(0);
var contentm = root.getElementsByTagName('m');
var contenta = root.getElementsByTagName('a');
var contentb = root.getElementsByTagName('b');
var contentc = root.getElementsByTagName('c');
if (contentm) {
/* Update Container M */
}
if (contenta) {
/* Update Container A */
}
if (contentb) {
/* Update Container B */
}
if (contentc) {
/* Update Container C */
}

Resources