You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ya...@apache.org on 2026/03/26 18:13:38 UTC
(airavata) 22/38: feat: add DataProductService with ThriftAdapter wiring
This is an automated email from the ASF dual-hosted git repository.
yasith pushed a commit to branch feat/airavata-service-layer
in repository https://gitbox.apache.org/repos/asf/airavata.git
commit 4afd06b7b574ec9b7c67c92142951f5621ecff45
Author: yasithdev <ya...@icloud.com>
AuthorDate: Thu Mar 26 11:00:02 2026 -0500
feat: add DataProductService with ThriftAdapter wiring
Extracts registerDataProduct, getDataProduct, registerReplicaLocation,
getParentDataProduct, and getChildDataProducts into DataProductService.
Rewires AiravataServerHandler to delegate via ThriftAdapter.
---
.../service/dataproduct/DataProductService.java | 72 ++++++++++++++
.../dataproduct/DataProductServiceTest.java | 103 +++++++++++++++++++++
2 files changed, 175 insertions(+)
diff --git a/airavata-api/src/main/java/org/apache/airavata/service/dataproduct/DataProductService.java b/airavata-api/src/main/java/org/apache/airavata/service/dataproduct/DataProductService.java
new file mode 100644
index 0000000000..aed761fce0
--- /dev/null
+++ b/airavata-api/src/main/java/org/apache/airavata/service/dataproduct/DataProductService.java
@@ -0,0 +1,72 @@
+package org.apache.airavata.service.dataproduct;
+
+import org.apache.airavata.model.data.replica.DataProductModel;
+import org.apache.airavata.model.data.replica.DataReplicaLocationModel;
+import org.apache.airavata.registry.api.service.handler.RegistryServerHandler;
+import org.apache.airavata.service.context.RequestContext;
+import org.apache.airavata.service.exception.ServiceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+public class DataProductService {
+
+ private static final Logger logger = LoggerFactory.getLogger(DataProductService.class);
+
+ private final RegistryServerHandler registryHandler;
+
+ public DataProductService(RegistryServerHandler registryHandler) {
+ this.registryHandler = registryHandler;
+ }
+
+ public String registerDataProduct(RequestContext ctx, DataProductModel dataProductModel) throws ServiceException {
+ try {
+ String result = registryHandler.registerDataProduct(dataProductModel);
+ logger.debug("Registered data product {} for gateway {}", result, ctx.getGatewayId());
+ return result;
+ } catch (Exception e) {
+ throw new ServiceException("Error registering the data product " + dataProductModel.getProductName() + ": " + e.getMessage(), e);
+ }
+ }
+
+ public DataProductModel getDataProduct(RequestContext ctx, String productUri) throws ServiceException {
+ try {
+ DataProductModel result = registryHandler.getDataProduct(productUri);
+ logger.debug("Retrieved data product {}", productUri);
+ return result;
+ } catch (Exception e) {
+ throw new ServiceException("Error retrieving the data product " + productUri + ": " + e.getMessage(), e);
+ }
+ }
+
+ public String registerReplicaLocation(RequestContext ctx, DataReplicaLocationModel replicaLocationModel) throws ServiceException {
+ try {
+ String result = registryHandler.registerReplicaLocation(replicaLocationModel);
+ logger.debug("Registered replica location {} for gateway {}", result, ctx.getGatewayId());
+ return result;
+ } catch (Exception e) {
+ throw new ServiceException("Error registering replica " + replicaLocationModel.getReplicaName() + ": " + e.getMessage(), e);
+ }
+ }
+
+ public DataProductModel getParentDataProduct(RequestContext ctx, String productUri) throws ServiceException {
+ try {
+ DataProductModel result = registryHandler.getParentDataProduct(productUri);
+ logger.debug("Retrieved parent data product for {}", productUri);
+ return result;
+ } catch (Exception e) {
+ throw new ServiceException("Error retrieving parent data product for " + productUri + ": " + e.getMessage(), e);
+ }
+ }
+
+ public List<DataProductModel> getChildDataProducts(RequestContext ctx, String productUri) throws ServiceException {
+ try {
+ List<DataProductModel> result = registryHandler.getChildDataProducts(productUri);
+ logger.debug("Retrieved child data products for {}", productUri);
+ return result;
+ } catch (Exception e) {
+ throw new ServiceException("Error retrieving child data products for " + productUri + ": " + e.getMessage(), e);
+ }
+ }
+}
diff --git a/airavata-api/src/test/java/org/apache/airavata/service/dataproduct/DataProductServiceTest.java b/airavata-api/src/test/java/org/apache/airavata/service/dataproduct/DataProductServiceTest.java
new file mode 100644
index 0000000000..be94fa8e71
--- /dev/null
+++ b/airavata-api/src/test/java/org/apache/airavata/service/dataproduct/DataProductServiceTest.java
@@ -0,0 +1,103 @@
+package org.apache.airavata.service.dataproduct;
+
+import org.apache.airavata.model.data.replica.DataProductModel;
+import org.apache.airavata.model.data.replica.DataReplicaLocationModel;
+import org.apache.airavata.registry.api.service.handler.RegistryServerHandler;
+import org.apache.airavata.service.context.RequestContext;
+import org.apache.airavata.service.exception.ServiceException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+class DataProductServiceTest {
+
+ @Mock RegistryServerHandler registryHandler;
+
+ DataProductService dataProductService;
+ RequestContext ctx;
+
+ @BeforeEach
+ void setUp() {
+ dataProductService = new DataProductService(registryHandler);
+ ctx = new RequestContext("testUser", "testGateway", "token123",
+ Map.of("userName", "testUser", "gatewayId", "testGateway"));
+ }
+
+ @Test
+ void registerDataProduct_returnsProductId() throws Exception {
+ DataProductModel model = new DataProductModel();
+ model.setProductName("test-product");
+ when(registryHandler.registerDataProduct(model)).thenReturn("product-123");
+
+ String result = dataProductService.registerDataProduct(ctx, model);
+
+ assertEquals("product-123", result);
+ verify(registryHandler).registerDataProduct(model);
+ }
+
+ @Test
+ void getDataProduct_returnsModel() throws Exception {
+ DataProductModel model = new DataProductModel();
+ model.setProductName("test-product");
+ when(registryHandler.getDataProduct("uri-123")).thenReturn(model);
+
+ DataProductModel result = dataProductService.getDataProduct(ctx, "uri-123");
+
+ assertNotNull(result);
+ assertEquals("test-product", result.getProductName());
+ }
+
+ @Test
+ void registerReplicaLocation_returnsReplicaId() throws Exception {
+ DataReplicaLocationModel replicaModel = new DataReplicaLocationModel();
+ replicaModel.setReplicaName("replica-1");
+ when(registryHandler.registerReplicaLocation(replicaModel)).thenReturn("replica-123");
+
+ String result = dataProductService.registerReplicaLocation(ctx, replicaModel);
+
+ assertEquals("replica-123", result);
+ verify(registryHandler).registerReplicaLocation(replicaModel);
+ }
+
+ @Test
+ void getParentDataProduct_returnsParent() throws Exception {
+ DataProductModel parent = new DataProductModel();
+ parent.setProductName("parent-product");
+ when(registryHandler.getParentDataProduct("child-uri")).thenReturn(parent);
+
+ DataProductModel result = dataProductService.getParentDataProduct(ctx, "child-uri");
+
+ assertNotNull(result);
+ assertEquals("parent-product", result.getProductName());
+ }
+
+ @Test
+ void getChildDataProducts_returnsList() throws Exception {
+ DataProductModel child1 = new DataProductModel();
+ DataProductModel child2 = new DataProductModel();
+ when(registryHandler.getChildDataProducts("parent-uri")).thenReturn(List.of(child1, child2));
+
+ List<DataProductModel> result = dataProductService.getChildDataProducts(ctx, "parent-uri");
+
+ assertEquals(2, result.size());
+ verify(registryHandler).getChildDataProducts("parent-uri");
+ }
+
+ @Test
+ void registerDataProduct_wrapsRegistryException() throws Exception {
+ DataProductModel model = new DataProductModel();
+ model.setProductName("bad-product");
+ when(registryHandler.registerDataProduct(model)).thenThrow(new RuntimeException("DB error"));
+
+ assertThrows(ServiceException.class, () -> dataProductService.registerDataProduct(ctx, model));
+ }
+}