org.codehaus.jackson.map.JsonMappingException Java Examples

The following examples show how to use org.codehaus.jackson.map.JsonMappingException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsonSerDeser.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Convert from a JSON file
 * @param resource input file
 * @return the parsed JSON
 * @throws IOException IO problems
 * @throws JsonMappingException failure to map from the JSON to this class
 */
@SuppressWarnings({"IOResourceOpenedButNotSafelyClosed"})
public synchronized T fromResource(String resource)
    throws IOException, JsonParseException, JsonMappingException {
  InputStream resStream = null;
  try {
    resStream = this.getClass().getResourceAsStream(resource);
    if (resStream == null) {
      throw new FileNotFoundException(resource);
    }
    return mapper.readValue(resStream, classType);
  } catch (IOException e) {
    LOG.error("Exception while parsing json resource {}: {}", resource, e);
    throw e;
  } finally {
    IOUtils.closeStream(resStream);
  }
}
 
Example #2
Source File: RestDemoServiceIT.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 6 votes vote down vote up
@Test
public void testGetLegacyPodcast() throws JsonGenerationException,
		JsonMappingException, IOException {

	ClientConfig clientConfig = new ClientConfig();
	clientConfig.register(JacksonFeature.class);

	Client client = ClientBuilder.newClient(clientConfig);

	WebTarget webTarget = client
			.target("http://localhost:8888/demo-rest-spring-jersey-jpa2-hibernate-0.0.1-SNAPSHOT/podcasts/2");

	Builder request = webTarget.request(MediaType.APPLICATION_JSON);

	Response response = request.get();
	Assert.assertTrue(response.getStatus() == 200);

	Podcast podcast = response.readEntity(Podcast.class);

	ObjectMapper mapper = new ObjectMapper();
	System.out
			.print("Received podcast from database *************************** "
					+ mapper.writerWithDefaultPrettyPrinter()
							.writeValueAsString(podcast));

}
 
Example #3
Source File: TestOLAPCubeCountDistinct.java    From Cubert with Apache License 2.0 6 votes vote down vote up
@Test
void testThreeDimsTeamGroupingSets() throws JsonGenerationException,
        JsonMappingException,
        IOException,
        InterruptedException
{
    // members: srinivas, maneesh, krishna, saurabh, rui
    // dimensions: country code, number of monitors, vegetarian
    Object[][] rows =
            { { 1, (int) 1, (int) 2, (int) 1 }, { 2, (int) 1, (int) 2, (int) 2 },
                    { 3, (int) 1, (int) 1, (int) 1 },
                    { 4, (int) 1, (int) 1, (int) 2 },
                    { 5, (int) 2, (int) 2, (int) 2 } };
    String[] expected =
            new String[] { "(1,,,4)", "(2,,,1)", "(1,1,,2)", "(1,2,,2)", "(2,2,,1)" };
    validateGroupingSets(rows, expected, new String[] { "Dim0,Dim1", "Dim0" });
}
 
Example #4
Source File: TestOLAPCube.java    From Cubert with Apache License 2.0 6 votes vote down vote up
@Test
void testGroupingSetsSum() throws JsonGenerationException,
        JsonMappingException,
        IOException,
        InterruptedException
{
    // clickCount
    // dimensions: country code, number of monitors, vegetarian
    Object[][] rows =
            { { 1, (int) 1, (int) 1, (int) 1 }, { 1, (int) 1, (int) 1, (int) 2 },
                    { 2, (int) 1, (int) 2, (int) 1 },
                    { 3, (int) 1, (int) 2, (int) 2 },
                    { 2, (int) 2, (int) 2, (int) 2 } };

    String[] expected =
            new String[] { "(1,,,7)", "(2,,,2)", "(1,1,,2)", "(1,2,,5)", "(2,2,,2)" };

    validateGroupingSets(rows, expected, new String[] { "Dim0,Dim1", "Dim0" });
}
 
