Get a count of a linked collection using OData and LINQ - linq

I set up the OData feed for Stack Overflow as outlined in the wonderful article Using LINQPad to Query Stack Overflow and I want to do something like:
Users.Where(x=>x.Badges.Count==0).Take(5)
to get the users that have no Badges ("Badges? We don't need no stinkin' badges!"). I get a DataServiceQueryException:

Unfortunately, OData doesn't support aggregate functions - it supports only the limited set of querying functions described here.
Aggregate operators
All aggregate operations are unsupported against a DataServiceQuery,
including the following:
Aggregate
Average
Count
LongCount
Max
Min
Sum
Aggregate operations must either be performed on the client or be
encapsulated by a service operation.
Hopefully Microsoft will enhance the OData client in the future - it is frustrating to (seemingly) have all the power of LINQ and then not be able to use it.

Looks like Badges doesn't have a Count property. This is why the exception occurred.
<EntityType Name="Badge">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property xmlns:p8="http://schemas.microsoft.com/ado/2009/02/edm/annotation" Name="Id" Type="Edm.Int32" Nullable="false" p8:StoreGeneratedPattern="Identity" />
<Property Name="UserId" Type="Edm.Int32" Nullable="true" />
<Property Name="Name" Type="Edm.String" Nullable="true" MaxLength="50" Unicode="true" FixedLength="false" />
<Property Name="Date" Type="Edm.DateTime" Nullable="true" />
<NavigationProperty Name="User" Relationship="MetaModel.BadgeUser" FromRole="Badge" ToRole="User" />
</EntityType>
Probably you'd need to process each User to check whether the Badges navigation property resolves to anything.

Filtering on count of entities in navigation properties is currently not supported (as already noted by Joe Albahari above). In the latest CTP OData supports any and all functions which would allow you to filter on "empty" navigation properties.
See
http://blogs.msdn.com/b/astoriateam/archive/2011/10/13/announcing-wcf-data-services-oct-2011-ctp-for-net-4-and-silverlight-4.aspx to get the latest CTP.
Here is a discussion of the any/all feature:
http://www.odata.org/blog/even-more-any-and-all

Related

Crawl image and their metadata using nutch and index them into solr

