use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.
the class NotificationResource method get.
/**
* @param type child resource type
* @param name child resource name
* @return UnsupportedOperationException
*/
public ExperimentCatResource get(ResourceType type, Object notificationId) throws RegistryException {
EntityManager em = null;
try {
if (!type.equals(ResourceType.NOTIFICATION)) {
logger.error("Unsupported resource type for Notification resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported resource type for Notification resource.");
}
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(NOTIFICATION);
generator.setParameter(NotificationConstants.NOTIFICATION_ID, notificationId);
Query q = generator.selectQuery(em);
Notification notification = (Notification) q.getSingleResult();
em.getTransaction().commit();
em.close();
if (notification != null)
return Utils.getResource(ResourceType.NOTIFICATION, notification);
else
return null;
} 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();
}
}
}
use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.
the class ProcessResource method remove.
public void remove(ResourceType type, Object name) throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
Query q;
QueryGenerator generator;
switch(type) {
case PROCESS_ERROR:
generator = new QueryGenerator(PROCESS_ERROR);
generator.setParameter(ProcessErrorConstants.ERROR_ID, name);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
case PROCESS_STATUS:
generator = new QueryGenerator(PROCESS_STATUS);
generator.setParameter(ProcessStatusConstants.STATUS_ID, name);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
case PROCESS_INPUT:
generator = new QueryGenerator(PROCESS_INPUT);
generator.setParameter(ProcessInputConstants.INPUT_NAME, name);
generator.setParameter(ProcessInputConstants.PROCESS_ID, processId);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
case PROCESS_OUTPUT:
generator = new QueryGenerator(PROCESS_OUTPUT);
generator.setParameter(ProcessOutputConstants.OUTPUT_NAME, name);
generator.setParameter(ProcessOutputConstants.PROCESS_ID, processId);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
case PROCESS_RESOURCE_SCHEDULE:
generator = new QueryGenerator(PROCESS_RESOURCE_SCHEDULE);
generator.setParameter(ProcessResourceScheduleConstants.PROCESS_ID, processId);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
case TASK:
generator = new QueryGenerator(TASK);
generator.setParameter(TaskConstants.TASK_ID, name);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
case JOB:
generator = new QueryGenerator(JOB);
generator.setParameter(JobConstants.JOB_ID, name);
generator.setParameter(JobConstants.PROCESS_ID, processId);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
default:
logger.error("Unsupported resource type for process detail resource.", new IllegalArgumentException());
break;
}
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();
}
}
}
use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.
the class ProjectResource method get.
/**
* @param type child resource type
* @param name child resource name
* @return child resource
*/
public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException {
EntityManager em = null;
try {
if (type == ResourceType.EXPERIMENT) {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(EXPERIMENT);
generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
Query q = generator.selectQuery(em);
Experiment experiment = (Experiment) q.getSingleResult();
ExperimentResource experimentResource = (ExperimentResource) Utils.getResource(ResourceType.EXPERIMENT, experiment);
em.getTransaction().commit();
em.close();
return experimentResource;
} else if (type == ResourceType.PROJECT_USER) {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(PROJECT_USER);
generator.setParameter(ProjectUserConstants.USERNAME, name);
generator.setParameter(ProjectUserConstants.PROJECT_ID, this.id);
Query q = generator.selectQuery(em);
ProjectUser prUser = (ProjectUser) q.getSingleResult();
ExperimentResource experimentResource = (ExperimentResource) Utils.getResource(ResourceType.PROJECT_USER, prUser);
em.getTransaction().commit();
em.close();
return experimentResource;
} else {
logger.error("Unsupported resource type for project resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported resource type for project resource.");
}
} catch (Exception e) {
throw new RegistryException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
}
use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.
the class ProjectResource 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();
if (type == ResourceType.EXPERIMENT) {
QueryGenerator generator = new QueryGenerator(EXPERIMENT);
generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
Query q = generator.deleteQuery(em);
q.executeUpdate();
} else if (type == ResourceType.PROJECT_USER) {
QueryGenerator generator = new QueryGenerator(PROJECT_USER);
generator.setParameter(ProjectUserConstants.USERNAME, name);
generator.setParameter(ProjectUserConstants.PROJECT_ID, this.id);
Query q = generator.deleteQuery(em);
q.executeUpdate();
} else {
em.getTransaction().commit();
em.close();
logger.error("Unsupported resource type for project resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported resource type for project resource.");
}
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();
}
}
}
use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.
the class TaskResource 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 TASK_ERROR:
generator = new QueryGenerator(TASK_ERROR);
generator.setParameter(TaskErrorConstants.TASK_ID, taskId);
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
TaskError taskError = (TaskError) result;
TaskErrorResource taskErrorResource = (TaskErrorResource) Utils.getResource(ResourceType.TASK_ERROR, taskError);
resourceList.add(taskErrorResource);
}
}
break;
case TASK_STATUS:
generator = new QueryGenerator(TASK_STATUS);
generator.setParameter(TaskStatusConstants.TASK_ID, taskId);
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
TaskStatus taskStatus = (TaskStatus) result;
TaskStatusResource taskStatusResource = (TaskStatusResource) Utils.getResource(ResourceType.TASK_STATUS, taskStatus);
resourceList.add(taskStatusResource);
}
}
break;
case JOB:
generator = new QueryGenerator(JOB);
generator.setParameter(JobConstants.TASK_ID, taskId);
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;
}
Aggregations