Search in sources :

Example 1 with PerunNotifRegex

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;
}
Also used : PerunNotifRegex(cz.metacentrum.perun.notif.entities.PerunNotifRegex) PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject) HashSet(java.util.HashSet)

Example 2 with PerunNotifRegex

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);
}
Also used : PerunNotifRegexUsedException(cz.metacentrum.perun.notif.exceptions.PerunNotifRegexUsedException) NotExistsException(cz.metacentrum.perun.notif.exceptions.NotExistsException) PerunNotifRegex(cz.metacentrum.perun.notif.entities.PerunNotifRegex)

Example 3 with PerunNotifRegex

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;
}
Also used : NotExistsException(cz.metacentrum.perun.notif.exceptions.NotExistsException) PerunNotifRegex(cz.metacentrum.perun.notif.entities.PerunNotifRegex) NotifRegexAlreadyExistsException(cz.metacentrum.perun.notif.exceptions.NotifRegexAlreadyExistsException) PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject)

Example 4 with 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;
}
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)

Example 5 with PerunNotifRegex

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);
}
Also used : PerunNotifRegex(cz.metacentrum.perun.notif.entities.PerunNotifRegex) PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject) HashSet(java.util.HashSet)

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