public GadgetState get(final PortletConfiguration portletConfiguration) { URI gadgetUri = portletConfiguration.getGadgetURI(); if (gadgetUri == null) { gadgetUri = URI.create( "/invalid/legacy/portlet/Please_remove_this_gadget_from_your_dashboard!"); } return GadgetState.gadget(GadgetId.valueOf(portletConfiguration.getId().toString())) .specUri(gadgetUri) .color(portletConfiguration.getColor()) .userPrefs(portletConfiguration.getUserPrefs()) .build(); }
private DashboardState storeDashboardState(final DashboardState dashboardState) { Assertions.notNull("dashboardState", dashboardState); final DashboardId dashboardId = dashboardState.getId(); final long portalPageId = toLong(dashboardId); // check first if the portal page exists! final PortalPage portalPage = portalPageStore.getPortalPage(portalPageId); if (portalPage == null) { throw new DashboardStateStoreException("No portal page found with id '" + portalPageId + "'"); } updatePortalPage(portalPage, dashboardState); final Map<Long, PortletConfiguration> oldPortlets = getCurrentPortletConfigurationsMap(portalPageId); for (DashboardState.ColumnIndex columnIndex : dashboardState.getLayout().getColumnRange()) { int row = 0; for (final GadgetState gadgetState : dashboardState.getGadgetsInColumn(columnIndex)) { final long gadgetId = toLong(gadgetState.getId()); // update existing portlets if (oldPortlets.containsKey(gadgetId)) { final PortletConfiguration oldPortletConfiguration = oldPortlets.get(gadgetId); oldPortletConfiguration.setColumn(columnIndex.index()); oldPortletConfiguration.setRow(row++); oldPortletConfiguration.setColor(gadgetState.getColor()); oldPortletConfiguration.setUserPrefs(gadgetState.getUserPrefs()); portletConfigurationStore.store(oldPortletConfiguration); oldPortlets.remove(gadgetId); } else { portletConfigurationStore.addGadget( portalPageId, gadgetId, columnIndex.index(), row++, gadgetState.getGadgetSpecUri(), gadgetState.getColor(), gadgetState.getUserPrefs()); } } } // delete any portlets left over in the oldPortlets map for (PortletConfiguration existingPortlet : oldPortlets.values()) { portletConfigurationStore.delete(existingPortlet); } return retrieve(dashboardId); }
public GadgetSpec getGadgetSpec( final GadgetState gadgetState, final GadgetRequestContext gadgetRequestContext) throws GadgetParsingException { return getGadgetSpec( gadgetState.getGadgetSpecUri(), gadgetState.getUserPrefs(), gadgetRequestContext); }