Search in sources :

Example 11 with QueryGenerator

use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.

the class JobResource method get.

public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException {
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        QueryGenerator generator;
        Query q;
        switch(type) {
            case JOB_STATUS:
                generator = new QueryGenerator(JOB_STATUS);
                generator.setParameter(JobStatusConstants.STATUS_ID, name);
                q = generator.selectQuery(em);
                JobStatus status = (JobStatus) q.getSingleResult();
                JobStatusResource statusResource = (JobStatusResource) Utils.getResource(ResourceType.JOB_STATUS, status);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return statusResource;
            default:
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                logger.error("Unsupported resource type for Job resource.", new IllegalArgumentException());
                throw new IllegalArgumentException("Unsupported resource type for Job resource.");
        }
    } 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();
        }
    }
}
Also used : JobStatus(org.apache.airavata.registry.core.experiment.catalog.model.JobStatus) EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) Query(javax.persistence.Query) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 12 with QueryGenerator

use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.

the class NotificationResource method getAllNotifications.

public List<ExperimentCatResource> getAllNotifications(String gatewayId) throws RegistryException {
    List<ExperimentCatResource> resourceList = new ArrayList<ExperimentCatResource>();
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        QueryGenerator generator = new QueryGenerator(NOTIFICATION);
        generator.setParameter(NotificationConstants.GATEWAY_ID, gatewayId);
        Query q = generator.selectQuery(em);
        List<?> results = q.getResultList();
        if (results.size() != 0) {
            for (Object result : results) {
                Notification notification = (Notification) result;
                NotificationResource notificationResource = (NotificationResource) Utils.getResource(ResourceType.NOTIFICATION, notification);
                resourceList.add(notificationResource);
            }
        }
        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 resourceList;
}
Also used : EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) RegistryException(org.apache.airavata.registry.cpi.RegistryException) Notification(org.apache.airavata.registry.core.experiment.catalog.model.Notification) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Example 13 with QueryGenerator

use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.

the class NotificationResource method remove.

