airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scnakand...@apache.org
Subject [24/44] airavata git commit: Mongo Registry WIP
Date Sun, 07 Jun 2015 17:01:05 GMT
Mongo Registry WIP


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/945161ea
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/945161ea
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/945161ea

Branch: refs/heads/mongo-registry
Commit: 945161ea138dc9576f8f2bc6ce7452cc386821b0
Parents: 847f2d9
Author: Supun Nakandala <scnakandala@apache.org>
Authored: Wed May 27 23:15:35 2015 +0530
Committer: Supun Nakandala <scnakandala@apache.org>
Committed: Wed May 27 23:15:35 2015 +0530

----------------------------------------------------------------------
 .../registry/jpa/impl/ExperimentRegistry.java   | 230 ++++---------------
 .../registry/jpa/impl/ProjectRegistry.java      | 148 +++---------
 .../persistance/registry/jpa/mongo/Test.java    |   2 -
 .../registry/jpa/mongo/dao/ExperimentDao.java   |  76 ++++--
 .../registry/jpa/mongo/dao/ProjectDao.java      | 189 +++++++++++++++
 .../registry/mongo/ExperimentDaoTest.java       |  30 ++-
 6 files changed, 338 insertions(+), 337 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/945161ea/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
index e7791fa..e6f7c4c 100644
--- a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
+++ b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
@@ -23,7 +23,6 @@ package org.apache.airavata.persistance.registry.jpa.impl;
 
 import org.apache.airavata.common.logger.AiravataLogger;
 import org.apache.airavata.common.logger.AiravataLoggerFactory;
-import org.apache.airavata.common.utils.AiravataUtils;
 import org.apache.airavata.model.appcatalog.appinterface.OutputDataObjectType;
 import org.apache.airavata.model.workspace.experiment.*;
 import org.apache.airavata.persistance.registry.jpa.ResourceType;
@@ -37,7 +36,6 @@ import org.apache.airavata.registry.cpi.RegistryModelType;
 import org.apache.airavata.registry.cpi.ResultOrderType;
 import org.apache.airavata.registry.cpi.utils.Constants;
 
