Search in sources :

Example 1 with Notification

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;
}
Also used : EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) RegistryException(org.apache.airavata.registry.cpi.RegistryException) Notification(org.apache.airavata.registry.core.experiment.catalog.model.Notification) RegistryException(org.apache.airavata.registry.cpi.RegistryException) ExperimentCatResource(org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)

Example 2 with Notification

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();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) QueryGenerator(org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator) Query(javax.persistence.Query) RegistryException(org.apache.airavata.registry.cpi.RegistryException) Notification(org.apache.airavata.registry.core.experiment.catalog.model.Notification) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Example 3 with Notification

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();
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) RegistryException(org.apache.airavata.registry.cpi.RegistryException) Notification(org.apache.airavata.registry.core.experiment.catalog.model.Notification) RegistryException(org.apache.airavata.registry.cpi.RegistryException)

Aggregations

EntityManager (javax.persistence.EntityManager)3 Notification (org.apache.airavata.registry.core.experiment.catalog.model.Notification)3 RegistryException (org.apache.airavata.registry.cpi.RegistryException)3 Query (javax.persistence.Query)2 QueryGenerator (org.apache.airavata.registry.core.experiment.catalog.utils.QueryGenerator)2 ArrayList (java.util.ArrayList)1 ExperimentCatResource (org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource)1