Example #5
Source File: TestOLAPCubeCountDistinct.java    From Cubert with Apache License 2.0 6 votes vote down vote up
@Test
void testThreeDimsTeam() throws JsonGenerationException,
        JsonMappingException,
        IOException,
        InterruptedException
{
    Object[][] rows =
            { { 1, (int) 1, (int) 2, (int) 1 }, { 2, (int) 1, (int) 2, (int) 2 },
                    { 3, (int) 1, (int) 1, (int) 1 },
                    { 4, (int) 1, (int) 1, (int) 2 },
                    { 5, (int) 2, (int) 2, (int) 2 } };
    String[] expected =
            new String[] { "(1,2,1,1)", "(1,2,2,1)", "(1,1,1,1)", "(1,1,2,1)",
                    "(2,2,2,1)", "(1,,,4)", "(2,,,1)", "(,1,,2)", "(,2,,3)",
                    "(,,1,2)", "(,,2,3)", "(1,1,,2)", "(1,2,,2)", "(2,2,,1)",
                    "(,1,1,1)", "(,1,2,1)", "(,2,1,1)", "(,2,2,2)", "(1,,1,2)",
                    "(1,,2,2)", "(2,,2,1)", "(,,,5)" };
    validate(rows, expected);
}
 
Example #6
Source File: MockController.java    From helix with Apache License 2.0 6 votes vote down vote up
void sendMessage(String msgId, String instanceName, String fromState, String toState,
    String partitionKey, int partitionId) throws InterruptedException, JsonGenerationException,
    JsonMappingException, IOException {
  Message message = new Message(MessageType.STATE_TRANSITION, msgId);
  message.setMsgId(msgId);
  message.setSrcName(srcName);
  message.setTgtName(instanceName);
  message.setMsgState(MessageState.NEW);
  message.setFromState(fromState);
  message.setToState(toState);
  // message.setPartitionId(partitionId);
  message.setPartitionName(partitionKey);

  String path = PropertyPathBuilder.instanceMessage(clusterName, instanceName, message.getId());
  ObjectMapper mapper = new ObjectMapper();
  StringWriter sw = new StringWriter();
  mapper.writeValueUsingView(sw, message, Message.class);
  System.out.println(sw.toString());
  client.delete(path);

  Thread.sleep(10000);
  ZNRecord record = client.readData(PropertyPathBuilder.liveInstance(clusterName, instanceName));
  message.setTgtSessionId(record.getSimpleField(LiveInstanceProperty.SESSION_ID.toString())
      .toString());
  client.createPersistent(path, message);
}
 
Example #7
Source File: DelegatingAvroKeyInputFormat.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
public static String getSourceNameFromPath(FileSplit fileSplit, Configuration configuration)
    throws IOException, JsonParseException, JsonMappingException {
  String content = configuration.get("schema.path.mapping");
  Map<String, String> schemaPathMapping =
      new ObjectMapper().readValue(content, MAP_STRING_STRING_TYPE);
  LOGGER.info("Schema Path Mapping: {}", schemaPathMapping);

  String sourceName = null;
  for (String path : schemaPathMapping.keySet()) {
    if (fileSplit.getPath().toString().indexOf(path) > -1) {
      sourceName = schemaPathMapping.get(path);
      break;
    }
  }
  return sourceName;
}
 
Example #8
Source File: FoxbpmStatusService.java    From FoxBPM with Apache License 2.0 6 votes vote down vote up
public Status getStatus(Throwable throwable, Request request, Response response) {
	Status status = null;
	if (throwable instanceof JsonMappingException && throwable.getCause() != null) {
		status = getSpecificStatus(throwable.getCause(), request, response);
	}
	if (status == null) {
		Throwable causeThrowable = null;
		if (throwable.getCause() != null && throwable.getCause() instanceof FoxBPMException) {
			causeThrowable = throwable.getCause();
		} else {
			causeThrowable = throwable;
		}
		status = getSpecificStatus(causeThrowable, request, response);
	}
	return status != null ? status : Status.SERVER_ERROR_INTERNAL;
}
 
