Making the requested changes
MODIFY
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/UserComputeResourcePreferenceEntity.java
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/UserComputeResourcePreferenceEntity.java
@@ -75,7 +75,10 @@ public class UserComputeResourcePreferenceEntity {
private boolean validated;
@ManyToOne(targetEntity = UserResourceProfileEntity.class, cascade = CascadeType.MERGE)
- @JoinColumn(name = "USER_ID")
+ @JoinColumns({
+ @JoinColumn(name = "USER_ID"),
+ @JoinColumn(name="GATEWAY_ID")
+ })
private UserResourceProfileEntity userResourceProfile;
public UserComputeResourcePreferenceEntity() {

MODIFY
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/UserComputeResourcePreferencePK.java
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/UserComputeResourcePreferencePK.java
@@ -32,16 +32,8 @@ public class UserComputeResourcePreferencePK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
- @Id
- @Column(name = "RESOURCE_ID")
private String computeResourceId;
-
- @Id
- @Column(name = "USER_ID")
private String userId;
-
- @Id
- @Column(name = "GATEWAY_ID")
private String gatewayId;
public UserComputeResourcePreferencePK() {

MODIFY
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/UserResourceProfilePK.java
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/UserResourceProfilePK.java
@@ -32,12 +32,7 @@ public class UserResourceProfilePK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
- @Id
- @Column(name = "USER_ID")
private String userId;
-
- @Id
- @Column(name = "GATEWAY_ID")
private String gatewayId;
public UserResourceProfilePK() {

MODIFY
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/UserStoragePreferenceEntity.java
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/UserStoragePreferenceEntity.java
@@ -53,7 +53,10 @@ public class UserStoragePreferenceEntity {
private String loginUserName;
@ManyToOne(targetEntity = UserResourceProfileEntity.class, cascade = CascadeType.MERGE)
- @JoinColumn(name = "USER_ID")
+ @JoinColumns({
+ @JoinColumn(name = "USER_ID"),
+ @JoinColumn(name="GATEWAY_ID")
+ })
private UserResourceProfileEntity userResourceProfile;
public UserStoragePreferenceEntity() {

MODIFY
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/UserStoragePreferencePK.java
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/UserStoragePreferencePK.java
@@ -32,16 +32,8 @@ public class UserStoragePreferencePK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
- @Id
- @Column(name = "STORAGE_RESOURCE_ID")
private String storageResourceId;
-
- @Id
- @Column(name = "USER_ID")
private String userId;
-
- @Id
- @Column(name = "GATEWAY_ID")
private String gatewayId;
public UserStoragePreferencePK() {

MODIFY
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/UserResourceProfileRepository.java
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/UserResourceProfileRepository.java
@@ -59,14 +59,14 @@ public class UserResourceProfileRepository extends AppCatAbstractRepository<User
if (userResourceProfileEntity.getUserComputeResourcePreferences() != null) {
logger.debug("Populating the Primary Key UserComputeResourcePreferences objects for the User Resource Profile");
- userResourceProfileEntity.getUserComputeResourcePreferences().forEach(userComputeResourcePreferenceEntity -> userComputeResourcePreferenceEntity.setUserId(userId));
- userResourceProfileEntity.getUserComputeResourcePreferences().forEach(userComputeResourcePreferenceEntity -> userComputeResourcePreferenceEntity.setGatewayId(gatewayId));
+ userResourceProfileEntity.getUserComputeResourcePreferences().forEach(userComputeResourcePreferenceEntity -> { userComputeResourcePreferenceEntity.setUserId(userId);
+ userComputeResourcePreferenceEntity.setGatewayId(gatewayId); });
}
if (userResourceProfileEntity.getUserStoragePreferences() != null) {
logger.debug("Populating the Primary Key UserStoragePreferences objects for the User Resource Profile");
- userResourceProfileEntity.getUserStoragePreferences().forEach(userStoragePreferenceEntity -> userStoragePreferenceEntity.setUserId(userId));
- userResourceProfileEntity.getUserStoragePreferences().forEach(userStoragePreferenceEntity -> userStoragePreferenceEntity.setGatewayId(gatewayId));
+ userResourceProfileEntity.getUserStoragePreferences().forEach(userStoragePreferenceEntity -> { userStoragePreferenceEntity.setUserId(userId);
+ userStoragePreferenceEntity.setGatewayId(gatewayId); });
}
if (!isUserResourceProfileExists(userId, gatewayId)) {
@@ -90,53 +90,33 @@ public class UserResourceProfileRepository extends AppCatAbstractRepository<User
@Override
public UserResourceProfile getUserResourceProfile(String userId, String gatewayId) throws AppCatalogException {
- Map<String, Object> queryParameters = new HashMap<>();
- queryParameters.put(DBConstants.UserResourceProfile.USER_ID, userId);
- queryParameters.put(DBConstants.UserResourceProfile.GATEWAY_ID, gatewayId);
- List<UserResourceProfile> userResourceProfileList = select(QueryConstants.GET_USER_RESOURCE_PROFILE, -1, 0, queryParameters);
-
- if(!userResourceProfileList.isEmpty() && userResourceProfileList != null) {
- logger.debug("Return the record (there is only one record)");
- return userResourceProfileList.get(0);
- }
-
- return null;
+ UserResourceProfilePK userResourceProfilePK = new UserResourceProfilePK();
+ userResourceProfilePK.setUserId(userId);
+ userResourceProfilePK.setGatewayId(gatewayId);
+ UserResourceProfile userResourceProfile = get(userResourceProfilePK);
+ return userResourceProfile;
}
@Override
public UserComputeResourcePreference getUserComputeResourcePreference(String userId, String gatewayId, String hostId) throws AppCatalogException {
UserComputeResourcePreferenceRepository userComputeResourcePreferenceRepository = new UserComputeResourcePreferenceRepository();
- Map<String, Object> queryParameters = new HashMap<>();
- queryParameters.put(DBConstants.UserComputeResourcePreference.USER_ID, userId);
- queryParameters.put(DBConstants.UserComputeResourcePreference.GATEWAY_ID, gatewayId);
- queryParameters.put(DBConstants.UserComputeResourcePreference.COMPUTE_RESOURCE_ID, hostId);
- List<UserComputeResourcePreference> userComputeResourcePreferenceList =
- userComputeResourcePreferenceRepository.select(QueryConstants.GET_USER_COMPUTE_RESOURCE_PREFERENCE, -1, 0, queryParameters);
-
- if(!userComputeResourcePreferenceList.isEmpty() && userComputeResourcePreferenceList != null) {
- logger.debug("Return the record (there is only one record)");
- return userComputeResourcePreferenceList.get(0);
- }
-
- return null;
+ UserComputeResourcePreferencePK userComputeResourcePreferencePK = new UserComputeResourcePreferencePK();
+ userComputeResourcePreferencePK.setUserId(userId);
+ userComputeResourcePreferencePK.setGatewayId(gatewayId);
+ userComputeResourcePreferencePK.setComputeResourceId(hostId);
+ UserComputeResourcePreference userComputeResourcePreference = userComputeResourcePreferenceRepository.get(userComputeResourcePreferencePK);
+ return userComputeResourcePreference;
}
@Override
public UserStoragePreference getUserStoragePreference(String userId, String gatewayId, String storageId) throws AppCatalogException {
UserStoragePreferenceRepository userStoragePreferenceRepository = new UserStoragePreferenceRepository();
- Map<String, Object> queryParameters = new HashMap<>();
- queryParameters.put(DBConstants.UserStoragePreference.USER_ID, userId);
- queryParameters.put(DBConstants.UserStoragePreference.GATEWAY_ID, gatewayId);
- queryParameters.put(DBConstants.UserStoragePreference.STORAGE_RESOURCE_ID, storageId);
- List<UserStoragePreference> userStoragePreferenceList =
- userStoragePreferenceRepository.select(QueryConstants.GET_USER_STORAGE_PREFERENCE, -1, 0, queryParameters);
-
- if(!userStoragePreferenceList.isEmpty() && userStoragePreferenceList != null) {
- logger.debug("Return the record (there is only one record)");
- return userStoragePreferenceList.get(0);
- }
-
- return null;
+ UserStoragePreferencePK userStoragePreferencePK = new UserStoragePreferencePK();
+ userStoragePreferencePK.setUserId(userId);
+ userStoragePreferencePK.setGatewayId(gatewayId);
+ userStoragePreferencePK.setStorageResourceId(storageId);
+ UserStoragePreference userStoragePreference = userStoragePreferenceRepository.get(userStoragePreferencePK);
+ return userStoragePreference;
}
@Override

MODIFY
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java
@@ -38,23 +38,14 @@ public interface QueryConstants {
String FIND_ALL_GROUP_COMPUTE_RESOURCE_POLICY = "SELECT CR FROM "+ ComputeResourcePolicyEntity.class.getSimpleName() + " CR " +
"WHERE CR.groupResourceProfileId LIKE : " + DBConstants.GroupResourceProfile.GROUP_RESOURCE_PROFILE_ID;
- String GET_USER_RESOURCE_PROFILE = "SELECT DISTINCT URP FROM " + UserResourceProfileEntity.class.getSimpleName() + " URP " +
- "WHERE URP.userId LIKE :"+ DBConstants.UserResourceProfile.USER_ID + " AND URP.gatewayId LIKE :" +
- DBConstants.UserResourceProfile.GATEWAY_ID;
String GET_ALL_USER_RESOURCE_PROFILE = "SELECT URP FROM " + UserResourceProfileEntity.class.getSimpleName() + " URP";
String GET_ALL_GATEWAY_ID = "SELECT DISTINCT URP FROM " + UserResourceProfileEntity.class.getSimpleName() + " URP " +
"WHERE URP.gatewayId LIKE :" + DBConstants.UserResourceProfile.GATEWAY_ID;
- String GET_USER_COMPUTE_RESOURCE_PREFERENCE = "SELECT DISTINCT UCRP FROM " + UserComputeResourcePreferenceEntity.class.getSimpleName() + " UCRP " +
- "WHERE UCRP.userId LIKE :" + DBConstants.UserComputeResourcePreference.USER_ID + " AND UCRP.gatewayId LIKE :" + DBConstants.UserComputeResourcePreference.GATEWAY_ID +
- " AND UCRP.computeResourceId LIKE :" + DBConstants.UserComputeResourcePreference.COMPUTE_RESOURCE_ID;
String GET_ALL_USER_COMPUTE_RESOURCE_PREFERENCE = "SELECT UCRP FROM " + UserComputeResourcePreferenceEntity.class.getSimpleName() + " UCRP " +
"WHERE UCRP.userId LIKE :" + DBConstants.UserComputeResourcePreference.USER_ID + " AND UCRP.gatewayId LIKE :" +
DBConstants.UserComputeResourcePreference.GATEWAY_ID;
- String GET_USER_STORAGE_PREFERENCE = "SELECT DISTINCT USP FROM " + UserStoragePreferenceEntity.class.getSimpleName() + " USP " +
- "WHERE USP.userId LIKE :" + DBConstants.UserStoragePreference.USER_ID + " AND USP.gatewayId LIKE :" + DBConstants.UserStoragePreference.GATEWAY_ID +
- " AND USP.storageResourceId LIKE :" + DBConstants.UserStoragePreference.STORAGE_RESOURCE_ID;
String GET_ALL_USER_STORAGE_PREFERENCE = "SELECT USP FROM " + UserStoragePreferenceEntity.class.getSimpleName() + " USP " +
"WHERE USP.userId LIKE :" + DBConstants.UserStoragePreference.USER_ID + " AND USP.gatewayId LIKE :" +
DBConstants.UserStoragePreference.GATEWAY_ID;

Making the requested changes