Search in sources :

Example 6 with PerunNotifObject

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

the class PerunNotifRegexDaoImpl method getPerunNotifRegexForTemplateId.

@Override
public Set<PerunNotifRegex> getPerunNotifRegexForTemplateId(int id) throws InternalErrorException {
    logger.debug("Loading regexes for template with id: {}", id);
    List<PerunNotifRegex> regexes = this.getJdbcTemplate().query("SELECT * from pn_regex regex JOIN pn_template_regex bind ON regex.id=bind.regex_id WHERE bind.template_id = ?", new Object[] { id }, PerunNotifRegex.PERUN_NOTIF_REGEX);
    if (regexes != null) {
        for (PerunNotifRegex regex : regexes) {
            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("Regexes loaded with object for template id: {}, result: {}", Arrays.asList(id, regexes));
    return new HashSet<PerunNotifRegex>(regexes);
}
Also used : PerunNotifRegex(cz.metacentrum.perun.notif.entities.PerunNotifRegex) PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject) HashSet(java.util.HashSet)

Example 7 with PerunNotifObject

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

the class PerunNotifObjectDaoImpl method getPerunNotifObjectById.

@Override
public PerunNotifObject getPerunNotifObjectById(int id) throws InternalErrorException {
    logger.debug("Getting PerunNotifObject from db by id: {}", id);
    try {
        PerunNotifObject object = this.getJdbcTemplate().queryForObject("SELECT * FROM pn_object object where object.id = ?", new Object[] { id }, PerunNotifObject.PERUN_NOTIF_OBJECT);
        logger.debug("PerunNotifObject retrieved from db: {}", object);
        return object;
    } catch (EmptyResultDataAccessException ex) {
        logger.debug("PerunNotifObject with id: {} not found.", id);
        return null;
    }
}
Also used : EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject)

Example 8 with PerunNotifObject

use of cz.metacentrum.perun.notif.entities.PerunNotifObject 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 9 with PerunNotifObject

use of cz.metacentrum.perun.notif.entities.PerunNotifObject 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 10 with PerunNotifObject

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

the class PerunNotifObjectManagerImpl method removePerunNotifObjectById.

@Override
public void removePerunNotifObjectById(int id) throws InternalErrorException {
    PerunNotifObject objectToRemove = getPerunNotifObjectById(id);
    if (objectToRemove == null) {
        throw new NotExistsException("Object does not exists in db.");
    }
    perunNotifObjectDao.removePerunNotifObjectById(id);
    perunNotifRegexManager.removePerunNotifObjectFromCache(objectToRemove);
}
Also used : NotExistsException(cz.metacentrum.perun.notif.exceptions.NotExistsException) PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject)

Aggregations

PerunNotifObject (cz.metacentrum.perun.notif.entities.PerunNotifObject)12 PerunNotifRegex (cz.metacentrum.perun.notif.entities.PerunNotifRegex)7 HashSet (java.util.HashSet)3 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