Search in sources :

Example 16 with CompositeIdentifier

use of org.apache.airavata.registry.cpi.CompositeIdentifier in project airavata by apache.

the class UserComputeHostPreferenceResource method get.

@Override
public AppCatalogResource get(Object identifier) throws AppCatalogException {
    CompositeIdentifier ids;
    if (identifier instanceof CompositeIdentifier) {
        ids = (CompositeIdentifier) identifier;
    } else {
        logger.error("Identifier should be a instance of CompositeIdentifier class");
        throw new AppCatalogException("Identifier should be a instance of CompositeIdentifier class");
    }
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_COMPUTE_RESOURCE_PREFERENCE);
        generator.setParameter(UserComputeResourcePreferenceConstants.RESOURCE_ID, ids.getTopLevelIdentifier().toString());
        generator.setParameter(UserComputeResourcePreferenceConstants.USER_ID, ids.getSecondLevelIdentifier().toString());
        generator.setParameter(UserComputeResourcePreferenceConstants.GATEWAY_ID, ids.getThirdLevelIdentifier().toString());
        Query q = generator.selectQuery(em);
        UserComputeResourcePreference preference = (UserComputeResourcePreference) q.getSingleResult();
        UserComputeHostPreferenceResource preferenceResource = (UserComputeHostPreferenceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.USER_COMPUTE_RESOURCE_PREFERENCE, preference);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return preferenceResource;
    } 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) CompositeIdentifier(org.apache.airavata.registry.cpi.CompositeIdentifier) Query(javax.persistence.Query) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 17 with CompositeIdentifier

use of org.apache.airavata.registry.cpi.CompositeIdentifier in project airavata by apache.

the class UserComputeHostPreferenceResource method get.

@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> preferenceResourceList = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_COMPUTE_RESOURCE_PREFERENCE);
        List results;
        if (fieldName.equals(UserComputeResourcePreferenceConstants.RESOURCE_ID)) {
            generator.setParameter(UserComputeResourcePreferenceConstants.RESOURCE_ID, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    UserComputeResourcePreference preference = (UserComputeResourcePreference) result;
                    if (preference.getComputeHostResource() != null) {
                        UserComputeHostPreferenceResource preferenceResource = (UserComputeHostPreferenceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.USER_COMPUTE_RESOURCE_PREFERENCE, preference);
                        preferenceResourceList.add(preferenceResource);
                    }
                }
            }
        } else if (fieldName.equals(UserComputeResourcePreferenceConstants.USER_ID)) {
            CompositeIdentifier ids;
            if (value instanceof CompositeIdentifier) {
                ids = (CompositeIdentifier) value;
            } else {
                logger.error("Identifier should be a instance of CompositeIdentifier class");
                throw new AppCatalogException("Identifier should be a instance of CompositeIdentifier class");
            }
            generator.setParameter(UserComputeResourcePreferenceConstants.USER_ID, ids.getTopLevelIdentifier().toString());
            generator.setParameter(UserComputeResourcePreferenceConstants.GATEWAY_ID, ids.getSecondLevelIdentifier().toString());
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    UserComputeResourcePreference preference = (UserComputeResourcePreference) result;
                    if (preference.getComputeHostResource() != null) {
                        UserComputeHostPreferenceResource preferenceResource = (UserComputeHostPreferenceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.USER_COMPUTE_RESOURCE_PREFERENCE, preference);
                        preferenceResourceList.add(preferenceResource);
                    }
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for Compute host preference Resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for Compute host preference 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 preferenceResourceList;
}
Also used : CompositeIdentifier(org.apache.airavata.registry.cpi.CompositeIdentifier) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ArrayList(java.util.ArrayList) List(java.util.List) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 18 with CompositeIdentifier

use of org.apache.airavata.registry.cpi.CompositeIdentifier in project airavata by apache.

the class UserComputeHostPreferenceResource method isExists.

@Override
public boolean isExists(Object identifier) throws AppCatalogException {
    CompositeIdentifier ids;
    if (identifier instanceof CompositeIdentifier) {
        ids = (CompositeIdentifier) identifier;
    } else {
        logger.error("Identifier should be a instance of CompositeIdentifier class");
        throw new AppCatalogException("Identifier should be a instance of CompositeIdentifier class");
    }
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        String resourceId = ids.getTopLevelIdentifier().toString();
        String userId = ids.getSecondLevelIdentifier().toString();
        String gatewayId = ids.getThirdLevelIdentifier().toString();
        UserComputeResourcePreference existingPreference = em.find(UserComputeResourcePreference.class, new UserComputeResourcePreferencePK(userId, gatewayId, resourceId));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return existingPreference != null;
    } 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();
        }
    }
}
Also used : AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) EntityManager(javax.persistence.EntityManager) CompositeIdentifier(org.apache.airavata.registry.cpi.CompositeIdentifier) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 19 with CompositeIdentifier

use of org.apache.airavata.registry.cpi.CompositeIdentifier in project airavata by apache.

the class UserResourceProfileResource method isExists.

public boolean isExists(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    CompositeIdentifier ids;
    if (identifier instanceof CompositeIdentifier) {
        ids = (CompositeIdentifier) identifier;
    } else {
        logger.error("Identifier should be a instance of CompositeIdentifier class");
        throw new AppCatalogException("Identifier should be a instance of CompositeIdentifier class");
    }
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_RESOURCE_PROFILE);
        List results;
        generator.setParameter(UserResourceProfileConstants.USER_ID, ids.getTopLevelIdentifier().toString());
        generator.setParameter(UserResourceProfileConstants.GATEWAY_ID, ids.getSecondLevelIdentifier().toString());
        q = generator.selectQuery(em);
        results = q.getResultList();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return results != null;
    } 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) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) CompositeIdentifier(org.apache.airavata.registry.cpi.CompositeIdentifier) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Example 20 with CompositeIdentifier

use of org.apache.airavata.registry.cpi.CompositeIdentifier in project airavata by apache.

the class UserStoragePreferenceResource method remove.

@Override
public void remove(Object identifier) throws AppCatalogException {
    CompositeIdentifier ids;
    if (identifier instanceof CompositeIdentifier) {
        ids = (CompositeIdentifier) identifier;
    } else {
        logger.error("Identifier should be a instance of CompositeIdentifier class");
        throw new AppCatalogException("Identifier should be a instance of CompositeIdentifier class");
    }
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_STORAGE_PREFERENCE);
        generator.setParameter(UserStoragePreferenceConstants.STORAGE_ID, ids.getTopLevelIdentifier().toString());
        generator.setParameter(UserStoragePreferenceConstants.USER_ID, ids.getSecondLevelIdentifier().toString());
        generator.setParameter(UserStoragePreferenceConstants.GATEWAY_ID, ids.getThirdLevelIdentifier().toString());
        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) CompositeIdentifier(org.apache.airavata.registry.cpi.CompositeIdentifier) Query(javax.persistence.Query) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)

Aggregations

AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)22 CompositeIdentifier (org.apache.airavata.registry.cpi.CompositeIdentifier)22 EntityManager (javax.persistence.EntityManager)12 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)12 Query (javax.persistence.Query)10 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)10 ArrayList (java.util.ArrayList)4 List (java.util.List)4 UserStoragePreference (org.apache.airavata.registry.core.app.catalog.model.UserStoragePreference)3 UserComputeResourcePreference (org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference)2 UserStoragePreference (org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference)2 UserResourceProfile (org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile)2 UserStoragePreferencePK (org.apache.airavata.registry.core.app.catalog.model.UserStoragePreferencePK)1