public static Result upload() {
    try {
      Http.MultipartFormData body = request().body().asMultipartFormData();
      Http.MultipartFormData.FilePart picture = body.getFile("picture");
      if (picture != null) {
        String fileName = picture.getFilename();
        logger.info("Uploading file name: {}", fileName);

        File pictureFile = picture.getFile();
        pictureFile.getTotalSpace();
        logger.info("Total space: {}", pictureFile);

        File folder = pictureFile.getParentFile();
        File renamedFile = new File(folder, fileName);

        File result = ExifImageUtils.rotateFromOrientationData(pictureFile, renamedFile);

        // final String absolutePath = pictureFile.getAbsolutePath();
        // final String escapedPath = UrlEscapers.urlPathSegmentEscaper().escape(absolutePath);

        // return ok(views.html.main.render(escapedPath));
        return ok(views.html.main.render(result.getAbsolutePath()));
      }

      return ok("asdf");
    } catch (Exception e) {
      logger.error("Error uploading", e);
      return internalServerError(e.getMessage());
    }
  }
 /**
  * Create a new SysAdminUtilsImpl
  *
  * @param lifecycle the play application lifecycle listener
  * @param configuration the play application configuration
  * @param databaseDependencyService the service which secure the availability of the database
  * @param actorSystem the Akka actor system
  */
 @Inject
 public SysAdminUtilsImpl(
     ApplicationLifecycle lifecycle,
     Configuration configuration,
     IDatabaseDependencyService databaseDependencyService,
     ActorSystem actorSystem) {
   log.info("SERVICE>>> SysAdminUtilsImpl starting...");
   this.actorSystem = actorSystem;
   this.configuration = configuration;
   initAutomatedSystemStatus();
   lifecycle.addStopHook(
       () -> {
         log.info("SERVICE>>> SysAdminUtilsImpl stopping...");
         if (automaticSystemStatus != null) {
           try {
             getAutomaticSystemStatus().cancel();
           } catch (Exception e) {
             log.error("Unable to stop the automatic system status", e);
           }
         }
         log.info("SERVICE>>> SysAdminUtilsImpl stopped");
         return Promise.pure(null);
       });
   log.info("SERVICE>>> SysAdminUtilsImpl started");
 }
Exemple #3
0
  public T create(final T t) {
    try {
      logger.info("About to persist the entity " + t);

      getEntityManager().persist(t);
    } catch (Throwable e) {
      logger.info("Exception creating entity " + e.getMessage(), e);

      throw new RuntimeException(e);
    }

    return t;
  }
 @Override
 public void dumpSystemStatus(String eventName, boolean logAsDebug) {
   if (logAsDebug) {
     log.debug(eventName + " " + ArrayUtils.toString(getSystemStatus()));
   } else {
     log.info(eventName + " " + ArrayUtils.toString(getSystemStatus()));
   }
 }
 /** Initialize the automated system status. */
 private void initAutomatedSystemStatus() {
   if (this.getConfiguration().getBoolean("maf.sysadmin.dump.vmstatus.active")) {
     int frequency = this.getConfiguration().getInt("maf.sysadmin.dump.vmstatus.frequency");
     log.info(">>>>>>>>>>>>>>>> Activate automated system status, frequency " + frequency);
     automaticSystemStatus =
         scheduleRecurring(
             true,
             "AUTOMATED STATUS",
             Duration.create(frequency, TimeUnit.SECONDS),
             Duration.create(frequency, TimeUnit.SECONDS),
             new Runnable() {
               @Override
               public void run() {
                 try {
                   flushOldStates();
                 } catch (Exception e) {
                   log.error("Failed to flush the old states of recurring jobs", e);
                 }
               }
             });
     log.info(">>>>>>>>>>>>>>>> Activate automated system status (end)");
   }
 }
Exemple #6
0
 @Override
 protected String createNewPay(Integer payerId, String host, Object... all) {
   logger.info(payerId + "正在进行银联支付");
   Integer count = (Integer) all[0];
   Integer itemId = (Integer) all[1];
   Payment payment =
       createPayment(
           payerId,
           Payment.TYPE_UNIONPAY_WAP,
           PayStatus.PREPAY.name(),
           false,
           new Normal(count, itemId));
   prePayInfo = UnionPayHelper.genUnionOrderInfo(getSignData(payment.id, payment.money, host));
   return host;
 }
Exemple #7
0
  @Override
  protected String infoNotify(Map<String, String> requestParams) {
    String respCode = requestParams.get("respCode");
    if (StringUtil.isNotBlank(respCode) && respCode.equals("00")) {
      String outTradeNo = new String(requestParams.get("orderId").replaceFirst("^0*", ""));
      // 获取交易金额 txnAmt
      String totalFee = String.valueOf(Double.valueOf(requestParams.get("txnAmt")) / 100);
      // 获取付款时间
      String payedMill = requestParams.get("txnTime");
      // 获取流水号
      String tradeNo = requestParams.get("queryId");

      String tradeStatus = "SUCCESS";
      Date payedAt = DateUtil.timeMillToDate(payedMill);
      Integer id = resultOfPayment(outTradeNo, tradeNo, tradeStatus, totalFee, payedAt);

      logger.info(id + "验证签名结果[成功].");
    } else {
      logger.error("银联支付返回,失败" + "\n以下是回掉信息" + requestParams.toString());
    }
    return notifySuccess();
  }
