PageResource extends AssetResource<Page> { @RequestMapping(value = "/{pageId}", method = RequestMethod.PUT) public ResponseEntity<Void> save(HttpServletRequest request, @PathVariable("pageId") String pageId, @RequestBody Page page) throws RepositoryException { String newPageId; try { Page currentPage = pageService.get(pageId); if (currentPage.getName().equals(page.getName())) { newPageId = pageId; } else { newPageId = pageRepository.getNextAvailableId(page.getName()); } } catch (NotFoundException e) { newPageId = pageRepository.getNextAvailableId(page.getName()); } page.setId(newPageId); setPageUUIDIfNotSet(page); page.setAssets(filter(page.getAssets(), new PageAssetPredicate())); pageRepository.updateLastUpdateAndSave(page); ResponseEntity<Void> responseEntity; if (!newPageId.equals(pageId)) { assetService.duplicateAsset(pageRepository.resolvePath(pageId), pageRepository.resolvePath(pageId), pageId, newPageId); pageRepository.delete(pageId); responseEntity = getMovedResourceResponse(request, newPageId); messagingTemplate.convertAndSend(PREVIEWABLE_REMOVAL, pageId); } else { messagingTemplate.convertAndSend(PREVIEWABLE_UPDATE, pageId); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); responseEntity = new ResponseEntity<>(headers, HttpStatus.OK); } return responseEntity; } @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_not_save_an_external_asset_when_upload_send_an_error() throws Exception { Page page = mockPageOfId("my-page"); Asset asset = anAsset().build(); doThrow(IllegalArgumentException.class).when(pageAssetService).save(page, asset); mockMvc.perform( post("/rest/pages/my-page/assets") .contentType(MediaType.APPLICATION_JSON_VALUE) .content(convertObjectToJsonBytes(asset))) .andExpect(status().isBadRequest()); }