use of cz.metacentrum.perun.core.api.AuditMessage in project perun by CESNET.
the class AuditerImplIntegrationTest method getCorrectMessageFromLastMessages.
@Test
public void getCorrectMessageFromLastMessages() throws Exception {
System.out.println("AuditeTest.getCorrectMessageFromLastMessages");
for (int i = 0; i < 20; i++) {
if (i == 5)
perun.getAuditer().log(sess, "Abdjsj&#(234JSK");
else
perun.getAuditer().log(sess, "Testovaci text c." + i + ".");
}
List<AuditMessage> messages = perun.getAuditer().getMessages(20);
boolean contain = false;
for (AuditMessage m : messages) {
if (m.getMsg().equals("Abdjsj&#(234JSK"))
contain = true;
}
assertTrue("One of messages need to contain specific message.", contain);
}
use of cz.metacentrum.perun.core.api.AuditMessage in project perun by CESNET.
the class SchedulingManagerImpl method processPerunAuditMessages.
/**
* The method loads perun audit messages from the database and saves them as PerunNotifAudiMessages.
*/
public void processPerunAuditMessages() throws Exception {
List<PerunNotifAuditMessage> perunNotifAuditMessages = new ArrayList<PerunNotifAuditMessage>();
try {
List<AuditMessage> messages = perun.getAuditMessagesManagerBl().pollConsumerMessagesForParser(consumerName);
for (AuditMessage message : messages) {
try {
PerunNotifAuditMessage perunNotifAuditMessage = perunNotifAuditMessagesManager.saveMessageToPerunAuditerMessage(message.getMsg(), session);
perunNotifAuditMessages.add(perunNotifAuditMessage);
} catch (InternalErrorException ex) {
logger.error("Error during saving message to db. Message: " + message.getMsg());
throw ex;
}
}
} catch (Exception ex) {
logger.error("Error during perunNotification process.");
throw ex;
}
}
use of cz.metacentrum.perun.core.api.AuditMessage in project perun by CESNET.
the class Auditer method pollConsumerMessagesForParser.
public List<AuditMessage> pollConsumerMessagesForParser(String consumerName) throws InternalErrorException {
if (consumerName == null)
throw new InternalErrorException("Auditer consumer doesn't exist.");
try {
if (jdbc.queryForInt("select count(*) from auditer_consumers where name=?", consumerName) != 1) {
throw new InternalErrorException("Auditer consumer doesn't exist.");
}
int lastProcessedId = getLastProcessedId(consumerName);
int maxId = jdbc.queryForInt("select max(id) from auditer_log");
if (maxId > lastProcessedId) {
List<AuditMessage> messages = jdbc.query("select " + Auditer.auditMessageMappingSelectQuery + " from auditer_log where id > ? and id <= ? order by id", AUDITMESSAGE_MAPPER_FOR_PARSER, lastProcessedId, maxId);
lastProcessedId = maxId;
jdbc.update("update auditer_consumers set last_processed_id=?, modified_at=" + Compatibility.getSysdate() + " where name=?", lastProcessedId, consumerName);
return messages;
}
return new ArrayList<AuditMessage>();
} catch (Exception ex) {
throw new InternalErrorException(ex);
}
}
Aggregations