@Test public void testGetAllTemplatesForUser() { MockResourceResponse response = new MockResourceResponse(); MockResourceRequest request = new MockResourceRequest(); List <Long> organizationIds = new LinkedList<Long>(); organizationIds.add((long) 1); organizationIds.add((long) 2); when(mockUser.getLastName()).thenReturn("Bartonicek"); when(mockLiferayService.getUser(request, response)).thenReturn(mockUser); when(mockLiferayService.getOrganizationIds(mockUser)).thenReturn(organizationIds); try{ mainController.getTemplates(request, response, 1, 1); JsonNode rootNode = objectMapper.readValue(response.getContentAsString(), JsonNode.class); int templatesExpected = 1; int rowsFound = 0; for (@SuppressWarnings("unused") JsonNode node : rootNode.path("rows")) { ++rowsFound; } assertEquals(templatesExpected, rowsFound); } catch (Exception e){ ExceptionUtil.throwSystemException(e); } }
@ResourceMapping(GET_TEMPLATES) public void getTemplates(ResourceRequest request, ResourceResponse response, @RequestParam("page") int page, @RequestParam("rows") int rows) throws Exception { try { User user = liferayService.getUser(request, response); if (user == null) return; List<Long> organizationIds = liferayService.getOrganizationIds(user); List<ConfigurationTemplate> templates = templateService.loadAllForOrganizations(organizationIds); createOnePageResponse(response, templates, page, rows); } catch (Exception e) { ExceptionUtil.throwSystemException(e); } }
MainController extends AbstractController { @ResourceMapping(GET_TEMPLATES) public void getTemplates(ResourceRequest request, ResourceResponse response, @RequestParam("page") int page, @RequestParam("rows") int rows) throws Exception { try { User user = liferayService.getUser(request, response); if (user == null) return; List<Long> organizationIds = liferayService.getOrganizationIds(user); List<ConfigurationTemplate> templates = templateService.loadAllForOrganizations(organizationIds); createOnePageResponse(response, templates, page, rows); } catch (Exception e) { ExceptionUtil.throwSystemException(e); } } }
MainController extends AbstractController { @ResourceMapping(GET_TEMPLATES) public void getTemplates(ResourceRequest request, ResourceResponse response, @RequestParam("page") int page, @RequestParam("rows") int rows) throws Exception { try { User user = liferayService.getUser(request, response); if (user == null) return; List<Long> organizationIds = liferayService.getOrganizationIds(user); List<ConfigurationTemplate> templates = templateService.loadAllForOrganizations(organizationIds); createOnePageResponse(response, templates, page, rows); } catch (Exception e) { ExceptionUtil.throwSystemException(e); } } MainController(); }
MainController extends AbstractController { @ResourceMapping(GET_TEMPLATES) public void getTemplates(ResourceRequest request, ResourceResponse response, @RequestParam("page") int page, @RequestParam("rows") int rows) throws Exception { try { User user = liferayService.getUser(request, response); if (user == null) return; List<Long> organizationIds = liferayService.getOrganizationIds(user); List<ConfigurationTemplate> templates = templateService.loadAllForOrganizations(organizationIds); createOnePageResponse(response, templates, page, rows); } catch (Exception e) { ExceptionUtil.throwSystemException(e); } } MainController(); @RenderMapping String showView(RenderRequest request, RenderResponse response); @Authenticated @ResourceMapping(GET_ELEMENTS) void getElements(ResourceRequest request, ResourceResponse response, @RequestParam("page") int page, @RequestParam("rows") int rows); @ResourceMapping(GET_TEMPLATES) void getTemplates(ResourceRequest request, ResourceResponse response, @RequestParam("page") int page, @RequestParam("rows") int rows); @Authenticated @ResourceMapping(GET_MODULES) void getModules(ResourceRequest request, ResourceResponse response, @RequestParam("page") int page, @RequestParam("rows") int rows); @Authenticated @ResourceMapping(GET_PACKAGES) void getPackages(ResourceRequest request, ResourceResponse response, @RequestParam("page") int page, @RequestParam("rows") int rows); }
MainController extends AbstractController { @ResourceMapping(GET_TEMPLATES) public void getTemplates(ResourceRequest request, ResourceResponse response, @RequestParam("page") int page, @RequestParam("rows") int rows) throws Exception { try { User user = liferayService.getUser(request, response); if (user == null) return; List<Long> organizationIds = liferayService.getOrganizationIds(user); List<ConfigurationTemplate> templates = templateService.loadAllForOrganizations(organizationIds); createOnePageResponse(response, templates, page, rows); } catch (Exception e) { ExceptionUtil.throwSystemException(e); } } MainController(); @RenderMapping String showView(RenderRequest request, RenderResponse response); @Authenticated @ResourceMapping(GET_ELEMENTS) void getElements(ResourceRequest request, ResourceResponse response, @RequestParam("page") int page, @RequestParam("rows") int rows); @ResourceMapping(GET_TEMPLATES) void getTemplates(ResourceRequest request, ResourceResponse response, @RequestParam("page") int page, @RequestParam("rows") int rows); @Authenticated @ResourceMapping(GET_MODULES) void getModules(ResourceRequest request, ResourceResponse response, @RequestParam("page") int page, @RequestParam("rows") int rows); @Authenticated @ResourceMapping(GET_PACKAGES) void getPackages(ResourceRequest request, ResourceResponse response, @RequestParam("page") int page, @RequestParam("rows") int rows);  }