Ejemplo n.º 1
0
  @RequestMapping("list")
  public ModelAndView list() {
    List<Media> list = service.query(0);
    JSONArray array = new JSONArray();
    for (Media ch : list) {
      array.add(ch.toJson());
    }

    return ViewUtil.renderListView("_media.jsp", array.toJSONString());
  }
  public JSONObject getManufacturers() {

    JSONObject result = new JSONObject();

    Connection dbConnection = null;

    try {
      Class.forName("com.mysql.jdbc.Driver");

      dbConnection =
          DriverManager.getConnection(PathNames.DB_URL, PathNames.USERNAME, PathNames.PASSWORD);

      String query =
          "SELECT * FROM "
              + PathNames.DB_MANUFACTURER_CATEGORIES
              + " cats, "
              + PathNames.DB_MANUFACTURERS
              + " mans WHERE cats.category_key='"
              + catkey
              + "' AND mans.manufacturer_id=cats.manufacturer_id";

      System.out.println(query);
      // Execute a query
      Statement statement = dbConnection.createStatement();

      ResultSet rs = statement.executeQuery(query);

      JSONArray typeList = new JSONArray();

      while (rs.next()) {
        JSONObject curr = new JSONObject();
        curr.put("catkey", rs.getString("category_key"));
        curr.put("manufacturer_id", rs.getString("manufacturer_id"));
        curr.put("manufacturer", rs.getString("manufacturer"));
        curr.put("image", rs.getString("image_name"));
        typeList.add(curr);
      }

      result.put("manufacturers", typeList);
      manufacturers = result;

    } catch (SQLException | ClassNotFoundException ex) {
      ex.printStackTrace();
    } finally {
      try {
        dbConnection.close();
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    return result;
  }
Ejemplo n.º 3
0
 public static JSONObject jsonObjectFromManifest(Manifest manifest) {
   JSONObject rootObject = new JSONObject();
   rootObject.put(ManifestConstants.TIME, manifest.getTimestamp());
   rootObject.put(
       ManifestConstants.GUID, manifest.getGuid()); // unique identifier for this manifest.
   rootObject.put(ManifestConstants.URLROOT, manifest.getUrlRoot());
   rootObject.put(ManifestConstants.VERSION, manifest.getVersion());
   // let's get that array
   JSONArray array = new JSONArray();
   for (Entry entry : manifest.getEntries()) {
     array.add(jsonObjectFromEntry(entry));
   }
   rootObject.put(ManifestConstants.ENTRIES, array);
   return rootObject;
 }
  /**
   * This method is use for create web application
   *
   * @param payload request payload for web app create api
   * @param webAppDetail bean object of the web application
   * @throws IOException Throws this when failed to create web application
   * @throws RegistryException Throws this when UUID failed while requesting
   * @throws AppManagementException Throws this when gateway port failed while retrieving
   * @throws java.lang.InterruptedException Throws this when thread failed
   */
  private String createWebApplication(String payload, WebAppDetail webAppDetail)
      throws IOException, RegistryException, AppManagementException, InterruptedException {
    String currentUserName = webAppDetail.getUserName();
    String creatorSession = webAppDetail.getCreatorSession();
    httpHandler.doPostHttps(
        httpsBackEndUrl + "/publisher/asset/webapp",
        payload,
        creatorSession,
        "application/x-www-form-urlencoded");

    JSONArray claimsAry = new JSONArray();
    ConcurrentHashMap<String, String[]> claimMap = webAppDetail.getClaims();
    Iterator entries = claimMap.entrySet().iterator();
    while (entries.hasNext()) {
      Map.Entry thisEntry = (Map.Entry) entries.next();
      String claimName = ((String[]) thisEntry.getValue())[0];
      claimsAry.add(claimName);
    }
    JSONObject configJson = new JSONObject();
    configJson.put("provider", "wso2is-5.0.0"); // use a constant
    configJson.put("logout_url", "");
    configJson.put("claims", claimsAry);
    configJson.put("app_name", webAppDetail.getWebAppName());
    configJson.put("app_verison", webAppDetail.getVersion());
    configJson.put("app_transport", "http");
    configJson.put("app_context", webAppDetail.getContext());
    configJson.put("app_provider", webAppDetail.getUserName());
    configJson.put("app_allowAnonymous", "false");
    configJson.put("app_acsURL", "");
    httpHandler.doPostHttps(
        httpsBackEndUrl + "/publisher/api/sso/addConfig",
        configJson.toJSONString(),
        creatorSession,
        "application/json; charset=UTF-8");
    String appPath =
        "/_system/governance/appmgt/applicationdata/provider/"
            + currentUserName
            + "/"
            + webAppDetail.getWebAppName()
            + "/1.0.0/webapp";
    String UUID = wsRegistryServiceClient.getUUID(appPath);
    String trackingIDResponse =
        httpHandler
            .doGet(
                httpsBackEndUrl + "/publisher/api/asset/webapp/trackingid/" + UUID,
                "",
                creatorSession,
                "")
            .split(":")[1]
            .trim();
    String trackingID = trackingIDResponse.substring(1, (trackingIDResponse.length() - 2));
    webAppDetail.setTrackingCode(trackingID);
    invokeStatistcsJavascriptBuilder =
        new InvokeStatistcsJavascriptBuilder(
            trackingID, ipAddress, Configuration.getGatewayPort("http"));
    if (webAppDetail.getWebAppName().equals("PlanYourTrip_" + currentUserName)) {
      invokeStatistcsJavascriptBuilder.buildInvokeStaticsJavascriptFile(
          appmHomePath + "/repository/deployment/server/webapps/plan-your-trip-1.2.0");
    } else if (webAppDetail.getWebAppName().equals("TravelBooking_" + currentUserName)) {
      invokeStatistcsJavascriptBuilder.buildInvokeStaticsJavascriptFile(
          appmHomePath + "/repository/deployment/server/webapps/travel-booking-1.2.0/js");
    }
    log.info(webAppDetail.getWebAppName() + " created and UUID is : " + UUID);
    return UUID;
  }