コード例 #1
0
ファイル: NCubeManager.java プロジェクト: ccriderGAIG/n-cube
  public static List<NCube> getNCubesFromResource(String name) {
    String lastSuccessful = "";
    try {
      Object[] cubes = getJsonObjectFromResource(name);
      List<NCube> cubeList = new ArrayList<>(cubes.length);

      for (Object cube : cubes) {
        JsonObject ncube = (JsonObject) cube;
        String json = JsonWriter.objectToJson(ncube);
        NCube nCube = NCube.fromSimpleJson(json);
        nCube.sha1();
        addCube(nCube.getApplicationID(), nCube);
        lastSuccessful = nCube.getName();
        cubeList.add(nCube);
      }

      return cubeList;
    } catch (Exception e) {
      String s =
          "Failed to load cubes from resource: "
              + name
              + ", last successful cube: "
              + lastSuccessful;
      LOG.warn(s);
      throw new RuntimeException(s, e);
    }
  }
コード例 #2
0
  /** {@inheritDoc} */
  @SuppressWarnings("rawtypes")
  @Override
  public JSONObject serialize(final BasicOperator operator, final int node_id)
      throws JSONException {
    final JSONObject json = new JSONObject();
    /*
     * store preceeding's and remove them from the subgraph, because they
     * are not to be serialized (but they are added later)
     */
    final List<BasicOperator> storePrecds =
        new LinkedList<BasicOperator>(((SubgraphContainer) operator).getPrecedingOperators());
    for (final BasicOperator op : storePrecds) {
      ((SubgraphContainer) operator).removePrecedingOperator(op);
    }
    /*
     * store succeeding's and remove them from the subgraph (see above)
     */
    final List<OperatorIDTuple> storeSuccs =
        new LinkedList<OperatorIDTuple>(((SubgraphContainer) operator).getSucceedingOperators());
    for (final OperatorIDTuple op : storeSuccs) {
      ((SubgraphContainer) operator).removeSucceedingOperator(op);
    }

    json.put("type", operator.getClass().getName());
    json.put("node_id", node_id);

    /*
     * now serialize the subgraph container
     */
    final SubgraphContainerFormatter serializer = new SubgraphContainerFormatter();
    final JSONObject serializedGraph =
        serializer.serialize(((SubgraphContainer) operator).getRootOfSubgraph(), 0);
    json.put("subgraph", serializedGraph);

    /*
     * now serialize the subgraph container's key
     */
    final Object key = ((SubgraphContainer) operator).getKey();
    try {
      final String sgKey = JsonWriter.objectToJson(key);
      json.put("key", sgKey);
    } catch (final IOException e) {
      json.put("key", "Not serializable.");
      propagate(
          new RuntimeException(
              String.format("The key of subgraphContainer %s is not serialzable.", operator)));
    }

    // now add the connections ... we have removed above.
    for (final BasicOperator op : storePrecds) {
      ((SubgraphContainer) operator).addPrecedingOperator(op);
    }
    for (final OperatorIDTuple op : storeSuccs) {
      ((SubgraphContainer) operator).addSucceedingOperator(op);
    }
    return json;
  }
コード例 #3
0
  public void formatTokensForHTML(
      HttpServletRequest request, String requestToken, String responseToken) {

    if (requestToken == null) {
      requestToken = "..";
    }
    ;
    if (responseToken == null) {
      responseToken = "..";
    }
    ;

    String[] requestTokenComponents = requestToken.split("\\.");
    String[] responseTokenComponents = responseToken.split("\\.");

    request.setAttribute("requestTokenHeader", requestTokenComponents[0]);
    request.setAttribute(
        "requestTokenHeaderJSON",
        JsonWriter.formatJson(new String(Base64.decode(requestTokenComponents[0]))));

    request.setAttribute("requestTokenPayload", requestTokenComponents[1]);
    request.setAttribute(
        "requestTokenPayloadJSON",
        JsonWriter.formatJson(new String(Base64.decode(requestTokenComponents[1]))));

    request.setAttribute("requestTokenSignature", requestTokenComponents[2]);
    request.setAttribute("requestTokenSignatureJSON", "HMAC-SHA256 Signature");

    request.setAttribute("responseTokenHeader", responseTokenComponents[0]);
    request.setAttribute(
        "responseTokenHeaderJSON",
        JsonWriter.formatJson(new String(Base64.decode(responseTokenComponents[0]))));

    request.setAttribute("responseTokenPayload", responseTokenComponents[1]);
    request.setAttribute(
        "responseTokenPayloadJSON",
        JsonWriter.formatJson(new String(Base64.decode(responseTokenComponents[1]))));

    request.setAttribute("responseTokenSignature", responseTokenComponents[2]);
    request.setAttribute("responseTokenSignatureJSON", "HMAC-SHA256 Signature");
  }