How to include child classes in OQL query in ewam? - ewam

I have a parent class for eg say A and it has 4 child classes say B,C,D and E. All the child classes are persistent. However, when I write the query as below the child classes are not picked up by my query.
OQL select * from A using the cursor
Do I have to write individual query for each child class?

Use of ++
Look through all instances of the class as well as all instances of the class’s decedents. (include all child classes in the search)
++
Examples:
forEach curCar in OQL select * from x in aVehicle++
where x.Color = cRed
curCar.Price += 100
endFor
forEach curPerson in OQL select * from x in aPerson++
where x.myAddress.City like ‘%New ‘ Order by x.Name
WriteLn(curPerson)
endFor
Please also see wTECH101 day 5 "101A-OQL-Search.pptx" as well as
eWAM help - search for OQL

Related

Finding children of IfcBuildingStorey using ifcopenshell

By using ifchopenshell I can easily traverse all storeys using this code
for ifc_storey in ifc_file.by_type("IfcBuildingStorey"):
print(str(ifc_storey.Name))
However, for each storey I would like to find all the Ifc elements of type IfcSpace, that belongs to it.
How can I query this? Thank you.
I finally solved it using this code:
def getChildrenOfType(ifcParentElement,ifcType):
items=[]
if type(ifcType) != list:
ifcType=[ifcType]
_getChildrenOfType(items,ifcParentElement,ifcType,0)
return items
def _getChildrenOfType(targetList,element,ifcTypes,level):
# follow Spatial relation
if (element.is_a('IfcSpatialStructureElement')):
for rel in element.ContainsElements:
relatedElements = rel.RelatedElements
for child in relatedElements:
_getChildrenOfType(targetList,child, ifcTypes, level + 1)
# follow Aggregation Relation
if (element.is_a('IfcObjectDefinition')):
for rel in element.IsDecomposedBy:
relatedObjects = rel.RelatedObjects
for child in relatedObjects:
_getChildrenOfType(targetList,child, ifcTypes, level + 1)
for typ in ifcTypes:
if (element.is_a(typ)):
targetList.append(element)

cts search to test if the element is not available

