For anyone who's interested..this is what I ended up doing(only works for AND
queries for now for non-repeating fields in query)..at least good for POC.
Basically, I re-used same queryItem object. I know its an ugly duckling
:(...will see if I can make it better.
qualMap- Map that contains key/value (e.g.'Type'="ABC", 'Type' is key and "ABC"
is value))
CMDBQueryQualifierSimpleOp[] simpleQuery = new
CMDBQueryQualifierSimpleOp[qualMap.size()];
int i = 0;
for (Map.Entry<String, String> map : qualMap.entrySet())
{
simpleQuery[i] = new
CMDBQueryQualifierSimpleOp(CMDBQueryQualifierSimpleOp.CMDB_QUERY_QUAL_OP_EQUAL,
map.getKey(), new CMDBQueryQualifierValueTypeValue(new
Value(Integer.parseInt(map.getValue()))));
i++;
}
CMDBQueryQualifierOpAnd cf3 = null;
CMDBQueryItem queryItem2 = null;
if (qualMap.size() > 1)
{
for (int j = 0; j < qualMap.size(); j++)
{
if (j % 2 == 0)
{
if (cf3 == null)
{
cf3 = new CMDBQueryQualifierOpAnd(simpleQuery[j],
simpleQuery[j + 1]);//0,1
} else
{
cf3 = new CMDBQueryQualifierOpAnd(cf3, simpleQuery[j]);
}
}
}
queryItem2 = new CMDBQueryItem(destination, destinationClassId,
cf3, resultSetAttributes);
} else
{
queryItem2 = new CMDBQueryItem(destination, destinationClassId,
simpleQuery[0], resultSetAttributes);
}
Thanks
Chintan.
--- On Thu, 4/11/13, Chintan Shah <[email protected]> wrote:
From: Chintan Shah <[email protected]>
Subject: CMDB Graph API question(food for thought?..maybe)
To: "ARSList" <[email protected]>
Date: Thursday, April 11, 2013, 7:10 PM
Hi List,
I am wondering if anyone has encountered this before or not.
I was going through Javadoc of CMDB API and came across the class
"CMDBQueryQualifier" which is one of the crucial classes involved in getting
Graph API to work.
CMDBQueryItem(CMDBClassNameKey classNameKey,
java.lang.String id,
CMDBQueryQualifier constraint,
java.util.ArrayList<java.lang.String> contentSelector)
Now,
Direct Known Subclasses of CMDBQueryQualifier are
CMDBQueryQualifierAndOr, CMDBQueryQualifierOpNot, CMDBQueryQualifierSetOp,
CMDBQueryQualifierSimpleOp
and CMDBQueryQualifierAndOr has the followingDirect Known Subclasses:
CMDBQueryQualifierOpAnd, CMDBQueryQualifierOpOr
CMDBQueryQualifierOpAnd needs a right and left operand to work.
CMDBQueryQualifierOpAnd(CMDBQueryQualifier leftOp,
CMDBQueryQualifier rightOp)
Constructs a CMDBQueryQualifierOpAnd object using the left
and right operands.This is extremely tedious because for a simple query(like
below) involving 2 operands, I have to do this
e.g 'ABC'=5 AND 'PQR'=0
CMDBQueryQualifierSimpleOp cf1 = new
CMDBQueryQualifierSimpleOp(CMDBQueryQualifierSimpleOp.CMDB_QUERY_QUAL_OP_EQUAL,
"ABC", new CMDBQueryQualifierValueTypeValue(new Value(5)));
CMDBQueryQualifierSimpleOp cf2 = new
CMDBQueryQualifierSimpleOp(CMDBQueryQualifierSimpleOp.CMDB_QUERY_QUAL_OP_EQUAL,
"DEF", new CMDBQueryQualifierValueTypeValue(new Value(0)));
CMDBQueryQualifierOpAnd cf3 = new CMDBQueryQualifierOpAnd(cf1, cf2);
CMDBQueryItem queryItem2 = new CMDBQueryItem(destination,
destinationClassId, cf3, resultSetAttributes);
What
if key/value pairs in qualification increases? How do we deal with not going
through pain of creating new objects every time qualification is changed?
e.g. ('ABC'=5 AND 'PQR'=0) AND ( 'JKL'=8 AND 'RST'=10)
Now, I need to create 4 more objects:1. simple query for JKL that does (JKL=8)
2. simple query for RST that does (RST=10)
3. QueryQualifier AND for representing left and right side (JKL=8 AND RST=10)4.
To represent AND operation between #3 and (ABC=5 AND PQR=0)( variable cf3 in
code above)
Am I missing anything or not looking at correct place, because I cant find my
way out of using CMDBQueryQualifier constraint. It would have been much easier
if API would just accept a String as the constraint or maybe something like
below:
Constructor:
CMDBQueryQualifierOpAnd(ArrayList<CMDBQueryQualifierSimpleOp>)
The implementation of this constructor should automatically add AND between
each SimpleOp object.
Actually, core QualifierInfo object would have made the job much easier.
QualifierInfo qualByQuery = context.parseQualification(..);
Thoughts? How can we overcome this tedious behavior?
I spent good amount of time looking at this, but hey, if anything is obvious
and I missed it, please pardon me.
ThanksChintan.
_______________________________________________________________________________
UNSUBSCRIBE or access ARSlist Archives at www.arslist.org
"Where the Answers Are, and have been for 20 years"