airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [airavata] branch develop updated: AIRAVATA-2876 Fix saving SetEnvPaths entities
Date Tue, 11 Sep 2018 15:55:22 GMT
This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata.git


The following commit(s) were added to refs/heads/develop by this push:
     new 6c95c1b  AIRAVATA-2876 Fix saving SetEnvPaths entities
6c95c1b is described below

commit 6c95c1b7cd778cb0ede5494ec3c81632c3a48ee2
Author: Marcus Christie <machristie@apache.org>
AuthorDate: Tue Sep 11 11:54:48 2018 -0400

    AIRAVATA-2876 Fix saving SetEnvPaths entities
---
 .../entities/appcatalog/AppEnvironmentEntity.java  | 10 +++-
 ...yApendPathEntity.java => AppEnvironmentPK.java} | 56 ++++++++-------------
 .../appcatalog/LibraryApendPathEntity.java         |  2 +
 ...endPathEntity.java => LibraryAppendPathPK.java} | 56 +++++++--------------
 .../appcatalog/LibraryPrependPathEntity.java       |  4 +-
 ...ndPathEntity.java => LibraryPrependPathPK.java} | 57 ++++++++--------------
 .../ApplicationDeploymentRepositoryTest.java       | 23 +++++++--
 7 files changed, 89 insertions(+), 119 deletions(-)

diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/AppEnvironmentEntity.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/AppEnvironmentEntity.java
index 18b0c0d..854064c 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/AppEnvironmentEntity.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/AppEnvironmentEntity.java
@@ -28,6 +28,7 @@ import java.io.Serializable;
  */
 @Entity
 @Table(name = "APP_ENVIRONMENT")
