Yahoo GeoPlanet - find places in specified country or woeid - yahoo-api

I'm trying to make sure the result from text search is only UK or Ireland. My places REST request looks like this:
http://where.yahooapis.com/v1/places.q('Belfast')?format=json&appid=MyAppIdGoesHere
Is there another parameter for the URL that I can specify the country or woeid the result must be in?

I don't believe there is a way to add that specificity within the GeoPlanet web service call. There is support for Filters, including the $and filter which lets you combine two filters together, but it doesn't look like a combination exists that would satisfy your request directly.
As an alternative, you could make the API call, then filter the results to keep only those results in the matching country.
For example, the following is part of the results for a search for "Belfast". After retrieving these results, you could keep only those places where country=GB:
<place xmlns="http://where.yahooapis.com/v1/schema.rng"
xml:lang="en-GB" yahoo:uri="http://where.yahooapis.com/v1/place/44544">
<woeid>44544</woeid>
<placeTypeName code="7">Town</placeTypeName>
<name>Belfast</name>
<country code="GB" type="Country" woeid="23424975">United Kingdom</country>
<admin1 code="GB-NIR" type="Country" woeid="20070563">Northern Ireland</admin1>
<admin2 code="GB-BFS" type="County" woeid="20071112">Belfast</admin2>
<admin3 code="" type="Local Administrative Area" woeid="20078326">Belfast</admin3>
<locality1 type="Town" woeid="44544">Belfast</locality1>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng"
xml:lang="en-GB" yahoo:uri="http://where.yahooapis.com/v1/place/2361609">
<woeid>2361609</woeid>
<placeTypeName code="7">Town</placeTypeName>
<name>Belfast</name>
<country code="US" type="Country" woeid="23424977">United States</country>
<admin1 code="US-ME" type="State" woeid="2347578">Maine</admin1>
<admin2 code="" type="County" woeid="12588673">Waldo</admin2>
<admin3/>
<locality1 type="Town" woeid="2361609">Belfast</locality1>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng"
xml:lang="en-GB" yahoo:uri="http://where.yahooapis.com/v1/place/2348154">
<woeid>2348154</woeid>
<placeTypeName code="7">Town</placeTypeName>
<name>Belfast</name>
<country code="NZ" type="Country" woeid="23424916">New Zealand</country>
<admin1 code="NZ-CAN" type="Region" woeid="15021751">Canterbury</admin1>
<admin2 code="" type="County" woeid="55875854">Christchurch City</admin2>
<admin3/>
<locality1 type="Town" woeid="2348154">Belfast</locality1>
</place>
<place xmlns="http://where.yahooapis.com/v1/schema.rng"
xml:lang="en-GB" yahoo:uri="http://where.yahooapis.com/v1/place/2361600">
<woeid>2361600</woeid>
<placeTypeName code="7">Town</placeTypeName>
<name>Belfast</name>
<country code="US" type="Country" woeid="23424977">United States</country>
<admin1 code="US-NY" type="State" woeid="2347591">New York</admin1>
<admin2 code="" type="County" woeid="12589313">Allegany</admin2>
<admin3/>
<locality1 type="Town" woeid="2361600">Belfast</locality1>
</place>

This can be made possible by using the $and operator as your filter. Take note that the $and operator can combine two different filters, which is in your case you want to do the text search within a specified place (UK or Ireland). For that you can use the .woeid and the .q filters like so:
http://where.yahooapis.com/v1/places$and(.woeid(23424975),.q('Belfast'))?format=json&appid=YourAppIdGoesHere
wherein in this example, the numeric value 23424975 is the woeid of UK.

Related

How to write dynamic attributes

I need to write a dynamic Attribute name instead of hardcode of Name attribute in dataweave 2.0 mulesoft 4 in anypointstudio
<?xml version="1.0" encoding="UTF-8"?>
<iGoApplicationData>
<UserData>
<Data Name="UpdateUserProfile">True</Data>
<Data Name="Action">??</Data>
</iGoApplicationData>
So in order to generate an XML like yours the DW structure will look like
{
iGoApplicationData: {
UserData: {
Data #(Name: payload.foo): "True",
Data #((var.attributeName): "Action"): "??"
}
}
}
So in this example I show how to specify a value in the attribute or a dynamic attribute name. For the dynamic attribute value just type the expression on the value side of the attribute (the part that goes after the :)
For dynamic attribute name you need to wrap the expression between parenthesis. When the name is wrapped between parenthesis it is considered dynamic. This applies to object keys and attributes names

TYPO3 count objects with constraint and display result in fluid template

