Search in sources :

Example 66 with AppCatalogQueryGenerator

use of org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator in project airavata by apache.

the class GridftpDataMovementResource method get.

@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> gridftpDataMovementResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GRIDFTP_DATA_MOVEMENT);
        Query q;
        if ((fieldName.equals(GridftpDataMovementConstants.DATA_MOVEMENT_INTERFACE_ID)) || (fieldName.equals(GridftpDataMovementConstants.SECURITY_PROTOCOL))) {
            generator.setParameter(fieldName, value);
            q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            for (Object result : results) {
                GridftpDataMovement gridftpDataMovement = (GridftpDataMovement) result;
                GridftpDataMovementResource gridftpDataMovementResource = (GridftpDataMovementResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.GRIDFTP_DATA_MOVEMENT, gridftpDataMovement);
                gridftpDataMovementResources.add(gridftpDataMovementResource);
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Gridftp Data Movement Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Gridftp Data Movement Resource.");
        }
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
    return gridftpDataMovementResources;
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) GridftpDataMovement(org.apache.airavata.registry.core.app.catalog.model.GridftpDataMovement) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 67 with AppCatalogQueryGenerator

use of org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator in project airavata by apache.

the class GridftpDataMovementResource method getIds.

@Override
public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
    List<String> gridftpDataMovementResourceIDs = new ArrayList<String>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GRIDFTP_DATA_MOVEMENT);
        Query q;
        if ((fieldName.equals(GridftpDataMovementConstants.DATA_MOVEMENT_INTERFACE_ID)) || (fieldName.equals(GridftpDataMovementConstants.SECURITY_PROTOCOL))) {
            generator.setParameter(fieldName, value);
            q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            for (Object result : results) {
                GridftpDataMovement gridftpDataMovement = (GridftpDataMovement) result;
                GridftpDataMovementResource gridftpDataMovementResource = (GridftpDataMovementResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.GRIDFTP_DATA_MOVEMENT, gridftpDataMovement);
                gridftpDataMovementResourceIDs.add(gridftpDataMovementResource.getDataMovementInterfaceId());
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Gridftp Data Movement Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Gridftp Data Movement Resource.");
        }
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
    return gridftpDataMovementResourceIDs;
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) GridftpDataMovement(org.apache.airavata.registry.core.app.catalog.model.GridftpDataMovement) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 68 with AppCatalogQueryGenerator

use of org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator in project airavata by apache.

the class GridftpEndpointResource method remove.

@Override
public void remove(Object identifier) throws AppCatalogException {
    HashMap<String, String> ids;
    if (identifier instanceof Map) {
        ids = (HashMap<String, String>) identifier;
    } else {
        logger.error("Identifier should be a map with the field name and it's value");
        throw new AppCatalogException("Identifier should be a map with the field name and it's value");
    }
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GRIDFTP_ENDPOINT);
        generator.setParameter(GridftpEndpointConstants.ENDPOINT, ids.get(GridftpEndpointConstants.ENDPOINT));
        generator.setParameter(GridftpEndpointConstants.DATA_MOVEMENT_INTERFACE_ID, ids.get(GridftpEndpointConstants.DATA_MOVEMENT_INTERFACE_ID));
        Query q = generator.deleteQuery(em);
        q.executeUpdate();
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 69 with AppCatalogQueryGenerator

use of org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator in project airavata by apache.

the class GridftpEndpointResource method get.

@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> gridftpEndpointResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GRIDFTP_ENDPOINT);
        Query q;
        if ((fieldName.equals(GridftpEndpointConstants.ENDPOINT)) || (fieldName.equals(GridftpEndpointConstants.DATA_MOVEMENT_INTERFACE_ID))) {
            generator.setParameter(fieldName, value);
            q = generator.selectQuery(em);
            List<?> results = q.getResultList();
            for (Object result : results) {
                GridftpEndpoint gridftpEndpoint = (GridftpEndpoint) result;
                GridftpEndpointResource gridftpEndpointResource = (GridftpEndpointResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.GRIDFTP_ENDPOINT, gridftpEndpoint);
                gridftpEndpointResources.add(gridftpEndpointResource);
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Gridftp Endpoint Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Gridftp Endpoint Resource.");
        }
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
    return gridftpEndpointResources;
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) GridftpEndpoint(org.apache.airavata.registry.core.app.catalog.model.GridftpEndpoint) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 70 with AppCatalogQueryGenerator

use of org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator in project airavata by apache.

the class HostAliasAppResource method get.

public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> hostAliasResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(HOST_ALIAS);
        List results;
        if (fieldName.equals(HostAliasConstants.ALIAS)) {
            generator.setParameter(HostAliasConstants.ALIAS, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    HostAlias hostAlias = (HostAlias) result;
                    HostAliasAppResource hostAliasResource = (HostAliasAppResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.HOST_ALIAS, hostAlias);
                    hostAliasResources.add(hostAliasResource);
                }
            }
        } else if (fieldName.equals(HostAliasConstants.RESOURCE_ID)) {
            generator.setParameter(HostAliasConstants.RESOURCE_ID, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    HostAlias hostAlias = (HostAlias) result;
                    HostAliasAppResource hostAliasResource = (HostAliasAppResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.HOST_ALIAS, hostAlias);
                    hostAliasResources.add(hostAliasResource);
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Host Alias Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Host Alias Resource.");
        }
        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 AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
    return hostAliasResources;
}
Also used : Query(javax.persistence.Query) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) HostAlias(org.apache.airavata.registry.core.app.catalog.model.HostAlias) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Aggregations

EntityManager (javax.persistence.EntityManager)176 Query (javax.persistence.Query)176 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)176 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)176 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)176 ArrayList (java.util.ArrayList)80 List (java.util.List)41 HashMap (java.util.HashMap)36 Map (java.util.Map)36 CompositeIdentifier (org.apache.airavata.registry.cpi.CompositeIdentifier)10 ApplicationDeployment (org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment)5 ApplicationInterface (org.apache.airavata.registry.core.app.catalog.model.ApplicationInterface)5 ComputeResource (org.apache.airavata.registry.core.app.catalog.model.ComputeResource)5 StorageResource (org.apache.airavata.registry.core.app.catalog.model.StorageResource)5 ApplicationModule (org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)4 GatewayProfile (org.apache.airavata.registry.core.app.catalog.model.GatewayProfile)4 GlobusJobSubmission (org.apache.airavata.registry.core.app.catalog.model.GlobusJobSubmission)4 UserResourceProfile (org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile)4 ApplicationIntInput (org.apache.airavata.registry.core.app.catalog.model.ApplicationIntInput)3 ApplicationIntOutput (org.apache.airavata.registry.core.app.catalog.model.ApplicationIntOutput)3