PageResource extends AssetResource<Page> { @RequestMapping(value = "/{pageId}/resources", method = RequestMethod.GET) public List<String> getResources(@PathVariable("pageId") String pageId) { Page page = pageService.get(pageId); List<String> resources = newArrayList(transform( filterValues(page.getVariables(), new BonitaVariableResourcePredicate(BONITA_RESOURCE_REGEX)).values(), new BonitaResourceTransformer(BONITA_RESOURCE_REGEX))); List<String> extension = newArrayList(transform( filterValues(page.getVariables(), new BonitaVariableResourcePredicate(EXTENSION_RESOURCE_REGEX)) .values(), new BonitaResourceTransformer(EXTENSION_RESOURCE_REGEX))); resources.addAll(extension); Iterable<Component> components = componentVisitor.visit(page); List<Component> componentList = newArrayList(components); if (componentList.stream() .anyMatch(withAction("Start process"))) { resources.add("POST|bpm/process"); } if (componentList.stream() .anyMatch(withAction("Submit task"))) { resources.add("POST|bpm/userTask"); } resources.addAll(findResourcesIn(componentList.stream().filter(withAction("GET")), "url", "GET")); resources.addAll(findResourcesIn(componentList.stream().filter(withAction("POST")), "url", "POST")); resources.addAll(findResourcesIn(componentList.stream().filter(withAction("PUT")), "url", "PUT")); resources.addAll(findResourcesIn(componentList.stream().filter(withAction("DELETE")), "url", "DELETE")); resources.addAll(findResourcesIn(componentList.stream(), "apiUrl", "GET")); resources.addAll(findResourcesIn(componentList.stream().filter(withId("pbUpload")), "url", "POST")); resources.addAll(authRulesCollector.visit(page)); return resources.stream().distinct().collect(Collectors.toList()); } @Inject  PageResource(
            PageService pageService,
            PageRepository pageRepository,
            SimpMessagingTemplate messagingTemplate,
            ContractToPageMapper contractToPageMapper,
            AssetService<Page> pageAssetService,
            AssetVisitor assetVisitor,
            ComponentVisitor componentVisitor, AuthRulesCollector authRulesCollector); @RequestMapping(method = RequestMethod.GET) @JsonView(JsonViewLight.class) List<Page> list(); @RequestMapping(method = RequestMethod.POST) ResponseEntity<Page> create(@RequestBody Page page,
            @RequestParam(value = "duplicata", required = false) String sourcePageId); @RequestMapping(value = "/contract/{scope}/{name}", method = RequestMethod.POST) ResponseEntity<Page> create(@RequestBody Contract contract, @PathVariable("scope") String scope,
            @PathVariable("name") String name); @RequestMapping(value = "/{pageId}", method = RequestMethod.PUT) ResponseEntity<Void> save(HttpServletRequest request, @PathVariable("pageId") String pageId,
            @RequestBody Page page); @RequestMapping(value = "/{pageId}/name", method = RequestMethod.PUT) ResponseEntity<Void> rename(HttpServletRequest request, @PathVariable("pageId") String pageId,
            @RequestBody String name); @RequestMapping(value = "/{pageId}/favorite", method = RequestMethod.PUT) void favorite(@PathVariable("pageId") String pageId, @RequestBody Boolean favorite); @RequestMapping(value = "/{pageId}", method = RequestMethod.GET) MappingJacksonValue get(@PathVariable("pageId") String pageId); @RequestMapping(value = "/{pageId}", method = RequestMethod.DELETE) void delete(@PathVariable("pageId") String pageId); @RequestMapping(value = "/{pageId}/resources", method = RequestMethod.GET) List<String> getResources(@PathVariable("pageId") String pageId); static final String BONITA_RESOURCE_REGEX; static final String EXTENSION_RESOURCE_REGEX; }
