This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch group-based-auth
in repository https://gitbox.apache.org/repos/asf/airavata.git


The following commit(s) were added to refs/heads/group-based-auth by this push:
     new 99babaa  Set replica ids on new DataProductMode
99babaa is described below

commit 99babaa44082ffcaeec535627c37556ff6e99be1
Author: Marcus Christie <machris...@apache.org>
AuthorDate: Mon Apr 9 17:10:22 2018 -0400

    Set replica ids on new DataProductMode
---
 modules/registry-refactoring/pom.xml               | 12 +++++++
 .../replicacatalog/DataProductRepository.java      | 24 +++++++++----
 .../replicacatalog/RepCatAbstractRepository.java   |  5 ++-
 .../replicacatalog/DataProductRepositoryTest.java  | 42 ++++++++++++++++++++--
 .../src/test/resources/logback.xml                 | 31 ++++++++++++++++
 5 files changed, 105 insertions(+), 9 deletions(-)

diff --git a/modules/registry-refactoring/pom.xml 
b/modules/registry-refactoring/pom.xml
index 3c25b56..15a8da6 100644
--- a/modules/registry-refactoring/pom.xml
+++ b/modules/registry-refactoring/pom.xml
@@ -31,6 +31,12 @@
             <groupId>net.sf.dozer</groupId>
             <artifactId>dozer</artifactId>
             <version>5.4.0</version>
