use of org.apache.airavata.registry.core.app.catalog.model.GatewayProfile in project airavata by apache.
the class GatewayProfileResource method getIds.
public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
List<String> gatewayProfileResourceIDs = new ArrayList<String>();
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
Query q;
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GATEWAY_PROFILE);
List results;
if (fieldName.equals(GatewayProfileConstants.GATEWAY_ID)) {
generator.setParameter(GatewayProfileConstants.GATEWAY_ID, value);
q = generator.selectQuery(em);
results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
GatewayProfile gatewayProfile = (GatewayProfile) result;
gatewayProfileResourceIDs.add(gatewayProfile.getGatewayID());
}
}
} else {
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
logger.error("Unsupported field name for Gateway Profile resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported field name for Gateway Profile 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 gatewayProfileResourceIDs;
}
use of org.apache.airavata.registry.core.app.catalog.model.GatewayProfile in project airavata by apache.
the class GatewayProfileResource method getAll.
@Override
public List<AppCatalogResource> getAll() throws AppCatalogException {
List<AppCatalogResource> resourceList = new ArrayList<AppCatalogResource>();
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GATEWAY_PROFILE);
Query q = generator.selectQuery(em);
List results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
GatewayProfile gatewayProfile = (GatewayProfile) result;
GatewayProfileResource gatewayProfileResource = (GatewayProfileResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.GATEWAY_PROFILE, gatewayProfile);
resourceList.add(gatewayProfileResource);
}
}
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.core.app.catalog.model.GatewayProfile in project airavata by apache.
the class GatewayProfileResource method save.
public void save() throws AppCatalogException {
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
GatewayProfile existingGatewayProfile = em.find(GatewayProfile.class, gatewayID);
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
if (existingGatewayProfile != null) {
existingGatewayProfile.setUpdateTime(AiravataUtils.getCurrentTimestamp());
if (credentialStoreToken != null) {
existingGatewayProfile.setCredentialStoreToken(credentialStoreToken);
}
if (identityServerTenant != null) {
existingGatewayProfile.setIdentityServerTenant(identityServerTenant);
}
if (identityServerPwdCredToken != null) {
existingGatewayProfile.setIdentityServerPwdCredToken(identityServerPwdCredToken);
}
em.merge(existingGatewayProfile);
} else {
GatewayProfile gatewayProfile = new GatewayProfile();
gatewayProfile.setGatewayID(gatewayID);
gatewayProfile.setCreationTime(AiravataUtils.getCurrentTimestamp());
if (credentialStoreToken != null) {
gatewayProfile.setCredentialStoreToken(credentialStoreToken);
}
if (identityServerTenant != null) {
gatewayProfile.setIdentityServerTenant(identityServerTenant);
}
if (identityServerPwdCredToken != null) {
gatewayProfile.setIdentityServerPwdCredToken(identityServerPwdCredToken);
}
em.persist(gatewayProfile);
}
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.GatewayProfile in project airavata by apache.
the class GatewayProfileResource method isExists.
public boolean isExists(Object identifier) throws AppCatalogException {
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
GatewayProfile gatewayProfile = em.find(GatewayProfile.class, identifier);
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return gatewayProfile != 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();
}
}
}
use of org.apache.airavata.registry.core.app.catalog.model.GatewayProfile in project airavata by apache.
the class GatewayProfileResource method get.
public AppCatalogResource get(Object identifier) throws AppCatalogException {
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(GATEWAY_PROFILE);
generator.setParameter(GatewayProfileConstants.GATEWAY_ID, identifier);
Query q = generator.selectQuery(em);
GatewayProfile gatewayProfile = (GatewayProfile) q.getSingleResult();
GatewayProfileResource gatewayProfileResource = (GatewayProfileResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.GATEWAY_PROFILE, gatewayProfile);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return gatewayProfileResource;
} 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