Example #9
Source File: CurrentStatesResource.java    From helix with Apache License 2.0 6 votes vote down vote up
StringRepresentation getInstanceCurrentStatesRepresentation(String clusterName,
    String instanceName) throws JsonGenerationException, JsonMappingException, IOException {
  ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
  ;
  String instanceSessionId =
      ClusterRepresentationUtil.getInstanceSessionId(zkClient, clusterName, instanceName);

  String message =
      ClusterRepresentationUtil
          .getInstancePropertyNameListAsString(zkClient, clusterName, instanceName,
              PropertyType.CURRENTSTATES, instanceSessionId, MediaType.APPLICATION_JSON);

  StringRepresentation representation =
      new StringRepresentation(message, MediaType.APPLICATION_JSON);

  return representation;
}
 
Example #10
Source File: JsonSerDeser.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Convert from a JSON file
 * @param resource input file
 * @return the parsed JSON
 * @throws IOException IO problems
 * @throws JsonMappingException failure to map from the JSON to this class
 */
@SuppressWarnings({"IOResourceOpenedButNotSafelyClosed"})
public synchronized T fromResource(String resource)
    throws IOException, JsonParseException, JsonMappingException {
  InputStream resStream = null;
  try {
    resStream = this.getClass().getResourceAsStream(resource);
    if (resStream == null) {
      throw new FileNotFoundException(resource);
    }
    return mapper.readValue(resStream, classType);
  } catch (IOException e) {
    LOG.error("Exception while parsing json resource {}: {}", resource, e);
    throw e;
  } finally {
    IOUtils.closeStream(resStream);
  }
}
 
Example #11
Source File: DerpTest.java    From torrenttunes-client with GNU General Public License v3.0 6 votes vote down vote up
public static void derp6() throws JsonGenerationException, JsonMappingException, IOException {
//		Song song = Song.fetchSong(new File(DataSources.SAMPLE_SONG));
//		
//		String songJson = Tools.MAPPER.writeValueAsString(song);
//		
//		// Add the mac_address
//		ObjectNode on = Tools.MAPPER.valueToTree(Tools.jsonToNode(songJson));
//		on.put("uploader_ip_hash", DataSources.IP_HASH);
//		
//		String songUploadJson = Tools.nodeToJson(on);
//		log.info("song upload json:\n" + songUploadJson);
		
//		System.out.println(Tools.GSON2.toJson(Strings.EN.map));
		
//		Map<String, String> map = Strings.EN.map;
//		
//		for (Entry<String, String> e : map.entrySet()) {
//			System.out.println(e.getKey() + " : " + e.getValue());
//		}
		
//		WriteMultilingualHTMLFiles.write();
		
		
		
	}
 
Example #12
Source File: DerpTest.java    From torrenttunes-client with GNU General Public License v3.0 6 votes vote down vote up
public void derp() throws JsonGenerationException, JsonMappingException, IOException {
	//		TorrentClient tc = TorrentClient.start();
	//		ScanDirectory.start(new File(DataSources.SAMPLE_MUSIC_DIR), tc);

	// List all the music files in the sub or sub directories
	//		String[] types = {"mp3"};
	//
	//		Collection<File> files = FileUtils.listFiles(new File(DataSources.SAMPLE_MUSIC_DIR), types , true);
	//
	//
	//		Set<ScanInfo> scanInfos = new LinkedHashSet<ScanInfo>();
	//
	//		for (File file : files) {
	//			scanInfos.add(ScanInfo.create(file));
	//		}
	//		
	//		String json = Tools.MAPPER.writeValueAsString(scanInfos);
	//		System.out.println(json);


	Song song = Song.fetchSong(new File("/home/tyler/.torrenttunes-client/cache/1-06 Raconte-Moi Une Histoire.mp3"));
	System.out.println(song.getRecording());

}
 
Example #13
Source File: GeneralMesseageConsumer.java    From laser with Apache License 2.0 6 votes vote down vote up
private boolean setUserProfile(String uuid, Vector profile)
		throws JsonParseException, JsonMappingException, IOException {
	try {
		Object res = couchbaseClient.get(uuid);
		if (null == res) {
			return false;
		}

		String jsonValue = res.toString();
		UserProfile userProfile = UserProfile.createUserProfile(jsonValue);
		userProfile.setUserFeature(profile, mapper, true);
	} catch (RuntimeException e) {
		return false;
	}
	return true;
}
 
