airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scnakand...@apache.org
Subject airavata git commit: search Data Products By Name in replica catalog
Date Thu, 20 Apr 2017 18:01:21 GMT
Repository: airavata
Updated Branches:
  refs/heads/develop 6c38ebb3e -> 2afa065f9


search Data Products By Name in replica catalog


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/2afa065f
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/2afa065f
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/2afa065f

Branch: refs/heads/develop
Commit: 2afa065f964a430b9c626e1da7b1d5a0ff8cf5d0
Parents: 6c38ebb
Author: scnakandala <supun.nakandala@gmail.com>
Authored: Thu Apr 20 14:01:17 2017 -0400
Committer: scnakandala <supun.nakandala@gmail.com>
Committed: Thu Apr 20 14:01:17 2017 -0400

----------------------------------------------------------------------
 .../catalog/impl/ReplicaCatalogImpl.java        | 44 ++++++++++++++++++++
 .../replica/catalog/ReplicaCatalogTest.java     |  2 +
 .../airavata/registry/cpi/ReplicaCatalog.java   |  3 ++
 3 files changed, 49 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/2afa065f/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/impl/ReplicaCatalogImpl.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/impl/ReplicaCatalogImpl.java
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/impl/ReplicaCatalogImpl.java
index c35a3bd..e27e27a 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/impl/ReplicaCatalogImpl.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/impl/ReplicaCatalogImpl.java
@@ -34,6 +34,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.persistence.EntityManager;
+import javax.persistence.Query;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -363,4 +364,47 @@ public class ReplicaCatalogImpl implements ReplicaCatalog {
             }
         }
     }
+
+    @Override
+    public List<DataProductModel> searchDataProductsByName(String gatewayId, String
userId, String productName, int limit, int offset) throws ReplicaCatalogException {
+        EntityManager em = null;
+        try {
+            String query = "SELECT dp FROM DataProduct dp " +
+                    "WHERE dp.gatewayId = '" + gatewayId + "' AND dp.ownerName='" + userId
+ "' AND dp.productName LIKE '%"
+                    + productName + "%' ORDER BY dp.creationTime DESC";
+
+
+            em = ReplicaCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            Query q;
+
+            //pagination
+            if (offset >= 0 && limit >= 0) {
+                q = em.createQuery(query).setFirstResult(offset).setMaxResults(limit);
+            } else {
+                q = em.createQuery(query);
+            }
+
+            ArrayList<DataProductModel> returnModels = new ArrayList<>();
+            List resultList = q.getResultList();
+            for (Object o : resultList) {
+                DataProduct dataProduct = (DataProduct) o;
+                returnModels.add(ThriftDataModelConversion.getDataProductModel(dataProduct));
+            }
+            em.getTransaction().commit();
+            em.close();
+            return returnModels;
+        } catch (Exception e) {
+            e.printStackTrace();
+            logger.error(e.getMessage(), e);
+            throw new ReplicaCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/2afa065f/modules/registry/registry-core/src/test/java/org/apache/airavata/replica/catalog/ReplicaCatalogTest.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/test/java/org/apache/airavata/replica/catalog/ReplicaCatalogTest.java
b/modules/registry/registry-core/src/test/java/org/apache/airavata/replica/catalog/ReplicaCatalogTest.java
index a2e2abf..62e8736 100644
--- a/modules/registry/registry-core/src/test/java/org/apache/airavata/replica/catalog/ReplicaCatalogTest.java
+++ b/modules/registry/registry-core/src/test/java/org/apache/airavata/replica/catalog/ReplicaCatalogTest.java
@@ -82,6 +82,8 @@ public class ReplicaCatalogTest {
             String productUri = replicacatalog.registerDataProduct(dataProductModel);
             org.junit.Assert.assertNotNull(productUri);
             dataProductModel = replicacatalog.getDataProduct(productUri);
+            Assert.assertTrue(replicacatalog.searchDataProductsByName(dataProductModel.getGatewayId(),
dataProductModel.getOwnerName(),
+                    dataProductModel.getProductName().substring(1, 5), -1, 0).size() == 1);
             Assert.assertNotNull(dataProductModel);
             boolean result = replicacatalog.removeDataProduct(productUri);
             Assert.assertTrue(result);

http://git-wip-us.apache.org/repos/asf/airavata/blob/2afa065f/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalog.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalog.java
b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalog.java
index 9db6dc6..df888a9 100644
--- a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalog.java
+++ b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalog.java
@@ -51,4 +51,7 @@ public interface ReplicaCatalog {
     DataProductModel getParentDataProduct(String productUri) throws ReplicaCatalogException;
 
     List<DataProductModel> getChildDataProducts(String productUri) throws ReplicaCatalogException;
+
+    List<DataProductModel> searchDataProductsByName(String gatewayId, String userId,
String productName,
+                                                    int limit, int offset) throws ReplicaCatalogException;
 }


Mime
View raw message