Search in sources :

Example 1 with QueryGenerator

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();
        }
    }
}
Also used : QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) ExperimentCatalogException(org.apache.airavata.registry.cpi.ExperimentCatalogException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 2 with QueryGenerator

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;
}
Also used : QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ExperimentCatalogException(org.apache.airavata.registry.cpi.ExperimentCatalogException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 3 with QueryGenerator

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();
        }
    }
}
Also used : QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) ArrayList(java.util.ArrayList) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ExperimentCatalogException(org.apache.airavata.registry.cpi.ExperimentCatalogException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 4 with QueryGenerator

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();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 5 with QueryGenerator

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;
}
Also used : Query(javax.persistence.Query) ArrayList(java.util.ArrayList) RegistryException(org.apache.airavata.registry.cpi.RegistryException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) ArrayList(java.util.ArrayList) List(java.util.List) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Aggregations

QueryGenerator (org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator)31 RegistryException (org.apache.airavata.registry.cpi.RegistryException)31 EntityManager (javax.persistence.EntityManager)25 Query (javax.persistence.Query)25 ArrayList (java.util.ArrayList)11 ExperimentCatResource (org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)10 List (java.util.List)8 ExperimentCatalogException (org.apache.airavata.registry.cpi.ExperimentCatalogException)6 Job (org.apache.airavata.registry.core.experiment.catalog.model.Job)2 JobStatus (org.apache.airavata.registry.core.experiment.catalog.model.JobStatus)2 Notification (org.apache.airavata.registry.core.experiment.catalog.model.Notification)2 Process (org.apache.airavata.registry.core.experiment.catalog.model.Process)2 TaskError (org.apache.airavata.registry.core.experiment.catalog.model.TaskError)2 TaskStatus (org.apache.airavata.registry.core.experiment.catalog.model.TaskStatus)2