airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [airavata] 01/03: AIRAVATA-2872 Allow setting resourceSpecificCredStoreToken to null
Date Tue, 06 Nov 2018 16:47:37 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

commit f4b61a7614c51f0eb0c7cc0406e1746327bc64c7
Author: Marcus Christie <machristie@apache.org>
AuthorDate: Wed Oct 31 09:58:55 2018 -0400

    AIRAVATA-2872 Allow setting resourceSpecificCredStoreToken to null
    
    Changed the "detach state" setting in OpenJPA to "all" which changes how
    null values are merged. Without "all", null values are treated as simply
    unspecified and are not merged in. With "all", null values are treated
    as specified values that are merged in.
    
    One consequence is that any field on the JPA entities that isn't in the
    Thrift models OpenJPA will attempt to set it to null. For this reason,
    @ManyToOne references, which aren't in the Thrift models, are configured
    so that the @JoinColumn is not nullable and not updateable, which is
    true regardless but is necessary now with the change in "detach state"
    setting.
    
    I also set up orphanRemoval on the GroupResourceProfileEntity to test
    that that would still work as well.
---
 .../appcatalog/BatchQueueResourcePolicyEntity.java | 16 ++++--
 .../appcatalog/BatchQueueResourcePolicyPK.java     | 60 ----------------------
 .../appcatalog/ComputeResourcePolicyEntity.java    | 18 +++++--
 .../appcatalog/GroupComputeResourcePrefEntity.java | 22 ++++++--
 .../appcatalog/GroupResourceProfileEntity.java     | 15 ++++--
 .../appcatalog/GroupResourceProfilePK.java         | 59 ---------------------
 .../GroupSSHAccountProvisionerConfig.java          | 14 ++++-
 .../appcatalog/BatchQueuePolicyRepository.java     |  3 +-
 .../appcatalog/GroupResourceProfileRepository.java | 26 +++-------
 .../core/utils/JPAUtil/AppCatalogJPAUtils.java     |  1 +
 .../core/utils/JPAUtil/ExpCatalogJPAUtils.java     |  1 +
 .../core/utils/JPAUtil/RepCatalogJPAUtils.java     |  1 +
 .../utils/JPAUtil/WorkflowCatalogJPAUtils.java     |  1 +
 .../registry/core/utils/ObjectMapperSingleton.java |  7 +--
 .../src/main/resources/appcatalog-derby.sql        |  2 +-
 .../src/main/resources/appcatalog-mysql.sql        |  2 +-
 .../GroupResourceProfileRepositoryTest.java        | 35 +++++++++++++
 .../src/test/resources/appcatalog-derby.sql        |  2 +-
 18 files changed, 121 insertions(+), 164 deletions(-)

diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/BatchQueueResourcePolicyEntity.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/BatchQueueResourcePolicyEntity.java
index 4cb3abb..f0631d7 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/BatchQueueResourcePolicyEntity.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/BatchQueueResourcePolicyEntity.java
@@ -20,7 +20,15 @@
 */
 package org.apache.airavata.registry.core.entities.appcatalog;
 
-import javax.persistence.*;
+import org.apache.openjpa.persistence.jdbc.ForeignKey;
+import org.apache.openjpa.persistence.jdbc.ForeignKeyAction;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
 import java.io.Serializable;
 
 /**
@@ -28,7 +36,6 @@ import java.io.Serializable;
  */
 @Entity
 @Table(name = "BATCH_QUEUE_RESOURCE_POLICY")
