public InvResourceAvailReport[] getInvResourceAvailReport() {
    ServiceManager serviceManager = new ServiceManager();
    InvResourceAvailReport[] InvResourceAvailReportArray = null;

    /* String resourceGrpFrom = AdfmfJavaUtilities.getELValue("#{pageFlowScope.jobFrom}").toString();
    String resourceGrpTo = AdfmfJavaUtilities.getELValue("#{pageFlowScope.jobTo}").toString();
    String resourceFrom = AdfmfJavaUtilities.getELValue("#{pageFlowScope.assemblyFrom}").toString();
    String resourceTo = AdfmfJavaUtilities.getELValue("#{pageFlowScope.assemblyTo}").toString();
        String projectName = AdfmfJavaUtilities.getELValue("#{pageFlowScope.jobStatus}").toString();
    String onDate = AdfmfJavaUtilities.getELValue("#{pageFlowScope.dateFrom}").toString();
    String timeFrame = AdfmfJavaUtilities.getELValue("#{pageFlowScope.dateTo}").toString();
     */

    String resourceGrpFrom =
        AdfmfJavaUtilities.getELValue("#{pageFlowScope.resourceGrp}").toString();
    String resourceGrpTo =
        AdfmfJavaUtilities.getELValue("#{pageFlowScope.resourceGrpTo}").toString();
    String resourceFrom = AdfmfJavaUtilities.getELValue("#{pageFlowScope.resource}").toString();
    String resourceTo = AdfmfJavaUtilities.getELValue("#{pageFlowScope.resourceTo}").toString();
    String projectName = AdfmfJavaUtilities.getELValue("#{pageFlowScope.projectName}").toString();
    String onDate = "-999";
    String timeFrame = "-999";

    String jsonArrayAsString =
        serviceManager.invokeREAD(
            RestURIs.getResourceAvailReportURI(
                resourceGrpFrom,
                resourceGrpTo,
                resourceFrom,
                resourceTo,
                projectName,
                onDate,
                timeFrame));
    //   System.out.println(jsonArrayAsString);
    try {
      JSONObject jsonObject = new JSONObject(jsonArrayAsString);
      JSONObject parent = jsonObject.getJSONObject("X_RESOURCE_AVAIL_TAB");
      JSONArray nodeArray = parent.getJSONArray("X_RESOURCE_AVAIL_TAB_ITEM");
      //   System.out.println(parent);
      int size = nodeArray.length();
      for (int i = 0; i < size; i++) {

        JSONObject temp = nodeArray.getJSONObject(i);

        String resourceName = temp.getString("RESOURCE_NAME");
        BigDecimal perUtilization = new BigDecimal(temp.getString("PER_UTILIZATION"));

        InvResourceAvailReport InvResourceAvail =
            new InvResourceAvailReport(resourceName, perUtilization);

        InvResourceAvailReportList.add(InvResourceAvail);
      }
      InvResourceAvailReportArray =
          InvResourceAvailReportList.toArray(
              new InvResourceAvailReport[InvResourceAvailReportList.size()]);
    } catch (Exception e) {
      e.getMessage();
      System.out.println(e.getMessage());
    }
    return InvResourceAvailReportArray;
  }
  public BuyerPieChart[] getBuyerPieChart() {
    ServiceManager serviceManager = new ServiceManager();
    BuyerPieChart[] buyerPieChartArray = null;

    //   String jsonArrayAsString =
    // serviceManager.invokeREAD(RestURIs.getBuyerDashboardURI("57","JAN-15","82","BUYER_PIE_CHART"));
    String periodParam = null;
    String operatingUnit = null;
    Connection conn = null;
    Statement stmt = null;
    try {
      conn = ConnectionFactory.getConnection();
      stmt = conn.createStatement();
      ResultSet result =
          stmt.executeQuery(
              "SELECT SAVED.DASHBOARD_TYPE , SAVED.PARAM_NAME ,SAVED.PARAM_VALUE FROM DASHBOARD_PARAMS SAVED WHERE SAVED.DASHBOARD_TYPE='BUYERS'");

      while (result.next()) {
        String paramName = result.getString("PARAM_NAME");
        String paramValue = result.getString("PARAM_VALUE");
        if (paramName.equals("CURRENT_PERIOD".toString())) {
          periodParam = paramValue;
        } else if (paramName.equals("OPERATING_UNIT".toString())) {
          operatingUnit = paramValue;
        }
      }
    } catch (Exception e) {
      periodParam = "JAN-15";
      operatingUnit = "82";
    }
    /* Call web Service */
    String jsonArrayAsString =
        serviceManager.invokeREAD(
            RestURIs.getBuyerDashboardURI("59", periodParam, operatingUnit, "BUYER_PIE_CHART"));

    try {
      JSONObject jsonObject = new JSONObject(jsonArrayAsString);
      JSONObject parent = jsonObject.getJSONObject("X_BUYER_PIE_CHART_TAB");
      JSONArray nodeArray = parent.getJSONArray("X_BUYER_PIE_CHART_TAB_ITEM");
      //   System.out.println(parent);
      buyerPieChartList.clear();
      int size = nodeArray.length();
      for (int i = 0; i < size; i++) {

        JSONObject temp = nodeArray.getJSONObject(i);

        String buyerName = temp.getString("BUYER_NAME");
        BigDecimal buyerPoolPercent = new BigDecimal(temp.getString("BUYER_POOOL_PERCENT"));
        BigDecimal poAwaitingApprovalPercent =
            new BigDecimal(temp.getString("PO_AWAITING_APPROVAL_PERCENT"));
        BigDecimal poAwaitingShippingPercent =
            new BigDecimal(temp.getString("PO_AWAITING_SHIPPING_PERCENT"));
        BigDecimal poIncompletePercent = new BigDecimal(temp.getString("PO_INCOMPLETE_PERCENT"));
        BigDecimal recordId = new BigDecimal(temp.getString("RECORD_ID"));

        BuyerPieChart buyerPieChart1 =
            new BuyerPieChart(buyerName, "Buyer Pool Percent", buyerPoolPercent, recordId);
        buyerPieChartList.add(buyerPieChart1);

        BuyerPieChart buyerPieChart2 =
            new BuyerPieChart(
                buyerName, "PO Awaiting Approval Percent", poAwaitingApprovalPercent, recordId);
        buyerPieChartList.add(buyerPieChart2);
        BuyerPieChart buyerPieChart3 =
            new BuyerPieChart(
                buyerName, "PO Awaiting Shipping Percent", poAwaitingShippingPercent, recordId);
        buyerPieChartList.add(buyerPieChart3);
        BuyerPieChart buyerPieChart4 =
            new BuyerPieChart(buyerName, "PO Incomplete Percent", poIncompletePercent, recordId);
        buyerPieChartList.add(buyerPieChart4);
      }
      buyerPieChartArray = buyerPieChartList.toArray(new BuyerPieChart[buyerPieChartList.size()]);
    } catch (Exception e) {
      e.getMessage();
      System.out.println(e.getMessage());
    }
    return buyerPieChartArray;
  }
  public static PlacesResponse transformObject(ServiceResult service) {
    PlacesResponse response = new PlacesResponse();
    response.setStatus(service.getStatus());

    PlacesResultList results = new PlacesResultList();
    response.setResults(results);

    JSONArray resultList = service.getResults();
    for (int i = 0; i < resultList.length(); i++) {
      try {
        PlacesResult placesResult = new PlacesResult();
        JSONObject result = resultList.getJSONObject(i);

        if (result.get("icon") != null) {
          placesResult.setIcon((String) result.get("icon"));
        }

        if (result.get("name") != null) {
          placesResult.setName((String) result.get("name"));
        }

        if (result.get("vicinity") != null) {
          placesResult.setVicinity((String) result.get("vicinity"));
        }

        if (result.get("rating") != null) {

          // workaround for rating without decimal place (being Integer instead of Double)
          String stringDouble = result.get("rating") + "";

          if (stringDouble.indexOf(".") == -1) {
            stringDouble = stringDouble + ".0";
          }
          Double ratingDouble = Double.valueOf(stringDouble);
          placesResult.setRating(ratingDouble);
        }

        if (result.get("types") != null) {
          JSONArray types = (JSONArray) result.get("types");
          String placesType = "";
          for (int p = 0; p < types.length(); p++) {
            placesType += types.get(p) + ",";
          }
          placesResult.setTypes(placesType);
        }
        results.addPlacesResult(placesResult);
        if (result.get("geometry") != null) {
          JSONObject geometry = (JSONObject) result.get("geometry");
          PlacesGeometry geo = new PlacesGeometry();

          if (geometry.get("location") != null) {
            JSONObject location = (JSONObject) geometry.get("location");

            LatLng latLng = new LatLng();
            latLng.setLat(location.getDouble("lat"));
            latLng.setLng(location.getDouble("lng"));
            geo.setLocation(latLng);
          }

          placesResult.setGeometry(geo);
        }

      } catch (JSONException e) {
      }
    }
    return response;
  }