Search in sources :

Example 1 with NotExistsException

use of cz.metacentrum.perun.notif.exceptions.NotExistsException in project perun by CESNET.

the class PerunNotifTemplateManagerImpl method removePerunNotifTemplateMessage.

@Override
public void removePerunNotifTemplateMessage(int id) throws InternalErrorException {
    PerunNotifTemplateMessage templateMessage = getPerunNotifTemplateMessageById(id);
    if (templateMessage == null) {
        throw new NotExistsException("Template message with id: " + id + " not exists.");
    }
    perunNotifTemplateDao.removePerunNotifTemplateMessage(id);
    PerunNotifTemplate template = allTemplatesById.get(templateMessage.getTemplateId());
    template.getPerunNotifTemplateMessages().remove(templateMessage);
    StringTemplateLoader stringTemplateLoader = (StringTemplateLoader) configuration.getTemplateLoader();
    String templateName = createTemplateName(templateMessage);
    stringTemplateLoader.removeTemplate(templateName);
    configuration.clearTemplateCache();
}
Also used : StringTemplateLoader(cz.metacentrum.perun.notif.StringTemplateLoader) NotExistsException(cz.metacentrum.perun.notif.exceptions.NotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)

Example 2 with NotExistsException

use of cz.metacentrum.perun.notif.exceptions.NotExistsException in project perun by CESNET.

the class PerunNotifRegexManagerImpl method createPerunNotifRegex.

@Override
public PerunNotifRegex createPerunNotifRegex(PerunNotifRegex regex) throws InternalErrorException, 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 3 with NotExistsException

use of cz.metacentrum.perun.notif.exceptions.NotExistsException in project perun by CESNET.

the class PerunNotifRegexManagerImpl method removePerunNotifRegexById.

@Override
public void removePerunNotifRegexById(int id) throws InternalErrorException, 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 4 with NotExistsException

use of cz.metacentrum.perun.notif.exceptions.NotExistsException 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

NotExistsException (cz.metacentrum.perun.notif.exceptions.NotExistsException)4 PerunNotifObject (cz.metacentrum.perun.notif.entities.PerunNotifObject)2 PerunNotifRegex (cz.metacentrum.perun.notif.entities.PerunNotifRegex)2 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)1 StringTemplateLoader (cz.metacentrum.perun.notif.StringTemplateLoader)1 NotifRegexAlreadyExistsException (cz.metacentrum.perun.notif.exceptions.NotifRegexAlreadyExistsException)1 PerunNotifRegexUsedException (cz.metacentrum.perun.notif.exceptions.PerunNotifRegexUsedException)1