Search in sources :

Example 6 with Workflow

use of org.apache.airavata.registry.core.workflow.catalog.model.Workflow in project airavata by apache.

the class WorkflowResource method getAll.

@Override
public List<WorkflowCatalogResource> getAll() throws WorkflowCatalogException {
    List<WorkflowCatalogResource> workflows = new ArrayList<WorkflowCatalogResource>();
    EntityManager em = null;
    try {
        em = WorkflowCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW);
        generator.setParameter(WorkflowConstants.GATEWAY_ID, gatewayId);
        Query q = generator.selectQuery(em);
        List results = q.getResultList();
        if (results.size() != 0) {
            for (Object result : results) {
                Workflow workflow = (Workflow) result;
                WorkflowResource wfResource = (WorkflowResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.WORKFLOW, workflow);
                workflows.add(wfResource);
            }
        }
        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();
        }
    }
    return workflows;
}
Also used : 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) ArrayList(java.util.ArrayList) Workflow(org.apache.airavata.registry.core.workflow.catalog.model.Workflow) ArrayList(java.util.ArrayList) List(java.util.List) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException)

Example 7 with Workflow

use of org.apache.airavata.registry.core.workflow.catalog.model.Workflow in project airavata by apache.

the class EdgeResource method save.

public void save() throws WorkflowCatalogException {
    EntityManager em = null;
    try {
        em = WorkflowCatalogJPAUtils.getEntityManager();
        Edge existingEdge = em.find(Edge.class, new Edge_PK(templateId, edgeId));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = WorkflowCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingEdge != null) {
            existingEdge.setTemplateId(templateId);
            Workflow workflow = em.find(Workflow.class, templateId);
            existingEdge.setWorkflow(workflow);
            existingEdge.setComponentStatusId(statusId);
            existingEdge.setDescription(description);
            existingEdge.setName(name);
            existingEdge.setCreatedTime(createdTime);
            em.merge(existingEdge);
        } else {
            Edge edge = new Edge();
            edge.setTemplateId(templateId);
            Workflow workflow = em.find(Workflow.class, templateId);
            edge.setWorkflow(workflow);
            edge.setComponentStatusId(statusId);
            edge.setDescription(description);
            edge.setName(name);
            edge.setCreatedTime(AiravataUtils.getCurrentTimestamp());
            em.persist(edge);
        }
        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 : Edge_PK(org.apache.airavata.registry.core.workflow.catalog.model.Edge_PK) EntityManager(javax.persistence.EntityManager) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException) Workflow(org.apache.airavata.registry.core.workflow.catalog.model.Workflow) Edge(org.apache.airavata.registry.core.workflow.catalog.model.Edge) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException)

Example 8 with Workflow

use of org.apache.airavata.registry.core.workflow.catalog.model.Workflow in project airavata by apache.

the class NodeResource method save.

public void save() throws WorkflowCatalogException {
    EntityManager em = null;
    try {
        em = WorkflowCatalogJPAUtils.getEntityManager();
        Node existingNode = em.find(Node.class, new Node_PK(templateId, nodeId));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = WorkflowCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingNode != null) {
            existingNode.setTemplateId(templateId);
            Workflow workflow = em.find(Workflow.class, templateId);
            existingNode.setWorkflow(workflow);
            existingNode.setComponentStatusId(statusId);
            existingNode.setDescription(description);
            existingNode.setName(name);
            existingNode.setCreatedTime(createdTime);
            existingNode.setApplicationName(applicationName);
            existingNode.setApplicationId(applicationId);
            em.merge(existingNode);
        } else {
            Node node = new Node();
            node.setTemplateId(templateId);
            Workflow workflow = em.find(Workflow.class, templateId);
            node.setWorkflow(workflow);
            node.setComponentStatusId(statusId);
            node.setDescription(description);
            node.setName(name);
            node.setCreatedTime(AiravataUtils.getCurrentTimestamp());
            node.setApplicationName(applicationName);
            node.setApplicationId(applicationId);
            em.persist(node);
        }
        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) Node(org.apache.airavata.registry.core.workflow.catalog.model.Node) Node_PK(org.apache.airavata.registry.core.workflow.catalog.model.Node_PK) 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 9 with Workflow

use of org.apache.airavata.registry.core.workflow.catalog.model.Workflow in project airavata by apache.

the class PortResource method save.

