Search in sources :

Example 1 with AppModuleMapping

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

the class AppModuleMappingAppCatalogResourceAppCat method get.

@Override
public AppCatalogResource get(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();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APP_MODULE_MAPPING);
        generator.setParameter(AppModuleMappingConstants.INTERFACE_ID, ids.get(AppModuleMappingConstants.INTERFACE_ID));
        generator.setParameter(AppModuleMappingConstants.MODULE_ID, ids.get(AppModuleMappingConstants.MODULE_ID));
        Query q = generator.selectQuery(em);
        AppModuleMapping result = (AppModuleMapping) q.getSingleResult();
        AppModuleMappingAppCatalogResourceAppCat resource = (AppModuleMappingAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APP_MODULE_MAPPING, result);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return resource;
    } 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) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) AppCatalogQueryGenerator(org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AppModuleMapping

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

the class AppModuleMappingAppCatalogResourceAppCat method get.

@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
    List<AppCatalogResource> resourceList = new ArrayList<AppCatalogResource>();
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        Query q;
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APP_MODULE_MAPPING);
        List results;
        if (fieldName.equals(AppModuleMappingConstants.INTERFACE_ID)) {
            generator.setParameter(AppModuleMappingConstants.INTERFACE_ID, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    AppModuleMapping moduleMapping = (AppModuleMapping) result;
                    AppModuleMappingAppCatalogResourceAppCat resource = (AppModuleMappingAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APP_MODULE_MAPPING, moduleMapping);
                    resourceList.add(resource);
                }
            }
        } else if (fieldName.equals(AppModuleMappingConstants.MODULE_ID)) {
            generator.setParameter(AppModuleMappingConstants.MODULE_ID, value);
            q = generator.selectQuery(em);
            results = q.getResultList();
            if (results.size() != 0) {
                for (Object result : results) {
                    AppModuleMapping moduleMapping = (AppModuleMapping) result;
                    AppModuleMappingAppCatalogResourceAppCat resource = (AppModuleMappingAppCatalogResourceAppCat) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APP_MODULE_MAPPING, moduleMapping);
                    resourceList.add(resource);
                }
            }
        } else {
            em.getTransaction().commit();
            if (em.isOpen()) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                em.close();
            }
            logger.error("Unsupported field name for app module mapping resource.", new IllegalArgumentException());
            throw new IllegalArgumentException("Unsupported field name for app module mapping 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 resourceList;
}
Also used : AppModuleMapping(org.apache.airavata.registry.core.app.catalog.model.AppModuleMapping) 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 3 with AppModuleMapping

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

use of org.apache.airavata.registry.core.app.catalog.model.AppModuleMapping 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)4 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)4 AppModuleMapping (org.apache.airavata.registry.core.app.catalog.model.AppModuleMapping)4 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Query (javax.persistence.Query)2 AppModuleMapping_PK (org.apache.airavata.registry.core.app.catalog.model.AppModuleMapping_PK)2 AppCatalogQueryGenerator (org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ApplicationInterface (org.apache.airavata.registry.core.app.catalog.model.ApplicationInterface)1 ApplicationModule (org.apache.airavata.registry.core.app.catalog.model.ApplicationModule)1