Search in sources :

Example 6 with InternalErrorException

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

the class Auditer method registerListener.

/**
	 * Register the listener.
	 *
	 * @param listener
	 * @return false if the listener is already registered
	 */
@Deprecated
public boolean registerListener(AuditerListener listener, String name) throws InternalErrorException {
    if (listenersMap.containsKey(listener))
        return false;
    ListenerThread listenerThread = new ListenerThread(listener);
    listenersMap.put(listener, listenerThread);
    listenerThread.setConsumerName(name);
    // Get the last processed id of the current consumer
    try {
        // Check if the consumer is registered
        if (0 == jdbc.queryForInt("select count(id) from auditer_consumers where name=?", name)) {
            // Create the consumer
            int consumerId = Utils.getNewId(jdbc, "auditer_consumers_id_seq");
            jdbc.update("insert into auditer_consumers (id, name, last_processed_id) values (?,?,?)", consumerId, name, this.lastProcessedId);
            log.debug("New consumer ['{}'] created.", name);
            listenerThread.setLastProcessedId(this.lastProcessedId);
        } else {
            listenerThread.setLastProcessedId(jdbc.queryForInt("select last_processed_id from auditer_consumers where name=?", name));
        }
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
    listenerThread.start();
    log.debug("New Auditer listener registered. {}", listener);
    return true;
}
Also used : InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 7 with InternalErrorException

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

the class Auditer method flush.

/**
	 * Imidiately flushes stored message for last top-level transaction into the log
	 *
	 */
public void flush() {
    List<List<List<AuditerMessage>>> topLevelTransactions = getTopLevelTransactions();
    if (topLevelTransactions.isEmpty()) {
        log.trace("No messages to flush");
        return;
    }
    List<List<AuditerMessage>> transactionChain = topLevelTransactions.get(topLevelTransactions.size() - 1);
    if (transactionChain.isEmpty()) {
        log.trace("No messages to flush");
        topLevelTransactions.remove(topLevelTransactions.size() - 1);
        return;
    }
    if (transactionChain.size() != 1) {
        log.error("There should be only one list of messages while flushing representing the most outer transaction.");
    }
    List<AuditerMessage> messages = transactionChain.get(0);
    topLevelTransactions.remove(topLevelTransactions.size() - 1);
    if (topLevelTransactions.isEmpty()) {
        TransactionSynchronizationManager.unbindResourceIfPossible(this);
    }
    log.trace("Audit messages was flushed for current transaction.");
    synchronized (LOCK_DB_TABLE_AUDITER_LOG) {
        storeMessagesToDb(messages);
    }
    for (AuditerMessage message : messages) {
        for (VirtualAttributesModuleImplApi virtAttrModuleImplApi : registeredAttributesModules) {
            List<String> resolvingMessages = new ArrayList<String>();
            try {
                resolvingMessages.addAll(virtAttrModuleImplApi.resolveVirtualAttributeValueChange((PerunSessionImpl) message.getOriginaterPerunSession(), message.getMessage()));
            } catch (InternalErrorException ex) {
                log.error("Error when auditer trying to resolve messages in modules.", ex);
            } catch (WrongAttributeAssignmentException ex) {
                log.error("Error when auditer trying to resolve messages in modules.", ex);
            } catch (WrongReferenceAttributeValueException ex) {
                log.error("Error when auditer trying to resolve messages in modules.", ex);
            } catch (AttributeNotExistsException ex) {
                log.error("Error when auditer trying to resolve messages in modules.", ex);
            }
            if (!resolvingMessages.isEmpty()) {
                List<AuditerMessage> resolvingAuditerMessages = new ArrayList<>();
                for (String msg : resolvingMessages) {
                    resolvingAuditerMessages.add(new AuditerMessage(message.getOriginaterPerunSession(), msg));
                }
                storeMessagesToDb(resolvingAuditerMessages);
            }
        }
    }
}
Also used : VirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.VirtualAttributesModuleImplApi) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with InternalErrorException

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

the class AttributesManagerImpl method setAttributeRight.

@Override
public void setAttributeRight(PerunSession sess, AttributeRights rights) throws InternalErrorException {
    try {
        // get action types of the attribute and role from the database
        List<ActionType> dbActionTypes = jdbc.query("select action_types.action_type as action_type from attributes_authz join action_types " + "on attributes_authz.action_type_id=action_types.id where attr_id=? and " + "role_id=(select id from roles where name=?)", new RowMapper<ActionType>() {

            @Override
            public ActionType mapRow(ResultSet rs, int rowNum) throws SQLException {
                return ActionType.valueOf(rs.getString("action_type").toUpperCase());
            }
        }, rights.getAttributeId(), rights.getRole().getRoleName());
        // inserting
        List<ActionType> actionTypesToInsert = new ArrayList<ActionType>();
        actionTypesToInsert.addAll(rights.getRights());
        actionTypesToInsert.removeAll(dbActionTypes);
        for (ActionType actionType : actionTypesToInsert) {
            jdbc.update("insert into attributes_authz (attr_id, role_id, action_type_id) values " + "(?, (select id from roles where name=?), (select id from action_types where action_type=?))", rights.getAttributeId(), rights.getRole().getRoleName(), actionType.getActionType());
        }
        // deleting
        List<ActionType> actionTypesToDelete = new ArrayList<ActionType>();
        actionTypesToDelete.addAll(dbActionTypes);
        actionTypesToDelete.removeAll(rights.getRights());
        for (ActionType actionType : actionTypesToDelete) {
            if (0 == jdbc.update("delete from attributes_authz where attr_id=? and role_id=(select id from roles where name=?) and " + "action_type_id=(select id from action_types where action_type=?)", rights.getAttributeId(), rights.getRole().getRoleName(), actionType.getActionType())) {
                throw new ConsistencyErrorException("Trying to delete non existing row : AttributeRight={ attributeId=" + Integer.toString(rights.getAttributeId()) + " role=" + rights.getRole().getRoleName() + " actionType=" + actionType.getActionType());
            }
        }
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) ActionType(cz.metacentrum.perun.core.api.ActionType) ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 9 with InternalErrorException

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

the class AttributesManagerImpl method actionTypeExists.

public boolean actionTypeExists(PerunSession sess, ActionType actionType) throws InternalErrorException {
    Utils.notNull(actionType, "actionType");
    Utils.notNull(actionType.getActionType(), "actionType.actionType");
    try {
        return 1 == jdbc.queryForInt("select count('x') from action_types where action_type=?", actionType.getActionType());
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 10 with InternalErrorException

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

the class AttributesManagerImpl method getAttributesModule.

/**
	 * Get the atributeModule
	 *
	 * @param moduleName name of the module
	 * @return instance of attribute module
	 *         null if attribute doesn't exists
	 *
	 * @throws InternalErrorException
	 */
private Object getAttributesModule(PerunSession sess, String moduleName) throws InternalErrorException {
    //try to get already loaded module.
    if (attributesModulesMap.containsKey(moduleName))
        return attributesModulesMap.get(moduleName);
    try {
        Class<?> moduleClass = classLoader.loadClass(moduleName);
        log.debug("Attribute module found. Module class={}  Module name={}", moduleClass, moduleName);
        Object module = moduleClass.newInstance();
        attributesModulesMap.put(moduleName, (AttributesModuleImplApi) module);
        return module;
    } catch (ClassNotFoundException ex) {
        //attrribute module don't exist
        return null;
    } catch (InstantiationException ex) {
        throw new InternalErrorException("Attribute module " + moduleName + " cannot be instaciated.", ex);
    } catch (IllegalAccessException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

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