@GetMapping("") public String listUploadedFiles(Model model) throws IOException { List<String> urls = storageService .loadAll() .map(path -> MvcUriComponentsBuilder .fromMethodName(FileUploadController.class, "serveFile", path.getFileName().toString()) .build().encode().toString()) .collect(Collectors.toList()); List<String> names = storageService .loadAll() .map(path -> path.getFileName().toString()) .collect(Collectors.toList()); List fileAndNames = new ArrayList<Map<String,String>>(urls.size()); for(int i=0; i<urls.size(); i++){ Map<String,String> mp = new HashMap<>(); mp.put("url",urls.get(i)); mp.put("name",names.get(i)); fileAndNames.add(mp); } model.addAttribute("files", fileAndNames); return "upload/uploadForm"; }
/** * Displays the sent message to the sender after sending. */ @GetMapping("/{id:[a-f0-9]{64}}") public String created(@PathVariable("id") final String id, @RequestParam("linkSecret") final String linkSecret, final Model model, final UriComponentsBuilder uriComponentsBuilder) { final SenderMessage senderMessage = messageService.getSenderMessage(id); final String receiveUrl = MvcUriComponentsBuilder .fromMappingName(uriComponentsBuilder, "RC#receive") .arg(0, senderMessage.getReceiverId()) .arg(1, linkSecret) .build(); model .addAttribute("receiveUrl", receiveUrl) .addAttribute("senderMessage", senderMessage) .addAttribute("linkSecret", linkSecret); return FORM_MSG_STATUS; }
@Override public List<LinkDefinition<Build>> getLinkDefinitions() { return Arrays.asList( LinkDefinitions.link( "_changeLog", build -> { BuildDiffRequest request = new BuildDiffRequest(); request.setFrom(build.getId()); return MvcUriComponentsBuilder.on(SVNController.class).changeLog(request); }, (build, rc) -> rc.isProjectFunctionGranted(build, ProjectView.class) && svnService.getSVNRepository(build.getBranch()).isPresent() ), LinkDefinitions.page( "_changeLogPage", (build, resourceContext) -> resourceContext.isProjectFunctionGranted(build, ProjectView.class) && svnService.getSVNRepository(build.getBranch()).isPresent(), "extension/svn/changelog" ) ); }
@Override public URI build(Object methodInvocation) { // Default builder UriComponentsBuilder builder = MvcUriComponentsBuilder.fromMethodCall(methodInvocation); // Default URI UriComponents uriComponents = builder.build(); // TODO #251 Workaround for SPR-12771 RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); HttpRequest httpRequest = new ServletServerHttpRequest(request); String portHeader = httpRequest.getHeaders().getFirst("X-Forwarded-Port"); if (StringUtils.hasText(portHeader)) { int port = Integer.parseInt(portHeader); String scheme = uriComponents.getScheme(); if (("https".equals(scheme) && port == 443) || ("http".equals(scheme) && port == 80)) { port = -1; } builder.port(port); } // OK return builder.build().toUri(); }
/** * Gets the list of information extensions for an entity */ @RequestMapping(value = "information/{entityType}/{id}", method = RequestMethod.GET) public Resources<EntityInformation> getInformation(@PathVariable ProjectEntityType entityType, @PathVariable ID id) { // Gets the entity ProjectEntity entity = getEntity(entityType, id); // List of informations to return List<EntityInformation> informations = extensionManager.getExtensions(EntityInformationExtension.class).stream() .map(x -> x.getInformation(entity)) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toList()); // OK return Resources.of( informations, uri(MvcUriComponentsBuilder.on(getClass()).getInformation(entityType, id)) ); }
@Override public List<LinkDefinition<Build>> getLinkDefinitions() { return Arrays.asList( LinkDefinitions.link( "_changeLog", build -> MvcUriComponentsBuilder.on(GitController.class).changeLog(new BuildDiffRequest().withFrom(build.getId())), (build, resourceContext) -> resourceContext.isProjectFunctionGranted(build, ProjectView.class) && gitService.isBranchConfiguredForGit(build.getBranch()) ), LinkDefinitions.page( "_changeLogPage", (build, resourceContext) -> resourceContext.isProjectFunctionGranted(build, ProjectView.class) && gitService.isBranchConfiguredForGit(build.getBranch()) , "extension/git/changelog" ) ); }
@ApiOperation(value = "Create the contribution of titles") @ApiResponses(value = { @ApiResponse(code = 400, message = "Incorrect data in the DTO"), @ApiResponse(code = 404, message = "No movie found or no user found"), @ApiResponse(code = 409, message = "An ID conflict or element exists"), }) @PreAuthorize("hasRole('ROLE_USER')") @PostMapping(value = "/{id}/contributions/othertitles", consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<Void> createOtherTitleContribution( @ApiParam(value = "The movie ID", required = true) @PathVariable("id") final Long id, @ApiParam(value = "The contribution", required = true) @RequestBody @Valid final ContributionNew<OtherTitle> contribution ) { log.info("Called with id {}, contribution {}", id, contribution); final Long cId = this.movieContributionPersistenceService.createOtherTitleContribution(contribution, id, this.authorizationService.getUserId()); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation( MvcUriComponentsBuilder .fromMethodName(MovieContributionRestController.class, "getOtherTitleContribution", cId) .buildAndExpand(cId) .toUri() ); return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED); }
@ApiOperation(value = "Create the contribution of release dates") @ApiResponses(value = { @ApiResponse(code = 400, message = "Incorrect data in the DTO"), @ApiResponse(code = 404, message = "No movie found or no user found"), @ApiResponse(code = 409, message = "An ID conflict or element exists"), }) @PreAuthorize("hasRole('ROLE_USER')") @PostMapping(value = "/{id}/contributions/releasedates", consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<Void> createReleaseDateContribution( @ApiParam(value = "The movie ID", required = true) @PathVariable("id") final Long id, @ApiParam(value = "The contribution", required = true) @RequestBody @Valid final ContributionNew<ReleaseDate> contribution ) { log.info("Called with id {}, contribution {}", id, contribution); final Long cId = this.movieContributionPersistenceService.createReleaseDateContribution(contribution, id, this.authorizationService.getUserId()); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation( MvcUriComponentsBuilder .fromMethodName(MovieContributionRestController.class, "getReleaseDateContribution", cId) .buildAndExpand(cId) .toUri() ); return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED); }
@ApiOperation(value = "Create the contribution of storylines") @ApiResponses(value = { @ApiResponse(code = 400, message = "Incorrect data in the DTO"), @ApiResponse(code = 404, message = "No movie found or no user found"), @ApiResponse(code = 409, message = "An ID conflict or element exists"), }) @PreAuthorize("hasRole('ROLE_USER')") @PostMapping(value = "/{id}/contributions/storylines", consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<Void> createStorylineContribution( @ApiParam(value = "The movie ID", required = true) @PathVariable("id") final Long id, @ApiParam(value = "The contribution", required = true) @RequestBody @Valid final ContributionNew<Storyline> contribution ) { log.info("Called with id {}, contribution {}", id, contribution); final Long cId = this.movieContributionPersistenceService.createStorylineContribution(contribution, id, this.authorizationService.getUserId()); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation( MvcUriComponentsBuilder .fromMethodName(MovieContributionRestController.class, "getStorylineContribution", cId) .buildAndExpand(cId) .toUri() ); return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED); }
@ApiOperation(value = "Create the contribution of box offices") @ApiResponses(value = { @ApiResponse(code = 400, message = "Incorrect data in the DTO"), @ApiResponse(code = 404, message = "No movie found or no user found"), @ApiResponse(code = 409, message = "An ID conflict or element exists"), }) @PreAuthorize("hasRole('ROLE_USER')") @PostMapping(value = "/{id}/contributions/boxoffices", consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<Void> createBoxOfficeContribution( @ApiParam(value = "The movie ID", required = true) @PathVariable("id") final Long id, @ApiParam(value = "The contribution", required = true) @RequestBody @Valid final ContributionNew<BoxOffice> contribution ) { log.info("Called with id {}, contribution {}", id, contribution); final Long cId = this.movieContributionPersistenceService.createBoxOfficeContribution(contribution, id, this.authorizationService.getUserId()); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation( MvcUriComponentsBuilder .fromMethodName(MovieContributionRestController.class, "getBoxOfficeContribution", cId) .buildAndExpand(cId) .toUri() ); return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED); }
@ApiOperation(value = "Create the contribution of sites") @ApiResponses(value = { @ApiResponse(code = 400, message = "Incorrect data in the DTO"), @ApiResponse(code = 404, message = "No movie found or no user found"), @ApiResponse(code = 409, message = "An ID conflict or element exists"), }) @PreAuthorize("hasRole('ROLE_USER')") @PostMapping(value = "/{id}/contributions/sites", consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<Void> createSiteContribution( @ApiParam(value = "The movie ID", required = true) @PathVariable("id") final Long id, @ApiParam(value = "The contribution", required = true) @RequestBody @Valid final ContributionNew<Site> contribution ) { log.info("Called with id {}, contribution {}", id, contribution); final Long cId = this.movieContributionPersistenceService.createSiteContribution(contribution, id, this.authorizationService.getUserId()); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation( MvcUriComponentsBuilder .fromMethodName(MovieContributionRestController.class, "getSiteContribution", cId) .buildAndExpand(cId) .toUri() ); return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED); }
@ApiOperation(value = "Create the contribution of countries") @ApiResponses(value = { @ApiResponse(code = 400, message = "Incorrect data in the DTO"), @ApiResponse(code = 404, message = "No movie found or no user found"), @ApiResponse(code = 409, message = "An ID conflict or element exists"), }) @PreAuthorize("hasRole('ROLE_USER')") @PostMapping(value = "/{id}/contributions/countries", consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<Void> createCountryContribution( @ApiParam(value = "The movie ID", required = true) @PathVariable("id") final Long id, @ApiParam(value = "The contribution", required = true) @RequestBody @Valid final ContributionNew<Country> contribution ) { log.info("Called with id {}, contribution {}", id, contribution); final Long cId = this.movieContributionPersistenceService.createCountryContribution(contribution, id, this.authorizationService.getUserId()); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation( MvcUriComponentsBuilder .fromMethodName(MovieContributionRestController.class, "getCountryContribution", cId) .buildAndExpand(cId) .toUri() ); return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED); }
@ApiOperation(value = "Create the contribution of languages") @ApiResponses(value = { @ApiResponse(code = 400, message = "Incorrect data in the DTO"), @ApiResponse(code = 404, message = "No movie found or no user found"), @ApiResponse(code = 409, message = "An ID conflict or element exists"), }) @PreAuthorize("hasRole('ROLE_USER')") @PostMapping(value = "/{id}/contributions/languages", consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<Void> createLanguageContribution( @ApiParam(value = "The movie ID", required = true) @PathVariable("id") final Long id, @ApiParam(value = "The contribution", required = true) @RequestBody @Valid final ContributionNew<Language> contribution ) { log.info("Called with id {}, contribution {}", id, contribution); final Long cId = this.movieContributionPersistenceService.createLanguageContribution(contribution, id, this.authorizationService.getUserId()); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation( MvcUriComponentsBuilder .fromMethodName(MovieContributionRestController.class, "getLanguageContribution", cId) .buildAndExpand(cId) .toUri() ); return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED); }
@ApiOperation(value = "Create the contribution of genres") @ApiResponses(value = { @ApiResponse(code = 400, message = "Incorrect data in the DTO"), @ApiResponse(code = 404, message = "No movie found or no user found"), @ApiResponse(code = 409, message = "An ID conflict or element exists"), }) @PreAuthorize("hasRole('ROLE_USER')") @PostMapping(value = "/{id}/contributions/genres", consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<Void> createGenreContribution( @ApiParam(value = "The movie ID", required = true) @PathVariable("id") final Long id, @ApiParam(value = "The contribution", required = true) @RequestBody @Valid final ContributionNew<Genre> contribution ) { log.info("Called with id {}, contribution {}", id, contribution); final Long cId = this.movieContributionPersistenceService.createGenreContribution(contribution, id, this.authorizationService.getUserId()); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation( MvcUriComponentsBuilder .fromMethodName(MovieContributionRestController.class, "getGenreContribution", cId) .buildAndExpand(cId) .toUri() ); return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED); }
@ApiOperation(value = "Create the contribution of reviews") @ApiResponses(value = { @ApiResponse(code = 400, message = "Incorrect data in the DTO"), @ApiResponse(code = 404, message = "No movie found or no user found"), @ApiResponse(code = 409, message = "An ID conflict or element exists"), }) @PreAuthorize("hasRole('ROLE_USER')") @PostMapping(value = "/{id}/contributions/reviews", consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<Void> createReviewContribution( @ApiParam(value = "The movie ID", required = true) @PathVariable("id") final Long id, @ApiParam(value = "The contribution", required = true) @RequestBody @Valid final ContributionNew<Review> contribution ) { log.info("Called with id {}, contribution {}", id, contribution); final Long cId = this.movieContributionPersistenceService.createReviewContribution(contribution, id, this.authorizationService.getUserId()); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation( MvcUriComponentsBuilder .fromMethodName(MovieContributionRestController.class, "getReviewContribution", cId) .buildAndExpand(cId) .toUri() ); return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED); }
@GetMapping("/") public String listUploadedFiles(Model model) throws IOException { model.addAttribute("files", storageService .loadAll() .map(path -> MvcUriComponentsBuilder .fromMethodName(ImageController.class, "serveFile", path.getFileName().toString()) .build().toString()) .collect(Collectors.toList())); return "uploadForm"; }
/** * Url获取函数,作为函数传入StorageService。 * @param path * @return FileInfo */ public static String getPathUrl(Path path) { String resourcePath = path.getName(0).relativize(path).toString().replace("\\", "/"); String methodName = path.toFile().isDirectory() ? "viewDir" : "serveFile"; Method method; try { method = FileServerEndpoint.class.getDeclaredMethod(methodName, HttpServletRequest.class); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("No " + methodName + " method in " + FileServerEndpoint.class.getSimpleName()); } String methodPath; RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class); if (requestMapping == null) { throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString()); } String[] paths = requestMapping.path(); if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) { methodPath = "/"; }else { methodPath = paths[0].substring(0, paths[0].length() - 2); } String baseUrl = MvcUriComponentsBuilder .fromController(FileServerEndpoint.class) .build().toString(); String pathUrl = baseUrl + methodPath + resourcePath; return pathUrl; }
@GetMapping("/") public String listUploadedFiles(Model model) throws IOException { model.addAttribute("files", storageService.loadAll() .map(path -> MvcUriComponentsBuilder.fromMethodName(ChartUploadController.class, "serveFile", path.getFileName().toString()).build().toString()) .collect(Collectors.toList())); return "uploadForm"; }
@GetMapping("/") public String listUploadedFiles(Model model) throws IOException { model.addAttribute("files", storageService .loadAll() .map(path -> MvcUriComponentsBuilder .fromMethodName(FileUploadController.class, "serveFile", path.getFileName().toString()) .build().toString()) .collect(Collectors.toList())); return "uploadForm"; }
public String listUploadedFiles(Model model) throws IOException { model.addAttribute("files", storageService .loadAll() .map(path -> MvcUriComponentsBuilder .fromMethodName(UploadController.class, "serveFile", path.getParent().getFileName().toString(), path.getFileName().toString()) .build().toString()) .collect(Collectors.toList())); return "site/uploadForm"; }
private ResponseEntity<Void> putMethodsResponseEntityFactory(HttpStatus httpStatus,SearchIndex searchIndex){ if(searchIndex != null){ URI location = MvcUriComponentsBuilder.fromMethodName(SearchBookService.class, "findSearchIndexById", searchIndex.getBookId()).build().toUri(); return ResponseEntity.status(httpStatus).location(location).build(); } else { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } }
@Override @RequestMapping(value = "", method = RequestMethod.GET) public Resource<ExtensionFeatureDescription> getDescription() { return Resource.of( feature.getFeatureDescription(), uri(MvcUriComponentsBuilder.on(getClass()).getDescription()) ) .with("configurations", uri(on(getClass()).getConfigurations()), securityService.isGlobalFunctionGranted(GlobalSettings.class)) ; }
@Override public List<Link> links(LDAPMapping resource, ResourceContext resourceContext) { return resourceContext.links() // Update .link(Link.UPDATE, MvcUriComponentsBuilder.on(LDAPController.class).getMappingUpdateForm(resource.getId())) // Delete .link(Link.DELETE, MvcUriComponentsBuilder.on(LDAPController.class).deleteMapping(resource.getId())) // OK .build(); }
@Override public List<LinkDefinition<Branch>> getLinkDefinitions() { return Collections.singletonList( LinkDefinitions.link( "_download", branch -> MvcUriComponentsBuilder.on(SVNController.class).download( branch.getId(), "" ), (branch, rc) -> rc.isProjectFunctionGranted(branch, ProjectConfig.class) && svnService.getSVNRepository(branch).isPresent() ) ); }
/** * Gets the list of actions for an entity */ @RequestMapping(value = "actions/{entityType}/{id}", method = RequestMethod.GET) public Resources<Action> getActions(@PathVariable ProjectEntityType entityType, @PathVariable ID id) { return Resources.of( extensionManager.getExtensions(ProjectEntityActionExtension.class).stream() .map(x -> x.getAction(getEntity(entityType, id)).map(action -> resolveExtensionAction(x, action))) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toList()), uri(MvcUriComponentsBuilder.on(getClass()).getActions(entityType, id)) ); }
/** * Gets the list of extensions. */ @RequestMapping(value = "", method = RequestMethod.GET) public Resource<ExtensionList> getExtensions() { return Resource.of( extensionManager.getExtensionList(), uri(MvcUriComponentsBuilder.on(getClass()).getExtensions()) ); }
@Override public List<LinkDefinition<Branch>> getLinkDefinitions() { return Collections.singletonList( LinkDefinitions.link( "_download", branch -> MvcUriComponentsBuilder.on(GitController.class).download( branch.getId(), null ), (branch, rc) -> rc.isProjectFunctionGranted(branch, ProjectConfig.class) && gitService.getBranchConfiguration(branch).isPresent() ) ); }
@Override public URI build(Object invocationInfo) { MvcUriComponentsBuilder.MethodInvocationInfo info = (MvcUriComponentsBuilder.MethodInvocationInfo) invocationInfo; return URI.create( format( "urn:test:%s#%s:%s", info.getControllerMethod().getDeclaringClass().getName(), info.getControllerMethod().getName(), Arrays.stream(info.getArgumentValues()) .map(o -> Objects.toString(o, "")) .map(this::encode) .collect(Collectors.joining(",")) ) ); }
@Override @RequestMapping(value = "", method = RequestMethod.GET) public Resource<ExtensionFeatureDescription> getDescription() { return Resource.of( feature.getFeatureDescription(), uri(MvcUriComponentsBuilder.on(getClass()).getDescription()) ) .with("configurations", uri(on(getClass()).getConfigurationList()), securityService.isGlobalFunctionGranted(GlobalSettings.class)) ; }
@ApiOperation(value = "Create the contribution of photos") @ApiResponses(value = { @ApiResponse(code = 400, message = "Incorrect data"), @ApiResponse(code = 404, message = "No movie found or no user found"), @ApiResponse(code = 409, message = "An ID conflict or element exists"), @ApiResponse(code = 412, message = "An I/O error occurs or incorrect content type"), @ApiResponse(code = 500, message = "An error occurred with the server") }) @PreAuthorize("hasRole('ROLE_USER')") @PostMapping(value = "/{id}/contributions/photos", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<Void> createPhotoContribution( @ApiParam(value = "The movie ID", required = true) @PathVariable("id") final Long id, @ApiParam(value = "Elements to be added") @RequestPart(required = false) List<MultipartFile> elementsToAdd, @ApiParam(value = "Element IDs to be updated") @RequestParam(defaultValue = "", required = false) Set<Long> idsToUpdate, @ApiParam(value = "Element to be updated") @RequestPart(required = false) List<MultipartFile> elementsToUpdate, @ApiParam(value = "Element IDs to be deleted") @RequestParam(defaultValue = "", required = false) Set<Long> idsToDelete, @ApiParam(value = "Sources of information(elements)", required = true) @RequestParam final Set<String> sources, @ApiParam(value = "Comment from the user") @RequestParam(required = false) final String comment ) { log.info("Called with id {}, elementsToAdd {}, idsToUpdate {}, elementsToUpdate{}, idsToDelete {}," + " sources {}, comment {}", id, elementsToAdd, idsToUpdate, elementsToUpdate, idsToDelete, sources, comment); final ContributionNew<ImageRequest> contribution = new ContributionNew<>(); final List<ImageRequest> listPhotosToAdd = new ArrayList<>(); for(final MultipartFile multipartFile : elementsToAdd) { final ImageRequest.Builder builder = new ImageRequest.Builder().withFile(MultipartFileUtils.convert(multipartFile)); listPhotosToAdd.add(builder.build()); } contribution.setElementsToAdd(listPhotosToAdd); final HashMap<Long, ImageRequest> mapPhotosToUpdate = MapUtils.merge(idsToUpdate, elementsToUpdate); contribution.setElementsToUpdate(mapPhotosToUpdate); contribution.setIdsToDelete(idsToDelete); contribution.setSources(sources); final Long cId = this.movieContributionPersistenceService.createPhotoContribution(contribution, id, this.authorizationService.getUserId()); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation( MvcUriComponentsBuilder .fromMethodName(MovieContributionRestController.class, "getPhotoContribution", cId) .buildAndExpand(cId) .toUri() ); return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED); }
@ApiOperation(value = "Create the contribution of posters") @ApiResponses(value = { @ApiResponse(code = 400, message = "Incorrect data"), @ApiResponse(code = 404, message = "No movie found or no user found"), @ApiResponse(code = 409, message = "An ID conflict or element exists"), @ApiResponse(code = 412, message = "An I/O error occurs or incorrect content type"), @ApiResponse(code = 500, message = "An error occurred with the server") }) @PreAuthorize("hasRole('ROLE_USER')") @PostMapping(value = "/{id}/contributions/posters", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<Void> createPosterContribution( @ApiParam(value = "The movie ID", required = true) @PathVariable("id") final Long id, @ApiParam(value = "Elements to be added") @RequestPart(required = false) List<MultipartFile> elementsToAdd, @ApiParam(value = "Element IDs to be updated") @RequestParam(defaultValue = "", required = false) Set<Long> idsToUpdate, @ApiParam(value = "Element to be updated") @RequestPart(required = false) List<MultipartFile> elementsToUpdate, @ApiParam(value = "Element IDs to be deleted") @RequestParam(defaultValue = "", required = false) Set<Long> idsToDelete, @ApiParam(value = "Sources of information(elements)", required = true) @RequestParam final Set<String> sources, @ApiParam(value = "Comment from the user") @RequestParam(required = false) final String comment ) { log.info("Called with id {}, elementsToAdd {}, idsToUpdate {}, elementsToUpdate{}, idsToDelete {}," + " sources {}, comment {}", id, elementsToAdd, idsToUpdate, elementsToUpdate, idsToDelete, sources, comment); final ContributionNew<ImageRequest> contribution = new ContributionNew<>(); final List<ImageRequest> listPhotosToAdd = new ArrayList<>(); for(final MultipartFile multipartFile : elementsToAdd) { final ImageRequest.Builder builder = new ImageRequest.Builder().withFile(MultipartFileUtils.convert(multipartFile)); listPhotosToAdd.add(builder.build()); } contribution.setElementsToAdd(listPhotosToAdd); final HashMap<Long, ImageRequest> mapPhotosToUpdate = MapUtils.merge(idsToUpdate, elementsToUpdate); contribution.setElementsToUpdate(mapPhotosToUpdate); contribution.setIdsToDelete(idsToDelete); contribution.setSources(sources); final Long cId = this.movieContributionPersistenceService.createPosterContribution(contribution, id, this.authorizationService.getUserId()); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation( MvcUriComponentsBuilder .fromMethodName(MovieContributionRestController.class, "getPosterContribution", cId) .buildAndExpand(cId) .toUri() ); return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED); }
public static void main(String[] args) throws JsonProcessingException { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://api.wx.com"); MvcUriComponentsBuilder.fromMethod(builder, WxBuildinVerifyService.class, ClassUtils.getMethod(WxBuildinVerifyService.class, "verify", null), "a", "a", "a", "a"); System.out.println(builder); }
@Test public void testDefaultConfig() throws Exception { loadBeanDefinitions("mvc-config.xml", 14); RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class); assertNotNull(mapping); assertEquals(0, mapping.getOrder()); assertTrue(mapping.getUrlPathHelper().shouldRemoveSemicolonContent()); mapping.setDefaultHandler(handlerMethod); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json"); NativeWebRequest webRequest = new ServletWebRequest(request); ContentNegotiationManager manager = mapping.getContentNegotiationManager(); assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest)); RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class); assertNotNull(adapter); assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect")); List<HttpMessageConverter<?>> converters = adapter.getMessageConverters(); assertTrue(converters.size() > 0); for (HttpMessageConverter<?> converter : converters) { if (converter instanceof AbstractJackson2HttpMessageConverter) { ObjectMapper objectMapper = ((AbstractJackson2HttpMessageConverter) converter).getObjectMapper(); assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)); assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)); assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); if (converter instanceof MappingJackson2XmlHttpMessageConverter) { assertEquals(XmlMapper.class, objectMapper.getClass()); } } } assertNotNull(appContext.getBean(FormattingConversionServiceFactoryBean.class)); assertNotNull(appContext.getBean(ConversionService.class)); assertNotNull(appContext.getBean(LocalValidatorFactoryBean.class)); assertNotNull(appContext.getBean(Validator.class)); // default web binding initializer behavior test request = new MockHttpServletRequest("GET", "/"); request.addParameter("date", "2009-10-31"); request.addParameter("percent", "99.99%"); MockHttpServletResponse response = new MockHttpServletResponse(); HandlerExecutionChain chain = mapping.getHandler(request); assertEquals(1, chain.getInterceptors().length); assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor); ConversionServiceExposingInterceptor interceptor = (ConversionServiceExposingInterceptor) chain.getInterceptors()[0]; interceptor.preHandle(request, response, handlerMethod); assertSame(appContext.getBean(ConversionService.class), request.getAttribute(ConversionService.class.getName())); adapter.handle(request, response, handlerMethod); assertTrue(handler.recordedValidationError); assertEquals(LocalDate.parse("2009-10-31").toDate(), handler.date); assertEquals(Double.valueOf(0.9999), handler.percent); CompositeUriComponentsContributor uriComponentsContributor = this.appContext.getBean( MvcUriComponentsBuilder.MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME, CompositeUriComponentsContributor.class); assertNotNull(uriComponentsContributor); }