public List<PortletConfiguration> getByPortalPage(final Long portalPageId) { notNull("portalPageId", portalPageId); final List<GenericValue> portletConfigsListGVs = delegator.findByAnd(TABLE, ImmutableMap.of(Columns.PORTALPAGE, portalPageId)); final List<PortletConfiguration> portletConfigs = new ArrayList<PortletConfiguration>(portletConfigsListGVs.size()); for (final GenericValue portletConfigGV : portletConfigsListGVs) { portletConfigs.add(createConfigurationFromGv(portletConfigGV)); } return portletConfigs; }
@VisibleForTesting Map<String, String> getUserPreferences(final Long id, final Option<URI> openSocialSpecUri, final Option<ModuleCompleteKey> completeModuleKey) { // according to migration plan in comment // https://ecosystem.atlassian.net/browse/ACJIRA-235?focusedCommentId=146468&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-146468 // At first stage only connect dashboard items i.e. locally rendered dashboard items without replacement URI, // have user preferences in dashboard items' properties. if (isLocalDashboardItemWithoutReplacementUri(openSocialSpecUri, completeModuleKey)) { return getDashboardItemProperties(id); } else { return getOpenSocialGadgetUserPreferences(id); } }
public void delete(final PortletConfiguration pc) { notNull("pc", pc); notNull("pc.id", pc.getId()); final GenericValue gv = getGenericValue(pc); if (gv != null) { removePropertySet(gv); delegator.removeValue(gv); removeDashboardItemProperties(pc); } }
public void updateUserPrefs(final Long gadgetId, final Map<String, String> userPrefs) { notNull("gadgetId", gadgetId); notNull("userPrefs", userPrefs); if (isLocalDashboardItemWithoutReplacementUri(gadgetId)) { updateLocalDashboardItemProperties(gadgetId, userPrefs); } else { updateOpenSocialGadgetUserPreferences(gadgetId, userPrefs); } }
private void updateLocalDashboardItemProperties(final Long gadgetId, final Map<String, String> properties) { removeLocalDashboardItemPreferences(gadgetId); for (Map.Entry<String, String> property : properties.entrySet()) { jsonEntityPropertyManager.put(DASHBOARD_ITEM_PROPERTY.getDbEntityName(), gadgetId, property.getKey(), toJsonString(property.getValue())); } }
private void removeDashboardItemProperties(final PortletConfiguration portletConfiguration) { if (isLocalDashboardItemWithoutReplacementUri(portletConfiguration.getOpenSocialSpecUri(), portletConfiguration.getCompleteModuleKey())) { removeLocalDashboardItemPreferences(portletConfiguration.getId()); } else { removeOpenSocialGadgetPreferences(portletConfiguration.getId()); } }
private boolean isLocalDashboardItemWithoutReplacementUri(long id) { notNull("portletId", id); final List<GenericValue> portletConfigsListGVs = delegator.findByAnd(TABLE, MapBuilder.singletonMap(Columns.ID, id)); if (portletConfigsListGVs.isEmpty()) { throw new IllegalArgumentException("You are trying to update preferences of gadget witch does not exist"); } final GenericValue portletConfigGV = portletConfigsListGVs.get(0); final Option<URI> openSocialSpecUri = Option.option(getGadgetXmlURI(portletConfigGV.getString(Columns.GADGET_XML), id)); final Option<ModuleCompleteKey> completeModuleKey = Option.option(portletConfigGV.getString(Columns.MODULE_KEY)).map(new Function<String, ModuleCompleteKey>() { @Override public ModuleCompleteKey apply(final String input) { return new ModuleCompleteKey(input); } }); return isLocalDashboardItemWithoutReplacementUri(openSocialSpecUri, completeModuleKey); }
private PortletConfiguration createConfigurationFromGv(final GenericValue portletConfigGV) { if (portletConfigGV == null) { return null; } final Long id = portletConfigGV.getLong(Columns.ID); final Option<URI> openSocialSpecUri = Option.option(getGadgetXmlURI(portletConfigGV.getString(Columns.GADGET_XML), id)); final String colorString = portletConfigGV.getString(Columns.COLOR); //legacy portlets may not have a value for these fields final Color gadgetColor = StringUtils.isEmpty(colorString) ? null : Color.valueOf(colorString); final Option<ModuleCompleteKey> completeModuleKey = Option.option(portletConfigGV.getString(Columns.MODULE_KEY)).map(new Function<String, ModuleCompleteKey>() { @Override public ModuleCompleteKey apply(final String input) { return new ModuleCompleteKey(input); } }); final Map<String, String> userPrefs = getUserPreferences(id, openSocialSpecUri, completeModuleKey); return new PortletConfigurationImpl(id, portletConfigGV.getLong(Columns.PORTALPAGE), portletConfigGV.getInteger(Columns.COLUMN), portletConfigGV.getInteger(Columns.ROW), openSocialSpecUri, gadgetColor, userPrefs, completeModuleKey); }
notNull("pc.id", pc.getId()); final GenericValue gv = getGenericValue(pc); if (gv == null) updateUserPrefs(pc.getId(), pc.getUserPrefs(), pc.getOpenSocialSpecUri(), pc.getCompleteModuleKey());
.toMap()); updateUserPrefs(gv.getLong("id"), userPreferences, openSocialSpecUri, moduleKey); return createConfigurationFromGv(gv);
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()); }
private void updateUserPrefs(final Long gadgetId, final Map<String, String> userPrefs, final Option<URI> openSocialSpecUri, final Option<ModuleCompleteKey> moduleKey) { notNull("gadgetId", gadgetId); notNull("userPrefs", userPrefs); if (isLocalDashboardItemWithoutReplacementUri(openSocialSpecUri, moduleKey)) { updateLocalDashboardItemProperties(gadgetId, userPrefs); } else { updateOpenSocialGadgetUserPreferences(gadgetId, userPrefs); } }
public PortletConfiguration getByPortletId(final Long portletId) { notNull("portletId", portletId); final List<GenericValue> portletConfigsListGVs = delegator.findByAnd(TABLE, MapBuilder.singletonMap(Columns.ID, portletId)); if (!portletConfigsListGVs.isEmpty()) { return createConfigurationFromGv(portletConfigsListGVs.get(0)); } else { return null; } }