Get the root level of dimension in Mdx using olap4j Api - mondrian

I have a problem that's really killing me. BTW I am new to Mdx and using olap4j Api to construct MDX Query. My problem is with the root element, Following is the code snippet:
Query myQuery = new Query("Generated Query", sales); // where sales is an object of type cube.
QueryDimension productDimension = myQuery.getDimension("Product");
So now I have an object with dimension Product to use. I want some thing like this [Product].[All Products] to be part of the MdxQuery when I add productDimension to an axis. I can hardcode [All Products] but if the dimensionName passed is other than Product, say Stores it would be an issue. SO what I want is, whether it would be possible to fetch some thing get the names like [All Products] or [All Stores] or [definite Measures] which is equivalent to [All Measures] dynamically using olap4j?
PS: This is a method which takes in a dimension name and returns the first Member of the dimension like [Product].[All Products] if product is passed or [Measures].[All Measures/some Measures] if measures are passed.

I was able to figure out on how to get the root element To get some thing like All Products or basically all member name then I need to do some thing as shown below:
Say, I want the all member name for productDimension[object of type Dimension for product] then,
Member allMember = productDimension.getDimension().getDefaultHierarchy().getRootMembers().get(0);
productDimension.include(Selection.Operator.MEMBER, allMember);
By doing so allMember will be part of the Mdx Query.

Related

geoserver cross-layer cql filter with feature id

