Ejemplo n.º 1
0
  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String thisUsersId = req.getParameter("userId");
    if ("true".equals(req.getParameter("pingAlive"))) {
      updateLastAliveTime(thisUsersId);
    } else {
      ObjectMapper mapper = new ObjectMapper();

      ArrayNode usersArray = mapper.createArrayNode();

      for (Map.Entry<String, User> userEntry : users.entrySet()) {
        if (!thisUsersId.equals(userEntry.getKey())) {
          User user = userEntry.getValue();
          Date now = new Date();
          if ((now.getTime() - user.getLastAliveTime().getTime()) / 1000 <= 10) {
            ObjectNode userJson = mapper.createObjectNode();
            userJson.put("user_id", userEntry.getKey());
            userJson.put("user_name", user.getName());
            usersArray.add(userJson);
          }
        }
      }

      ObjectNode usersJson = mapper.createObjectNode();
      usersJson.put("opponents", usersArray);

      resp.setContentType("application/json; charset=UTF-8");
      mapper.writeValue(resp.getWriter(), usersJson);
    }
  }
Ejemplo n.º 2
0
  @Test
  public void testGroupByWithSum1()
      throws JsonGenerationException, JsonMappingException, IOException, InterruptedException {
    Object[][] rows1 = {{0}, {2}, {2}, {5}, {10}, {100}};
    Block block = new ArrayBlock(Arrays.asList(rows1), new String[] {"a"}, 1);

    TupleOperator operator = new GroupByOperator();
    Map<String, Block> input = new HashMap<String, Block>();
    input.put("first", block);

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode json = mapper.createObjectNode();
    json.put("input", "first");
    ArrayNode anode = mapper.createArrayNode();
    anode.add("a");
    json.put("groupBy", anode);
    anode = mapper.createArrayNode();
    ObjectNode onode = mapper.createObjectNode();
    onode.put("type", "SUM");
    onode.put("input", "a");
    onode.put("output", "sum");
    anode.add(onode);
    json.put("aggregates", anode);

    BlockProperties props =
        new BlockProperties(null, new BlockSchema("INT a, INT sum"), (BlockProperties) null);
    operator.setInput(input, json, props);

    Block output = new TupleOperatorBlock(operator, props);

    ArrayBlock.assertData(
        output,
        new Object[][] {{0, 0}, {2, 4}, {5, 5}, {10, 10}, {100, 100}},
        new String[] {"a", "sum"});
  }
Ejemplo n.º 3
0
 /**
  * Convenience method for creating an error response
  *
  * @param jsonRpc the jsonrpc string
  * @param id the id
  * @param code the error code
  * @param message the error message
  * @param data the error data (if any)
  * @return the error response
  */
 private ObjectNode createErrorResponse(
     String jsonRpc, String id, int code, String message, Object data) {
   ObjectNode response = mapper.createObjectNode();
   ObjectNode error = mapper.createObjectNode();
   error.put("code", code);
   error.put("message", message);
   if (data != null) {
     error.put("data", mapper.valueToTree(data));
   }
   response.put("jsonrpc", jsonRpc);
   response.put("id", id);
   response.put("error", error);
   return response;
 }
Ejemplo n.º 4
0
  @Test
  public void testMergeJoinFullOuterEmptyRight()
      throws JsonGenerationException, JsonMappingException, IOException, InterruptedException {
    Object[][] rows1 = {{0}, {2}, {2}, {5}, {10}, {100}};
    Object[][] rows2 = {};
    Object[][] expected = {{0, null}, {2, null}, {2, null}, {5, null}, {10, null}, {100, null}};

    Block block1 = new ArrayBlock(Arrays.asList(rows1), new String[] {"a"});
    Block block2 = new ArrayBlock(Arrays.asList(rows2), new String[] {"a"});

    TupleOperator operator = new MergeJoinOperator();
    Map<String, Block> input = new HashMap<String, Block>();
    input.put("block1", block1);
    input.put("block2", block2);

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode node = mapper.createObjectNode();
    node.put("leftCubeColumns", "a");
    node.put("rightCubeColumns", "a");
    node.put("leftBlock", "block1");
    node.put("rightBlock", "block2");
    node.put("joinType", "full outer");
    BlockProperties props =
        new BlockProperties(
            null, new BlockSchema("INT block1___a, INT block2___a"), (BlockProperties) null);
    operator.setInput(input, node, props);

    Block output = new TupleOperatorBlock(operator, props);

    ArrayBlock.assertData(output, expected, new String[] {"block1.a", "block2.a"});
    System.out.println("Successfully tested MERGE JOIN FULL OUTER empty block");
  }