Example #14
Source File: OpenApiService.java    From SI with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public HashMap<String, Object> execute(String operation, String content) 
		throws JsonGenerationException, JsonMappingException, IOException, UserSysException
{	
	HashMap<String, Object> res = callOpenAPI(operation, content);
	
	
	//try {
		//int status = (Integer)res.get("status");
		String body = (String)res.get("body");
		ObjectMapper mapper = new ObjectMapper();
		Object json = mapper.readValue(body, Object.class);
		res.put("json", json);
	//} catch (JsonGenerationException ex) {
	//	res.put("exception", ex);
	//} catch (JsonMappingException ex) {
	//	res.put("exception", ex);
	//} catch (IOException ex) {
	//	res.put("exception", ex);
	//} catch (UserSysException ex) {
		
	//}
	
	return res;
}
 
Example #15
Source File: Simulator.java    From realtime-analytics with GNU General Public License v2.0 6 votes vote down vote up
private static void sendMessage() throws IOException, JsonProcessingException, JsonGenerationException,
            JsonMappingException, UnsupportedEncodingException, HttpException {
        ObjectMapper mapper = new ObjectMapper();

        Map<String, Object> m = new HashMap<String, Object>();

        m.put("si", "12345");
        m.put("ct", System.currentTimeMillis());
        
        String payload = mapper.writeValueAsString(m);
        HttpClient client = new HttpClient();
        PostMethod method = new PostMethod("http://localhost:8080/tracking/ingest/PulsarRawEvent");
//      method.addRequestHeader("Accept-Encoding", "gzip,deflate,sdch");
        method.setRequestEntity(new StringRequestEntity(payload, "application/json", "UTF-8"));
        int status = client.executeMethod(method);
        System.out.println(Arrays.toString(method.getResponseHeaders()));
        System.out.println("Status code: " + status + ", Body: " +  method.getResponseBodyAsString());
    }
 
Example #16
Source File: SocketServer.java    From tac2015-event-detection with GNU General Public License v3.0 6 votes vote down vote up
/***********  stdin/namedpipe loop  ***********/

	void namedpipeLoop() throws JsonGenerationException, JsonMappingException, IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
		String inputline;
		BufferedOutputStream out = new BufferedOutputStream(
				new FileOutputStream(outpipeFilename, true));
//		OutputStream out = new FileOutputStream(outpipeFilename, true);
		log("Waiting for commands on stdin");
		while ( (inputline=reader.readLine()) != null) {
			JsonNode result = parseAndRunCommand(inputline);
			writeResultToStream(result, out);
			out.flush();
			checkTimings();
		}

	}
 
Example #17
Source File: CurrentStateResource.java    From helix with Apache License 2.0 6 votes vote down vote up
StringRepresentation getInstanceCurrentStateRepresentation(String clusterName,
    String instanceName, String resourceGroup) throws JsonGenerationException,
    JsonMappingException, IOException {
  ZkClient zkClient = (ZkClient) getRequest().getAttributes().get(RestAdminApplication.ZKCLIENT);
  String instanceSessionId =
      ClusterRepresentationUtil.getInstanceSessionId(zkClient, clusterName, instanceName);
  Builder keyBuilder = new PropertyKey.Builder(clusterName);

  String message =
      ClusterRepresentationUtil.getInstancePropertyAsString(zkClient, clusterName,
          keyBuilder.currentState(instanceName, instanceSessionId, resourceGroup),
          MediaType.APPLICATION_JSON);
  StringRepresentation representation =
      new StringRepresentation(message, MediaType.APPLICATION_JSON);
  return representation;
}
 
