private static void checkForDefaultInstances(Widget w) { for (DefaultInstance di : w.getDefaultInstances()) { if (!defaultExists(di)) { WidgetInstance.createFromDefault(di); } } }
public static boolean defaultExists(DefaultInstance i) { String key = "WidgetManager-default-" + i.generator + "-exists"; if (Cache.get(key) != null) return true; WidgetInstance wi = WidgetInstance.find("byGenerator", i.generator).first(); if (wi != null) Cache.set(key, true, "1h"); return (wi != null); }
public static List<String> deleteInvalidInstances() { List<WidgetInstance> all = WidgetInstance.findAll(); List<String> deleted = new ArrayList(); for (WidgetInstance w : all) { try { w.getWidget(); } catch (InvalidWidgetException e) { deleted.add(w.name + " (" + w.getProvider() + ")"); Logger.info("Removing instance of invalid widget:" + w.getProvider()); w.delete(); } } return deleted; }