@Test public void should_add_bonita_resources_found_in_pages_widgets() throws Exception { setUpPageForResourcesTests(); Set<String> authRules = new TreeSet<>(); authRules.add("GET|living/application-menu"); authRules.add("POST|bpm/process"); page.setVariables(singletonMap("foo", anApiVariable("../API/bpm/userTask?filter=mine"))); when(authRulesCollector.visit(page)).thenReturn(authRules); String properties = new String(pageResource.getResources(page.getId()).toString()); assertThat(properties).contains("[GET|bpm/userTask, GET|living/application-menu, POST|bpm/process]"); }
@Test public void should_add_bonita_api_extensions_resources_found_in_pages_widgets() throws Exception { setUpPageForResourcesTests(); Set<String> authRules = new TreeSet<>(); authRules.add("POST|bpm/process"); HashMap<String, Variable> variables = new HashMap<>(); variables.put("foo", anApiVariable("../API/extension/CA31/SQLToObject?filter=mine")); variables.put("bar", anApiVariable("../API/extension/user/4")); variables.put("aa", anApiVariable("../API/extension/group/list")); variables.put("session", anApiVariable("../API/extension/user/group/unusedid")); variables.put("ab", anApiVariable("http: variables.put("user", anApiVariable("../API/identity/user/{{aaa}}/context")); variables.put("task", anApiVariable("../API/bpm/task/1/context")); variables.put("case", anApiVariable("../API/bpm/case{{dynamicQueries(true,0)}}")); variables.put("custom", anApiVariable("../API/extension/case{{dynamicQueries}}")); page.setVariables(variables); when(authRulesCollector.visit(page)).thenReturn(authRules); String properties = new String(pageResource.getResources(page.getId()).toString()); assertThat(properties).contains("[GET|bpm/task, GET|identity/user, GET|bpm/case, GET|extension/group/list, GET|extension/vehicule/voiture/roue, GET|extension/user/4, GET|extension/user/group/unusedid, GET|extension/CA31/SQLToObject, GET|extension/case, POST|bpm/process]"); }
@Test public void should_add_bonita_api_extensions_resources_found_in_page_data_table_properties() throws Exception { setUpPageForResourcesTests(); Component dataTableComponent = aComponent() .withPropertyValue("apiUrl", "constant", "../API/extension/car") .build(); when(componentVisitor.visit(page)).thenReturn(singleton(dataTableComponent)); String properties = new String(pageResource.getResources(page.getId()).toString()); assertThat(properties).contains("[GET|extension/car]"); }
@Test public void should_add_bonita_api_extensions_resources_found_in_page_button_with_DELETE_action() throws Exception { setUpPageForResourcesTests(); Component dataTableComponent = aComponent() .withPropertyValue("action", "constant", "DELETE") .withPropertyValue("url", ParameterType.INTERPOLATION.getValue(), "../API/bpm/document/1") .build(); when(componentVisitor.visit(page)).thenReturn(singleton(dataTableComponent)); String properties = new String(pageResource.getResources(page.getId()).toString()); assertThat(properties).contains("[DELETE|bpm/document]"); }
@Test public void should_add_bonita_api_extensions_resources_found_in_page_button_with_POST_action() throws Exception { setUpPageForResourcesTests(); Component dataTableComponent = aComponent() .withPropertyValue("action", "constant", "POST") .withPropertyValue("url", ParameterType.INTERPOLATION.getValue(), "../API/extension/user") .build(); when(componentVisitor.visit(page)).thenReturn(singleton(dataTableComponent)); String properties = new String(pageResource.getResources(page.getId()).toString()); assertThat(properties).contains("[POST|extension/user]"); }
@Test public void should_add_bonita_api_extensions_resources_found_in_page_fileUpload_widget() throws Exception { setUpPageForResourcesTests(); Component fileUploadComponent = aComponent() .withWidgetId("pbUpload") .withPropertyValue("url", ParameterType.CONSTANT.getValue(), "../API/extension/upload") .build(); when(componentVisitor.visit(page)).thenReturn(singleton(fileUploadComponent)); String properties = new String(pageResource.getResources(page.getId()).toString()); assertThat(properties).contains("[POST|extension/upload]"); }
@Test public void should_add_start_process_resource_if_a_start_process_submit_is_contained_in_the_page() throws Exception { setUpPageForResourcesTests(); when(componentVisitor.visit(page)).thenReturn(singleton(startProcessComponent)); String properties = new String(pageResource.getResources(page.getId()).toString()); assertThat(properties).contains("[POST|bpm/process]"); }
@Test public void should_add_submit_task_resource_if_a_start_submit_task_is_contained_in_the_page() throws Exception { setUpPageForResourcesTests(); when(componentVisitor.visit(page)).thenReturn(singleton(submitTaskComponent)); String properties = new String(pageResource.getResources(page.getId()).toString()); assertThat(properties).contains("[POST|bpm/userTask]"); }
@Test public void should_combined_start_process_submit_task_and_bonita_resources() throws Exception { setUpPageForResourcesTests(); when(componentVisitor.visit(page)) .thenReturn(asList(startProcessComponent, submitTaskComponent)); page.setVariables(singletonMap("foo", anApiVariable("/bonita/API/bpm/userTask"))); String properties = new String(pageResource.getResources(page.getId()).toString()); assertThat(properties).contains("[GET|bpm/userTask, POST|bpm/process, POST|bpm/userTask]"); }