/**
 * @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();
        QueryGenerator generator = new QueryGenerator(NOTIFICATION);
        generator.setParameter(NotificationConstants.NOTIFICATION_ID, name);
        Query q = generator.deleteQuery(em);
        q.executeUpdate();
        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();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) Query(javax.persistence.Query) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 14 with QueryGenerator

use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.

the class ProcessResource method get.

public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException {
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        QueryGenerator generator;
        Query q;
        switch(type) {
            case PROCESS_STATUS:
                generator = new QueryGenerator(PROCESS_STATUS);
                generator.setParameter(ProcessStatusConstants.STATUS_ID, name);
                q = generator.selectQuery(em);
                ProcessStatus status = (ProcessStatus) q.getSingleResult();
                ProcessStatusResource statusResource = (ProcessStatusResource) Utils.getResource(ResourceType.PROCESS_STATUS, status);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return statusResource;
            case PROCESS_ERROR:
                generator = new QueryGenerator(PROCESS_ERROR);
                generator.setParameter(ProcessErrorConstants.ERROR_ID, name);
                q = generator.selectQuery(em);
                ProcessError processError = (ProcessError) q.getSingleResult();
                ProcessErrorResource processErrorResource = (ProcessErrorResource) Utils.getResource(ResourceType.PROCESS_ERROR, processError);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return processErrorResource;
            case PROCESS_INPUT:
                generator = new QueryGenerator(PROCESS_INPUT);
                generator.setParameter(ProcessInputConstants.INPUT_NAME, name);
                generator.setParameter(ProcessInputConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                ProcessInput processInput = (ProcessInput) q.getSingleResult();
                ProcessInputResource processInputResource = (ProcessInputResource) Utils.getResource(ResourceType.PROCESS_INPUT, processInput);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return processInputResource;
            case PROCESS_OUTPUT:
                generator = new QueryGenerator(PROCESS_OUTPUT);
                generator.setParameter(ProcessOutputConstants.OUTPUT_NAME, name);
                generator.setParameter(ProcessInputConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                ProcessOutput processOutput = (ProcessOutput) q.getSingleResult();
                ProcessOutputResource outputResource = (ProcessOutputResource) Utils.getResource(ResourceType.PROCESS_OUTPUT, processOutput);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return outputResource;
            case PROCESS_RESOURCE_SCHEDULE:
                generator = new QueryGenerator(PROCESS_RESOURCE_SCHEDULE);
                generator.setParameter(ProcessResourceScheduleConstants.PROCESS_ID, name);
                q = generator.selectQuery(em);
                ProcessResourceSchedule processResourceSchedule = (ProcessResourceSchedule) q.getSingleResult();
                ProcessResourceScheduleResource processResourceScheduleResource = (ProcessResourceScheduleResource) Utils.getResource(ResourceType.PROCESS_RESOURCE_SCHEDULE, processResourceSchedule);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return processResourceScheduleResource;
            case TASK:
                generator = new QueryGenerator(TASK);
                generator.setParameter(TaskConstants.TASK_ID, name);
                q = generator.selectQuery(em);
                Task task = (Task) q.getSingleResult();
                TaskResource taskResource = (TaskResource) Utils.getResource(ResourceType.TASK, task);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return taskResource;
            case JOB:
                generator = new QueryGenerator(JOB);
                generator.setParameter(JobConstants.JOB_ID, name);
                generator.setParameter(JobConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                Job job = (Job) q.getSingleResult();
                JobResource jobResource = (JobResource) Utils.getResource(ResourceType.JOB, job);
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                return jobResource;
            default:
                em.getTransaction().commit();
                if (em.isOpen()) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    em.close();
                }
                logger.error("Unsupported resource type for process resource.", new IllegalArgumentException());
                throw new IllegalArgumentException("Unsupported resource type for process resource.");
        }
    } catch (Exception e) {
        throw new RegistryException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : Query(javax.persistence.Query) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator)

Example 15 with QueryGenerator

use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.

the class ProcessResource method get.

public List<ExperimentCatResource> get(ResourceType type) throws RegistryException {
    List<ExperimentCatResource> resourceList = new ArrayList<ExperimentCatResource>();
    EntityManager em = null;
    try {
        em = ExpCatResourceUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        QueryGenerator generator;
        List results;
        switch(type) {
            case PROCESS_INPUT:
                generator = new QueryGenerator(PROCESS_INPUT);
                generator.setParameter(ProcessInputConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        ProcessInput processInput = (ProcessInput) result;
                        ProcessInputResource processInputResource = (ProcessInputResource) Utils.getResource(ResourceType.PROCESS_INPUT, processInput);
                        resourceList.add(processInputResource);
                    }
                }
                break;
            case PROCESS_OUTPUT:
                generator = new QueryGenerator(PROCESS_OUTPUT);
                generator.setParameter(ProcessOutputConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        ProcessOutput processOutput = (ProcessOutput) result;
                        ProcessOutputResource processOutputResource = (ProcessOutputResource) Utils.getResource(ResourceType.PROCESS_OUTPUT, processOutput);
                        resourceList.add(processOutputResource);
                    }
                }
                break;
            case TASK:
                generator = new QueryGenerator(TASK);
                generator.setParameter(TaskConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        Task task = (Task) result;
                        TaskResource taskResource = (TaskResource) Utils.getResource(ResourceType.TASK, task);
                        resourceList.add(taskResource);
                    }
                }
                break;
            case PROCESS_ERROR:
                generator = new QueryGenerator(PROCESS_ERROR);
                generator.setParameter(ProcessErrorConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        ProcessError processError = (ProcessError) result;
                        ProcessErrorResource processErrorResource = (ProcessErrorResource) Utils.getResource(ResourceType.PROCESS_ERROR, processError);
                        resourceList.add(processErrorResource);
                    }
                }
                break;
            case PROCESS_STATUS:
                generator = new QueryGenerator(PROCESS_STATUS);
                generator.setParameter(ProcessStatusConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        ProcessStatus processStatus = (ProcessStatus) result;
                        ProcessStatusResource processStatusResource = (ProcessStatusResource) Utils.getResource(ResourceType.PROCESS_STATUS, processStatus);
                        resourceList.add(processStatusResource);
                    }
                }
                break;
            case JOB:
                generator = new QueryGenerator(JOB);
                generator.setParameter(JobConstants.PROCESS_ID, processId);
                q = generator.selectQuery(em);
                results = q.getResultList();
                if (results.size() != 0) {
                    for (Object result : results) {
                        Job job = (Job) result;
                        JobResource jobResource = (JobResource) Utils.getResource(ResourceType.JOB, job);
                        resourceList.add(jobResource);
                    }
                }
                break;
            default:
                logger.error("Unsupported resource type for task resource.", new UnsupportedOperationException());
                throw new UnsupportedOperationException();
        }
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            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 resourceList;
}
Also used : Query(javax.persistence.Query) ArrayList(java.util.ArrayList) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) ArrayList(java.util.ArrayList) List(java.util.List) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Aggregations

QueryGenerator (org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator)31 RegistryException (org.apache.airavata.registry.cpi.RegistryException)31 EntityManager (javax.persistence.EntityManager)25 Query (javax.persistence.Query)25 ArrayList (java.util.ArrayList)11 ExperimentCatResource (org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)10 List (java.util.List)8 ExperimentCatalogException (org.apache.airavata.registry.cpi.ExperimentCatalogException)6 Job (org.apache.airavata.registry.core.experiment.catalog.model.Job)2 JobStatus (org.apache.airavata.registry.core.experiment.catalog.model.JobStatus)2 Notification (org.apache.airavata.registry.core.experiment.catalog.model.Notification)2 Process (org.apache.airavata.registry.core.experiment.catalog.model.Process)2 TaskError (org.apache.airavata.registry.core.experiment.catalog.model.TaskError)2 TaskStatus (org.apache.airavata.registry.core.experiment.catalog.model.TaskStatus)2