Ejemplo n.º 5
0
  public String createChallangeNAClaims(String req, String claimDefs, int size) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode claimDefNodes = (ArrayNode) mapper.readTree(claimDefs);

    req = req.replaceAll("\"", "");
    byte[] reqElemBytes = Base64.decode(req);

    Element reqElem = null;
    ArrayList<IdentityClaimDefinition> icds = new ArrayList<IdentityClaimDefinition>();

    for (int i = 0; i < size; i++) {
      String onVal = claimDefNodes.get(i).getTextValue();

      ObjectNode claimDefOn = (ObjectNode) mapper.readTree(onVal);
      IdentityClaimDefinition idClaimDef = new IdentityClaimDefinition(claimDefOn);
      icds.add(idClaimDef);

      if (reqElem == null) {
        Pairing pairing = idClaimDef.getParams().getPairing();
        reqElem = pairing.getG1().newElement();
        reqElem.setFromBytes(reqElemBytes);
        //				System.out.println(reqElem);
      }
    }

    Pairing pairing = icds.get(0).getParams().getPairing();
    Field gt = pairing.getGT();
    Element sessionKey = gt.newRandomElement().getImmutable();
    Element sessionKeyOrig = sessionKey.getImmutable();
    // System.out.println("Key: " + sessionKey);

    JsonNode rootNode = mapper.createObjectNode();
    ObjectNode on = (ObjectNode) rootNode;
    Encrypt encrypt = new Encrypt();

    for (int i = 0; i < size; i++) {
      IdentityClaimDefinition claimDef = icds.get(i);

      Element share = null;
      if (i < (size - 1)) {
        share = gt.newRandomElement().getImmutable();
        sessionKey = sessionKey.sub(share).getImmutable();
      } else {
        // Last one should be the remaining part of session key
        share = sessionKey;
      }

      encrypt.init(claimDef.getParams());
      // System.out.println("Part : " + i + " : " + share);
      AECipherTextBlock ct = encrypt.doEncrypt(share, reqElem);

      on.put(claimDef.getName(), ct.serializeJSON());
    }

    //		System.out.println(sessionKeyOrig);
    String sk = new String(Base64.encode(sessionKeyOrig.toBytes()));
    sk = sk.replaceAll(" ", "");
    on.put("SessionKey", sk);
    return on.toString();
  }
Ejemplo n.º 6
0
  /**
   * Create a session key, encrypt it with the given request and claimDef. Return a serialized JSON
   * node with the session key and challenge.
   *
   * @param request Request from user: Base64 encoded bytes of the request element.
   * @param claimDef Claim definition to use: JSON encoded
   * @return
   * @throws Exception
   */
  public String createChallange(String request, String claimDef) throws Exception {

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode claimDefOn = (ObjectNode) mapper.readTree(claimDef);
    IdentityClaimDefinition idClaimDef = new IdentityClaimDefinition(claimDefOn);

    byte[] reqElemBytes = Base64.decode(request);
    Element reqElem = idClaimDef.getParams().getPairing().getG1().newElement();
    reqElem.setFromBytes(reqElemBytes);

    Element sessionKey =
        idClaimDef.getParams().getPairing().getGT().newRandomElement().getImmutable();

    // Encrypt session key
    Encrypt encrypt = new Encrypt();
    encrypt.init(idClaimDef.getParams());
    AECipherTextBlock ct = encrypt.doEncrypt(sessionKey, reqElem);

    JsonNode rootNode = mapper.createObjectNode();
    ObjectNode on = (ObjectNode) rootNode;

    on.put(idClaimDef.getName(), ct.serializeJSON());
    String sk = new String(Base64.encode(sessionKey.toBytes()));
    sk = sk.replaceAll(" ", "");
    on.put("SessionKey", sk);

    return on.toString();
  }
Ejemplo n.º 7
0
  @Test
  public void testSortOperator()
      throws JsonGenerationException, JsonMappingException, IOException, InterruptedException {
    System.out.println("Testing SORT operator");

    Object[][] rows1 = {{0, 10, 0}, {2, 5, 2}, {2, 8, 5}, {5, 9, 6}, {10, 11, 1}, {100, 6, 10}};
    Block block = new ArrayBlock(Arrays.asList(rows1), new String[] {"a", "b", "c"}, 1);

    TupleOperator operator = new SortOperator();
    Map<String, Block> input = new HashMap<String, Block>();
    input.put("unsorted", block);

    ObjectMapper mapper = new ObjectMapper();

    ObjectNode json = mapper.createObjectNode();
    json.put("input", "unsorted");
    ArrayNode anode = mapper.createArrayNode();
    anode.add("b");
    anode.add("c");
    json.put("sortBy", anode);

    BlockProperties props =
        new BlockProperties(null, new BlockSchema("INT a, INT b, INT c"), (BlockProperties) null);
    operator.setInput(input, json, props);

    Block output = new TupleOperatorBlock(operator, props);

    System.out.println("output is " + output);
    ArrayBlock.assertData(
        output,
        new Object[][] {{2, 5, 2}, {100, 6, 10}, {2, 8, 5}, {5, 9, 6}, {0, 10, 0}, {10, 11, 1}},
        new String[] {"a", "b", "c"});
  }
Ejemplo n.º 8
0
 /**
  * @param keyValues The map to turn into the string.
  * @return A string of format {"key":"value",...}
  */
 String getMessagesFromMap(final Map<String, String> keyValues) {
   ObjectNode node = objectMapper.createObjectNode();
   for (Map.Entry<String, String> entry : keyValues.entrySet()) {
     node.put(entry.getKey(), entry.getValue());
   }
   return node.size() > 0 ? node.toString() : null;
 }
Ejemplo n.º 9
0
  @Test
  // when there are multiple rows in one table
  public void testMergeJoin4()
      throws JsonGenerationException, JsonMappingException, IOException, InterruptedException {
    Object[][] rows1 = {{0}, {2}, {2}, {5}, {10}, {100}};
    Object[][] rows2 = {{1}, {2}, {7}, {9}, {100}, {100}};
    Object[][] expected = {{2, 2}, {2, 2}, {100, 100}, {100, 100}};

    Block block1 = new ArrayBlock(Arrays.asList(rows1), new String[] {"a"});
    Block block2 = new ArrayBlock(Arrays.asList(rows2), new String[] {"a"});

    TupleOperator operator = new MergeJoinOperator();
    Map<String, Block> input = new HashMap<String, Block>();
    input.put("block1", block1);
    input.put("block2", block2);

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode node = mapper.createObjectNode();
    node.put("leftCubeColumns", "a");
    node.put("rightCubeColumns", "a");
    node.put("leftBlock", "block1");

    BlockProperties props =
        new BlockProperties(
            null, new BlockSchema("INT block1___a, INT block2___a"), (BlockProperties) null);
    operator.setInput(input, node, props);

    Block output = new TupleOperatorBlock(operator, props);

    ArrayBlock.assertData(output, expected, new String[] {"block1.a", "block2.a"});
  }
