use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.
the class ExpCatResourceUtils method removeGateway.
/**
* @param gatewayId
* @return
*/
public static boolean removeGateway(String gatewayId) {
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.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 ExpCatResourceUtils method getAllGateways.
public static List<ExperimentCatResource> getAllGateways() throws RegistryException {
List<ExperimentCatResource> resourceList = new ArrayList<ExperimentCatResource>();
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(AbstractExpCatResource.GATEWAY);
Query q = generator.selectQuery(em);
List results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
Gateway gateway = (Gateway) result;
GatewayResource gatewayResource = (GatewayResource) Utils.getResource(ResourceType.GATEWAY, gateway);
resourceList.add(gatewayResource);
}
}
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 resourceList;
}
use of org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator in project airavata by apache.
the class ExpCatResourceUtils method getAllUsersInGateway.
public static List<String> getAllUsersInGateway(String gatewayId) throws RegistryException {
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(AbstractExpCatResource.USERS);
generator.setParameter(AbstractExpCatResource.UserConstants.GATEWAY_ID, gatewayId);
Query q = generator.selectQuery(em);
List<Users> users = q.getResultList();
em.getTransaction().commit();
em.close();
ArrayList<String> usernameList = new ArrayList<>();
if (users != null) {
for (int i = 0; i < users.size(); i++) {
usernameList.add(users.get(i).getUserName());
}
}
return usernameList;
} 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 WorkerResource 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();
Query q;
QueryGenerator generator;
switch(type) {
case PROJECT:
generator = new QueryGenerator(PROJECT);
generator.setParameter(ProjectConstants.PROJECT_ID, name);
q = generator.deleteQuery(em);
q.executeUpdate();
break;
case EXPERIMENT:
generator = new QueryGenerator(EXPERIMENT);
generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
q = generator.deleteQuery(em);
q.executeUpdate();
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.getMessage());
} 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
* @return list of child resources
*/
@Override
public List<ExperimentCatResource> get(ResourceType type) throws RegistryException {
List<ExperimentCatResource> resourceList = new ArrayList<ExperimentCatResource>();
EntityManager em = null;
try {
if (type == ResourceType.EXPERIMENT) {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(EXPERIMENT);
generator.setParameter(ExperimentConstants.PROJECT_ID, id);
Query q = generator.selectQuery(em);
List<?> results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
Experiment experiment = (Experiment) result;
ExperimentResource experimentResource = (ExperimentResource) Utils.getResource(ResourceType.EXPERIMENT, experiment);
resourceList.add(experimentResource);
}
}
em.getTransaction().commit();
em.close();
} else if (type == ResourceType.PROJECT_USER) {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(PROJECT_USER);
generator.setParameter(ProjectUserConstants.PROJECT_ID, id);
Query q = generator.selectQuery(em);
List<?> results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
ProjectUser projectUser = (ProjectUser) result;
ProjectUserResource pr = (ProjectUserResource) Utils.getResource(ResourceType.PROJECT_USER, projectUser);
resourceList.add(pr);
}
}
em.getTransaction().commit();
em.close();
} else {
logger.error("Unsupported resource type for project resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported resource type for project 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();
}
}
return resourceList;
}
Aggregations