@RequestMapping(value = "/resource", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void addContent( @RequestParam String type, @RequestParam String name, @RequestParam String language, @RequestParam(required = false) String value, @RequestParam(required = false) MultipartFile contentFile) throws CMSLiteException, IOException { if (isBlank(type)) { throw new CMSLiteException("Resource type is required"); } if (isBlank(name)) { throw new CMSLiteException("Resource name is required"); } if (isBlank(language)) { throw new CMSLiteException("Resource language is required"); } switch (type) { case "string": if (isBlank(value)) { throw new CMSLiteException("Resource content is required"); } if (cmsLiteService.isStringContentAvailable(language, name)) { throw new CMSLiteException( String.format("Resource %s in %s language already exists.", name, language)); } cmsLiteService.addContent(new StringContent(language, name, value)); break; case "stream": if (null == contentFile) { throw new CMSLiteException("Resource content is required"); } if (cmsLiteService.isStreamContentAvailable(language, name)) { throw new CMSLiteException( String.format("Resource %s in %s language already exists.", name, language)); } String checksum = md5Hex(contentFile.getBytes()); String contentType = contentFile.getContentType(); cmsLiteService.addContent( new StreamContent( language, name, ArrayUtils.toObject(contentFile.getBytes()), checksum, contentType)); break; default: } }
@RequestMapping(value = "/resource/string/{language}/{name}", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void editStringContent( @PathVariable String language, @PathVariable String name, @RequestParam String value) throws ContentNotFoundException, CMSLiteException, IOException { StringContent stringContent = cmsLiteService.getStringContent(language, name); stringContent.setValue(value); cmsLiteService.addContent(stringContent); }
@RequestMapping(value = "/resource/stream/{language}/{name}", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public void editStreamContent( @PathVariable String language, @PathVariable String name, @RequestParam MultipartFile contentFile) throws ContentNotFoundException, CMSLiteException, IOException { StreamContent streamContent = cmsLiteService.getStreamContent(language, name); streamContent.setChecksum(md5Hex(contentFile.getBytes())); streamContent.setContentType(contentFile.getContentType()); streamContent.setContent(ArrayUtils.toObject(contentFile.getBytes())); cmsLiteService.addContent(streamContent); }