use of org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator in project airavata by apache.
the class AppModuleResource method get.
@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
List<AppCatalogResource> moduleResources = new ArrayList<AppCatalogResource>();
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;
AppModuleResource moduleResource = (AppModuleResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_MODULE, applicationModule);
moduleResources.add(moduleResource);
}
}
} 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;
}
use of org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator in project airavata by apache.
the class AppModuleResource method getAll.
@Override
public List<AppCatalogResource> getAll() throws AppCatalogException {
List<AppCatalogResource> appModuleResources = new ArrayList<AppCatalogResource>();
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_MODULE);
generator.setParameter(ApplicationModuleConstants.GATEWAY_ID, gatewayId);
Query q = generator.selectQuery(em);
List<?> results = q.getResultList();
for (Object result : results) {
ApplicationModule module = (ApplicationModule) result;
AppModuleResource appModuleResource = (AppModuleResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_MODULE, module);
appModuleResources.add(appModuleResource);
}
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();
}
}
return appModuleResources;
}
use of org.apache.airavata.registry.core.app.catalog.util.AppCatalogQueryGenerator in project airavata by apache.
the class ApplicationInputResource method remove.
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(APPLICATION_INPUT);
generator.setParameter(AppInputConstants.INTERFACE_ID, ids.get(AppInputConstants.INTERFACE_ID));
if (ids.get(AppInputConstants.INPUT_KEY) != null) {
generator.setParameter(AppInputConstants.INPUT_KEY, ids.get(AppInputConstants.INPUT_KEY));
}
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.core.app.catalog.util.AppCatalogQueryGenerator in project airavata by apache.
the class ApplicationInputResource method get.
public AppCatalogResource get(Object identifier) throws AppCatalogException {
HashMap<String, String> ids;
if (identifier instanceof Map) {
ids = (HashMap<String, String>) 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(APPLICATION_INPUT);
generator.setParameter(AppInputConstants.INTERFACE_ID, ids.get(AppInputConstants.INTERFACE_ID));
generator.setParameter(AppInputConstants.INPUT_KEY, ids.get(AppInputConstants.INPUT_KEY));
Query q = generator.selectQuery(em);
ApplicationIntInput applicationInput = (ApplicationIntInput) q.getSingleResult();
ApplicationInputResource applicationInputResource = (ApplicationInputResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.APPLICATION_INPUT, applicationInput);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return applicationInputResource;
} 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.core.app.catalog.util.AppCatalogQueryGenerator in project airavata by apache.
the class ApplicationInputResource method getIds.
public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
List<String> appInputResourceIDs = new ArrayList<String>();
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
Query q;
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_INPUT);
List results;
if (fieldName.equals(AppInputConstants.INTERFACE_ID)) {
generator.setParameter(AppInputConstants.INTERFACE_ID, value);
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
ApplicationIntInput applicationInput = (ApplicationIntInput) result;
appInputResourceIDs.add(applicationInput.getInterfaceID());
}
}
} else if (fieldName.equals(AppInputConstants.INPUT_KEY)) {
generator.setParameter(AppInputConstants.INPUT_KEY, value);
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
ApplicationIntInput applicationInput = (ApplicationIntInput) result;
appInputResourceIDs.add(applicationInput.getInterfaceID());
}
}
} else if (fieldName.equals(AppInputConstants.DATA_TYPE)) {
generator.setParameter(AppInputConstants.DATA_TYPE, value);
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
ApplicationIntInput applicationInput = (ApplicationIntInput) result;
appInputResourceIDs.add(applicationInput.getInterfaceID());
}
}
} else {
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
logger.error("Unsupported field name for AppInput resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported field name for AppInput 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 appInputResourceIDs;
}
Aggregations