@Test public void getRolesGroupByWidget_noWidgetRolesExistYet() throws Exception { expect(mockEntityManager.createQuery(anyObject(String.class))).andReturn(mockQuery); Object[] widgetWithNoRoles = new Object[2]; widgetWithNoRoles[0] = "WIDGET"; List<Object[]> widgets = new ArrayList<>(); widgets.add(widgetWithNoRoles); expect(mockQuery.getResultList()).andReturn(widgets); replayAll(); List<RolesGroupByWidgetDto> rolesByWidget = unit.getRolesGroupByWidget(); verifyAll(); assertEquals(1, rolesByWidget.size()); assertEquals(0, rolesByWidget.get(0).getWidgetAuthorizedRoles().size()); assertEquals("WIDGET", rolesByWidget.get(0).getWidgetName()); }
public List<RolesGroupByWidgetDto> getRolesGroupByWidget() throws AcmObjectNotFoundException { String queryText = "SELECT widget.widgetName, wrole.roleName FROM Widget widget LEFT OUTER JOIN WidgetRole wrole " + "ON widget.widgetId=wrole.widgetId ORDER BY widget.widgetName"; Query rolesByWidget = getEntityManager().createQuery(queryText); List<Object[]> rolesPerWidget = rolesByWidget.getResultList(); List<RolesGroupByWidgetDto> result = new ArrayList<>(); List<WidgetRoleName> roles = new ArrayList<>(); RolesGroupByWidgetDto rolesPerW = new RolesGroupByWidgetDto(); String widgetN = null; String roleN = null; for (Object[] roleWidget : rolesPerWidget) { widgetN = (String) roleWidget[0]; roleN = (String) roleWidget[1]; if (rolesPerW.getWidgetName() == null) { rolesPerW.setWidgetName(widgetN); addRoleNameIfNotNull(roles, roleN); } else if (widgetN.equals(rolesPerW.getWidgetName())) { addRoleNameIfNotNull(roles, roleN); } else { rolesPerW.setWidgetAuthorizedRoles(roles); result.add(rolesPerW); rolesPerW = new RolesGroupByWidgetDto(); roles = new ArrayList<>(); rolesPerW.setWidgetName(widgetN); addRoleNameIfNotNull(roles, roleN); } } if (!rolesPerWidget.isEmpty()) { rolesPerW.setWidgetAuthorizedRoles(roles); result.add(rolesPerW); } if (result.isEmpty()) { throw new AcmObjectNotFoundException("dashboard", null, "Roles not found for all widgets", null); } return result; }
WidgetDao extends AcmAbstractDao<Widget> { public List<RolesGroupByWidgetDto> getRolesGroupByWidget() throws AcmObjectNotFoundException { String queryText = "SELECT widget.widgetName, wrole.roleName FROM Widget widget LEFT OUTER JOIN WidgetRole wrole " + "ON widget.widgetId=wrole.widgetId ORDER BY widget.widgetName"; Query rolesByWidget = getEntityManager().createQuery(queryText); List<Object[]> rolesPerWidget = rolesByWidget.getResultList(); List<RolesGroupByWidgetDto> result = new ArrayList<>(); List<WidgetRoleName> roles = new ArrayList<>(); RolesGroupByWidgetDto rolesPerW = new RolesGroupByWidgetDto(); String widgetN = null; String roleN = null; for (Object[] roleWidget : rolesPerWidget) { widgetN = (String) roleWidget[0]; roleN = (String) roleWidget[1]; if (rolesPerW.getWidgetName() == null) { rolesPerW.setWidgetName(widgetN); addRoleNameIfNotNull(roles, roleN); } else if (widgetN.equals(rolesPerW.getWidgetName())) { addRoleNameIfNotNull(roles, roleN); } else { rolesPerW.setWidgetAuthorizedRoles(roles); result.add(rolesPerW); rolesPerW = new RolesGroupByWidgetDto(); roles = new ArrayList<>(); rolesPerW.setWidgetName(widgetN); addRoleNameIfNotNull(roles, roleN); } } if (!rolesPerWidget.isEmpty()) { rolesPerW.setWidgetAuthorizedRoles(roles); result.add(rolesPerW); } if (result.isEmpty()) { throw new AcmObjectNotFoundException("dashboard", null, "Roles not found for all widgets", null); } return result; } }
WidgetDao extends AcmAbstractDao<Widget> { public List<RolesGroupByWidgetDto> getRolesGroupByWidget() throws AcmObjectNotFoundException { String queryText = "SELECT widget.widgetName, wrole.roleName FROM Widget widget LEFT OUTER JOIN WidgetRole wrole " + "ON widget.widgetId=wrole.widgetId ORDER BY widget.widgetName"; Query rolesByWidget = getEntityManager().createQuery(queryText); List<Object[]> rolesPerWidget = rolesByWidget.getResultList(); List<RolesGroupByWidgetDto> result = new ArrayList<>(); List<WidgetRoleName> roles = new ArrayList<>(); RolesGroupByWidgetDto rolesPerW = new RolesGroupByWidgetDto(); String widgetN = null; String roleN = null; for (Object[] roleWidget : rolesPerWidget) { widgetN = (String) roleWidget[0]; roleN = (String) roleWidget[1]; if (rolesPerW.getWidgetName() == null) { rolesPerW.setWidgetName(widgetN); addRoleNameIfNotNull(roles, roleN); } else if (widgetN.equals(rolesPerW.getWidgetName())) { addRoleNameIfNotNull(roles, roleN); } else { rolesPerW.setWidgetAuthorizedRoles(roles); result.add(rolesPerW); rolesPerW = new RolesGroupByWidgetDto(); roles = new ArrayList<>(); rolesPerW.setWidgetName(widgetN); addRoleNameIfNotNull(roles, roleN); } } if (!rolesPerWidget.isEmpty()) { rolesPerW.setWidgetAuthorizedRoles(roles); result.add(rolesPerW); } if (result.isEmpty()) { throw new AcmObjectNotFoundException("dashboard", null, "Roles not found for all widgets", null); } return result; }  }
WidgetDao extends AcmAbstractDao<Widget> { public List<RolesGroupByWidgetDto> getRolesGroupByWidget() throws AcmObjectNotFoundException { String queryText = "SELECT widget.widgetName, wrole.roleName FROM Widget widget LEFT OUTER JOIN WidgetRole wrole " + "ON widget.widgetId=wrole.widgetId ORDER BY widget.widgetName"; Query rolesByWidget = getEntityManager().createQuery(queryText); List<Object[]> rolesPerWidget = rolesByWidget.getResultList(); List<RolesGroupByWidgetDto> result = new ArrayList<>(); List<WidgetRoleName> roles = new ArrayList<>(); RolesGroupByWidgetDto rolesPerW = new RolesGroupByWidgetDto(); String widgetN = null; String roleN = null; for (Object[] roleWidget : rolesPerWidget) { widgetN = (String) roleWidget[0]; roleN = (String) roleWidget[1]; if (rolesPerW.getWidgetName() == null) { rolesPerW.setWidgetName(widgetN); addRoleNameIfNotNull(roles, roleN); } else if (widgetN.equals(rolesPerW.getWidgetName())) { addRoleNameIfNotNull(roles, roleN); } else { rolesPerW.setWidgetAuthorizedRoles(roles); result.add(rolesPerW); rolesPerW = new RolesGroupByWidgetDto(); roles = new ArrayList<>(); rolesPerW.setWidgetName(widgetN); addRoleNameIfNotNull(roles, roleN); } } if (!rolesPerWidget.isEmpty()) { rolesPerW.setWidgetAuthorizedRoles(roles); result.add(rolesPerW); } if (result.isEmpty()) { throw new AcmObjectNotFoundException("dashboard", null, "Roles not found for all widgets", null); } return result; }  @Transactional Widget saveWidget(Widget in); @Transactional WidgetRole saveWidgetRole(WidgetRole widgetRole); Widget getWidgetByWidgetName(String widgetName); List<Widget> getWidgetsByWidgetNames(List<String> widgetNames); List<Widget> getAllWidgets(); List<RolesGroupByWidgetDto> getRolesGroupByWidget(); List<Widget> getAllWidgetsByRoles(Set<String> roles); @Transactional WidgetRole addWidgetToARole(Widget widget, AcmRole role); void deleteWidgetRole(WidgetRole widgetRole); @Transactional void deleteWidget(Widget widget); @Transactional int deleteAllWidgetRolesByWidgetName(String widgetName); EntityManager getEntityManager(); void setEntityManager(EntityManager entityManager); }
WidgetDao extends AcmAbstractDao<Widget> { public List<RolesGroupByWidgetDto> getRolesGroupByWidget() throws AcmObjectNotFoundException { String queryText = "SELECT widget.widgetName, wrole.roleName FROM Widget widget LEFT OUTER JOIN WidgetRole wrole " + "ON widget.widgetId=wrole.widgetId ORDER BY widget.widgetName"; Query rolesByWidget = getEntityManager().createQuery(queryText); List<Object[]> rolesPerWidget = rolesByWidget.getResultList(); List<RolesGroupByWidgetDto> result = new ArrayList<>(); List<WidgetRoleName> roles = new ArrayList<>(); RolesGroupByWidgetDto rolesPerW = new RolesGroupByWidgetDto(); String widgetN = null; String roleN = null; for (Object[] roleWidget : rolesPerWidget) { widgetN = (String) roleWidget[0]; roleN = (String) roleWidget[1]; if (rolesPerW.getWidgetName() == null) { rolesPerW.setWidgetName(widgetN); addRoleNameIfNotNull(roles, roleN); } else if (widgetN.equals(rolesPerW.getWidgetName())) { addRoleNameIfNotNull(roles, roleN); } else { rolesPerW.setWidgetAuthorizedRoles(roles); result.add(rolesPerW); rolesPerW = new RolesGroupByWidgetDto(); roles = new ArrayList<>(); rolesPerW.setWidgetName(widgetN); addRoleNameIfNotNull(roles, roleN); } } if (!rolesPerWidget.isEmpty()) { rolesPerW.setWidgetAuthorizedRoles(roles); result.add(rolesPerW); } if (result.isEmpty()) { throw new AcmObjectNotFoundException("dashboard", null, "Roles not found for all widgets", null); } return result; }  @Transactional Widget saveWidget(Widget in); @Transactional WidgetRole saveWidgetRole(WidgetRole widgetRole); Widget getWidgetByWidgetName(String widgetName); List<Widget> getWidgetsByWidgetNames(List<String> widgetNames); List<Widget> getAllWidgets(); List<RolesGroupByWidgetDto> getRolesGroupByWidget(); List<Widget> getAllWidgetsByRoles(Set<String> roles); @Transactional WidgetRole addWidgetToARole(Widget widget, AcmRole role); void deleteWidgetRole(WidgetRole widgetRole); @Transactional void deleteWidget(Widget widget); @Transactional int deleteAllWidgetRolesByWidgetName(String widgetName); EntityManager getEntityManager(); void setEntityManager(EntityManager entityManager);  }