Below is the XML structure where I want to get the entries for which element co:isbn is not available:-
<tr:trackingRecord xmlns:tr="https://www.mla.org/Schema/Tracking/tr"
xmlns:co="https://www.mla.org/Schema/commonModule/co"
xmlns:r="http://www.rsuitecms.com/rsuite/ns/metadata">
<tr:journal>
<tr:trackingDetails>
<tr:entry>
<co:trackingEntryID>2015323313</co:trackingEntryID>
<co:publicationDate>2015</co:publicationDate>
<co:volume>21</co:volume>
</tr:entry>
<tr:entry>
<co:trackingEntryID>2015323314</co:trackingEntryID>
<co:publicationDate>2015</co:publicationDate>
<co:isbn>
<co:entry>NA</co:entry>
<co:value>1234567890128</co:value>
</co:isbn>
</tr:entry>
<tr:entry>
<co:trackingEntryID>2015323315</co:trackingEntryID>
<co:publicationDate>2015</co:publicationDate>
<co:volume>21</co:volume>
<co:isbn></co:isbn>
</tr:entry>
<tr:entry>
<co:trackingEntryID>2015323316</co:trackingEntryID>
<co:publicationDate>2015</co:publicationDate>
<co:volume>21</co:volume>
</tr:entry>
</tr:trackingDetails>
</tr:journal>
</tr:trackingRecord>
Please suggest the cts:query for the same.
If you can edit xml structure, add one attribute in entry element, like
<tr:entry isbnPresent="yes"> for isbn present,
<tr:entry isbnPresent="no"> for isbn absent
and based on these field fire search with,
cts:element-attribute-value
on it.
OR
without editing schema, try like, ,
for $i in cts:search(//tr:entry,"2015")
return if(fn:exists($i//co:isbn)) then () else $i

Getting the level x value of the currentmember in a parent-child hierarchy in MDX

I have an employee parent-child hierarchy in a dimension called Employees which shows the managerial structure of an organisation. This hierarchy is [Employees].[Managerial].
There is another hierarchy that lists all the employees for an organisation. This is a single level hierarchy and it is [Employess].[All Employees].
I have a query that looks something like this:
With
Member measures.[FullTimeSalary] as measures.[Salary] * measures.[FullTimeFactor]
Select {measures.[FullTimeSalary]} on 0,
Non empty
{
[Employess].[All Employees].[All].Children
}
On 1
From MyCube
Where ([Time].[Month].&[201501])
Now if I expand the parent-child hierarchy (the [Employees].[Managerial] hierarchy) I can see each of the different levels of this structure( [Level 02], [Level 03], [Level 04], ect) and what I need to do now is create a new calculated measure called measures.[SupervisingManager] that brings back the currentmembers value at [Level 03] of the hierarchy.
I've tried
member measures.[SupervisingManager] as [Employees].[Managerial].[Level 03].currentmember.member_name
but that just returns "#Error" and using
member measures.[SupervisingManager] as [Employees].[Managerial].currentmember.member_name
returns that currentmember. I also experimented with
measures.[SupervisingManager] as [Employees].[Managerial].currentmember.parent.member_name
but the issue with this is that the currentmember can be located at any within the hierarchy. The only way I can think of doing this is to do a massive case statement, get the ordinal value of the current member and use the appropriate .parent.parent logic. Is there a neater way to do this?
Maybe something along these lines will help:
WITH
MEMBER measures.[FullTimeSalary] AS
measures.[Salary] * measures.[FullTimeFactor]
MEMBER measures.[SupervisingManager] AS
IIF
(
[Employees].CurrentMember.Parent.Level.Name = 'Level 03'
,[Employees].CurrentMember.Parent.Member_Caption
,'n/a'
)
SELECT
{
measures.[FullTimeSalary]
,measures.[SupervisingManager]
} ON 0
,NON EMPTY
{[Employess].[All Employees].[All].Children} ON 1
FROM MyCube
WHERE
[Time].[Month].&[201501];

cannot find the correct syntax for this

I have a row in the table:
//*[contains(text(), 'Cape Town')]
and the delete graphic:
//*[contains(#id, 'DeleteLinkButton')]
in the table.
How do I click on //*[contains(#id, 'DeleteLinkButton')] of row //*[contains(text(), 'Cape Town')]?
If you want to find a node with XPath in relation to another node then in most cases you don't want to use an absolute path starting with / or even //, instead you would use a relative path like .//*[contains(#id, 'DeleteLinkButton')] as that would find descendants of the context node where the id attribute value contains DeleteLinkButton.
So with Javascript in the browser you would have e.g.
var myRow = ...;
and then you could call
myRow.ownerDocument.evaluate('.//*[contains(#id, 'DeleteLinkButton')]', myRow, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();

Parsing images via nokogiri and xpath

I currently have a piece of code which will grab a product title, description, and price and for that it works great. However, I also need it to get the image URL which is where my dilemma is. I tried using a xpath inside the loop I have at the bottom and it lists out ALL the images that are equal to 220 on EVERY product which I dont want at all. So basically I get something like this....
product 1 Title here
product 1 Description here
product 1 price here
http://www.test.com/product1.jpg
http://www.test.com/product2.jpg
http://www.test.com/product3.jpg
http://www.test.com/product4.jpg
product 2 Title here
product 2 Description here
product 2 price here
http://www.test.com/product1.jpg
http://www.test.com/product2.jpg
http://www.test.com/product3.jpg
http://www.test.com/product4.jpg
Where as I obviously want product 1 to just have http://www.test.com/product1.jpg and product 2 to have http://www.test.com/product2.jpg etc, etc. The images are just in a div tag with no class or ID hence why I didnt just easily put them into a css selector. Im really new to ruby/nokogiri so any help would be great.
require 'nokogiri'
require 'open-uri'
url = "http://thewebsitehere"
data = Nokogiri::HTML(open(url))
products = data.css('.item')
products.each do |product|
puts product.at_css('.vproduct_list_title').text.strip
puts product.at_css('.vproduct_list_descr').text.strip
puts product.at_css('.price-value').text.strip
puts product.xpath('//img[#width = 220]/#src').map {|a| a.value }
end
Try changing:
puts product.xpath('//img[#width = 220]/#src').map {|a| a.value }
to:
puts product.xpath('.//img[#width = 220]/#src').map {|a| a.value }
The point of the '.' there is to say you want all images that are children of the current node (e.g. so you're not peeking at product 2's images).
File#basename will return only the filename:
File.basename('http://www.test.com/product4.jpg')
#=> "product4.jpg"
So you probably want something like this:
puts product.xpath('//img[#width = 220]/#src').map {|a| File.basename(a.value) }

Resources