Search in sources :

Example 1 with InternalErrorException

use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.

the class Auditer method pollConsumerMessages.

public List<String> pollConsumerMessages(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<String> messages = jdbc.query("select " + Auditer.auditMessageMappingSelectQuery + " from auditer_log where id > ? and id <= ? order by id", AUDITER_LOG_MAPPER, 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<String>();
    } catch (Exception ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : 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)

Example 2 with InternalErrorException

use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.

the class Auditer method pollConsumerFullMessages.

public List<String> pollConsumerFullMessages(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<String> messages = jdbc.query("select " + Auditer.auditMessageMappingSelectQuery + " from auditer_log where id > ? and id <= ? order by id", AUDITER_FULL_LOG_MAPPER, 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<String>();
    } catch (Exception ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : 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)

Example 3 with InternalErrorException

use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.

the class Auditer method initialize.

public void initialize() throws InternalErrorException {
    try {
        this.lastProcessedId = jdbc.queryForInt("select max(id) from auditer_log");
        log.debug("Auditer initialized with lastProcessedId [{}].", this.lastProcessedId);
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 4 with InternalErrorException

use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.

the class Auditer method createAuditerConsumer.

public void createAuditerConsumer(String consumerName) throws InternalErrorException {
    try {
        int lastProcessedId = jdbc.queryForInt("select max(id) from auditer_log");
        int consumerId = Utils.getNewId(jdbc, "auditer_consumers_id_seq");
        jdbc.update("insert into auditer_consumers (id, name, last_processed_id) values (?,?,?)", consumerId, consumerName, lastProcessedId);
        log.debug("New consumer [name: '{}', lastProcessedId: '{}'] created.", consumerName, lastProcessedId);
    } catch (Exception e) {
        throw new InternalErrorException(e);
    }
}
Also used : 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)

Example 5 with InternalErrorException

use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.

the class Auditer method storeMessageToDb.

/**
	 * Store the message to the DB.
	 *
	 * @param sess
	 * @param message
	 */
public void storeMessageToDb(final PerunSession sess, final String message) {
    synchronized (LOCK_DB_TABLE_AUDITER_LOG) {
        try {
            final int msgId = Utils.getNewId(jdbc, "auditer_log_id_seq");
            jdbc.execute("insert into auditer_log (id, msg, actor, created_at, created_by_uid) values (?,?,?," + Compatibility.getSysdate() + ",?)", new AbstractLobCreatingPreparedStatementCallback(lobHandler) {

                public void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
                    ps.setInt(1, msgId);
                    lobCreator.setClobAsString(ps, 2, message);
                    ps.setString(3, sess.getPerunPrincipal().getActor());
                    ps.setInt(4, sess.getPerunPrincipal().getUserId());
                }
            });
        } catch (RuntimeException e) {
            log.error("Cannot store auditer log message ['{}'], exception: {}", message, e);
        } catch (InternalErrorException e) {
            log.error("Cannot get unique id for new auditer log message ['{}'], exception: {}", message, e);
        }
    }
}
Also used : AbstractLobCreatingPreparedStatementCallback(org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatementCallback) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) LobCreator(org.springframework.jdbc.support.lob.LobCreator)

Aggregations

InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)376 Attribute (cz.metacentrum.perun.core.api.Attribute)119 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)104 ArrayList (java.util.ArrayList)94 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)89 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)78 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)68 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)67 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)44 User (cz.metacentrum.perun.core.api.User)37 Group (cz.metacentrum.perun.core.api.Group)36 InternalErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException)33 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)33 HashMap (java.util.HashMap)30 IOException (java.io.IOException)28 Member (cz.metacentrum.perun.core.api.Member)24 Map (java.util.Map)24 Facility (cz.metacentrum.perun.core.api.Facility)23 List (java.util.List)23 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)22