Make it possible to create EiffelEvent with an already created UUID

The current code generate an UUID automatically when creating a
EiffelEvent. With this change we can set the UUID ourself.

Solves: Jira GER-1545
Change-Id: I862db92f46d5baa30d0252bbeccbd8d02ed05173
diff --git a/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/mapping/EiffelEventFactory.java b/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/mapping/EiffelEventFactory.java
index df4f63c..624a152 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/mapping/EiffelEventFactory.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/mapping/EiffelEventFactory.java
@@ -177,6 +177,30 @@
       Integer changeNbr,
       Long epochMillisCreated,
       List<UUID> parentEventIds) {
+    return createScc(
+        authorName,
+        authorEmail,
+        authorUsername,
+        repoName,
+        branch,
+        commitSha1,
+        changeNbr,
+        epochMillisCreated,
+        parentEventIds,
+        Optional.empty());
+  }
+
+  public EiffelSourceChangeCreatedEventInfo createScc(
+      String authorName,
+      String authorEmail,
+      String authorUsername,
+      String repoName,
+      String branch,
+      String commitSha1,
+      Integer changeNbr,
+      Long epochMillisCreated,
+      List<UUID> parentEventIds,
+      Optional<UUID> uuid) {
     if (branch.startsWith(RefNames.REFS_HEADS)) {
       branch = branch.substring(RefNames.REFS_HEADS.length());
     }
@@ -195,7 +219,7 @@
                     .details(commitUrl(repoName, commitSha1))
                     .id(changeNbr != null ? String.valueOf(changeNbr) : null)
                     .tracker(GERRIT))
-            .meta(getMeta(epochMillisCreated));
+            .meta(getMeta(epochMillisCreated, uuid));
     parentEventIds.stream()
         .forEach(
             id ->
@@ -213,7 +237,8 @@
       String commitSha1,
       Long epochMillisCreated,
       List<UUID> parentEventIds,
-      UUID sccId) {
+      UUID sccId,
+      Optional<UUID> uuid) {
     EiffelSourceChangeSubmittedEventInfo.Builder scs =
         EiffelSourceChangeSubmittedEventInfo.builder()
             .submitter(EiffelPersonInfo.builder().email(email).name(name).id(username))
@@ -223,7 +248,7 @@
                     .branch(branch)
                     .repoName(repoName)
                     .repoUri(projectUrl(repoName)))
-            .meta(getMeta(epochMillisCreated));
+            .meta(getMeta(epochMillisCreated, uuid));
     parentEventIds.stream()
         .forEach(
             id ->
@@ -257,6 +282,10 @@
   }
 
   private EiffelMetaInfo.Builder getMeta(Long epochMillisCreated) {
+    return getMeta(epochMillisCreated, Optional.empty());
+  }
+
+  private EiffelMetaInfo.Builder getMeta(Long epochMillisCreated, Optional<UUID> id) {
     return EiffelMetaInfo.builder()
         .source(
             EiffelSourceInfo.builder()
@@ -265,7 +294,7 @@
                 .host(host)
                 .serializer(packageUrl))
         .time(epochMillisCreated)
-        .id(UUID.randomUUID());
+        .id(id.orElse(UUID.randomUUID()));
   }
 
   private String projectUrl(String projectName) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/mapping/EiffelEventMapper.java b/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/mapping/EiffelEventMapper.java
index b5e4a35..a57cf6a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/mapping/EiffelEventMapper.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/mapping/EiffelEventMapper.java
@@ -88,6 +88,16 @@
   public EiffelSourceChangeCreatedEventInfo toScc(
       RevCommit commit, String repoName, String branch, List<UUID> parentEventIds)
       throws ConfigInvalidException, IOException {
+    return toScc(commit, repoName, branch, parentEventIds, Optional.empty());
+  }
+
+  public EiffelSourceChangeCreatedEventInfo toScc(
+      RevCommit commit,
+      String repoName,
+      String branch,
+      List<UUID> parentEventIds,
+      Optional<UUID> id)
+      throws ConfigInvalidException, IOException {
     Optional<ChangeData> change = findChange(commit, repoName, branch);
 
     /* Don't trust the ChangeData if there are inconsistencies between the index and what's
@@ -108,7 +118,8 @@
             commit.getName(),
             null,
             commitTimeInEpochMillis(commit),
-            parentEventIds);
+            parentEventIds,
+            id);
   }
 
   @VisibleForTesting
@@ -138,6 +149,20 @@
       List<UUID> parentEventIds,
       UUID sccId)
       throws ConfigInvalidException, IOException {
+    return toScs(
+        commit, repoName, branch, submitter, submittedAt, parentEventIds, sccId, Optional.empty());
+  }
+
+  public EiffelSourceChangeSubmittedEventInfo toScs(
+      RevCommit commit,
+      String repoName,
+      String branch,
+      AccountInfo submitter,
+      Long submittedAt,
+      List<UUID> parentEventIds,
+      UUID sccId,
+      Optional<UUID> id)
+      throws ConfigInvalidException, IOException {
     SubmitInfo submitInfo;
     if (submitter != null) {
       submitInfo = new SubmitInfo();
@@ -164,7 +189,8 @@
             commit.getName(),
             submitInfo.submittedAt,
             parentEventIds,
-            sccId);
+            sccId,
+            id);
   }
 
   @VisibleForTesting