]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20864 Reset grace period when setting new license.
authorWojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com>
Fri, 27 Oct 2023 09:26:31 +0000 (11:26 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 8 Nov 2023 20:02:52 +0000 (20:02 +0000)
server/sonar-server-common/src/main/java/org/sonar/server/property/InternalProperties.java
server/sonar-server-common/src/main/java/org/sonar/server/property/InternalPropertiesImpl.java
server/sonar-server-common/src/main/java/org/sonar/server/property/MapInternalProperties.java
server/sonar-server-common/src/test/java/org/sonar/server/property/InternalPropertiesImplTest.java

index d9ba1f91ad8940d4868ab5caf1e64be0afb12cf7..2ce66cddc95a1b3b5f8e6d3aed4360c1c7eb9bd7 100644 (file)
@@ -74,4 +74,10 @@ public interface InternalProperties {
    * @throws IllegalArgumentException if {@code propertyKey} is {@code null} or empty
    */
   void write(String propertyKey, @Nullable String value);
+
+  /**
+   * Delete the specified property.
+   *
+   */
+  void delete(String propertyKey);
 }
index ec7cae9b116daee5fb29000a9681b5d91abcca71..a5304e2b7cae41d034a4fd63a384b09337520da7 100644 (file)
@@ -59,6 +59,15 @@ public class InternalPropertiesImpl implements InternalProperties {
     }
   }
 
+  @Override
+  public void delete(String propertyKey) {
+    checkPropertyKey(propertyKey);
+    try (DbSession dbSession = dbClient.openSession(false)) {
+      dbClient.internalPropertiesDao().delete(dbSession, propertyKey);
+      dbSession.commit();
+    }
+  }
+
   private static void checkPropertyKey(@Nullable String propertyKey) {
     checkArgument(propertyKey != null && !propertyKey.isEmpty(), "property key can't be null nor empty");
   }
index 353984515d3242416ee1bc427d0682f4ac61cfe1..5545a9aa98fac39c57dc58ca773c584d0f026012 100644 (file)
@@ -44,6 +44,12 @@ public class MapInternalProperties implements InternalProperties {
     values.put(propertyKey, value);
   }
 
+  @Override
+  public void delete(String propertyKey) {
+    checkPropertyKey(propertyKey);
+    values.remove(propertyKey);
+  }
+
   private static void checkPropertyKey(@Nullable String propertyKey) {
     checkArgument(propertyKey != null && !propertyKey.isEmpty(), "property key can't be null nor empty");
   }
index da714b784613fb087bf46e0a8c08eec9ae88f1ed..5d4715a1098fd3a6fc1ef3325d516d72ec333dd6 100644 (file)
@@ -103,6 +103,13 @@ public class InternalPropertiesImplTest {
     verify(dbSession).commit();
   }
 
+  @Test
+  public void delete_shouldCallDaoAndDeleteProperty() {
+    underTest.delete(SOME_KEY);
+    verify(internalPropertiesDao).delete(dbSession, SOME_KEY);
+    verify(dbSession).commit();
+  }
+
   private void expectKeyNullOrEmptyIAE(ThrowingCallable callback) {
     assertThatThrownBy(callback)
       .isInstanceOf(IllegalArgumentException.class)