use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.
the class ExpCatResourceUtils method isUserExist.
public static boolean isUserExist(String username, String gatewayId) throws RegistryException {
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(AbstractExpCatResource.USERS);
generator.setParameter(AbstractExpCatResource.UserConstants.USERNAME, username);
generator.setParameter(AbstractExpCatResource.UserConstants.GATEWAY_ID, gatewayId);
Query q = generator.selectQuery(em);
int size = q.getResultList().size();
em.getTransaction().commit();
em.close();
return size > 0;
} 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 ExpCatResourceUtils method removeGatewayWorker.
/**
* @param gatewayResource
* @param userResource
* @return
*/
public static boolean removeGatewayWorker(GatewayResource gatewayResource, UserResource userResource) {
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(AbstractExpCatResource.GATEWAY_WORKER);
generator.setParameter(AbstractExpCatResource.GatewayWorkerConstants.GATEWAY_ID, gatewayResource.getGatewayName());
generator.setParameter(AbstractExpCatResource.UserConstants.USERNAME, userResource.getUserName());
Query q = generator.deleteQuery(em);
q.executeUpdate();
em.getTransaction().commit();
em.close();
return true;
} catch (Exception e) {
logger.error(e.getMessage(), e);
return false;
} 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 GatewayResource method get.
/**
* Gateway can get information of his children
* @param type child resource type
* @param name child resource name
* @return specific child resource type
*/
public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator;
Query q;
switch(type) {
case GATEWAY_WORKER:
generator = new QueryGenerator(GATEWAY_WORKER);
generator.setParameter(GatewayWorkerConstants.USERNAME, name);
generator.setParameter(GatewayWorkerConstants.GATEWAY_ID, gatewayId);
q = generator.selectQuery(em);
GatewayWorker worker = (GatewayWorker) q.getSingleResult();
WorkerResource workerResource = (WorkerResource) Utils.getResource(ResourceType.GATEWAY_WORKER, worker);
em.getTransaction().commit();
em.close();
return workerResource;
case USER:
generator = new QueryGenerator(USERS);
generator.setParameter(UserConstants.USERNAME, name);
q = generator.selectQuery(em);
Users user = (Users) q.getSingleResult();
UserResource userResource = (UserResource) Utils.getResource(ResourceType.USER, user);
em.getTransaction().commit();
em.close();
return userResource;
case EXPERIMENT:
generator = new QueryGenerator(EXPERIMENT);
generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
q = generator.selectQuery(em);
Experiment experiment = (Experiment) q.getSingleResult();
ExperimentResource experimentResource = (ExperimentResource) Utils.getResource(ResourceType.EXPERIMENT, experiment);
em.getTransaction().commit();
em.close();
return experimentResource;
default:
em.getTransaction().commit();
em.close();
logger.error("Unsupported resource type for gateway resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported resource type for gateway resource.");
}
} 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 JobResource 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 JOB_STATUS:
generator = new QueryGenerator(JOB_STATUS);
generator.setParameter(JobStatusConstants.STATUS_ID, name);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
default:
logger.error("Unsupported resource type for job details 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 JobResource 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 JOB_STATUS:
generator = new QueryGenerator(JOB_STATUS);
generator.setParameter(JobStatusConstants.JOB_ID, jobId);
generator.setParameter(JobStatusConstants.TASK_ID, taskId);
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
JobStatus jobStatus = (JobStatus) result;
JobStatusResource jobStatusResource = (JobStatusResource) Utils.getResource(ResourceType.JOB_STATUS, jobStatus);
resourceList.add(jobStatusResource);
}
}
break;
default:
logger.error("Unsupported resource type for job 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