public void save() throws WorkflowCatalogException {
    EntityManager em = null;
    try {
        em = WorkflowCatalogJPAUtils.getEntityManager();
        Port existingPort = em.find(Port.class, new Port_PK(templateId, portId));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = WorkflowCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingPort != null) {
            existingPort.setTemplateId(templateId);
            Workflow workflow = em.find(Workflow.class, templateId);
            existingPort.setWorkflow(workflow);
            existingPort.setComponentStatusId(statusId);
            existingPort.setDescription(description);
            existingPort.setName(name);
            existingPort.setCreatedTime(createdTime);
            em.merge(existingPort);
        } else {
            Port edge = new Port();
            edge.setTemplateId(templateId);
            Workflow workflow = em.find(Workflow.class, templateId);
            edge.setWorkflow(workflow);
            edge.setComponentStatusId(statusId);
            edge.setDescription(description);
            edge.setName(name);
            edge.setCreatedTime(AiravataUtils.getCurrentTimestamp());
            em.persist(edge);
        }
        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 : Port_PK(org.apache.airavata.registry.core.workflow.catalog.model.Port_PK) EntityManager(javax.persistence.EntityManager) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException) Port(org.apache.airavata.registry.core.workflow.catalog.model.Port) 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 10 with Workflow

use of org.apache.airavata.registry.core.workflow.catalog.model.Workflow in project airavata by apache.

the class WorkflowOutputResource method save.

public void save() throws WorkflowCatalogException {
    EntityManager em = null;
    try {
        em = WorkflowCatalogJPAUtils.getEntityManager();
        WorkflowOutput existingWorkflowOutput = em.find(WorkflowOutput.class, new WorkflowOutput_PK(wfTemplateId, outputKey));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = WorkflowCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingWorkflowOutput != null) {
            existingWorkflowOutput.setTemplateId(wfTemplateId);
            Workflow workflow = em.find(Workflow.class, wfTemplateId);
            existingWorkflowOutput.setWorkflow(workflow);
            existingWorkflowOutput.setDataType(dataType);
            existingWorkflowOutput.setOutputKey(outputKey);
            if (outputVal != null) {
                existingWorkflowOutput.setOutputVal(outputVal.toCharArray());
            }
            existingWorkflowOutput.setDataMovement(dataMovement);
            existingWorkflowOutput.setDataNameLocation(dataNameLocation);
            em.merge(existingWorkflowOutput);
        } else {
            WorkflowOutput workflowOutput = new WorkflowOutput();
            workflowOutput.setTemplateId(wfTemplateId);
            Workflow workflow = em.find(Workflow.class, wfTemplateId);
            workflowOutput.setWorkflow(workflow);
            workflowOutput.setDataType(dataType);
            workflowOutput.setOutputKey(outputKey);
            if (outputVal != null) {
                workflowOutput.setOutputVal(outputVal.toCharArray());
            }
            workflowOutput.setDataMovement(dataMovement);
            workflowOutput.setDataNameLocation(dataNameLocation);
            em.persist(workflowOutput);
        }
        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 : WorkflowOutput(org.apache.airavata.registry.core.workflow.catalog.model.WorkflowOutput) 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) WorkflowOutput_PK(org.apache.airavata.registry.core.workflow.catalog.model.WorkflowOutput_PK)

Aggregations

EntityManager (javax.persistence.EntityManager)14 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)14 Workflow (org.apache.airavata.registry.core.workflow.catalog.model.Workflow)14 WorkflowCatalogException (org.apache.airavata.registry.cpi.WorkflowCatalogException)14 Query (javax.persistence.Query)5 WorkflowCatalogQueryGenerator (org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator)5 ArrayList (java.util.ArrayList)4 List (java.util.List)2 ComponentStatus (org.apache.airavata.registry.core.workflow.catalog.model.ComponentStatus)1 Edge (org.apache.airavata.registry.core.workflow.catalog.model.Edge)1 Edge_PK (org.apache.airavata.registry.core.workflow.catalog.model.Edge_PK)1 Node (org.apache.airavata.registry.core.workflow.catalog.model.Node)1 Node_PK (org.apache.airavata.registry.core.workflow.catalog.model.Node_PK)1 Port (org.apache.airavata.registry.core.workflow.catalog.model.Port)1 Port_PK (org.apache.airavata.registry.core.workflow.catalog.model.Port_PK)1 WorkflowInput (org.apache.airavata.registry.core.workflow.catalog.model.WorkflowInput)1 WorkflowInput_PK (org.apache.airavata.registry.core.workflow.catalog.model.WorkflowInput_PK)1 WorkflowOutput (org.apache.airavata.registry.core.workflow.catalog.model.WorkflowOutput)1 WorkflowOutput_PK (org.apache.airavata.registry.core.workflow.catalog.model.WorkflowOutput_PK)1 WorkflowStatus (org.apache.airavata.registry.core.workflow.catalog.model.WorkflowStatus)1