Ejemplo n.º 10
0
  @Test
  public void testCombinedBlockLeftRunsout()
      throws JsonGenerationException, JsonMappingException, IOException, InterruptedException {
    Object[][] rows1 = {{2}, {7}, {9}};
    Object[][] rows2 = {{3}, {5}, {10}};

    Block block1 = new ArrayBlock(Arrays.asList(rows1), new String[] {"a"}, 1);
    Block block2 = new ArrayBlock(Arrays.asList(rows2), new String[] {"a"}, 1);

    TupleOperator operator = new CombineOperator();
    Map<String, Block> input = new HashMap<String, Block>();
    input.put("cube1", block1);
    input.put("cube2", block2);

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode node = mapper.createObjectNode();
    JsonNode ct = mapper.readValue("[\"a\"]", JsonNode.class);
    node.put("pivotBy", ct);

    BlockProperties props =
        new BlockProperties(null, new BlockSchema("INT a"), (BlockProperties) null);
    operator.setInput(input, node, props);

    Block output = new TupleOperatorBlock(operator, props);

    ArrayBlock.assertData(
        output, new Object[][] {{2}, {3}, {5}, {7}, {9}, {10}}, new String[] {"a"});
  }
Ejemplo n.º 11
0
  public void testDictionaryEncoding() throws IOException, InterruptedException {
    // create dictionary block
    Object[][] dictRows = {{1000, 100, 1}, {1000, 101, 2}};
    Block dictionary =
        new ArrayBlock(Arrays.asList(dictRows), new String[] {"colname", "colvalue", "code"});

    // create data block
    Object[][] dataRows = {{100, 10}, {100, 11}, {101, 10}};
    Block dataBlock = new ArrayBlock(Arrays.asList(dataRows), new String[] {"1000", "a"});

    // create operator
    Map<String, Block> input = new HashMap<String, Block>();
    input.put("block1", dictionary);
    input.put("block2", dataBlock);
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode node = mapper.createObjectNode();
    node.put("dictionary", "block1");

    TupleOperator operator = new DictionaryEncodeOperator();
    BlockProperties props =
        new BlockProperties(null, new BlockSchema("INT 1000, INT a"), (BlockProperties) null);
    operator.setInput(input, node, props);

    Block output = new TupleOperatorBlock(operator, props);

    Object[][] expected = {{1, 10}, {1, 11}, {2, 10}};

    ArrayBlock.assertData(output, expected, new String[] {"1000", "a"});
  }
  public ObjectNode processMutHm(long entrezGeneId, ArrayList<Integer> sampleList, HashMap mutHm) {
    ObjectNode _datum = mapper.createObjectNode();

    // create map to pair sample and value
    HashMap<Integer, String> mapSampleValue = new HashMap<>();
    for (Integer sampleId :
        sampleList) { // Assign every sample (included non mutated ones) values -- mutated ->
                      // Mutation Type, non-mutated -> "Non"
      String mutationStatus = "Non";
      String tmpStr =
          new StringBuilder()
              .append(Integer.toString(sampleId))
              .append(Long.toString(entrezGeneId))
              .toString();
      if (mutHm.containsKey(tmpStr)) mutationStatus = "Mutated";
      mapSampleValue.put(sampleId, mutationStatus);
    }

    // remove empty entry
    Iterator it = mapSampleValue.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pair = (Map.Entry) it.next();
      if (pair.getValue().equals("NA")
          || pair.getValue().equals("NaN")
          || pair.getValue().equals("null")) {
        it.remove();
      }
    }

    // get Gene Name and Cytoband
    DaoGeneOptimized daoGeneOptimized = DaoGeneOptimized.getInstance();
    String geneName = daoGeneOptimized.getGene(entrezGeneId).getHugoGeneSymbolAllCaps();
    String cytoband = daoGeneOptimized.getGene(entrezGeneId).getCytoband();

    // statistics analysis
    if (!(Arrays.asList(queriedGenes)).contains(geneName)) { // remove queried genes from result
      _datum.put(COL_NAME_GENE, geneName);
      _datum.put(COL_NAME_CYTOBAND, cytoband);
      _datum.put(COL_NAME_PCT_ALTERED, calcPct(mapSampleValue, profileType, "altered"));
      _datum.put(COL_NAME_PCT_UNALTERED, calcPct(mapSampleValue, profileType, "unaltered"));
      _datum.put(
          COL_NAME_RATIO,
          calcRatio(
              calcPct(mapSampleValue, profileType, "altered"),
              calcPct(mapSampleValue, profileType, "unaltered")));
      _datum.put(COL_NAME_DIRECTION, "place holder"); // calculation is done by the front-end
      _datum.put(COL_NAME_P_VALUE, calcPval(mapSampleValue, profileType, geneticProfileStableId));
      if (!(calcPct(mapSampleValue, profileType, "altered") == 0.0
              && calcPct(mapSampleValue, profileType, "unaltered") == 0.0)
          && !Double.isNaN(calcPval(mapSampleValue, profileType, geneticProfileStableId))) {
        return _datum;
      }
    }

    return null;
  }
 public JsonNode serialize(Locale locale, ObjectMapper mapper) {
   final ObjectNode jsonOverview = mapper.createObjectNode();
   if (this.getLastResult() != null) {
     jsonOverview.put("text_result", this.getLastResult().getTextResult());
     jsonOverview.put("content_type", this.getLastResult().getContentType());
   } else {
     jsonOverview.put("text_result", (String) null);
     jsonOverview.put("content_type", (String) null);
   }
   return jsonOverview;
 }
