@Override
public void handleResult(ResultContext context) {
- Map<String, String> row = (Map<String, String>) context.getResultObject();
- String project = row.get("project");
- String user = row.get("user");
- String group = row.get("permission_group");
+ Map<String, Object> row = (Map<String, Object>) context.getResultObject();
+ String project = (String) row.get("project");
+ String user = (String) row.get("user");
+ String group = (String) row.get("permission_group");
+ Date updatedAt = (Date) row.get("updated_at");
IssueAuthorizationDto issueAuthorizationDto = authorizationDtoMap.get(project);
if (issueAuthorizationDto == null) {
issueAuthorizationDto = new IssueAuthorizationDto()
.setProject(project)
.setPermission(UserRole.USER);
+ issueAuthorizationDto.setUpdatedAt(updatedAt);
}
if (group != null) {
issueAuthorizationDto.addGroup(group);
Map<String, IssueAuthorizationDto> authorizationDtoMap = newHashMap();
- List<Map<String, String>> rows = session.selectList("org.sonar.core.issue.db.IssueAuthorizationMapper.selectAfterDate", params);
- for (Map<String, String> row : rows) {
- String project = row.get("project");
- String user = row.get("user");
- String group = row.get("permission_group");
+ List<Map<String, Object>> rows = session.selectList("org.sonar.core.issue.db.IssueAuthorizationMapper.selectAfterDate", params);
+ for (Map<String, Object> row : rows) {
+ String project = (String) row.get("project");
+ String user = (String) row.get("user");
+ String group = (String) row.get("permission_group");
+ Date updatedAt = (Date) row.get("updated_at");
IssueAuthorizationDto issueAuthorizationDto = authorizationDtoMap.get(project);
if (issueAuthorizationDto == null) {
issueAuthorizationDto = new IssueAuthorizationDto()
.setProject(project)
.setPermission(UserRole.USER);
+ issueAuthorizationDto.setUpdatedAt(updatedAt);
}
if (group != null) {
issueAuthorizationDto.addGroup(group);
package org.sonar.server.issue.index;
import org.sonar.server.search.BaseDoc;
+import org.sonar.server.search.IndexUtils;
+import java.util.Date;
import java.util.List;
import java.util.Map;
return (List<String>) getField(IssueAuthorizationNormalizer.IssueAuthorizationField.USERS.field());
}
+ public Date updatedAt() {
+ return IndexUtils.parseDateTime((String) getNullableField(IssueAuthorizationNormalizer.IssueAuthorizationField.UPDATED_AT.field()));
+ }
+
}
public static final IndexField PERMISSION = add(IndexField.Type.STRING, "permission");
public static final IndexField GROUPS = add(IndexField.Type.STRING, "groups");
public static final IndexField USERS = add(IndexField.Type.STRING, "users");
+ public static final IndexField UPDATED_AT = add(IndexField.Type.DATE, BaseNormalizer.UPDATED_AT_FIELD);
public static final Set<IndexField> ALL_FIELDS = getAllFields();
update.put(IssueAuthorizationField.PERMISSION.field(), dto.getPermission());
update.put(IssueAuthorizationField.USERS.field(), dto.getUsers());
update.put(IssueAuthorizationField.GROUPS.field(), dto.getGroups());
+ update.put(IssueAuthorizationField.UPDATED_AT.field(), dto.getUpdatedAt());
/** Upsert elements */
Map<String, Object> upsert = getUpsertFor(IssueAuthorizationField.ALL_FIELDS, update);
assertThat(result.language()).isNull();
assertThat(result.subProjectId()).isNull();
assertThat(result.projectId()).isEqualTo(1);
+ assertThat(result.getAuthorizationUpdatedAt()).isEqualTo(DateUtils.parseDate("2014-06-18"));
}
@Test
.setLanguage("java")
.setPath("src/org/struts/RequestContext.java")
.setSubProjectId(3L)
- .setEnabled(true);
+ .setEnabled(true)
+ .setAuthorizationUpdatedAt(DateUtils.parseDate("2014-06-18"));
dao.insert(session, componentDto);
session.commit();
assertThat(dto.getPermission()).isEqualTo("user");
assertThat(dto.getGroups()).containsExactly("Anyone", "devs");
assertThat(dto.getUsers()).containsExactly("user1");
+ assertThat(dto.getUpdatedAt()).isNotNull();
}
@Test
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
+import org.sonar.api.utils.DateUtils;
import org.sonar.api.web.UserRole;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.permission.PermissionFacade;
public void synchronize() throws Exception {
project = new ComponentDto()
.setKey("Sample")
- .setProjectId(1L);
+ .setProjectId(1L)
+ .setAuthorizationUpdatedAt(DateUtils.parseDate("2014-09-11"));
db.componentDao().insert(session, project);
GroupDto sonarUsers = new GroupDto().setName("devs");
assertThat(issueAuthorizationDoc.permission()).isEqualTo("user");
assertThat(issueAuthorizationDoc.groups()).containsExactly("devs");
assertThat(issueAuthorizationDoc.users()).containsExactly("john");
+ assertThat(issueAuthorizationDoc.updatedAt()).isNotNull();
tester.clearIndexes();
tester.get(Platform.class).executeStartupTasks();
--- /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.search;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.platform.Platform;
+import org.sonar.server.rule.RuleTesting;
+import org.sonar.server.rule.index.RuleIndex;
+import org.sonar.server.tester.ServerTester;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class IndexSynchronizerMediumTest {
+
+ @ClassRule
+ public static ServerTester tester = new ServerTester();
+
+ IndexSynchronizer synchronizer;
+ DbClient dbClient;
+ IndexClient indexClient;
+ Platform platform;
+ DbSession dbSession;
+
+ @Before
+ public void setUp() throws Exception {
+ dbClient = tester.get(DbClient.class);
+ indexClient = tester.get(IndexClient.class);
+ platform = tester.get(Platform.class);
+ dbSession = dbClient.openSession(false);
+ synchronizer = new IndexSynchronizer(dbClient, indexClient);
+ tester.clearDbAndIndexes();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ if (dbSession != null) {
+ dbSession.close();
+ }
+ }
+
+ @Test
+ public void can_synchronize() throws Exception {
+
+ int numberOfRules = 100;
+
+ for (int i = 0; i < numberOfRules; i++) {
+ dbClient.ruleDao().insert(dbSession, RuleTesting.newDto(RuleKey.of("test", "x" + i)));
+ }
+ dbSession.commit();
+
+ assertThat(indexClient.get(RuleIndex.class).countAll()).isEqualTo(numberOfRules);
+ tester.clearIndexes();
+ assertThat(indexClient.get(RuleIndex.class).countAll()).isEqualTo(0);
+
+ synchronizer.synchronize(dbSession, dbClient.ruleDao(), indexClient.get(RuleIndex.class));
+ assertThat(indexClient.get(RuleIndex.class).countAll()).isEqualTo(numberOfRules);
+ }
+}
+++ /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.search;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.sonar.api.rule.RuleKey;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.platform.Platform;
-import org.sonar.server.rule.RuleTesting;
-import org.sonar.server.rule.index.RuleIndex;
-import org.sonar.server.tester.ServerTester;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class IndexSynchronizerTest {
-
- @ClassRule
- public static ServerTester tester = new ServerTester();
-
- IndexSynchronizer synchronizer;
- DbClient dbClient;
- IndexClient indexClient;
- Platform platform;
- DbSession dbSession;
-
- @Before
- public void setUp() throws Exception {
- dbClient = tester.get(DbClient.class);
- indexClient = tester.get(IndexClient.class);
- platform = tester.get(Platform.class);
- dbSession = dbClient.openSession(false);
- synchronizer = new IndexSynchronizer(dbClient, indexClient);
- tester.clearDbAndIndexes();
- }
-
- @After
- public void tearDown() throws Exception {
- if (dbSession != null) {
- dbSession.close();
- }
- }
-
- @Test
- public void can_synchronize() throws Exception {
-
- int numberOfRules = 100;
-
- for (int i = 0; i < numberOfRules; i++) {
- dbClient.ruleDao().insert(dbSession, RuleTesting.newDto(RuleKey.of("test", "x" + i)));
- }
- dbSession.commit();
-
- assertThat(indexClient.get(RuleIndex.class).countAll()).isEqualTo(numberOfRules);
- tester.clearIndexes();
- assertThat(indexClient.get(RuleIndex.class).countAll()).isEqualTo(0);
-
- synchronizer.synchronize(dbSession, dbClient.ruleDao(), indexClient.get(RuleIndex.class));
- assertThat(indexClient.get(RuleIndex.class).countAll()).isEqualTo(numberOfRules);
- }
-}
\ No newline at end of file
<projects id="1" kee="org.struts:struts-core:src/org/struts/RequestContext.java" name="RequestContext.java" long_name="org.struts.RequestContext"
qualifier="FIL" scope="FIL" language="java" path="src/org/struts/RequestContext.java" root_id="3"
description="[null]" enabled="[true]" copy_resource_id="[null]" person_id="[null]" deprecated_kee="[null]"
- authorization_updated_at="[null]" created_at="2014-06-18"
+ authorization_updated_at="2014-06-18" created_at="2014-06-18"
/>
</dataset>
<!-- root project -->
<projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
description="the description" long_name="Apache Struts"
- enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]" authorization_updated_at="[null]" />
+ enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]" authorization_updated_at="2014-06-18" />
<snapshots id="1" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
status="P" islast="[true]" purge_status="[null]"
period1_mode="[null]" period1_param="[null]" period1_date="[null]"
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import java.util.Date;
+
public class ComponentDto extends AuthorizedComponentDto implements Component {
private String path;
private Long projectId;
private Long subProjectId;
private boolean enabled = true;
+ private Date authorizationUpdatedAt;
public ComponentDto setId(Long id) {
super.setId(id);
return this;
}
+ /**
+ * Only available on projects
+ */
+ @CheckForNull
+ public Date getAuthorizationUpdatedAt() {
+ return authorizationUpdatedAt;
+ }
+
+ public ComponentDto setAuthorizationUpdatedAt(@Nullable Date authorizationUpdatedAt) {
+ this.authorizationUpdatedAt = authorizationUpdatedAt;
+ return this;
+ }
}
p.language as language,
s.root_project_id as projectId,
p.root_id as subProjectId,
- p.path as path
+ p.path as path,
+ p.authorization_updated_at as authorizationUpdatedAt
</sql>
<sql id="authorizedComponentColumns">
</select>
<sql id="insertColumns">
- (kee, name, long_name, qualifier, scope, language, root_id, path, created_at)
+ (kee, name, long_name, qualifier, scope, language, root_id, path, created_at, authorization_updated_at)
</sql>
<insert id="insert" parameterType="Component" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
insert into projects <include refid="insertColumns"/>
- values (#{kee}, #{name}, #{longName}, #{qualifier}, #{scope}, #{language}, #{subProjectId}, #{path}, #{createdAt})
+ values (#{kee}, #{name}, #{longName}, #{qualifier}, #{scope}, #{language}, #{subProjectId}, #{path}, #{createdAt}, #{authorizationUpdatedAt})
</insert>
</mapper>
project_authorization.project as "project",
project_authorization.login as "user",
project_authorization.permission_group as "permission_group",
- project_authorization.permission_role as "permission_role"
+ project_authorization.permission_role as "permission_role",
+ project_authorization.updated_at as "updated_at"
FROM (
-- users
SELECT
projects.kee AS project,
+ projects.authorization_updated_at AS updated_at,
users.login AS login,
NULL AS permission_group,
user_roles.role as permission_role
-- groups without Anyone
SELECT
projects.kee AS project,
+ projects.authorization_updated_at AS updated_at,
NULL AS login,
groups.name AS permission_group,
group_roles.role as permission_role
-- Anyone groups
SELECT
projects.kee AS project,
+ projects.authorization_updated_at AS updated_at,
NULL AS login,
#{anyone} AS permission_group,
group_roles.role as permission_role
package org.sonar.core.component;
import org.junit.Test;
+import org.sonar.api.utils.DateUtils;
import static org.fest.assertions.Assertions.assertThat;
.setLanguage("java")
.setPath("src/org/struts/RequestContext.java")
.setProjectId(2L)
- .setSubProjectId(3L);
+ .setSubProjectId(3L)
+ .setAuthorizationUpdatedAt(DateUtils.parseDate("2014-09-11"));
assertThat(componentDto.getId()).isEqualTo(1L);
assertThat(componentDto.key()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java");
assertThat(componentDto.language()).isEqualTo("java");
assertThat(componentDto.projectId()).isEqualTo(2L);
assertThat(componentDto.subProjectId()).isEqualTo(3L);
+ assertThat(componentDto.getAuthorizationUpdatedAt()).isEqualTo(DateUtils.parseDate("2014-09-11"));
}
@Test