I want to get the features of layer A that have intersection with a specific feature in layer B (using the id of the feature in layer B). below is my query:
localhost:8080/geoserver/wms?LAYERS=sf:roads,sf:restricted,sf:bugsites&STYLES=&FORMAT=image/png&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=EPSG:26713&CQL_FILTER=INCLUDE;INCLUDE;INTERSECTS(the_geom, querySingle('sf:restricted', 'the_geom','IN('restricted.4')'))&BBOX=589081.6705629,4914128.1213261,609174.02430924,4928177.0717971&WIDTH=512&HEIGHT=358
but the query cannot be parsed and I receive this error:
finally I fixed it...
I used two single quotations around the id and it works fine :| (one double quotation doesn't work).
INTERSECTS(the_geom, querySingle('sf:restricted', 'the_geom','IN(''restricted.4'')'))
The issue is in the query that gets the feature from the second layer (querySingle('sf:restricted', 'the_geom','IN('restricted.4')'))
The 3rd argument should be the where clause, including the field name and the desired value. As you are looking for a single ID, it could be 'ID=4'
Have a look at the example page, the ID field for sf:restricted is cat
querySingle('sf:restricted', 'the_geom','cat = 4')

Concatenating a LINQ query and LINQ sort statement

I'm having a problem joining two LINQ queries.
Currently, my (original) code looks like this
s.AnimalTypes.Sort((x, y) => string.Compare(x.Type, y.Type));
What I'm needing to do is change this based on a date, then select all data past that date, so I have
s.AnimalTypes.Select(t=>t.DateChanged > dateIn).ToList()
s.AnimalTypes.Sort((…
This doesn't look right as it's not sorting the data selected, rather sorting everything in s.AnimalTypes.
Is there a way to concatenate the two LINQ lines? I've tried
s.AnimalTypes.Select(t=>t.DateChanged > dateIn).ToList().Sort((…
but this gives me an error on the Sort section.
Is there a simple way to do this? I've looked around and Grouo and OrderBy keep cropping up, but I'm not sure these are what I need here.
Thanks
From your description, I believe you want something like:
var results = s.AnimalTypes.Where(t => t.DateChanged > dateIn).OrderBy(t => t.Type);
You can call ToList() to convert to a List<T> at the end if required.
There are a couple of fundamental concepts I believe you are missing here -
First, unlike List<T>.Sort, the LINQ extension methods don't change the original collections, but rather return a new IEnumerable<T> with the filtered or sorted results. This means you always need to assign something to the return value (hence my var results = above).
Second, Select performs a mapping operation - transforming the data from one form to another. For example, you could use it to extract out the DateChanged (Select(t => t.DateChanged)), but this would give you an enumeration of dates, not the original animal types. In order to filter or restrict the list with a predicate (criteria), you'd use Where instead.
Finally, you can use OrderBy to reorder the resulting enumerable.
You are using Select when you actually want to use Where.
Select is a projection from one a collection of one type into another type - you won't increase or reduce the number of items in a collection using Select, but you can instead select each object's name or some other property.
Where is what you would use to filter a collection based on a boolean predicate.

MDX Parameter - SSRS

Parameter Value (It’s Unique Name) = [Company].[Company Hierarchy].&[10]
Parameter Label (It’s Name) = HQ
I want to type in “HQ” and generate report for “[Company].[Company Hierarchy].&[10]”
So, basically, I want to TYPE in label text and transform that somehow so ssrs would generate report for it’s value that matches MDX format [dim].[hierarchy].&[member]
It's kind of hard to explain but how would I go about setting up the parameter and how would I use that parameter for datasets?
Thank you
It is possible to use NameColumn in SSAS.
If you properly set up your Company dimension, you will be able to reach your dimension via its name and not via its key.
[Company].[Company Hierarchy].&[10] (that's the way you get the dimension with the key 10. The key 10 is unique, returning only one member)
[Company].[Company Hierarchy].[HQ] (that's the way you get the dimension with its name. [HQ] in this example might not be unique. Notice that I don't use & this time.)

Trying to execute a WHERE IN: Invalid 'where' condition. An entity member is invoking an invalid property or method

I'm trying to get a list of cases whose AccountID is found in a previous list.
The error occurs on the last line of the following:
// Gets the list of permissions for the current contact
var perms = ServiceContext.GetCaseAccessByContact(Contact).Cast<Adx_caseaccess>();
// Get the list of account IDs from the permissions list
var customerIDs = perms.Select(p => p.adx_accountid).Distinct();
// Get the list of cases that belong to any account whose ID is in the `customerID` list
var openCases = (from c in ServiceContext.IncidentSet where customerIDs.Contains(c.AccountId) select c).ToList();
I'm not sure what the "invalid property" is the error is talking about. The code compiles, I just get the error at runtime.
The problem is the CRM Linq Provider. It doesn't support all of the available options that the Linq-to-objects provider offers. In this case, the CRM does not support the Enumerable.Contains() method.
where:
The left side of the clause must be an attribute name and the
right side of the clause must be a value. You cannot set the left side
to a constant. Both the sides of the clause cannot be constants.
Supports the String functions Contains, StartsWith, EndsWith, and
Equals.
You can work around this in one of two ways:
Rework your query to use a more natural join.
If a join is not possible, you can use Dynamic Linq to generate a list of OR clauses on each item in customerIDs. This would function similarly to Enumerable.Contains.
See my answer or the accepted answer to the question "How to get all the birthdays of today?" for two separate ways to accomplish this.

WCF Data Services - neither .Expand or .LoadProperty seems to do what I need

I am building a school management app where they track student tardiness and absences. I've got three entities to help me in this. A Students entity (first name, last name, ID, etc.); a SystemAbsenceTypes entity with SystemAbsenceTypeID values for Late, Absent-with-Reason, Absent-without-Reason; and a cross-reference table called StudentAbsences (matching the student IDs with the absence-type ID, plus a date, and a Notes field).
What I want to do is query my entities for a given student, and then add up the number of each kind of Absence, for a given date range. I prepare my currentStudent object without a problem, then I do this...
Me.Data.LoadProperty(currentStudent, "StudentAbsences") 'Loads the cross-ref data
lblDaysLate.Text = (From ab In currentStudent.StudentAbsences Where ab.SystemAbsenceTypes.SystemAbsenceTypeID = Common.enuStudentAbsenceTypes.Late).Count.ToString
...and this second line fails, complaining "Object reference not set to an instance of an object."
I presume the problem is that while it DOES see that there are (let's say) four absences for the currentStudent (ie, currentStudent.StudentAbsences.Count = 4) -- it can't yet "peer into" each one of the absences to look at its type. In fact, each of the four StudentAbsence objects has a property called SystemAbsenceType, which then finally has the SystemAbsenceTypeID.
How do I use .Expand or .LoadProperty to make this happen? Do I need to blindly loop through all these collections, firing off .LoadProperty on everything before I can do my query?
Is there some other technique?
When you load the student, try expanding the related properties.
var currentStudent = context.Students.Expand("StudentAbsences")
.Expand("StudentAbsences/SystemAbsenceTypes")
.Where(....).First();

Resources