use of de.metas.event.Event.Builder in project metasfresh-webui-api by metasfresh.
the class DebugRestController method postEvent.
@RequestMapping(value = "/eventBus/postEvent", method = RequestMethod.GET)
public void postEvent(//
@RequestParam(name = "topicName", defaultValue = "de.metas.event.GeneralNotifications") final String topicName, //
@RequestParam(name = "message", defaultValue = "test message") final String message, //
@RequestParam(name = "toUserId", defaultValue = "-1") final int toUserId, //
@RequestParam(name = "important", defaultValue = "false") final boolean important, //
@RequestParam(name = "targetType", required = false) final String targetTypeStr, //
@RequestParam(name = "targetDocumentType", required = false, defaultValue = "143") final String targetDocumentType, //
@RequestParam(name = "targetDocumentId", required = false) final String targetDocumentId) {
final Topic topic = Topic.builder().name(topicName).type(Type.LOCAL).build();
final Builder eventBuilder = Event.builder().setSummary("summary").setDetailPlain(message).putProperty(UserNotificationRepository.EVENT_PARAM_Important, important);
if (toUserId > 0) {
eventBuilder.addRecipient_User_ID(toUserId);
}
final TargetType targetType = Check.isEmpty(targetTypeStr) ? null : TargetType.forJsonValue(targetTypeStr);
if (targetType == TargetType.Window) {
final String targetTableName = documentCollection.getDocumentDescriptorFactory().getDocumentDescriptor(WindowId.fromJson(targetDocumentType)).getEntityDescriptor().getTableName();
final TableRecordReference targetRecord = TableRecordReference.of(targetTableName, Integer.parseInt(targetDocumentId));
eventBuilder.setRecord(targetRecord);
}
final Event event = eventBuilder.build();
Services.get(IEventBusFactory.class).getEventBus(topic).postEvent(event);
}
Aggregations