예제 #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 "";
  }
예제 #2
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!");
    }
  }