I want to build a mini image based search engine to which I can provide image file and it will search for similar images in the solr. I'm using nutch for the crawling part and indexing the data into solr. I've done changes into nutch conf files like -
Added image/* into mimetype-filter.txt
Removed image extensions from suffix-urlfilter.txt - not to skip them
I also added fields into solr schema.xml -
<field name="name" type="string" indexed="true" stored="true" />
<field name="iso" type="string" indexed="true" stored="true" multiValued="true" />
<field name="iso_string" type="string" indexed="true" stored="true" multiValued="true" />
<field name="aperture" type="double" indexed="true" stored="true" />
<field name="exposure" type="string" indexed="true" stored="true" />
<field name="exposure_time" type="double" indexed="true" stored="true" />
<field name="focal" type="string" indexed="true" stored="true" />
<field name="focal_35" type="string" indexed="true" stored="true" />
<dynamicField name="ignored_*" type="string" indexed="false" stored="false" multiValued="true" />
But when I crawl, there is no data that is indexed into solr. I'm unable to find any documentation/tutorial regarding this. I've also gone through some posts on stackoverflow for image crawling using nutch. But I didn't find those helpful.
Can someone please guide me to the right direction regarding how to proceed ? Thanks in advance.
There is no easy/short answer for this issue, parsing images is a tricky business, even without involving the crawling part. On top of what you've already done you need first to enable the parse-tika plugin (parse-html only deals with HTML documents). Apache Tika is able to extract some metadata about the images.
You also need to enable the mimetype-filter plugin (this is not only editing the config file but enabling in the nutch-site.xml file). After these configurations are done you should try the bin/nutch parsechecker <URL> tool to test a URL that contains some images and see if you can find the URLs to the images in the Outlinks section. Also, check running the parsechecker against an image URL to see what metadata the parsechecker is extracting. After this, run the bin/nutch indexchecker tool against both URLs and check which fields it is going to index into Solr and create those in your schema accordingly. Keep in mind that Tika may extracty different metadata for each format.

Cocoa Scripting: "whose clause" cannot access certain properties

I am working on making my application scriptable. I struggle with the "whose" filter clause.
I want to make this work, but while name can be used, country can not:
tell application "myapp"
get every city whose name is "Berlin" -- works
get every city whose country is "Germany" -- error -1700 (Can’t make country into type specifier)
end tell
The relevant parts of the sdef look like this:
<class name="application" code="capp">
<cocoa class="NSApplication"/>
<element type="city">
<cocoa key="allCities"/>
<accessor style="index"/>
</element>
<class name="city" code="Citi" plural="cities">
<cocoa class="ScriptableCity"/>
<property name="name" code="pnam" type="text" access="r">
<cocoa key="name"/>
</property>
<property name="country" code="Ctry" type="text" access="r">
<cocoa key="country"/>
</property>
</class>
What must I do to make country work with "whose" as well? Apparently, the "whose" clause wants a type specifier, not a property name, but I can't make sense of this.
I have implemented indicesOfObjectsByEvaluatingObjectSpecifier:, but that only gets called for name, not for country.
Oh, I had it all wrong. My program code is fine. The issue is caused by the fact that I also have a class named country. So AppleScript, looking at the outmost scope for the identifier first, finds the class country and tries to use that for the comparison. Had the error message included the word "class", this would have been easier to detect, probably.
There are now two solutions:
Rename the property in the Sdef so that it does not clash with the class name any more, e.g. to country name.
Use of it in order to change the scope for the lookup of the identifier, like this:
get every city whose country of it is "Germany"
It is also important to make sure that if the same property name is used in several classes, they all use the same 4-char type code. Otherwise this problem can surface as well.

Redeem rate for Freestanding Coupons in Oracle ATG commerce

Any clue on how can I keep a track regarding how many Freestanding Coupons were used in Oracle ATG? I know that for bulk vouchers we have the Redemption Rate, but for the simple vouchers there's no such thing.
For example I created 500 vouchers with the code XXXXX and I want to see how many were used during the checkout.
Cheers
One way to do this would be to use the dyn/admin to query the number of uses for the given voucher code:
Open the ClaimableRepository in dyn/admin http://your-host-name:your-port/dyn/admin/nucleus/atg/commerce/claimable/ClaimableRepository/
In the text area below Run XML Operation Tags on the Repository enter the following:
<print-item item-descriptor="PromotionClaimable" id="my-promotion-id" /> and hit the 'enter' button. This will print something like this:
------ Printing item with id: my-promotion-id
<add-item item-descriptor="DeployablePromotionClaimable" id="my-promotion-id">
<set-property name="expirationDate"><![CDATA[11/26/2015 23:59:00]]></set-property>
<set-property name="displayName"><![CDATA[10% discount on my items]></set-property>
<!-- rdonly derived <set-property name="derivedDisplayName"><![CDATA[10% discount on my items]]></set-property> -->
<set-property name="uses"><![CDATA[4]]></set-property>
<!-- export is false <set-property name="version"><![CDATA[13]]></set-property> -->
<set-property name="lastModified"><![CDATA[10/28/2015 16:18:09]]></set-property>
<set-property name="status"><![CDATA[claimed]]></set-property>
<set-property name="startDate"><![CDATA[8/13/2015 00:00:00]]></set-property>
<!-- rdonly derived <set-property name="hasPromotions"><![CDATA[true]]></set-property> -->
<set-property name="promotions"><![CDATA[promo100001]]></set-property>
<set-property name="type"><![CDATA[DeployablePromotionClaimable]]></set-property>
</add-item>
The line <set-property name="uses"><![CDATA[4]]></set-property> tells you how many times that voucher/coupon has been used, which in this case is 4.
UPDATE:
The above method does not work as it returns the total number of coupons available when the promotion is setup. This means the quickest way to get this information would be to query the completed orders which use the coupon.

Spring webflow: Continue to 'next' state from decision-state

My scenario is this: I need to implement a type of authorization check to be made in multiple flows. Right now one of my flows looks like this:
<flow parent="myparent-flow">
<decision-state id="checkAuthorization">
<if test="bean.notAuthorized"
then="redirectToSomePage"
else="view1" />
</decision-state>
<view-state id="view1" />
<!-- ... -->
</flow>
I need to implement that same authorization check for a number of flows, and while I can copy-paste the same logic everywhere I would really like to, if possible, put this in the parent flow itself, which is already used to execute some logic on-start of each flow.
The problem here is the else-class in the decision-state. Since it is a parent flow to many subflows it will not know the name of the first state in the child flow. I would like to use it as such that it would somehow go ahead and execute the next state in the flow, which exists in the child flow. My optimal solution would be something like this:
<flow> <!-- flow name = myparent-flow -->
<decision-state id="checkAuthorization">
<if test="bean.notAuthorized"
then="redirectToSomeFlow"
else="continueExecutionInChildFlow" />
</decision-state>
<end-state id="redirectToSomeFlow" view="flowRedirect:someFlow" />
</flow>
This would then be defined as parent flow in all my flows so that I don't have to duplicate this logic. Is it possible to do such a thing with Spring?
One possible way to achieve it could be by setting a variable on the specific flow and use this variable for the end-state redirection afterwards, like:
<if test="bean.notAuthorized"
then="redirectToSomeFlow"
else="${conversationScope.resultView}" />
The variable could be set by using:
<set name="conversationScope.resultView" value="'viewName'" />

How to use more than one custom filter invoked after each other?

hi all i am using spring security 3.0.2
and i have one custom filter and its order is last
and i want to add another filter after that filter, is the following config right ?
<custom-filter position="LAST" ref="filter1"/>
<custom-filter after="LAST" ref="filter2"/>
After looking in my own code I noticed that I didn't use the 'ref' attribute, but instead I place this tag inside my bean definition as follow:
<bean id="ntlmFilter" class="org.springframework.security.ntlm.samples.failover.NtlmProcessingFilter">
<sec:custom-filter position="NTLM_FILTER" />
<property name="authenticationManager" ref="authenticationManager" />
<property name="retryOnAuthFailure" value="false" />
<property name="securityConfiguration" ref="securityConfiguration" />
</bean>
Source: http://github.com/aloiscochard/spring-security-ntlm-samples/blob/master/spring-security-ntlm-samples-failover/src/main/resources/applicationContext-security.xml
Even if it's for spring-security 2, the behavior is the same in version 3.
You can find all possible position in the org.springframework.security.config.http.SecurityFilters enumeration:
http://grepcode.com/file/repo1.maven.org/maven2/org.springframework.security/spring-security-config/3.0.2.RELEASE/org/springframework/security/config/http/SecurityFilters.java
You can use some postition already defined in this enumeration to define in which order your custom filters must be set.
For exemple:
one filter before LAST and one at LAST (but not after LAST ! nothing can be after LAST !)
or one filter before SWITCH_USER_FILTER and one after.
Don't know where your are placing your tags ? but I like to have them directly inside the filter bean... easier to maintain :-)
Hope that's help !
PS: Since position are based on integer you can perhaps put number instead of enumeration value (be warn to us correct position number, look at the logic inside the SecurityFilters enumeration), not sure if accepted ...

Resources