use of org.apache.airavata.registry.core.app.catalog.model.LocalSubmission in project airavata by apache.
the class LocalSubmissionResource method get.
@Override
public List<AppCatalogResource> get(String fieldName, Object value) throws AppCatalogException {
List<AppCatalogResource> localSubmissionResources = new ArrayList<AppCatalogResource>();
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(LOCAL_SUBMISSION);
Query q;
if ((fieldName.equals(LocalSubmissionConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(LocalSubmissionConstants.JOB_SUBMISSION_INTERFACE_ID))) {
generator.setParameter(fieldName, value);
q = generator.selectQuery(em);
List<?> results = q.getResultList();
for (Object result : results) {
LocalSubmission localSubmission = (LocalSubmission) result;
LocalSubmissionResource localSubmissionResource = (LocalSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.LOCAL_SUBMISSION, localSubmission);
localSubmissionResources.add(localSubmissionResource);
}
} else {
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
logger.error("Unsupported field name for Local Submission Resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported field name for Local Submission Resource.");
}
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 localSubmissionResources;
}
use of org.apache.airavata.registry.core.app.catalog.model.LocalSubmission in project airavata by apache.
the class LocalSubmissionResource method getIds.
@Override
public List<String> getIds(String fieldName, Object value) throws AppCatalogException {
List<String> localSubmissionResourceIDs = new ArrayList<String>();
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(LOCAL_SUBMISSION);
Query q;
if ((fieldName.equals(LocalSubmissionConstants.RESOURCE_JOB_MANAGER_ID)) || (fieldName.equals(LocalSubmissionConstants.JOB_SUBMISSION_INTERFACE_ID))) {
generator.setParameter(fieldName, value);
q = generator.selectQuery(em);
List<?> results = q.getResultList();
for (Object result : results) {
LocalSubmission localSubmission = (LocalSubmission) result;
LocalSubmissionResource localSubmissionResource = (LocalSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.LOCAL_SUBMISSION, localSubmission);
localSubmissionResourceIDs.add(localSubmissionResource.getJobSubmissionInterfaceId());
}
} else {
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
logger.error("Unsupported field name for Local Submission Resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported field name for Local Submission Resource.");
}
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 localSubmissionResourceIDs;
}
use of org.apache.airavata.registry.core.app.catalog.model.LocalSubmission in project airavata by apache.
the class LocalSubmissionResource method save.
@Override
public void save() throws AppCatalogException {
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
LocalSubmission existingLocalSubmission = em.find(LocalSubmission.class, jobSubmissionInterfaceId);
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
LocalSubmission localSubmission;
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
if (existingLocalSubmission == null) {
localSubmission = new LocalSubmission();
localSubmission.setCreationTime(AiravataUtils.getCurrentTimestamp());
} else {
localSubmission = existingLocalSubmission;
localSubmission.setUpdateTime(AiravataUtils.getCurrentTimestamp());
}
localSubmission.setResourceJobManagerId(getResourceJobManagerId());
ResourceJobManager resourceJobManager = em.find(ResourceJobManager.class, getResourceJobManagerId());
localSubmission.setResourceJobManager(resourceJobManager);
localSubmission.setJobSubmissionInterfaceId(getJobSubmissionInterfaceId());
localSubmission.setSecurityProtocol(getSecurityProtocol());
if (existingLocalSubmission == null) {
em.persist(localSubmission);
} else {
em.merge(localSubmission);
}
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.LocalSubmission in project airavata by apache.
the class LocalSubmissionResource method isExists.
@Override
public boolean isExists(Object identifier) throws AppCatalogException {
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
LocalSubmission localSubmission = em.find(LocalSubmission.class, identifier);
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return localSubmission != 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.LocalSubmission in project airavata by apache.
the class LocalSubmissionResource method get.
@Override
public AppCatalogResource get(Object identifier) throws AppCatalogException {
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(LOCAL_SUBMISSION);
generator.setParameter(LocalSubmissionConstants.JOB_SUBMISSION_INTERFACE_ID, identifier);
Query q = generator.selectQuery(em);
LocalSubmission localSubmission = (LocalSubmission) q.getSingleResult();
LocalSubmissionResource localSubmissionResource = (LocalSubmissionResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.LOCAL_SUBMISSION, localSubmission);
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
return localSubmissionResource;
} 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