Small cleanup
Signed-off-by: Ruben Romero Montes <rromerom@redhat.com>
This commit is contained in:
parent
de45795d29
commit
1291497f1d
|
@ -42,7 +42,7 @@ public interface ExtensionFormat {
|
|||
*/
|
||||
Map<String, String> transport();
|
||||
|
||||
public static ExtensionFormat of(final InMemoryFormat inMemory,
|
||||
static ExtensionFormat of(final InMemoryFormat inMemory,
|
||||
final String key, final String value) {
|
||||
|
||||
final Map<String, String> transport = new HashMap<>();
|
||||
|
@ -62,7 +62,7 @@ public interface ExtensionFormat {
|
|||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static ExtensionFormat of(final InMemoryFormat inMemory,
|
||||
static ExtensionFormat of(final InMemoryFormat inMemory,
|
||||
Entry<String, String> ... transport){
|
||||
Objects.requireNonNull(inMemory);
|
||||
Objects.requireNonNull(transport);
|
||||
|
@ -89,7 +89,7 @@ public interface ExtensionFormat {
|
|||
* @param extensions
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, String> marshal(Collection<ExtensionFormat>
|
||||
static Map<String, String> marshal(Collection<ExtensionFormat>
|
||||
extensions) {
|
||||
|
||||
return extensions.stream()
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
@ -219,10 +220,8 @@ public final class BinaryUnmarshaller {
|
|||
A attributes = attributeUnmarshaller.unmarshal(attributesMap);
|
||||
|
||||
T data = attributes.getMediaType()
|
||||
.map((mime) -> {
|
||||
return dataUnmarshallers.get(mime);
|
||||
})
|
||||
.filter((un) -> null != un)
|
||||
.map((mime) -> dataUnmarshallers.get(mime))
|
||||
.filter(Objects::nonNull)
|
||||
.map(unmarshaller ->
|
||||
unmarshaller.unmarshal(payload, attributes))
|
||||
.orElse(null);
|
||||
|
|
|
@ -51,7 +51,7 @@ public class StructuredMarshaller {
|
|||
return new Builder<>();
|
||||
}
|
||||
|
||||
public static interface MediaTypeStep<A extends Attributes, T, P, H> {
|
||||
public interface MediaTypeStep<A extends Attributes, T, P, H> {
|
||||
/**
|
||||
* Sets the media type of CloudEvents envelope
|
||||
* @param headerName Example {@code Content-Type} for HTTP
|
||||
|
@ -60,7 +60,7 @@ public class StructuredMarshaller {
|
|||
EnvelopeMarshallerStep<A, T, P, H> mime(String headerName, H mediaType);
|
||||
}
|
||||
|
||||
public static interface EnvelopeMarshallerStep<A extends Attributes, T, P, H> {
|
||||
public interface EnvelopeMarshallerStep<A extends Attributes, T, P, H> {
|
||||
/**
|
||||
* Sets the marshaller for the CloudEvent
|
||||
* @param marshaller
|
||||
|
@ -68,7 +68,7 @@ public class StructuredMarshaller {
|
|||
ExtensionAccessorStep<A, T, P, H> map(EnvelopeMarshaller<A, T, P> marshaller);
|
||||
}
|
||||
|
||||
public static interface ExtensionAccessorStep<A extends Attributes, T, P, H> {
|
||||
public interface ExtensionAccessorStep<A extends Attributes, T, P, H> {
|
||||
/**
|
||||
* To skip the extension special handling
|
||||
*/
|
||||
|
@ -76,11 +76,11 @@ public class StructuredMarshaller {
|
|||
ExtensionMarshallerStep<A, T, P, H> map(ExtensionFormatAccessor<A, T> accessor);
|
||||
}
|
||||
|
||||
public static interface ExtensionMarshallerStep<A extends Attributes, T, P, H> {
|
||||
public interface ExtensionMarshallerStep<A extends Attributes, T, P, H> {
|
||||
HeaderMapperStep<A, T, P, H> map(ExtensionMarshaller marshaller);
|
||||
}
|
||||
|
||||
public static interface HeaderMapperStep<A extends Attributes, T, P, H> {
|
||||
public interface HeaderMapperStep<A extends Attributes, T, P, H> {
|
||||
EventStep<A, T, P, H> map(FormatHeaderMapper<H> mapper);
|
||||
}
|
||||
|
||||
|
|
|
@ -144,18 +144,15 @@ public class StructuredUnmarshaller {
|
|||
Optional.ofNullable(extensionMapper)
|
||||
.map(mapper -> mapper.map(headers))
|
||||
.orElse(new HashMap<>());
|
||||
|
||||
CloudEvent<A, T> result =
|
||||
unmarshaller.unmarshal(payload,
|
||||
() ->
|
||||
|
||||
return unmarshaller.unmarshal(payload,
|
||||
() ->
|
||||
extensionUnmarshallers.stream()
|
||||
.map(unmarshaller ->
|
||||
unmarshaller.unmarshal(extensionsMap))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -58,14 +58,14 @@ public class HeaderMapper {
|
|||
.toLowerCase(Locale.US), header.getValue()))
|
||||
.filter(header -> !header.getKey()
|
||||
.equals(ContextAttributes.datacontenttype.name()))
|
||||
.map(header -> new SimpleEntry<>(HEADER_PREFIX+header.getKey(),
|
||||
.map(header -> new SimpleEntry<>(HEADER_PREFIX + header.getKey(),
|
||||
header.getValue()))
|
||||
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
|
||||
|
||||
result.putAll(
|
||||
extensions.entrySet()
|
||||
.stream()
|
||||
.filter(extension -> null!= extension.getValue())
|
||||
.filter(extension -> null != extension.getValue())
|
||||
.collect(Collectors.toMap(Entry::getKey, Entry::getValue))
|
||||
);
|
||||
|
||||
|
|
|
@ -78,10 +78,7 @@ public class StructuredMarshallerTest {
|
|||
|
||||
StructuredMarshaller.<Attributes, Much, String, String>builder()
|
||||
.mime("Content-Type", "application/cloudevents+json")
|
||||
.map((ce) -> {
|
||||
|
||||
return null;
|
||||
})
|
||||
.map((ce) -> null)
|
||||
.skip()
|
||||
.withEvent(null);
|
||||
}
|
||||
|
@ -91,10 +88,7 @@ public class StructuredMarshallerTest {
|
|||
// act
|
||||
StructuredMarshaller.<Attributes, Much, String, String>builder()
|
||||
.mime("Content-Type", "application/cloudevents+json")
|
||||
.map((ce) -> {
|
||||
|
||||
return null;
|
||||
})
|
||||
.map((ce) -> null)
|
||||
.skip()
|
||||
.withEvent(() -> null);
|
||||
}
|
||||
|
@ -106,10 +100,7 @@ public class StructuredMarshallerTest {
|
|||
|
||||
StructuredMarshaller.<Attributes, Much, String, String>builder()
|
||||
.mime("Content-Type", "application/cloudevents+json")
|
||||
.map((ce) -> {
|
||||
|
||||
return null;
|
||||
})
|
||||
.map((ce) -> null)
|
||||
.map(null);
|
||||
}
|
||||
|
||||
|
@ -118,14 +109,8 @@ public class StructuredMarshallerTest {
|
|||
// act
|
||||
StructuredMarshaller.<Attributes, Much, String, String>builder()
|
||||
.mime("Content-Type", "application/cloudevents+json")
|
||||
.map((ce) -> {
|
||||
|
||||
return null;
|
||||
})
|
||||
.map((event) -> {
|
||||
|
||||
return null;
|
||||
});
|
||||
.map((ce) -> null)
|
||||
.map((event) -> null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -135,14 +120,8 @@ public class StructuredMarshallerTest {
|
|||
|
||||
StructuredMarshaller.<Attributes, Much, String, String>builder()
|
||||
.mime("Content-Type", "application/cloudevents+json")
|
||||
.map((ce) -> {
|
||||
|
||||
return null;
|
||||
})
|
||||
.map((event) -> {
|
||||
|
||||
return null;
|
||||
})
|
||||
.map((ce) -> null)
|
||||
.map((event) -> null)
|
||||
.map(null);
|
||||
}
|
||||
|
||||
|
@ -150,18 +129,9 @@ public class StructuredMarshallerTest {
|
|||
public void should_ok_on_extension_marshaller() {
|
||||
StructuredMarshaller.<Attributes, Much, String, String>builder()
|
||||
.mime("Content-Type", "application/cloudevents+json")
|
||||
.map((ce) -> {
|
||||
|
||||
return null;
|
||||
})
|
||||
.map((event) -> {
|
||||
|
||||
return null;
|
||||
})
|
||||
.map((extensions) -> {
|
||||
|
||||
return null;
|
||||
});
|
||||
.map((ce) -> null)
|
||||
.map((event) -> null)
|
||||
.map((extensions) -> null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -171,18 +141,9 @@ public class StructuredMarshallerTest {
|
|||
|
||||
StructuredMarshaller.<Attributes, Much, String, String>builder()
|
||||
.mime("Content-Type", "application/cloudevents+json")
|
||||
.map((ce) -> {
|
||||
|
||||
return null;
|
||||
})
|
||||
.map((event) -> {
|
||||
|
||||
return null;
|
||||
})
|
||||
.map((extensions) -> {
|
||||
|
||||
return null;
|
||||
})
|
||||
.map((ce) -> null)
|
||||
.map((event) -> null)
|
||||
.map((extensions) -> null)
|
||||
.map(null);
|
||||
}
|
||||
|
||||
|
@ -190,18 +151,9 @@ public class StructuredMarshallerTest {
|
|||
public void should_ok_on_header_mapper() {
|
||||
StructuredMarshaller.<Attributes, Much, String, String>builder()
|
||||
.mime("Content-Type", "application/cloudevents+json")
|
||||
.map((ce) -> {
|
||||
|
||||
return null;
|
||||
})
|
||||
.map((event) -> {
|
||||
|
||||
return null;
|
||||
})
|
||||
.map((extensions) -> {
|
||||
|
||||
return null;
|
||||
})
|
||||
.map((ce) -> null)
|
||||
.map((event) -> null)
|
||||
.map((extensions) -> null)
|
||||
.map((attributes, extensions) -> null);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue