Search in sources :

Example 1 with PerunNotifObject

use of cz.metacentrum.perun.notif.entities.PerunNotifObject in project perun by CESNET.

the class PerunNotifObjectManagerImpl method createPerunNotifObject.

@Override
public PerunNotifObject createPerunNotifObject(PerunNotifObject object) throws InternalErrorException {
    PerunNotifObject perunNotifObject = perunNotifObjectDao.createPerunNotifObject(object);
    perunNotifRegexManager.addObjectToCache(object);
    return perunNotifObject;
}
Also used : PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject)

Example 2 with PerunNotifObject

use of cz.metacentrum.perun.notif.entities.PerunNotifObject in project perun by CESNET.

the class PerunNotifObjectManagerImpl method updatePerunNotifObject.

@Override
public PerunNotifObject updatePerunNotifObject(PerunNotifObject object) throws InternalErrorException {
    PerunNotifObject newObject = perunNotifObjectDao.updatePerunNotifObject(object);
    perunNotifRegexManager.addObjectToCache(newObject);
    return newObject;
}
Also used : PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject)

Example 3 with PerunNotifObject

use of cz.metacentrum.perun.notif.entities.PerunNotifObject in project perun by CESNET.

the class PerunNotifRegexManagerImpl method updatePerunNotifRegex.

public PerunNotifRegex updatePerunNotifRegex(PerunNotifRegex regex) throws InternalErrorException {
    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) HashSet(java.util.HashSet) PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject)

Example 4 with PerunNotifObject

use of cz.metacentrum.perun.notif.entities.PerunNotifObject 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 5 with PerunNotifObject

use of cz.metacentrum.perun.notif.entities.PerunNotifObject in project perun by CESNET.

the class PerunNotifObjectDaoImpl method updatePerunNotifObject.

@Override
public PerunNotifObject updatePerunNotifObject(PerunNotifObject object) throws InternalErrorException {
    logger.debug("Updating object in db: {}", object);
    this.getJdbcTemplate().update("update pn_object set properties = ?, name = ?, class_name = ? where id = ?", object.getSerializedProperties(), object.getName(), object.getObjectClass().getName(), object.getId());
    PerunNotifObject result = getPerunNotifObjectById(object.getId());
    logger.debug("PerunNotifObject updated in db, returning object: {}", result);
    return result;
}
Also used : 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