+            <exclusions>
+               <exclusion>
+                   <groupId>org.slf4j</groupId>
+                   <artifactId>slf4j-log4j12</artifactId>
+               </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.apache.openjpa</groupId>
@@ -70,6 +76,12 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <version>${logback.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.airavata</groupId>
             <artifactId>airavata-commons</artifactId>
             <version>0.17-SNAPSHOT</version>
diff --git 
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepository.java
 
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepository.java
index 6377d86..1821d28 100644
--- 
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepository.java
+++ 
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepository.java
@@ -37,6 +37,7 @@ import java.util.*;
 
 public class DataProductRepository extends 
RepCatAbstractRepository<DataProductModel, DataProductEntity, String> 
implements DataProductInterface {
     private final static Logger logger = 
LoggerFactory.getLogger(DataProductRepository.class);
+    private final static DataReplicaLocationRepository 
dataReplicaLocationRepository = new DataReplicaLocationRepository();
 
     public DataProductRepository() {
         super(DataProductModel.class, DataProductEntity.class);
@@ -69,17 +70,28 @@ public class DataProductRepository extends 
RepCatAbstractRepository<DataProductM
             throw new ReplicaCatalogException("Parent product does not exist 
or parent type is not Collection");
         }
 
-        if (dataProductEntity.getReplicaLocations() != null) {
-            logger.debug("Populating the product URI for ReplicaLocations 
objects for the Data Product");
-            
dataProductEntity.getReplicaLocations().forEach(dataReplicaLocationEntity -> 
dataReplicaLocationEntity.setProductUri(productUri));
-        }
+        final Timestamp currentTime = new 
Timestamp(System.currentTimeMillis());
 
         if (!isDataProductExists(productUri)) {
             logger.debug("Checking if the Data Product already exists");
-            dataProductEntity.setCreationTime(new 
Timestamp(System.currentTimeMillis()));
+            dataProductEntity.setCreationTime(currentTime);
+        }
+
+        if (dataProductEntity.getReplicaLocations() != null) {
+            logger.debug("Populating the product URI for ReplicaLocations 
objects for the Data Product");
+            
dataProductEntity.getReplicaLocations().forEach(dataReplicaLocationEntity -> {
+                dataReplicaLocationEntity.setProductUri(productUri);
+                if (dataReplicaLocationEntity.getReplicaId() == null) {
+                    
dataReplicaLocationEntity.setReplicaId(UUID.randomUUID().toString());
+                }
+                if 
(!dataReplicaLocationRepository.isExists(dataReplicaLocationEntity.getReplicaId())){
+                    dataReplicaLocationEntity.setCreationTime(currentTime);
+                }
+                dataReplicaLocationEntity.setLastModifiedTime(currentTime);
+            });
         }
 
-        dataProductEntity.setLastModifiedTime(new 
Timestamp(System.currentTimeMillis()));
+        dataProductEntity.setLastModifiedTime(currentTime);
 
         return execute(entityManager -> 
entityManager.merge(dataProductEntity));
 
diff --git 
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/RepCatAbstractRepository.java
 
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/RepCatAbstractRepository.java
index c8b603c..ceeb228 100644
--- 
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/RepCatAbstractRepository.java
+++ 
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/RepCatAbstractRepository.java
@@ -118,7 +118,10 @@ public abstract class RepCatAbstractRepository<T, E, Id> {
             entityManager.getTransaction().begin();
             R r = committer.commit(entityManager);
             entityManager.getTransaction().commit();
-            return  r;
+            return r;
+        } catch(Exception e) {
+            logger.error("Failed to execute Replica Catalog transaction", e);
+            throw e;
         }finally {
             if (entityManager != null && entityManager.isOpen()) {
                 if (entityManager.getTransaction().isActive()) {
diff --git 
a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepositoryTest.java
 
b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepositoryTest.java
index 9281fbe..4ed5242 100644
--- 
a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepositoryTest.java
+++ 
b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepositoryTest.java
@@ -21,6 +21,9 @@ package 
org.apache.airavata.registry.core.repositories.replicacatalog;
 
 import org.apache.airavata.model.data.replica.DataProductModel;
 import org.apache.airavata.model.data.replica.DataProductType;
+import org.apache.airavata.model.data.replica.DataReplicaLocationModel;
+import org.apache.airavata.model.data.replica.ReplicaLocationCategory;
+import org.apache.airavata.model.data.replica.ReplicaPersistentType;
 import 
org.apache.airavata.registry.core.entities.replicacatalog.DataProductMetadataEntity;
 import 
org.apache.airavata.registry.core.repositories.replicacatalog.util.Initialize;
 import org.apache.airavata.registry.cpi.ReplicaCatalogException;
@@ -30,10 +33,13 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 public class DataProductRepositoryTest {
 
@@ -113,4 +119,36 @@ public class DataProductRepositoryTest {
         dataProductRepository.removeDataProduct(productUri2);
     }
 
+    @Test
+    public void testDataProductWithReplicaLocation() throws 
ReplicaCatalogException {
+        DataProductModel testDataProductModel1 = new DataProductModel();
+        testDataProductModel1.setGatewayId(gatewayId);
+        testDataProductModel1.setOwnerName(userId);
+        testDataProductModel1.setDataProductType(DataProductType.FILE);
+        testDataProductModel1.setProductName(productName);
+
+        DataReplicaLocationModel replicaLocationModel1 = new 
DataReplicaLocationModel();
+        replicaLocationModel1.setFilePath("/path/to/file.dat");
+        replicaLocationModel1.setReplicaDescription("Description of replica");
+        
replicaLocationModel1.setReplicaLocationCategory(ReplicaLocationCategory.GATEWAY_DATA_STORE);
+        replicaLocationModel1.setReplicaName("file.dat");
+        replicaLocationModel1.setStorageResourceId("storage_resource_id");
+        
replicaLocationModel1.setReplicaPersistentType(ReplicaPersistentType.PERSISTENT);
+
+        testDataProductModel1.addToReplicaLocations(replicaLocationModel1);
+
+        String productUri1 = 
dataProductRepository.registerDataProduct(testDataProductModel1);
+        assertTrue(dataProductRepository.isDataProductExists(productUri1));
+
+        DataProductModel retrievedDataProductModel1 = 
dataProductRepository.getDataProduct(productUri1);
+        assertEquals(productUri1, retrievedDataProductModel1.getProductUri());
+
+        assertEquals(1, retrievedDataProductModel1.getReplicaLocationsSize());
+        DataReplicaLocationModel retrievedReplicaLocationModel1 = 
retrievedDataProductModel1.getReplicaLocations().get(0);
+        assertEquals(productUri1, 
retrievedReplicaLocationModel1.getProductUri());
+
+        dataProductRepository.removeDataProduct(productUri1);
+        assertFalse(dataProductRepository.isDataProductExists(productUri1));
+    }
+
 }
diff --git a/modules/registry-refactoring/src/test/resources/logback.xml 
b/modules/registry-refactoring/src/test/resources/logback.xml
new file mode 100644
index 0000000..7678869
--- /dev/null
+++ b/modules/registry-refactoring/src/test/resources/logback.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  ~
+  -->
+<configuration>
+    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <pattern>[%p] %m%n</pattern>
+        </encoder>
+    </appender>
+    <root level="INFO">
+        <appender-ref ref="CONSOLE"/>
+        <!--<appender-ref ref="LOGFILE"/>-->
+    </root>
+</configuration>

-- 
To stop receiving notification emails like this one, please contact
machris...@apache.org.

Reply via email to