]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5329 - Consolidated with UUID id
authorStephane Gamard <stephane.gamard@searchbox.com>
Thu, 19 Jun 2014 13:47:58 +0000 (15:47 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Thu, 19 Jun 2014 14:17:51 +0000 (16:17 +0200)
sonar-core/src/main/java/org/sonar/core/activity/db/ActivityDto.java
sonar-core/src/main/java/org/sonar/core/activity/db/ActivityKey.java [deleted file]
sonar-core/src/main/java/org/sonar/core/activity/db/ActivityMapper.java
sonar-server/src/main/java/org/sonar/server/activity/db/ActivityDao.java
sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndex.java
sonar-server/src/main/java/org/sonar/server/activity/index/ActivityNormalizer.java

index 11da7e4af19081f2f8e2756399d0ff9aee338da7..eac3e65d45de34c78a1c1088fcfc067c908421ab 100644 (file)
@@ -26,11 +26,14 @@ import org.sonar.core.activity.Activity;
 import org.sonar.core.activity.ActivityLog;
 import org.sonar.core.persistence.Dto;
 
+import java.util.UUID;
+
 /**
  * @since 4.4
  */
-public final class ActivityDto extends Dto<ActivityKey> {
+public final class ActivityDto extends Dto<String> {
 
+  private String key;
   private String message;
   private Activity.Type type;
   private String action;
@@ -39,11 +42,12 @@ public final class ActivityDto extends Dto<ActivityKey> {
   private String data;
 
   protected ActivityDto() {
+    this.key = UUID.randomUUID().toString();
   }
 
   @Override
-  public ActivityKey getKey() {
-    return ActivityKey.of(this.getCreatedAt(), type, author);
+  public String getKey() {
+    return key;
   }
 
   @Override
diff --git a/sonar-core/src/main/java/org/sonar/core/activity/db/ActivityKey.java b/sonar-core/src/main/java/org/sonar/core/activity/db/ActivityKey.java
deleted file mode 100644 (file)
index 7031b1f..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.core.activity.db;
-
-import com.google.common.base.Preconditions;
-import org.sonar.core.activity.Activity;
-
-import java.io.Serializable;
-import java.util.Date;
-
-/**
- * @since 4.4
- */
-public class ActivityKey implements Serializable {
-
-  private Date createdAt;
-  private Activity.Type type;
-  private String author;
-
-  public ActivityKey(Date createdAt, Activity.Type type, String author) {
-    this.createdAt = createdAt;
-    this.type = type;
-    this.author = author;
-  }
-
-  /**
-   * Create a key. Parameters are NOT null.
-   */
-  public static ActivityKey of(Date createdAt, Activity.Type type, String author) {
-    Preconditions.checkArgument(createdAt != null, "Time must be set");
-    Preconditions.checkArgument(type != null, "Type must be set");
-    Preconditions.checkArgument(author != null, "Author must be set");
-    return new ActivityKey(createdAt, type, author);
-  }
-
-  /**
-   * Create a key from a string representation (see {@link #toString()}. An {@link IllegalArgumentException} is raised
-   * if the format is not valid.
-   */
-  public static ActivityKey parse(String s) {
-    String[] split = s.split(":");
-    Preconditions.checkArgument(split.length == 3, "Invalid log key: " + s);
-    return ActivityKey.of(new Date(Long.getLong(split[0])),
-      Activity.Type.valueOf(split[1]), split[2]);
-  }
-
-  public Date getCreatedAt() {
-    return createdAt;
-  }
-
-  public void setCreatedAt(Date createdAt) {
-    this.createdAt = createdAt;
-  }
-
-  public String getAuthor() {
-    return author;
-  }
-
-  public ActivityKey setAuthor(String author) {
-    this.author = author;
-    return this;
-  }
-
-  public Activity.Type getType() {
-    return type;
-  }
-
-  public ActivityKey setType(Activity.Type type) {
-    this.type = type;
-    return this;
-  }
-
-  @Override
-  public String toString() {
-    return this.createdAt.getTime() +
-      ":" + this.type +
-      ":" + this.getAuthor();
-  }
-}
index dd47fc8129b290f50060d9921ed02c8d0ac19b5d..0d507e08a832b08eb140a2de76d952b7a8ade88c 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonar.core.activity.db;
 
-import org.apache.ibatis.annotations.Param;
-
 import java.util.List;
 
 /**
@@ -30,7 +28,5 @@ public interface ActivityMapper {
 
   void insert(ActivityDto rule);
 
-  ActivityDto selectByKey(@Param("key") ActivityKey key);
-
   List<ActivityDto> selectAll();
 }
index 80c471929ffa1a90d7e7ed4950cf6e4668752910..0049e3468e49cd93301e1d99fa0ddf16bc1281ae 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.activity.db;
 import com.google.common.annotations.VisibleForTesting;
 import org.sonar.api.utils.System2;
 import org.sonar.core.activity.db.ActivityDto;
-import org.sonar.core.activity.db.ActivityKey;
 import org.sonar.core.activity.db.ActivityMapper;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.server.db.BaseDao;
@@ -36,7 +35,7 @@ import java.util.List;
 /**
  * @since 4.4
  */
-public class ActivityDao extends BaseDao<ActivityMapper, ActivityDto, ActivityKey> {
+public class ActivityDao extends BaseDao<ActivityMapper, ActivityDto, String> {
 
   public ActivityDao() {
     this(System2.INSTANCE);
@@ -48,8 +47,8 @@ public class ActivityDao extends BaseDao<ActivityMapper, ActivityDto, ActivityKe
   }
 
   @Override
-  protected ActivityDto doGetNullableByKey(DbSession session, ActivityKey key) {
-    return mapper(session).selectByKey(key);
+  protected ActivityDto doGetNullableByKey(DbSession session, String key) {
+    throw new IllegalStateException("Cannot execute getByKey on Activities in DB");
   }
 
   @Override
@@ -64,7 +63,7 @@ public class ActivityDao extends BaseDao<ActivityMapper, ActivityDto, ActivityKe
   }
 
   @Override
-  protected void doDeleteByKey(DbSession session, ActivityKey key) {
+  protected void doDeleteByKey(DbSession session, String key) {
     throw new IllegalStateException("Cannot delete Log!");
   }
 
index 3abb43fa16cbda408b45eef5669d245e6ebdb312..026c663ae88f192f6b41b77759852885beb524a6 100644 (file)
@@ -31,7 +31,6 @@ import org.elasticsearch.index.query.OrFilterBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.sonar.core.activity.Activity;
 import org.sonar.core.activity.db.ActivityDto;
-import org.sonar.core.activity.db.ActivityKey;
 import org.sonar.core.cluster.WorkQueue;
 import org.sonar.core.profiling.Profiling;
 import org.sonar.server.search.BaseIndex;
@@ -48,23 +47,22 @@ import java.util.Map;
 /**
  * @since 4.4
  */
-public class ActivityIndex extends BaseIndex<Activity, ActivityDto, ActivityKey> {
+public class ActivityIndex extends BaseIndex<Activity, ActivityDto, String> {
 
   public ActivityIndex(Profiling profiling, ActivityNormalizer normalizer, WorkQueue workQueue, ESNode node) {
     super(IndexDefinition.LOG, normalizer, workQueue, node, profiling);
   }
 
   @Override
-  protected String getKeyValue(ActivityKey key) {
-    // FIXME too many collision with key.toString() due to lack of time precision
-    return null;// return key.toString();
+  protected String getKeyValue(String key) {
+    return key;
   }
 
   @Override
   protected Map mapKey() {
-    return null;
-    // Map<String, Object> mapping = new HashMap<String, Object>();
-    // return mapping;
+    Map<String, Object> mapping = new HashMap<String, Object>();
+    mapping.put("path", ActivityNormalizer.LogFields.KEY.field());
+    return mapping;
   }
 
   @Override
index 3e43c4adf3783a87352b28f64a5e002c638b063b..def1b40fa769cad0d9926c5291c0850e165360fb 100644 (file)
@@ -24,7 +24,6 @@ import org.elasticsearch.action.support.replication.ReplicationType;
 import org.elasticsearch.action.update.UpdateRequest;
 import org.sonar.api.utils.KeyValueFormat;
 import org.sonar.core.activity.db.ActivityDto;
-import org.sonar.core.activity.db.ActivityKey;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.search.BaseNormalizer;
@@ -44,11 +43,12 @@ import java.util.Set;
 /**
  * @since 4.4
  */
-public class ActivityNormalizer extends BaseNormalizer<ActivityDto, ActivityKey> {
+public class ActivityNormalizer extends BaseNormalizer<ActivityDto, String> {
 
 
   public static final class LogFields extends Indexable {
 
+    public final static IndexField KEY = add(IndexField.Type.STRING, "key");
     public final static IndexField TYPE = addSortable(IndexField.Type.STRING, "type");
     public final static IndexField ACTION = addSortable(IndexField.Type.STRING, "action");
     public final static IndexField CREATED_AT = addSortable(IndexField.Type.DATE, "createdAt");
@@ -79,7 +79,7 @@ public class ActivityNormalizer extends BaseNormalizer<ActivityDto, ActivityKey>
   }
 
   @Override
-  public List<UpdateRequest> normalize(ActivityKey activityKey) {
+  public List<UpdateRequest> normalize(String activityKey) {
     DbSession dbSession = db.openSession(false);
     List<UpdateRequest> requests = new ArrayList<UpdateRequest>();
     try {
@@ -94,6 +94,7 @@ public class ActivityNormalizer extends BaseNormalizer<ActivityDto, ActivityKey>
   public List<UpdateRequest> normalize(ActivityDto dto) {
 
     Map<String, Object> logDoc = new HashMap<String, Object>();
+    logDoc.put(LogFields.KEY.field(), dto.getKey());
     logDoc.put(LogFields.TYPE.field(), dto.getType());
     logDoc.put(LogFields.ACTION.field(), dto.getAction());
     logDoc.put(LogFields.AUTHOR.field(), dto.getAuthor());
@@ -105,7 +106,7 @@ public class ActivityNormalizer extends BaseNormalizer<ActivityDto, ActivityKey>
 
    /* Creating updateRequest */
     return ImmutableList.of(new UpdateRequest()
-      //Need to make a UUID because Key does not insure unicity
+      .id(dto.getKey())
       .replicationType(ReplicationType.ASYNC)
       .doc(logDoc)
       .upsert(logDoc));