Search in sources :

Example 1 with UserResourceProfilePK

use of org.apache.airavata.registry.core.app.catalog.model.UserResourceProfilePK 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 2 with UserResourceProfilePK

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

the class UserStoragePreferenceResource method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        UserStoragePreference existingPreference = em.find(UserStoragePreference.class, new UserStoragePreferencePK(userId, gatewayID, storageResourceId));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        UserResourceProfile userResourceProfile = em.find(UserResourceProfile.class, new UserResourceProfilePK(userId, gatewayID));
        if (existingPreference != null) {
            existingPreference.setStorageResourceId(storageResourceId);
            existingPreference.setUserId(userId);
            existingPreference.setGatewayID(gatewayID);
            existingPreference.setUserResourceProfile(userResourceProfile);
            existingPreference.setLoginUserName(loginUserName);
            existingPreference.setComputeResourceCSToken(resourceCSToken);
            existingPreference.setFsRootLocation(fsRootLocation);
            em.merge(existingPreference);
        } else {
            UserStoragePreference resourcePreference = new UserStoragePreference();
            resourcePreference.setStorageResourceId(storageResourceId);
            resourcePreference.setGatewayID(gatewayID);
            resourcePreference.setUserId(userId);
            resourcePreference.setUserResourceProfile(userResourceProfile);
            resourcePreference.setLoginUserName(loginUserName);
            resourcePreference.setComputeResourceCSToken(resourceCSToken);
            resourcePreference.setFsRootLocation(fsRootLocation);
            em.persist(resourcePreference);
        }
        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 : UserStoragePreferencePK(org.apache.airavata.registry.core.app.catalog.model.UserStoragePreferencePK) UserResourceProfilePK(org.apache.airavata.registry.core.app.catalog.model.UserResourceProfilePK) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) UserStoragePreference(org.apache.airavata.registry.core.app.catalog.model.UserStoragePreference) UserResourceProfile(org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Aggregations

EntityManager (javax.persistence.EntityManager)2 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)2 UserResourceProfile (org.apache.airavata.registry.core.app.catalog.model.UserResourceProfile)2 UserResourceProfilePK (org.apache.airavata.registry.core.app.catalog.model.UserResourceProfilePK)2 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)2 UserStoragePreference (org.apache.airavata.registry.core.app.catalog.model.UserStoragePreference)1 UserStoragePreferencePK (org.apache.airavata.registry.core.app.catalog.model.UserStoragePreferencePK)1