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); }