Hi! I'm trying to write code that will do two things:
- Get a list of the aspects in the docbase
- For each aspect, get the attributes defined (attribute name, type, is repeating, max length)
Getting a list of the aspects is easy - just query the dmc_aspects table. However, I'm having problems trying to get the aspect attributes. I've tried a few methods to get this to work, but I haven't found the perfect solution yet. Perhaps I'm missing something. Here's what I've tried so far. The code below is a mix of actual java code and pseudocode.
Get an IDfType for the Aspect
I figured this was a longshot, but I was hoping that the DFC treated aspects just like types. No such luck. This code runs, but doesn't give me what I want:
IDfPersistentObject obj = session.getObject(new DfId(<the-dmc_aspect-object-id>));IDfType aspectType = obj.getType();//getName() returns the aspect name//getAttrCount() and getAttr(i) return values, but they're not the aspect attributes
Inspect the i_attr_def object
The actual aspect attribute values are stored in the object defined by the i_attr_def on the dmc_aspect object. So, I figured maybe I could get to the attribute definintions that way. Unfortunately, in my docbase anyway, normal users cannot query this table. For some reason, even dmadmin cannot query the table. I can run a describe query on the table in dqMan or Samson, but that doesn't help me much because you can't run a describe query using DFC. I tried, but it throws a query parser syntax error.
I also tried running code like this:
String describeString = session.describe("TYPE", "dmi_030000018000023c");
This works. However, it's a string so there would be really messy string parsing involved. Plus, it looks like it doesn't contain whether or not the attribute is repeating. Even if it did, I'd be leery of using this because of the string parsing.
Data Dictionary
I thought that maybe the aspect attributes are stored in the data dictionary in the same way that normal type attributes are, but again no luck. These queries all return no results:
select * from dmi_dd_type_info where type_name = 'my_aspect';select * from dmi_dd_attr_info where type_name = 'my_aspect';select * from dmi_dd_common_info where type_name = 'my_aspect';
Get an object with the aspect
Code like this works:
//Run a query to get the first object with the aspect in the r_aspect_name attribute//get the IDfSysObject for the first result//Iterate over the attributes using getAttrCount()//get each attribute. If the attribute starts with aspectName + "." then get use getAttr(i) to get the attribute. //From here, we can use getName(), getDataType(), isRepeating(), and getLength() to get the information we want
This method works, however there's a big limitation. If you install an aspect, but you don't apply it anywhere, the code won't know about any of the attributes.
Any Ideas?
Please let me know if you have any ideas on a better solution. Of the above, I like the last one the best, but that limitation is a big one. I feel like I have to be missing something. I saw this (unanswered) thread that discusses using the DFS schema service. I'd like to avoid using DFS if possible and stick to DFC/DQL. After all, the DFS just wraps the DFC - so if it's possible via the Schema service, there must be a way to get to the same infomration with DFC, right?
Any ideas? Thanks in advance!
George