Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
We have a small Windchill customization created by a PTC consultant several years ago. This customization is called from ThingWorx with a wtpart ID. The customization collects representations of the wtpart and copies the content (typically PDF files) to a folder on the Windchill server to make it available to ThingWorx. The customization does a few things to get ApplicationData objects from the wtpart, then uses the ApplicationData object in a call to ContentServerHelper.service.writeContentStream() to download the file(s).
I'm using an OData endpoint in ThingWorx to get all the information I need about the representations, so I want to modify the Windchill customization to simply (hopefully) obtain a file given an ID like OR:wt.content.ApplicationData:12125968441. I'm assuming there is a way I can get the ApplicationData object from the ID string, then use the existing code to obtain the file.
My question is: In the Windchill API, how can I get the ApplicationData object from an ID string like "OR:wt.content.ApplicationData:12125968441"?
Here's what I've tried, and it's throwing an exception because I can't cast ApplicationData to ContentHolder. I really don't know what I'm doing here, just taking a stab at it.
ReferenceFactory rf = new ReferenceFactory();
WTReference reference = (WTReference) rf.getReference(objRef); // objRef is like "OR:wt.content.ApplicationData:12125968441"
ContentHolder holder = ContentHelper.service.getContents((ContentHolder) reference.getObject());
ApplicationData appData = ApplicationData.newApplicationData(holder);
Thanks for any advice.
Solved! Go to Solution.
I haven't worked with WTReference too much it appears you have a ApplicationData object not a ContentHolder. Your getObject should return the ApplicationData directly. I have a similar download program which from a Doc or CADdoc (both of which are ContentHolders), you can use wt.content.ContentHelper to get the ApplicationData objects associated. Now, there can be many ApplicationData objects linked to a content holder. In the case of docs, there is primary and attachments. Here is a snipit:
ContentHolder ch = (ContentHolder)ContentHelper.service.getContents(doc);
if (type.equals("PRIMARY"))
{
ApplicationData ad = (ApplicationData)ContentHelper.getPrimary((FormatContentHolder)ch);
url = ContentHelper.getDownloadURL(ch, ad, false).toString();
break;
}
else
{
if (filename == null)
break; //cannot search for right file
Vector files=ContentHelper.getApplicationData(ch);
Iterator it=files.iterator();
while (it.hasNext())
{
ApplicationData ad=(ApplicationData)it.next();
if (ad.getFileName().equals(filename))
{
url = ContentHelper.getDownloadURL(ch, ad, false).toString();
break;
}
}
break;
}
I haven't worked with WTReference too much it appears you have a ApplicationData object not a ContentHolder. Your getObject should return the ApplicationData directly. I have a similar download program which from a Doc or CADdoc (both of which are ContentHolders), you can use wt.content.ContentHelper to get the ApplicationData objects associated. Now, there can be many ApplicationData objects linked to a content holder. In the case of docs, there is primary and attachments. Here is a snipit:
ContentHolder ch = (ContentHolder)ContentHelper.service.getContents(doc);
if (type.equals("PRIMARY"))
{
ApplicationData ad = (ApplicationData)ContentHelper.getPrimary((FormatContentHolder)ch);
url = ContentHelper.getDownloadURL(ch, ad, false).toString();
break;
}
else
{
if (filename == null)
break; //cannot search for right file
Vector files=ContentHelper.getApplicationData(ch);
Iterator it=files.iterator();
while (it.hasNext())
{
ApplicationData ad=(ApplicationData)it.next();
if (ad.getFileName().equals(filename))
{
url = ContentHelper.getDownloadURL(ch, ad, false).toString();
break;
}
}
break;
}
Ah yes, I was overlooking the obvious - the getObject indeed returns the ApplicationData object I was looking for. Thanks for your help!