--- /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;
+
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * @since 4.4
+ */
+public interface Activity {
+
+ public static enum Type {
+ NONE, ACTIVE_RULE, SERVER
+ }
+
+ Date time();
+
+ String author();
+
+ Integer executionTime();
+
+ Map<String, String> details();
+
+ String message();
+
+}
--- /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;
+
+import java.util.Map;
+
+/**
+ * @since 4.4
+ */
+public interface ActivityLog {
+
+ Map<String, String> getDetails();
+
+ int getExecutionTime();
+
+}
--- /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 org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+import org.sonar.api.utils.KeyValueFormat;
+import org.sonar.core.activity.Activity;
+import org.sonar.core.activity.ActivityLog;
+import org.sonar.core.persistence.Dto;
+
+/**
+ * @since 4.4
+ */
+public final class ActivityDto extends Dto<ActivityKey> {
+
+ private String message;
+ private Activity.Type type;
+ private String author;
+
+ private Integer executionTime;
+
+ private String data;
+
+ protected ActivityDto() {
+ }
+
+ @Override
+ public ActivityKey getKey() {
+ return ActivityKey.of(this.getCreatedAt(), type, author);
+ }
+
+ @Override
+ public String toString() {
+ return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
+ }
+
+ public Activity.Type getType() {
+ return type;
+ }
+
+ public ActivityDto setType(Activity.Type type) {
+ this.type = type;
+ return this;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public ActivityDto setAuthor(String author) {
+ this.author = author;
+ return this;
+ }
+
+ public Integer getExecutionTime() {
+ return executionTime;
+ }
+
+ public ActivityDto setExecutionTime(Integer executionTime) {
+ this.executionTime = executionTime;
+ return this;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public ActivityDto setData(String data) {
+ this.data = data;
+ return this;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public ActivityDto setMessage(String message) {
+ this.message = message;
+ return this;
+ }
+
+ public static ActivityDto createFor(String message) {
+ return new ActivityDto()
+ .setMessage(message);
+ }
+
+ public static ActivityDto createFor(ActivityLog activityLog) {
+ return new ActivityDto()
+ .setData(KeyValueFormat.format(activityLog.getDetails()))
+ .setExecutionTime(activityLog.getExecutionTime());
+ }
+}
--- /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();
+ }
+}
--- /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 org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @since 4.4
+ */
+public interface ActivityMapper {
+
+ void insert(ActivityDto rule);
+
+ ActivityDto selectByKey(@Param("key") ActivityKey key);
+
+ List<ActivityDto> selectAll();
+}
+++ /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.log;
-
-import java.util.Date;
-import java.util.Map;
-
-/**
- * @since 4.4
- */
-public interface Log {
-
- public static enum Type {
- NONE, ACTIVE_RULE, SERVER
- }
-
- Date time();
-
- String author();
-
- Integer executionTime();
-
- Map<String, String> details();
-
- String message();
-
-}
+++ /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.log;
-
-import java.util.Map;
-
-/**
- * @since 4.4
- */
-public interface Loggable {
-
- Map<String, String> getDetails();
-
- int getExecutionTime();
-
-}
+++ /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.log.db;
-
-import org.apache.commons.lang.builder.ReflectionToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-import org.sonar.api.utils.KeyValueFormat;
-import org.sonar.core.log.Log;
-import org.sonar.core.log.Loggable;
-import org.sonar.core.persistence.Dto;
-
-/**
- * @since 4.4
- */
-public final class LogDto extends Dto<LogKey> {
-
- private String message;
- private Log.Type type;
- private String author;
-
- private Integer executionTime;
-
- private String data;
-
- protected LogDto(){
- }
-
- @Override
- public LogKey getKey() {
- return LogKey.of(this.getCreatedAt(), type, author);
- }
-
- @Override
- public String toString() {
- return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
- }
-
- public Log.Type getType() {
- return type;
- }
-
- public LogDto setType(Log.Type type) {
- this.type = type;
- return this;
- }
-
- public String getAuthor() {
- return author;
- }
-
- public LogDto setAuthor(String author) {
- this.author = author;
- return this;
- }
-
- public Integer getExecutionTime() {
- return executionTime;
- }
-
- public LogDto setExecutionTime(Integer executionTime) {
- this.executionTime = executionTime;
- return this;
- }
-
- public String getData() {
- return data;
- }
-
- public LogDto setData(String data) {
- this.data = data;
- return this;
- }
-
- public String getMessage() {
- return message;
- }
-
- public LogDto setMessage(String message) {
- this.message = message;
- return this;
- }
-
- public static LogDto createFor(String message) {
- return new LogDto()
- .setMessage(message);
- }
-
- public static LogDto createFor(Loggable loggable) {
- return new LogDto()
- .setData(KeyValueFormat.format(loggable.getDetails()))
- .setExecutionTime(loggable.getExecutionTime());
- }
-}
+++ /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.log.db;
-
-import com.google.common.base.Preconditions;
-import org.sonar.core.log.Log;
-
-import java.io.Serializable;
-import java.util.Date;
-
-/**
- * @since 4.4
- */
-public class LogKey implements Serializable {
-
- private Date createdAt;
- private Log.Type type;
- private String author;
-
- public LogKey(Date createdAt, Log.Type type, String author) {
- this.createdAt = createdAt;
- this.type = type;
- this.author = author;
- }
-
- /**
- * Create a key. Parameters are NOT null.
- */
- public static LogKey of(Date createdAt, Log.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 LogKey(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 LogKey parse(String s) {
- String[] split = s.split(":");
- Preconditions.checkArgument(split.length == 3, "Invalid log key: " + s);
- return LogKey.of(new Date(Long.getLong(split[0])),
- Log.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 LogKey setAuthor(String author) {
- this.author = author;
- return this;
- }
-
- public Log.Type getType() {
- return type;
- }
-
- public LogKey setType(Log.Type type) {
- this.type = type;
- return this;
- }
-
- @Override
- public String toString() {
- return this.createdAt.getTime() +
- ":" + this.type +
- ":" + this.getAuthor();
- }
-}
+++ /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.log.db;
-
-import org.apache.ibatis.annotations.Param;
-
-import java.util.List;
-
-/**
- * @since 4.4
- */
-public interface LogMapper {
-
- void insert(LogDto rule);
-
- LogDto selectByKey(@Param("key") LogKey key);
-
- List<LogDto> selectAll();
-}
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.mapping.Environment;
-import org.apache.ibatis.session.*;
+import org.apache.ibatis.session.Configuration;
+import org.apache.ibatis.session.ExecutorType;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
import org.apache.ibatis.type.JdbcType;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
import org.sonar.api.database.model.MeasureModel;
+import org.sonar.core.activity.db.ActivityDto;
+import org.sonar.core.activity.db.ActivityMapper;
import org.sonar.core.cluster.WorkQueue;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.component.db.ComponentMapper;
import org.sonar.core.config.Logback;
-import org.sonar.core.dashboard.*;
+import org.sonar.core.dashboard.ActiveDashboardDto;
+import org.sonar.core.dashboard.ActiveDashboardMapper;
+import org.sonar.core.dashboard.DashboardDto;
+import org.sonar.core.dashboard.DashboardMapper;
+import org.sonar.core.dashboard.WidgetDto;
+import org.sonar.core.dashboard.WidgetMapper;
+import org.sonar.core.dashboard.WidgetPropertyDto;
+import org.sonar.core.dashboard.WidgetPropertyMapper;
import org.sonar.core.dependency.DependencyDto;
import org.sonar.core.dependency.DependencyMapper;
import org.sonar.core.dependency.ResourceSnapshotDto;
import org.sonar.core.duplication.DuplicationUnitDto;
import org.sonar.core.graph.jdbc.GraphDto;
import org.sonar.core.graph.jdbc.GraphDtoMapper;
-import org.sonar.core.issue.db.*;
-import org.sonar.core.log.db.LogDto;
-import org.sonar.core.log.db.LogMapper;
+import org.sonar.core.issue.db.ActionPlanDto;
+import org.sonar.core.issue.db.ActionPlanMapper;
+import org.sonar.core.issue.db.ActionPlanStatsDto;
+import org.sonar.core.issue.db.ActionPlanStatsMapper;
+import org.sonar.core.issue.db.IssueChangeDto;
+import org.sonar.core.issue.db.IssueChangeMapper;
+import org.sonar.core.issue.db.IssueDto;
+import org.sonar.core.issue.db.IssueFilterDto;
+import org.sonar.core.issue.db.IssueFilterFavouriteDto;
+import org.sonar.core.issue.db.IssueFilterFavouriteMapper;
+import org.sonar.core.issue.db.IssueFilterMapper;
+import org.sonar.core.issue.db.IssueMapper;
+import org.sonar.core.issue.db.IssueStatsMapper;
import org.sonar.core.measure.db.MeasureDto;
import org.sonar.core.measure.db.MeasureFilterDto;
import org.sonar.core.measure.db.MeasureFilterMapper;
import org.sonar.core.measure.db.MeasureMapper;
import org.sonar.core.notification.db.NotificationQueueDto;
import org.sonar.core.notification.db.NotificationQueueMapper;
-import org.sonar.core.permission.*;
+import org.sonar.core.permission.GroupWithPermissionDto;
+import org.sonar.core.permission.PermissionTemplateDto;
+import org.sonar.core.permission.PermissionTemplateGroupDto;
+import org.sonar.core.permission.PermissionTemplateMapper;
+import org.sonar.core.permission.PermissionTemplateUserDto;
+import org.sonar.core.permission.UserWithPermissionDto;
import org.sonar.core.properties.PropertiesMapper;
import org.sonar.core.properties.PropertyDto;
import org.sonar.core.purge.PurgeMapper;
import org.sonar.core.purge.PurgeableSnapshotDto;
-import org.sonar.core.qualitygate.db.*;
-import org.sonar.core.qualityprofile.db.*;
-import org.sonar.core.resource.*;
+import org.sonar.core.qualitygate.db.ProjectQgateAssociationDto;
+import org.sonar.core.qualitygate.db.ProjectQgateAssociationMapper;
+import org.sonar.core.qualitygate.db.QualityGateConditionDto;
+import org.sonar.core.qualitygate.db.QualityGateConditionMapper;
+import org.sonar.core.qualitygate.db.QualityGateDto;
+import org.sonar.core.qualitygate.db.QualityGateMapper;
+import org.sonar.core.qualityprofile.db.ActiveRuleDto;
+import org.sonar.core.qualityprofile.db.ActiveRuleMapper;
+import org.sonar.core.qualityprofile.db.ActiveRuleParamDto;
+import org.sonar.core.qualityprofile.db.QualityProfileDto;
+import org.sonar.core.qualityprofile.db.QualityProfileMapper;
+import org.sonar.core.resource.ResourceDto;
+import org.sonar.core.resource.ResourceIndexDto;
+import org.sonar.core.resource.ResourceIndexerMapper;
+import org.sonar.core.resource.ResourceKeyUpdaterMapper;
+import org.sonar.core.resource.ResourceMapper;
+import org.sonar.core.resource.SnapshotDto;
import org.sonar.core.rule.RuleDto;
import org.sonar.core.rule.RuleMapper;
import org.sonar.core.rule.RuleParamDto;
import org.sonar.core.technicaldebt.db.RequirementMigrationDto;
import org.sonar.core.template.LoadedTemplateDto;
import org.sonar.core.template.LoadedTemplateMapper;
-import org.sonar.core.user.*;
+import org.sonar.core.user.AuthorDto;
+import org.sonar.core.user.AuthorMapper;
+import org.sonar.core.user.GroupDto;
+import org.sonar.core.user.GroupMembershipDto;
+import org.sonar.core.user.GroupMembershipMapper;
+import org.sonar.core.user.GroupRoleDto;
+import org.sonar.core.user.RoleMapper;
+import org.sonar.core.user.UserDto;
+import org.sonar.core.user.UserMapper;
+import org.sonar.core.user.UserRoleDto;
import java.io.InputStream;
loadAlias(conf, "ActiveRule", ActiveRuleDto.class);
loadAlias(conf, "ActiveRuleParam", ActiveRuleParamDto.class);
loadAlias(conf, "RequirementMigration", RequirementMigrationDto.class);
- loadAlias(conf, "Log", LogDto.class);
+ loadAlias(conf, "Log", ActivityDto.class);
// AuthorizationMapper has to be loaded before IssueMapper because this last one used it
loadMapper(conf, "org.sonar.core.user.AuthorizationMapper");
loadMapper(conf, ResourceMapper.class);
loadMapper(conf, "org.sonar.core.permission.PermissionMapper");
- Class<?>[] mappers = {LogMapper.class, ActiveDashboardMapper.class, AuthorMapper.class, DashboardMapper.class,
+ Class<?>[] mappers = {ActivityMapper.class, ActiveDashboardMapper.class, AuthorMapper.class, DashboardMapper.class,
DependencyMapper.class, DuplicationMapper.class, GraphDtoMapper.class,
IssueMapper.class, IssueStatsMapper.class, IssueChangeMapper.class, IssueFilterMapper.class, IssueFilterFavouriteMapper.class,
LoadedTemplateMapper.class, MeasureFilterMapper.class, PermissionTemplateMapper.class, PropertiesMapper.class, PurgeMapper.class,
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.core.log.db.LogMapper">
-
- <insert id="insert" parameterType="Log" useGeneratedKeys="false" lang="raw">
- insert into logs
- (created_at, log_type,execution_time_field,user_login,data_field, log_message)
- values (#{createdAt}, #{type}, #{executionTime}, #{author}, #{data}, #{message})
- </insert>
-
- <select id="selectByKey" parameterType="map" resultType="Log" lang="raw">
- SELECT
- l.created_at as "createdAt",
- l.log_type as "type",
- l.execution_time_field as "executionTime",
- l.user_login as "author",
- l.data_field as "data",
- l.log_message as "message"
- FROM logs l
- WHERE l.created_at=#{key.createdAt}
- AND l.user_login=#{key.author}
- AND l.log_type=#{key.type}
- </select>
-
- <select id="selectAll" parameterType="map" resultType="Log" lang="raw">
- SELECT
- l.created_at as "createdAt",
- l.log_type as "type",
- l.execution_time_field as "executionTime",
- l.user_login as "author",
- l.data_field as "data",
- l.log_message as "message"
- FROM logs l
- </select>
-</mapper>
-
--- /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.profiling;
+
+import org.junit.Test;
+
+public class ProfilingActivityFactoryTest {
+
+ @Test
+ public void just_for_coverage() throws Exception {
+ new ProfilingLogFactory().getLogger("domain");
+ }
+}
+++ /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.profiling;
-
-import org.junit.Test;
-
-public class ProfilingLogFactoryTest {
-
- @Test
- public void just_for_coverage() throws Exception {
- new ProfilingLogFactory().getLogger("domain");
- }
-}
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.technicaldebt.db.CharacteristicDao;
import org.sonar.core.template.LoadedTemplateDao;
+import org.sonar.server.activity.db.ActivityDao;
import org.sonar.server.component.persistence.ComponentDao;
-import org.sonar.server.log.db.LogDao;
import org.sonar.server.measure.persistence.MeasureDao;
import org.sonar.server.qualityprofile.db.ActiveRuleDao;
import org.sonar.server.rule.db.RuleDao;
private final ComponentDao componentDao;
private final ResourceDao resourceDao;
private final MeasureDao measureDao;
- private final LogDao logDao;
+ private final ActivityDao activityDao;
public DbClient(Database db, MyBatis myBatis, DaoComponent... daoComponents) {
this.db = db;
componentDao = getDao(map, ComponentDao.class);
resourceDao = getDao(map, ResourceDao.class);
measureDao = getDao(map, MeasureDao.class);
- logDao = getDao(map, LogDao.class);
+ activityDao = getDao(map, ActivityDao.class);
}
public Database database() {
return measureDao;
}
- public LogDao logDao() {
- return logDao;
+ public ActivityDao activityDao() {
+ return activityDao;
}
private <K> K getDao(Map<Class, DaoComponent> map, Class<K> clazz) {
+++ /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.server.log;
-
-import org.sonar.core.log.Log;
-import org.sonar.core.log.Loggable;
-import org.sonar.core.log.db.LogDto;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.log.index.LogIndex;
-import org.sonar.server.log.index.LogQuery;
-import org.sonar.server.search.IndexClient;
-import org.sonar.server.search.QueryOptions;
-import org.sonar.server.search.Result;
-import org.sonar.server.user.UserSession;
-
-import java.util.List;
-
-/**
- * Log service is used to log Activity classes which represents an event to DB and Index.
- *
- * @see org.sonar.core.log.Loggable
- * @since 4.4
- */
-public class LogService {
-
- private final DbClient dbClient;
- private final IndexClient indexClient;
-
- public LogService(DbClient dbClient, IndexClient indexClient) {
- this.dbClient = dbClient;
- this.indexClient = indexClient;
- }
-
- private String getAuthor() {
- return (UserSession.get().login() != null) ? UserSession.get().login() : "UNKNOWN";
- }
-
- private void save(DbSession session, LogDto log) {
- dbClient.logDao().insert(session,
- log.setAuthor(getAuthor()));
- }
-
- public void write(DbSession session, Log.Type type, String message) {
- this.write(session, type, message, null);
- }
-
- public void write(DbSession session, Log.Type type, String message, Integer time) {
- this.save(session, LogDto.createFor(message)
- .setType(type)
- .setExecutionTime(time));
- }
-
- public <L extends Loggable> void write(DbSession session, Log.Type type, List<L> logs) {
- for (Loggable log : logs) {
- this.write(session, type, log);
- }
- }
-
- public <L extends Loggable> void write(DbSession session, Log.Type type, L log) {
- this.save(session, LogDto.createFor(log)
- .setType(type));
- }
-
- public LogQuery newLogQuery() {
- return new LogQuery();
- }
-
- public Result<Log> search(LogQuery query, QueryOptions options) {
- return indexClient.get(LogIndex.class).search(query, options);
- }
-}
+++ /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.server.log.db;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.sonar.api.utils.System2;
-import org.sonar.core.log.db.LogDto;
-import org.sonar.core.log.db.LogKey;
-import org.sonar.core.log.db.LogMapper;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.server.db.BaseDao;
-import org.sonar.server.search.IndexDefinition;
-
-import java.util.List;
-
-/**
- * @since 4.4
- */
-public class LogDao extends BaseDao<LogMapper, LogDto, LogKey> {
-
- public LogDao() {
- this(System2.INSTANCE);
- }
-
- @VisibleForTesting
- public LogDao(System2 system) {
- super(IndexDefinition.LOG, LogMapper.class, system);
- }
-
- @Override
- protected LogDto doGetNullableByKey(DbSession session, LogKey key) {
- return mapper(session).selectByKey(key);
- }
-
- @Override
- protected LogDto doInsert(DbSession session, LogDto item) {
- mapper(session).insert(item);
- return item;
- }
-
- @Override
- protected LogDto doUpdate(DbSession session, LogDto item) {
- throw new IllegalStateException("Cannot update Log!");
- }
-
- @Override
- protected void doDeleteByKey(DbSession session, LogKey key) {
- throw new IllegalStateException("Cannot delete Log!");
- }
-
- public List<LogDto> findAll(DbSession session) {
- return mapper(session).selectAll();
- }
-
- @Override
- public void synchronizeAfter(DbSession session, long timestamp) {
- throw new IllegalStateException("Log Index does not synchronize!");
- }
-}
+++ /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.server.log.index;
-
-import org.sonar.core.log.Log;
-import org.sonar.server.search.BaseDoc;
-
-import java.util.Date;
-import java.util.Map;
-
-/**
- * @since 4.4
- */
-public class LogDoc extends BaseDoc implements Log {
-
- protected LogDoc(Map<String, Object> fields) {
- super(fields);
- }
-
- @Override
- public Date time() {
- return this.getField(LogNormalizer.LogFields.DATE.field());
- }
-
- @Override
- public String author() {
- return this.getField(LogNormalizer.LogFields.AUTHOR.field());
- }
-
- @Override
- public Integer executionTime() {
- return this.getField(LogNormalizer.LogFields.EXECUTION.field());
- }
-
- @Override
- public Map<String, String> details() {
- return this.getField(LogNormalizer.LogFields.DETAILS.field());
- }
-
- @Override
- public String message() {
- return this.getField(LogNormalizer.LogFields.MESSAGE.field());
- }
-}
+++ /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.server.log.index;
-
-import org.elasticsearch.action.search.SearchRequestBuilder;
-import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.action.search.SearchType;
-import org.elasticsearch.common.settings.ImmutableSettings;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.sonar.core.cluster.WorkQueue;
-import org.sonar.core.log.Log;
-import org.sonar.core.log.db.LogDto;
-import org.sonar.core.log.db.LogKey;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.BaseIndex;
-import org.sonar.server.search.ESNode;
-import org.sonar.server.search.IndexDefinition;
-import org.sonar.server.search.IndexField;
-import org.sonar.server.search.QueryOptions;
-import org.sonar.server.search.Result;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @since 4.4
- */
-public class LogIndex extends BaseIndex<Log, LogDto, LogKey> {
-
- public LogIndex(Profiling profiling, LogNormalizer normalizer, WorkQueue workQueue, ESNode node) {
- super(IndexDefinition.LOG, normalizer, workQueue, node, profiling);
- }
-
- @Override
- protected String getKeyValue(LogKey key) {
- // FIXME too many collision with key.toString() due to lack of time precision
- return null;// return key.toString();
- }
-
- @Override
- protected Map mapKey() {
- return null;
- // Map<String, Object> mapping = new HashMap<String, Object>();
- // return mapping;
- }
-
- @Override
- protected Settings getIndexSettings() throws IOException {
- return ImmutableSettings.builder().build();
- }
-
- @Override
- protected Map mapProperties() {
- Map<String, Object> mapping = new HashMap<String, Object>();
- for (IndexField field : LogNormalizer.LogFields.ALL_FIELDS) {
- mapping.put(field.field(), mapField(field));
- }
- return mapping;
- }
-
- @Override
- protected Log toDoc(final Map<String, Object> fields) {
- return new LogDoc(fields);
- }
-
- public Result<Log> findAll() {
- return new Result<Log>(this, getClient().prepareSearch(this.getIndexName())
- .setQuery(QueryBuilders.matchAllQuery())
- .setTypes(this.getIndexType())
- .setSize(Integer.MAX_VALUE)
- .get());
- }
-
- public Result<Log> search(LogQuery query, QueryOptions options) {
- SearchRequestBuilder esSearch = getClient()
- .prepareSearch(this.getIndexName())
- .setTypes(this.getIndexType())
- .setIndices(this.getIndexName());
-
- // TODO implement query and filters based on LogQuery
- esSearch.setQuery(QueryBuilders.matchAllQuery());
-
- if (options.isScroll()) {
- esSearch.setSearchType(SearchType.SCAN);
- esSearch.setScroll(TimeValue.timeValueMinutes(3));
- }
-
- SearchResponse esResult = esSearch.get();
-
- return new Result<Log>(this, esResult);
- }
-}
+++ /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.server.log.index;
-
-import com.google.common.collect.ImmutableList;
-import org.elasticsearch.action.support.replication.ReplicationType;
-import org.elasticsearch.action.update.UpdateRequest;
-import org.sonar.api.utils.KeyValueFormat;
-import org.sonar.core.log.db.LogDto;
-import org.sonar.core.log.db.LogKey;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.search.BaseNormalizer;
-import org.sonar.server.search.IndexDefinition;
-import org.sonar.server.search.IndexField;
-import org.sonar.server.search.Indexable;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @since 4.4
- */
-public class LogNormalizer extends BaseNormalizer<LogDto, LogKey> {
-
-
- public static final class LogFields extends Indexable {
-
- public final static IndexField KEY = addSortableAndSearchable(IndexField.Type.STRING, "key");
- public final static IndexField TYPE = addSortable(IndexField.Type.STRING, "type");
- public final static IndexField DATE = addSortable(IndexField.Type.DATE, "date");
- public final static IndexField EXECUTION = add(IndexField.Type.NUMERIC, "executionTime");
- public final static IndexField AUTHOR = addSearchable(IndexField.Type.STRING, "author");
- public final static IndexField DETAILS = addSearchable(IndexField.Type.OBJECT, "details");
- public final static IndexField MESSAGE = addSearchable(IndexField.Type.STRING, "message");
-
- public static Set<IndexField> ALL_FIELDS = getAllFields();
-
- private static Set<IndexField> getAllFields() {
- Set<IndexField> fields = new HashSet<IndexField>();
- for (Field classField : LogFields.class.getDeclaredFields()) {
- if (Modifier.isFinal(classField.getModifiers()) && Modifier.isStatic(classField.getModifiers())) {
- try {
- fields.add(IndexField.class.cast(classField.get(null)));
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
- }
- return fields;
- }
- }
-
- public LogNormalizer(DbClient db) {
- super(IndexDefinition.LOG, db);
- }
-
- @Override
- public List<UpdateRequest> normalize(LogKey logKey) {
- DbSession dbSession = db.openSession(false);
- List<UpdateRequest> requests = new ArrayList<UpdateRequest>();
- try {
- requests.addAll(normalize(db.logDao().getNullableByKey(dbSession, logKey)));
- } finally {
- dbSession.close();
- }
- return requests;
- }
-
- @Override
- public List<UpdateRequest> normalize(LogDto 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.AUTHOR.field(), dto.getAuthor());
- logDoc.put(LogFields.MESSAGE.field(), dto.getMessage());
- logDoc.put(LogFields.EXECUTION.field(), dto.getExecutionTime());
- logDoc.put(LogFields.DATE.field(), dto.getCreatedAt());
-
- logDoc.put(LogFields.DETAILS.field(), KeyValueFormat.parse(dto.getData()));
-
- /* Creating updateRequest */
- return ImmutableList.of(new UpdateRequest()
- //Need to make a UUID because Key does not insure unicity
- .replicationType(ReplicationType.ASYNC)
- .doc(logDoc)
- .upsert(logDoc));
- }
-}
+++ /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.server.log.index;
-
-import org.sonar.core.log.Log;
-
-import java.util.Collection;
-import java.util.Date;
-
-/**
- * @since 4.4
- */
-public class LogQuery {
-
- private Date since;
- private Date to;
- private Collection<Log.Type> types;
-
- public LogQuery() {
- }
-
- public Date getSince() {
- return since;
- }
-
- public void setSince(Date since) {
- this.since = since;
- }
-
- public Date getTo() {
- return to;
- }
-
- public void setTo(Date to) {
- this.to = to;
- }
-
- public Collection<Log.Type> getTypes() {
- return types;
- }
-
- public void setTypes(Collection<Log.Type> types) {
- this.types = types;
- }
-}
+++ /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.server.log.ws;
-
-import org.sonar.api.resources.Languages;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.core.log.Log;
-import org.sonar.server.log.index.LogNormalizer;
-import org.sonar.server.search.ws.BaseMapping;
-import org.sonar.server.text.MacroInterpreter;
-
-import java.util.Map;
-
-/**
- * Conversion between Log and WS JSON response
- */
-public class LogMapping extends BaseMapping {
-
-
- public LogMapping(Languages languages, MacroInterpreter macroInterpreter) {
- super();
- addIndexStringField("key", LogNormalizer.LogFields.KEY.field());
- addIndexStringField("type", LogNormalizer.LogFields.TYPE.field());
- addIndexDatetimeField("createdAt", LogNormalizer.LogFields.DATE.field());
- addIndexStringField("userLogin", LogNormalizer.LogFields.AUTHOR.field());
- addIndexStringField("message", LogNormalizer.LogFields.MESSAGE.field());
- addIndexStringField("executionTime", LogNormalizer.LogFields.EXECUTION.field());
- addField("details", new DetailField());
- }
-
- private static class DetailField extends IndexField<Log> {
- DetailField() {
- super(LogNormalizer.LogFields.DETAILS.field());
- }
-
- @Override
- public void write(JsonWriter json, Log log) {
- json.name("details").beginObject();
- for (Map.Entry<String, String> detail : log.details().entrySet()) {
- json.prop(detail.getKey(), detail.getValue());
- }
- json.endObject();
- }
- }
-}
+++ /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.server.log.ws;
-
-import org.sonar.api.server.ws.WebService;
-
-public class LogsWebService implements WebService {
-
- public static final String API_ENDPOINT = "api/logs";
-
- private final SearchAction search;
-
- public LogsWebService(SearchAction search) {
- this.search = search;
- }
-
- @Override
- public void define(Context context) {
- NewController controller = context
- .createController(API_ENDPOINT)
- .setDescription("Logs search and views");
-
- search.define(controller);
- controller.done();
- }
-}
+++ /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.server.log.ws;
-
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.RequestHandler;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.core.log.Log;
-import org.sonar.server.log.LogService;
-import org.sonar.server.log.index.LogDoc;
-import org.sonar.server.log.index.LogQuery;
-import org.sonar.server.search.QueryOptions;
-import org.sonar.server.search.Result;
-import org.sonar.server.search.ws.SearchOptions;
-
-/**
- * @since 4.4
- */
-public class SearchAction implements RequestHandler {
-
- public static final String PARAM_TYPE = "type";
-
- public static final String SEARCH_ACTION = "search";
-
- private final LogService logService;
- private final LogMapping mapping;
-
- public SearchAction(LogService logService, LogMapping mapping) {
- this.logService = logService;
- this.mapping = mapping;
- }
-
- void define(WebService.NewController controller) {
- WebService.NewAction action = controller
- .createAction(SEARCH_ACTION)
- .setDescription("Search for a logs")
- .setSince("4.4")
- .setHandler(this);
-
- // Other parameters
- action.createParam(PARAM_TYPE)
- .setDescription("Select types of log to search")
- .setPossibleValues(Log.Type.values())
- .setDefaultValue(StringUtils.join(Log.Type.values(), ","));
-
- // Generic search parameters
- SearchOptions.defineFieldsParam(action, mapping.supportedFields());
-
- SearchOptions.definePageParams(action);
- }
-
- @Override
- public void handle(Request request, Response response) {
- LogQuery query = createLogQuery(logService.newLogQuery(), request);
- SearchOptions searchOptions = SearchOptions.create(request);
- QueryOptions queryOptions = mapping.newQueryOptions(searchOptions);
-
- Result<Log> results = logService.search(query, queryOptions);
-
- JsonWriter json = response.newJsonWriter().beginObject();
- searchOptions.writeStatistics(json, results);
- writeLogs(results, json, searchOptions);
- json.endObject().close();
- }
-
- public static LogQuery createLogQuery(LogQuery query, Request request) {
- // query.setTypes(request.param(SearchOptions.PARAM_TEXT_QUERY));
- return query;
- }
-
- private void writeLogs(Result<Log> result, JsonWriter json, SearchOptions options) {
- json.name("logs").beginArray();
- for (Log log : result.getHits()) {
- mapping.write((LogDoc) log, json, options);
- }
- json.endArray();
- }
-}
import org.sonar.jpa.session.DatabaseSessionProvider;
import org.sonar.jpa.session.DefaultDatabaseConnector;
import org.sonar.jpa.session.ThreadLocalDatabaseSessionFactory;
+import org.sonar.server.activity.ActivityService;
+import org.sonar.server.activity.db.ActivityDao;
+import org.sonar.server.activity.index.ActivityIndex;
+import org.sonar.server.activity.index.ActivityNormalizer;
+import org.sonar.server.activity.ws.ActivitiesWebService;
+import org.sonar.server.activity.ws.ActivityMapping;
import org.sonar.server.authentication.ws.AuthenticationWs;
import org.sonar.server.charts.ChartFactory;
import org.sonar.server.component.DefaultComponentFinder;
import org.sonar.server.issue.ws.IssueSearchAction;
import org.sonar.server.issue.ws.IssueShowAction;
import org.sonar.server.issue.ws.IssuesWs;
-import org.sonar.server.log.LogService;
-import org.sonar.server.log.db.LogDao;
-import org.sonar.server.log.index.LogIndex;
-import org.sonar.server.log.index.LogNormalizer;
-import org.sonar.server.log.ws.LogMapping;
-import org.sonar.server.log.ws.LogsWebService;
import org.sonar.server.measure.MeasureFilterEngine;
import org.sonar.server.measure.MeasureFilterExecutor;
import org.sonar.server.measure.MeasureFilterFactory;
ComponentDao.class,
DbClient.class,
MeasureFilterDao.class,
- LogDao.class,
+ ActivityDao.class,
// Elasticsearch
ESNode.class,
ActiveRuleIndex.class,
IndexQueueWorker.class,
IndexClient.class,
- LogNormalizer.class,
- LogIndex.class,
+ ActivityNormalizer.class,
+ ActivityIndex.class,
// LogService
- LogService.class
+ ActivityService.class
));
components.addAll(CorePropertyDefinitions.all());
pico.addSingleton(ActiveRuleCompleter.class);
pico.addSingleton(AppAction.class);
- pico.addSingleton(LogsWebService.class);
- pico.addSingleton(org.sonar.server.log.ws.SearchAction.class);
- pico.addSingleton(LogMapping.class);
+ pico.addSingleton(ActivitiesWebService.class);
+ pico.addSingleton(SearchAction.class);
+ pico.addSingleton(ActivityMapping.class);
// measure
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
-import org.sonar.core.log.Loggable;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.core.activity.ActivityLog;
import org.sonar.core.qualityprofile.db.ActiveRuleKey;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.util.Map;
-public class ActiveRuleChange implements Loggable {
+public class ActiveRuleChange implements ActivityLog {
static enum Type {
ACTIVATED, DEACTIVATED, UPDATED
details.put("ruleKey", getKey().ruleKey().toString());
details.put("profileKey", getKey().qProfile().toString());
}
+ if (!parameters.isEmpty()) {
+ for (Map.Entry<String, String> param : parameters.entrySet()) {
+ details.put("param_" + param.getKey(), param.getValue());
+ }
+ }
+ if (StringUtils.isNotEmpty(severity)) {
+ details.put("severity", severity);
+ }
+ if (inheritance != null) {
+ details.put("inheritance", inheritance.name());
+ }
return details.build();
}
*/
package org.sonar.server.qualityprofile;
-import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import org.sonar.api.ServerComponent;
return counts;
}
- public Multimap<QualityProfileKey, FacetValue> getAllProfileStats() {
+ public Multimap<String, FacetValue> getStatsByProfile(QualityProfileKey key) {
+ return index.get(ActiveRuleIndex.class).getStatsByProfileKey(key);
+ }
+
+ public Map<QualityProfileKey, Multimap<String, FacetValue>> getAllProfileStats() {
List<QualityProfileKey> keys = Lists.newArrayList();
for (QualityProfileDto profile : this.findAll()) {
keys.add(profile.getKey());
}
-
- Multimap<QualityProfileKey, FacetValue> stats = ArrayListMultimap.create();
-
- Collection<FacetValue> profilesStats = index.get(ActiveRuleIndex.class).getStatsByProfileKey(keys);
- for (FacetValue profileStat : profilesStats) {
- stats.put(QualityProfileKey.parse(profileStat.getKey()), profileStat);
- }
- return stats;
+ return index.get(ActiveRuleIndex.class).getStatsByProfileKey(keys);
}
}
import org.apache.commons.lang.StringUtils;
import org.sonar.api.ServerComponent;
import org.sonar.api.server.rule.RuleParamType;
-import org.sonar.core.log.Log;
+import org.sonar.core.activity.Activity;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.preview.PreviewCache;
import org.sonar.core.qualityprofile.db.ActiveRuleDto;
import org.sonar.core.rule.RuleParamDto;
import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.log.LogService;
+import org.sonar.server.log.ActivityService;
import org.sonar.server.qualityprofile.db.ActiveRuleDao;
import org.sonar.server.rule.Rule;
import org.sonar.server.rule.index.RuleIndex;
import org.sonar.server.util.TypeValidations;
import javax.annotation.Nullable;
-
import java.util.Iterator;
import java.util.List;
import java.util.Map;
private final RuleActivatorContextFactory contextFactory;
private final PreviewCache previewCache;
private final IndexClient index;
- private final LogService log;
+ private final ActivityService log;
public RuleActivator(DbClient db, IndexClient index,
- RuleActivatorContextFactory contextFactory, TypeValidations typeValidations,
- PreviewCache previewCache, LogService log) {
+ RuleActivatorContextFactory contextFactory, TypeValidations typeValidations,
+ PreviewCache previewCache, ActivityService log) {
this.db = db;
this.index = index;
this.contextFactory = contextFactory;
}
if (!changes.isEmpty()) {
- log.write(dbSession, Log.Type.ACTIVE_RULE, changes);
+ log.write(dbSession, Activity.Type.ACTIVE_RULE, changes);
previewCache.reportGlobalModification();
}
return changes;
* 1. defined by end-user
* 2. else inherited from parent profile
* 3. else defined by rule defaults
- *
+ * <p/>
* On custom rules, it's always rule parameters that are used
*/
private void applySeverityAndParamToChange(RuleActivation activation, RuleActivatorContext context, ActiveRuleChange change) {
}
if (!changes.isEmpty()) {
- log.write(dbSession, Log.Type.ACTIVE_RULE, changes);
+ log.write(dbSession, Activity.Type.ACTIVE_RULE, changes);
previewCache.reportGlobalModification();
}
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
return request.get().getCount();
}
-
- public Collection<FacetValue> getStatsByProfileKey(List<QualityProfileKey> keys) {
-
- // Get QProfiles keys as Strings
- String[] stringKeys = new String[keys.size()];
- for (int i = 0; i < keys.size(); i++) {
- stringKeys[i] = keys.get(i).toString();
- }
+ public Multimap<String, FacetValue> getStatsByProfileKey(QualityProfileKey key) {
SearchResponse response = getClient().prepareSearch(this.getIndexName())
.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
- FilterBuilders.termsFilter(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field(), stringKeys)))
+ FilterBuilders.termsFilter(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field(), key.toString())))
.addAggregation(AggregationBuilders.terms(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field())
.field(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field())
.subAggregation(AggregationBuilders.terms(ActiveRuleNormalizer.ActiveRuleField.INHERITANCE.field())
.field(ActiveRuleNormalizer.ActiveRuleField.INHERITANCE.field())
.subAggregation(AggregationBuilders.terms(ActiveRuleNormalizer.ActiveRuleField.SEVERITY.field())
.field(ActiveRuleNormalizer.ActiveRuleField.SEVERITY.field()))))
+ .addAggregation(AggregationBuilders.terms(ActiveRuleNormalizer.ActiveRuleField.INHERITANCE.field())
+ .field(ActiveRuleNormalizer.ActiveRuleField.INHERITANCE.field()))
+ .addAggregation(AggregationBuilders.terms(ActiveRuleNormalizer.ActiveRuleField.SEVERITY.field())
+ .field(ActiveRuleNormalizer.ActiveRuleField.SEVERITY.field()))
+
.setSize(0)
.setTypes(this.getIndexType())
.get();
- Multimap<String, FacetValue> stats = this.processAggregations(response.getAggregations());
+ return this.processAggregations(response.getAggregations());
+ }
- return stats.get(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field());
+ public Map<QualityProfileKey, Multimap<String, FacetValue>> getStatsByProfileKey(List<QualityProfileKey> keys) {
+ //TODO Optimize in a single request.
+ Map<QualityProfileKey, Multimap<String, FacetValue>> stats = new HashMap<QualityProfileKey, Multimap<String, FacetValue>>();
+ for (QualityProfileKey key : keys) {
+ stats.put(key, getStatsByProfileKey(key));
+ }
+ return stats;
}
}
import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.api.rule.RuleKey;
-import org.sonar.core.log.Log;
+import org.sonar.core.activity.Activity;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.qualityprofile.db.ActiveRuleKey;
import org.sonar.core.qualityprofile.db.QualityProfileKey;
+import org.sonar.server.activity.ActivityService;
+import org.sonar.server.activity.index.ActivityIndex;
import org.sonar.server.db.DbClient;
-import org.sonar.server.log.LogService;
-import org.sonar.server.log.index.LogIndex;
import org.sonar.server.tester.ServerTester;
import static org.fest.assertions.Assertions.assertThat;
@ClassRule
public static ServerTester tester = new ServerTester();
- LogService service = tester.get(LogService.class);
- LogIndex index = tester.get(LogIndex.class);
+ ActivityService service = tester.get(ActivityService.class);
+ ActivityIndex index = tester.get(ActivityIndex.class);
DbClient db;
DbSession dbSession;
.setSeverity("BLOCKER")
.setParameter("param1", "value1");
- service.write(dbSession, Log.Type.ACTIVE_RULE, change);
+ service.write(dbSession, Activity.Type.ACTIVE_RULE, change);
dbSession.commit();
// 0. AssertBase case
assertThat(index.findAll().getHits()).hasSize(1);
- Log log = Iterables.getFirst(index.findAll().getHits(), null);
- assertThat(log).isNotNull();
- assertThat(log.details().get("key")).isEqualTo(key.toString());
+ Activity activity = Iterables.getFirst(index.findAll().getHits(), null);
+ assertThat(activity).isNotNull();
+ assertThat(activity.details().get("key")).isEqualTo(key.toString());
}
}
\ No newline at end of file
--- /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.server.startup;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.slf4j.Logger;
+import org.sonar.api.CoreProperties;
+import org.sonar.core.properties.PropertiesDao;
+import org.sonar.core.properties.PropertyDto;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.*;
+
+public class ActivityServerIdTest {
+
+ @Mock
+ private PropertiesDao dao;
+
+ @Mock
+ private Logger logger;
+
+ private LogServerId logServerId;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+
+ when(dao.selectGlobalProperty(CoreProperties.PERMANENT_SERVER_ID)).thenReturn(new PropertyDto().setValue("123456789"));
+ when(dao.selectGlobalProperty(CoreProperties.ORGANISATION)).thenReturn(new PropertyDto().setValue("SonarSource"));
+ when(dao.selectGlobalProperty(CoreProperties.SERVER_ID_IP_ADDRESS)).thenReturn(new PropertyDto().setValue("1.2.3.4"));
+
+ logServerId = new LogServerId(dao);
+ }
+
+ @Test
+ public void shouldLogMessage() {
+ logServerId.logServerId(logger);
+
+ String log =
+ "Server information:\n"
+ + " - ID : \"123456789\"\n"
+ + " - Organisation : \"SonarSource\"\n"
+ + " - Registered IP : \"1.2.3.4\"\n";
+
+ verify(logger, times(1)).info(log);
+ }
+
+ @Test
+ public void shouldNotLogMessage() {
+ when(dao.selectGlobalProperty(CoreProperties.PERMANENT_SERVER_ID)).thenReturn(null);
+
+ logServerId.logServerId(logger);
+
+ verify(logger, never()).info(anyString());
+ }
+
+ @Test
+ public void testStartMethod() {
+ // just to have 100% coverage ;-)
+ logServerId.start();
+ }
+
+}
+++ /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.server.startup;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.slf4j.Logger;
-import org.sonar.api.CoreProperties;
-import org.sonar.core.properties.PropertiesDao;
-import org.sonar.core.properties.PropertyDto;
-
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class LogServerIdTest {
-
- @Mock
- private PropertiesDao dao;
-
- @Mock
- private Logger logger;
-
- private LogServerId logServerId;
-
- @Before
- public void init() {
- MockitoAnnotations.initMocks(this);
-
- when(dao.selectGlobalProperty(CoreProperties.PERMANENT_SERVER_ID)).thenReturn(new PropertyDto().setValue("123456789"));
- when(dao.selectGlobalProperty(CoreProperties.ORGANISATION)).thenReturn(new PropertyDto().setValue("SonarSource"));
- when(dao.selectGlobalProperty(CoreProperties.SERVER_ID_IP_ADDRESS)).thenReturn(new PropertyDto().setValue("1.2.3.4"));
-
- logServerId = new LogServerId(dao);
- }
-
- @Test
- public void shouldLogMessage() {
- logServerId.logServerId(logger);
-
- String log =
- "Server information:\n"
- + " - ID : \"123456789\"\n"
- + " - Organisation : \"SonarSource\"\n"
- + " - Registered IP : \"1.2.3.4\"\n";
-
- verify(logger, times(1)).info(log);
- }
-
- @Test
- public void shouldNotLogMessage() {
- when(dao.selectGlobalProperty(CoreProperties.PERMANENT_SERVER_ID)).thenReturn(null);
-
- logServerId.logServerId(logger);
-
- verify(logger, never()).info(anyString());
- }
-
- @Test
- public void testStartMethod() {
- // just to have 100% coverage ;-)
- logServerId.start();
- }
-
-}