@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="UL_UNRELEASED_LOCK_EXCEPTION_PATH", justification="This appears to be doing exactly the right thing with the finally-clause to release the lock") public PortletConfiguration addGadget(final Long pageId, final Long portletConfigurationId, final Integer column, final Integer row, final URI gadgetXml, final Color color, final Map<String, String> userPreferences) { return addDashboardItem(pageId, portletConfigurationId, column, row, Option.some(gadgetXml), color, userPreferences, Option.<ModuleCompleteKey>none()); }
@EventListener public void onClearCache(final ClearCacheEvent event) { this.flush(); }
@Override public List<PortletConfiguration> getByPortalPage(final Long portalPageId) { notNull("portalPageId", portalPageId); final List<Long> configIds = cacheByPageId.get(portalPageId); final ArrayList<PortletConfiguration> returnList = new ArrayList<PortletConfiguration>(configIds.size()); for (final Object element : configIds) { final Long id = (Long) element; final PortletConfiguration portletConfiguration = getByPortletId(id); if (portletConfiguration != null) { returnList.add(portletConfiguration); } } return returnList; }
@Override public PortletConfiguration getByPortletId(final Long portletId) { notNull("portletId", portletId); final CacheObject<PortletConfiguration> portletConfigurationCacheObject = cacheById.get(portletId); return portletConfigurationCacheObject != null ? copyConfiguration(portletConfigurationCacheObject.getValue()) : null; }
void updateGadgetConfigurations(final List<Long> fieldsToConvertToSystem) throws GenericEntityException { final List<GenericValue> labelsGadgetGVs = ofBizDelegator.findByLike(OfbizPortletConfigurationStore.TABLE, MapBuilder.singletonMap(OfbizPortletConfigurationStore.Columns.GADGET_XML, LABEL_GADGET)); final List<Long> labelGadgetIds = CollectionUtil.transform(labelsGadgetGVs, GenericValueFunctions.getLong(OfbizPortletConfigurationStore.Columns.ID)); if (!labelGadgetIds.isEmpty()) { final EntityCondition entityCondition = new EntityConditionList(Arrays.asList(new EntityExpr(OfbizPortletConfigurationStore.UserPreferenceColumns.PORTLETID, EntityOperator.IN, labelGadgetIds), new EntityExpr(OfbizPortletConfigurationStore.UserPreferenceColumns.KEY, EntityOperator.EQUALS, "fieldId")), EntityOperator.AND); final List<GenericValue> userPrefGVs = ofBizDelegator.findByCondition(OfbizPortletConfigurationStore.USER_PREFERENCES_TABLE, entityCondition, null); for (GenericValue userPrefGV : userPrefGVs) { final String value = userPrefGV.getString(OfbizPortletConfigurationStore.UserPreferenceColumns.VALUE); final Long id = CustomFieldUtils.getCustomFieldId(value); if (id != null && fieldsToConvertToSystem.contains(id)) { userPrefGV.setString(OfbizPortletConfigurationStore.UserPreferenceColumns.VALUE, IssueFieldConstants.LABELS); userPrefGV.store(); } } //finally swap over to the new system gadget! ofBizDelegator.bulkUpdateByPrimaryKey(OfbizPortletConfigurationStore.TABLE, MapBuilder.singletonMap(OfbizPortletConfigurationStore.Columns.GADGET_XML, NEW_LABEL_GADGET), labelGadgetIds); cachingPortletConfigurationStore.onClearCache(null); } }
@Override public PortletConfiguration addDashboardItem(final Long pageId, final Long portletConfigurationId, final Integer column, final Integer row, final Option<URI> openSocialSpecUri, final Color color, final Map<String, String> userPreferences, final Option<ModuleCompleteKey> moduleKey) { notNull("pageId", pageId); notNull("column", column); notNull("row", row); notNull("userPreferences", userPreferences); notNull("color", color); PortletConfiguration returnConfig = null; try { returnConfig = delegateStore.addDashboardItem(pageId, portletConfigurationId, column, row, openSocialSpecUri, color, userPreferences, moduleKey); } finally { if (returnConfig != null) { // Remove the cached page as this will now be stale and not contain the new entry. cacheByPageId.remove(returnConfig.getDashboardPageId()); } } return copyConfiguration(returnConfig); }
@Override public void doUpgrade(final boolean setupMode) throws Exception { try { final DateTime startedAt = new DateTime(); int deletedGadgets = Delete.from(GADGET_TABLE).whereLike(GADGET_URI_COLUMN, BUGZILLA_GADGET_URI).execute(ofBizDelegator); log.debug(String.format("Upgrade task took %d seconds to remove %d bugzilla gadgets.", Seconds.secondsBetween(startedAt, new DateTime()).getSeconds(), deletedGadgets)); } finally { // making sure the portlet cache is cleared before a user renders an existing dashboard cachingPortletConfigurationStore.flush(); } } }
@Override public void doUpgrade(boolean setupMode) throws Exception { final EntityExpr condition = new EntityExpr(OfbizPortletConfigurationStore.Columns.GADGET_XML, EntityOperator.LIKE, INTRO_GADGET_XML); OfBizListIterator gadgetsIterator = delegator.findListIteratorByCondition(OfbizPortletConfigurationStore.TABLE, condition); try { for (GenericValue row : gadgetsIterator) { row.set(OfbizPortletConfigurationStore.Columns.MODULE_KEY, INTRO_DASHBOARD_ITEM_KEY); delegator.store(row); } } finally { cachingPortletConfigurationStore.flush(); gadgetsIterator.close(); } }
@Override public void doUpgrade(final boolean setupMode) throws Exception { try { Delete.from(OfbizPortletConfigurationStore.TABLE) .whereLike(OfbizPortletConfigurationStore.Columns.MODULE_KEY, ADMIN_DASHBOARD_ITEM_KEY) .execute(ofBizDelegator); Delete.from(OfbizPortletConfigurationStore.TABLE) .whereLike(OfbizPortletConfigurationStore.Columns.GADGET_XML, ADMIN_GADGET_XML) .execute(ofBizDelegator); } finally { cachingPortletConfigurationStore.flush(); } }