I have build an extension with the extension builder that handles objects, an object can be an "item" or a "project".
An object has a field status which has 4 options, and is filled with an integer (3 = sold).
An object can be signed as a "project", in that case it has a boolean 1 for isproject and a field items with related objects as items.
this all works fine, I can iterate trough the projects with my fluid template and with <f:count>{object.items}</f:count> display the number of items appartaining to the project.
In the same fashion I should display the count of only the sold items ...
(<f:count where="object.items.status == 3">{object.items}</f:count> this obviously does not work, just to render the idea)
with <f:debug>{object}</f:debug> I see the field status defined for all items ...
since I have no idea how to approch this I might have left out some vital information
As indicated in the previous answer, you can use the GroupedFor ViewHelper for this purpose. But using it would be to much logic inside the fluid template thats the reason why this should be done in the controller, model or repository.
Example: Adding a Getter to the Object-Model
/**
* #return int
*/
public function getSoldItems() {
$soldCount = 0;
foreach($this->getItems() as $item) {
// 0 = sold
if($item->getStatus()===0) {
$soldCount++;
}
}
return $soldCount;
}
In fluid you can call the Getter with {object.soldItems}
A better performance solution especially with lazy loading subobjects would be counting with the repository. For this you have to create a function in the repository and call it inside the Getter-Function. To use common repository methods for creating the query, you need a "Backrelation" of items to the object. Otherwise you have to write the query with "statement()" on your own.
You can count them in the controller or use the GroupedFor ViewHelper https://fluidtypo3.org/viewhelpers/fluid/master/GroupedForViewHelper.html
Check this workaround:
<f:variable name="counter" value="0" />
<!-- Loop over the elements -->
<f:for each="{bookings}" as="booking">
<!-- Check if the criteria is met -->
<f:if condition="{booking.paid}">
<!-- Increment the counter -->
<f:variable name="counter" value="{counter + 1}" />
</f:if>
</f:for>
<!-- Display the counter-Variable -->
{counter}

Grab JSPX user input directly from a trinidad UIXComponent in my Java code?

I would like to retrieve the user input from a component within my Java code. Something akin to textbox.text in aspx/.NET. I am finding the documentation very confusing and my attempts don't compile. Is there a way?
<tr:inputDate id="date" required="true"
inlineStyle="color:rgb(0,58,117); font-weight:bold;"
value="#{processScope.benefit.serviceDate}"
immediate="false"
onchange="submit();"
label="#{mb_ResourceBean.res['claim.serviceDate.label']}">
<tr:convertDateTime pattern="yyyy/MM/dd" secondaryPattern="yyyyMMdd"
type="date"/>
<tr:validateDateTimeRange minimum="#{bk_ClaimBean.minDate}"
maximum="#{bk_ClaimBean.maxDate}"/>
</tr:inputDate>
Poor half-attempt to grab input:
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
UIXComponent component = viewRoot.findComponent("date"); //does not compile
I'm not sure what you are trying to achieve, but since you already have a value binding (#{processScope.benefit.serviceDate}) and you have onchange="submit();" in your <tr:inputDate> it looks like you want to use a valueChangeListener.
You need a method to handle the value change event in your bean, for example:
public void dateChanged(ValueChangeEvent event)
{
System.out.println("New value: "+ event.getNewValue());
System.out.println("instanceof Date: "+ (event.getNewValue() instanceof Date));
}
In your jspx you have to add the listener. Also you might want to use autoSubmit="true" instead of onchange="submit();", for example:
<tr:inputDate value="#{myBean.myDate}"
valueChangeListener="#{myBean.dateChanged}"
immediate="true" autoSubmit="true"/>
The code in your question does not compile since viewRoot.findComponent() will return a UIComponent. You need to cast it to UIXComponent.
Also, you need to take the naming containers into account. You will need to use something like: viewRoot.findComponent("formId:date");. In this case formId is the id of your <tr:form>.

How to select siblings (xpath syntax) with Perl's XML::Twig?

