org.springframework.tuple.TupleBuilder Java Examples

The following examples show how to use org.springframework.tuple.TupleBuilder. 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: BoardEventNotificationSink.java    From event-store-demo with GNU General Public License v3.0 6 votes vote down vote up
@StreamListener( Sink.INPUT )
public void processNotification( final String json ) {
    log.debug( "processNotification : enter" );

    Tuple event = TupleBuilder.fromString( json );

    Assert.hasText( event.getString( "eventType" ), "eventType not set" );
    Assert.hasText( event.getString( "boardUuid" ), "boardUuid not set" );
    Assert.hasText( event.getString( "occurredOn" ), "occurredOn not set" );

    String eventType = event.getString( "eventType" );
    if( eventType.equals( "BoardInitialized" ) ) {
        log.debug( "processNotification : exit, no board should exist in cache if 'BoardInitialized' event is received" );

        return;
    }

    this.service.uncacheTarget( UUID.fromString( event.getString( "boardUuid" ) ) );

    log.debug( "processNotification : exit" );
}
 
Example #2
Source File: TensorTupleConverter.java    From tensorflow-spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
public static Tuple toTuple(Tensor tensor) {
	ByteBuffer buffer = ByteBuffer.allocate(tensor.numBytes());
	tensor.writeTo(buffer);

	// Retrieve all bytes in the buffer
	buffer.clear();
	byte[] bytes = new byte[buffer.capacity()];

       buffer.get(bytes, 0, bytes.length);

	return TupleBuilder.tuple()
			.put(TF_DATA_TYPE, tensor.dataType().name())
			.put(TF_SHAPE, tensor.shape())
			.put(TF_VALUE, bytes)
			.build();
}
 
Example #3
Source File: EnrichProcessor.java    From FraudDetection-Microservices with Apache License 2.0 6 votes vote down vote up
private MutableMessage<?> convertToMutable(Message<?> input) throws Exception{
    Object payload = input.getPayload();
    if (payload instanceof Tuple && !(payload instanceof MutableTuple)) {
            payload = TupleBuilder.mutableTuple().putAll((Tuple) payload).build();
    }
    else if (payload instanceof String){
		String strPayload = input.getPayload().toString();
		Iterator<Entry<String, Object>> objects = new ObjectMapper().readValue(strPayload, Map.class).entrySet().iterator();
		TupleBuilder tuples = TupleBuilder.mutableTuple();
		while (objects.hasNext()){
			Entry<String,Object> entry = objects.next();
			tuples.put(entry.getKey(), entry.getValue());
		}        	
		payload = tuples.build();
    }
    return new MutableMessage<>(payload, input.getHeaders());
}
 
Example #4
Source File: FieldValueCounterSinkTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Test
public void testPojoTupleFieldName() {
	TestPojoTuple testPojo = new TestPojoTuple();
	testPojo.setTest(TupleBuilder.tuple().of("test1", "Hi"));
	assertNotNull(this.sink.input());
	Message<TestPojoTuple> message1 = MessageBuilder.withPayload(testPojo).build();
	sink.input().send(message1);
	TestPojoTuple testPojo2 = new TestPojoTuple();
	testPojo2.setTest(TupleBuilder.tuple().of("test2", "Hello"));
	Message<TestPojoTuple> message2 = MessageBuilder.withPayload(testPojo2).build();
	sink.input().send(message2);
	TestPojoTuple testPojo3 = new TestPojoTuple();
	testPojo3.setTest(TupleBuilder.tuple().of("test1", "Hi"));
	Message<TestPojoTuple> message3 = MessageBuilder.withPayload(testPojo3).build();
	sink.input().send(message3);
	assertEquals(2, this.fieldValueCounterRepository.findOne(FVC_NAME).getFieldValueCounts().get("{\"test1\":\"Hi\"}").longValue());
	assertEquals(1, this.fieldValueCounterRepository.findOne(FVC_NAME).getFieldValueCounts().get("{\"test2\":\"Hello\"}").longValue());
}
 
