Search in sources :

Example 6 with ApplicationModule

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

the class AppModuleMappingAppCatalogResourceAppCat method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        AppModuleMapping existngModuleMap = em.find(AppModuleMapping.class, new AppModuleMapping_PK(interfaceId, moduleId));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        ApplicationInterface applicationInterface = em.find(ApplicationInterface.class, interfaceId);
        ApplicationModule applicationModule = em.find(ApplicationModule.class, moduleId);
        if (existngModuleMap != null) {
            existngModuleMap.setApplicationInterface(applicationInterface);
            existngModuleMap.setApplicationModule(applicationModule);
            em.merge(existngModuleMap);
        } else {
            AppModuleMapping appModuleMapping = new AppModuleMapping();
            appModuleMapping.setInterfaceID(interfaceId);
            appModuleMapping.setApplicationInterface(applicationInterface);
            appModuleMapping.setModuleID(moduleId);
            appModuleMapping.setApplicationModule(applicationModule);
            em.persist(appModuleMapping);
        }
        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 : AppModuleMapping(org.apache.airavata.registry.core.app.catalog.model.AppModuleMapping) AppModuleMapping_PK(org.apache.airavata.registry.core.app.catalog.model.AppModuleMapping_PK) EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationInterface(org.apache.airavata.registry.core.app.catalog.model.ApplicationInterface) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) ApplicationModule(org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)

Example 7 with ApplicationModule

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

the class AppModuleResource method isExists.

@Override
public boolean isExists(Object identifier) throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        ApplicationModule applicationModule = em.find(ApplicationModule.class, identifier);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return applicationModule != 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) ApplicationModule(org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)

Example 8 with ApplicationModule

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

the class AppModuleResource method save.

@Override
public void save() throws AppCatalogException {
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        ApplicationModule existingModule = em.find(ApplicationModule.class, moduleId);
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        if (existingModule != null) {
            existingModule.setModuleName(moduleName);
            existingModule.setModuleVersion(moduleVersion);
            existingModule.setModuleDesc(moduleDesc);
            existingModule.setGatewayId(gatewayId);
            existingModule.setUpdateTime(AiravataUtils.getCurrentTimestamp());
            em.merge(existingModule);
        } else {
            ApplicationModule applicationModule = new ApplicationModule();
            applicationModule.setModuleID(moduleId);
            applicationModule.setModuleName(moduleName);
            applicationModule.setModuleVersion(moduleVersion);
            applicationModule.setModuleDesc(moduleDesc);
            applicationModule.setGatewayId(gatewayId);
            applicationModule.setCreationTime(AiravataUtils.getCurrentTimestamp());
            em.persist(applicationModule);
        }
        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 : EntityManager(javax.persistence.EntityManager) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) ApplicationModule(org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)

Aggregations

EntityManager (javax.persistence.EntityManager)8 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)8 ApplicationModule (org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)8 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)8 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)2 AppModuleMapping (org.apache.airavata.registry.core.app.catalog.model.AppModuleMapping)1 AppModuleMapping_PK (org.apache.airavata.registry.core.app.catalog.model.AppModuleMapping_PK)1 ApplicationDeployment (org.apache.airavata.registry.core.app.catalog.model.ApplicationDeployment)1 ApplicationInterface (org.apache.airavata.registry.core.app.catalog.model.ApplicationInterface)1 ComputeResource (org.apache.airavata.registry.core.app.catalog.model.ComputeResource)1