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;
}
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;
}
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;
}
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);
}
}
}
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;
}
Aggregations