I need to select the next node via next_sibling or first_elt. But I want to filter by node name (containing the string "TON")
first_elt ('HILTON[#method]' or 'SHERATON[#method]');
or
next_sibling ('HILTON[#method]' or 'SHERATON[#method]');
or
next_sibling ('TON[#method]');
Example I tried (not working):
#!/usr/bin/perl -w
use warnings;
use XML::Twig;
$t-> parsefile ('file.xml');
my $Y0=$t->first_elt('HILTON[#method]' or 'SHERATON[#method]');
it will just process for 'HILTON[#method]'
my $Y0=$t->first_elt('/*TON[#method]');
wrong navigation condition '/*TON[#method]' () at C:/strawberry/perl/site/lib/XML/Twig.pm line 3523
As this is outside of the XPath subset supported by XML::Twig, you have to use a custom filter, by passing code to first_elt:
$t->first_elt( sub { $_[0]->tag=~ m{TON$} && $_[0]->att( 'method') })
This returns the first element for which the sub returns a true value.
The need for such an expression is a bit troubling though. In your example you define a class of elements by the fact that their name ends in TON. What happens when you have a CARLTON element? Or when MARRIOTT elements need to be processed with SHERATON and HILTON? Do you need to rewrite your queries?
If you are the one designing the format of the data, I would suggest revising the format. HILTON and SHERATON should probably be attributes of a HOTEL, BRAND or OWNER tag. Maybe an additional attribute would be useful, to mark that both types should be processed similarly. This attribute would only make sense if it is a property intrinsic to the data.
If the data is what it is and you have no input on its format, then I would have a list of the tags to process and check on these:
my %TAGS_TO_PROCESS= map { $_ => 1 } qw( HILTON SHERATON);
my $elt= $t->first_elt( sub { $TAGS_TO_PROCESS{$_[0]->tag} && $_[0]->att( 'method') })
This way adding/substracting other tags is easy.
Use:
*[substring(name(), string-length(name()) - 2) = 'TON'][#method][1]
Explanation:
This expression uses an XPath 1.0 equevalent for the XPath 2.0 standard function ends-with():
The XPath 1.0 equivalent of the XPath 2.0 expression:
ends-with($s, $s2)
is:
substring($s, string-lenth() - string-length($s2) + 1) = $s2
In this last expression we substitute $s with name() and $s2 with 'TON'
XSLT - based verification:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<xsl:copy-of select=
"*[substring(name(), string-length(name()) - 2) = 'TON'][#method] "/>
==========
<xsl:copy-of select=
"*[substring(name(), string-length(name()) - 2) = 'TON'][#method][1] "/>
</xsl:template>
</xsl:stylesheet>
when applied on this XML document:
<t>
<HILTON method="buy"/>
<TON method="burn"/>
<TONIC method="drink"/>
<HILTON nomethod="yes"/>
<SHERATON/>
<SHERATON method="visit"/>
</t>
the transformation evaluates the two XPath expressions and the selected nodes are copied to the output:
<HILTON method="buy"/>
<TON method="burn"/>
<SHERATON method="visit"/>
==========
<HILTON method="buy"/>
The first expression selects all elements - children of the context node, whose name ends with "TON" and that also have a method attribute.
The second expression selects the first node from those, selected by the first expression.

Linq to XML returns no items when there are items in the XML

I am trying to query some XML data using Linq because it's easier than using XPath and as a good "proof of concept" for my co-workers as to how we can use Linq. Here is my XML:
<Booking>
<ServiceCollection>
<Service>
<BookingID>10508507</BookingID>
<AdditionalChargeID>1</AdditionalChargeID>
<ServiceName>Fuel Surcharge</ServiceName>
<ServiceCost>56.87</ServiceCost>
<ServiceCharge>103.41</ServiceCharge>
<showInNotes>0</showInNotes>
<showInHeader>0</showInHeader>
<BOLHeaderText />
</Service>
<Service>
<BookingID>10508507</BookingID>
<AdditionalChargeID>2</AdditionalChargeID>
<ServiceName>Lift Gate at Pickup Point</ServiceName>
<ServiceCost>25.00</ServiceCost>
<ServiceCharge>42.00</ServiceCharge>
<showInNotes>1</showInNotes>
<showInHeader>1</showInHeader>
<BOLHeaderText>Lift Gate at Pickup Point</BOLHeaderText>
</Service>
</ServiceCollection>
</Booking>
Now, here is my C# code (ignore the Conversions class; they simply make sure a default value is returned if the item is null):
var accessorials = from accessorial in accessorialsXml.Elements("ServiceCollection").Elements("Service")
select new Accessorial
{
BookingID = Conversions.GetInt(accessorial.Element("BookingID").Value),
Name = accessorial.Element("ServiceName").Value,
Cost = Conversions.GetDecimal(accessorial.Element("ServiceCost").Value),
Charge = Conversions.GetDecimal(accessorial.Element("ServiceCharge").Value),
ShowInNotes = Conversions.GetBool(accessorial.Element("showInNotes").Value),
ShowInHeader = Conversions.GetBool(accessorial.Element("showInheader").Value),
BillOfLadingText = accessorial.Element("BOLHeaderText").Value
};
return accessorials.ToList();
I have a Unit test which is failing because the count of accessorials (the "Service" node in the XML) is 0 when it should be 2. I tested out this same code in LinqPad (returning an anonymous class instead of an actual entity) and it is returning the proper number of values, yet the code here returns no objects.
Any ideas?
The bug may lie in how you're getting accessorialsXml in the first place. Try outputting the contents of this object before doing the query, to make sure it's exactly the same as the string you're using in LINQPad.