Search in sources :

Example 1 with AuditMessage

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);
}
Also used : AuditMessage(cz.metacentrum.perun.core.api.AuditMessage) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 2 with AuditMessage

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;
    }
}
Also used : AuditMessage(cz.metacentrum.perun.core.api.AuditMessage) PerunNotifAuditMessage(cz.metacentrum.perun.notif.entities.PerunNotifAuditMessage) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) PerunNotifAuditMessage(cz.metacentrum.perun.notif.entities.PerunNotifAuditMessage) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 3 with AuditMessage

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);
    }
}
Also used : AuditMessage(cz.metacentrum.perun.core.api.AuditMessage) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) DataAccessException(org.springframework.dao.DataAccessException) SQLException(java.sql.SQLException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) IOException(java.io.IOException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)

Aggregations

AuditMessage (cz.metacentrum.perun.core.api.AuditMessage)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 ArrayList (java.util.ArrayList)2 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)1 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)1 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)1 InternalErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException)1 PerunNotifAuditMessage (cz.metacentrum.perun.notif.entities.PerunNotifAuditMessage)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 Test (org.junit.Test)1 DataAccessException (org.springframework.dao.DataAccessException)1 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)1