-@IdClass(BatchQueueResourcePolicyPK.class)
 public class BatchQueueResourcePolicyEntity implements Serializable {
 
     private static final long serialVersionUID = 1L;
@@ -55,8 +62,9 @@ public class BatchQueueResourcePolicyEntity implements Serializable {
     @Column(name = "MAX_ALLOWED_WALLTIME")
     private Integer maxAllowedWalltime;
 
-    @ManyToOne(targetEntity = GroupResourceProfileEntity.class, cascade = CascadeType.MERGE)
-    @JoinColumn(name = "GROUP_RESOURCE_PROFILE_ID")
+    @ManyToOne(targetEntity = GroupResourceProfileEntity.class)
+    @JoinColumn(name = "GROUP_RESOURCE_PROFILE_ID", nullable = false, updatable = false)
+    @ForeignKey(deleteAction = ForeignKeyAction.CASCADE)
     private GroupResourceProfileEntity groupResourceProfile;
 
     public BatchQueueResourcePolicyEntity() {
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/BatchQueueResourcePolicyPK.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/BatchQueueResourcePolicyPK.java
deleted file mode 100644
index 296bdb1..0000000
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/BatchQueueResourcePolicyPK.java
+++ /dev/null
@@ -1,60 +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.registry.core.entities.appcatalog;
-
-import java.io.Serializable;
-
-/**
- * The primary key class for the batch_queue_resource_policy database table.
- *
- */
-public class BatchQueueResourcePolicyPK implements Serializable{
-
-    private static final long serialVersionUID = 1L;
-
-    private String resourcePolicyId;
-
-    public BatchQueueResourcePolicyPK() {
-    }
-
-    public String getResourcePolicyId() {
-        return resourcePolicyId;
-    }
-
-    public void setResourcePolicyId(String resourcePolicyId) {
-        this.resourcePolicyId = resourcePolicyId;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-
-        BatchQueueResourcePolicyPK that = (BatchQueueResourcePolicyPK) o;
-
-        return resourcePolicyId != null ? resourcePolicyId.equals(that.resourcePolicyId)
: that.resourcePolicyId == null;
-    }
-
-    @Override
-    public int hashCode() {
-        return resourcePolicyId != null ? resourcePolicyId.hashCode() : 0;
-    }
-}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/ComputeResourcePolicyEntity.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/ComputeResourcePolicyEntity.java
index e62fba5..da7dcb9 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/ComputeResourcePolicyEntity.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/ComputeResourcePolicyEntity.java
@@ -20,7 +20,18 @@
 */
 package org.apache.airavata.registry.core.entities.appcatalog;
 
-import javax.persistence.*;
+import org.apache.openjpa.persistence.jdbc.ForeignKey;
+import org.apache.openjpa.persistence.jdbc.ForeignKeyAction;
+
+import javax.persistence.CollectionTable;
+import javax.persistence.Column;
+import javax.persistence.ElementCollection;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
 import java.io.Serializable;
 import java.util.List;
 
@@ -49,8 +60,9 @@ public class ComputeResourcePolicyEntity implements Serializable {
     @Column(name = "QUEUE_NAME")
     private List<String> allowedBatchQueues;
 
-    @ManyToOne(targetEntity = GroupResourceProfileEntity.class, cascade = CascadeType.MERGE)
-    @JoinColumn(name = "GROUP_RESOURCE_PROFILE_ID")
+    @ManyToOne(targetEntity = GroupResourceProfileEntity.class)
+    @JoinColumn(name = "GROUP_RESOURCE_PROFILE_ID", nullable = false, updatable = false)
+    @ForeignKey(deleteAction = ForeignKeyAction.CASCADE)
     private GroupResourceProfileEntity groupResourceProfile;
 
     public ComputeResourcePolicyEntity() {
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GroupComputeResourcePrefEntity.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GroupComputeResourcePrefEntity.java
index 7db64be..8260764 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GroupComputeResourcePrefEntity.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GroupComputeResourcePrefEntity.java
@@ -21,8 +21,21 @@ package org.apache.airavata.registry.core.entities.appcatalog;
 
 import org.apache.airavata.model.appcatalog.computeresource.JobSubmissionProtocol;
 import org.apache.airavata.model.data.movement.DataMovementProtocol;
-
-import javax.persistence.*;
+import org.apache.openjpa.persistence.jdbc.ForeignKey;
+import org.apache.openjpa.persistence.jdbc.ForeignKeyAction;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
 import java.io.Serializable;
 import java.sql.Timestamp;
 import java.util.List;
@@ -95,8 +108,9 @@ public class GroupComputeResourcePrefEntity implements Serializable {
     @OneToMany(targetEntity = GroupSSHAccountProvisionerConfig.class, mappedBy = "groupComputeResourcePref",
cascade = CascadeType.ALL, fetch = FetchType.EAGER)
     private List<GroupSSHAccountProvisionerConfig> groupSSHAccountProvisionerConfigs;
 
-    @ManyToOne(targetEntity = GroupResourceProfileEntity.class, cascade = CascadeType.MERGE)
-    @JoinColumn(name = "GROUP_RESOURCE_PROFILE_ID")
+    @ManyToOne(targetEntity = GroupResourceProfileEntity.class)
+    @JoinColumn(name = "GROUP_RESOURCE_PROFILE_ID", nullable = false, updatable = false)
+    @ForeignKey(deleteAction = ForeignKeyAction.CASCADE)
     private  GroupResourceProfileEntity groupResourceProfile;
 
     public GroupComputeResourcePrefEntity() {
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GroupResourceProfileEntity.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GroupResourceProfileEntity.java
index 3add1b1..c6bc0a1 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GroupResourceProfileEntity.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GroupResourceProfileEntity.java
@@ -19,7 +19,13 @@
  */
 package org.apache.airavata.registry.core.entities.appcatalog;
 
-import javax.persistence.*;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
 import java.io.Serializable;
 import java.util.List;
 
@@ -28,7 +34,6 @@ import java.util.List;
  */
 @Entity
 @Table(name = "GROUP_RESOURCE_PROFILE")
-@IdClass(GroupResourceProfilePK.class)
 public class GroupResourceProfileEntity implements Serializable {
 
     private static final long serialVersionUID = 1L;
@@ -53,15 +58,15 @@ public class GroupResourceProfileEntity implements Serializable {
     private String defaultCredentialStoreToken;
 
     @OneToMany(targetEntity = GroupComputeResourcePrefEntity.class, cascade = CascadeType.ALL,
-            mappedBy = "groupResourceProfile", fetch = FetchType.EAGER)
+            mappedBy = "groupResourceProfile", fetch = FetchType.EAGER, orphanRemoval = true)
     private List<GroupComputeResourcePrefEntity> computePreferences;
 
     @OneToMany(targetEntity = ComputeResourcePolicyEntity.class, cascade = CascadeType.ALL,
-            mappedBy = "groupResourceProfile", fetch = FetchType.EAGER)
+            mappedBy = "groupResourceProfile", fetch = FetchType.EAGER, orphanRemoval = true)
     private List<ComputeResourcePolicyEntity> computeResourcePolicies;
 
     @OneToMany(targetEntity = BatchQueueResourcePolicyEntity.class, cascade = CascadeType.ALL,
-            mappedBy = "groupResourceProfile", fetch = FetchType.EAGER)
+            mappedBy = "groupResourceProfile", fetch = FetchType.EAGER, orphanRemoval = true)
     private List<BatchQueueResourcePolicyEntity> batchQueueResourcePolicies;
 
     public GroupResourceProfileEntity() {
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GroupResourceProfilePK.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GroupResourceProfilePK.java
deleted file mode 100644
index 0a46b68..0000000
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GroupResourceProfilePK.java
+++ /dev/null
@@ -1,59 +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.registry.core.entities.appcatalog;
-
-import java.io.Serializable;
-
-/**
- * The primary key class for the group_resource_profile database table.
- */
-public class GroupResourceProfilePK implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    private String groupResourceProfileId;
-
-    public GroupResourceProfilePK() {
-
-    }
-
-    public String getGroupResourceProfileId() {
-        return groupResourceProfileId;
-    }
-
-    public void setGroupResourceProfileId(String groupResourceProfileId) {
-        this.groupResourceProfileId = groupResourceProfileId;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-
-        GroupResourceProfilePK that = (GroupResourceProfilePK) o;
-
-        return groupResourceProfileId != null ? groupResourceProfileId.equals(that.groupResourceProfileId)
: that.groupResourceProfileId == null;
-    }
-
-    @Override
-    public int hashCode() {
-        return groupResourceProfileId != null ? groupResourceProfileId.hashCode() : 0;
-    }
-}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GroupSSHAccountProvisionerConfig.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GroupSSHAccountProvisionerConfig.java
index c4eb6c9..1241144 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GroupSSHAccountProvisionerConfig.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/GroupSSHAccountProvisionerConfig.java
@@ -19,7 +19,18 @@
  */
 package org.apache.airavata.registry.core.entities.appcatalog;
 
-import javax.persistence.*;
+import org.apache.openjpa.persistence.jdbc.ForeignKey;
+import org.apache.openjpa.persistence.jdbc.ForeignKeyAction;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
 import java.io.Serializable;
 
 /**
@@ -52,6 +63,7 @@ public class GroupSSHAccountProvisionerConfig implements Serializable{
             @JoinColumn(name = "RESOURCE_ID", referencedColumnName = "RESOURCE_ID", nullable
= false),
             @JoinColumn(name = "GROUP_RESOURCE_PROFILE_ID", referencedColumnName = "GROUP_RESOURCE_PROFILE_ID",
nullable = false)
     })
+    @ForeignKey(deleteAction = ForeignKeyAction.CASCADE)
     private GroupComputeResourcePrefEntity groupComputeResourcePref;
 
     public GroupSSHAccountProvisionerConfig() {
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/BatchQueuePolicyRepository.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/BatchQueuePolicyRepository.java
index 859b096..74c12f1 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/BatchQueuePolicyRepository.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/BatchQueuePolicyRepository.java
@@ -21,12 +21,11 @@ package org.apache.airavata.registry.core.repositories.appcatalog;
 
 import org.apache.airavata.model.appcatalog.groupresourceprofile.BatchQueueResourcePolicy;
 import org.apache.airavata.registry.core.entities.appcatalog.BatchQueueResourcePolicyEntity;
-import org.apache.airavata.registry.core.entities.appcatalog.BatchQueueResourcePolicyPK;
 
 /**
  * Created by skariyat on 2/10/18.
  */
-public class BatchQueuePolicyRepository extends AppCatAbstractRepository<BatchQueueResourcePolicy,
BatchQueueResourcePolicyEntity, BatchQueueResourcePolicyPK> {
+public class BatchQueuePolicyRepository extends AppCatAbstractRepository<BatchQueueResourcePolicy,
BatchQueueResourcePolicyEntity, String> {
 
     public BatchQueuePolicyRepository() {
         super(BatchQueueResourcePolicy.class, BatchQueueResourcePolicyEntity.class);
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GroupResourceProfileRepository.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GroupResourceProfileRepository.java
index 3c9a401..07709b2 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GroupResourceProfileRepository.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GroupResourceProfileRepository.java
@@ -24,10 +24,8 @@ import org.apache.airavata.model.appcatalog.groupresourceprofile.ComputeResource
 import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupComputeResourcePreference;
 import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupResourceProfile;
 import org.apache.airavata.model.commons.airavata_commonsConstants;
-import org.apache.airavata.registry.core.entities.appcatalog.BatchQueueResourcePolicyPK;
 import org.apache.airavata.registry.core.entities.appcatalog.GroupComputeResourcePrefPK;
 import org.apache.airavata.registry.core.entities.appcatalog.GroupResourceProfileEntity;
-import org.apache.airavata.registry.core.entities.appcatalog.GroupResourceProfilePK;
 import org.apache.airavata.registry.core.utils.DBConstants;
 import org.apache.airavata.registry.core.utils.QueryConstants;
 
@@ -39,7 +37,7 @@ import java.util.UUID;
 /**
  * Created by skariyat on 2/8/18.
  */
-public class GroupResourceProfileRepository extends AppCatAbstractRepository<GroupResourceProfile,
GroupResourceProfileEntity, GroupResourceProfilePK> {
+public class GroupResourceProfileRepository extends AppCatAbstractRepository<GroupResourceProfile,
GroupResourceProfileEntity, String> {
 
     public GroupResourceProfileRepository() {
         super(GroupResourceProfile.class, GroupResourceProfileEntity.class);
@@ -90,22 +88,16 @@ public class GroupResourceProfileRepository extends AppCatAbstractRepository<Gro
     }
 
     public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) {
-        GroupResourceProfilePK groupResourceProfilePK = new GroupResourceProfilePK();
-        groupResourceProfilePK.setGroupResourceProfileId(groupResourceProfileId);
-        GroupResourceProfile groupResourceProfile = get(groupResourceProfilePK);
+        GroupResourceProfile groupResourceProfile = get(groupResourceProfileId);
         return groupResourceProfile;
     }
 
     public boolean removeGroupResourceProfile(String groupResourceProfileId) {
-        GroupResourceProfilePK groupResourceProfilePK = new GroupResourceProfilePK();
-        groupResourceProfilePK.setGroupResourceProfileId(groupResourceProfileId);
-        return delete(groupResourceProfilePK);
+        return delete(groupResourceProfileId);
     }
 
     public boolean isGroupResourceProfileExists(String groupResourceProfileId) {
-        GroupResourceProfilePK groupResourceProfilePK = new GroupResourceProfilePK();
-        groupResourceProfilePK.setGroupResourceProfileId(groupResourceProfileId);
-        return isExists(groupResourceProfilePK);
+        return isExists(groupResourceProfileId);
     }
 
     public List<GroupResourceProfile> getAllGroupResourceProfiles(String gatewayId,
List<String> accessibleGroupResProfileIds) {
@@ -133,10 +125,7 @@ public class GroupResourceProfileRepository extends AppCatAbstractRepository<Gro
     }
 
     public boolean removeBatchQueueResourcePolicy(String resourcePolicyId) {
-        BatchQueueResourcePolicyPK batchQueueResourcePolicyPK = new BatchQueueResourcePolicyPK();
-        batchQueueResourcePolicyPK.setResourcePolicyId(resourcePolicyId);
-
-        return (new BatchQueuePolicyRepository().delete(batchQueueResourcePolicyPK));
+        return (new BatchQueuePolicyRepository().delete(resourcePolicyId));
     }
 
     public GroupComputeResourcePreference getGroupComputeResourcePreference(String computeResourceId,
String groupResourceProfileId) {
@@ -152,10 +141,7 @@ public class GroupResourceProfileRepository extends AppCatAbstractRepository<Gro
     }
 
     public BatchQueueResourcePolicy getBatchQueueResourcePolicy(String resourcePolicyId)
{
-        BatchQueueResourcePolicyPK batchQueueResourcePolicyPK = new BatchQueueResourcePolicyPK();
-        batchQueueResourcePolicyPK.setResourcePolicyId(resourcePolicyId);
-
-        return (new BatchQueuePolicyRepository().get(batchQueueResourcePolicyPK));
+        return (new BatchQueuePolicyRepository().get(resourcePolicyId));
     }
 
     public List<GroupComputeResourcePreference> getAllGroupComputeResourcePreferences(String
groupResourceProfileId) {
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/AppCatalogJPAUtils.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/AppCatalogJPAUtils.java
index f3c82f4..097effd 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/AppCatalogJPAUtils.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/AppCatalogJPAUtils.java
@@ -64,6 +64,7 @@ public class AppCatalogJPAUtils {
             properties.put("openjpa.Log", "DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO");
             properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
             properties.put("openjpa.jdbc.QuerySQLCache", "false");
+            properties.put("openjpa.DetachState", "all");
             properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72,
PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=31536000,  autoReconnect=true");
             factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
         }
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/ExpCatalogJPAUtils.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/ExpCatalogJPAUtils.java
index d83733a..9c9d4ff 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/ExpCatalogJPAUtils.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/ExpCatalogJPAUtils.java
@@ -64,6 +64,7 @@ public class ExpCatalogJPAUtils {
             properties.put("openjpa.RemoteCommitProvider", "sjvm");
             properties.put("openjpa.Log", "DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO");
             properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
+            properties.put("openjpa.DetachState", "all");
             properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72,
PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=31536000,  autoReconnect=true");
 //			properties.put("openjpa.jdbc.QuerySQLCache", "false");
             factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/RepCatalogJPAUtils.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/RepCatalogJPAUtils.java
index 234db06..2cc6f03 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/RepCatalogJPAUtils.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/RepCatalogJPAUtils.java
@@ -60,6 +60,7 @@ public class RepCatalogJPAUtils {
             properties.put("openjpa.Log","DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO");
             properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
             properties.put("openjpa.jdbc.QuerySQLCache", "false");
+            properties.put("openjpa.DetachState", "all");
             properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72,"
+
                     " PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=31536000,
 autoReconnect=true");
             factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/WorkflowCatalogJPAUtils.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/WorkflowCatalogJPAUtils.java
index 57971b3..852007e 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/WorkflowCatalogJPAUtils.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/WorkflowCatalogJPAUtils.java
@@ -61,6 +61,7 @@ public class WorkflowCatalogJPAUtils {
             properties.put("openjpa.Log","DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO");
             properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
             properties.put("openjpa.jdbc.QuerySQLCache", "false");
+            properties.put("openjpa.DetachState", "all");
             properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72,
PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=31536000,  autoReconnect=true");
             factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
         }
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ObjectMapperSingleton.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ObjectMapperSingleton.java
index b184bc1..8ff15c4 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ObjectMapperSingleton.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/ObjectMapperSingleton.java
@@ -20,6 +20,7 @@
 */
 package org.apache.airavata.registry.core.utils;
 
+import org.apache.commons.lang3.ClassUtils;
 import org.apache.thrift.TBase;
 import org.apache.thrift.TFieldIdEnum;
 import org.dozer.CustomFieldMapper;
@@ -53,9 +54,9 @@ public class ObjectMapperSingleton extends DozerBeanMapper{
     private static class MyCustomFieldMapper implements CustomFieldMapper {
         @Override
         public boolean mapField(Object source, Object destination, Object sourceFieldValue,
ClassMap classMap, FieldMap fieldMap) {
-            // Just skipping mapping field if not set on Thrift source model
-            if (isSourceUnsetThriftField(source, fieldMap)) {
-                logger.debug("Skipping field " + fieldMap.getSrcFieldName() + " since it
is unset thrift field");
+            // Just skipping mapping field if not set on Thrift source model and it is primitive
+            if (isSourceUnsetThriftField(source, fieldMap) && ClassUtils.isPrimitiveOrWrapper(source.getClass()))
{
+                logger.debug("Skipping field " + fieldMap.getSrcFieldName() + " since it
is unset thrift field and is primitive");
                 return true;
             }
             return false;
diff --git a/modules/registry-refactoring/src/main/resources/appcatalog-derby.sql b/modules/registry-refactoring/src/main/resources/appcatalog-derby.sql
index 8cddba8..5c5c55c 100644
--- a/modules/registry-refactoring/src/main/resources/appcatalog-derby.sql
+++ b/modules/registry-refactoring/src/main/resources/appcatalog-derby.sql
@@ -633,7 +633,7 @@ CREATE TABLE GROUP_COMPUTE_RESOURCE_PREFERENCE
         SSH_ACCOUNT_PROVISIONER_ADDITIONAL_INFO VARCHAR(1000),
         PRIMARY KEY(RESOURCE_ID,GROUP_RESOURCE_PROFILE_ID),
         FOREIGN KEY (RESOURCE_ID) REFERENCES COMPUTE_RESOURCE(RESOURCE_ID) ON DELETE CASCADE,
-        FOREIGN KEY (GROUP_RESOURCE_PROFILE_ID) REFERENCES GROUP_RESOURCE_PROFILE(GROUP_RESOURCE_PROFILE_ID)
+        FOREIGN KEY (GROUP_RESOURCE_PROFILE_ID) REFERENCES GROUP_RESOURCE_PROFILE(GROUP_RESOURCE_PROFILE_ID)
ON DELETE CASCADE
 );
 
 CREATE TABLE GRP_SSH_ACC_PROV_CONFIG
diff --git a/modules/registry-refactoring/src/main/resources/appcatalog-mysql.sql b/modules/registry-refactoring/src/main/resources/appcatalog-mysql.sql
index 3c4a7e5..21dc233 100644
--- a/modules/registry-refactoring/src/main/resources/appcatalog-mysql.sql
+++ b/modules/registry-refactoring/src/main/resources/appcatalog-mysql.sql
@@ -632,7 +632,7 @@ CREATE TABLE GROUP_COMPUTE_RESOURCE_PREFERENCE
         SSH_ACCOUNT_PROVISIONER_ADDITIONAL_INFO VARCHAR(1000),
         PRIMARY KEY(RESOURCE_ID,GROUP_RESOURCE_PROFILE_ID),
         FOREIGN KEY (RESOURCE_ID) REFERENCES COMPUTE_RESOURCE(RESOURCE_ID) ON DELETE CASCADE,
-        FOREIGN KEY (GROUP_RESOURCE_PROFILE_ID) REFERENCES GROUP_RESOURCE_PROFILE(GROUP_RESOURCE_PROFILE_ID)
+        FOREIGN KEY (GROUP_RESOURCE_PROFILE_ID) REFERENCES GROUP_RESOURCE_PROFILE(GROUP_RESOURCE_PROFILE_ID)
ON DELETE CASCADE
 )ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
 CREATE TABLE GRP_SSH_ACC_PROV_CONFIG
diff --git a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/appcatalog/GroupResourceProfileRepositoryTest.java
b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/appcatalog/GroupResourceProfileRepositoryTest.java
index 3815dad..2489094 100644
--- a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/appcatalog/GroupResourceProfileRepositoryTest.java
+++ b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/appcatalog/GroupResourceProfileRepositoryTest.java
@@ -32,6 +32,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 public class GroupResourceProfileRepositoryTest extends TestBase {
@@ -207,6 +208,40 @@ public class GroupResourceProfileRepositoryTest extends TestBase {
         assertTrue(groupResourceProfileRepository.getAllGroupComputeResourcePolicies(groupResourceProfileId).size()
== 2);
         assertTrue(groupResourceProfileRepository.getAllGroupBatchQueueResourcePolicies(groupResourceProfileId).size()
== 2);
 
+        // AIRAVATA-2872 Test setting resourceSpecificCredentialStoreToken to a value and
then changing it to null
+        GroupResourceProfile retrievedGroupResourceProfile = groupResourceProfileRepository.getGroupResourceProfile(groupResourceProfileId);
+        GroupComputeResourcePreference retrievedGroupComputeResourcePreference = retrievedGroupResourceProfile.getComputePreferences().stream()
+                .filter(pref -> pref.getComputeResourceId().equals(resourceId1))
+                .findFirst()
+                .get();
+        assertNull(retrievedGroupComputeResourcePreference.getResourceSpecificCredentialStoreToken());
+        retrievedGroupComputeResourcePreference.setResourceSpecificCredentialStoreToken("abc123");
+        groupResourceProfileRepository.updateGroupResourceProfile(retrievedGroupResourceProfile);
+
+        GroupResourceProfile retrievedGroupResourceProfile2 = groupResourceProfileRepository.getGroupResourceProfile(groupResourceProfileId);
+        GroupComputeResourcePreference retrievedGroupComputeResourcePreference2 = retrievedGroupResourceProfile2.getComputePreferences().stream()
+                .filter(pref -> pref.getComputeResourceId().equals(resourceId1))
+                .findFirst()
+                .get();
+        assertEquals("abc123", retrievedGroupComputeResourcePreference2.getResourceSpecificCredentialStoreToken());
+        retrievedGroupComputeResourcePreference2.setResourceSpecificCredentialStoreToken(null);
+        assertNull(retrievedGroupComputeResourcePreference2.getResourceSpecificCredentialStoreToken());
+        groupResourceProfileRepository.updateGroupResourceProfile(retrievedGroupResourceProfile2);
+
+        GroupResourceProfile retrievedGroupResourceProfile3 = groupResourceProfileRepository.getGroupResourceProfile(groupResourceProfileId);
+        GroupComputeResourcePreference retrievedGroupComputeResourcePreference3 = retrievedGroupResourceProfile3.getComputePreferences().stream()
+                .filter(pref -> pref.getComputeResourceId().equals(resourceId1))
+                .findFirst()
+                .get();
+        assertNull(retrievedGroupComputeResourcePreference3.getResourceSpecificCredentialStoreToken());
+
+        // Orphan removal test
+        assertEquals(2, retrievedGroupResourceProfile3.getComputePreferencesSize());
+        retrievedGroupResourceProfile3.setComputePreferences(retrievedGroupResourceProfile3.getComputePreferences().subList(0,
1));
+        groupResourceProfileRepository.updateGroupResourceProfile(retrievedGroupResourceProfile3);
+        GroupResourceProfile retrievedGroupResourceProfile4 = groupResourceProfileRepository.getGroupResourceProfile(groupResourceProfileId);
+        assertEquals(1, retrievedGroupResourceProfile4.getComputePreferencesSize());
+
         groupResourceProfileRepository.removeGroupResourceProfile(groupResourceProfileId);
         computeResourceRepository.removeComputeResource(resourceId1);
         computeResourceRepository.removeComputeResource(resourceId2);
diff --git a/modules/registry-refactoring/src/test/resources/appcatalog-derby.sql b/modules/registry-refactoring/src/test/resources/appcatalog-derby.sql
index 792f1e1..0dbbd6a 100644
--- a/modules/registry-refactoring/src/test/resources/appcatalog-derby.sql
+++ b/modules/registry-refactoring/src/test/resources/appcatalog-derby.sql
@@ -639,7 +639,7 @@ CREATE TABLE GROUP_COMPUTE_RESOURCE_PREFERENCE
         SSH_ACCOUNT_PROVISIONER_ADDITIONAL_INFO VARCHAR(1000),
         PRIMARY KEY(RESOURCE_ID,GROUP_RESOURCE_PROFILE_ID),
         FOREIGN KEY (RESOURCE_ID) REFERENCES COMPUTE_RESOURCE(RESOURCE_ID) ON DELETE CASCADE,
-        FOREIGN KEY (GROUP_RESOURCE_PROFILE_ID) REFERENCES GROUP_RESOURCE_PROFILE(GROUP_RESOURCE_PROFILE_ID)
+        FOREIGN KEY (GROUP_RESOURCE_PROFILE_ID) REFERENCES GROUP_RESOURCE_PROFILE(GROUP_RESOURCE_PROFILE_ID)
ON DELETE CASCADE
 );
 
 CREATE TABLE GRP_SSH_ACC_PROV_CONFIG


Mime
View raw message