Package com.ketayao.ketacustom.entity.component

Examples of com.ketayao.ketacustom.entity.component.Resource


   
    return new ResponseEntity<String>(HttpStatus.OK);
  }
 
  private ResponseEntity<String> upload2Db(MultipartFile file) {
    Resource resource = new Resource();
    resource.setName(file.getOriginalFilename());
    resource.setSize(FileUtils.getHumanReadableFileSize(file.getSize()));
    resource.setUploadTime(new Date());
    resource.setUuid(Identities.uuid2());
    resource.setStoreType(StoreType.DB);
   
    try {
      resource.setFile(file.getBytes());
      resourceService.saveOrUpdate(resource);
     
      LogUitls.putArgs(LogMessageObject.newWrite().setObjects(new Object[]{resource.getName()}));
    } catch (Exception e) {
      LOG.error(Exceptions.getStackTraceAsString(e));
      return new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }
   
View Full Code Here


 
  @RequiresPermissions("Resource:download")
  @RequestMapping(value = "/download/{storeType}/{uuid}", method = RequestMethod.GET)
  public @ResponseBody String download(HttpServletRequest request, HttpServletResponse response,
      @PathVariable StoreType storeType, @PathVariable String uuid) {
    Resource resource = resourceService.getByUuid(uuid);
    if (resource == null) {
      return "找不到" + uuid + "文件或已被删除。";
    }
 
    switch (storeType) {
View Full Code Here

  @RequiresPermissions("Resource:delete")
  @RequestMapping(value="/delete", method=RequestMethod.POST)
  public @ResponseBody String deleteMany(Long[] ids, HttpServletRequest request) {
    AjaxObject ajaxObject = new AjaxObject("删除资源成功!");
    for (Long id : ids) {
      Resource resource = resourceService.get(id);
      if (resource.getStoreType().equals(StoreType.FILE)) {
        String storePath = getFileStorePath(request);
        String filePath = storePath + File.separator + resource.getRealStoreName();
        File file = new File(filePath);
        if (file.exists()) {
          try {
            org.apache.commons.io.FileUtils.forceDelete(file);
          } catch (IOException e) {
            //LOG.error("强制删除文件:" + resource.getName() + "失败。");
            return AjaxObject.newError(resource.getName() + "文件删除失败,请稍后再试。")
                .setCallbackType("").toString();
          }
        }
      }
     
View Full Code Here

  }
 
  @RequiresPermissions("Resource:edit")
  @RequestMapping(value="/update/{id}", method=RequestMethod.GET)
  public String preUpdate(@PathVariable Long id, Map<String, Object> map) {
    Resource resource = resourceService.get(id);
   
    map.put("resource", resource);
    map.put("name", resource.getOnlyName());
    return UPDATE;
  }
View Full Code Here

 
  @Log(message="{0}修改成了{1}。")
  @RequiresPermissions("Resource:edit")
  @RequestMapping(value="/update", method=RequestMethod.POST)
  public @ResponseBody String update(Resource resource) {
    Resource oldResource = resourceService.get(resource.getId());
    String oldName = oldResource.getName();
    // 不能修改文件类型
    oldResource.setName(resource.getName() + "." + FileUtils.getFileExt(oldName));
   
    resourceService.saveOrUpdate(oldResource);
    LogUitls.putArgs(LogMessageObject.newWrite().setObjects(new Object[]{oldName, oldResource.getName()}));
    return AjaxObject.newOk("修改资源成功!").toString();
  }
View Full Code Here

   
    File uploadedFile = new File(uploadPath, newFileName);
    try {
      org.apache.commons.io.FileUtils.writeByteArrayToFile(uploadedFile, file.getBytes());
     
      Resource resource = new Resource();
      resource.setName(file.getOriginalFilename());
      resource.setSize(FileUtils.getHumanReadableFileSize(file.getSize()));
      resource.setUploadTime(new Date());
      resource.setUuid(uuid);
      resource.setStoreType(StoreType.FILE);
     
      resourceService.saveOrUpdate(resource);
      LogUitls.putArgs(LogMessageObject.newWrite().setObjects(new Object[]{resource.getName()}));
    } catch (Exception e) {
      if (uploadedFile.exists()) {
        uploadedFile.delete();
      }
      LOG.error(Exceptions.getStackTraceAsString(e));
View Full Code Here

TOP

Related Classes of com.ketayao.ketacustom.entity.component.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.