* @param idKey
* @param properties
* @return
*/
private IWidgetInstance addNewWidgetInstance(IPersistenceManager persistenceManager, String api_key, String userId, String sharedDataKey, IWidget widget, String nonce, String idKey, Configuration properties, String lang) {
IWidgetInstance widgetInstance = persistenceManager.newInstance(IWidgetInstance.class);
widgetInstance.setUserId(userId);
widgetInstance.setSharedDataKey(sharedDataKey);
widgetInstance.setIdKey(idKey);
widgetInstance.setNonce(nonce);
widgetInstance.setApiKey(api_key);
if (LocalizationUtils.isValidLanguageTag(lang)) widgetInstance.setLang(lang);
// set the defaults widget for this type
widgetInstance.setWidget(widget);
widgetInstance.setHidden(false);
widgetInstance.setShown(true);
widgetInstance.setUpdated(false);
widgetInstance.setLocked(false);
// Setup opensocial token if needed
widgetInstance.setOpensocialToken(""); //$NON-NLS-1$
if (properties.getBoolean("opensocial.enable")){ //$NON-NLS-1$
try {
if (properties.getString("opensocial.token").equals("secure")){ //$NON-NLS-1$ //$NON-NLS-2$
widgetInstance.setOpensocialToken(OpenSocialUtils.createEncryptedToken(widgetInstance,properties.getString("opensocial.key"), localizedMessages)); //$NON-NLS-1$
}
else {
widgetInstance.setOpensocialToken(OpenSocialUtils.createPlainToken(widgetInstance, localizedMessages));
}
} catch (Exception e) {
_logger.error(e.getMessage());
}
}