Ejemplo n.º 1
0
  @HandlesEvent("uploadimage")
  public Resolution uploadImage() {
    logRequest();

    if (!sessionIsValid()) {
      return getStringTimeoutResolution();
    }
    if (imageFile == null) {
      return getStringResolution("error");
    }

    newImageName =
        Utils.getFullDateString(Utils.currentSeconds())
            + "_"
            + Utils.currentSeconds()
            + "."
            + Utils.getFileSuffix(imageFile.getFileName()).toLowerCase();
    String saveDir = Constants.PATH_FILE + Constants.IMAGE_FOLDER;
    Utils.makeSureDirExists(saveDir);

    try {
      imageFile.save(new File(saveDir + newImageName));

      return getStringResolution("ok");
    } catch (Exception e) {
      return getStringResolution("error");
    }
  }
 public Resolution parse() throws Exception {
   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
   String excelFilePath =
       adminUploadsPath
           + "/catalogFiles/"
           + sdf.format(new Date())
           + "/"
           + category
           + "_"
           + sdf.format(new Date())
           + ".xls";
   File excelFile = new File(excelFilePath);
   excelFile.getParentFile().mkdirs();
   fileBean.save(excelFile);
   User loggedOnUser = null;
   if (getPrincipal() != null) {
     loggedOnUser = getUserService().getUserById(getPrincipal().getId());
   }
   try {
     Set<Product> productSet = getXslParser().readProductList(excelFile, loggedOnUser);
   } catch (Exception e) {
     logger.error("Exception while reading excel sheet.", e);
     addRedirectAlertMessage(new SimpleMessage("Upload failed - " + e.getMessage()));
     return new ForwardResolution("/pages/admin/catalogDump.jsp");
   }
   getProductManager().insertCatalogue(excelFile, null);
   // excelFile.delete();
   addRedirectAlertMessage(new SimpleMessage("Database Updated"));
   return new ForwardResolution("/pages/admin/catalogDump.jsp");
 }