Skip to content

Event Management Client for Java

Introduction

The Event Management Service enables the users to create and update events that are associated to entities. It also manages different types of events created by users.

See Event Management for more information about the service.

Event operations

The Event Controller manages standard and custom events. It creates, lists, and updates the events based on the API calls.

Client name: EventClient

Create new event

Create a new event.

Note

Entity ids are cached with 1 minute retention. It can be possible that if an entity (asset) is created it will be visible for Event Management only after the cache is refreshed.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
    // Construct the EventClient object
    EventClient eventClient =  EventClient.builder()
                                   .mindsphereCredentials(credentials)
                                   .restClientConfig(config)
                                   .build();

    // Json string representing Mindsphere standard event or custom event
    String eventJsonString = "{\r\n" +
            "  \"typeId\": \"3cb8c2b1-f72e-43fa-ae39-ee9de14b8f26\",\r\n" +
            "  \"correlationId\": \"3ecc3658-96bb-47ff-93b3-93afd640ee10\",\r\n" +
            "  \"entityId\": \"50fd8ab5-23b3-45f7-aca1-12b0b186707b\",\r\n" +
            "  \"timestamp\": \"2018-01-09T13:40:23.438Z\",\r\n" +
            "  \"customStringField\": \"customValue\",\r\n" +
            "  \"customIntegerField\": 10\r\n" +
            "}"

    BaseEvent createdEvent = null;
    try {
        createdEvent = eventClient.createEvent(eventJsonString);
    } catch (MindsphereException ex) {
        // Exception Handling
    }

Create a new custom event

Create a custom event.
A custom event is an event, which has been assigned to a user-defined event type.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
    // Construct the EventClient object as shown above

    //Construct the CustomEvent object to be created
    CustomEvent customEvent = new CustomEvent();
    customEvent.setTypeId(eventTypeId);
    customEvent.setEntityId(entityId);
    customEvent.setTimestamp(timestamp);

    Map<String, Object> fields = new HashMap<>();
    fields.put("customField", "customValue");
    customEvent.setFields(fields);

    CustomEvent createdCustomEvent = null;
    try {
       createdCustomEvent = eventClient.createCustomEvent(customEvent);
    } catch (MindsphereException ex) {
        // Exception Handling
    }

Create a new standard event

Create a standard event.

These events use a predefined event type, with the following additional properties:

  • description
  • severity
  • code
  • source
  • acknowledged
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
    // Construct the EventClient object as shown above

    //Construct the StandardEvent object to be created
    MindsphereStandardEvent standardEvent = new MindsphereStandardEvent();
    standardEvent.setDescription(description);
    standardEvent.setSeverity(severity);
    standardEvent.setCode(code);
    standardEvent.setAcknowledged(acknowledged);
    standardEvent.setEntityId(entityId);
    standardEvent.setTimestamp(timestamp);

    MindsphereStandardEvent createdStandardEvent = null;
    try {
        createdStandardEvent = eventClient.createStandardEvent(standardEvent);
    } catch (MindsphereException ex) {
        // Exception Handling
    }

Query events

Returns events based on the request parameters.

Note

The default number of elements that will be returned in a page is 20.

1
2
3
4
5
6
7
8
    // Construct the EventClient object as shown above

    Events events = null;
    try {
        events = eventClient.getEvents(size, page, filter, sort, ifNoneMatch, history);
    } catch (MindsphereException ex) {
        // Exception Handling
    }

Query event by ID

Returns an event with the specified ID.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
    // Construct the EventClient object as shown above

    BaseEvent event = null;
    try {
        event = eventClient.getEventById(eventId);

        // The retrieved event can be checked for type as follows
        if (event != null && event instanceof MindsphereStandardEvent) {
            // Process the retrieved Standard event
        } else if (event != null && event instanceof CustomEvent) {
            // Process the retrieved custom event
        }
    } catch (MindsphereException ex) {
        // Exception Handling
    }