Example #5
Source File: JdbcSinkIntegrationTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Test
public void testInsertion() {
	Tuple tupleA = TupleBuilder.tuple().of("a", "hello1", "b", 42);
	Tuple tupleB = TupleBuilder.tuple().of("a", "hello2", "b", null);
	Tuple tupleC = TupleBuilder.tuple().of("a", "hello3");
	channels.input().send(MessageBuilder.withPayload(tupleA).build());
	channels.input().send(MessageBuilder.withPayload(tupleB).build());
	channels.input().send(MessageBuilder.withPayload(tupleC).build());
	Assert.assertThat(jdbcOperations.queryForObject(
			"select count(*) from messages where a = ? and b = ?",
			Integer.class, tupleA.getString("a"), tupleA.getInt("b")), is(1));
	Assert.assertThat(jdbcOperations.queryForObject(
			"select count(*) from messages where a = ? and b IS NULL",
			Integer.class, tupleB.getString("a")), is(1));
	Assert.assertThat(jdbcOperations.queryForObject(
			"select count(*) from messages where a = ? and b IS NULL",
			Integer.class, tupleC.getString("a")), is(1));
}
 
Example #6
Source File: EventStoreController.java    From event-store-demo with GNU General Public License v3.0 5 votes vote down vote up
@PostMapping( "/" )
public ResponseEntity saveEvent( @RequestBody String json ) {

    Tuple event = TupleBuilder.fromString( json );

    Assert.isTrue( event.hasFieldName( "eventType" ), "eventType is required" );
    Assert.isTrue( event.hasFieldName( "boardUuid" ), "boardUuid is required" );
    Assert.isTrue( event.hasFieldName( "occurredOn" ), "occurredOn is required" );

    this.service.processDomainEvent( event );

    return ResponseEntity
            .accepted()
            .build();
}
 
Example #7
Source File: LinearRegressionTensorflowProcessorIntegrationTests.java    From tensorflow-spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test(expected = MessageHandlingException.class)
public void testEvaluationIncorrectTupleInput() {
	Tuple incompleteInputTuple = TupleBuilder.tuple()
			//	missing data type
			.put(TF_SHAPE, new long[0])
			.put(TF_VALUE, new byte[0])
			.build();
	testEvaluation(incompleteInputTuple);
}
 
Example #8
Source File: PmmlProcessorConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
private MutableMessage<?> convertToMutable(Message<?> input) {
	Object payload = input.getPayload();
	if (payload instanceof Tuple && !(payload instanceof MutableTuple)) {
		payload = TupleBuilder.mutableTuple().putAll((Tuple) payload).build();
	}
	return new MutableMessage<>(payload, input.getHeaders());
}
 
Example #9
Source File: DomainEventServiceTests.java    From event-store-demo with GNU General Public License v3.0 3 votes vote down vote up
@Test
public void testProcessBoardInitializedEvent() throws Exception {

    this.service.processDomainEvent( TupleBuilder.fromString( BOARD_INITIALIZED_EVENT ) );

    verify( this.repository, times( 1 ) ).save( any( DomainEventsEntity.class ) );
    verify( this.notificationPublisher, times( 1 ) ).sendNotification( any( Tuple.class ) );

}
 
Example #10
Source File: DomainEventServiceTests.java    From event-store-demo with GNU General Public License v3.0 3 votes vote down vote up
@Test
public void testProcessBoardRenamedEvent() throws Exception {

    DomainEventsEntity domainEventsEntity = createDomainEventsEntity();
    when( this.repository.findById( anyString() ) ).thenReturn( Optional.of( domainEventsEntity ) );

    this.service.processDomainEvent( TupleBuilder.fromString( BOARD_RENAMED_EVENT ) );

    verify( this.repository, times( 1 ) ).findById( anyString() );
    verify( this.repository, times( 1 ) ).save( any( DomainEventsEntity.class ) );
    verify( this.notificationPublisher, times( 1 ) ).sendNotification( any( Tuple.class ) );

}
 
Example #11
Source File: NotificationPublisherTests.java    From event-store-demo with GNU General Public License v3.0 3 votes vote down vote up
@Test
public void testSendNotification() throws Exception {

    BlockingQueue<Message<?>> messages = collector.forChannel( source.output() );

    Tuple event = TupleBuilder.fromString( BOARD_INITIALIZED_EVENT );
    this.notificationPublisher.sendNotification( event );

    assertThat( messages, receivesPayloadThat( is( BOARD_INITIALIZED_EVENT ) ) );

}