Search in sources :

Example 1 with Builder

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);
}
Also used : TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) Builder(de.metas.event.Event.Builder) TargetType(de.metas.ui.web.notification.UserNotification.TargetType) Event(de.metas.event.Event) Topic(de.metas.event.Topic) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Event (de.metas.event.Event)1 Builder (de.metas.event.Event.Builder)1 Topic (de.metas.event.Topic)1 TargetType (de.metas.ui.web.notification.UserNotification.TargetType)1 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1