Exemple #8
0
  public File exportNeolixFile(String start, String end) {

    Workbook wb = new HSSFWorkbook();
    Sheet sheet = wb.createSheet("sheet1");
    sheet.setColumnWidth(0, 6000);
    sheet.setColumnWidth(1, 5000);
    sheet.setColumnWidth(2, 5000);
    ExcelGenerateHelper helper = ExcelGenerateHelper.getInstance(wb);

    // 获取行索引
    int rowIndex = 0;
    int colIndex = 0;

    // 表头
    String[] titles = {"订单编号", "运单号", "发货备注"};

    // 生成表头
    helper.setRowIndex(rowIndex++);
    helper.generateHeader(sheet, titles, 0, StringUtils.EMPTY, StringUtils.EMPTY);

    // 循环生成数据行
    String sql = "call get_NeolixMail('" + start + "','" + end + "')"; // SQL语句  //调用存储过程
    logger.info(sql);
    JdbcOperWithClose db = JdbcOperWithClose.getInstance(); // 创建DBHelper对象
    try {
      db.getPrepareStateDao(sql);
      ResultSet rs = db.pst.executeQuery(); // 执行语句,得到结果集
      while (rs.next()) {
        String orderCode = rs.getString("orderCode");
        String mailNum = rs.getString("mailnum");
        String remark = rs.getString("remark");
        colIndex = 0;
        Row row = sheet.createRow(rowIndex++);
        helper.createStringCell(row, colIndex++, orderCode); // 订单号
        helper.createStringCell(row, colIndex++, mailNum); // 运单号
        helper.createStringCell(row, colIndex++, remark); // 备注
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      db.close();
    }
    // 在application.conf中配置的路径
    String path = Configuration.root().getString("export.path");
    File file = new File(path);
    file.mkdir(); // 判断文件夹是否存在,不存在就创建

    FileOutputStream out = null;
    String fileName = path + "neolix" + System.currentTimeMillis() + ".xls";
    try {
      out = new FileOutputStream(fileName);
      wb.write(out);
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        out.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return new File(fileName);
  }
 @Override
 public void dumpSystemConfiguration() {
   log.info("INITIAL CONFIGURATION " + ArrayUtils.toString(getMaxSystemParameters()));
 }
  @Override
  public List<VirtualMachine> getVirtualMachines(
      Long applicationId, Long componentId, Long instanceId, Long cloudId) {
    List<VirtualMachine> vms;
    List<VirtualMachine> result = new ArrayList<VirtualMachine>();

    vms = virtualMachineModelService.getAll();

    for (VirtualMachine vm : vms) {
      boolean suitable = true;
      List<Instance> instances = null;
      List<ApplicationComponent> appComps = null;

      // Filter for application id
      if (applicationId != null) {
        instances = this.getInstances(vm.getId());
        appComps = new ArrayList<>();
        for (Instance instance : instances) {
          if (instance.getVirtualMachine().getId().equals(vm.getId())) {
            LOGGER.info("Instance " + instance.getId() + " belongs to VM " + vm.getId());
            appComps.add(
                getApplicationComponentForInstance(instance.getApplicationComponent().getId()));
          }
        }

        boolean oneInstanceFit = false;

        for (ApplicationComponent ac : appComps) {
          if (ac.getApplication().getId() == applicationId) {
            oneInstanceFit = true;
          }
        }

        suitable = oneInstanceFit;
      }

      // Filter for component id
      if (suitable && componentId != null) {
        if (instances == null) {
          instances = this.getInstances(vm.getId());
          appComps = new ArrayList<ApplicationComponent>();
          for (Instance instance : instances) {
            appComps.add(
                getApplicationComponentForInstance(instance.getApplicationComponent().getId()));
          }
        }

        boolean oneInstanceFit = false;

        for (ApplicationComponent ac : appComps) {
          if (ac.getComponent().getId() == componentId) {
            oneInstanceFit = true;
          }
        }

        suitable = oneInstanceFit;
      }

      // Filter for instance id
      if (suitable && instanceId != null) {
        if (instances == null) {
          instances = this.getInstances(vm.getId());
        }

        boolean oneInstanceFit = false;
        for (Instance instance : instances) {
          if (instance.getId() == instanceId) {
            oneInstanceFit = true;
          }
        }

        suitable = oneInstanceFit;
      }

      // Filter for cloud id
      if (suitable && cloudId != null) {
        if (vm.cloud().getId() != cloudId) {
          suitable = false;
        }
      }

      // Add to result
      if (suitable) {
        result.add(vm);
      }
    }

    return result;
  }