use of cz.metacentrum.perun.notif.entities.PerunNotifRegex in project perun by CESNET.
the class PerunNotifRegexManagerImpl method updatePerunNotifRegex.
public PerunNotifRegex updatePerunNotifRegex(PerunNotifRegex regex) {
PerunNotifRegex oldRegex = perunNotifRegexDao.getPerunNotifRegexById(regex.getId());
PerunNotifRegex updatedRegex = perunNotifRegexDao.updatePerunNotifRegexInternals(regex);
Set<PerunNotifObject> oldObjects = new HashSet<PerunNotifObject>(oldRegex.getObjects());
Set<PerunNotifObject> newObjects = updatedRegex.getObjects();
for (PerunNotifObject object : newObjects) {
if (oldObjects.contains(object)) {
// Object relation has not changed
oldObjects.remove(object);
} else {
// Object is new in relation
perunNotifObjectDao.saveObjectRelation(updatedRegex.getId(), object.getId());
}
}
// In set oldObjects remains now only objects which relation has been removed.
for (PerunNotifObject objectsToRemove : oldObjects) {
perunNotifObjectDao.removePerunNotifObjectRegexRelation(updatedRegex.getId(), objectsToRemove.getId());
}
for (PerunNotifRegex regexToUpdate : allRegex) {
if (regexToUpdate.getId().equals(updatedRegex.getId())) {
regexToUpdate.update(updatedRegex);
return updatedRegex;
}
}
logger.warn("Updating regex in cache failed. Regex not found in cache id: {}", updatedRegex.getId());
return updatedRegex;
}
use of cz.metacentrum.perun.notif.entities.PerunNotifRegex in project perun by CESNET.
the class PerunNotifRegexManagerImpl method removePerunNotifRegexById.
@Override
public void removePerunNotifRegexById(int id) throws PerunNotifRegexUsedException {
PerunNotifRegex regex = getPerunNotifRegexById(id);
if (regex == null) {
throw new NotExistsException("Regex does not exists in db");
}
List<Integer> referencedTemplates = perunNotifRegexDao.getTemplateIdsForRegexId(id);
if (referencedTemplates != null && !referencedTemplates.isEmpty()) {
throw new PerunNotifRegexUsedException("Regex is still used.", referencedTemplates);
}
perunNotifRegexDao.removePerunNotifRegexById(id);
allRegex.remove(regex);
}
use of cz.metacentrum.perun.notif.entities.PerunNotifRegex in project perun by CESNET.
the class PerunNotifRegexManagerImpl method createPerunNotifRegex.
@Override
public PerunNotifRegex createPerunNotifRegex(PerunNotifRegex regex) throws NotifRegexAlreadyExistsException {
// check if there is no other Notif regex with the same regular expression
for (PerunNotifRegex item : getAllPerunNotifRegexes()) {
if (item.getRegex().equals(regex.getRegex())) {
throw new NotifRegexAlreadyExistsException(regex);
}
}
PerunNotifRegex perunNotifRegex = perunNotifRegexDao.saveInternals(regex);
for (PerunNotifObject object : regex.getObjects()) {
if (object.getId() == null) {
throw new NotExistsException("Object does not exists.");
}
perunNotifObjectDao.saveObjectRelation(regex.getId(), object.getId());
}
allRegex.add(regex);
return perunNotifRegex;
}
use of cz.metacentrum.perun.notif.entities.PerunNotifRegex in project perun by CESNET.
the class PerunNotifTemplateDaoImpl method getAllPerunNotifTemplates.
public List<PerunNotifTemplate> getAllPerunNotifTemplates() {
List<PerunNotifTemplate> result = this.getJdbcTemplate().query("SELECT * from pn_template", PerunNotifTemplate.PERUN_NOTIF_TEMPLATE);
for (PerunNotifTemplate template : result) {
// Gets all template ids which are connected to given regexIds
Set<PerunNotifRegex> perunNotifRegexs = perunNotifRegexDao.getPerunNotifRegexForTemplateId(template.getId());
template.setMatchingRegexs(perunNotifRegexs);
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 result;
}
use of cz.metacentrum.perun.notif.entities.PerunNotifRegex in project perun by CESNET.
the class PerunNotifRegexDaoImpl method getPerunNotifRegexForTemplateId.
@Override
public Set<PerunNotifRegex> getPerunNotifRegexForTemplateId(int id) {
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);
}
Aggregations