Example #18
Source File: DelegatingAvroKeyInputFormat.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
public static String getSourceNameFromPath(FileSplit fileSplit, Configuration configuration)
    throws IOException, JsonParseException, JsonMappingException {
  String content = configuration.get("schema.path.mapping");
  Map<String, String> schemaPathMapping =
      new ObjectMapper().readValue(content, MAP_STRING_STRING_TYPE);
  LOGGER.info("Schema Path Mapping: {}", schemaPathMapping);

  String sourceName = null;
  for (String path : schemaPathMapping.keySet()) {
    if (fileSplit.getPath().toString().indexOf(path) > -1) {
      sourceName = schemaPathMapping.get(path);
      break;
    }
  }
  return sourceName;
}
 
Example #19
Source File: TestOperators.java    From Cubert with Apache License 2.0 5 votes vote down vote up
@Test
// when there are multiple rows in one table
public void testRightMergeJoin() throws JsonGenerationException,
        JsonMappingException,
        IOException,
        InterruptedException
{
    Object[][] rows1 = { { 0 }, { 2 }, { 2 }, { 5 }, { 10 }, { 100 } };
    Object[][] rows2 = { { 1 }, { 2 }, { 7 }, { 9 }, { 100 }, { 100 } };
    Object[][] expected =
            { { null, 1 }, { 2, 2 }, { 2, 2 }, { null, 7 }, { null, 9 },
                    { 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");
    node.put("rightBlock", "block2");
    node.put("joinType", "right 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" });
}
 
Example #20
Source File: TestOperators.java    From Cubert with Apache License 2.0 5 votes vote down vote up
@Test
// when there are multiple rows in one table
public void testMergeJoin2() throws JsonGenerationException,
        JsonMappingException,
        IOException,
        InterruptedException
{
    Object[][] rows1 = { { 2 }, { 2 }, { 5 }, { 10 } };
    Object[][] rows2 = { { 1 }, { 7 }, { 9 } };
    Object[][] expected = {};

    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" });
}
 
Example #21
Source File: TestOLAPCubeCountDistinct.java    From Cubert with Apache License 2.0 5 votes vote down vote up
void validate(Object[][] rows, String[] expected) throws JsonGenerationException,
        JsonMappingException,
        IOException,
        InterruptedException
{
    validateGroupingSets(rows, expected, null);
}
 
Example #22
Source File: TestOLAPCubeCountDistinct.java    From Cubert with Apache License 2.0 5 votes vote down vote up
@Test
void testOneDimension() throws JsonGenerationException,
        JsonMappingException,
        IOException,
        InterruptedException
{
    Object[][] rows = { { 1, (int) 10 }, { 2, (int) 10 }, { 2, (int) 10 } };
    String[] expected = new String[] { "(10,2)", "(,2)" };
    validate(rows, expected);
}
 
Example #23
Source File: TestOperators.java    From Cubert with Apache License 2.0 5 votes vote down vote up
@Test
// when there are multiple rows in one table
public void testMergeJoin3() throws JsonGenerationException,
        JsonMappingException,
        IOException,
        InterruptedException
{
    Object[][] rows1 = { { 0 }, { 2 }, { 2 }, { 5 }, { 10 } };
    Object[][] rows2 = { { 1 }, { 2 }, { 2 }, { 7 }, { 9 } };
    Object[][] expected = { { 2, 2 }, { 2, 2 }, { 2, 2 }, { 2, 2 } };

    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" });
}
 
Example #24
Source File: JSONUtil.java    From ranger with Apache License 2.0 5 votes vote down vote up
public File writeJsonToFile(ViewBaseBean viewBean, String fileName)
		throws JsonGenerationException, JsonMappingException, IOException {

	if (fileName.length() < 3) {
		fileName = "file_" + fileName;
	}

	File file = File.createTempFile(fileName, ".json");
	JsonUtilsV2.getMapper().defaultPrettyPrintingWriter().writeValue(file, viewBean);

	return file;
}
 
Example #25
Source File: MockControllerProcess.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * @param args
 * @throws IOException
 * @throws JsonMappingException
 * @throws JsonGenerationException
 * @throws InterruptedException
 */
public static void main(String[] args) throws JsonGenerationException, JsonMappingException,
    InterruptedException, IOException {

  MockController storageController =
      new MockController("cm-instance-0", "localhost:2181", "storage-cluster");
  MockController relayController =
      new MockController("cm-instance-0", "localhost:2181", "relay-cluster");

  ArrayList<String> instanceNames = new ArrayList<String>();
  instanceNames.add("relay0");
  instanceNames.add("relay1");
  instanceNames.add("relay2");
  instanceNames.add("relay3");
  instanceNames.add("relay4");

  relayController.createExternalView(instanceNames, 10, 2, "EspressoDB", 0);

  // Messages to initiate offline->slave->master->slave transitions

  storageController.sendMessage("TestMessageId1", "localhost_8900", "Offline", "Slave",
      "EspressoDB.partition-0", 0);
  Thread.sleep(10000);
  storageController.sendMessage("TestMessageId2", "localhost_8900", "Slave", "Master",
      "EspressoDB.partition-0", 0);
  Thread.sleep(10000);
  storageController.sendMessage("TestMessageId3", "localhost_8900", "Master", "Slave",
      "EspressoDB.partition-0", 0);
  Thread.sleep(10000);

  // Change the external view to trigger the consumer to listen from
  // another relay
  relayController.createExternalView(instanceNames, 10, 2, "EspressoDB", 10);

  storageController.sendMessage("TestMessageId4", "localhost_8900", "Slave", "Offline",
      "EspressoDB.partition-0", 0);
  Thread.sleep(10000);
}
 
Example #26
Source File: TestOperators.java    From Cubert with Apache License 2.0 5 votes vote down vote up
@Test
// when there are multiple rows in one table
public void testMergeJoin1() throws JsonGenerationException,
        JsonMappingException,
        IOException,
        InterruptedException
{
    Object[][] rows1 = { { 2 }, { 2 }, { 7 }, { 9 } };
    Object[][] rows2 = { { 2 }, { 7 }, { 9 } };
    Object[][] expected = { { 2, 2 }, { 2, 2 }, { 7, 7 }, { 9, 9 } };

    ArrayBlock block1 = new ArrayBlock(Arrays.asList(rows1), new String[] { "a" });
    ArrayBlock 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" });
}
 
Example #27
Source File: RestDemoServiceIT.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 5 votes vote down vote up
@Test
public void testGetPodcasts() throws JsonGenerationException,
		JsonMappingException, IOException {

	ClientConfig clientConfig = new ClientConfig();
	clientConfig.register(JacksonFeature.class);

	Client client = ClientBuilder.newClient(clientConfig);

	WebTarget webTarget = client
			.target("http://localhost:8888/demo-rest-spring-jersey-tomcat-mybatis-0.0.1-SNAPSHOT/podcasts/");

	Builder request = webTarget.request();
	request.header("Content-type", MediaType.APPLICATION_JSON);

	Response response = request.get();
	Assert.assertTrue(response.getStatus() == 200);

	List<Podcast> podcasts = response
			.readEntity(new GenericType<List<Podcast>>() {
			});

	ObjectMapper mapper = new ObjectMapper();
	System.out.print(mapper.writerWithDefaultPrettyPrinter()
			.writeValueAsString(podcasts));

	Assert.assertTrue("At least one podcast is present",
			podcasts.size() > 0);
}
 
Example #28
Source File: PubSubWebSocketClient.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessage(String message)
{
  PubSubMessage<Object> pubSubMessage;
  try {
    pubSubMessage = codec.parseMessage(message);
    PubSubWebSocketClient.this.onMessage(pubSubMessage.getType().getIdentifier(), pubSubMessage.getTopic(), pubSubMessage.getData());
  } catch (JsonParseException jpe) {
    logger.warn("Ignoring unparseable JSON message: {}", message, jpe);
  } catch (JsonMappingException jme) {
    logger.warn("Ignoring JSON mapping in message: {}", message, jme);
  } catch (IOException ex) {
    onError(ex);
  }
}
 
Example #29
Source File: TestOperators.java    From Cubert with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example #30
Source File: TestOperators.java    From Cubert with Apache License 2.0 5 votes vote down vote up
@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" });
}