Search in sources :

Example 11 with PerunNotifObject

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

Example 12 with PerunNotifObject

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