This is an automated email from the ASF dual-hosted git repository.
yasithdev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata.git
The following commit(s) were added to refs/heads/master by this push:
new 78ed5b8441 refactor: drop the redundant sharing-service SharingHelper
(#636)
78ed5b8441 is described below
commit 78ed5b8441fd9a99d8d0dfb39f1943b5a6aca937
Author: Yasith Jayawardana <[email protected]>
AuthorDate: Sun Jun 7 19:32:15 2026 -0400
refactor: drop the redundant sharing-service SharingHelper (#636)
ResourceSharingService was the only consumer of sharing-service's
util.SharingHelper, a near-duplicate of the shared
org.apache.airavata.util.SharingHelper that was also incorrectly annotated
@Service despite having a private constructor and only static methods. It now
uses the core helper directly, since its arguments are compatible
(registryHandler is a RegistryProvider, gatewayGroupsInitializer a
GatewayGroupsProvider, and sharingHandler a SharingService which implements the
Sharin [...]
---
.../sharing/service/ResourceSharingService.java | 2 +-
.../airavata/sharing/util/SharingHelper.java | 117 ---------------------
2 files changed, 1 insertion(+), 118 deletions(-)
diff --git
a/airavata-api/sharing-service/src/main/java/org/apache/airavata/sharing/service/ResourceSharingService.java
b/airavata-api/sharing-service/src/main/java/org/apache/airavata/sharing/service/ResourceSharingService.java
index 81ba765828..90f0443c57 100644
---
a/airavata-api/sharing-service/src/main/java/org/apache/airavata/sharing/service/ResourceSharingService.java
+++
b/airavata-api/sharing-service/src/main/java/org/apache/airavata/sharing/service/ResourceSharingService.java
@@ -36,7 +36,7 @@ import
org.apache.airavata.model.group.proto.ResourcePermissionType;
import org.apache.airavata.model.group.proto.ResourceType;
import org.apache.airavata.sharing.model.UserEntity;
import org.apache.airavata.sharing.model.UserGroupEntity;
-import org.apache.airavata.sharing.util.SharingHelper;
+import org.apache.airavata.util.SharingHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
diff --git
a/airavata-api/sharing-service/src/main/java/org/apache/airavata/sharing/util/SharingHelper.java
b/airavata-api/sharing-service/src/main/java/org/apache/airavata/sharing/util/SharingHelper.java
deleted file mode 100644
index 210aee9ef2..0000000000
---
a/airavata-api/sharing-service/src/main/java/org/apache/airavata/sharing/util/SharingHelper.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/**
-*
-* 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.airavata.sharing.util;
-
-import java.util.Arrays;
-import org.apache.airavata.config.ServerSettings;
-import org.apache.airavata.interfaces.GatewayGroupsProvider;
-import org.apache.airavata.interfaces.RegistryProvider;
-import org.apache.airavata.model.appcatalog.gatewaygroups.proto.GatewayGroups;
-import org.apache.airavata.model.group.proto.ResourcePermissionType;
-import org.apache.airavata.sharing.model.EntityEntity;
-import org.apache.airavata.sharing.model.PermissionTypeEntity;
-import org.apache.airavata.sharing.service.SharingService;
-import org.springframework.stereotype.Service;
-
-@Service
-public class SharingHelper {
-
- private SharingHelper() {
- // utility class
- }
-
- public static boolean isSharingEnabled() {
- try {
- return ServerSettings.isEnableSharing();
- } catch (Exception e) {
- return false;
- }
- }
-
- public static boolean userHasAccess(
- SharingService sharingHandler,
- String gatewayId,
- String userId,
- String entityId,
- ResourcePermissionType permissionType) {
- String qualifiedUserId = userId.contains("@") ? userId : userId + "@"
+ gatewayId;
- try {
- boolean hasOwnerAccess = sharingHandler.userHasAccess(
- gatewayId, qualifiedUserId, entityId, gatewayId + ":" +
ResourcePermissionType.OWNER);
- if (permissionType.equals(ResourcePermissionType.OWNER)) return
hasOwnerAccess;
- return hasOwnerAccess
- || sharingHandler.userHasAccess(
- gatewayId, qualifiedUserId, entityId, gatewayId +
":" + permissionType);
- } catch (Exception e) {
- throw new RuntimeException("Unable to check if user has access",
e);
- }
- }
-
- public static GatewayGroups retrieveGatewayGroups(
- RegistryProvider registryHandler, GatewayGroupsProvider
gatewayGroupsInitializer, String gatewayId)
- throws Exception {
- if (registryHandler.isGatewayGroupsExists(gatewayId)) {
- return registryHandler.getGatewayGroups(gatewayId);
- }
- return gatewayGroupsInitializer.initializeGatewayGroups(gatewayId);
- }
-
- public static void shareEntityWithAdminGatewayGroups(
- SharingService sharingHandler,
- RegistryProvider registryHandler,
- GatewayGroupsProvider gatewayGroupsInitializer,
- EntityEntity entity)
- throws Exception {
- String domainId = entity.getDomainId();
- GatewayGroups gatewayGroups = retrieveGatewayGroups(registryHandler,
gatewayGroupsInitializer, domainId);
- createManageSharingPermissionTypeIfMissing(sharingHandler, domainId);
- sharingHandler.shareEntityWithGroups(
- domainId,
- entity.getEntityId(),
- Arrays.asList(gatewayGroups.getAdminsGroupId()),
- domainId + ":MANAGE_SHARING",
- true);
- sharingHandler.shareEntityWithGroups(
- domainId,
- entity.getEntityId(),
- Arrays.asList(gatewayGroups.getAdminsGroupId()),
- domainId + ":WRITE",
- true);
- sharingHandler.shareEntityWithGroups(
- domainId,
- entity.getEntityId(),
- Arrays.asList(gatewayGroups.getAdminsGroupId(),
gatewayGroups.getReadOnlyAdminsGroupId()),
- domainId + ":READ",
- true);
- }
-
- public static void
createManageSharingPermissionTypeIfMissing(SharingService sharingHandler,
String domainId)
- throws Exception {
- String permissionTypeId = domainId + ":MANAGE_SHARING";
- if (!sharingHandler.isPermissionExists(domainId, permissionTypeId)) {
- PermissionTypeEntity permissionType = new PermissionTypeEntity();
- permissionType.setPermissionTypeId(permissionTypeId);
- permissionType.setDomainId(domainId);
- permissionType.setName("MANAGE_SHARING");
- permissionType.setDescription("Manage sharing permission type");
- sharingHandler.createPermissionType(permissionType);
- }
- }
-}