Search in sources :

Example 1 with Workflow

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

the class WorkflowInputResource method save.

public void save() throws WorkflowCatalogException {
    EntityManager em = null;
    try {
        em = WorkflowCatalogJPAUtils.getEntityManager();
        WorkflowInput existingWFInput = em.find(WorkflowInput.class, new WorkflowInput_PK(wfTemplateId, inputKey));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        WorkflowInput workflowInput;
        em = WorkflowCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingWFInput == null) {
            workflowInput = new WorkflowInput();
        } else {
            workflowInput = existingWFInput;
        }
        workflowInput.setTemplateID(wfTemplateId);
        Workflow workflow = em.find(Workflow.class, wfTemplateId);
        workflowInput.setWorkflow(workflow);
        workflowInput.setDataType(dataType);
        workflowInput.setInputKey(inputKey);
        if (inputVal != null) {
            workflowInput.setInputVal(inputVal.toCharArray());
        }
        workflowInput.setMetadata(metadata);
        workflowInput.setAppArgument(appArgument);
        workflowInput.setUserFriendlyDesc(userFriendlyDesc);
        workflowInput.setStandardInput(standardInput);
        workflowInput.setRequiredToCMD(requiredToCMD);
        workflowInput.setRequired(isRequired);
        workflowInput.setDataStaged(dataStaged);
        if (existingWFInput == null) {
            em.persist(workflowInput);
        } else {
            em.merge(workflowInput);
        }
        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) WorkflowInput(org.apache.airavata.registry.core.workflow.catalog.model.WorkflowInput) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) WorkflowCatalogException(org.apache.airavata.registry.cpi.WorkflowCatalogException) WorkflowInput_PK(org.apache.airavata.registry.core.workflow.catalog.model.WorkflowInput_PK)

Example 2 with Workflow

use of org.apache.airavata.registry.core.workflow.catalog.model.Workflow 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 3 with Workflow

use of org.apache.airavata.registry.core.workflow.catalog.model.Workflow 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 4 with Workflow

use of org.apache.airavata.registry.core.workflow.catalog.model.Workflow 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 5 with Workflow

use of org.apache.airavata.registry.core.workflow.catalog.model.Workflow 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)

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