You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ho...@apache.org on 2026/08/31 08:34:39 UTC
(streampipes) 01/01: Migrate stored metadata to dataset naming
This is an automated email from the ASF dual-hosted git repository.
JHoelli pushed a commit to branch 4738-metadata-direct
in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit 4c42fcc7528cd8b4061366a5b43d9b6d98f1ae86
Author: Jacqueline Höllig <j....@gmx.net>
AuthorDate: Mon Aug 31 10:30:43 2026 +0200
Migrate stored metadata to dataset naming
---
.../core/migrations/AvailableMigrations.java | 2 +
.../RenameDataLakeMetadataToDatasetMigration.java | 72 ++++++++++++++
...nameDataLakeMetadataToDatasetMigrationTest.java | 110 +++++++++++++++++++++
3 files changed, 184 insertions(+)
diff --git a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/migrations/AvailableMigrations.java b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/migrations/AvailableMigrations.java
index 2e03b74c09..0d525752fc 100644
--- a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/migrations/AvailableMigrations.java
+++ b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/migrations/AvailableMigrations.java
@@ -38,6 +38,7 @@ import org.apache.streampipes.service.core.migrations.v099.RemoveAssetUserRoleMi
import org.apache.streampipes.service.core.migrations.v099.RemoveDuplicatedAssetPermissions;
import org.apache.streampipes.service.core.migrations.v099.RemoveInternalNotificationSinkMigration;
import org.apache.streampipes.service.core.migrations.v099.RemoveObsoletePrivilegesMigration;
+import org.apache.streampipes.service.core.migrations.v099.RenameDataLakeMetadataToDatasetMigration;
import org.apache.streampipes.service.core.migrations.v099.UniqueDashboardIdMigration;
import org.apache.streampipes.service.core.migrations.v099.connect.MigrateAdaptersToUseScript;
import org.apache.streampipes.service.core.migrations.v099.connect.MigratePlc4xS7AdaptersToGenericAdapter;
@@ -98,6 +99,7 @@ public class AvailableMigrations {
new MoveAssetContentMigration(),
new CreateAssetPermissionMigration(permissionStorage, assetStorage),
new CreateDatasetPermissionMigration(permissionStorage, pipelineStorage, datasetStorage),
+ new RenameDataLakeMetadataToDatasetMigration(permissionStorage),
new RemoveObsoletePrivilegesMigration(privilegeStorage),
new UniqueDashboardIdMigration(dashboardStorage),
new AddScriptTemplateViewMigration(),
diff --git a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/migrations/v099/RenameDataLakeMetadataToDatasetMigration.java b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/migrations/v099/RenameDataLakeMetadataToDatasetMigration.java
new file mode 100644
index 0000000000..c6bdd2ff4a
--- /dev/null
+++ b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/migrations/v099/RenameDataLakeMetadataToDatasetMigration.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.service.core.migrations.v099;
+
+import org.apache.streampipes.model.client.user.Permission;
+import org.apache.streampipes.service.core.migrations.Migration;
+import org.apache.streampipes.storage.api.user.IPermissionStorage;
+
+import java.io.IOException;
+import java.util.Map;
+
+public class RenameDataLakeMetadataToDatasetMigration implements Migration {
+
+ static final String DATA_LAKE_MEASURE_CLASS =
+ "org.apache.streampipes.model.datalake.DataLakeMeasure";
+ static final String DATASET_MEASURE_CLASS =
+ "org.apache.streampipes.model.dataset.DatasetMeasure";
+ static final String DATA_LAKE_WIDGET_CLASS =
+ "org.apache.streampipes.model.datalake.DataExplorerWidgetModel";
+ static final String DATASET_WIDGET_CLASS =
+ "org.apache.streampipes.model.dataset.DataExplorerWidgetModel";
+
+ private static final Map<String, String> CLASS_NAME_RENAMES = Map.of(
+ DATA_LAKE_MEASURE_CLASS, DATASET_MEASURE_CLASS,
+ DATA_LAKE_WIDGET_CLASS, DATASET_WIDGET_CLASS
+ );
+
+ private final IPermissionStorage permissionStorage;
+
+ public RenameDataLakeMetadataToDatasetMigration(IPermissionStorage permissionStorage) {
+ this.permissionStorage = permissionStorage;
+ }
+
+ @Override
+ public boolean shouldExecute() {
+ return permissionStorage.findAll().stream()
+ .map(Permission::getObjectClassName)
+ .anyMatch(CLASS_NAME_RENAMES::containsKey);
+ }
+
+ @Override
+ public void executeMigration() throws IOException {
+ permissionStorage.findAll().forEach(permission -> {
+ var renamedClass = CLASS_NAME_RENAMES.get(permission.getObjectClassName());
+ if (renamedClass != null) {
+ permission.setObjectClassName(renamedClass);
+ permissionStorage.updateElement(permission);
+ }
+ });
+ }
+
+ @Override
+ public String getDescription() {
+ return "Rename stored data lake metadata to dataset naming";
+ }
+}
diff --git a/streampipes-service-core/src/test/java/org/apache/streampipes/service/core/migrations/v099/RenameDataLakeMetadataToDatasetMigrationTest.java b/streampipes-service-core/src/test/java/org/apache/streampipes/service/core/migrations/v099/RenameDataLakeMetadataToDatasetMigrationTest.java
new file mode 100644
index 0000000000..889f7f5121
--- /dev/null
+++ b/streampipes-service-core/src/test/java/org/apache/streampipes/service/core/migrations/v099/RenameDataLakeMetadataToDatasetMigrationTest.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.service.core.migrations.v099;
+
+import org.apache.streampipes.model.client.user.Permission;
+import org.apache.streampipes.storage.api.user.IPermissionStorage;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+class RenameDataLakeMetadataToDatasetMigrationTest {
+
+ private IPermissionStorage permissionStorage;
+ private RenameDataLakeMetadataToDatasetMigration migration;
+
+ @BeforeEach
+ void setUp() {
+ this.permissionStorage = mock(IPermissionStorage.class);
+ this.migration = new RenameDataLakeMetadataToDatasetMigration(permissionStorage);
+ }
+
+ @Test
+ void shouldExecuteReturnsTrueWhenOldDataLakeClassNamesExist() {
+ var permission = permissionWithClassName(
+ RenameDataLakeMetadataToDatasetMigration.DATA_LAKE_MEASURE_CLASS
+ );
+ when(permissionStorage.findAll()).thenReturn(List.of(permission));
+
+ assertTrue(migration.shouldExecute());
+ }
+
+ @Test
+ void shouldExecuteReturnsFalseWhenMetadataAlreadyUsesDatasetNaming() {
+ var permission = permissionWithClassName(
+ RenameDataLakeMetadataToDatasetMigration.DATASET_MEASURE_CLASS
+ );
+ when(permissionStorage.findAll()).thenReturn(List.of(permission));
+
+ assertFalse(migration.shouldExecute());
+ }
+
+ @Test
+ void executeMigrationRenamesDatasetAndWidgetPermissionMetadata() throws IOException {
+ var measurePermission = permissionWithClassName(
+ RenameDataLakeMetadataToDatasetMigration.DATA_LAKE_MEASURE_CLASS
+ );
+ var widgetPermission = permissionWithClassName(
+ RenameDataLakeMetadataToDatasetMigration.DATA_LAKE_WIDGET_CLASS
+ );
+ var unchangedPermission = permissionWithClassName("org.apache.streampipes.model.dashboard.DashboardModel");
+
+ when(permissionStorage.findAll()).thenReturn(List.of(
+ measurePermission,
+ widgetPermission,
+ unchangedPermission
+ ));
+
+ migration.executeMigration();
+
+ assertEquals(
+ RenameDataLakeMetadataToDatasetMigration.DATASET_MEASURE_CLASS,
+ measurePermission.getObjectClassName()
+ );
+ assertEquals(
+ RenameDataLakeMetadataToDatasetMigration.DATASET_WIDGET_CLASS,
+ widgetPermission.getObjectClassName()
+ );
+ assertEquals(
+ "org.apache.streampipes.model.dashboard.DashboardModel",
+ unchangedPermission.getObjectClassName()
+ );
+
+ verify(permissionStorage).updateElement(measurePermission);
+ verify(permissionStorage).updateElement(widgetPermission);
+ verify(permissionStorage, never()).updateElement(unchangedPermission);
+ }
+
+ private Permission permissionWithClassName(String className) {
+ var permission = new Permission();
+ permission.setObjectClassName(className);
+ return permission;
+ }
+}