private PortletConfiguration toPortletConfiguration(final DashboardItemState dashboardItemState, final Long page, final Integer column, final Integer row) { final long itemId = toLong(dashboardItemState.getId()); return dashboardItemState.accept(new DashboardItemStateVisitor<PortletConfiguration>() { @Override public PortletConfiguration visit(final GadgetState state) { return new PortletConfigurationImpl(itemId, page, column, row, Option.some(state.getGadgetSpecUri()), state.getColor(), state.getUserPrefs(), Option.<ModuleCompleteKey>none()); } @Override public PortletConfiguration visit(final LocalDashboardItemState state) { final Option<URI> openSocialSpecUri = state.getDashboardItemModuleId().getReplacedGadgetId().map(new Function<OpenSocialDashboardItemModuleId, URI>() { @Override public URI apply(final OpenSocialDashboardItemModuleId input) { return input.getSpecUri(); } }); final Option<ModuleCompleteKey> moduleKey = Option.some(state.getDashboardItemModuleId().getFullModuleKey()); return new PortletConfigurationImpl(itemId, page, column, row, openSocialSpecUri, state.getColor(), Collections.<String, String>emptyMap(), moduleKey); } }); }
public Void visit(final GadgetState gadget) { try { layout.addGadget(finalColumnIndex, gadget, gadgetSpecFactory.getGadgetSpec(gadget, gadgetRequestContext)); } catch (GadgetParsingException e) { log.log(Level.WARN, "Ignoring gadget with id: " + dashboardItem.getId()); } return null; }
@Override public boolean apply(final DashboardItemState dashboardItemState) { VoteContext voteResult = dashboardItemState.accept(new DashboardItemStateVisitor<VoteContext>() { @Override public VoteContext visit(final GadgetState gadgetState) { final Option<PluginGadgetSpec> gadgetSpecResult = getPluginGadgetSpec(gadgetState.getGadgetSpecUri()); if (!gadgetSpecResult.isDefined()) { return new VoteContext(ALLOW); } return voteOnWithReason(gadgetSpecResult.get(), remoteUser); } @Override public VoteContext visit(final LocalDashboardItemState localDashboardItemState) { // We don't need to filter local dashboard items, they wont be displayed if user does not have permission to see them. return new VoteContext(ALLOW); } }); raiseAnalyticEvents(dashboardItemState, voteResult, Users.isAnonymous(remoteUser)); return ! voteResult.isDeny(); } };
public static DashboardItem fromDashboardItemState(DashboardItemState state, DashboardId containedInDashboard) { return new DashboardItemImpl(DashboardItemLocator.itemLocator(containedInDashboard, state.getId())); } }
private void raiseAnalyticEvents(final DashboardItemState dashboardItemState, final VoteContext voteContext, final boolean isAnonymousUser) { if (voteContext.isDeny() && voteContext.getReason().isDefined()) { // raise events for hidden gadgets only final String gadgetName = dashboardItemState.accept(new DashboardItemStateVisitor<String>() { @Override public String visit(final GadgetState gadgetState) { return gadgetState.getGadgetSpecUri().toString(); } @Override public String visit(final LocalDashboardItemState localDashboardItemState) { return localDashboardItemState.getDashboardItemModuleId().getFullModuleKey().getCompleteKey(); } }); final Reason reason = voteContext.getReason().get(); final Option<Condition> conditionClass = voteContext.getConditionClass(); final String conditionClassName = conditionClass.isDefined() ? conditionClass.get().getClass().getSimpleName() : null; eventPublisher.publish(new GadgetHiddenEvent(gadgetName, conditionClassName, reason, isAnonymousUser)); } } }
private PortletConfiguration toPortletConfiguration(final DashboardItemState dashboardItemState, final Long page, final Integer column, final Integer row) { final long itemId = toLong(dashboardItemState.getId()); return dashboardItemState.accept(new DashboardItemStateVisitor<PortletConfiguration>() { @Override public PortletConfiguration visit(final GadgetState state) { return new PortletConfigurationImpl(itemId, page, column, row, Option.some(state.getGadgetSpecUri()), state.getColor(), state.getUserPrefs(), Option.<ModuleCompleteKey>none()); } @Override public PortletConfiguration visit(final LocalDashboardItemState state) { final Option<URI> openSocialSpecUri = state.getDashboardItemModuleId().getReplacedGadgetId().map(new Function<OpenSocialDashboardItemModuleId, URI>() { @Override public URI apply(final OpenSocialDashboardItemModuleId input) { return input.getSpecUri(); } }); final Option<ModuleCompleteKey> moduleKey = Option.some(state.getDashboardItemModuleId().getFullModuleKey()); return new PortletConfigurationImpl(itemId, page, column, row, openSocialSpecUri, state.getColor(), Collections.<String, String>emptyMap(), moduleKey); } }); }
/** * Moves all items one position down. * * @param dashboardItems dashboard items which are moved one position down. * @param firstNewRow the first row, starting from which the items are moved down. * @param column in which the items are going to be moved. */ private void moveDashboardItemsOnePositionDown(final Iterable<DashboardItemState> dashboardItems, final int firstNewRow, final int column) { final Long dashboardId = toLong(updateDashboardState.getId()); final Iterable<DashboardItemState> itemsBelowNewItem = drop(firstNewRow, dashboardItems); int row = firstNewRow; for (DashboardItemState dashboardItemState : itemsBelowNewItem) { portletConfigurationStore.updateGadgetPosition(toLong(dashboardItemState.getId()), row, column, dashboardId); row += 1; } } }
dashboardItem.accept(new DashboardItemStateVisitor<Void>()
public void visit(final RemoveGadgetChange removeGadgetChange) { final PortletConfiguration gadgetToRemove = portletConfigurationStore.getByPortletId(toLong(removeGadgetChange.getGadgetId())); final Iterable<DashboardItemState> gadgets = updateDashboardState.getDashboardColumns().getItemsInColumn(DashboardState.ColumnIndex.from(gadgetToRemove.getColumn())); portletConfigurationStore.delete(gadgetToRemove); int row = 0; for (DashboardItemState gadget : gadgets) { portletConfigurationStore.updateGadgetPosition(toLong(gadget.getId()), row, gadgetToRemove.getColumn(), toLong(updateDashboardState.getId())); row++; } }