use of org.apache.airavata.registry.cpi.AppCatalogException 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();
}
}
}
use of org.apache.airavata.registry.cpi.AppCatalogException in project airavata by apache.
the class AppModuleMappingAppCatalogResourceAppCat method removeAll.
public void removeAll() throws AppCatalogException {
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APP_MODULE_MAPPING);
Query q = generator.deleteQuery(em);
q.executeUpdate();
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
} 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();
}
}
}
use of org.apache.airavata.registry.cpi.AppCatalogException 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;
}
use of org.apache.airavata.registry.cpi.AppCatalogException in project airavata by apache.
the class AppModuleMappingAppCatalogResourceAppCat method remove.
@Override
public void remove(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));
if (ids.get(AppModuleMappingConstants.MODULE_ID) != null) {
generator.setParameter(AppModuleMappingConstants.MODULE_ID, ids.get(AppModuleMappingConstants.MODULE_ID));
}
Query q = generator.deleteQuery(em);
q.executeUpdate();
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
} 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();
}
}
}
use of org.apache.airavata.registry.cpi.AppCatalogException in project airavata by apache.
the class AppModuleResource method getIds.
@Override
public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
List<String> moduleResources = new ArrayList<String>();
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
Query q;
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_MODULE);
List results;
if (fieldName.equals(ApplicationModuleConstants.MODULE_NAME)) {
generator.setParameter(ApplicationModuleConstants.MODULE_NAME, value);
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
ApplicationModule applicationModule = (ApplicationModule) result;
moduleResources.add(applicationModule.getModuleID());
}
}
} else {
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
logger.error("Unsupported field name for app module resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported field name for app module 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 moduleResources;
}
Aggregations