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();
}
}
}
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;
}
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;
}
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();
}
}
}
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();
}
}
}
Aggregations