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

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

tilaks26 commented on a change in pull request #191: [AIRAVATA-2728] 
Refactoring Experiment Catalog Implementation
URL: https://github.com/apache/airavata/pull/191#discussion_r185113098
 
 

 ##########
 File path: 
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/ExperimentSummaryRepository.java
 ##########
 @@ -0,0 +1,265 @@
+package org.apache.airavata.registry.core.repositories.expcatalog;
+
+import org.apache.airavata.model.experiment.ExperimentStatistics;
+import org.apache.airavata.model.experiment.ExperimentSummaryModel;
+import org.apache.airavata.model.status.ExperimentState;
+import 
org.apache.airavata.registry.core.entities.expcatalog.ExperimentSummaryEntity;
+import org.apache.airavata.registry.core.utils.DBConstants;
+import org.apache.airavata.registry.cpi.RegistryException;
+import org.apache.airavata.registry.cpi.ResultOrderType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Timestamp;
+import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ExperimentSummaryRepository extends 
ExpCatAbstractRepository<ExperimentSummaryModel, ExperimentSummaryEntity, 
String> {
+    private final static Logger logger = 
LoggerFactory.getLogger(ExperimentRepository.class);
+
+    public ExperimentSummaryRepository() { super(ExperimentSummaryModel.class, 
ExperimentSummaryEntity.class); }
+
+    public List<ExperimentSummaryModel> searchExperiments(Map<String, String> 
filters, int limit,
+                                                          int offset, Object 
orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
+        return searchAllAccessibleExperiments(null, filters, limit, offset, 
orderByIdentifier, resultOrderType);
+    }
+
+    public List<ExperimentSummaryModel> 
searchAllAccessibleExperiments(List<String> accessibleExperimentIds, 
Map<String, String> filters, int limit,
+                                                                       int 
offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws 
RegistryException {
+        String query = "SELECT ES FROM " + 
ExperimentSummaryEntity.class.getSimpleName() + " ES WHERE ";
+        Map<String, Object> queryParameters = new HashMap<>();
+
+        if (filters != null && !filters.isEmpty()) {
+
+            for (String field : filters.keySet()) {
+
+                if (field.equals(DBConstants.Experiment.USER_NAME)) {
+                    logger.debug("Filter Experiments by User");
+                    queryParameters.put(DBConstants.Experiment.USER_NAME, 
filters.get(field));
+                    query += "ES.userName LIKE :" + 
DBConstants.Experiment.USER_NAME + " AND ";
+                }
+
+                else if (field.equals(DBConstants.Experiment.GATEWAY_ID)) {
+                    logger.debug("Filter Experiments by Gateway ID");
+                    queryParameters.put(DBConstants.Experiment.GATEWAY_ID, 
filters.get(field));
+                    query += "ES.gatewayId LIKE :" + 
DBConstants.Experiment.GATEWAY_ID + " AND ";
+                }
+
+                else if (field.equals(DBConstants.Experiment.PROJECT_ID)) {
+                    logger.debug("Filter Experiments by Project ID");
+                    queryParameters.put(DBConstants.Experiment.PROJECT_ID, 
filters.get(field));
+                    query += "ES.projectId LIKE :" + 
DBConstants.Experiment.PROJECT_ID + " AND ";
+                }
+
+                else if (field.equals(DBConstants.Experiment.EXPERIMENT_NAME)) 
{
+                    logger.debug("Filter Experiments by Name");
+                    
queryParameters.put(DBConstants.Experiment.EXPERIMENT_NAME, filters.get(field));
+                    query += "ES.name LIKE :" + 
DBConstants.Experiment.EXPERIMENT_NAME + " AND ";
+                }
+
+                else if (field.equals(DBConstants.Experiment.DESCRIPTION)) {
+                    logger.debug("Filter Experiments by Description");
+                    queryParameters.put(DBConstants.Experiment.DESCRIPTION, 
filters.get(field));
+                    query += "ES.description LIKE :" + 
DBConstants.Experiment.DESCRIPTION + " AND ";
+                }
+
+                else if (field.equals(DBConstants.Experiment.EXECUTION_ID)) {
+                    logger.debug("Filter Experiments by Execution ID");
+                    queryParameters.put(DBConstants.Experiment.EXECUTION_ID, 
filters.get(field));
+                    query += "ES.executionId LIKE :" + 
DBConstants.Experiment.EXECUTION_ID + " AND ";
+                }
+
+            }
+
+        }
+
+        if (filters.get(DBConstants.ExperimentStatus.STATE) != null) {
+            logger.debug("Filter Experiments by State");
+            String state = 
ExperimentState.valueOf(filters.get(DBConstants.ExperimentStatus.STATE)).toString();
+            queryParameters.put(DBConstants.ExperimentStatus.STATE, state);
+            query += "ES.state LIKE :" + DBConstants.ExperimentStatus.STATE + 
" AND ";
+        }
+
+        if (filters.get(DBConstants.ExperimentSummary.FROM_DATE) != null
+                && filters.get(DBConstants.ExperimentSummary.TO_DATE) != null) 
{
+
+            Timestamp fromDate = 
Timestamp.valueOf(filters.get(DBConstants.ExperimentSummary.FROM_DATE));
+            Timestamp toDate = 
Timestamp.valueOf(filters.get(DBConstants.ExperimentSummary.TO_DATE));
+
+            if (toDate.after(fromDate)) {
+                logger.debug("Filter Experiments by CreationTime");
+                queryParameters.put(DBConstants.ExperimentSummary.FROM_DATE, 
fromDate);
+                queryParameters.put(DBConstants.ExperimentSummary.TO_DATE, 
toDate);
+                query += "ES.creationTime BETWEEN :" + 
DBConstants.ExperimentSummary.FROM_DATE + " AND :" + 
DBConstants.ExperimentSummary.TO_DATE + " AND ";
+            }
+
+        }
+
+        if (accessibleExperimentIds != null && 
!accessibleExperimentIds.isEmpty()) {
+            logger.debug("Filter Experiments by Accessible Experiment IDs");
+            
queryParameters.put(DBConstants.Experiment.ACCESSIBLE_EXPERIMENT_IDS, 
accessibleExperimentIds);
+            query += " ES.experimentId IN :" + 
DBConstants.Experiment.ACCESSIBLE_EXPERIMENT_IDS;
+        }
+
+        else {
+            logger.debug("Removing the last operator from the query");
+            query = query.substring(0, query.length() - 5);
+        }
+
+        List<ExperimentSummaryModel> experimentSummaryModelList = 
select(query, limit, offset, queryParameters);
+        return experimentSummaryModelList;
+    }
+
+    public ExperimentStatistics getExperimentStatistics(Map<String,String> 
filters) throws RegistryException {
+
+        try {
+
+            ExperimentStatistics experimentStatistics = new 
ExperimentStatistics();
+            String gatewayId = null;
+            String userName = null;
+            String applicationName = null;
+            String resourceHostName = null;
+            Timestamp fromDate = null;
+            Timestamp toDate = null;
+
+            for (String field : filters.keySet()) {
+
+                if (field.equals(DBConstants.Experiment.GATEWAY_ID)) {
 
 Review comment:
   Done.

----------------------------------------------------------------
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 Experiment Catalog Implementation
> ---------------------------------------------
>
>                 Key: AIRAVATA-2728
>                 URL: https://issues.apache.org/jira/browse/AIRAVATA-2728
>             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