/** * This is an enhanced equals for portlets that allows equality for unpersisted portlets. At times (like addPortlet) * a portlet may have been associated with its window prior to being persisted. In this case we can consider * it equal if it is associated with the same dashboard(1) and has the same positioning. Note that key-name pairing * can not be used for equality as a dashboard is allowed to have the same portlet multiple times, with a default * name. But they can not hold the same position. * <pre> * (1) Even the dashboard comparison has been made flexible. To allow for lazy persist of the dashboard (to * allow for the default group or resource dashboard to not be persisted) we allow the dash comparison * to be done by name if an entity id is 0. This should be safe as dashboard names are set prior to * persist, and should be unique for the session user. * * @param storedPortlet * @param updatedPortlet * @return */ private boolean equalsDashboardPortlet( DashboardPortlet storedPortlet, DashboardPortlet updatedPortlet) { if (storedPortlet.equals(updatedPortlet)) { return true; } // make sure at least one portlet is not persisted for pseudo-equality if (storedPortlet.getId() > 0 && updatedPortlet.getId() > 0) { return false; } // must match position for pseudo-equality if (storedPortlet.getColumn() != updatedPortlet.getColumn()) { return false; } if (storedPortlet.getIndex() != updatedPortlet.getIndex()) { return false; } // must match dash (ids if persisted, otherwise name) for pseudo-equality boolean unpersistedDash = (storedPortlet.getDashboard().getId() == 0 || updatedPortlet.getDashboard().getId() == 0); boolean dashMatchId = (!unpersistedDash && (storedPortlet.getDashboard().getId() == updatedPortlet.getDashboard().getId())); boolean dashMatchName = (unpersistedDash && storedPortlet .getDashboard() .getName() .equals(updatedPortlet.getDashboard().getName())); if (!(dashMatchId || dashMatchName)) { return false; } return true; }