Update an event

Update an existing event with the specified ID.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
    // Construct the EventClient object as shown above

    BaseEvent event = null;
    try {
        event = eventClient.updateEvents(eventId, eventJsonString, ifMatch);

        // The retrieved event can be checked for type as shown above for further processing
    } catch (MindsphereException ex) {
        // Exception Handling
    }

Update a standard event

Update an existing standard event with the specified ID.

1
2
3
4
5
6
7
8
    // Construct the EventClient object as shown above

    MindsphereStandardEvent updatedStandardEvent = null;
    try {
        updatedStandardEvent = eventClient.updateEvents(eventId, standardEvent, ifMatch);
    } catch (MindsphereException ex) {
        // Exception Handling
    }

Update a custom event

Update an existing custom event with the specified ID.

1
2
3
4
5
6
7
8
    // Construct the EventClient object as shown above

    CustomEvent customEvent = null;
    try {
        customEvent = eventClient.updateEvents(eventId, customEvent, ifMatch);
    } catch (MindsphereException ex) {
        // Exception Handling
    }

Event type operations

It creates, lists, and updates the event types based on the API calls.

Client name: EventTypeClient

Create new event type

Create a new event type with the specified content.

The Default id is the generated UUID. If ID is provided, then it has to be prefixed with the current tenant and has to be followed by a dot

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    // Construct the EventTypeClient object
    EventTypeClient eventTypeClient =  EventTypeClient.builder()
                                           .mindsphereCredentials(credentials)
                                           .restClientConfig(config)
                                           .build();

    // Define the Event Type to be created
    String eventTypeName = "OilTemperatureRise";
    EventType eventType = new EventType();
    eventType.setName(eventTypeName);
    eventType.setTtl(10);
    eventType.setScope(ScopeEnum.LOCAL);

    // Define Field values to be associated with the Event Type
    Field field = new Field();
    field.setName("temperature");
    field.setFilterable(Boolean.TRUE);
    field.required(Boolean.TRUE);
    field.setType(FieldTypeEnum.INTEGER);

    // Associate Field values to the Event Type
    List<Field> fieldList = new ArrayList<>();
    fieldList.add(field);
    eventType.setFields(fieldList);

    EventType createdEventType = null;
    try {
        createdEventType = eventTypeClient.createEventType(eventType);
    } catch (MindsphereException e) {
        // Exception handling
    }

Query event types

Returns event types based on the request parameters.

1
2
3
4
5
6
7
8
    //Construct EventTypeClient object as shown above

    EventTypes eventTypes = null;
    try {
        eventTypes = eventTypeClient.getEventTypes(page, size, sort, filter, ifNoneMatch);
    } catch (MindsphereException e) {
        // Exception Handling
    }

Get an event type by ID

Returns an event type by ID.

1
2
3
4
5
6
7
8
    //Construct EventTypeClient object as shown above

    EventType eventType = null;
    try {
        eventType = eventTypeClient.getEventTypesById(eventTypeId, ifNoneMatch);
    } catch (MindsphereException e) {
        // Exception Handling
    }

Update an event type

Update an event type of the specified id, by sending only the changed content.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
    //Construct EventTypeClient object as shown above

    //Define the Event Tyoe Patch that will be used to update the event Type
    EventTypePatch eventTypePatch = new EventTypePatch();
    eventTypePatch.setOperation(OperationEnum.REPLACE);
    eventTypePatch.setPath("/scope");
    eventTypePatch.setValue(ScopeEnum.GLOBAL.getValue());

    EventType updatedEventType = null;
    try {
        updatedEventType = eventTypeClient.updateEventType(eventTypeId, eventType.getEtag().toString(), patch);
    } catch (MindsphereException e) {
        // Exception Handling
    }

Any questions left?

Ask the community


Except where otherwise noted, content on this site is licensed under the MindSphere Development License Agreement.