dnet-applications/apps/dhp-broker-application/src/main/java/eu/dnetlib/broker/events/output/MockDispatcher.java

54 lines
1.7 KiB
Java
Raw Normal View History

2020-09-04 14:33:19 +02:00
package eu.dnetlib.broker.events.output;
2020-07-02 08:55:42 +02:00
import java.io.StringWriter;
2020-09-11 12:05:11 +02:00
import java.util.Map;
2020-07-02 08:55:42 +02:00
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
2020-09-04 14:33:19 +02:00
import eu.dnetlib.broker.common.elasticsearch.Event;
import eu.dnetlib.broker.common.subscriptions.NotificationMode;
import eu.dnetlib.broker.common.subscriptions.Subscription;
2020-07-02 08:55:42 +02:00
@Component
@Profile("dev")
public class MockDispatcher extends AbstractNotificationDispatcher<String> {
private static final Log log = LogFactory.getLog(MockDispatcher.class);
@Override
protected String prepareAction(final Subscription subscription, final Event... events) throws Exception {
final StringWriter sw = new StringWriter();
sw.write("\n********************************");
sw.write("\n* New notification");
sw.write("\n* - Subscription : " + subscription);
sw.write("\n* - N. events : " + events.length);
sw.write("\n********************************");
return sw.toString();
}
2020-09-11 12:05:11 +02:00
@Override
protected String prepareAction(final Subscription subscription, final Map<String, Object> params) throws Exception {
final StringWriter sw = new StringWriter();
sw.write("\n********************************");
sw.write("\n* New notification");
sw.write("\n* - Subscription : " + subscription);
params.entrySet().forEach(e -> sw.write("\n* - " + e.getKey() + ": " + e.getValue()));
sw.write("\n********************************");
return sw.toString();
}
2020-07-02 08:55:42 +02:00
@Override
protected void performAction(final String message) throws Exception {
log.info(message);
}
@Override
public NotificationMode getMode() {
return NotificationMode.MOCK;
}
}