Ejemplo n.º 14
0
  @Test
  public void showRoles() {
    ObjectMapper m = new ObjectMapper();
    ObjectNode body = m.createObjectNode();
    body.put("domain_object", "system");
    body.put("user", "datenbereitstellera");

    JsonNode node = client.showRoles(body);

    log.info("roles: {}", node.toString());
  }
Ejemplo n.º 15
0
  @Test
  public void showUser() {
    ObjectMapper m = new ObjectMapper();
    ObjectNode body = m.createObjectNode();

    ClientResponse<JsonNode> response =
        client.showUser(
            (String) properties.getProperty(PROPERTY_NAME_CKAN_AUTHORIZATION_KEY), body);
    if (response.getStatus() == Response.Status.OK.getStatusCode()) {
      log.info(response.getEntity().toString());
    }
  }
Ejemplo n.º 16
0
 public String toJson(ObjectMapper mapper) {
   ObjectNode rootNode = mapper.createObjectNode();
   ArrayNode keysNode = rootNode.putArray("keys");
   for (Object key : keys) {
     keysNode.addPOJO(key);
   }
   try {
     return mapper.writeValueAsString(rootNode);
   } catch (Exception e) {
     throw Exceptions.propagate(e);
   }
 }
  /**
   * Calculate the results graph data. The graph includes final rank graph and final vs provisional
   * score graph.
   *
   * @param resultInfos the results
   */
  private void calculateResultsGraphData(List<ResultInfo> resultInfos) {
    // Sort the results info by final score.
    Collections.sort(
        resultInfos,
        new Comparator<ResultInfo>() {
          public int compare(ResultInfo resultInfo, ResultInfo resultInfo2) {
            if (resultInfo.getFinalRank() < resultInfo2.getFinalRank()) {
              return 0;
            }
            if (resultInfo.getFinalRank() == resultInfo2.getFinalRank()) {
              return String.CASE_INSENSITIVE_ORDER.compare(
                  resultInfo.getHandle(), resultInfo2.getHandle());
            }
            return 1;
          }
        });
    ObjectMapper objectMapper = new ObjectMapper();
    ObjectNode finalScoreRankingData = objectMapper.createObjectNode();
    ObjectNode finalVsProvisionalScoreData = objectMapper.createObjectNode();
    ArrayNode rating = objectMapper.createArrayNode();
    ArrayNode score = objectMapper.createArrayNode();
    for (ResultInfo result : resultInfos) {
      ObjectNode finalScoreNode = objectMapper.createObjectNode();
      finalScoreNode.put("handle", result.getHandle());
      finalScoreNode.put("number", result.getFinalScore());
      finalScoreNode.put("rank", result.getFinalRank());
      rating.add(finalScoreNode);

      ObjectNode finalProvisionalScoreNode = objectMapper.createObjectNode();
      finalProvisionalScoreNode.put("handle", result.getHandle());
      finalProvisionalScoreNode.put("finalScore", result.getFinalScore());
      finalProvisionalScoreNode.put("provisionalScore", result.getProvisionalScore());
      score.add(finalProvisionalScoreNode);
    }
    finalScoreRankingData.put("rating", rating);
    finalVsProvisionalScoreData.put("score", score);

    viewData.setFinalScoreRankingData(finalScoreRankingData.toString());
    viewData.setFinalVsProvisionalScoreData(finalVsProvisionalScoreData.toString());
  }
