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;
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
+++ /dev/null
-/*
- * 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();
- }
-}
*/
package org.sonar.core.activity.db;
-import org.apache.ibatis.annotations.Param;
-
import java.util.List;
/**
void insert(ActivityDto rule);
- ActivityDto selectByKey(@Param("key") ActivityKey key);
-
List<ActivityDto> selectAll();
}
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;
/**
* @since 4.4
*/
-public class ActivityDao extends BaseDao<ActivityMapper, ActivityDto, ActivityKey> {
+public class ActivityDao extends BaseDao<ActivityMapper, ActivityDto, String> {
public ActivityDao() {
this(System2.INSTANCE);
}
@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
}
@Override
- protected void doDeleteByKey(DbSession session, ActivityKey key) {
+ protected void doDeleteByKey(DbSession session, String key) {
throw new IllegalStateException("Cannot delete Log!");
}
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;
/**
* @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
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;
/**
* @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");
}
@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 {
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());
/* 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));