try {
// Reads plugin status from datastore and clear plugin datastore
for (final JSONObject oldPluginDesc : persistedPlugins) {
final String descId = oldPluginDesc.getString(Keys.OBJECT_ID);
final AbstractPlugin plugin = get(plugins, descId);
pluginRepository.remove(descId);
if (null != plugin) {
final String status = oldPluginDesc.getString(Plugin.PLUGIN_STATUS);
final String setting = oldPluginDesc.optString(Plugin.PLUGIN_SETTING);
plugin.setStatus(PluginStatus.valueOf(status));
try {
if (StringUtils.isNotBlank(setting)) {
plugin.setSetting(new JSONObject(setting));
}
} catch (final JSONException e) {
LOGGER.log(Level.WARN, "the formatter of the old config failed to convert to json", e);
}
}
}
// Adds these plugins into datastore
for (final AbstractPlugin plugin : plugins) {
final JSONObject pluginDesc = plugin.toJSONObject();
pluginRepository.add(pluginDesc);
LOGGER.log(Level.TRACE, "Refreshed plugin[{0}]", pluginDesc);
}