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

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_r185103423
 
 

 ##########
 File path: 
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/ExperimentRepository.java
 ##########
 @@ -20,82 +20,413 @@
 */
 package org.apache.airavata.registry.core.repositories.expcatalog;
 
+import org.apache.airavata.model.application.io.InputDataObjectType;
+import org.apache.airavata.model.application.io.OutputDataObjectType;
+import org.apache.airavata.model.commons.ErrorModel;
 import org.apache.airavata.model.experiment.ExperimentModel;
-import org.apache.airavata.registry.core.entities.expcatalog.ExperimentEntity;
-import org.apache.airavata.registry.core.repositories.AbstractRepository;
-import org.apache.airavata.registry.core.utils.JPAUtils;
+import org.apache.airavata.model.experiment.UserConfigurationDataModel;
+import org.apache.airavata.model.status.*;
+import org.apache.airavata.registry.core.entities.expcatalog.*;
+import org.apache.airavata.registry.core.utils.DBConstants;
+import org.apache.airavata.registry.core.utils.ExpCatalogUtils;
 import org.apache.airavata.registry.core.utils.ObjectMapperSingleton;
+import org.apache.airavata.registry.core.utils.QueryConstants;
+import org.apache.airavata.registry.cpi.*;
 import org.dozer.Mapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.List;
+import java.sql.Timestamp;
+import java.util.*;
 
