use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.
the class ExperimentResource 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 EXPERIMENT_ERROR:
generator = new QueryGenerator(EXPERIMENT_ERROR);
generator.setParameter(ExperimentErrorConstants.ERROR_ID, name);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
case EXPERIMENT_STATUS:
generator = new QueryGenerator(EXPERIMENT_STATUS);
generator.setParameter(ExperimentStatusConstants.EXPERIMENT_ID, experimentId);
generator.setParameter(ExperimentStatusConstants.STATUS_ID, name);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
case EXPERIMENT_INPUT:
generator = new QueryGenerator(EXPERIMENT_INPUT);
generator.setParameter(ExperimentInputConstants.INPUT_NAME, name);
generator.setParameter(ExperimentInputConstants.EXPERIMENT_ID, experimentId);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
case EXPERIMENT_OUTPUT:
generator = new QueryGenerator(EXPERIMENT_OUTPUT);
generator.setParameter(ExperimentOutputConstants.OUTPUT_NAME, name);
generator.setParameter(ExperimentOutputConstants.EXPERIMENT_ID, experimentId);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
case USER_CONFIGURATION_DATA:
generator = new QueryGenerator(USER_CONFIGURATION_DATA);
generator.setParameter(UserConfigurationDataConstants.EXPERIMENT_ID, experimentId);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
case PROCESS:
generator = new QueryGenerator(PROCESS);
generator.setParameter(ProcessConstants.PROCESS_ID, name);
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 ExperimentResource method get.
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 EXPERIMENT_STATUS:
generator = new QueryGenerator(EXPERIMENT_STATUS);
generator.setParameter(ExperimentStatusConstants.STATUS_ID, name);
q = generator.selectQuery(em);
ExperimentStatus status = (ExperimentStatus) q.getSingleResult();
ExperimentStatusResource statusResource = (ExperimentStatusResource) Utils.getResource(ResourceType.EXPERIMENT_STATUS, status);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return statusResource;
case EXPERIMENT_ERROR:
generator = new QueryGenerator(EXPERIMENT_ERROR);
generator.setParameter(ExperimentErrorConstants.ERROR_ID, name);
q = generator.selectQuery(em);
ExperimentError experimentError = (ExperimentError) q.getSingleResult();
ExperimentErrorResource processErrorResource = (ExperimentErrorResource) Utils.getResource(ResourceType.EXPERIMENT_ERROR, experimentError);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return processErrorResource;
case EXPERIMENT_INPUT:
generator = new QueryGenerator(EXPERIMENT_INPUT);
generator.setParameter(ExperimentInputConstants.INPUT_NAME, name);
generator.setParameter(ExperimentInputConstants.EXPERIMENT_ID, experimentId);
q = generator.selectQuery(em);
ExperimentInput experimentInput = (ExperimentInput) q.getSingleResult();
ExperimentInputResource experimentInputResource = (ExperimentInputResource) Utils.getResource(ResourceType.EXPERIMENT_INPUT, experimentInput);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return experimentInputResource;
case EXPERIMENT_OUTPUT:
generator = new QueryGenerator(EXPERIMENT_OUTPUT);
generator.setParameter(ExperimentOutputConstants.OUTPUT_NAME, name);
generator.setParameter(ExperimentInputConstants.EXPERIMENT_ID, experimentId);
q = generator.selectQuery(em);
ExperimentOutput experimentOutput = (ExperimentOutput) q.getSingleResult();
ExperimentOutputResource outputResource = (ExperimentOutputResource) Utils.getResource(ResourceType.EXPERIMENT_OUTPUT, experimentOutput);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return outputResource;
case USER_CONFIGURATION_DATA:
generator = new QueryGenerator(USER_CONFIGURATION_DATA);
generator.setParameter(UserConfigurationDataConstants.EXPERIMENT_ID, name);
q = generator.selectQuery(em);
UserConfigurationData configurationData = (UserConfigurationData) q.getSingleResult();
UserConfigurationDataResource configurationDataResource = (UserConfigurationDataResource) Utils.getResource(ResourceType.USER_CONFIGURATION_DATA, configurationData);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return configurationDataResource;
case PROCESS:
generator = new QueryGenerator(PROCESS);
generator.setParameter(ProcessConstants.PROCESS_ID, name);
q = generator.selectQuery(em);
Process process = (Process) q.getSingleResult();
ProcessResource processResource = (ProcessResource) Utils.getResource(ResourceType.PROCESS, process);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return processResource;
default:
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
logger.error("Unsupported resource type for experiment resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported resource type for experiment 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 WorkerResource method get.
/**
* @param type child resource type
* @param name child resource name
* @return child resource
*/
public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException {
ExperimentCatResource result = null;
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator;
Query q;
switch(type) {
case PROJECT:
generator = new QueryGenerator(PROJECT);
generator.setParameter(ProjectConstants.PROJECT_ID, name);
q = generator.selectQuery(em);
Project project = (Project) q.getSingleResult();
result = Utils.getResource(ResourceType.PROJECT, project);
break;
case EXPERIMENT:
generator = new QueryGenerator(EXPERIMENT);
generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
q = generator.selectQuery(em);
Experiment experiment = (Experiment) q.getSingleResult();
result = Utils.getResource(ResourceType.EXPERIMENT, experiment);
break;
default:
logger.error("Unsupported resource type for worker resource.", new IllegalArgumentException());
break;
}
em.getTransaction().commit();
em.close();
} catch (Exception e) {
throw new RegistryException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
return result;
}
use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.
the class WorkerResource method get.
/**
* Method get all results of the given child resource type with paginaltion and ordering
*
* @param type child resource type
* @param limit
* @param offset
* @param orderByIdentifier
* @param resultOrderType
* @return list of child resources
* @throws org.apache.airavata.registry.cpi.RegistryException
*/
public List<ExperimentCatResource> get(ResourceType type, int limit, int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
List<ExperimentCatResource> result = new ArrayList<ExperimentCatResource>();
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator;
Query q;
switch(type) {
case PROJECT:
generator = new QueryGenerator(PROJECT);
UserPK userPK = new UserPK();
userPK.setGatewayId(getGatewayId());
userPK.setUserName(user);
Users users = em.find(Users.class, userPK);
Gateway gatewayModel = em.find(Gateway.class, gatewayId);
generator.setParameter("users", users);
if (gatewayModel != null) {
generator.setParameter("gateway", gatewayModel);
}
// ordering - only supported only by CREATION_TIME
if (orderByIdentifier != null && resultOrderType != null && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.CREATION_TIME)) {
q = generator.selectQuery(em, ProjectConstants.CREATION_TIME, resultOrderType);
} else {
q = generator.selectQuery(em);
}
// pagination
if (limit > 0 && offset >= 0) {
q.setFirstResult(offset);
q.setMaxResults(limit);
}
for (Object o : q.getResultList()) {
Project project = (Project) o;
org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource projectResource = (org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource) Utils.getResource(ResourceType.PROJECT, project);
result.add(projectResource);
}
break;
case EXPERIMENT:
generator = new QueryGenerator(EXPERIMENT);
generator.setParameter(ExperimentConstants.USER_NAME, getUser());
// ordering - only supported only by CREATION_TIME
if (orderByIdentifier != null && resultOrderType != null && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.CREATION_TIME)) {
q = generator.selectQuery(em, ExperimentConstants.CREATION_TIME, resultOrderType);
} else {
q = generator.selectQuery(em);
}
// pagination
if (limit > 0 && offset >= 0) {
q.setFirstResult(offset);
q.setMaxResults(limit);
}
for (Object o : q.getResultList()) {
Experiment experiment = (Experiment) o;
ExperimentResource experimentResource = (ExperimentResource) Utils.getResource(ResourceType.EXPERIMENT, experiment);
result.add(experimentResource);
}
break;
default:
logger.error("Unsupported resource type for worker resource.", new IllegalArgumentException());
break;
}
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();
}
}
return result;
}
use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.
the class ExpCatResourceUtils method isGatewayExist.
/**
* @param gatewayId
* @return
*/
public static boolean isGatewayExist(String gatewayId) throws RegistryException {
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(AbstractExpCatResource.GATEWAY);
generator.setParameter(AbstractExpCatResource.GatewayConstants.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();
}
}
}
Aggregations