Search in sources :

Example 1 with AppModuleMapping_PK

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

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

the class AppModuleMappingAppCatalogResourceAppCat method isExists.

@Override
public boolean isExists(Object identifier) throws AppCatalogException {
    HashMap<String, String> ids;
    if (identifier instanceof Map) {
        ids = (HashMap) 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();
        AppModuleMapping moduleMapping = em.find(AppModuleMapping.class, new AppModuleMapping_PK(ids.get(AppModuleMappingConstants.INTERFACE_ID), ids.get(AppModuleMappingConstants.MODULE_ID)));
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return moduleMapping != 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 : AppModuleMapping(org.apache.airavata.registry.core.app.catalog.model.AppModuleMapping) AppModuleMapping_PK(org.apache.airavata.registry.core.app.catalog.model.AppModuleMapping_PK) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) EntityManager(javax.persistence.EntityManager) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

EntityManager (javax.persistence.EntityManager)2 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)2 AppModuleMapping (org.apache.airavata.registry.core.app.catalog.model.AppModuleMapping)2 AppModuleMapping_PK (org.apache.airavata.registry.core.app.catalog.model.AppModuleMapping_PK)2 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ApplicationInterface (org.apache.airavata.registry.core.app.catalog.model.ApplicationInterface)1 ApplicationModule (org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)1