-public class ExperimentRepository extends AbstractRepository<ExperimentModel, 
ExperimentEntity, String> {
+public class ExperimentRepository extends 
ExpCatAbstractRepository<ExperimentModel, ExperimentEntity, String> {
     private final static Logger logger = 
LoggerFactory.getLogger(ExperimentRepository.class);
 
-    public ExperimentRepository(Class<ExperimentModel> thriftGenericClass, 
Class<ExperimentEntity> dbEntityGenericClass) {
-        super(thriftGenericClass, dbEntityGenericClass);
+    public ExperimentRepository() {
+        super(ExperimentModel.class, ExperimentEntity.class);
     }
 
-    @Override
-    public ExperimentModel create(ExperimentModel experiment){
-        return update(experiment);
+    protected String saveExperimentModelData(ExperimentModel experimentModel) 
throws RegistryException {
+        ExperimentEntity experimentEntity = saveExperiment(experimentModel);
+        return experimentEntity.getExperimentId();
     }
 
-    @Override
-    public ExperimentModel update(ExperimentModel experiment){
-        String experimentId = experiment.getExperimentId();
+    protected ExperimentEntity saveExperiment(ExperimentModel experimentModel) 
throws RegistryException {
+        if (experimentModel.getExperimentId() == null || 
experimentModel.getExperimentId().equals("DO_NOT_SET_AT_CLIENTS")) {
+            logger.debug("Setting the Experiment's ExperimentId");
+            
experimentModel.setExperimentId(ExpCatalogUtils.getID(experimentModel.getExperimentName()));
+        }
+
+        String experimentId = experimentModel.getExperimentId();
         Mapper mapper = ObjectMapperSingleton.getInstance();
-        ExperimentEntity entity = mapper.map(experiment, 
ExperimentEntity.class);
-
-        if(entity.getUserConfigurationData() != null) {
-            entity.getUserConfigurationData().setExperimentId(experimentId);
-            if 
(entity.getUserConfigurationData().getComputeResourceSchedulingEntity() != null)
-                
entity.getUserConfigurationData().getComputeResourceSchedulingEntity().setExperimentId(experimentId);
-        }
-        if(entity.getExperimentInputs() != null)
-            
entity.getExperimentInputs().forEach(expIn->expIn.setExperimentId(experimentId));
-        if(entity.getExperimentOutputs() != null)
-            
entity.getExperimentOutputs().forEach(expOut->expOut.setExperimentId(experimentId));
-        if(entity.getExperimentErrors() != null)
-            
entity.getExperimentErrors().forEach(expErr->expErr.setExperimentId(experimentId));
-        if(entity.getExperimentStatuses() != null)
-            
entity.getExperimentStatuses().forEach(expStatus->expStatus.setExperimentId(experimentId));
-
-        if(entity.getProcesses() != null){
-            entity.getProcesses().forEach(process->{
-                process.setExperimentId(experimentId);
-                String processId = process.getProcessId();
-                if(process.getProcessResourceSchedule() != null)
-                    
process.getProcessResourceSchedule().setProcessId(processId);
-                if(process.getProcessInputs() != null)
-                    
process.getProcessInputs().forEach(proInput->proInput.setProceseId(processId));
-                if(process.getProcessOutputs() != null)
-                    
process.getProcessOutputs().forEach(proOutput->proOutput.setProcessId(processId));
-                if(process.getProcessErrors() != null)
-                    
process.getProcessErrors().forEach(processErr->processErr.setProcessId(processId));
-                if(process.getProcessStatuses() != null)
-                    
process.getProcessStatuses().forEach(processStat->processStat.setProcessId(processId));
-
-                if(process.getTasks() != null){
-                    process.getTasks().forEach(task->{
-                        String taskId = task.getTaskId();
-                        task.setParentProcessId(processId);
-
-
-                    });
-                }
-            });
-        }
-
-        ExperimentEntity persistedCopy = JPAUtils.execute(entityManager -> 
entityManager.merge(entity));
-        return mapper.map(persistedCopy, ExperimentModel.class);
-    }
-
-    @Override
-    public List<ExperimentModel> select(String criteria, int offset, int 
limit){
-        throw new UnsupportedOperationException("Due to performance overheads 
this method is not supported. Instead use" +
-                " ExperimentSummaryRepository");
+        ExperimentEntity experimentEntity = mapper.map(experimentModel, 
ExperimentEntity.class);
+
+        if (experimentEntity.getUserConfigurationData() != null) {
+            logger.debug("Populating the Primary Key of UserConfigurationData 
object for the Experiment");
+            
experimentEntity.getUserConfigurationData().setExperimentId(experimentId);
+        }
+
+        if (experimentEntity.getExperimentInputs() != null) {
+            logger.debug("Populating the Primary Key of ExperimentInput 
objects for the Experiment");
+            
experimentEntity.getExperimentInputs().forEach(experimentInputEntity -> 
experimentInputEntity.setExperimentId(experimentId));
+        }
+
+        if (experimentEntity.getExperimentOutputs() != null) {
+            logger.debug("Populating the Primary Key of ExperimentOutput 
objects for the Experiment");
+            
experimentEntity.getExperimentOutputs().forEach(experimentOutputEntity -> 
experimentOutputEntity.setExperimentId(experimentId));
+        }
+
+        if (experimentEntity.getExperimentStatus() != null) {
+            logger.debug("Populating the Primary Key of ExperimentStatus 
objects for the Experiment");
+            
experimentEntity.getExperimentStatus().forEach(experimentStatusEntity -> 
experimentStatusEntity.setExperimentId(experimentId));
+        }
+
+        if (experimentEntity.getErrors() != null) {
+            logger.debug("Populating the Primary Key of ExperimentError 
objects for the Experiment");
+            experimentEntity.getErrors().forEach(experimentErrorEntity -> 
experimentErrorEntity.setExperimentId(experimentId));
+        }
+
+        if (experimentEntity.getProcesses() != null) {
+            logger.debug("Populating the Process objects' Experiment ID for 
the Experiment");
+            experimentEntity.getProcesses().forEach(processEntity -> 
processEntity.setExperimentId(experimentId));
+        }
+
+        if (!isExperimentExist(experimentId)) {
+            logger.debug("Checking if the Experiment already exists");
+            experimentEntity.setCreationTime(new 
Timestamp((System.currentTimeMillis())));
+        }
+
+        return execute(entityManager -> entityManager.merge(experimentEntity));
+    }
+
+    public String addExperiment(ExperimentModel experimentModel) throws 
RegistryException {
+        return saveExperimentModelData(experimentModel);
+    }
+
+    public void updateExperiment(ExperimentModel updatedExperimentModel, 
String experimentId) throws RegistryException {
+        saveExperimentModelData(updatedExperimentModel);
+    }
+
+    public ExperimentModel getExperiment(String experimentId) throws 
RegistryException {
+        return get(experimentId);
+    }
+
+    public String addUserConfigurationData(UserConfigurationDataModel 
userConfigurationDataModel, String experimentId) throws RegistryException {
+        ExperimentModel experimentModel = getExperiment(experimentId);
+        experimentModel.setUserConfigurationData(userConfigurationDataModel);
+        updateExperiment(experimentModel, experimentId);
+        return experimentId;
+    }
+
+    public String updateUserConfigurationData(UserConfigurationDataModel 
updatedUserConfigurationDataModel, String experimentId) throws 
RegistryException {
+        return addUserConfigurationData(updatedUserConfigurationDataModel, 
experimentId);
+    }
+
+    public UserConfigurationDataModel getUserConfigurationData(String 
experimentId) throws RegistryException {
+        ExperimentModel experimentModel = getExperiment(experimentId);
+        return experimentModel.getUserConfigurationData();
+    }
+
+    public String addExperimentInputs(List<InputDataObjectType> 
experimentInputs, String experimentId) throws RegistryException {
+        ExperimentModel experimentModel = getExperiment(experimentId);
+        List<InputDataObjectType> inputDataObjectTypeList = 
experimentModel.getExperimentInputs();
+
+        for (InputDataObjectType input : experimentInputs) {
+
+            if (inputDataObjectTypeList != null && 
!inputDataObjectTypeList.contains(input)) {
+                logger.debug("Adding the ExperimentInput to the list");
+                inputDataObjectTypeList.add(input);
+                experimentModel.setExperimentInputs(inputDataObjectTypeList);
+                updateExperiment(experimentModel, experimentId);
+            }
+
+        }
+
+        return experimentId;
+    }
+
+    public void updateExperimentInputs(List<InputDataObjectType> 
updatedExperimentInputs, String experimentId) throws RegistryException {
+        addExperimentInputs(updatedExperimentInputs, experimentId);
 
 Review comment:
   ```addExperimentInputs``` also calls ```updateExperiment``` which would then 
update the experiment inputs.

----------------------------------------------------------------
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