[ 
https://issues.apache.org/jira/browse/AIRAVATA-2712?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16414454#comment-16414454
 ] 

ASF GitHub Bot commented on AIRAVATA-2712:
------------------------------------------

tilaks26 commented on a change in pull request #185: [AIRAVATA-2712] 
Refactoring App Catalog Implementation - UserResourceProfile
URL: https://github.com/apache/airavata/pull/185#discussion_r177217674
 
 

 ##########
 File path: 
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/UserResourceProfileRepository.java
 ##########
 @@ -0,0 +1,227 @@
+/**
+ *
+ * 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.repositories.appcatalog;
+
+import 
org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference;
+import 
org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile;
+import 
org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference;
+import 
org.apache.airavata.registry.core.entities.appcatalog.UserComputeResourcePreferencePK;
+import 
org.apache.airavata.registry.core.entities.appcatalog.UserResourceProfileEntity;
+import 
org.apache.airavata.registry.core.entities.appcatalog.UserResourceProfilePK;
+import 
org.apache.airavata.registry.core.entities.appcatalog.UserStoragePreferencePK;
+import org.apache.airavata.registry.core.utils.DBConstants;
+import org.apache.airavata.registry.core.utils.ObjectMapperSingleton;
+import org.apache.airavata.registry.core.utils.QueryConstants;
+import org.apache.airavata.registry.cpi.AppCatalogException;
+import org.apache.airavata.registry.cpi.CompositeIdentifier;
+import org.apache.airavata.registry.cpi.UsrResourceProfile;
+import org.dozer.Mapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Timestamp;
+import java.util.*;
+
+public class UserResourceProfileRepository extends 
AppCatAbstractRepository<UserResourceProfile, UserResourceProfileEntity, 
UserResourceProfilePK> implements UsrResourceProfile {
+    private final static Logger logger = 
LoggerFactory.getLogger(UserResourceProfileRepository.class);
+
+    public UserResourceProfileRepository() {
+        super(UserResourceProfile.class, UserResourceProfileEntity.class);
+    }
+
+    protected String saveUserResourceProfileData(UserResourceProfile 
userResourceProfile) throws AppCatalogException {
+        UserResourceProfileEntity userResourceProfileEntity = 
saveUserResourceProfile(userResourceProfile);
+        return userResourceProfileEntity.getUserId();
+    }
+
+    protected UserResourceProfileEntity 
saveUserResourceProfile(UserResourceProfile userResourceProfile) throws 
AppCatalogException {
+        String userId = userResourceProfile.getUserId();
+        String gatewayId = userResourceProfile.getGatewayID();
+        Mapper mapper = ObjectMapperSingleton.getInstance();
+        UserResourceProfileEntity userResourceProfileEntity = 
mapper.map(userResourceProfile, UserResourceProfileEntity.class);
+
+        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));
+        }
+
+        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));
+        }
+
+        if (!isUserResourceProfileExists(userId, gatewayId)) {
+            logger.debug("Checking if the User Resource Profile already 
exists");
+            userResourceProfileEntity.setCreationTime(new 
Timestamp(System.currentTimeMillis()));
+        }
+
+        userResourceProfileEntity.setUpdateTime(new 
Timestamp(System.currentTimeMillis()));
+        return execute(entityManager -> 
entityManager.merge(userResourceProfileEntity));
+    }
+
+    @Override
+    public String addUserResourceProfile(UserResourceProfile 
userResourceProfile) throws AppCatalogException {
+        return saveUserResourceProfileData(userResourceProfile);
+    }
+
+    @Override
+    public void updateUserResourceProfile(String userId, String gatewayId, 
UserResourceProfile updatedProfile) throws AppCatalogException {
+        saveUserResourceProfileData(updatedProfile);
+    }
+
+    @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;
+    }
+
+    @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;
+    }
+
+    @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;
+    }
+
+    @Override
+    public List<UserResourceProfile> getAllUserResourceProfiles() throws 
AppCatalogException {
+        List<UserResourceProfile> userResourceProfileList = 
select(QueryConstants.GET_ALL_USER_RESOURCE_PROFILE, 0);
+        return userResourceProfileList;
+    }
+
+    @Override
+    public List<UserComputeResourcePreference> 
getAllUserComputeResourcePreferences(String userId, String gatewayId) 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);
+        List<UserComputeResourcePreference> userComputeResourcePreferenceList =
+                
userComputeResourcePreferenceRepository.select(QueryConstants.GET_ALL_USER_COMPUTE_RESOURCE_PREFERENCE,
 -1, 0, queryParameters);
+        return userComputeResourcePreferenceList;
+    }
+
+    @Override
+    public List<UserStoragePreference> getAllUserStoragePreferences(String 
userId, String gatewayId) 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);
+        List<UserStoragePreference> userStoragePreferenceList =
+                
userStoragePreferenceRepository.select(QueryConstants.GET_ALL_USER_STORAGE_PREFERENCE,
 -1, 0, queryParameters);
+        return userStoragePreferenceList;
+    }
+
+    @Override
+    public List<String> getGatewayProfileIds(String gatewayName) throws 
AppCatalogException {
+        Map<String, Object> queryParameters = new HashMap<>();
+        queryParameters.put(DBConstants.UserResourceProfile.GATEWAY_ID, 
gatewayName);
+        List<UserResourceProfile> userResourceProfileList = 
select(QueryConstants.GET_ALL_GATEWAY_ID, -1, 0, queryParameters);
+        List<String> gatewayIdList = new ArrayList<>();
+        for (UserResourceProfile userResourceProfile : 
userResourceProfileList) {
+            gatewayIdList.add(userResourceProfile.getGatewayID());
+        }
+        return gatewayIdList;
+    }
+
+    @Override
+    public String getUserNamefromID(String userId, String gatewayID) throws 
AppCatalogException {
 
 Review comment:
   Sure.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Refactoring App Catalog Implementation - User Resource Profile
> --------------------------------------------------------------
>
>                 Key: AIRAVATA-2712
>                 URL: https://issues.apache.org/jira/browse/AIRAVATA-2712
>             Project: Airavata
>          Issue Type: Improvement
>          Components: Registry API
>            Reporter: Sneha Tilak
>            Assignee: Sneha Tilak
>            Priority: Major
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to