Search in sources :

Example 6 with PerunNotifRegex

use of cz.metacentrum.perun.notif.entities.PerunNotifRegex in project perun by CESNET.

the class PerunNotifRegexDaoImpl method getAll.

@Override
public List<PerunNotifRegex> getAll() {
    logger.debug("Getting all PerunNotifRegexes from db.");
    List<PerunNotifRegex> result = this.getJdbcTemplate().query("SELECT * from pn_regex ", PerunNotifRegex.PERUN_NOTIF_REGEX);
    logger.debug("Regexes loaded from db: {}, loading objects.", result);
    for (PerunNotifRegex regex : result) {
        List<PerunNotifObject> objects = this.getJdbcTemplate().query("SELECT * from pn_object object JOIN pn_regex_object bind ON object.id = bind.object_id WHERE bind.regex_id = ?", new Object[] { regex.getId() }, PerunNotifObject.PERUN_NOTIF_OBJECT);
        regex.addObjects(objects);
    }
    logger.debug("Objects loaded, resulting regexes: {}", result);
    return result;
}
Also used : PerunNotifRegex(cz.metacentrum.perun.notif.entities.PerunNotifRegex) PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject)

Example 7 with PerunNotifRegex

use of cz.metacentrum.perun.notif.entities.PerunNotifRegex in project perun by CESNET.

the class PerunNotifRegexDaoImpl method getPerunNotifRegexById.

@Override
public PerunNotifRegex getPerunNotifRegexById(int id) throws InternalErrorException {
    logger.debug("Loading regex from db by id: {}", id);
    PerunNotifRegex regex = null;
    try {
        regex = this.getJdbcTemplate().queryForObject("SELECT * from pn_regex where id = ?", new Object[] { id }, PerunNotifRegex.PERUN_NOTIF_REGEX);
    } catch (EmptyResultDataAccessException ex) {
        logger.debug("Regex with id: {}, not found.", id);
        return null;
    }
    logger.debug("Regex with id: {}, loaded from db. Loading objects.", id);
    List<PerunNotifObject> objects = this.getJdbcTemplate().query("SELECT * from pn_object object JOIN pn_regex_object bind ON object.id = bind.object_id WHERE bind.regex_id = ?", new Object[] { regex.getId() }, PerunNotifObject.PERUN_NOTIF_OBJECT);
    regex.addObjects(objects);
    logger.debug("Objects loaded result: {}", regex);
    return regex;
}
Also used : PerunNotifRegex(cz.metacentrum.perun.notif.entities.PerunNotifRegex) PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject)

Example 8 with PerunNotifRegex

use of cz.metacentrum.perun.notif.entities.PerunNotifRegex in project perun by CESNET.

the class PerunNotifRegexManagerImpl method getIdsOfRegexesMatchingMessage.

@Override
public Set<Integer> getIdsOfRegexesMatchingMessage(PerunNotifAuditMessage auditMessage) throws InternalErrorException {
    Set<PerunNotifObject> setOfObjects = new HashSet<PerunNotifObject>();
    for (PerunBean bean : auditMessage.getPerunBeanList()) {
        for (PerunNotifObject object : allObjects) {
            if (object.getObjectClass() != null) {
                if (bean.getClass().isAssignableFrom(object.getObjectClass())) {
                    setOfObjects.add(object);
                }
            }
        }
    }
    Set<Integer> result = new HashSet<Integer>();
    for (PerunNotifRegex regex : allRegex) {
        if (auditMessage.getMessage().matches(regex.getRegex())) {
            //We test whether message has all objects
            boolean matches = true;
            for (PerunNotifObject object : regex.getObjects()) {
                if (!setOfObjects.contains(object)) {
                    matches = false;
                }
            }
            if (matches) {
                result.add(regex.getId());
            }
        }
    }
    return result;
}
Also used : PerunBean(cz.metacentrum.perun.core.api.PerunBean) PerunNotifRegex(cz.metacentrum.perun.notif.entities.PerunNotifRegex) HashSet(java.util.HashSet) PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject)

Example 9 with PerunNotifRegex

