]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8227 Create project measures authorisation index
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 19 Oct 2016 06:50:11 +0000 (08:50 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 20 Oct 2016 11:12:07 +0000 (13:12 +0200)
server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresAuthorizationDoc.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresIndexDefinition.java

diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresAuthorizationDoc.java b/server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresAuthorizationDoc.java
new file mode 100644 (file)
index 0000000..85950f3
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.component.es;
+
+import com.google.common.collect.Maps;
+import org.sonar.server.es.BaseDoc;
+
+import static org.sonar.server.component.es.ProjectMeasuresIndexDefinition.FIELD_AUTHORIZATION_PROJECT_UUID;
+
+public class ProjectMeasuresAuthorizationDoc extends BaseDoc {
+
+  public ProjectMeasuresAuthorizationDoc() {
+    super(Maps.newHashMap());
+  }
+
+  @Override
+  public String getId() {
+    return projectUuid();
+  }
+
+  @Override
+  public String getRouting() {
+    return projectUuid();
+  }
+
+  @Override
+  public String getParent() {
+    return null;
+  }
+
+  public String projectUuid() {
+    return getField(FIELD_AUTHORIZATION_PROJECT_UUID);
+  }
+
+  public ProjectMeasuresAuthorizationDoc setProjectUuid(String s) {
+    setField(FIELD_AUTHORIZATION_PROJECT_UUID, s);
+    return this;
+  }
+}
index 3c454d7d0960a03e25847fb38bdbaf990454f22e..c64d7c954b9790bf8984eb701d1110efc8141cf2 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.component.es;
 
+import com.google.common.collect.ImmutableMap;
 import org.sonar.api.config.Settings;
 import org.sonar.server.es.IndexDefinition;
 import org.sonar.server.es.NewIndex;
@@ -26,6 +27,7 @@ import org.sonar.server.es.NewIndex;
 public class ProjectMeasuresIndexDefinition implements IndexDefinition {
 
   public static final String INDEX_PROJECT_MEASURES = "projectmeasures";
+
   public static final String TYPE_PROJECT_MEASURES = "projectmeasures";
   public static final String FIELD_KEY = "key";
   public static final String FIELD_NAME = "name";
@@ -35,6 +37,12 @@ public class ProjectMeasuresIndexDefinition implements IndexDefinition {
   public static final String FIELD_MEASURES_KEY = "key";
   public static final String FIELD_MEASURES_VALUE = "value";
 
+  public static final String TYPE_AUTHORIZATION = "authorization";
+  public static final String FIELD_AUTHORIZATION_PROJECT_UUID = "project";
+  public static final String FIELD_AUTHORIZATION_GROUPS = "groups";
+  public static final String FIELD_AUTHORIZATION_USERS = "users";
+  public static final String FIELD_AUTHORIZATION_UPDATED_AT = "updatedAt";
+
   private final Settings settings;
 
   public ProjectMeasuresIndexDefinition(Settings settings) {
@@ -47,6 +55,7 @@ public class ProjectMeasuresIndexDefinition implements IndexDefinition {
     index.refreshHandledByIndexer();
     index.configureShards(settings, 5);
 
+    // type "projectmeasures"
     NewIndex.NewIndexType mapping = index.createType(TYPE_PROJECT_MEASURES);
     mapping.stringFieldBuilder(FIELD_KEY).disableNorms().build();
     mapping.stringFieldBuilder(FIELD_NAME).enableSorting().enableGramSearch().build();
@@ -59,5 +68,14 @@ public class ProjectMeasuresIndexDefinition implements IndexDefinition {
 
     // do not store document but only indexation of information
     mapping.setEnableSource(false);
+
+    // type "authorization"
+    NewIndex.NewIndexType authorizationMapping = index.createType(TYPE_AUTHORIZATION);
+    authorizationMapping.setAttribute("_routing", ImmutableMap.of("required", "true"));
+    authorizationMapping.createDateTimeField(FIELD_AUTHORIZATION_UPDATED_AT);
+    authorizationMapping.stringFieldBuilder(FIELD_AUTHORIZATION_PROJECT_UUID).disableNorms().build();
+    authorizationMapping.stringFieldBuilder(FIELD_AUTHORIZATION_GROUPS).disableNorms().build();
+    authorizationMapping.stringFieldBuilder(FIELD_AUTHORIZATION_USERS).disableNorms().build();
+    authorizationMapping.setEnableSource(false);
   }
 }