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();
}
}
}
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();
}
}
}
Aggregations