-import java.sql.Timestamp;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -253,7 +251,7 @@ public class ExperimentRegistry {
         try {
             TaskDetails taskDetails = experimentDao.getTaskDetail((String) ids.getTopLevelIdentifier());
             for (JobDetails jobDetails : taskDetails.getJobDetailsList()) {
-                if (jobDetails.getJobId().equals((String) ids.getSecondLevelIdentifier())) {
+                if (jobDetails.getJobId().equals(ids.getSecondLevelIdentifier())) {
                     jobDetails.setApplicationStatus(status);
                     experimentDao.updateTaskDetail(taskDetails);
                     return;
@@ -512,94 +510,26 @@ public class ExperimentRegistry {
         }
     }
 
-    //Todo
     public String addErrorDetails(ErrorDetails error, Object id) throws RegistryException {
         try {
-            ErrorDetailResource errorResource = null;
-            ExperimentResource experiment;
-            TaskDetailResource taskDetail;
-            WorkflowNodeDetailResource workflowNode;
-            // figure out the id is an experiment, node task or job
-            if (id instanceof String) {
-                // FIXME : for .12 we only saveExperiment task related errors
-//                if (isExperimentExist((String) id)) {
-//                    experiment = gatewayResource.getExperiment((String) id);
-//                    errorResource = (ErrorDetailResource) experiment.create(ResourceType.ERROR_DETAIL);
-//                } else if (isWFNodeExist((String) id)) {
-//                    experiment = (ExperimentResource) gatewayResource.create(ResourceType.EXPERIMENT);
-//                    workflowNode = experiment.getWorkflowNode((String) id);
-//                    errorResource = (ErrorDetailResource) workflowNode.create(ResourceType.ERROR_DETAIL);
-//                    errorResource.setExperimentResource(workflowNode.getExperimentResource());
-//                } else
-                if (isTaskDetailExist((String) id)) {
-                    experiment = (ExperimentResource) gatewayResource.create(ResourceType.EXPERIMENT);
-                    workflowNode = (WorkflowNodeDetailResource) experiment.create(ResourceType.WORKFLOW_NODE_DETAIL);
-                    taskDetail = workflowNode.getTaskDetail((String) id);
-                    errorResource = (ErrorDetailResource) taskDetail.create(ResourceType.ERROR_DETAIL);
-                    if (error.getErrorId() != null && !error.getErrorId().equals(experimentModelConstants.DEFAULT_ID)) {
-                        List<ErrorDetailResource> errorDetailList = taskDetail.getErrorDetailList();
-                        if (errorDetailList != null && !errorDetailList.isEmpty()) {
-                            for (ErrorDetailResource errorDetailResource : errorDetailList) {
-                                if (errorDetailResource.getErrorId() == Integer.parseInt(error.getErrorId())) {
-                                    errorResource = errorDetailResource;
-                                }
-                            }
-                        }
-                    }
-                    errorResource.setTaskDetailResource(taskDetail);
-                    errorResource.setNodeDetail(taskDetail.getWorkflowNodeDetailResource());
-                    errorResource.setExperimentResource(taskDetail.getWorkflowNodeDetailResource().getExperimentResource());
-                } else {
-//                    logger.error("The id provided is not an experiment id or a workflow id or a task id..");
-                }
+            // FIXME : for .12 we only saveExperiment task related errors
+            if(id instanceof String){
+                TaskDetails taskDetails = experimentDao.getTaskDetail((String) id);
+                taskDetails.getErrors().add(error);
+                experimentDao.updateTaskDetail(taskDetails);
+                return (String) id;
             } else if (id instanceof CompositeIdentifier) {
                 CompositeIdentifier cid = (CompositeIdentifier) id;
-                if (isJobDetailExist(cid)) {
-                    experiment = (ExperimentResource) gatewayResource.create(ResourceType.EXPERIMENT);
-                    workflowNode = (WorkflowNodeDetailResource) experiment.create(ResourceType.WORKFLOW_NODE_DETAIL);
-                    taskDetail = workflowNode.getTaskDetail((String) cid.getTopLevelIdentifier());
-                    JobDetailResource jobDetail = taskDetail.getJobDetail((String) cid.getSecondLevelIdentifier());
-                    errorResource = (ErrorDetailResource) jobDetail.create(ResourceType.ERROR_DETAIL);
-                    if (error.getErrorId() != null && !error.getErrorId().equals(experimentModelConstants.DEFAULT_ID)) {
-                        List<ErrorDetailResource> errorDetailList = taskDetail.getErrorDetailList();
-                        if (errorDetailList != null && !errorDetailList.isEmpty()) {
-                            for (ErrorDetailResource errorDetailResource : errorDetailList) {
-                                if (errorDetailResource.getErrorId() == Integer.parseInt(error.getErrorId())) {
-                                    errorResource = errorDetailResource;
-                                }
-                            }
-                        }
+                TaskDetails taskDetails = experimentDao.getTaskDetail((String) cid.getTopLevelIdentifier());
+                for(JobDetails jobDetails: taskDetails.getJobDetailsList()){
+                    if(jobDetails.getJobId().equals(cid.getSecondLevelIdentifier())){
+                        jobDetails.getErrors().add(error);
+                        experimentDao.updateTaskDetail(taskDetails);
+                        return (String) cid.getSecondLevelIdentifier();
                     }
-                    errorResource.setTaskDetailResource(taskDetail);
-                    errorResource.setNodeDetail(taskDetail.getWorkflowNodeDetailResource());
-                    errorResource.setExperimentResource(taskDetail.getWorkflowNodeDetailResource().getExperimentResource());
-                } else {
-                    logger.error("The id provided is not a job in the system..");
                 }
             } else {
-//                logger.error("The id provided is not an experiment id or a workflow id or a task id or a composite " +
-//                        "identifier for job..");
-            }
-            if (errorResource != null) {
-                errorResource.setCreationTime(AiravataUtils.getTime(error.getCreationTime()));
-                errorResource.setActualErrorMsg(error.getActualErrorMessage());
-                errorResource.setUserFriendlyErrorMsg(error.getUserFriendlyMessage());
-                if (error.getErrorCategory() != null) {
-                    errorResource.setErrorCategory(error.getErrorCategory().toString());
-                }
-                errorResource.setTransientPersistent(error.isTransientOrPersistent());
-                if (error.getCorrectiveAction() != null) {
-                    errorResource.setCorrectiveAction(error.getCorrectiveAction().toString());
-                } else {
-                    errorResource.setCorrectiveAction(CorrectiveAction.CONTACT_SUPPORT.toString());
-                }
-                if (error.getActionableGroup() != null) {
-                    errorResource.setActionableGroup(error.getActionableGroup().toString());
-                } else {
-                    errorResource.setActionableGroup(ActionableGroup.GATEWAYS_ADMINS.toString());
-                }
-                errorResource.save();
-                return String.valueOf(errorResource.getErrorId());
+                logger.error("Unsupported data type...");
             }
         } catch (Exception e) {
             logger.error("Unable to add error details...", e);
@@ -729,7 +659,6 @@ public class ExperimentRegistry {
         }
     }
 
-    //Todo
     /**
      * Method to getExperiment matching experiment list
      *
@@ -739,58 +668,9 @@ public class ExperimentRegistry {
      * @throws RegistryException
      */
     public List<Experiment> getExperimentList(String fieldName, Object value) throws RegistryException {
-        List<Experiment> experiments = new ArrayList();
-        try {
-            if (fieldName.equals(Constants.FieldConstants.ExperimentConstants.USER_NAME)) {
-                WorkerResource resource = (WorkerResource) gatewayResource.create(ResourceType.GATEWAY_WORKER);
-                resource.setUser((String) value);
-                List<ExperimentResource> resources = resource.getExperiments();
-                for (ExperimentResource experimentResource : resources) {
-                    Experiment experiment = ThriftDataModelConversion.getExperiment(experimentResource);
-                    experiments.add(experiment);
-                }
-                return experiments;
-            } else if (fieldName.equals(Constants.FieldConstants.ExperimentConstants.PROJECT_ID)) {
-                ProjectResource project = workerResource.getProject((String) value);
-                List<ExperimentResource> resources = project.getExperiments();
-                for (ExperimentResource resource : resources) {
-                    Experiment experiment = ThriftDataModelConversion.getExperiment(resource);
-                    experiments.add(experiment);
-                }
-                return experiments;
-            } else if (fieldName.equals(Constants.FieldConstants.ExperimentConstants.GATEWAY)) {
-                List<ExperimentResource> resources = gatewayResource.getExperiments();
-                for (ExperimentResource resource : resources) {
-                    Experiment experiment = ThriftDataModelConversion.getExperiment(resource);
-                    experiments.add(experiment);
-                }
-                return experiments;
-            }
-            if (fieldName.equals(Constants.FieldConstants.ExperimentConstants.WORKFLOW_NODE_LIST)) {
-                if (value instanceof List<?>) {
-                    return getExperimentList(fieldName, ((List<?>) value).get(0));
-                } else if (value instanceof WorkflowNodeDetails) {
-                    //WorkflowNodeDetailResource nodeDetailResource = getWorkflowNodeDetailResource(((WorkflowNodeDetails) value).getNodeInstanceId());
-//                    if (nodeDetailResource != null) {
-//                        return Arrays.asList(new Experiment[]{ThriftDataModelConversion
-//                                .getExperiment(nodeDetailResource
-//                                        .getExperimentResource())});
-//                    }
-                } else {
-                    logger.error("Unsupported field value to retrieve workflow node detail list...");
-                }
-
-            } else {
-                logger.error("Unsupported field name to retrieve experiment list...");
-            }
-        } catch (Exception e) {
-            logger.error("Error while getting experiment list...", e);
-            throw new RegistryException(e);
-        }
-        return experiments;
+        return getExperimentList(fieldName, value, -1, -1, null, null);
     }
 
-    //Todo
     /**
      * Method to getExperiment matching experiment list with pagination and ordering
      *
@@ -806,28 +686,32 @@ public class ExperimentRegistry {
     public List<Experiment> getExperimentList(String fieldName, Object value, int limit, int offset,
                                               Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
         List<Experiment> experiments = new ArrayList();
+        Map<String, String> filters = new HashMap();
         try {
             if (fieldName.equals(Constants.FieldConstants.ExperimentConstants.USER_NAME)) {
-                WorkerResource resource = (WorkerResource) gatewayResource.create(ResourceType.GATEWAY_WORKER);
-                resource.setUser((String) value);
-                List<ExperimentResource> resources = resource.getExperiments(limit, offset,
-                        orderByIdentifier, resultOrderType);
-                for (ExperimentResource experimentResource : resources) {
-                    Experiment experiment = ThriftDataModelConversion.getExperiment(experimentResource);
-                    experiments.add(experiment);
-                }
-                return experiments;
+                filters.put(fieldName, (String)value);
+                return experimentDao.searchExperiments(filters, limit, offset, orderByIdentifier, resultOrderType);
             } else if (fieldName.equals(Constants.FieldConstants.ExperimentConstants.PROJECT_ID)) {
-                ProjectResource project = workerResource.getProject((String) value);
-                List<ExperimentResource> resources = project.getExperiments(limit, offset,
-                        Constants.FieldConstants.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
-                for (ExperimentResource resource : resources) {
-                    Experiment experiment = ThriftDataModelConversion.getExperiment(resource);
-                    experiments.add(experiment);
+                filters.put(fieldName, (String)value);
+                return experimentDao.searchExperiments(filters, limit, offset, orderByIdentifier, resultOrderType);
+            } else if (fieldName.equals(Constants.FieldConstants.ExperimentConstants.GATEWAY)) {
+                filters.put(fieldName, (String)value);
+                return experimentDao.searchExperiments(filters, limit, offset, orderByIdentifier, resultOrderType);
+            } else if (fieldName.equals(Constants.FieldConstants.ExperimentConstants.WORKFLOW_NODE_LIST)) {
+                if (value instanceof List<?>) {
+                    return getExperimentList(fieldName, ((List<?>) value).get(0));
+                } else if (value instanceof WorkflowNodeDetails) {
+                    List<Experiment> experimentList = new ArrayList();
+                    experimentList.add(experimentDao.getParentExperimentOfWFNode(
+                            ((WorkflowNodeDetails)value).getNodeInstanceId())
+                    );
+                } else {
+                    logger.error("Unsupported field value to retrieve workflow node detail list...");
                 }
-                return experiments;
+
+            } else {
+                logger.error("Unsupported field name to retrieve experiment list...");
             }
-            logger.error("Unsupported field name to retrieve experiment list...");
         } catch (Exception e) {
             logger.error("Error while getting experiment list...", e);
             throw new RegistryException(e);
@@ -846,13 +730,9 @@ public class ExperimentRegistry {
                 if (value instanceof List<?>) {
                     return getWFNodeDetails(fieldName, ((List<?>) value).get(0));
                 } else if (value instanceof TaskDetails) {
-                    //Fixme
-//                    TaskDetailResource taskDetailResource = getTaskDetailResource(((TaskDetails) value).getTaskId());
-//                    if (taskDetailResource != null) {
-//                        return Arrays.asList(new WorkflowNodeDetails[]{ThriftDataModelConversion
-//                                .getWorkflowNodeDetails(taskDetailResource
-//                                        .getWorkflowNodeDetailResource())});
-//                    }
+                    List<WorkflowNodeDetails> workflowNodeDetailsList = new ArrayList();
+                    workflowNodeDetailsList.add(experimentDao.getParentWFNodeOfTask(((TaskDetails)value).getTaskId()));
+                    return workflowNodeDetailsList;
                 } else {
                     logger.error("Unsupported field value to retrieve workflow node detail list...");
                 }
@@ -1269,27 +1149,14 @@ public class ExperimentRegistry {
         }
     }
 
-    //Todo
     public List<String> getExperimentIds(String fieldName, Object value) throws RegistryException {
         List<String> expIDs = new ArrayList();
         try {
-            if (fieldName.equals(Constants.FieldConstants.ExperimentConstants.GATEWAY)) {
-                if (gatewayResource == null) {
-                    logger.error("You should use an existing gateway in order to retrieve experiments..");
-                    return null;
-                } else {
-                    List<ExperimentResource> resources = gatewayResource.getExperiments();
-                    for (ExperimentResource resource : resources) {
-                        String expID = resource.getExpID();
-                        expIDs.add(expID);
-                    }
-                }
-            } else if (fieldName.equals(Constants.FieldConstants.ExperimentConstants.USER_NAME)) {
-                List<ExperimentResource> resources = workerResource.getExperiments();
-                expIDs.addAll(resources.stream().map(ExperimentResource::getExpID).collect(Collectors.toList()));
-            } else if (fieldName.equals(Constants.FieldConstants.ExperimentConstants.PROJECT_ID)) {
-                List<ExperimentResource> resources = workerResource.getExperiments();
-                expIDs.addAll(resources.stream().map(ExperimentResource::getExpID).collect(Collectors.toList()));
+            if (fieldName.equals(Constants.FieldConstants.ExperimentConstants.GATEWAY)
+                        || fieldName.equals(Constants.FieldConstants.ExperimentConstants.USER_NAME)
+                        || fieldName.equals(Constants.FieldConstants.ExperimentConstants.PROJECT_ID)) {
+                getExperimentList(fieldName, value).stream().forEach(ex->expIDs.add(ex.getExperimentId()));
+                return expIDs;
             }
         } catch (Exception e) {
             logger.error("Error while retrieving experiment ids..", e);
@@ -1326,7 +1193,6 @@ public class ExperimentRegistry {
         return transferIds;
     }
 
-
     public void removeExperiment(String experimentId) throws RegistryException {
         try {
             Experiment experiment = new Experiment();
@@ -1721,10 +1587,14 @@ public class ExperimentRegistry {
         experimentList.stream().forEach(experiment->{
             ExperimentSummary expSummary = new ExperimentSummary();
             expSummary.setExperimentId(experiment.getExperimentId());
+            expSummary.setProjectId(experiment.getProjectId());
             expSummary.setName(experiment.getName());
             expSummary.setDescription(experiment.getDescription());
+            expSummary.setUserName(experiment.getUserName());
             expSummary.setCreationTime(experiment.getCreationTime());
-            //Todo
+            expSummary.setApplicationId(experiment.getApplicationId());
+            expSummary.setExperimentStatus(experiment.getExperimentStatus());
+            expSummary.setErrors(experiment.getErrors());
             experimentSummaries.add(expSummary);
         });
         return experimentSummaries;
@@ -1770,4 +1640,4 @@ public class ExperimentRegistry {
                 return false;
         }
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/945161ea/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ProjectRegistry.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ProjectRegistry.java b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ProjectRegistry.java
index 928fe64..620c535 100644
--- a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ProjectRegistry.java
+++ b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ProjectRegistry.java
@@ -21,12 +21,13 @@
 
 package org.apache.airavata.persistance.registry.jpa.impl;
 
-import org.apache.airavata.common.utils.AiravataUtils;
 import org.apache.airavata.model.workspace.Project;
 import org.apache.airavata.persistance.registry.jpa.ResourceType;
 import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
-import org.apache.airavata.persistance.registry.jpa.resources.*;
-import org.apache.airavata.persistance.registry.jpa.utils.ThriftDataModelConversion;
+import org.apache.airavata.persistance.registry.jpa.mongo.dao.ProjectDao;
+import org.apache.airavata.persistance.registry.jpa.resources.GatewayResource;
+import org.apache.airavata.persistance.registry.jpa.resources.UserResource;
+import org.apache.airavata.persistance.registry.jpa.resources.WorkerResource;
 import org.apache.airavata.registry.cpi.RegistryException;
 import org.apache.airavata.registry.cpi.ResultOrderType;
 import org.apache.airavata.registry.cpi.utils.Constants;
@@ -40,7 +41,11 @@ public class ProjectRegistry {
     private WorkerResource workerResource;
     private final static Logger logger = LoggerFactory.getLogger(ProjectRegistry.class);
 
+    private ProjectDao projectDao;
+
     public ProjectRegistry(GatewayResource gatewayResource, UserResource user) throws RegistryException {
+        this.projectDao = new ProjectDao();
+
         if (!ResourceUtils.isGatewayExist(gatewayResource.getGatewayId())){
             this.gatewayResource = gatewayResource;
         }else {
@@ -55,50 +60,17 @@ public class ProjectRegistry {
     }
 
     public String addProject (Project project, String gatewayId) throws RegistryException{
-        String projectId;
         try {
             if (!ResourceUtils.isUserExist(project.getOwner())){
                 ResourceUtils.addUser(project.getOwner(), null);
             }
-            ProjectResource projectResource = new ProjectResource();
-            projectId = getProjectId(project.getName());
-            projectResource.setId(projectId);
-            project.setProjectId(projectId);
-            projectResource.setName(project.getName());
-            projectResource.setDescription(project.getDescription());
-            projectResource.setCreationTime(AiravataUtils.getTime(project.getCreationTime()));
-            GatewayResource gateway = (GatewayResource)ResourceUtils.getGateway(gatewayId);
-            projectResource.setGateway(gateway);
-            WorkerResource worker = new WorkerResource(project.getOwner(), workerResource.getGateway());
-            projectResource.setWorker(worker);
-            projectResource.save();
-            ProjectUserResource resource = (ProjectUserResource)projectResource.create(
-                    ResourceType.PROJECT_USER);
-            resource.setProjectId(project.getProjectId());
-            resource.setUserName(project.getOwner());
-            resource.save();
-            List<String> sharedGroups = project.getSharedGroups();
-            if (sharedGroups != null && !sharedGroups.isEmpty()){
-                for (String group : sharedGroups){
-                    //TODO - add shared groups
-                    logger.info("Groups are not supported at the moment...");
-                }
-            }
-
-            List<String> sharedUsers = project.getSharedUsers();
-            if (sharedUsers != null && !sharedUsers.isEmpty()){
-                for (String username : sharedUsers){
-                    ProjectUserResource pr = (ProjectUserResource)projectResource.
-                            create(ResourceType.PROJECT_USER);
-                    pr.setUserName(username);
-                    pr.save();
-                }
-            }
+            project.setProjectId(getProjectId(project.getName()));
+            projectDao.createProject(project);
+            return project.getProjectId();
         }catch (Exception e){
             logger.error("Error while saving project to registry", e);
            throw new RegistryException(e);
         }
-        return projectId;
     }
 
     private String getProjectId (String projectName){
@@ -108,11 +80,6 @@ public class ProjectRegistry {
 
     public void updateProject (Project project, String projectId) throws RegistryException{
         try {
-            ProjectResource existingProject = workerResource.getProject(projectId);
-            existingProject.setDescription(project.getDescription());
-            existingProject.setName(project.getName());
-            existingProject.setCreationTime(AiravataUtils.getTime(project.getCreationTime()));
-//            existingProject.setGateway(gatewayResource);
             UserResource user = (UserResource)ResourceUtils.getUser(project.getOwner());
             if (!gatewayResource.isExists(ResourceType.GATEWAY_WORKER, user.getUserName())){
                 workerResource = ResourceUtils.addGatewayWorker(gatewayResource, user);
@@ -120,31 +87,7 @@ public class ProjectRegistry {
                 workerResource = (WorkerResource)ResourceUtils.getWorker(
                         gatewayResource.getGatewayName(), user.getUserName());
             }
-            WorkerResource worker = new WorkerResource(project.getOwner(), gatewayResource);
-            existingProject.setWorker(worker);
-            existingProject.save();
-            ProjectUserResource resource = (ProjectUserResource)existingProject.create(
-                    ResourceType.PROJECT_USER);
-            resource.setProjectId(projectId);
-            resource.setUserName(project.getOwner());
-            resource.save();
-            List<String> sharedGroups = project.getSharedGroups();
-            if (sharedGroups != null && !sharedGroups.isEmpty()){
-                for (String group : sharedGroups){
-                    //TODO - add shared groups
-                    logger.info("Groups are not supported at the moment...");
-                }
-            }
-
-            List<String> sharedUsers = project.getSharedUsers();
-            if (sharedUsers != null && !sharedUsers.isEmpty()){
-                for (String username : sharedUsers){
-                    ProjectUserResource pr = (ProjectUserResource)existingProject.create(
-                            ResourceType.PROJECT_USER);
-                    pr.setUserName(username);
-                    pr.save();
-                }
-            }
+            projectDao.updateProject(project);
         }catch (Exception e){
             logger.error("Error while saving project to registry", e);
            throw new RegistryException(e);
@@ -153,15 +96,11 @@ public class ProjectRegistry {
 
     public Project getProject (String projectId) throws RegistryException{
         try {
-            ProjectResource project = workerResource.getProject(projectId);
-            if (project != null){
-                return ThriftDataModelConversion.getProject(project);
-            }
+            return projectDao.getProject(projectId);
         }catch (Exception e){
             logger.error("Error while retrieving project from registry", e);
            throw new RegistryException(e);
         }
-        return null;
     }
 
     /**
@@ -188,23 +127,14 @@ public class ProjectRegistry {
      */
     public List<Project> getProjectList (String fieldName, Object value, int limit, int offset,
                                          Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException{
-        List<Project> projects = new ArrayList<Project>();
         try {
-            if (fieldName.equals(Constants.FieldConstants.ProjectConstants.OWNER)){
-                workerResource.setUser((String)value);
-                List<ProjectResource> projectList = workerResource.getProjects();
-                if (projectList != null && !projectList.isEmpty()){
-                    for (ProjectResource pr : projectList){
-                        projects.add(ThriftDataModelConversion.getProject(pr));
-                    }
-                }
-                return projects;
-            }
+                Map<String, String> filters = new HashMap();
+                filters.put(fieldName, (String)value);
+                return  projectDao.searchProjects(filters, limit, offset, orderByIdentifier, resultOrderType);
         }catch (Exception e){
             logger.error("Error while retrieving project from registry", e);
             throw new RegistryException(e);
         }
-        return projects;
     }
 
     /**
@@ -233,48 +163,23 @@ public class ProjectRegistry {
      */
     public List<Project> searchProjects(Map<String, String> filters, int limit,
             int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
-        Map<String, String> fil = new HashMap<String, String>();
-        if (filters != null && filters.size() != 0){
-            List<Project> projects = new ArrayList<Project>();
-            try {
-                for (String field : filters.keySet()){
-                    if (field.equals(Constants.FieldConstants.ProjectConstants.PROJECT_NAME)){
-                        fil.put(AbstractResource.ProjectConstants.PROJECT_NAME, filters.get(field));
-                    }else if (field.equals(Constants.FieldConstants.ProjectConstants.OWNER)){
-                        fil.put(AbstractResource.ProjectConstants.USERNAME, filters.get(field));
-                    }else if (field.equals(Constants.FieldConstants.ProjectConstants.DESCRIPTION)){
-                        fil.put(AbstractResource.ProjectConstants.DESCRIPTION, filters.get(field));
-                    }else if (field.equals(Constants.FieldConstants.ProjectConstants.GATEWAY_ID)){
-                        fil.put(AbstractResource.ProjectConstants.GATEWAY_ID, filters.get(field));
-                    }
-                }
-                List<ProjectResource> projectResources = workerResource
-                        .searchProjects(fil, limit, offset, orderByIdentifier, resultOrderType);
-                if (projectResources != null && !projectResources.isEmpty()){
-                    for (ProjectResource pr : projectResources){
-                        projects.add(ThriftDataModelConversion.getProject(pr));
-                    }
-                }
-                return projects;
+          try {
+                return  projectDao.searchProjects(filters, limit, offset, orderByIdentifier, resultOrderType);
             }catch (Exception e){
                 logger.error("Error while retrieving project from registry", e);
                 throw new RegistryException(e);
             }
-        }
-        return null;
+
     }
 
     public List<String> getProjectIds (String fieldName, Object value) throws RegistryException{
         List<String> projectIds = new ArrayList<String>();
         try {
             if (fieldName.equals(Constants.FieldConstants.ProjectConstants.OWNER)){
-                workerResource.setUser((String)value);
-                List<ProjectResource> projectList = workerResource.getProjects();
-                if (projectList != null && !projectList.isEmpty()){
-                    for (ProjectResource pr : projectList){
-                        projectIds.add(pr.getName());
-                    }
-                }
+                Map<String, String> filters = new HashMap();
+                filters.put(fieldName, (String)value);
+                projectDao.searchProjects(filters, -1, -1, null, null).stream()
+                .forEach(pr->projectIds.add(pr.getProjectId()));
                 return projectIds;
             }
         }catch (Exception e){
@@ -286,7 +191,9 @@ public class ProjectRegistry {
 
     public void removeProject (String projectId) throws RegistryException {
         try {
-            workerResource.removeProject(projectId);
+            Project project = new Project();
+            project.setProjectId(projectId);
+            projectDao.deleteProject(project);
         } catch (Exception e) {
             logger.error("Error while removing the project..", e);
            throw new RegistryException(e);
@@ -295,11 +202,10 @@ public class ProjectRegistry {
 
     public boolean isProjectExist(String projectId) throws RegistryException {
         try {
-            return workerResource.isProjectExists(projectId);
+            return projectDao.getProject(projectId) != null;
         } catch (Exception e) {
             logger.error("Error while retrieving project...", e);
            throw new RegistryException(e);
         }
     }
-
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/945161ea/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/mongo/Test.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/mongo/Test.java b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/mongo/Test.java
index 4f0dcca..4e04940 100644
--- a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/mongo/Test.java
+++ b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/mongo/Test.java
@@ -20,7 +20,6 @@
 */
 package org.apache.airavata.persistance.registry.jpa.mongo;
 
-import org.apache.airavata.common.utils.AiravataUtils;
 import org.apache.airavata.model.workspace.experiment.Experiment;
 import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory;
 import org.apache.airavata.persistance.registry.jpa.mongo.dao.ExperimentDao;
@@ -40,7 +39,6 @@ public class Test {
     private final static Logger logger = LoggerFactory.getLogger(Test.class);
 
     public static void main(String[] args) throws RegistryException, IOException {
-        AiravataUtils.setExecutionAsServer();
         Registry registry = RegistryFactory.getDefaultRegistry();
 //        String experiemtnId = "SLM-Espresso-Stampede_45667ea8-aae3-4a8e-807d-a16312035c35";
 //        long time1 = System.currentTimeMillis();

http://git-wip-us.apache.org/repos/asf/airavata/blob/945161ea/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/mongo/dao/ExperimentDao.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/mongo/dao/ExperimentDao.java b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/mongo/dao/ExperimentDao.java
index 85375ed..af15716 100644
--- a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/mongo/dao/ExperimentDao.java
+++ b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/mongo/dao/ExperimentDao.java
@@ -47,14 +47,15 @@ public class ExperimentDao{
     private ModelConversionHelper modelConversionHelper;
 
     private static final String EXPERIMENT_ID = "experiment_id";
-    private static final String EXPERIMENT_NAME= "experiment_name";
-    private static final String EXPERIMENT_DESCRIPTION = "experiment_description";
+    private static final String EXPERIMENT_NAME= "name";
+    private static final String EXPERIMENT_DESCRIPTION = "description";
     private static final String USER_NAME = "user_name";
     private static final String GATEWAY = "gateway_execution_id";
     private static final String APPLICATION_ID = "application_id";
     private static final String EXPERIMENT_STATUS_STATE = "experiment_status.experiment_state";
     private static final String CREATION_TIME = "creation_time";
 
+    //Todo Nested Indexes - Its good if we can get rid of them
     private static final String WORKFLOW_NODE_ID = "workflow_node_details_list.node_instance_id";
     private static final String TASK_ID = "workflow_node_details_list.task_details_list.task_id";
 
@@ -62,7 +63,7 @@ public class ExperimentDao{
     public ExperimentDao(){
         collection = MongoUtil.getAiravataRegistry().getCollection(EXPERIMENTS_COLLECTION_NAME);
         modelConversionHelper = new ModelConversionHelper();
-        //collection.dropIndexes();
+        collection.dropIndexes();
         initIndexes();
     }
 
@@ -74,11 +75,11 @@ public class ExperimentDao{
         collection.createIndex(new BasicDBObject(WORKFLOW_NODE_ID, 1));
         collection.createIndex(new BasicDBObject(TASK_ID, 1));
 
-        //Defining a full-text index on experiment name and experiment description
-        BasicDBObject object = new BasicDBObject();
-        object.put(EXPERIMENT_NAME, "text");
-        object.put(EXPERIMENT_DESCRIPTION, "text");
-        collection.createIndex (object);
+//        //Defining a full-text index on experiment name and experiment description
+//        BasicDBObject object = new BasicDBObject();
+//        object.put(EXPERIMENT_NAME, "text");
+//        object.put(EXPERIMENT_DESCRIPTION, "text");
+//        collection.createIndex (object);
     }
 
     public List<Experiment> getAllExperiments() throws RegistryException{
@@ -153,15 +154,15 @@ public class ExperimentDao{
         BasicDBObjectBuilder queryBuilder = BasicDBObjectBuilder.start();
         for (String field : filters.keySet()) {
             if (field.equals(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_NAME)) {
-                //Fixme This is expensive operation
-                queryBuilder.add(EXPERIMENT_NAME, "/.*" + filters.get(field) + "/.*");
+                queryBuilder.add(EXPERIMENT_NAME, new BasicDBObject(
+                        "$regex", ".*" + filters.get(field) + ".*"));
             } else if (field.equals(Constants.FieldConstants.ExperimentConstants.USER_NAME)) {
                 queryBuilder.add(USER_NAME, filters.get(field));
             } else if (field.equals(Constants.FieldConstants.ExperimentConstants.GATEWAY)) {
                 queryBuilder.add(GATEWAY, filters.get(field));
             } else if (field.equals(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_DESC)) {
-                //Fixme This is expensive operation
-                queryBuilder.add(EXPERIMENT_DESCRIPTION, "/.*" + filters.get(field) + "/.*");
+                queryBuilder.add(EXPERIMENT_DESCRIPTION, new BasicDBObject(
+                        "$regex", ".*" + filters.get(field) + ".*"));
             } else if (field.equals(Constants.FieldConstants.ExperimentConstants.APPLICATION_ID)) {
                 queryBuilder.add(APPLICATION_ID, filters.get(field));
             } else if (field.equals(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_STATUS)) {
@@ -218,7 +219,7 @@ public class ExperimentDao{
     }
 
     public void updateWFNode(WorkflowNodeDetails workflowNodeDetail) throws RegistryException{
-        Experiment experiment = getExperimentOfWFNode(workflowNodeDetail.getNodeInstanceId());
+        Experiment experiment = getParentExperimentOfWFNode(workflowNodeDetail.getNodeInstanceId());
         for(WorkflowNodeDetails wfnd: experiment.getWorkflowNodeDetailsList()){
             if(wfnd.getNodeInstanceId().equals(workflowNodeDetail.getNodeInstanceId())){
                 experiment.getWorkflowNodeDetailsList().remove(wfnd);
@@ -230,7 +231,7 @@ public class ExperimentDao{
     }
 
     public void deleteWFNode(WorkflowNodeDetails workflowNodeDetail) throws RegistryException{
-        Experiment experiment = getExperimentOfWFNode(workflowNodeDetail.getNodeInstanceId());
+        Experiment experiment = getParentExperimentOfWFNode(workflowNodeDetail.getNodeInstanceId());
         for(WorkflowNodeDetails wfnd: experiment.getWorkflowNodeDetailsList()){
             if(wfnd.getNodeInstanceId().equals(workflowNodeDetail.getNodeInstanceId())){
                 experiment.getWorkflowNodeDetailsList().remove(wfnd);
@@ -241,7 +242,7 @@ public class ExperimentDao{
     }
 
     public WorkflowNodeDetails getWFNode(String nodeId) throws RegistryException{
-        Experiment experiment = getExperimentOfWFNode(nodeId);
+        Experiment experiment = getParentExperimentOfWFNode(nodeId);
         for(WorkflowNodeDetails wfnd: experiment.getWorkflowNodeDetailsList()){
             if(wfnd.getNodeInstanceId().equals(nodeId)){
                 return wfnd;
@@ -250,9 +251,8 @@ public class ExperimentDao{
         return null;
     }
 
-
     public void createTaskDetail(String nodeId, TaskDetails taskDetail) throws RegistryException{
-        Experiment experiment = getExperimentOfWFNode(nodeId);
+        Experiment experiment = getParentExperimentOfWFNode(nodeId);
         for(WorkflowNodeDetails wfnd: experiment.getWorkflowNodeDetailsList()){
             if(wfnd.getNodeInstanceId().equals(nodeId)){
                 wfnd.getTaskDetailsList().add(taskDetail);
@@ -263,7 +263,7 @@ public class ExperimentDao{
     }
 
     public void updateTaskDetail(TaskDetails taskDetail) throws RegistryException{
-        Experiment experiment = getExperimentOfTask(taskDetail.getTaskId());
+        Experiment experiment = getParentExperimentOfTask(taskDetail.getTaskId());
         for(WorkflowNodeDetails wfnd: experiment.getWorkflowNodeDetailsList()){
             for(TaskDetails taskDetails: wfnd.getTaskDetailsList()){
                 if(taskDetails.getTaskId().equals(taskDetail)){
@@ -277,7 +277,7 @@ public class ExperimentDao{
     }
 
     public void deleteTaskDetail(TaskDetails taskDetail) throws RegistryException{
-        Experiment experiment = getExperimentOfTask(taskDetail.getTaskId());
+        Experiment experiment = getParentExperimentOfTask(taskDetail.getTaskId());
         for(WorkflowNodeDetails wfnd: experiment.getWorkflowNodeDetailsList()){
             for(TaskDetails taskDetails: wfnd.getTaskDetailsList()){
                 if(taskDetails.getTaskId().equals(taskDetail)){
@@ -290,7 +290,7 @@ public class ExperimentDao{
     }
 
     public TaskDetails getTaskDetail(String taskId) throws RegistryException{
-        Experiment experiment = getExperimentOfTask(taskId);
+        Experiment experiment = getParentExperimentOfTask(taskId);
         for(WorkflowNodeDetails wfnd: experiment.getWorkflowNodeDetailsList()){
             for(TaskDetails taskDetails: wfnd.getTaskDetailsList()){
                 if(taskDetails.getTaskId().equals(taskId)){
@@ -303,12 +303,12 @@ public class ExperimentDao{
 
 
     /**
-     * Method to getExperiment the parent Experiment of a given workflow node instance id
+     * Method to get parent Experiment of the given workflow node instance id
      * @param nodeInstanceId
      * @return
      * @throws RegistryException
      */
-    public Experiment getExperimentOfWFNode(String nodeInstanceId) throws RegistryException{
+    public Experiment getParentExperimentOfWFNode(String nodeInstanceId) throws RegistryException{
         try {
             DBObject criteria = new BasicDBObject(WORKFLOW_NODE_ID, nodeInstanceId);
             DBObject doc = collection.findOne(criteria);
@@ -324,12 +324,12 @@ public class ExperimentDao{
     }
 
     /**
-     * Method to getExperiment the parent experiment of a given task id
+     * Method to get the parent experiment of the given task id
      * @param taskId
      * @return
      * @throws RegistryException
      */
-    public Experiment getExperimentOfTask(String taskId) throws RegistryException{
+    public Experiment getParentExperimentOfTask(String taskId) throws RegistryException{
         try {
             DBObject criteria = new BasicDBObject(TASK_ID, taskId);
             DBObject doc = collection.findOne(criteria);
@@ -343,4 +343,32 @@ public class ExperimentDao{
         }
         return null;
     }
+
+    /**
+     * Method to get the parent workflow node of the given task id
+     * @param taskId
+     * @return
+     * @throws RegistryException
+     */
+    public WorkflowNodeDetails getParentWFNodeOfTask(String taskId) throws RegistryException{
+        try {
+            DBObject criteria = new BasicDBObject(TASK_ID, taskId);
+            DBObject doc = collection.findOne(criteria);
+            if(doc != null){
+                String json = doc.toString();
+                Experiment experiment = (Experiment)modelConversionHelper.deserializeObject(
+                        Experiment.class, json);
+                for(WorkflowNodeDetails wfnd: experiment.getWorkflowNodeDetailsList()){
+                    for(TaskDetails taskDetails: wfnd.getTaskDetailsList()){
+                        if(taskDetails.getTaskId().equals(taskId)){
+                            return wfnd;
+                        }
+                    }
+                }
+            }
+        } catch (IOException e) {
+            throw new RegistryException(e);
+        }
+        return null;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/945161ea/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/mongo/dao/ProjectDao.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/mongo/dao/ProjectDao.java b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/mongo/dao/ProjectDao.java
new file mode 100644
index 0000000..e3ea7eb
--- /dev/null
+++ b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/mongo/dao/ProjectDao.java
@@ -0,0 +1,189 @@
+/*
+ *
+ * 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.persistance.registry.jpa.mongo.dao;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.mongodb.*;
+import com.mongodb.util.JSON;
+import org.apache.airavata.model.workspace.Project;
+import org.apache.airavata.persistance.registry.jpa.mongo.conversion.ModelConversionHelper;
+import org.apache.airavata.persistance.registry.jpa.mongo.utils.MongoUtil;
+import org.apache.airavata.registry.cpi.RegistryException;
+import org.apache.airavata.registry.cpi.ResultOrderType;
+import org.apache.airavata.registry.cpi.utils.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class ProjectDao {
+    private final static Logger logger = LoggerFactory.getLogger(ProjectDao.class);
+
+    private static final String PROJECTS_COLLECTION_NAME = "projects";
+    private DBCollection collection;
+    private ModelConversionHelper modelConversionHelper;
+
+    private static final String PROJECT_ID = "project_id";
+    private static final String PROJECT_NAME = "name";
+    private static final String PROJECT_DESCRIPTION = "description";
+    private static final String PROJECT_OWNER = "owner";
+    private static final String PROJECT_CREATION_TIME = "creation_time";
+
+    public ProjectDao(){
+        collection = MongoUtil.getAiravataRegistry().getCollection(PROJECTS_COLLECTION_NAME);
+        modelConversionHelper = new ModelConversionHelper();
+        collection.dropIndexes();
+        initIndexes();
+    }
+
+    /**
+     * If indexes are already defined this will simply ignore them
+     */
+    private void initIndexes(){
+        collection.createIndex(new BasicDBObject(PROJECT_ID, 1), new BasicDBObject("unique", true));
+        collection.createIndex(new BasicDBObject(PROJECT_NAME, 1));
+        collection.createIndex(new BasicDBObject(PROJECT_OWNER, 1));
+        collection.createIndex(new BasicDBObject(PROJECT_DESCRIPTION, 1));
+        collection.createIndex(new BasicDBObject(PROJECT_CREATION_TIME, 1));
+    }
+
+    public List<Project> getAllProjects() throws RegistryException{
+        List<Project> projectList = new ArrayList();
+        DBCursor cursor = collection.find();
+        for(DBObject document: cursor){
+            try {
+                projectList.add((Project) modelConversionHelper.deserializeObject(
+                        Project.class, document.toString()));
+            } catch (IOException e) {
+                throw new RegistryException(e);
+            }
+        }
+        return projectList;
+    }
+
+    public void createProject(Project project) throws RegistryException{
+        try {
+            WriteResult result = collection.insert((DBObject) JSON.parse(
+                    modelConversionHelper.serializeObject(project)));
+            logger.debug("No of inserted results "+ result.getN());
+        } catch (JsonProcessingException e) {
+            throw new RegistryException(e);
+        }
+    }
+
+    /**
+     * The following operation replaces the document with item equal to
+     * the given project id. The newly replaced document will only
+     * contain the the _id field and the fields in the replacement document.
+     * @param project
+     * @throws org.apache.airavata.registry.cpi.RegistryException
+     */
+    public void updateProject(Project project) throws RegistryException{
+        try {
+            DBObject query = BasicDBObjectBuilder.start().add(
+                    PROJECT_ID, project.getProjectId()).get();
+            WriteResult result = collection.update(query, (DBObject) JSON.parse(
+                    modelConversionHelper.serializeObject(project)));
+            logger.debug("No of updated results "+ result.getN());
+        } catch (JsonProcessingException e) {
+            throw new RegistryException(e);
+        }
+    }
+
+    public void deleteProject(Project project) throws RegistryException{
+        DBObject query = BasicDBObjectBuilder.start().add(
+                PROJECT_ID, project.getProjectId()).get();
+        WriteResult result = collection.remove(query);
+        logger.debug("No of removed experiments " + result.getN());
+    }
+
+    public Project getProject(String projectId) throws RegistryException{
+        try {
+            DBObject criteria = new BasicDBObject(PROJECT_ID, projectId);
+            DBObject doc = collection.findOne(criteria);
+            if(doc != null){
+                String json = doc.toString();
+                return (Project)modelConversionHelper.deserializeObject(
+                        Project.class, json);
+            }
+        } catch (IOException e) {
+            throw new RegistryException(e);
+        }
+        return null;
+    }
+
+    public List<Project> searchProjects(Map<String, String> filters, int limit,
+        int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException{
+        List<Project> projectList = new ArrayList();
+        BasicDBObjectBuilder queryBuilder = BasicDBObjectBuilder.start();
+        for (String field : filters.keySet()) {
+//            if (field.equals(Constants.FieldConstants.ProjectConstants.PROJECT_NAME)){
+//                fil.put(AbstractResource.ProjectConstants.PROJECT_NAME, filters.get(field));
+//            }else if (field.equals(Constants.FieldConstants.ProjectConstants.OWNER)){
+//                fil.put(AbstractResource.ProjectConstants.USERNAME, filters.get(field));
+//            }else if (field.equals(Constants.FieldConstants.ProjectConstants.DESCRIPTION)){
+//                fil.put(AbstractResource.ProjectConstants.DESCRIPTION, filters.get(field));
+//            }else if (field.equals(Constants.FieldConstants.ProjectConstants.GATEWAY_ID)){
+//                fil.put(AbstractResource.ProjectConstants.GATEWAY_ID, filters.get(field));
+//            }
+        }
+
+        //handling pagination and ordering. ordering is allowed only on PROJECT_CREATION_TIME
+        DBCursor cursor;
+        if(limit > 0 && offset >= 0) {
+            if(orderByIdentifier != null && orderByIdentifier.equals(
+                    Constants.FieldConstants.ProjectConstants.CREATION_TIME)){
+                if(resultOrderType.equals(ResultOrderType.ASC)) {
+                    cursor = collection.find(queryBuilder.get()).sort(new BasicDBObject(PROJECT_CREATION_TIME, 1))
+                            .skip(offset).limit(limit);
+                }else{
+                    cursor = collection.find(queryBuilder.get()).sort(new BasicDBObject(PROJECT_CREATION_TIME, -1))
+                            .skip(offset).limit(limit);
+                }
+            }else {
+                cursor = collection.find(queryBuilder.get()).skip(offset).limit(limit);
+            }
+        }else{
+            if(resultOrderType != null && resultOrderType.equals(
+                    Constants.FieldConstants.ProjectConstants.CREATION_TIME)){
+                if(resultOrderType.equals(ResultOrderType.ASC)) {
+                    cursor = collection.find(queryBuilder.get()).sort(new BasicDBObject(PROJECT_CREATION_TIME, 1));
+                }else{
+                    cursor = collection.find(queryBuilder.get()).sort(new BasicDBObject(PROJECT_CREATION_TIME, -1));
+                }
+            }else {
+                cursor = collection.find(queryBuilder.get());
+            }
+        }
+        for(DBObject document: cursor){
+            try {
+                projectList.add((Project) modelConversionHelper.deserializeObject(
+                        Project.class, document.toString()));
+            } catch (IOException e) {
+                throw new RegistryException(e);
+            }
+        }
+        return projectList;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/945161ea/modules/registry/airavata-mongo-registry/src/test/java/org/apache/airavata/persistence/registry/mongo/ExperimentDaoTest.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-mongo-registry/src/test/java/org/apache/airavata/persistence/registry/mongo/ExperimentDaoTest.java b/modules/registry/airavata-mongo-registry/src/test/java/org/apache/airavata/persistence/registry/mongo/ExperimentDaoTest.java
index 6b4d5cf..1def159 100644
--- a/modules/registry/airavata-mongo-registry/src/test/java/org/apache/airavata/persistence/registry/mongo/ExperimentDaoTest.java
+++ b/modules/registry/airavata-mongo-registry/src/test/java/org/apache/airavata/persistence/registry/mongo/ExperimentDaoTest.java
@@ -22,7 +22,6 @@ package org.apache.airavata.persistence.registry.mongo;
 
 import com.mongodb.MongoClient;
 import junit.framework.Assert;
-import org.apache.airavata.common.utils.AiravataUtils;
 import org.apache.airavata.model.appcatalog.appinterface.InputDataObjectType;
 import org.apache.airavata.model.workspace.experiment.*;
 import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory;
@@ -31,6 +30,8 @@ import org.apache.airavata.persistance.registry.jpa.mongo.utils.MongoUtil;
 import org.apache.airavata.registry.cpi.Registry;
 import org.apache.airavata.registry.cpi.RegistryException;
 import org.apache.airavata.registry.cpi.RegistryModelType;
+import org.apache.airavata.registry.cpi.ResultOrderType;
+import org.apache.airavata.registry.cpi.utils.Constants;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -40,7 +41,9 @@ import org.slf4j.LoggerFactory;
 import java.io.BufferedReader;
 import java.io.FileReader;
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.UUID;
 
 public class ExperimentDaoTest {
@@ -112,7 +115,6 @@ public class ExperimentDaoTest {
 
     @Test
     public void test() throws RegistryException, IOException {
-        AiravataUtils.setExecutionAsServer();
         Registry registry = RegistryFactory.getDefaultRegistry();
         MongoUtil.dropAiravataRegistry();
 
@@ -149,7 +151,6 @@ public class ExperimentDaoTest {
 //        long time2 = System.currentTimeMillis();
 //        System.out.println(time2-time1);
 //        Assert.assertNotNull(experiment);
-        AiravataUtils.setExecutionAsServer();
 
         ExperimentDao experimentDao = new ExperimentDao();
         BufferedReader reader = new BufferedReader(new FileReader("/home/supun/Downloads/WORKFLOW_NODE_DETAIL.csv"));
@@ -159,7 +160,7 @@ public class ExperimentDaoTest {
         long time1 = System.currentTimeMillis();
         while(temp != null && !temp.isEmpty()){
             try{
-                Experiment experiment = experimentDao.getExperimentOfWFNode(temp.trim());
+                Experiment experiment = experimentDao.getParentExperimentOfWFNode(temp.trim());
                 if(experiment != null) {
                     System.out.println(i + " :" + experiment.getExperimentId());
                     count++;
@@ -190,7 +191,6 @@ public class ExperimentDaoTest {
 //        AiravataUtils.setExecutionAsServer();
 //        Registry registry = RegistryFactory.getDefaultRegistry();
 //        MongoUtil.dropAiravataRegistry();
-        AiravataUtils.setExecutionAsServer();
 
         ExperimentDao experimentDao = new ExperimentDao();
         BufferedReader reader = new BufferedReader(new FileReader("/home/supun/Downloads/TASK_DETAIL.csv"));
@@ -200,7 +200,7 @@ public class ExperimentDaoTest {
         long time1 = System.currentTimeMillis();
         while(temp != null && !temp.isEmpty()){
             try{
-                Experiment experiment = experimentDao.getExperimentOfTask(temp.trim());
+                Experiment experiment = experimentDao.getParentExperimentOfTask(temp.trim());
                 if(experiment != null) {
                     //System.out.println(i + " :" + experiment.getExperimentId());
                     count++;
@@ -224,7 +224,6 @@ public class ExperimentDaoTest {
         String nodeId = "tempNode_758b52ba-091b-43a5-a7b7-4c3a239c5d1e";
         String newNodeId = "newNode_758b52ba-091b-43a5-a7b7-4c3a2325d1e";
         String expId = "AlamoTest3_3965f4e2-0213-4434-9c3f-fe898b018666";
-        AiravataUtils.setExecutionAsServer();
         ExperimentDao experimentDao = new ExperimentDao();
         WorkflowNodeDetails wfNode = experimentDao.getWFNode("newNode_758b52ba-091b-43a5-a7b7-4c3a239c5d1e");
         Assert.assertTrue(wfNode.getNodeInstanceId().equals("newNode_758b52ba-091b-43a5-a7b7-4c3a239c5d1e"));
@@ -250,8 +249,7 @@ public class ExperimentDaoTest {
 
     @Test
     public void testTask() throws RegistryException {
-        String taskId = "tempNode_f43e1a37-5aec-4061-ae15-111a050b98e0";
-        AiravataUtils.setExecutionAsServer();
+        String taskId = "tempNode_58e1b2e4-f7d6-4543-9281-43dcb58e2c1a";
         ExperimentDao experimentDao = new ExperimentDao();
         TaskDetails taskDetails = experimentDao.getTaskDetail(taskId);
         Assert.assertTrue(taskDetails.getTaskId().equals(taskId));
@@ -261,8 +259,20 @@ public class ExperimentDaoTest {
         taskDetails = experimentDao.getTaskDetail(taskId);
         Assert.assertTrue(taskDetails.getTaskId().equals(taskId));
 
-        String expid = "AlamoTest1_6107d1f0-d64e-4690-8686-71ce87c4ad24";
+        String expid = "alamotest2_5420547e-877a-4a9c-8752-377c2806906c";
         Experiment experiment = experimentDao.getExperiment(expid);
         System.out.println();
     }
+
+    @Test
+    public void testSearch() throws RegistryException{
+        Map<String, String> filters = new HashMap();
+        filters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, "Eroma123");
+        filters.put(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_DESC, "Test");
+        List<Experiment> result = experimentDao.searchExperiments(
+                filters, 10, 2, Constants.FieldConstants.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
+        Assert.assertNotNull(result);
+        Assert.assertTrue(result.size()==10);
+        Assert.assertTrue(result.get(0).getCreationTime() > result.get(9).getCreationTime());
+    }
 }
\ No newline at end of file


Mime
View raw message