use of cz.metacentrum.perun.notif.entities.PerunNotifRegex in project perun by CESNET.

the class PerunNotifRegexManagerImpl method removePerunNotifObjectFromCache.

@Override
public void removePerunNotifObjectFromCache(PerunNotifObject objectToRemove) {
    boolean removed = false;
    for (Iterator<PerunNotifObject> iter = allObjects.iterator(); iter.hasNext(); ) {
        PerunNotifObject objectFromCache = iter.next();
        if (objectFromCache.getId().equals(objectToRemove.getId())) {
            iter.remove();
            removed = true;
        }
    }
    if (!removed) {
        logger.warn("Remove of object from cache failed. Object is not in cache. ID: {}", objectToRemove.getId());
    }
    for (PerunNotifRegex regex : allRegex) {
        Set<PerunNotifObject> regexObjects = regex.getObjects();
        if (regexObjects.contains(objectToRemove)) {
            regexObjects.remove(objectToRemove);
        }
    }
}
Also used : PerunNotifRegex(cz.metacentrum.perun.notif.entities.PerunNotifRegex) PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject)

Example 10 with PerunNotifRegex

use of cz.metacentrum.perun.notif.entities.PerunNotifRegex in project perun by CESNET.

the class PerunNotifTemplateDaoImpl method getPerunNotifTemplateById.

@Override
public PerunNotifTemplate getPerunNotifTemplateById(int id) throws InternalErrorException {
    PerunNotifTemplate template = null;
    try {
        template = this.getJdbcTemplate().queryForObject("SELECT * from pn_template where id = ?", new Object[] { id }, PerunNotifTemplate.PERUN_NOTIF_TEMPLATE);
    } catch (EmptyResultDataAccessException ex) {
        //This exception is thrown when object is not found
        return null;
    }
    Set<PerunNotifRegex> regexes = perunNotifRegexDao.getPerunNotifRegexForTemplateId(template.getId());
    template.setMatchingRegexs(regexes);
    List<PerunNotifReceiver> perunNotifReceiver = this.getJdbcTemplate().query("SELECT * from pn_receiver where template_id = ?", new Object[] { template.getId() }, PerunNotifReceiver.PERUN_NOTIF_RECEIVER);
    template.setReceivers(perunNotifReceiver);
    List<PerunNotifTemplateMessage> perunNotifTemplateMessages = this.getJdbcTemplate().query("SELECT * from pn_template_message where template_id = ?", new Object[] { template.getId() }, PerunNotifTemplateMessage.PERUN_NOTIF_TEMPLATE_MESSAGE_ROW_MAPPER);
    template.setPerunNotifTemplateMessages(perunNotifTemplateMessages);
    return template;
}
Also used : PerunNotifTemplate(cz.metacentrum.perun.notif.entities.PerunNotifTemplate) PerunNotifTemplateMessage(cz.metacentrum.perun.notif.entities.PerunNotifTemplateMessage) PerunNotifReceiver(cz.metacentrum.perun.notif.entities.PerunNotifReceiver) PerunNotifRegex(cz.metacentrum.perun.notif.entities.PerunNotifRegex) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Aggregations

PerunNotifRegex (cz.metacentrum.perun.notif.entities.PerunNotifRegex)10 PerunNotifObject (cz.metacentrum.perun.notif.entities.PerunNotifObject)7 HashSet (java.util.HashSet)3 PerunNotifReceiver (cz.metacentrum.perun.notif.entities.PerunNotifReceiver)2 PerunNotifTemplate (cz.metacentrum.perun.notif.entities.PerunNotifTemplate)2 PerunNotifTemplateMessage (cz.metacentrum.perun.notif.entities.PerunNotifTemplateMessage)2 NotExistsException (cz.metacentrum.perun.notif.exceptions.NotExistsException)2 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)2 PerunBean (cz.metacentrum.perun.core.api.PerunBean)1 NotifRegexAlreadyExistsException (cz.metacentrum.perun.notif.exceptions.NotifRegexAlreadyExistsException)1 PerunNotifRegexUsedException (cz.metacentrum.perun.notif.exceptions.PerunNotifRegexUsedException)1