Search in sources :

Example 1 with UserResourceProfile

use of org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile in project airavata by apache.

the class UserResourceProfileResource method get.

public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> userResourceProfileResources = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    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");
    }
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_RESOURCE_PROFILE);
        List results;
        if (fieldName.equals(UserResourceProfileConstants.USER_ID)) {
            generator.setParameter(UserStoragePreferenceConstants.USER_ID, ids.getTopLevelIdentifier().toString());
            generator.setParameter(UserStoragePreferenceConstants.GATEWAY_ID, ids.getSecondLevelIdentifier().toString());
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    UserResourceProfile userResourceProfile = (UserResourceProfile) result;
                    UserResourceProfileResource userResourceProfileResource = (UserResourceProfileResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.USER_RESOURCE_PROFILE, userResourceProfile);
                    userResourceProfileResources.add(userResourceProfileResource);
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for User Resource Profile resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for User Resource Profile 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 userResourceProfileResources;
}
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) UserResourceProfile(org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile)

Example 2 with UserResourceProfile

use of org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile in project airavata by apache.

the class UserResourceProfileResource method get.

public AppCatalogResource get(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();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_RESOURCE_PROFILE);
        generator.setParameter(UserResourceProfileConstants.USER_ID, ids.getTopLevelIdentifier().toString());
        generator.setParameter(UserResourceProfileConstants.GATEWAY_ID, ids.getSecondLevelIdentifier().toString());
        Query q = generator.selectQuery(em);
        if (q.getResultList().size() != 0) {
            UserResourceProfile userResourceProfile = (UserResourceProfile) q.getSingleResult();
            UserResourceProfileResource userResourceProfileResource = (UserResourceProfileResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.USER_RESOURCE_PROFILE, userResourceProfile);
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            userResourceProfileResource.setUserId(ids.getTopLevelIdentifier().toString());
            return userResourceProfileResource;
        } else {
            return 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) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator) UserResourceProfile(org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile)

Example 3 with UserResourceProfile

use of org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile in project airavata by apache.

the class UserResourceProfileResource method getAll.

@Override
public List<AppCatalogResource> getAll() throws AppCatalogException {
    List<AppCatalogResource> resourceList = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_RESOURCE_PROFILE);
        Query q = generator.selectQuery(em);
        List results = q.getResultList();
        if (results.size() != 0) {
            for (Object result : results) {
                UserResourceProfile userResourceProfile = (UserResourceProfile) result;
                UserResourceProfileResource userResourceProfileResource = (UserResourceProfileResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.USER_RESOURCE_PROFILE, userResourceProfile);
                resourceList.add(userResourceProfileResource);
            }
        }
        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 resourceList;
}
Also used : EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator) UserResourceProfile(org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 4 with UserResourceProfile

use of org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile in project airavata by apache.

the class UserResourceProfileResource method save.

public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        UserResourceProfile existingUserResourceProfile = em.find(UserResourceProfile.class, new UserResourceProfilePK(userId, gatewayID));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingUserResourceProfile != null) {
            existingUserResourceProfile.setUpdateTime(AiravataUtils.getCurrentTimestamp());
            if (credentialStoreToken != null) {
                existingUserResourceProfile.setCredentialStoreToken(credentialStoreToken);
            }
            if (identityServerTenant != null) {
                existingUserResourceProfile.setIdentityServerTenant(identityServerTenant);
            }
            if (identityServerPwdCredToken != null) {
                existingUserResourceProfile.setIdentityServerPwdCredToken(identityServerPwdCredToken);
            }
            em.merge(existingUserResourceProfile);
        } else {
            UserResourceProfile userResourceProfile = new UserResourceProfile();
            userResourceProfile.setGatewayID(gatewayID);
            userResourceProfile.setUserId(userId);
            userResourceProfile.setCreationTime(AiravataUtils.getCurrentTimestamp());
            if (credentialStoreToken != null) {
                userResourceProfile.setCredentialStoreToken(credentialStoreToken);
            }
            if (identityServerTenant != null) {
                userResourceProfile.setIdentityServerTenant(identityServerTenant);
            }
            if (identityServerPwdCredToken != null) {
                userResourceProfile.setIdentityServerPwdCredToken(identityServerPwdCredToken);
            }
            em.persist(userResourceProfile);
        }
        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();
        }
    }
}
Also used : UserResourceProfilePK(org.apache.airavata.registry.core.app.catalog.model.UserResourceProfilePK) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) UserResourceProfile(org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 5 with UserResourceProfile

use of org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile in project airavata by apache.

the class UserResourceProfileResource method getIds.

public List<String> getIds(String userId, Object value) throws AppCatalogException {
    List<String> userResourceProfileResourceIDs = new ArrayList<String>();
    EntityManager em = null;
    HashMap<String, String> ids;
    if (value instanceof Map) {
        ids = (HashMap) value;
    } 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");
    }
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(USER_RESOURCE_PROFILE);
        List results;
        if (userId.equals(UserResourceProfileConstants.USER_ID)) {
            generator.setParameter(UserResourceProfileConstants.USER_ID, ids.get(UserResourceProfileConstants.USER_ID));
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    UserResourceProfile userResourceProfile = (UserResourceProfile) result;
                    userResourceProfileResourceIDs.add(userResourceProfile.getUserID());
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for User Resource Profile resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for User Resource Profile 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 userResourceProfileResourceIDs;
}
Also used : 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) HashMap(java.util.HashMap) Map(java.util.Map) UserResourceProfile(org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile)

Aggregations

EntityManager (javax.persistence.EntityManager)6 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)6 UserResourceProfile (org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile)6 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)6 Query (javax.persistence.Query)4 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 UserResourceProfilePK (org.apache.airavata.registry.core.app.catalog.model.UserResourceProfilePK)2 CompositeIdentifier (org.apache.airavata.registry.cpi.CompositeIdentifier)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UserStoragePreference (org.apache.airavata.registry.core.app.catalog.model.UserStoragePreference)1 UserStoragePreferencePK (org.apache.airavata.registry.core.app.catalog.model.UserStoragePreferencePK)1