Esempio n. 1
0
  public synchronized String upload(HashMap<String, String> payload) {
    HashMap<String, String> verifiedPayload = verifyPayload(payload);
    Charset utf8 = Charset.forName("UTF-8");
    HttpClient httpclient = new DefaultHttpClient();
    try {
      MultipartEntity reqEntity = new MultipartEntity();

      reqEntity.addPart("projectTitle", new StringBody(verifiedPayload.get("projectTitle"), utf8));
      reqEntity.addPart(
          "projectDescription", new StringBody(verifiedPayload.get("projectDescription"), utf8));
      if (verifiedPayload.get("catroidFileName") != null) {
        String filename = verifiedPayload.get("catroidFileName");
        copyFile(
            Config.FILESYSTEM_BASE_PATH + Config.SELENIUM_GRID_TESTDATA + filename,
            Config.FILESYSTEM_TEMP_FOLDER + filename);
        reqEntity.addPart("catroidFileName", new StringBody(filename));
      } else {
        reqEntity.addPart("upload", new FileBody(new File(verifiedPayload.get("upload"))));
      }
      reqEntity.addPart("fileChecksum", new StringBody(verifiedPayload.get("fileChecksum"), utf8));
      reqEntity.addPart("userEmail", new StringBody(verifiedPayload.get("userEmail"), utf8));
      reqEntity.addPart("userLanguage", new StringBody(verifiedPayload.get("userLanguage"), utf8));
      reqEntity.addPart("username", new StringBody(verifiedPayload.get("username"), utf8));
      reqEntity.addPart("token", new StringBody(verifiedPayload.get("token"), utf8));

      HttpPost httppost =
          new HttpPost(
              this.webSite + Config.TESTS_BASE_PATH.substring(1) + "api/upload/upload.json");
      httppost.setEntity(reqEntity);
      HttpResponse response = httpclient.execute(httppost);
      HttpEntity resEntity = response.getEntity();

      if (resEntity != null) {
        String answer = EntityUtils.toString(resEntity);
        if (CommonFunctions.getValueFromJSONobject(answer, "statusCode").equals("200")) {
          String projectId = CommonFunctions.getValueFromJSONobject(answer, "projectId");
          verifiedPayload.put("projectId", projectId);
          this.uploadedProjects.add(verifiedPayload);
        }
        if (answer.equals("")) {
          System.out.println(
              "Got empty answer from api/upload.php! Maybe there is a syntax error?!");
        }
        return answer;
      }
    } catch (Exception e) {
      System.out.println("Unknown Exception - upload failed! " + e.getMessage());
      return "";
    } finally {
      try {
        httpclient.getConnectionManager().shutdown();
      } catch (Exception ignore) {
      }
    }
    return "";
  }
  private void okActionPerformed(java.awt.event.ActionEvent evt) {
    if (smtp.getText().trim().isEmpty()) {
      CommonFunctions.showErrorMessage(this, "You must enter a SMTP server.");
      return;
    } else if (smtpUsername.getText().trim().isEmpty()) {
      CommonFunctions.showErrorMessage(this, "You must enter the SMTP username.");
      return;
    } else {
      try {
        int port = Integer.parseInt(smtpPort.getText());
        if (port <= 0) throw new NumberFormatException();

        new InternetAddress(email.getText()).validate();
      } catch (NumberFormatException e) {
        CommonFunctions.showErrorMessage(this, "You must enter a valid SMTP port.");
        return;
      } catch (AddressException e) {
        CommonFunctions.showErrorMessage(this, "You must enter a valid source email address.");
        return;
      }
    }

    retval = 0;

    List<Student> selectedStudents = new ArrayList();
    for (int i = 0; i < studentsTbl.getRowCount(); i++) {
      if ((boolean) studentsTbl.getValueAt(i, 0)) {
        selectedStudents.add(students.get(studentsTbl.convertRowIndexToModel(i)));
      }
    }

    output =
        new Object[] {
          email.getText(),
          smtp.getText(),
          smtpPort.getText(),
          smtpUsername.getText(),
          new String(smtpPassword.getPassword()),
          selectedStudents
        };

    setVisible(false);
  }
Esempio n. 3
0
  public Date getJobExecTime(int jobID) {
    if (isConnected) {
      Com4jObject objJob = jobScheduler.getAbatObjectLite(jobID);

      Com4jObject abatJob = null;

      abatJob = objJob.queryInterface(IAbatJobHistory.class);

      return new Date(
          ((IAbatJobHistory) abatJob).completionDateTime().getTime()
              + CommonFunctions.getCurrentTimezoneOffset());

    } else {
      return new Date();
    }
  }
Esempio n. 4
0
  private void deleteProject(String projectId) {
    if (!projectId.equals("")) {
      try {
        Driver driver = new Driver();
        DriverManager.registerDriver(driver);

        Connection connection =
            DriverManager.getConnection(
                Config.DB_HOST + Config.DB_NAME, Config.DB_USER, Config.DB_PASS);
        Statement statement = connection.createStatement();
        statement.executeUpdate("DELETE FROM projects WHERE id='" + projectId + "';");
        statement.close();
        connection.close();
        DriverManager.deregisterDriver(driver);
      } catch (SQLException e) {
        System.out.println(
            "ProjectUploader: deleteProject: SQL Exception couldn't execute sql query!");
      }

      (new File(
              Config.FILESYSTEM_BASE_PATH
                  + Config.PROJECTS_DIRECTORY
                  + projectId
                  + Config.PROJECTS_EXTENTION))
          .delete();
      (new File(
              Config.FILESYSTEM_BASE_PATH
                  + Config.PROJECTS_QR_DIRECTORY
                  + projectId
                  + Config.PROJECTS_QR_EXTENTION))
          .delete();
      (new File(
              Config.FILESYSTEM_BASE_PATH
                  + Config.PROJECTS_THUMBNAIL_DIRECTORY
                  + projectId
                  + Config.PROJECTS_THUMBNAIL_EXTENTION_ORIG))
          .delete();
      (new File(
              Config.FILESYSTEM_BASE_PATH
                  + Config.PROJECTS_THUMBNAIL_DIRECTORY
                  + projectId
                  + Config.PROJECTS_THUMBNAIL_EXTENTION_SMALL))
          .delete();
      (new File(
              Config.FILESYSTEM_BASE_PATH
                  + Config.PROJECTS_THUMBNAIL_DIRECTORY
                  + projectId
                  + Config.PROJECTS_THUMBNAIL_EXTENTION_LARGE))
          .delete();
      CommonFunctions.deleteDir(
          new File(
              Config.FILESYSTEM_BASE_PATH
                  + Config.PROJECTS_UNZIPPED_DIRECTORY
                  + projectId
                  + Config.FILESYSTEM_SEPARATOR));
    } else {
      System.out.println(
          "ProjectUploader: deleteProject: invalid project id:'"
              + projectId
              + "' - couldn't delete!");
    }
  }