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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations