/** * Returns a MetaData instances containing the current entries, <b>and</b> the given {@code key} if it was * not yet present in this MetaData. * If {@code key} already existed, the current value will be used. * Otherwise the Supplier function will provide the {@code value} for {@code key} * * @param key The key for the entry * @param value A Supplier function which provides the value * @return a MetaData instance with an additional entry */ public MetaData andIfNotPresent(String key, Supplier<Object> value) { return containsKey(key) ? this : this.and(key, value.get()); }
@Override public boolean matches(Message<?> message) { return !(parameterType.isPrimitive() || (boolean) metaDataValue.get(REQUIRED_PROPERTY)) || ( message.getMetaData().containsKey(metaDataValue.get(META_DATA_VALUE_PROPERTY).toString()) && parameterType.isInstance(message.getMetaData().get(metaDataValue.get(META_DATA_VALUE_PROPERTY).toString())) ); } }
@Override public Map<String, ?> correlationDataFor(Message<?> message) { if (headerNames.length == 0) { return Collections.emptyMap(); } Map<String, Object> data = new HashMap<>(); final MetaData metaData = message.getMetaData(); for (String headerName : headerNames) { if (metaData.containsKey(headerName)) { data.put(headerName, metaData.get(headerName)); } } return data; } }
@Test public void testReturnedEventMessageBehavior() { testSubject.appendEvents(createEvent().withMetaData(singletonMap("key", "value"))); DomainEventMessage<?> messageWithMetaData = testSubject.readEvents(AGGREGATE).next(); /// we make sure persisted events have the same MetaData alteration logic DomainEventMessage<?> altered = messageWithMetaData.withMetaData(singletonMap("key2", "value")); DomainEventMessage<?> combined = messageWithMetaData.andMetaData(singletonMap("key2", "value")); assertTrue(altered.getMetaData().containsKey("key2")); altered.getPayload(); assertFalse(altered.getMetaData().containsKey("key")); assertTrue(altered.getMetaData().containsKey("key2")); assertTrue(combined.getMetaData().containsKey("key")); assertTrue(combined.getMetaData().containsKey("key2")); assertNotNull(messageWithMetaData.getPayload()); assertNotNull(messageWithMetaData.getMetaData()); assertFalse(messageWithMetaData.getMetaData().isEmpty()); }
/** * Returns a MetaData instances containing the current entries, <b>and</b> the given {@code key} if it was * not yet present in this MetaData. * If {@code key} already existed, the current value will be used. * Otherwise the Supplier function will provide the {@code value} for {@code key} * * @param key The key for the entry * @param value A Supplier function which provides the value * @return a MetaData instance with an additional entry */ public MetaData andIfNotPresent(String key, Supplier<Object> value) { return containsKey(key) ? this : this.and(key, value.get()); }
/** * Returns a MetaData instances containing the current entries, <b>and</b> the given {@code key} if it was * not yet present in this MetaData. * If {@code key} already existed, the current value will be used. * Otherwise the Supplier function will provide the {@code value} for {@code key} * * @param key The key for the entry * @param value A Supplier function which provides the value * @return a MetaData instance with an additional entry */ public MetaData andIfNotPresent(String key, Supplier<Object> value) { return containsKey(key) ? this : this.and(key, value.get()); }
@Override public boolean matches(Message<?> message) { return !(parameterType.isPrimitive() || (boolean) metaDataValue.get(REQUIRED_PROPERTY)) || ( message.getMetaData().containsKey(metaDataValue.get(META_DATA_VALUE_PROPERTY).toString()) && parameterType.isInstance(message.getMetaData().get(metaDataValue.get(META_DATA_VALUE_PROPERTY).toString())) ); } }
@Override public boolean matches(Message<?> message) { return !(parameterType.isPrimitive() || (boolean) metaDataValue.get(REQUIRED_PROPERTY)) || ( message.getMetaData().containsKey(metaDataValue.get(META_DATA_VALUE_PROPERTY).toString()) && parameterType.isInstance(message.getMetaData().get(metaDataValue.get(META_DATA_VALUE_PROPERTY).toString())) ); } }
@Override public Map<String, ?> correlationDataFor(Message<?> message) { if (headerNames.length == 0) { return Collections.emptyMap(); } Map<String, Object> data = new HashMap<>(); final MetaData metaData = message.getMetaData(); for (String headerName : headerNames) { if (metaData.containsKey(headerName)) { data.put(headerName, metaData.get(headerName)); } } return data; } }
@Override public Map<String, ?> correlationDataFor(Message<?> message) { if (headerNames.length == 0) { return Collections.emptyMap(); } Map<String, Object> data = new HashMap<>(); final MetaData metaData = message.getMetaData(); for (String headerName : headerNames) { if (metaData.containsKey(headerName)) { data.put(headerName, metaData.get(headerName)); } } return data; } }