Ejemplo n.º 18
0
  public static void main(String args[]) {

    JacksonTester tester = new JacksonTester();

    try {
      ObjectMapper mapper = new ObjectMapper();

      JsonNode rootNode = mapper.createObjectNode();
      JsonNode marksNode = mapper.createArrayNode();

      ((ArrayNode) marksNode).add(100);
      ((ArrayNode) marksNode).add(90);
      ((ArrayNode) marksNode).add(85);

      ((ObjectNode) rootNode).put("name", "Mahesh Kumar");
      ((ObjectNode) rootNode).put("age", 21);
      ((ObjectNode) rootNode).put("verified", false);
      ((ObjectNode) rootNode).put("marks", marksNode);

      mapper.writeValue(new File("student.json"), rootNode);

      rootNode = mapper.readTree(new File("student.json"));

      JsonNode nameNode = rootNode.path("name");
      System.out.println("Name: " + nameNode.getTextValue());

      JsonNode ageNode = rootNode.path("age");
      System.out.println("Age: " + ageNode.getIntValue());

      JsonNode verifiedNode = rootNode.path("verified");
      System.out.println("Verified: " + (verifiedNode.getBooleanValue() ? "Yes" : "No"));

      JsonNode marksNode1 = rootNode.path("marks");
      Iterator<JsonNode> iterator = marksNode1.getElements();
      System.out.print("Marks: [ ");

      while (iterator.hasNext()) {
        JsonNode marks = iterator.next();
        System.out.print(marks.getIntValue() + " ");
      }

      System.out.println("]");
    } catch (JsonParseException e) {
      e.printStackTrace();
    } catch (JsonMappingException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 19
0
  public List<String> map(String metrics, Map<String, String> tags) {
    try {
      ObjectMapper objectMapper = new ObjectMapper();
      JsonNode jsonNode = objectMapper.readTree(metrics);

      ObjectNode objectNode = objectMapper.createObjectNode();
      objectNode.put("@timestamp", System.currentTimeMillis());
      objectNode.put("metrics", jsonNode);
      for (Map.Entry<String, String> tag : tags.entrySet()) {
        objectNode.put(tag.getKey(), tag.getValue());
      }
      return ImmutableList.of(objectMapper.writeValueAsString(objectNode));
    } catch (IOException e) {
      throw new RuntimeException("Failed to create metrics", e);
    }
  }
Ejemplo n.º 20
0
  public JsonNode getTask(
      FramedGraph<OrientBaseGraph> orientGraph, ObjectMapper objectMapper, String taskJid) {
    final ORID taskRid = RidConverter.convertToRID(taskJid);
    final XTask task = orientGraph.getVertex(taskRid, XTask.class);
    if (task == null)
      throw new ObjectNotFoundException("Task with jid " + taskJid + " does not exist.");

    ObjectNode result = objectMapper.createObjectNode();
    result.put("status", task.getStatus());

    DateFormat dateFormat = DateFormat.getDateTimeInstance();
    result.put("startTime", dateFormat.format(task.getStartTime()));

    result.put("jid", RidConverter.convertFromRID((ORID) task.asVertex().getId()));

    return result;
  }
Ejemplo n.º 21
0
  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    String lastUserIdStr = null;
    String userName = req.getParameter("user_name");
    synchronized (this) {
      lastUserIdStr = Integer.toString(++lastUserId);
      User user = new User(lastUserIdStr, userName, new Date());
      users.put(lastUserIdStr, user);
    }

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode userJson = mapper.createObjectNode();
    userJson.put("user_id", lastUserIdStr);
    userJson.put("user_name", userName);

    resp.setContentType("application/json; charset=UTF-8");
    mapper.writeValue(resp.getWriter(), userJson);
  }
  public static void submit(String submissionIdentifier, String pipeline, int startingProcessIndex)
      throws IOException {
    setup();

    ObjectNode userOb = objectMapper.createObjectNode();

    userOb.put("priority", properties.getProperty("biosamples.conan.priority"));
    userOb.put("pipelineName", pipeline);
    userOb.put("startingProcessIndex", startingProcessIndex);
    userOb.put("restApiKey", properties.getProperty("biosamples.conan.apikey"));
    ObjectNode inputParameters = userOb.putObject("inputParameters");
    inputParameters.put("SampleTab Accession", submissionIdentifier);

    log.trace(userOb.toString());

    // Send data
    HttpPost postRequest =
        new HttpPost(properties.getProperty("biosamples.conan.url") + "/api/submissions/");
    postRequest.setConfig(
        RequestConfig.custom()
            .setSocketTimeout(0)
            .setConnectTimeout(0)
            .setConnectionRequestTimeout(0)
            .build());
    StringEntity input = new StringEntity(userOb.toString());
    input.setContentType("application/json");
    postRequest.setEntity(input);

    // get response
    try (CloseableHttpResponse response = httpClient.execute(postRequest)) {
      try (BufferedReader br =
          new BufferedReader(new InputStreamReader((response.getEntity().getContent())))) {
        // TODO parse response and raise exception if submit failed
        String line;
        while ((line = br.readLine()) != null) {
          log.info(line);
        }
      }
      EntityUtils.consume(response.getEntity());
    }
  }
Ejemplo n.º 23
0
  public boolean writeInfoToResourceFile(String resourceFileName) {
    ObjectMapper objMapper = new ObjectMapper();
    ObjectNode infoObj = objMapper.createObjectNode();
    infoObj.put("loginId", loginId);
    infoObj.put("mainSummoner", mainSummoner);
    infoObj.put("client version", clientVersion);
    infoObj.put("mainServer", mainServer.getServerCode());

    int i = 0;
    for (String summonerName : summonerList) {
      infoObj.put("summoner" + i, summonerName);
      i++;
    }

    try {
      objMapper.writeValue(new File(resourceFileName), infoObj);
    } catch (IOException e) {

      e.printStackTrace();
    }
    return true;
  }
Ejemplo n.º 24
0
  @Test
  // testing multiple join keys
  public void testMergeJoinMultipleJoinKeys()
      throws JsonGenerationException, JsonMappingException, IOException, InterruptedException {
    Object[][] rows1 = {{0, 1}, {2, 1}, {2, 2}, {5, 1}, {10, 1}, {100, 1}};
    Object[][] rows2 = {{1, 1}, {2, 0}, {2, 1}, {5, 1}, {100, 2}, {100, 3}};
    Object[][] expected = {{2, 1, 2, 1}, {5, 1, 5, 1}};

    Block block1 = new ArrayBlock(Arrays.asList(rows1), new String[] {"a", "b"});
    Block block2 = new ArrayBlock(Arrays.asList(rows2), new String[] {"c", "a"});

    TupleOperator operator = new MergeJoinOperator();
    Map<String, Block> input = new HashMap<String, Block>();
    input.put("block1", block1);
    input.put("block2", block2);

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode node = mapper.createObjectNode();
    ArrayNode lkeys = mapper.createArrayNode();
    lkeys.add("a");
    lkeys.add("b");
    node.put("leftCubeColumns", lkeys);
    ArrayNode rkeys = mapper.createArrayNode();
    rkeys.add("c");
    rkeys.add("a");
    node.put("rightCubeColumns", rkeys);
    node.put("leftBlock", "block1");

    BlockProperties props =
        new BlockProperties(
            null,
            new BlockSchema("INT block1___a, INT block1___b, INT block2___c, INT block2___a"),
            (BlockProperties) null);
    operator.setInput(input, node, props);

    Block output = new TupleOperatorBlock(operator, props);

    ArrayBlock.assertData(output, expected, new String[] {"block1.a", "block2.a"});
  }
Ejemplo n.º 25
0
 @Get
 public ObjectNode getById() {
   ObjectNode modelNode = null;
   ObjectMapper objectMapper = new ObjectMapper();
   modelNode = objectMapper.createObjectNode();
   String output = (String) getRequest().getAttributes().get("output");
   String id = (String) getRequest().getAttributes().get("userId");
   TSUser tsUser = userService.get(TSUser.class, id);
   Map<String, String> excludeProperty = new HashMap<String, String>();
   excludeProperty.put("TSDepart", "TSDepart");
   if (output != null && output.equals("json")) {
     modelNode.put("result", Utils.toSingleJson(tsUser, TSUser.class, excludeProperty).toString());
   }
   if (output != null && output.equals("xml")) {
     try {
       modelNode.put("result", Utils.toSingleXml(tsUser, TSUser.class, excludeProperty).getText());
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   return modelNode;
 }
Ejemplo n.º 26
0
  /**
   * Handles the given {@link ObjectNode} and writes the responses to the given {@link
   * OutputStream}.
   *
   * @param node the {@link JsonNode}
   * @param ops the {@link OutputStream}
   * @throws JsonGenerationException
   * @throws JsonMappingException
   * @throws IOException
   */
  private void handleObject(ObjectNode node, OutputStream ops)
      throws JsonGenerationException, JsonMappingException, IOException {

    // validate request
    if (!node.has("jsonrpc") || !node.has("method")) {
      mapper.writeValue(
          ops, createErrorResponse("jsonrpc", "null", -32600, "Invalid Request", null));
      return;
    }

    // parse request
    String jsonRpc = node.get("jsonrpc").getValueAsText();
    String methodName = node.get("method").getValueAsText();
    String id = node.get("id").getValueAsText();
    JsonNode params = node.get("params");
    int paramCount = (params != null) ? params.size() : 0;

    // find methods
    Set<Method> methods = new HashSet<Method>();
    methods.addAll(ReflectionUtil.findMethods(getHandlerClass(), methodName));

    // method not found
    if (methods.isEmpty()) {
      mapper.writeValue(ops, createErrorResponse(jsonRpc, id, -32601, "Method not found", null));
      return;
    }

    // iterate through the methods and remove
    // the one's who's parameter count's don't
    // match the request
    Iterator<Method> itr = methods.iterator();
    while (itr.hasNext()) {
      Method method = itr.next();
      if (method.getParameterTypes().length != paramCount) {
        itr.remove();
      }
    }

    // choose a method
    Method method = null;
    List<JsonNode> paramNodes = new ArrayList<JsonNode>();

    // handle param arrays, no params, and single methods
    if (paramCount == 0 || params.isArray() || (methods.size() == 1)) {
      method = methods.iterator().next();
      for (int i = 0; i < paramCount; i++) {
        paramNodes.add(params.get(i));
      }

      // handle named params
    } else if (params.isObject()) {

      // loop through each method
      for (Method m : methods) {

        // get method annotations
        Annotation[][] annotations = m.getParameterAnnotations();
        boolean found = true;
        List<JsonNode> namedParams = new ArrayList<JsonNode>();
        for (int i = 0; i < annotations.length; i++) {

          // look for param name annotations
          String paramName = null;
          for (int j = 0; j < annotations[i].length; j++) {
            if (!JsonRpcParamName.class.isInstance(annotations[i][j])) {
              continue;
            } else {
              paramName = JsonRpcParamName.class.cast(annotations[i][j]).value();
              continue;
            }
          }

          // bail if param name wasn't found
          if (paramName == null) {
            found = false;
            break;

            // found it by name
          } else if (params.has(paramName)) {
            namedParams.add(params.get(paramName));
          }
        }

        // did we find it?
        if (found) {
          method = m;
          paramNodes.addAll(namedParams);
          break;
        }
      }
    }

    // invalid parameters
    if (method == null) {
      mapper.writeValue(
          ops, createErrorResponse(jsonRpc, id, -32602, "Invalid method parameters.", null));
      return;
    }

    // invoke the method
    JsonNode result = null;
    ObjectNode error = null;
    Throwable thrown = null;
    try {
      result = invoke(method, paramNodes);
    } catch (Throwable e) {
      thrown = e;
      if (InvocationTargetException.class.isInstance(e)) {
        e = InvocationTargetException.class.cast(e).getTargetException();
      }
      error = mapper.createObjectNode();
      error.put("code", 0);
      error.put("message", e.getMessage());
      error.put("data", e.getClass().getName());
    }

    // bail if notification request
    if (id == null) {
      return;
    }

    // create response
    ObjectNode response = mapper.createObjectNode();
    response.put("jsonrpc", jsonRpc);
    response.put("id", id);
    if (error == null) {
      response.put("result", result);
    } else if (error != null) {
      response.put("error", error);
    }

    // write it
    mapper.writeValue(ops, response);

    // re-throw errors
    if (thrown != null) {
      throw new RuntimeException(thrown);
    }
  }
Ejemplo n.º 27
0
  @org.junit.Test
  public void testMerge() {
    standardInit();
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode to_merge = mapper.createObjectNode();

    int[] vector = {0, 0, 1, 0};
    ArrayNode timestamp1 = createSerializedTimestamp(vector, mapper);
    ArrayNode timestamp2 = createSerializedTimestamp(vector, mapper);

    ObjectNode yale_value = mapper.createObjectNode();
    yale_value.put("shmem_timestamp", timestamp2);
    yale_value.put("value", "College");

    ObjectNode yale_node = mapper.createObjectNode();
    yale_node.put("Yale", yale_value);

    ObjectNode name_value = mapper.createObjectNode();
    name_value.put("shmem_timestamp", timestamp1);
    name_value.put("value", yale_node);

    ObjectNode name_object = mapper.createObjectNode();
    name_object.put("name", name_value);

    // The merge should fail. We're expecting a MergeException.
    Throwable expected_exception = null;
    try {
      ShMem.s_state.merge(name_object, "");
    } catch (Exception ex) {
      expected_exception = ex;
    }
    assertTrue(expected_exception instanceof ShMemObject.MergeException);

    // Now try merging something that doesn't conflict.
    expected_exception = null;
    standardInit();
    ObjectNode abc_value = mapper.createObjectNode();
    abc_value.put("value", "xyz");
    abc_value.put("shmem_timestamp", timestamp1);
    ObjectNode abc_node = mapper.createObjectNode();
    abc_node.put("abc", abc_value);

    // The merge should go through fine.
    try {
      ShMem.s_state.merge(abc_node, "");
    } catch (Exception ex) {
      expected_exception = ex;
    }
    assertTrue(expected_exception == null);
    String xyz_string = ShMem.s_state.get("abc").getTextValue();
    assertTrue(xyz_string.equals("xyz"));

    standardInit();
    int[] new_timestamp = {2, 2, 1, 0};
    timestamp1 = createSerializedTimestamp(new_timestamp, mapper);
    timestamp2 = createSerializedTimestamp(new_timestamp, mapper);

    yale_value.put("shmem_timestamp", timestamp2);
    name_value.put("shmem_timestamp", timestamp1);
    expected_exception = null;
    try {
      ShMem.s_state.merge(name_object, "");
    } catch (Exception e) {
      expected_exception = e;
    }

    assertTrue(expected_exception == null);
    assertEquals(VectorTimestamp.Compare(ShMemObject.s_now, new_timestamp), Comparison.EQ);
    String college_string = ShMem.s_state.get("name").get("Yale").getTextValue();
    assertTrue(college_string.equals("College"));
    int[] yale_timestamp =
        ((ShMemObject) ShMem.s_state.get("name")).m_key_map.get("Yale").m_timestamp;
    assertEquals(VectorTimestamp.Compare(yale_timestamp, new_timestamp), Comparison.EQ);
    int[] name_timestamp = ShMem.s_state.m_key_map.get("name").m_timestamp;
    assertEquals(VectorTimestamp.Compare(name_timestamp, new_timestamp), Comparison.EQ);
  }
  @Override
  public ObjectNode process(long entrezGeneId, String[] values, ArrayList<Integer> sampleList) {

    ObjectNode _datum = mapper.createObjectNode();

    // create map to pair sample and value
    HashMap<Integer, String> mapSampleValue = new HashMap<>();
    for (int i = 0; i < values.length; i++) {
      String value = values[i];
      Integer sampleId = sampleList.get(i);
      mapSampleValue.put(sampleId, value);
    }

    // remove empty entry
    Iterator it = mapSampleValue.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pair = (Map.Entry) it.next();
      if (pair.getValue().equals("NA")
          || pair.getValue().equals("NaN")
          || pair.getValue().equals("null")) {
        it.remove();
      }
    }

    // get Gene Name and Cytoband
    DaoGeneOptimized daoGeneOptimized = DaoGeneOptimized.getInstance();
    String geneName = daoGeneOptimized.getGene(entrezGeneId).getHugoGeneSymbolAllCaps();
    String cytoband = daoGeneOptimized.getGene(entrezGeneId).getCytoband();

    // statistics analysis
    if (profileType.equals(GeneticAlterationType.COPY_NUMBER_ALTERATION.toString())) {
      if (!(Arrays.asList(queriedGenes)).contains(geneName)) { // remove queried genes from result
        _datum.put(COL_NAME_GENE, geneName);
        _datum.put(COL_NAME_CYTOBAND, cytoband);
        _datum.put(
            COL_NAME_PCT_ALTERED,
            Integer.toString(countAltered(mapSampleValue, profileType, "altered"))
                + "////"
                + Double.toString(calcPct(mapSampleValue, profileType, "altered")));
        _datum.put(
            COL_NAME_PCT_UNALTERED,
            Integer.toString(countAltered(mapSampleValue, profileType, "unaltered"))
                + "////"
                + Double.toString(calcPct(mapSampleValue, profileType, "unaltered")));
        _datum.put(
            COL_NAME_RATIO,
            calcRatio(
                calcPct(mapSampleValue, profileType, "altered"),
                calcPct(mapSampleValue, profileType, "unaltered")));
        _datum.put(COL_NAME_DIRECTION, "place holder"); // calculation is done by the front-end
        _datum.put(COL_NAME_P_VALUE, calcPval(mapSampleValue, profileType, geneticProfileStableId));
        if (!(calcPct(mapSampleValue, profileType, "altered") == 0.0
                && calcPct(mapSampleValue, profileType, "unaltered") == 0.0)
            && !Double.isNaN(calcPval(mapSampleValue, profileType, geneticProfileStableId))) {
          return _datum;
        }
      }
    } else if (profileType.equals(GeneticAlterationType.MRNA_EXPRESSION.toString())) {
      _datum.put(COL_NAME_GENE, geneName);
      _datum.put(COL_NAME_CYTOBAND, cytoband);
      _datum.put(
          COL_NAME_MEAN_ALTERED, calcMean(mapSampleValue, "altered", geneticProfileStableId));
      _datum.put(
          COL_NAME_MEAN_UNALTERED, calcMean(mapSampleValue, "unaltered", geneticProfileStableId));
      _datum.put(
          COL_NAME_STDEV_ALTERED, calcSTDev(mapSampleValue, "altered", geneticProfileStableId));
      _datum.put(
          COL_NAME_STDEV_UNALTERED, calcSTDev(mapSampleValue, "unaltered", geneticProfileStableId));
      _datum.put(COL_NAME_P_VALUE, calcPval(mapSampleValue, profileType, geneticProfileStableId));
      if (!Double.isNaN(calcPval(mapSampleValue, profileType, geneticProfileStableId))) {
        return _datum;
      }
    } else if (profileType.equals(GeneticAlterationType.PROTEIN_LEVEL.toString())) {
      _datum.put(COL_NAME_GENE, geneName);
      _datum.put(COL_NAME_CYTOBAND, cytoband);
      _datum.put(
          COL_NAME_MEAN_ALTERED, calcMean(mapSampleValue, "altered", geneticProfileStableId));
      _datum.put(
          COL_NAME_MEAN_UNALTERED, calcMean(mapSampleValue, "unaltered", geneticProfileStableId));
      _datum.put(
          COL_NAME_STDEV_ALTERED, calcSTDev(mapSampleValue, "altered", geneticProfileStableId));
      _datum.put(
          COL_NAME_STDEV_UNALTERED, calcSTDev(mapSampleValue, "unaltered", geneticProfileStableId));
      _datum.put(COL_NAME_P_VALUE, calcPval(mapSampleValue, profileType, geneticProfileStableId));
      if (!Double.isNaN(calcPval(mapSampleValue, profileType, geneticProfileStableId))) {
        return _datum;
      }
    }

    return null;
  }
Ejemplo n.º 29
0
  private void serialize() throws GVCException {
    JsonGenerator jsonGenerator;
    StringWriter stringWriter = new StringWriter();
    try {
      jsonGenerator = jsonFactory.createJsonGenerator(stringWriter);
    } catch (IOException e) {
      throw new GVCException(e);
    }
    jsonGenerator.useDefaultPrettyPrinter();

    ObjectNode rootNode = objectMapper.createObjectNode();

    // Parent
    if (this.parent == null) rootNode.put("parent", "null");
    else rootNode.put("parent", this.parent.getHash());

    // Date
    rootNode.put("date", df.format(this.date));

    // Comment
    rootNode.put("comment", this.comment);

    // Files Added
    /* This is a JSON "object", it looks something like this:
     * 	{
     * 		filesAdded: {
     * 			sd5df5s2: [file1, file2],
     * 			f52s556c: [file3]
     * 		}
     * 	}
     */
    if (this.filesAdded == null) {
      rootNode.put("filesAdded", "null");
    } else {
      ObjectNode addedOb = rootNode.putObject("filesAdded");
      for (String fHash : this.filesAdded.keySet()) {
        // this will be an array of filenames for this hash
        ArrayNode aNode = addedOb.putArray(fHash);

        for (File file : this.filesAdded.get(fHash)) {
          // Normalize the filesystem separator to /
          String fileS = file.toString().replace(File.separator, "/");
          aNode.add(fileS);
        }
      }
    }

    // Files Removed
    if (this.filesRemoved == null) {
      rootNode.put("filesRemoved", "null");
    } else {
      ObjectNode removedOb = rootNode.putObject("filesRemoved");
      for (String fHash : this.filesRemoved.keySet()) {
        // this will be an array of filenames for this hash
        ArrayNode rNode = removedOb.putArray(fHash);

        for (File file : this.filesRemoved.get(fHash)) {
          // Normalize the filesystem separator to /
          String fileS = file.toString().replace(File.separator, "/");
          rNode.add(fileS);
        }
      }
    }

    // And write it all out to a string.
    try {
      jsonGenerator.writeObject(rootNode);
      this.serialized = stringWriter.getBuffer().toString();
    } catch (Exception e) {
      throw new GVCException(e);
    }
  }
Ejemplo n.º 30
0
  /**
   * @param request
   * @param claimDefs Array of claim defs
   * @return
   * @throws Exception
   */
  public String createChallangeNClaimsThreads(String requests, String claimDefs) throws Exception {
    ObjectMapper mapper = new ObjectMapper();

    // System.out.println(requests);
    String[] split = requests.split(",");
    ArrayNode claimDefNodes = (ArrayNode) mapper.readTree(claimDefs);

    ArrayList<IdentityClaimDefinition> icds = new ArrayList<IdentityClaimDefinition>();
    ArrayList<Element> reqs = new ArrayList<Element>();

    for (int i = 0; i < split.length; i++) {
      String onVal = claimDefNodes.get(i).getTextValue();
      ObjectNode claimDefOn = (ObjectNode) mapper.readTree(onVal);
      IdentityClaimDefinition idClaimDef = new IdentityClaimDefinition(claimDefOn);
      icds.add(idClaimDef);

      Pairing pairing = idClaimDef.getParams().getPairing();
      // System.out.println(idClaimDef.serializeJSON());
      String tmpReq = split[i].replaceAll("\"", "");

      byte[] reqElemBytes = Base64.decode(tmpReq);
      // System.out.println(reqElemBytes.length);
      Element reqElem = pairing.getG1().newElement();
      reqElem.setFromBytes(reqElemBytes);
      // System.out.println(reqElem.getImmutable());

      reqs.add(reqElem);
    }

    Pairing pairing = icds.get(0).getParams().getPairing();
    Field gt = pairing.getGT();
    Element sessionKey = gt.newRandomElement().getImmutable();
    Element sessionKeyOrig = sessionKey.getImmutable();
    // System.out.println("Key: " + sessionKey);

    JsonNode rootNode = mapper.createObjectNode();
    ObjectNode on = (ObjectNode) rootNode;

    ArrayList<EncrypterThread> ets = new ArrayList<ServiceProvider.EncrypterThread>();

    for (int i = 0; i < split.length; i++) {
      IdentityClaimDefinition claimDef = icds.get(i);

      Element share = null;
      if (i < (split.length - 1)) {
        share = gt.newRandomElement().getImmutable();
        sessionKey = sessionKey.sub(share).getImmutable();
      } else {
        // Last one should be the remaining part of session key
        share = sessionKey;
      }

      EncrypterThread t =
          new EncrypterThread(claimDef.getName(), claimDef.getParams(), share, reqs.get(i), on);
      t.start();
      ets.add(t);
    }

    for (EncrypterThread t : ets) {
      t.join();
    }

    String sk = new String(Base64.encode(sessionKeyOrig.toBytes()));
    sk = sk.replaceAll(" ", "");
    on.put("SessionKey", sk);
    return on.toString();
  }