http://git-wip-us.apache.org/repos/asf/airavata/blob/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/UserResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/UserResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/UserResource.java new file mode 100644 index 0000000..a0927cb --- /dev/null +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/UserResource.java @@ -0,0 +1,186 @@ +/* + * + * 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.experiment.catalog.resources; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.SecurityUtil; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils; +import org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource; +import org.apache.airavata.registry.core.experiment.catalog.ResourceType; +import org.apache.airavata.registry.core.experiment.catalog.model.Users; +import org.apache.airavata.registry.cpi.RegistryException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import java.security.NoSuchAlgorithmException; +import java.util.List; + +public class UserResource extends AbstractExpCatResource { + private final static Logger logger = LoggerFactory.getLogger(UserResource.class); + private String userName; + private String password; + /** + * + */ + public UserResource() { + } + + /** + * + * @param userName user name + */ + public void setUserName(String userName) { + this.userName = userName; + } + + /** + * + * @return user name + */ + public String getUserName() { + return userName; + } + + + /** + * User is a hypothical data structure. + * @param type child resource type + * @return child resource + */ + public ExperimentCatResource create(ResourceType type) throws RegistryException { + logger.error("Unsupported resource type for user resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + /** + * + * @param type child resource type + * @param name child resource name + */ + public void remove(ResourceType type, Object name) throws RegistryException{ + logger.error("Unsupported resource type for user resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + /** + * + * @param type child resource type + * @param name child resource name + * @return UnsupportedOperationException + */ + public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException { + logger.error("Unsupported resource type for user resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + /** + * + * @param type child resource type + * @return UnsupportedOperationException + */ + public List<ExperimentCatResource> get(ResourceType type) throws RegistryException{ + logger.error("Unsupported resource type for user resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + /** + * save user to the database + */ + public void save() throws RegistryException { + EntityManager em = null; + try { + em = ExpCatResourceUtils.getEntityManager(); + Users existingUser = em.find(Users.class, userName); + em.close(); + + em = ExpCatResourceUtils.getEntityManager(); + em.getTransaction().begin(); + Users user = new Users(); + user.setUser_name(userName); + if (password != null && !password.equals("")) { + try { + user.setPassword(SecurityUtil.digestString(password, + ServerSettings.getSetting("default.registry.password.hash.method"))); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("Error hashing default admin password. Invalid hash algorithm.", e); + } catch (ApplicationSettingsException e) { + throw new RuntimeException("Error reading hash algorithm from configurations", e); + } + } + if (existingUser != null) { + if (password != null && !password.equals("")) { + try { + existingUser.setPassword(SecurityUtil.digestString(password, + ServerSettings.getSetting("default.registry.password.hash.method"))); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException("Error hashing default admin password. Invalid hash algorithm.", e); + } catch (ApplicationSettingsException e) { + throw new RuntimeException("Error reading hash algorithm from configurations", e); + } + } + user = em.merge(existingUser); + } else { + em.persist(user); + } + em.getTransaction().commit(); + em.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new RegistryException(e); + } finally { + if (em != null && em.isOpen()) { + if (em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + } + } + + /** + * + * @param type child resource type + * @param name child resource name + * @return UnsupportedOperationException + */ + public boolean isExists(ResourceType type, Object name) throws RegistryException{ + logger.error("Unsupported resource type for user resource.", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + + /** + * + * @return password + */ + public String getPassword() { + return password; + } + + /** + * + * @param password password + */ + public void setPassword(String password) { + this.password = password; + } +}
http://git-wip-us.apache.org/repos/asf/airavata/blob/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/Utils.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/Utils.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/Utils.java index 6164b12..bc8377c 100644 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/Utils.java +++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/Utils.java @@ -361,7 +361,7 @@ public class Utils { * @return GatewayResource object */ private static ExperimentCatResource createGateway(Gateway o) { - GatewayExperimentCatResource gatewayResource = new GatewayExperimentCatResource(); + GatewayResource gatewayResource = new GatewayResource(); gatewayResource.setGatewayName(o.getGateway_name()); gatewayResource.setGatewayId(o.getGateway_id()); gatewayResource.setDomain(o.getDomain()); @@ -375,7 +375,7 @@ public class Utils { * @return ProjectResource object */ private static ExperimentCatResource createProject(Project o) { - ProjectExperimentCatResource projectResource = new ProjectExperimentCatResource(); + ProjectResource projectResource = new ProjectResource(); if (o != null){ projectResource.setId(o.getProject_id()); projectResource.setName(o.getProject_name()); @@ -384,7 +384,7 @@ public class Utils { gateway_worker.setGateway(o.getGateway()); gateway_worker.setUser(o.getUsers()); gateway_worker.setUser_name(o.getUsers().getUser_name()); - WorkerExperimentCatResource workerResource = (WorkerExperimentCatResource) createGatewayWorker(gateway_worker); + WorkerResource workerResource = (WorkerResource) createGatewayWorker(gateway_worker); projectResource.setWorker(workerResource); projectResource.setDescription(o.getDescription()); projectResource.setCreationTime(o.getCreationTime()); @@ -394,7 +394,7 @@ public class Utils { } private static ExperimentCatResource createProjectUser(ProjectUser o) { - ProjectUserExperimentCatResource projectUserResource = new ProjectUserExperimentCatResource(); + ProjectUserResource projectUserResource = new ProjectUserResource(); if (o != null){ projectUserResource.setUserName(o.getUser().getUser_name()); projectUserResource.setProjectId(o.getProjectID()); @@ -408,7 +408,7 @@ public class Utils { * @return configuration resource object */ private static ExperimentCatResource createConfiguration (Configuration o){ - ConfigurationExperimentCatResource configurationResource = new ConfigurationExperimentCatResource(); + ConfigurationResource configurationResource = new ConfigurationResource(); if (o != null){ configurationResource.setConfigKey(o.getConfig_key()); configurationResource.setConfigVal(o.getConfig_val()); @@ -426,7 +426,7 @@ public class Utils { */ private static ExperimentCatResource createGatewayWorker(Gateway_Worker o) { if (o != null){ - WorkerExperimentCatResource workerResource = new WorkerExperimentCatResource(); + WorkerResource workerResource = new WorkerResource(); workerResource.setGatewayId(o.getGateway_id()); workerResource.setUser(o.getUser_name()); return workerResource; @@ -440,7 +440,7 @@ public class Utils { * @return UserResource object */ private static ExperimentCatResource createUser(Users o) { - UserExperimentCatResource userResource = new UserExperimentCatResource(); + UserResource userResource = new UserResource(); if (o != null){ userResource.setUserName(o.getUser_name()); userResource.setPassword(o.getPassword()); @@ -454,7 +454,7 @@ public class Utils { * @return Experiment resource object */ private static ExperimentCatResource createExperiment(Experiment o) { - ExperimentExperimentCatResource experimentResource = new ExperimentExperimentCatResource(); + ExperimentResource experimentResource = new ExperimentResource(); if (o != null){ experimentResource.setGatewayId(o.getGatewayId()); experimentResource.setExecutionUser(o.getExecutionUser()); @@ -477,10 +477,10 @@ public class Utils { experimentResource.setExperimentOutputputResources(getExperimentOutputs(o.getExperimentOutputs())); } if (o.getResourceScheduling() != null){ - experimentResource.setComputationSchedulingResource((ComputationSchedulingExperimentCatResource)createComputationalScheduling(o.getResourceScheduling())); + experimentResource.setComputationSchedulingResource((ComputationSchedulingResource)createComputationalScheduling(o.getResourceScheduling())); } if (o.getUserConfigurationData() != null){ - experimentResource.setUserConfigDataResource((ConfigDataExperimentCatResource)createExConfigDataResource(o.getUserConfigurationData())); + experimentResource.setUserConfigDataResource((ConfigDataResource)createExConfigDataResource(o.getUserConfigurationData())); } if (o.getWorkflowNodeDetails() != null && !o.getWorkflowNodeDetails().isEmpty()){ @@ -496,7 +496,7 @@ public class Utils { } if (o.getExperimentStatus() != null){ - experimentResource.setExperimentStatus((StatusExperimentCatResource)createStatusResource(o.getExperimentStatus())); + experimentResource.setExperimentStatus((StatusResource)createStatusResource(o.getExperimentStatus())); } if (o.getNotificationEmails() != null && !o.getNotificationEmails().isEmpty()){ @@ -512,7 +512,7 @@ public class Utils { * @return ExperimentSummary Resource object */ private static ExperimentCatResource createExperimentSummary(Experiment o) { - ExperimentSummaryExperimentCatResource experimentSummaryResource = new ExperimentSummaryExperimentCatResource(); + ExperimentSummaryResource experimentSummaryResource = new ExperimentSummaryResource(); if (o != null){ experimentSummaryResource.setExecutionUser(o.getExecutionUser()); experimentSummaryResource.setExpID(o.getExpId()); @@ -524,7 +524,7 @@ public class Utils { Status experimentStatus = o.getExperimentStatus(); if(experimentStatus != null) { - StatusExperimentCatResource statusResource = new StatusExperimentCatResource(); + StatusResource statusResource = new StatusResource(); statusResource.setStatusId(experimentStatus.getStatusId()); statusResource.setJobId(experimentStatus.getJobId()); statusResource.setState(experimentStatus.getState()); @@ -537,104 +537,104 @@ public class Utils { return experimentSummaryResource; } - private static List<ExperimentInputExperimentCatResource> getExperimentInputs(List<Experiment_Input> inputs){ - List<ExperimentInputExperimentCatResource> inputResources = new ArrayList<ExperimentInputExperimentCatResource>(); + private static List<ExperimentInputResource> getExperimentInputs(List<Experiment_Input> inputs){ + List<ExperimentInputResource> inputResources = new ArrayList<ExperimentInputResource>(); for (Experiment_Input input : inputs){ - inputResources.add((ExperimentInputExperimentCatResource)createExperimentInput(input)); + inputResources.add((ExperimentInputResource)createExperimentInput(input)); } return inputResources; } - private static List<ExperimentOutputExperimentCatResource> getExperimentOutputs(List<Experiment_Output> outputs){ - List<ExperimentOutputExperimentCatResource> outputResources = new ArrayList<>(); + private static List<ExperimentOutputResource> getExperimentOutputs(List<Experiment_Output> outputs){ + List<ExperimentOutputResource> outputResources = new ArrayList<>(); for (Experiment_Output output : outputs){ - outputResources.add((ExperimentOutputExperimentCatResource) createExperimentOutput(output)); + outputResources.add((ExperimentOutputResource) createExperimentOutput(output)); } return outputResources; } - private static List<NodeInputExperimentCatResource> getNodeInputs(List<NodeInput> inputs){ - List<NodeInputExperimentCatResource> inputResources = new ArrayList<NodeInputExperimentCatResource>(); + private static List<NodeInputResource> getNodeInputs(List<NodeInput> inputs){ + List<NodeInputResource> inputResources = new ArrayList<NodeInputResource>(); for (NodeInput input : inputs){ - inputResources.add((NodeInputExperimentCatResource)createNodeInput(input)); + inputResources.add((NodeInputResource)createNodeInput(input)); } return inputResources; } - private static List<NodeOutputExperimentCatResource> getNodeOutputs(List<NodeOutput> outputs){ - List<NodeOutputExperimentCatResource> outputResources = new ArrayList<>(); + private static List<NodeOutputResource> getNodeOutputs(List<NodeOutput> outputs){ + List<NodeOutputResource> outputResources = new ArrayList<>(); for (NodeOutput output : outputs){ - outputResources.add((NodeOutputExperimentCatResource) createNodeOutput(output)); + outputResources.add((NodeOutputResource) createNodeOutput(output)); } return outputResources; } - private static List<ApplicationInputExperimentCatResource> getApplicationInputs(List<ApplicationInput> inputs){ - List<ApplicationInputExperimentCatResource> inputResources = new ArrayList<ApplicationInputExperimentCatResource>(); + private static List<ApplicationInputResource> getApplicationInputs(List<ApplicationInput> inputs){ + List<ApplicationInputResource> inputResources = new ArrayList<ApplicationInputResource>(); for (ApplicationInput input : inputs){ - inputResources.add((ApplicationInputExperimentCatResource)createApplicationInput(input)); + inputResources.add((ApplicationInputResource)createApplicationInput(input)); } return inputResources; } - private static List<ApplicationOutputExperimentCatResource> getApplicationOutputs(List<ApplicationOutput> outputs){ - List<ApplicationOutputExperimentCatResource> outputResources = new ArrayList<>(); + private static List<ApplicationOutputResource> getApplicationOutputs(List<ApplicationOutput> outputs){ + List<ApplicationOutputResource> outputResources = new ArrayList<>(); for (ApplicationOutput output : outputs){ - outputResources.add((ApplicationOutputExperimentCatResource) createApplicationOutput(output)); + outputResources.add((ApplicationOutputResource) createApplicationOutput(output)); } return outputResources; } - private static List<WorkflowNodeDetailExperimentCatResource> getWorkflowNodeLit(List<WorkflowNodeDetail> nodes){ - List<WorkflowNodeDetailExperimentCatResource> nodeList = new ArrayList<>(); + private static List<WorkflowNodeDetailResource> getWorkflowNodeLit(List<WorkflowNodeDetail> nodes){ + List<WorkflowNodeDetailResource> nodeList = new ArrayList<>(); for (WorkflowNodeDetail node : nodes){ - nodeList.add((WorkflowNodeDetailExperimentCatResource) createWorkflowNodeDetail(node)); + nodeList.add((WorkflowNodeDetailResource) createWorkflowNodeDetail(node)); } return nodeList; } - private static List<StatusExperimentCatResource> getStateChangeList(List<Status> statusList){ - List<StatusExperimentCatResource> changeList = new ArrayList<>(); + private static List<StatusResource> getStateChangeList(List<Status> statusList){ + List<StatusResource> changeList = new ArrayList<>(); for (Status status : statusList){ - changeList.add((StatusExperimentCatResource) createStatusResource(status)); + changeList.add((StatusResource) createStatusResource(status)); } return changeList; } - private static List<ErrorDetailExperimentCatResource> getErrorList(List<ErrorDetail> errorDetails){ - List<ErrorDetailExperimentCatResource> errors = new ArrayList<>(); + private static List<ErrorDetailResource> getErrorList(List<ErrorDetail> errorDetails){ + List<ErrorDetailResource> errors = new ArrayList<>(); for (ErrorDetail error : errorDetails){ - errors.add((ErrorDetailExperimentCatResource) createErrorDetail(error)); + errors.add((ErrorDetailResource) createErrorDetail(error)); } return errors; } - private static List<JobDetailExperimentCatResource> getJobDetails(List<JobDetail> jobDetails){ - List<JobDetailExperimentCatResource> resources = new ArrayList<>(); + private static List<JobDetailResource> getJobDetails(List<JobDetail> jobDetails){ + List<JobDetailResource> resources = new ArrayList<>(); for (JobDetail jobDetail : jobDetails){ - resources.add((JobDetailExperimentCatResource) createJobDetail(jobDetail)); + resources.add((JobDetailResource) createJobDetail(jobDetail)); } return resources; } - private static List<DataTransferDetailExperimentCatResource> getDTDetails(List<DataTransferDetail> dataTransferDetails){ - List<DataTransferDetailExperimentCatResource> resources = new ArrayList<>(); + private static List<DataTransferDetailResource> getDTDetails(List<DataTransferDetail> dataTransferDetails){ + List<DataTransferDetailResource> resources = new ArrayList<>(); for (DataTransferDetail detail : dataTransferDetails){ - resources.add((DataTransferDetailExperimentCatResource) createDataTransferResource(detail)); + resources.add((DataTransferDetailResource) createDataTransferResource(detail)); } return resources; } - private static List<NotificationEmailExperimentCatResource> getEmailList(List<Notification_Email> emails){ - List<NotificationEmailExperimentCatResource> emailResources = new ArrayList<>(); + private static List<NotificationEmailResource> getEmailList(List<Notification_Email> emails){ + List<NotificationEmailResource> emailResources = new ArrayList<>(); for (Notification_Email email : emails){ - emailResources.add((NotificationEmailExperimentCatResource) createNotificationEmail(email)); + emailResources.add((NotificationEmailResource) createNotificationEmail(email)); } return emailResources; } private static ExperimentCatResource createNotificationEmail (Notification_Email o){ - NotificationEmailExperimentCatResource emailResource = new NotificationEmailExperimentCatResource(); + NotificationEmailResource emailResource = new NotificationEmailResource(); if (o != null){ emailResource.setExperimentId(o.getExperiment_id()); emailResource.setTaskId(o.getTaskId()); @@ -644,7 +644,7 @@ public class Utils { } private static ExperimentCatResource createExperimentInput (Experiment_Input o){ - ExperimentInputExperimentCatResource eInputResource = new ExperimentInputExperimentCatResource(); + ExperimentInputResource eInputResource = new ExperimentInputResource(); if (o != null){ eInputResource.setExperimentId(o.getExperiment_id()); eInputResource.setDataType(o.getDataType()); @@ -665,7 +665,7 @@ public class Utils { } private static ExperimentCatResource createExperimentOutput (Experiment_Output o){ - ExperimentOutputExperimentCatResource eOutputResource = new ExperimentOutputExperimentCatResource(); + ExperimentOutputResource eOutputResource = new ExperimentOutputResource(); if (o != null){ eOutputResource.setExperimentId(o.getExperiment_id()); eOutputResource.setExperimentKey(o.getEx_key()); @@ -684,7 +684,7 @@ public class Utils { } private static ExperimentCatResource createWorkflowNodeDetail (WorkflowNodeDetail o){ - WorkflowNodeDetailExperimentCatResource nodeDetailResource = new WorkflowNodeDetailExperimentCatResource(); + WorkflowNodeDetailResource nodeDetailResource = new WorkflowNodeDetailResource(); if (o != null){ nodeDetailResource.setExperimentId(o.getExpId()); nodeDetailResource.setCreationTime(o.getCreationTime()); @@ -705,7 +705,7 @@ public class Utils { } if (o.getNodeStatus() != null){ - nodeDetailResource.setNodeStatus((StatusExperimentCatResource) createStatusResource(o.getNodeStatus())); + nodeDetailResource.setNodeStatus((StatusResource) createStatusResource(o.getNodeStatus())); } if (o.getErrorDetails() != null && !o.getErrorDetails().isEmpty()){ @@ -715,16 +715,16 @@ public class Utils { return nodeDetailResource; } - private static List<TaskDetailExperimentCatResource> getTaskDetails (List<TaskDetail> taskDetails){ - List<TaskDetailExperimentCatResource> tasks = new ArrayList<>(); + private static List<TaskDetailResource> getTaskDetails (List<TaskDetail> taskDetails){ + List<TaskDetailResource> tasks = new ArrayList<>(); for (TaskDetail detail : taskDetails){ - tasks.add((TaskDetailExperimentCatResource) createTaskDetail(detail)); + tasks.add((TaskDetailResource) createTaskDetail(detail)); } return tasks; } private static ExperimentCatResource createTaskDetail(TaskDetail o){ - TaskDetailExperimentCatResource taskDetailResource = new TaskDetailExperimentCatResource(); + TaskDetailResource taskDetailResource = new TaskDetailResource(); if ( o != null){ taskDetailResource.setNodeId(o.getNodeId()); taskDetailResource.setCreationTime(o.getCreationTime()); @@ -740,20 +740,20 @@ public class Utils { taskDetailResource.setApplicationOutputs(getApplicationOutputs(o.getApplicationOutputs())); } if (o.getResourceScheduling() != null){ - taskDetailResource.setSchedulingResource((ComputationSchedulingExperimentCatResource) createComputationalScheduling(o.getResourceScheduling())); + taskDetailResource.setSchedulingResource((ComputationSchedulingResource) createComputationalScheduling(o.getResourceScheduling())); } if (o.getInputDataHandling() != null){ - taskDetailResource.setInputDataHandlingResource((AdvanceInputDataHandlingExperimentCatResource) createAdvancedInputDataResource(o.getInputDataHandling())); + taskDetailResource.setInputDataHandlingResource((AdvanceInputDataHandlingResource) createAdvancedInputDataResource(o.getInputDataHandling())); } if (o.getOutputDataHandling() != null){ - taskDetailResource.setOutputDataHandlingResource((AdvancedOutputDataHandlingExperimentCatResource) createAdvancedOutputDataResource(o.getOutputDataHandling())); + taskDetailResource.setOutputDataHandlingResource((AdvancedOutputDataHandlingResource) createAdvancedOutputDataResource(o.getOutputDataHandling())); } if (o.getErrorDetails() != null && !o.getErrorDetails().isEmpty()){ taskDetailResource.setErrors(getErrorList(o.getErrorDetails())); } if (o.getTaskStatus() != null){ - taskDetailResource.setTaskStatus((StatusExperimentCatResource) createStatusResource(o.getTaskStatus())); + taskDetailResource.setTaskStatus((StatusResource) createStatusResource(o.getTaskStatus())); } if (o.getNotificationEmails() != null && !o.getNotificationEmails().isEmpty()){ taskDetailResource.setEmailResourceList(getEmailList(o.getNotificationEmails())); @@ -770,7 +770,7 @@ public class Utils { } private static ExperimentCatResource createErrorDetail (ErrorDetail o){ - ErrorDetailExperimentCatResource errorDetailResource = new ErrorDetailExperimentCatResource(); + ErrorDetailResource errorDetailResource = new ErrorDetailResource(); if (o != null){ errorDetailResource.setExperimentId(o.getExpId()); errorDetailResource.setTaskId(o.getTaskId()); @@ -792,7 +792,7 @@ public class Utils { } private static ExperimentCatResource createApplicationInput (ApplicationInput o){ - ApplicationInputExperimentCatResource inputResource = new ApplicationInputExperimentCatResource(); + ApplicationInputResource inputResource = new ApplicationInputResource(); if (o != null){ inputResource.setTaskId(o.getTaskId()); inputResource.setInputKey(o.getInputKey()); @@ -813,7 +813,7 @@ public class Utils { } private static ExperimentCatResource createApplicationOutput (ApplicationOutput o){ - ApplicationOutputExperimentCatResource outputResource = new ApplicationOutputExperimentCatResource(); + ApplicationOutputResource outputResource = new ApplicationOutputResource(); if (o != null){ outputResource.setTaskId(o.getTaskId()); outputResource.setDataType(o.getDataType()); @@ -832,7 +832,7 @@ public class Utils { } private static ExperimentCatResource createNodeInput (NodeInput o){ - NodeInputExperimentCatResource inputResource = new NodeInputExperimentCatResource(); + NodeInputResource inputResource = new NodeInputResource(); if (o != null){ inputResource.setNodeId(o.getNodeId()); inputResource.setInputKey(o.getInputKey()); @@ -851,7 +851,7 @@ public class Utils { } private static ExperimentCatResource createNodeOutput (NodeOutput o){ - NodeOutputExperimentCatResource outputResource = new NodeOutputExperimentCatResource(); + NodeOutputResource outputResource = new NodeOutputResource(); if (o != null){ outputResource.setNodeId(o.getNodeId()); outputResource.setDataType(o.getDataType()); @@ -869,7 +869,7 @@ public class Utils { } private static ExperimentCatResource createJobDetail (JobDetail o){ - JobDetailExperimentCatResource jobDetailResource = new JobDetailExperimentCatResource(); + JobDetailResource jobDetailResource = new JobDetailResource(); if (o != null){ jobDetailResource.setTaskId(o.getTaskId()); if (o.getJobDescription() != null){ @@ -880,7 +880,7 @@ public class Utils { jobDetailResource.setComputeResourceConsumed(o.getComputeResourceConsumed()); jobDetailResource.setJobName(o.getJobName()); jobDetailResource.setWorkingDir(o.getWorkingDir()); - jobDetailResource.setJobStatus((StatusExperimentCatResource)createStatusResource(o.getJobStatus())); + jobDetailResource.setJobStatus((StatusResource)createStatusResource(o.getJobStatus())); jobDetailResource.setErrors(getErrorList(o.getErrorDetails())); } @@ -888,7 +888,7 @@ public class Utils { } private static ExperimentCatResource createDataTransferResource (DataTransferDetail o){ - DataTransferDetailExperimentCatResource transferDetailResource = new DataTransferDetailExperimentCatResource(); + DataTransferDetailResource transferDetailResource = new DataTransferDetailResource(); if (o != null){ transferDetailResource.setTaskId(o.getTaskId()); transferDetailResource.setTransferId(o.getTransferId()); @@ -897,14 +897,14 @@ public class Utils { transferDetailResource.setTransferDescription(new String(o.getTransferDesc())); } if (o.getDataTransferStatus() != null){ - transferDetailResource.setDatatransferStatus((StatusExperimentCatResource)createStatusResource(o.getDataTransferStatus())); + transferDetailResource.setDatatransferStatus((StatusResource)createStatusResource(o.getDataTransferStatus())); } } return transferDetailResource; } private static ExperimentCatResource createStatusResource (Status o){ - StatusExperimentCatResource statusResource = new StatusExperimentCatResource(); + StatusResource statusResource = new StatusResource(); if (o != null){ statusResource.setExperimentId(o.getExpId()); statusResource.setTaskId(o.getTaskId()); @@ -921,7 +921,7 @@ public class Utils { } private static ExperimentCatResource createExConfigDataResource (ExperimentConfigData o){ - ConfigDataExperimentCatResource configDataResource = new ConfigDataExperimentCatResource(); + ConfigDataResource configDataResource = new ConfigDataResource(); if (o != null){ configDataResource.setExperimentId(o.getExpId()); configDataResource.setAiravataAutoSchedule(o.isAiravataAutoSchedule()); @@ -930,16 +930,16 @@ public class Utils { configDataResource.setUserDn(o.getUserDn()); configDataResource.setGenerateCert(o.isGenerateCert()); if (o.getOutputDataHandling() != null){ - configDataResource.setAdvancedOutputDataHandlingResource((AdvancedOutputDataHandlingExperimentCatResource) createAdvancedOutputDataResource(o.getOutputDataHandling())); + configDataResource.setAdvancedOutputDataHandlingResource((AdvancedOutputDataHandlingResource) createAdvancedOutputDataResource(o.getOutputDataHandling())); } if (o.getInputDataHandling() != null){ - configDataResource.setAdvanceInputDataHandlingResource((AdvanceInputDataHandlingExperimentCatResource) createAdvancedInputDataResource(o.getInputDataHandling())); + configDataResource.setAdvanceInputDataHandlingResource((AdvanceInputDataHandlingResource) createAdvancedInputDataResource(o.getInputDataHandling())); } if (o.getResourceScheduling() != null){ - configDataResource.setComputationSchedulingResource((ComputationSchedulingExperimentCatResource) createComputationalScheduling(o.getResourceScheduling())); + configDataResource.setComputationSchedulingResource((ComputationSchedulingResource) createComputationalScheduling(o.getResourceScheduling())); } if (o.getQosParam() != null){ - configDataResource.setQosParamResource((QosParamExperimentCatResource) createQosParamResource(o.getQosParam())); + configDataResource.setQosParamResource((QosParamResource) createQosParamResource(o.getQosParam())); } } @@ -947,7 +947,7 @@ public class Utils { } private static ExperimentCatResource createComputationalScheduling (Computational_Resource_Scheduling o){ - ComputationSchedulingExperimentCatResource schedulingResource = new ComputationSchedulingExperimentCatResource(); + ComputationSchedulingResource schedulingResource = new ComputationSchedulingResource(); if (o != null){ schedulingResource.setExperimentId(o.getExpId()); schedulingResource.setTaskId(o.getTaskId()); @@ -968,7 +968,7 @@ public class Utils { } private static ExperimentCatResource createAdvancedInputDataResource (AdvancedInputDataHandling o){ - AdvanceInputDataHandlingExperimentCatResource dataHandlingResource = new AdvanceInputDataHandlingExperimentCatResource(); + AdvanceInputDataHandlingResource dataHandlingResource = new AdvanceInputDataHandlingResource(); if (o != null){ dataHandlingResource.setExperimentId(o.getExpId()); dataHandlingResource.setTaskId(o.getTaskId()); @@ -983,7 +983,7 @@ public class Utils { } private static ExperimentCatResource createAdvancedOutputDataResource (AdvancedOutputDataHandling o){ - AdvancedOutputDataHandlingExperimentCatResource dataHandlingResource = new AdvancedOutputDataHandlingExperimentCatResource(); + AdvancedOutputDataHandlingResource dataHandlingResource = new AdvancedOutputDataHandlingResource(); if (o != null){ dataHandlingResource.setExperimentId(o.getExpId()); dataHandlingResource.setTaskId(o.getTaskId()); @@ -996,7 +996,7 @@ public class Utils { } private static ExperimentCatResource createQosParamResource (QosParam o){ - QosParamExperimentCatResource qosParamResource = new QosParamExperimentCatResource(); + QosParamResource qosParamResource = new QosParamResource(); if (o != null){ qosParamResource.setExperimentId(o.getExpId()); qosParamResource.setTaskId(o.getTaskId()); http://git-wip-us.apache.org/repos/asf/airavata/blob/4045c094/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/WorkerExperimentCatResource.java ---------------------------------------------------------------------- diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/WorkerExperimentCatResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/WorkerExperimentCatResource.java deleted file mode 100644 index 91dc631..0000000 --- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/WorkerExperimentCatResource.java +++ /dev/null @@ -1,725 +0,0 @@ -/* - * - * 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.experiment.catalog.resources; - -import org.apache.airavata.model.workspace.experiment.ExperimentState; -import org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils; -import org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource; -import org.apache.airavata.registry.core.experiment.catalog.ResourceType; -import org.apache.airavata.registry.core.experiment.catalog.model.*; -import org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator; -import org.apache.airavata.registry.cpi.RegistryException; -import org.apache.airavata.registry.cpi.ResultOrderType; -import org.apache.airavata.registry.cpi.utils.Constants; -import org.apache.airavata.registry.cpi.utils.StatusType; -import org.apache.openjpa.persistence.OpenJPAPersistence; -import org.apache.openjpa.persistence.OpenJPAQuery; -import org.apache.openjpa.persistence.jdbc.FetchMode; -import org.apache.openjpa.persistence.jdbc.JDBCFetchPlan; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.persistence.EntityManager; -import javax.persistence.Query; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -public class WorkerExperimentCatResource extends AbstractExperimentCatResource { - private final static Logger logger = LoggerFactory.getLogger(WorkerExperimentCatResource.class); - private String user; - private String gatewayId; - - public WorkerExperimentCatResource() { - } - - public WorkerExperimentCatResource(String user, String gatewayId) { - this.user = user; - this.gatewayId = gatewayId; - } - - public String getGatewayId() { - return gatewayId; - } - - public void setGatewayId(String gatewayId) { - this.gatewayId = gatewayId; - } - - /** - * Gateway worker can create child data structures such as projects and user workflows - * @param type child resource type - * @return child resource - */ - public ExperimentCatResource create(ResourceType type) throws RegistryException{ - ExperimentCatResource result = null; - switch (type) { - case PROJECT: - ProjectExperimentCatResource projectResource = new ProjectExperimentCatResource(); - projectResource.setWorker(this); - projectResource.setGatewayId(gatewayId); - result=projectResource; - break; - case EXPERIMENT: - ExperimentExperimentCatResource experimentResource = new ExperimentExperimentCatResource(); - experimentResource.setExecutionUser(user); - experimentResource.setGatewayId(gatewayId); - result = experimentResource; - break; - default: - logger.error("Unsupported resource type for worker resource.", new IllegalArgumentException()); - throw new IllegalArgumentException("Unsupported resource type for worker resource."); - - } - return result; - } - - /** - * - * @param type child resource type - * @param name child resource name - */ - public void remove(ResourceType type, Object name) throws RegistryException{ - EntityManager em = null; - try { - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - Query q; - QueryGenerator generator; - switch (type) { - case PROJECT: - generator = new QueryGenerator(PROJECT); - generator.setParameter(ProjectConstants.PROJECT_ID, name); - q = generator.deleteQuery(em); - q.executeUpdate(); - break; - case EXPERIMENT: - generator = new QueryGenerator(EXPERIMENT); - generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name); - q = generator.deleteQuery(em); - q.executeUpdate(); - break; - default: - logger.error("Unsupported resource type for worker resource.", new IllegalArgumentException()); - break; - } - em.getTransaction().commit(); - em.close(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RegistryException(e.getMessage()); - } finally { - if (em != null && em.isOpen()) { - if (em.getTransaction().isActive()){ - em.getTransaction().rollback(); - } - em.close(); - } - } - } - - /** - * - * @param type child resource type - * @param name child resource name - * @return child resource - */ - public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException{ - ExperimentCatResource result = null; - EntityManager em = null; - try { - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - QueryGenerator generator; - Query q; - switch (type) { - case PROJECT: - generator = new QueryGenerator(PROJECT); - generator.setParameter(ProjectConstants.PROJECT_ID, name); - q = generator.selectQuery(em); - Project project = (Project) q.getSingleResult(); - result = Utils.getResource(ResourceType.PROJECT, project); - break; - case EXPERIMENT: - generator = new QueryGenerator(EXPERIMENT); - generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name); - q = generator.selectQuery(em); - Experiment experiment = (Experiment) q.getSingleResult(); - result = Utils.getResource(ResourceType.EXPERIMENT, experiment); - break; - default: - logger.error("Unsupported resource type for worker resource.", new IllegalArgumentException()); - break; - } - em.getTransaction().commit(); - em.close(); - } catch (Exception e) { - throw new RegistryException(e); - } finally { - if (em != null && em.isOpen()) { - if (em.getTransaction().isActive()){ - em.getTransaction().rollback(); - } - em.close(); - } - } - return result; - } - -// public List<GFacJobDataResource> getGFacJobs(String serviceDescriptionId, String hostDescriptionId, String applicationDescriptionId){ -// List<GFacJobDataResource> result = new ArrayList<GFacJobDataResource>(); -// EntityManager em = ResourceUtils.getEntityManager(); -// em.getTransaction().begin(); -// QueryGenerator generator; -// Query q; -// generator = new QueryGenerator(GFAC_JOB_DATA); -// generator.setParameter(GFacJobDataConstants.SERVICE_DESC_ID, serviceDescriptionId); -// generator.setParameter(GFacJobDataConstants.HOST_DESC_ID, hostDescriptionId); -// generator.setParameter(GFacJobDataConstants.APP_DESC_ID, applicationDescriptionId); -// q = generator.selectQuery(em); -// for (Object o : q.getResultList()) { -// GFac_Job_Data gFacJobData = (GFac_Job_Data)o; -// result.add((GFacJobDataResource)Utils.getResource(ResourceType.GFAC_JOB_DATA, gFacJobData)); -// } -// em.getTransaction().commit(); -// em.close(); -// return result; -// } -// -// public List<GFacJobStatusResource> getGFacJobStatuses(String jobId){ -// List<GFacJobStatusResource> resourceList = new ArrayList<GFacJobStatusResource>(); -// EntityManager em = ResourceUtils.getEntityManager(); -// em.getTransaction().begin(); -// QueryGenerator generator; -// Query q; -// generator = new QueryGenerator(GFAC_JOB_STATUS); -// generator.setParameter(GFacJobStatusConstants.LOCAL_JOB_ID, jobId); -// q = generator.selectQuery(em); -// for (Object result : q.getResultList()) { -// GFac_Job_Status gFacJobStatus = (GFac_Job_Status) result; -// GFacJobStatusResource gFacJobStatusResource = -// (GFacJobStatusResource)Utils.getResource(ResourceType.GFAC_JOB_STATUS, gFacJobStatus); -// resourceList.add(gFacJobStatusResource); -// } -// return resourceList; -// } - - /** - * Method get all results of the given child resource type - * - * @param type child resource type - * @return list of child resources - */ - public List<ExperimentCatResource> get(ResourceType type) throws RegistryException{ - return get(type, -1, -1, null, null); - } - - /** - * Method get all results of the given child resource type with paginaltion and ordering - * - * @param type child resource type - * @param limit - * @param offset - * @param orderByIdentifier - * @param resultOrderType - * @return list of child resources - * @throws RegistryException - */ - public List<ExperimentCatResource> get(ResourceType type, int limit, int offset, Object orderByIdentifier, - ResultOrderType resultOrderType) throws RegistryException{ - List<ExperimentCatResource> result = new ArrayList<ExperimentCatResource>(); - EntityManager em = null; - try { - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - QueryGenerator generator; - Query q; - switch (type) { - case PROJECT: - generator = new QueryGenerator(PROJECT); - Users users = em.find(Users.class, getUser()); - Gateway gatewayModel = em.find(Gateway.class, gatewayId); - generator.setParameter("users", users); - if (gatewayModel != null){ - generator.setParameter("gateway", gatewayModel); - } - - //ordering - only supported only by CREATION_TIME - if(orderByIdentifier != null && resultOrderType != null - && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.CREATION_TIME)) { - q = generator.selectQuery(em, ProjectConstants.CREATION_TIME, resultOrderType); - }else{ - q = generator.selectQuery(em); - } - - //pagination - if(limit>0 && offset>=0){ - q.setFirstResult(offset); - q.setMaxResults(limit); - } - - for (Object o : q.getResultList()) { - Project project = (Project) o; - ProjectExperimentCatResource projectResource = (ProjectExperimentCatResource) Utils.getResource(ResourceType.PROJECT, project); - result.add(projectResource); - } - break; - case EXPERIMENT: - generator = new QueryGenerator(EXPERIMENT); - generator.setParameter(ExperimentConstants.EXECUTION_USER, getUser()); - - //ordering - only supported only by CREATION_TIME - if(orderByIdentifier != null && resultOrderType != null - && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.CREATION_TIME)) { - q = generator.selectQuery(em, ExperimentConstants.CREATION_TIME, resultOrderType); - }else{ - q = generator.selectQuery(em); - } - - //pagination - if(limit>0 && offset>=0){ - q.setFirstResult(offset); - q.setMaxResults(limit); - } - for (Object o : q.getResultList()) { - Experiment experiment = (Experiment) o; - ExperimentExperimentCatResource experimentResource = (ExperimentExperimentCatResource) Utils.getResource(ResourceType.EXPERIMENT, experiment); - result.add(experimentResource); - } - - break; - default: - logger.error("Unsupported resource type for worker resource.", new IllegalArgumentException()); - break; - } - em.getTransaction().commit(); - em.close(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RegistryException(e); - } finally { - if (em != null && em.isOpen()) { - if (em.getTransaction().isActive()){ - em.getTransaction().rollback(); - } - em.close(); - } - } - return result; - } - - /** - * save gateway worker to database - */ - public void save() throws RegistryException{ - EntityManager em = null; - try { - em = ExpCatResourceUtils.getEntityManager(); - Gateway_Worker existingWorker = em.find(Gateway_Worker.class, new Gateway_Worker_PK(gatewayId, user)); - em.close(); - - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - Gateway_Worker gatewayWorker = new Gateway_Worker(); - Users existingUser = em.find(Users.class, this.user); - gatewayWorker.setUser(existingUser); - gatewayWorker.setUser_name(existingUser.getUser_name()); - gatewayWorker.setGateway_id(gatewayId); - if (existingWorker != null) { - existingWorker.setUser_name(existingUser.getUser_name()); - existingWorker.setUser(existingUser); - existingWorker.setGateway_id(gatewayId); - gatewayWorker = em.merge(existingWorker); - } else { - em.persist(gatewayWorker); - } - em.getTransaction().commit(); - em.close(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RegistryException(e); - } finally { - if (em != null && em.isOpen()) { - if (em.getTransaction().isActive()){ - em.getTransaction().rollback(); - } - em.close(); - } - } - } - - /** - * - * @return user name - */ - public String getUser() { - return user; - } - - /** - * - * @param user user name - */ - public void setUser(String user) { - this.user = user; - } - - /** - * - * @param id project id - * @return whether the project is available under the user - */ - public boolean isProjectExists(String id) throws RegistryException{ - return isExists(ResourceType.PROJECT, id); - } - - /** - * - * @param projectId project id - * @return project resource for the user - */ - public ProjectExperimentCatResource createProject(String projectId) throws RegistryException{ - ProjectExperimentCatResource project=(ProjectExperimentCatResource)create(ResourceType.PROJECT); - project.setId(projectId); - return project; - } - - public String getProjectID(String projectName) { - String pro = projectName.replaceAll("\\s", ""); - return pro + "_" + UUID.randomUUID(); - } - - /** - * - * @param id project id - * @return project resource - */ - public ProjectExperimentCatResource getProject(String id) throws RegistryException{ - return (ProjectExperimentCatResource)get(ResourceType.PROJECT, id); - } - - /** - * - * @param id project id - */ - public void removeProject(String id) throws RegistryException{ - remove(ResourceType.PROJECT, id); - } - - /** - * Get projects list of user - * @return list of projects for the user - */ - public List<ProjectExperimentCatResource> getProjects() throws RegistryException{ - return getProjects(-1, -1, null, null); - } - - - /** - * Get projects list of user with pagination and ordering - * - * @return list of projects for the user - */ - public List<ProjectExperimentCatResource> getProjects(int limit, int offset, Object orderByIdentifier, - ResultOrderType resultOrderType) throws RegistryException{ - List<ProjectExperimentCatResource> result=new ArrayList<ProjectExperimentCatResource>(); - List<ExperimentCatResource> list = get(ResourceType.PROJECT, limit, offset, orderByIdentifier, resultOrderType); - for (ExperimentCatResource resource : list) { - result.add((ProjectExperimentCatResource) resource); - } - return result; - } - - /** - * - * @param name experiment name - * @return whether experiment is already exist for the given user - */ - public boolean isExperimentExists(String name) throws RegistryException{ - return isExists(ResourceType.EXPERIMENT, name); - } - - - /** - * - * @param name experiment name - * @return experiment resource - */ - public ExperimentExperimentCatResource getExperiment(String name) throws RegistryException{ - return (ExperimentExperimentCatResource)get(ResourceType.EXPERIMENT, name); - } -// -// public GFacJobDataResource getGFacJob(String jobId){ -// return (GFacJobDataResource)get(ResourceType.GFAC_JOB_DATA,jobId); -// } - - /** - * Method to get list of expeirments of user - * @return list of experiments for the user - */ - public List<ExperimentExperimentCatResource> getExperiments() throws RegistryException{ - return getExperiments(-1, -1, null, null); - } - - /** - * Method to get list of experiments of user with pagination and ordering - * @param limit - * @param offset - * @param orderByIdentifier - * @param resultOrderType - * @return - * @throws RegistryException - */ - public List<ExperimentExperimentCatResource> getExperiments(int limit, int offset, Object orderByIdentifier, - ResultOrderType resultOrderType) throws RegistryException{ - List<ExperimentExperimentCatResource> result=new ArrayList<ExperimentExperimentCatResource>(); - List<ExperimentCatResource> list = get(ResourceType.EXPERIMENT, limit, offset, orderByIdentifier, resultOrderType); - for (ExperimentCatResource resource : list) { - result.add((ExperimentExperimentCatResource) resource); - } - return result; - } - - /** - * - * @param experimentId experiment name - */ - public void removeExperiment(String experimentId) throws RegistryException{ - remove(ResourceType.EXPERIMENT, experimentId); - } - - /** - * To search the projects of user with the given filter criteria and retrieve the results with - * pagination support. Results can be ordered based on an identifier (i.e column) either ASC or - * DESC. But in the current implementation ordering is only supported based on the project - * creation time - * - * @param filters - * @param limit - * @param offset - * @param orderByIdentifier - * @param resultOrderType - * @return - * @throws RegistryException - */ - public List<ProjectExperimentCatResource> searchProjects(Map<String, String> filters, int limit, - int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException { - List<ProjectExperimentCatResource> result = new ArrayList<ProjectExperimentCatResource>(); - EntityManager em = null; - try { - String query = "SELECT p from Project p WHERE "; - if (filters != null && filters.size() != 0) { - for (String field : filters.keySet()) { - String filterVal = filters.get(field); - if (field.equals(ProjectConstants.USERNAME)) { - query += "p." + field + "= '" + filterVal + "' AND "; - }else if (field.equals(ProjectConstants.GATEWAY_ID)) { - query += "p." + field + "= '" + filterVal + "' AND "; - }else { - if (filterVal.contains("*")){ - filterVal = filterVal.replaceAll("\\*", ""); - } - query += "p." + field + " LIKE '%" + filterVal + "%' AND "; - } - } - } - query = query.substring(0, query.length() - 5); - - //ordering - if( orderByIdentifier != null && resultOrderType != null - && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.CREATION_TIME)){ - String order = (resultOrderType == ResultOrderType.ASC) ? "ASC" : "DESC"; - query += " ORDER BY p." + ProjectConstants.CREATION_TIME + " " + order; - } - - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - Query q; - - //pagination - if(offset>=0 && limit >=0){ - q = em.createQuery(query).setFirstResult(offset).setMaxResults(limit); - }else{ - q = em.createQuery(query); - } - - List resultList = q.getResultList(); - for (Object o : resultList) { - Project project = (Project) o; - ProjectExperimentCatResource projectResource = - (ProjectExperimentCatResource) Utils.getResource(ResourceType.PROJECT, project); - result.add(projectResource); - } - em.getTransaction().commit(); - em.close(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RegistryException(e); - } finally { - if (em != null && em.isOpen()) { - if (em.getTransaction().isActive()){ - em.getTransaction().rollback(); - } - em.close(); - } - } - return result; - } - - /** - * To search the experiments of user with the given time period and filter criteria and retrieve the results with - * pagination support. Results can be ordered based on an identifier (i.e column) either ASC or - * DESC. But in the current implementation ordering is only supported based on creationTime. Also if - * time period values i.e fromTime and toTime are null they will be ignored. - * - * @param fromTime - * @param toTime - * @param filters - * @param limit - * @param offset - * @param orderByIdentifier - * @param resultOrderType - * @return - * @throws RegistryException - */ - public List<ExperimentSummaryExperimentCatResource> searchExperiments(Timestamp fromTime, Timestamp toTime, Map<String, String> filters, int limit, - int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException { - List<ExperimentSummaryExperimentCatResource> result = new ArrayList(); - EntityManager em = null; - try { - String query = "SELECT e, s FROM Experiment e " + - ",Status s WHERE e.expId=s.expId AND " + - "s.statusType='" + StatusType.EXPERIMENT + "' AND "; - if(filters.get(StatusConstants.STATE) != null) { - String experimentState = ExperimentState.valueOf(filters.get(StatusConstants.STATE)).toString(); - query += "s.state='" + experimentState + "' AND "; - } - - if(toTime != null && fromTime != null && toTime.after(fromTime)){ - query += "e.creationTime > '" + fromTime + "' " + "AND e.creationTime <'" + toTime + "' AND "; - } - - filters.remove(StatusConstants.STATE); - if (filters != null && filters.size() != 0) { - for (String field : filters.keySet()) { - String filterVal = filters.get(field); - if (field.equals(ExperimentConstants.EXECUTION_USER)) { - query += "e." + field + "= '" + filterVal + "' AND "; - }else if (field.equals(ExperimentConstants.GATEWAY_ID)) { - query += "e." + field + "= '" + filterVal + "' AND "; - } else if (field.equals(ExperimentConstants.PROJECT_ID)) { - query += "e." + field + "= '" + filterVal + "' AND "; - } else { - if (filterVal.contains("*")){ - filterVal = filterVal.replaceAll("\\*", ""); - } - query += "e." + field + " LIKE '%" + filterVal + "%' AND "; - } - } - } - query = query.substring(0, query.length() - 5); - - //ordering - if( orderByIdentifier != null && resultOrderType != null - && orderByIdentifier.equals(Constants.FieldConstants.ExperimentConstants.CREATION_TIME)){ - String order = (resultOrderType == ResultOrderType.ASC) ? "ASC" : "DESC"; - query += " ORDER BY e." + ExperimentConstants.CREATION_TIME + " " + order; - } - - em = ExpCatResourceUtils.getEntityManager(); - em.getTransaction().begin(); - Query q; - - //pagination - if(offset>=0 && limit >=0){ - q = em.createQuery(query).setFirstResult(offset).setMaxResults(limit); - }else{ - q = em.createQuery(query); - } - OpenJPAQuery kq = OpenJPAPersistence.cast(q); - JDBCFetchPlan fetch = (JDBCFetchPlan) kq.getFetchPlan(); - fetch.setEagerFetchMode(FetchMode.JOIN); - - List resultList = q.getResultList(); - for (Object o : resultList) { - Experiment experiment = (Experiment) ((Object[])o)[0]; - Status experimentStatus = (Status) ((Object[])o)[1]; - experiment.setExperimentStatus(experimentStatus); - ExperimentSummaryExperimentCatResource experimentSummaryResource = - (ExperimentSummaryExperimentCatResource) Utils.getResource(ResourceType.EXPERIMENT_SUMMARY, experiment); - result.add(experimentSummaryResource); - } - em.getTransaction().commit(); - em.close(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RegistryException(e); - } finally { - if (em != null && em.isOpen()) { - if (em.getTransaction().isActive()){ - em.getTransaction().rollback(); - } - em.close(); - } - } - return result; - } - - /** - * - * @return list of experiments for the user - */ - public List<ExperimentExperimentCatResource> getExperimentsByCaching(String user) throws RegistryException{ - List<ExperimentExperimentCatResource> result = new ArrayList<ExperimentExperimentCatResource>(); - EntityManager em = null; - try { - String query = "SELECT e from Experiment e WHERE e.executionUser = '" + user + "'"; - em = ExpCatResourceUtils.getEntityManager(); -// OpenJPAEntityManagerFactory oemf = OpenJPAPersistence.cast(em.getEntityManagerFactory()); -// QueryResultCache qcache = oemf.getQueryResultCache(); - // qcache.evictAll(Experiment.class); - em.getTransaction().begin(); - Query q = em.createQuery(query); - List resultList = q.getResultList(); - for (Object o : resultList) { - Experiment experiment = (Experiment) o; - ExperimentExperimentCatResource experimentResource = (ExperimentExperimentCatResource) Utils.getResource(ResourceType.EXPERIMENT, experiment); - result.add(experimentResource); - } - em.getTransaction().commit(); - em.close(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RegistryException(e); - } finally { - if (em != null && em.isOpen()) { - if (em.getTransaction().isActive()){ - em.getTransaction().rollback(); - } - em.close(); - } - } - return result; - } -}
