package adapters;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import converters.JsonConverter;
import datamodel.EventHubMessage;
import datamodel.Measurement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Date;

public class EventHubAdapter implements Adapter {
    private static final Logger logger = LoggerFactory.getLogger(EventHubAdapter.class);

    public String adaptMessage(String filteredJson, Measurement measurement) {
        String command = measurement.getCommand();
        String usedTool = command.substring(0, command.indexOf(' '));

        ObjectMapper mapper = new ObjectMapper();
        JsonNode data = null;

        try {
            data = mapper.readTree(filteredJson);
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }

        EventHubMessage eventHubMessage = new EventHubMessage();
        eventHubMessage.setComponent(null);
        eventHubMessage.setObject(usedTool);
        eventHubMessage.setLabels(new String[]{"userId-" + measurement.getClientId()});
        eventHubMessage.setType(null);
        eventHubMessage.setData(data);
        eventHubMessage.setTimestamp(Long.toString((new Date().getTime()) / 1000));
        return JsonConverter.objectToJsonString(eventHubMessage);
    }
}

@@ -317,16 +317,39 @@
 il.Date;
+%0Aimport java.util.UUID;
 %0A%0Apublic
@@ -480,16 +480,71 @@
 .class);
+%0A    public static final UUID uuid = UUID.randomUUID();
 %0A%0A    pu
@@ -1075,20 +1075,31 @@
 mponent(
-null
+uuid.toString()
 );%0A     
@@ -1345,22 +1345,8 @@
 amp(
-Long.toString(
 (new
@@ -1371,17 +1371,16 @@
  / 1000)
-)
 ;%0A      

Use a uuid to identify component.