Search in sources :

Example 6 with WorkflowCatalogException

use of org.apache.airavata.registry.cpi.WorkflowCatalogException in project airavata by apache.

the class WorkflowResource method save.

@Override
public void save() throws WorkflowCatalogException {
    EntityManager em = null;
    try {
        em = WorkflowCatalogJPAUtils.getEntityManager();
        Workflow existingWorkflow = em.find(Workflow.class, wfTemplateId);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        Workflow workflow;
        em = WorkflowCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingWorkflow == null) {
            workflow = new Workflow();
            workflow.setCreationTime(AiravataUtils.getCurrentTimestamp());
        } else {
            workflow = existingWorkflow;
            workflow.setUpdateTime(AiravataUtils.getCurrentTimestamp());
        }
        workflow.setWorkflowName(getWfName());
        workflow.setCreatedUser(getCreatedUser());
        workflow.setGatewayId(gatewayId);
        if (getGraph() != null) {
            workflow.setGraph(getGraph().toCharArray());
        }
        if (image != null) {
            workflow.setImage(image.getBytes());
        }
        workflow.setTemplateId(getWfTemplateId());
        if (existingWorkflow == null) {
            em.persist(workflow);
        } else {
            em.merge(workflow);
        }
        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 WorkflowCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException) Workflow(org.apache.airavata.registry.core.workflow.catalog.model.Workflow) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException)

Example 7 with WorkflowCatalogException

use of org.apache.airavata.registry.cpi.WorkflowCatalogException in project airavata by apache.

the class WorkflowResource method get.

@Override
public List<WorkflowCatalogResource> get(String fieldName, Object value) throws WorkflowCatalogException {
    List<WorkflowCatalogResource> workflowResources = new ArrayList<WorkflowCatalogResource>();
    EntityManager em = null;
    try {
        em = WorkflowCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW);
        Query q;
        if ((fieldName.equals(WorkflowConstants.TEMPLATE_ID)) || (fieldName.equals(WorkflowConstants.GATEWAY_ID))) {
            generator.setParameter(fieldName, value);
            q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            for (Object result : results) {
                Workflow workflow = (Workflow) result;
                WorkflowResource workflowResource = (WorkflowResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.WORKFLOW, workflow);
                workflowResources.add(workflowResource);
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Workflow Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Workflow Resource.");
        }
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new WorkflowCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
    return workflowResources;
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) Workflow(org.apache.airavata.registry.core.workflow.catalog.model.Workflow) EntityManager(javax.persistence.EntityManager) WorkflowCatalogQueryGenerator(org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator)

Example 8 with WorkflowCatalogException

use of org.apache.airavata.registry.cpi.WorkflowCatalogException in project airavata by apache.

the class WorkflowResource method getIds.

@Override
public List<String> getIds(String fieldName, Object value) throws WorkflowCatalogException {
    List<String> workflowResourceIDs = new ArrayList<String>();
    EntityManager em = null;
    try {
        em = WorkflowCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW);
        Query q;
        if ((fieldName.equals(WorkflowConstants.TEMPLATE_ID)) || (fieldName.equals(WorkflowConstants.GATEWAY_ID))) {
            generator.setParameter(fieldName, value);
            q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            for (Object result : results) {
                Workflow workflow = (Workflow) result;
                WorkflowResource workflowResource = (WorkflowResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.WORKFLOW, workflow);
                workflowResourceIDs.add(workflowResource.getWfTemplateId());
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Workflow Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Workflow Resource.");
        }
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new WorkflowCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
    return workflowResourceIDs;
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) Workflow(org.apache.airavata.registry.core.workflow.catalog.model.Workflow) EntityManager(javax.persistence.EntityManager) WorkflowCatalogQueryGenerator(org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator)

Example 9 with WorkflowCatalogException

use of org.apache.airavata.registry.cpi.WorkflowCatalogException in project airavata by apache.

the class WorkflowResource method isExists.

@Override
public boolean isExists(Object identifier) throws WorkflowCatalogException {
    EntityManager em = null;
    try {
        em = WorkflowCatalogJPAUtils.getEntityManager();
        Workflow workflow = em.find(Workflow.class, identifier);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return workflow != null;
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new WorkflowCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) EntityManager(javax.persistence.EntityManager) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException) Workflow(org.apache.airavata.registry.core.workflow.catalog.model.Workflow)

Example 10 with WorkflowCatalogException

use of org.apache.airavata.registry.cpi.WorkflowCatalogException in project airavata by apache.

the class WorkflowResource method remove.

@Override
public void remove(Object identifier) throws WorkflowCatalogException {
    EntityManager em = null;
    try {
        em = WorkflowCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW);
        generator.setParameter(WorkflowConstants.TEMPLATE_ID, identifier);
        Query q = generator.deleteQuery(em);
        q.executeUpdate();
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new WorkflowCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) EntityManager(javax.persistence.EntityManager) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException) Query(javax.persistence.Query) WorkflowCatalogQueryGenerator(org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator)

Aggregations

WorkflowCatalogException (org.apache.airavata.registry.cpi.WorkflowCatalogException)57 EntityManager (javax.persistence.EntityManager)50 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)50 Query (javax.persistence.Query)34 WorkflowCatalogQueryGenerator (org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator)34 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)19 Map (java.util.Map)18 List (java.util.List)16 Workflow (org.apache.airavata.registry.core.workflow.catalog.model.Workflow)14 ComponentStatus (org.apache.airavata.registry.core.workflow.catalog.model.ComponentStatus)5 Edge (org.apache.airavata.registry.core.workflow.catalog.model.Edge)5 Node (org.apache.airavata.registry.core.workflow.catalog.model.Node)5 Port (org.apache.airavata.registry.core.workflow.catalog.model.Port)5 WorkflowInput (org.apache.airavata.registry.core.workflow.catalog.model.WorkflowInput)5 WorkflowOutput (org.apache.airavata.registry.core.workflow.catalog.model.WorkflowOutput)5 WorkflowStatus (org.apache.airavata.registry.core.workflow.catalog.model.WorkflowStatus)5 InputDataObjectType (org.apache.airavata.model.application.io.InputDataObjectType)2 OutputDataObjectType (org.apache.airavata.model.application.io.OutputDataObjectType)2 Edge_PK (org.apache.airavata.registry.core.workflow.catalog.model.Edge_PK)2