use of org.apache.airavata.registry.core.experiment.catalog.model.Notification in project airavata by apache.
the class NotificationResource method getAllNotifications.
public List<ExperimentCatResource> getAllNotifications(String gatewayId) throws RegistryException {
List<ExperimentCatResource> resourceList = new ArrayList<ExperimentCatResource>();
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(NOTIFICATION);
generator.setParameter(NotificationConstants.GATEWAY_ID, gatewayId);
Query q = generator.selectQuery(em);
List<?> results = q.getResultList();
if (results.size() != 0) {
for (Object result : results) {
Notification notification = (Notification) result;
NotificationResource notificationResource = (NotificationResource) Utils.getResource(ResourceType.NOTIFICATION, notification);
resourceList.add(notificationResource);
}
}
em.getTransaction().commit();
em.close();
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RegistryException(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.experiment.catalog.model.Notification in project airavata by apache.
the class NotificationResource method get.
/**
* @param type child resource type
* @param name child resource name
* @return UnsupportedOperationException
*/
public ExperimentCatResource get(ResourceType type, Object notificationId) throws RegistryException {
EntityManager em = null;
try {
if (!type.equals(ResourceType.NOTIFICATION)) {
logger.error("Unsupported resource type for Notification resource.", new IllegalArgumentException());
throw new IllegalArgumentException("Unsupported resource type for Notification resource.");
}
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
QueryGenerator generator = new QueryGenerator(NOTIFICATION);
generator.setParameter(NotificationConstants.NOTIFICATION_ID, notificationId);
Query q = generator.selectQuery(em);
Notification notification = (Notification) q.getSingleResult();
em.getTransaction().commit();
em.close();
if (notification != null)
return Utils.getResource(ResourceType.NOTIFICATION, notification);
else
return null;
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RegistryException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
}
use of org.apache.airavata.registry.core.experiment.catalog.model.Notification in project airavata by apache.
the class NotificationResource method save.
/**
* save user to the database
*/
public void save() throws RegistryException {
EntityManager em = null;
try {
em = ExpCatResourceUtils.getEntityManager();
Notification existingNotification = em.find(Notification.class, notificationId);
em.close();
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
if (existingNotification != null) {
existingNotification.setNotificationId(notificationId);
existingNotification.setGatewayId(gatewayId);
existingNotification.setTitle(title);
existingNotification.setNotificationMessage(notificationMessage);
existingNotification.setPublishedDate(publishedTime);
existingNotification.setExpirationDate(expirationTime);
existingNotification.setCreationDate(creationTime);
existingNotification.setPriority(priority);
em.merge(existingNotification);
} else {
Notification notification = new Notification();
notification.setNotificationId(notificationId);
notification.setGatewayId(gatewayId);
notification.setTitle(title);
notification.setNotificationMessage(notificationMessage);
notification.setPublishedDate(publishedTime);
notification.setExpirationDate(expirationTime);
notification.setCreationDate(creationTime);
notification.setPriority(priority);
em.persist(notification);
}
em.getTransaction().commit();
em.close();
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RegistryException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
}
Aggregations