on 10-10-2006 1:48 PM
Hello MDM Gurus,
I'm having a problem using the Java API for retrieving the attributevalues of a taxonomy table for a specific record. Can anyone tell me how to do it?
With kind regards,
Gerwin
Hi Gerwin,
Can you be more specific? Do you mean to retrieve the linked attributes for a specific record in the main table, or do you wish to retrieve all available attributes for a specific node in a taxonomy table?
Walter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Walter,
Retrieving all available attributes for a specific node is not the problem. The problem is retrieving the values for linked attributes.
So, for instance, if I have a record with Product information, and my Taxonomy-table contains an attribute called "Material Type" and I select the attributevalue "Finished Product", then I would like to be able to retrieve the value "Finished Product".
Hope this clarifies the issue a little bit more.
With kind regards,
Gerwin
OK, let's start. If I am off-track, please let me know :-).
Firstly, there are two ways to get the linked attributes for a specific record:
<u>1. Get the attributes with the ResultSetDefinition</u>
Include the taxonomy field in the ResultSetDefinition and use <b>resultSetDefinition.SetIncludeAttributes(true)</b>. Then, when you have your result set, you can call the function <b>GetAttributes</b>
The AttributeValueExArray is an array of, you guessed it, <b>AttributeValueEx</b>.
Have a look at the API Javadoc, and the official API documentation. Hopefully the above will be enough to get you on your way.
Regards,
Walter
Example:
ResultSetDefinition rsd = new ResultSetDefinition("Products);
rsd.AddField("MyTaxonomyField");
rsd.SetIncludeAttributes(true);
rsd.SetCutoffPriority(100); // or whatever cutoff priority you desire
// add some more fields...
// get the ResultSet
A2iResultSet rs = catalogData.GetResultSet(....;
// Now loop through the result set and read the attributes for each record
for(i = 0; i < rs.GetRecordCount(); i++)
{
AttributeValueExArray avx = rs.GetAttributes(i, "MyTaxonomyField");
// do something with the attributes
}
<u>2. Use the GetLinkedAttributes functions</u>
Using this method can be more efficient than the first method if you do not necessarily want to retrieve the attributes for <i>every</i> record in a ResultSet.
Having got hold of a record ID, you can retrieve its linked attributes at any time by calling the function <b>CatalogData.GetLinkedAttributes</b>.
Example:
AttributeValueExArray avx = myCatalogDataObject.GetLinkedAttributes ("Products", "MyTaxonomyField", 123, 100);
/*
* 123 = recordId
* 100 = cutoff priority
*/
The AttributeValueExArray holds an array of <b>AttributeValueEx</b> objects. Have a look at the MDM API documentation as well as the Javadoc for more information.
Regards,
Walter
Hi Walter,
I already discovered lots of the code you sent me, but anyway thanks for that, because know I know that I am going at least in the right direction. Unfortunately I get stuck at the point where I have to "dismantle" the AttributeValueEx. If I cast it to an AttributeInfo-object, then I'm able to retrieve the attributename, but there's not method for retrieving the value for that attribute. SO, do you know how to proceed and to which object must I cast it in order to get the value?
I thank you in advance,
Gerwin
OK - this is where it starts getting tricky.
The AttributeInfoEx object holds two pieces of information - one with the attribute metadata, and one with the the actual attribute values. The metadata is obtained via the function <b>GetAttributeInfo()</b> which returns an <b>AttributeInfo</b> object. The AttributeInfo object includes, amongst other things, the attribute name and the the attribute type.
An attribute can be one of three types:
Feature (string)
Characteristic (numeric)
Coupled (numeric coupled attribute)
You determine the attribute type by inspecting the value of <b>AttributeInfo.GetType()</b> and comparing it to <b>CMRatingType</b> constants.
Attribute is a FEATURE if
type == CMRatingType.FeatureRating
Attribute is a CHARACTERISTIC if
type == CMRatingType.MinimumRating ||
type == CMRatingType.MaximumRating ||
type == CMRatingType.TypicalRating ||
type == CMRatingType.NominalRating ||
type == CMRatingType.AverageRating
Attribute is a COUPLED NUMERIC if
type > 16
From the Javadoc:
a2i.generated.CMRatingType
public static final byte AverageRating 16
public static final byte FeatureRating 0
public static final byte InvalidRating -1
public static final byte MaximumRating 2
public static final byte MinimumRating 1
public static final byte NominalRating 8
public static final byte TypicalRating 4
Depending on the attribute type, you can now retrieve the attribute values via one of three functions:
FeatureDomain <b>attributeInfoEx.GetFeatures()</b>
AttributeValueArray <b>attributeInfoExGetCharacteristics()</b>
CoupledAttributeValueArray <b>attributeInfoExGetCoupledNumerics()</b>
You can inspect these three objects (FeatureDomain, AttributeValueArray and CoupledAttributeValueArray)in the Javadocs for more info.
Regards,
Walter
Hi Walter,
Thanks for your reply. It solved my problem. I've been trying to reward your last reply, but I keep getting errors. As soon as it works again I'll update the rewards,
Gerwin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.