Hi -
I am trying to configure the icon for a vCACCAFE:CatalogItem (vCACCAFECatalogItem) from a workflow in vCO, using vCACCAFECatalogIconService. I've got a workflow that has the vCACCAFE:VCACHost, the CatalogItem and a vCO ResourceElement as input parameters, and it does the following javascript:
function stringToBytes ( str ) {
var ch, re = [];
for (var i = 0; i < str.length; i++ ) {
ch = str.charCodeAt(i); // get char
re[i] = ( ch & 0xFF ); // push byte to stack
}
// return an array of bytes
return re;
}
// get the image bytes of the ResourceElement
var mime = resource.getContentAsMimeAttachment(), content;
System.log('Name: ' + mime.name);
System.log('MimeType: ' + mime.mimeType);
// mime.content says it's a string.
// we need to convert to a byte array, or the
// vCACCAFEIcon.setImage() call below will cause a
// 'Data Serialization error'
var s = mime.content;
System.log('Read ' + s.length + ' string');
content = stringToBytes(s);
// these do show the right # of bytes
System.log('Found ' + content.length + ' bytes');
System.log('Content:' + (typeof content));
var iconsvc = host.createCatalogClient().getCatalogIconService(),
itemsvc = host.createCatalogClient().getCatalogAdminCatalogItemService(),
icon = new vCACCAFEIcon();
System.log('Creating icon object...');
icon.setContentType(resource.mimeType);
icon.setFileName(resource.name);
icon.setId(item.getId());
System.log('Setting image...');
icon.setImage(content);
// not sure if org is needed or correct...
System.log('Setting org...');
var org = new vCACCAFECatalogOrganizationReference();
org.setTenantRef(host.tenant);
icon.setOrganization(org);
System.log('Create or update icon ' + icon.getId());
var uri = iconsvc.createOrUpdateIcon(icon);
System.log('Icon uri: ' + uri);
item.setIconId(icon.getId());
itemsvc.updateCatalogItem(item);
It appears to create the icon in the icon service and updates the catalog item iconId, but the icon then doesn't render in the UI. The browser says that it's coming back as 51 or 52 (gzipped) bytes, even though our workflow log says that the content variable is the correct # of bytes (3415 in my case). At one point, in Firebug, I saw that the body of the http response for the icon was actually coming back as a line of javascript, but I can't get to it anymore.
I'm guessing it's something to do with string vs. byte[] and/or automatic argument conversion happening between the javascript engine and the vcaccafe java code and the vcac rest endpoint.
Any ideas are welcome.
Thanks,
Greg