+@IdClass(AppEnvironmentPK.class)
 public class AppEnvironmentEntity implements Serializable {
     private static final long serialVersionUID = 1L;
 
@@ -38,6 +39,7 @@ public class AppEnvironmentEntity implements Serializable {
     @Column(name = "VALUE")
     private String value;
 
+    @Id
     @Column(name = "NAME")
     private String name;
 
@@ -75,9 +77,13 @@ public class AppEnvironmentEntity implements Serializable {
         this.name = name;
     }
 
-    public int getEnvOrder() { return envPathOrder; }
+    public int getEnvPathOrder() {
+        return envPathOrder;
+    }
 
-    public void setEnvOrder(int envPathOrder) { this.envPathOrder = envPathOrder; }
+    public void setEnvPathOrder(int envPathOrder) {
+        this.envPathOrder = envPathOrder;
+    }
 
     public ApplicationDeploymentEntity getApplicationDeployment() {
         return applicationDeployment;
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryApendPathEntity.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/AppEnvironmentPK.java
similarity index 58%
copy from modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryApendPathEntity.java
copy to modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/AppEnvironmentPK.java
index 48ab6ea..6a013a7 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryApendPathEntity.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/AppEnvironmentPK.java
@@ -1,5 +1,4 @@
 /*
- *
  * 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
@@ -17,39 +16,24 @@
  * specific language governing permissions and limitations
  * under the License.
  *
-*/
+ */
+
 package org.apache.airavata.registry.core.entities.appcatalog;
 
-import javax.persistence.*;
 import java.io.Serializable;
 
-
-/**
- * The persistent class for the library_apend_path database table.
- */
-@Entity
-@Table(name = "LIBRARY_APEND_PATH")
-public class LibraryApendPathEntity implements Serializable {
+public class AppEnvironmentPK implements Serializable {
+    // default serial version id, required for serializable classes.
     private static final long serialVersionUID = 1L;
 
-    @Id
-    @Column(name = "DEPLOYMENT_ID")
     private String deploymentId;
-
-    @Column(name = "VALUE")
-    private String value;
-
-    @Column(name = "NAME")
     private String name;
 
-    @ManyToOne(targetEntity = ApplicationDeploymentEntity.class, cascade = CascadeType.MERGE)
-    @JoinColumn(name = "DEPLOYMENT_ID")
-    private ApplicationDeploymentEntity applicationDeployment;
-
-    public LibraryApendPathEntity() {
+    public AppEnvironmentPK() {
     }
 
     public String getDeploymentId() {
+
         return deploymentId;
     }
 
@@ -57,14 +41,6 @@ public class LibraryApendPathEntity implements Serializable {
         this.deploymentId = deploymentId;
     }
 
-    public String getValue() {
-        return value;
-    }
-
-    public void setValue(String value) {
-        this.value = value;
-    }
-
     public String getName() {
         return name;
     }
@@ -73,12 +49,22 @@ public class LibraryApendPathEntity implements Serializable {
         this.name = name;
     }
 
-    public ApplicationDeploymentEntity getApplicationDeployment() {
-        return applicationDeployment;
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof AppEnvironmentPK)) return false;
+
+        AppEnvironmentPK that = (AppEnvironmentPK) o;
+
+        if (!deploymentId.equals(that.deploymentId)) return false;
+        return name.equals(that.name);
     }
 
-    public void setApplicationDeployment(ApplicationDeploymentEntity applicationDeployment)
{
-        this.applicationDeployment = applicationDeployment;
+    @Override
+    public int hashCode() {
+        int result = deploymentId.hashCode();
+        result = 31 * result + name.hashCode();
+        return result;
     }
 
-}
\ No newline at end of file
+}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryApendPathEntity.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryApendPathEntity.java
index 48ab6ea..2b87e8e 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryApendPathEntity.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryApendPathEntity.java
@@ -29,6 +29,7 @@ import java.io.Serializable;
  */
 @Entity
 @Table(name = "LIBRARY_APEND_PATH")
+@IdClass(LibraryAppendPathPK.class)
 public class LibraryApendPathEntity implements Serializable {
     private static final long serialVersionUID = 1L;
 
@@ -39,6 +40,7 @@ public class LibraryApendPathEntity implements Serializable {
     @Column(name = "VALUE")
     private String value;
 
+    @Id
     @Column(name = "NAME")
     private String name;
 
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryApendPathEntity.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryAppendPathPK.java
similarity index 57%
copy from modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryApendPathEntity.java
copy to modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryAppendPathPK.java
index 48ab6ea..a3c3fac 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryApendPathEntity.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryAppendPathPK.java
@@ -1,5 +1,4 @@
 /*
- *
  * 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
@@ -17,38 +16,18 @@
  * specific language governing permissions and limitations
  * under the License.
  *
-*/
+ */
+
 package org.apache.airavata.registry.core.entities.appcatalog;
 
-import javax.persistence.*;
 import java.io.Serializable;
 
-
-/**
- * The persistent class for the library_apend_path database table.
- */
-@Entity
-@Table(name = "LIBRARY_APEND_PATH")
-public class LibraryApendPathEntity implements Serializable {
+public class LibraryAppendPathPK implements Serializable{
     private static final long serialVersionUID = 1L;
 
-    @Id
-    @Column(name = "DEPLOYMENT_ID")
     private String deploymentId;
-
-    @Column(name = "VALUE")
-    private String value;
-
-    @Column(name = "NAME")
     private String name;
 
-    @ManyToOne(targetEntity = ApplicationDeploymentEntity.class, cascade = CascadeType.MERGE)
-    @JoinColumn(name = "DEPLOYMENT_ID")
-    private ApplicationDeploymentEntity applicationDeployment;
-
-    public LibraryApendPathEntity() {
-    }
-
     public String getDeploymentId() {
         return deploymentId;
     }
@@ -57,14 +36,6 @@ public class LibraryApendPathEntity implements Serializable {
         this.deploymentId = deploymentId;
     }
 
-    public String getValue() {
-        return value;
-    }
-
-    public void setValue(String value) {
-        this.value = value;
-    }
-
     public String getName() {
         return name;
     }
@@ -73,12 +44,21 @@ public class LibraryApendPathEntity implements Serializable {
         this.name = name;
     }
 
-    public ApplicationDeploymentEntity getApplicationDeployment() {
-        return applicationDeployment;
-    }
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof LibraryAppendPathPK)) return false;
 
-    public void setApplicationDeployment(ApplicationDeploymentEntity applicationDeployment)
{
-        this.applicationDeployment = applicationDeployment;
+        LibraryAppendPathPK that = (LibraryAppendPathPK) o;
+
+        if (!deploymentId.equals(that.deploymentId)) return false;
+        return name.equals(that.name);
     }
 
-}
\ No newline at end of file
+    @Override
+    public int hashCode() {
+        int result = deploymentId.hashCode();
+        result = 31 * result + name.hashCode();
+        return result;
+    }
+}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryPrependPathEntity.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryPrependPathEntity.java
index 41a4fca..c015726 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryPrependPathEntity.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryPrependPathEntity.java
@@ -30,6 +30,7 @@ import java.io.Serializable;
  */
 @Entity
 @Table(name="LIBRARY_PREPAND_PATH")
+@IdClass(LibraryPrependPathPK.class)
 public class LibraryPrependPathEntity implements Serializable {
 	private static final long serialVersionUID = 1L;
 
@@ -39,7 +40,8 @@ public class LibraryPrependPathEntity implements Serializable {
 
 	@Column(name="VALUE")
 	private String value;
-	
+
+	@Id
 	@Column(name="NAME")
 	private String name;
 
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryApendPathEntity.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryPrependPathPK.java
similarity index 57%
copy from modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryApendPathEntity.java
copy to modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryPrependPathPK.java
index 48ab6ea..d40bfce 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryApendPathEntity.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/LibraryPrependPathPK.java
@@ -1,5 +1,4 @@
 /*
- *
  * 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
@@ -17,38 +16,19 @@
  * specific language governing permissions and limitations
  * under the License.
  *
-*/
+ */
+
 package org.apache.airavata.registry.core.entities.appcatalog;
 
-import javax.persistence.*;
 import java.io.Serializable;
 
-
-/**
- * The persistent class for the library_apend_path database table.
- */
-@Entity
-@Table(name = "LIBRARY_APEND_PATH")
-public class LibraryApendPathEntity implements Serializable {
+public class LibraryPrependPathPK implements Serializable {
+    // default serial version id, required for serializable classes.
     private static final long serialVersionUID = 1L;
 
-    @Id
-    @Column(name = "DEPLOYMENT_ID")
     private String deploymentId;
-
-    @Column(name = "VALUE")
-    private String value;
-
-    @Column(name = "NAME")
     private String name;
 
-    @ManyToOne(targetEntity = ApplicationDeploymentEntity.class, cascade = CascadeType.MERGE)
-    @JoinColumn(name = "DEPLOYMENT_ID")
-    private ApplicationDeploymentEntity applicationDeployment;
-
-    public LibraryApendPathEntity() {
-    }
-
     public String getDeploymentId() {
         return deploymentId;
     }
@@ -57,14 +37,6 @@ public class LibraryApendPathEntity implements Serializable {
         this.deploymentId = deploymentId;
     }
 
-    public String getValue() {
-        return value;
-    }
-
-    public void setValue(String value) {
-        this.value = value;
-    }
-
     public String getName() {
         return name;
     }
@@ -73,12 +45,21 @@ public class LibraryApendPathEntity implements Serializable {
         this.name = name;
     }
 
-    public ApplicationDeploymentEntity getApplicationDeployment() {
-        return applicationDeployment;
-    }
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof LibraryPrependPathPK)) return false;
 
-    public void setApplicationDeployment(ApplicationDeploymentEntity applicationDeployment)
{
-        this.applicationDeployment = applicationDeployment;
+        LibraryPrependPathPK that = (LibraryPrependPathPK) o;
+
+        if (!deploymentId.equals(that.deploymentId)) return false;
+        return name.equals(that.name);
     }
 
-}
\ No newline at end of file
+    @Override
+    public int hashCode() {
+        int result = deploymentId.hashCode();
+        result = 31 * result + name.hashCode();
+        return result;
+    }
+}
diff --git a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/appcatalog/ApplicationDeploymentRepositoryTest.java
b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/appcatalog/ApplicationDeploymentRepositoryTest.java
index 2836394..7a0bd15 100644
--- a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/appcatalog/ApplicationDeploymentRepositoryTest.java
+++ b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/appcatalog/ApplicationDeploymentRepositoryTest.java
@@ -34,12 +34,10 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-
 import java.util.*;
 
+import static org.junit.Assert.assertTrue;
+
 public class ApplicationDeploymentRepositoryTest extends TestBase {
 
     private static final Logger logger = LoggerFactory.getLogger(ApplicationDeploymentRepositoryTest.class);
@@ -72,12 +70,27 @@ public class ApplicationDeploymentRepositoryTest extends TestBase {
 
     private boolean deepCompareDeployment(ApplicationDeploymentDescription expected, ApplicationDeploymentDescription
actual) {
         boolean equals = true;
-        equals = equals & EqualsBuilder.reflectionEquals(expected, actual,
+        equals = equals && EqualsBuilder.reflectionEquals(expected, actual,
                 "moduleLoadCmds", "libPrependPaths", "libAppendPaths" ,"setEnvironment" ,"preJobCommands"
                 ,"postJobCommands", "__isset_bitfield");
+        equals = equals && deepCompareLists(expected.getSetEnvironment(), actual.getSetEnvironment(),
Comparator.comparingInt(SetEnvPaths::getEnvPathOrder));
+        equals = equals && deepCompareLists(expected.getLibPrependPaths(), actual.getLibPrependPaths(),
Comparator.comparingInt(SetEnvPaths::getEnvPathOrder));
+        equals = equals && deepCompareLists(expected.getLibAppendPaths(), actual.getLibAppendPaths(),
Comparator.comparingInt(SetEnvPaths::getEnvPathOrder));
+        equals = equals && deepCompareLists(expected.getModuleLoadCmds(), actual.getModuleLoadCmds(),
Comparator.comparingInt(CommandObject::getCommandOrder));
+        equals = equals && deepCompareLists(expected.getPreJobCommands(), actual.getPreJobCommands(),
Comparator.comparingInt(CommandObject::getCommandOrder));
+        equals = equals && deepCompareLists(expected.getPostJobCommands(), actual.getPostJobCommands(),
Comparator.comparingInt(CommandObject::getCommandOrder));
         return equals;
     }
 
+    private <T> boolean deepCompareLists(List<T> expected, List<T> actual,
Comparator<? super T> c) {
+
+        List<T> expectedCopy = new ArrayList<>(expected);
+        expectedCopy.sort(c);
+        List<T> actualCopy = new ArrayList<>(actual);
+        actualCopy.sort(c);
+        return EqualsBuilder.reflectionEquals(expectedCopy, actualCopy);
+    }
+
     private ApplicationDeploymentDescription prepareSampleDeployment(String tag, String applicationModule,
String computeResource) {
         CommandObject moduleLoadCmd = new CommandObject();
         moduleLoadCmd.setCommand("moduleLoadCmd");


Mime
View raw message