Search in sources :

Example 66 with ConsistencyErrorException

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

the class Utils method parseAdditionalUserExtSource.

/**
 * Returns additional user ext source either found in Perun or creates new. Parameter userExtSourceRaw is array of
 * Strings containing name, type and extLogin. If any of the required parts is empty, ParserException is thrown.
 * Used in extractAdditionalUserExtSources to get ues.
 *
 * @param sess perun session
 * @param userExtSourceRaw array of strings containing all parts of ues
 * @return UserExtSource additional ues
 */
private static UserExtSource parseAdditionalUserExtSource(PerunSession sess, String[] userExtSourceRaw) {
    // Get extLogin from 3rd part of userExtSourceRaw as well as ues attributes, so it needs to be parsed from it
    String extLogin = userExtSourceRaw[2].split(";")[0];
    // Check whether any of the required parts of ues are not empty
    if (userExtSourceRaw[0].isEmpty() || userExtSourceRaw[1].isEmpty() || extLogin.isEmpty()) {
        throw new ParserException("Some of the required parts of userExtSource are empty.");
    }
    ExtSource additionalExtSource;
    try {
        // Try to get extSource, with full extSource object (containg ID)
        additionalExtSource = ((PerunBl) sess.getPerun()).getExtSourcesManagerBl().getExtSourceByName(sess, userExtSourceRaw[0]);
    } catch (ExtSourceNotExistsException e) {
        try {
            // Create new one if not exists
            additionalExtSource = new ExtSource(userExtSourceRaw[0], userExtSourceRaw[1]);
            additionalExtSource = ((PerunBl) sess.getPerun()).getExtSourcesManagerBl().createExtSource(sess, additionalExtSource, null);
        } catch (ExtSourceExistsException e1) {
            throw new ConsistencyErrorException("Creating existing extSource: " + userExtSourceRaw[0]);
        }
    }
    // Get optional LoA (0 if not stated)
    int loa = parseAdditionalUESLoa(userExtSourceRaw);
    return new UserExtSource(additionalExtSource, loa, extLogin);
}
Also used : ParserException(cz.metacentrum.perun.core.api.exceptions.ParserException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceExistsException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)

Example 67 with ConsistencyErrorException

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

the class urn_perun_entityless_attribute_def_def_namespace_maxUID method checkAttributeSemantics.

@Override
public void checkAttributeSemantics(PerunSessionImpl perunSession, String key, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    Integer maxUID = attribute.valueAsInteger();
    if (maxUID == null)
        return;
    try {
        Attribute minUIDAttr = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, key, A_E_namespaceMinUID);
        Integer minUID = minUIDAttr.valueAsInteger();
        if (minUID != null) {
            if (maxUID < minUID)
                throw new WrongReferenceAttributeValueException(attribute, minUIDAttr, key, null, key, null, "Attribute value must be more than minUID. MinUID = " + minUID + ", and maxUID try to set = " + maxUID);
        }
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException("Attribute namespace-minUID is supposed to exist.", ex);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)

Example 68 with ConsistencyErrorException

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

the class UsersManagerImpl method updateNameTitles.

@Override
public User updateNameTitles(PerunSession sess, User user) {
    try {
        User userDb = jdbc.queryForObject("select " + userMappingSelectQuery + " from users where id=? ", USER_MAPPER, user.getId());
        if (userDb == null) {
            throw new ConsistencyErrorException("Updating titles for non existing user");
        }
        if ((user.getTitleBefore() != null && !user.getTitleBefore().equals(userDb.getTitleBefore())) || (user.getTitleBefore() == null && userDb.getTitleBefore() != null)) {
            jdbc.update("update users set title_before=?, modified_by=?, modified_by_uid=?, modified_at=" + Compatibility.getSysdate() + " where id=?", user.getTitleBefore(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getUserId(), user.getId());
            userDb.setTitleBefore(user.getTitleBefore());
        }
        if ((user.getTitleAfter() != null && !user.getTitleAfter().equals(userDb.getTitleAfter())) || ((user.getTitleAfter() == null && userDb.getTitleAfter() != null))) {
            jdbc.update("update users set title_after=?, modified_by=?, modified_by_uid=?, modified_at=" + Compatibility.getSysdate() + " where id=?", user.getTitleAfter(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getUserId(), user.getId());
            userDb.setTitleAfter(user.getTitleAfter());
        }
        return userDb;
    } catch (RuntimeException err) {
        throw new InternalErrorException(err);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 69 with ConsistencyErrorException

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

the class UsersManagerImpl method userExtSourceExists.

@Override
public boolean userExtSourceExists(PerunSession sess, UserExtSource userExtSource) {
    Utils.notNull(userExtSource, "userExtSource");
    Utils.notNull(userExtSource.getLogin(), "userExtSource.getLogin");
    Utils.notNull(userExtSource.getExtSource(), "userExtSource.getExtSource");
    try {
        // check by ext identity (login/ext source ID)
        if (userExtSource.getUserId() >= 0) {
            int numberOfExistences = jdbc.queryForInt("select count(1) from user_ext_sources where login_ext=? and ext_sources_id=? and user_id=?", userExtSource.getLogin(), userExtSource.getExtSource().getId(), userExtSource.getUserId());
            if (numberOfExistences == 1) {
                return true;
            } else if (numberOfExistences > 1) {
                throw new ConsistencyErrorException("UserExtSource " + userExtSource + " exists more than once.");
            }
            return false;
        } else {
            int numberOfExistences = jdbc.queryForInt("select count(1) from user_ext_sources where login_ext=? and ext_sources_id=?", userExtSource.getLogin(), userExtSource.getExtSource().getId());
            if (numberOfExistences == 1) {
                return true;
            } else if (numberOfExistences > 1) {
                throw new ConsistencyErrorException("UserExtSource " + userExtSource + " exists more than once.");
            }
            return false;
        }
    } catch (EmptyResultDataAccessException ex) {
        return false;
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 70 with ConsistencyErrorException

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

the class VosManagerImpl method deleteVo.

@Override
public Vo deleteVo(PerunSession sess, Vo vo) {
    try {
        // Delete authz entries for this VO
        AuthzResolverBlImpl.removeAllAuthzForVo(sess, vo);
        vo = jdbc.queryForObject("delete from vos where id=? returning " + voMappingSelectQuery, VO_MAPPER, vo.getId());
    } catch (EmptyResultDataAccessException e) {
        throw new ConsistencyErrorException("no record was deleted from the DB.");
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
    log.debug("Vo {} deleted", vo);
    return vo;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)281 Attribute (cz.metacentrum.perun.core.api.Attribute)212 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)162 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)120 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)111 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)102 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)84 User (cz.metacentrum.perun.core.api.User)60 ArrayList (java.util.ArrayList)51 Group (cz.metacentrum.perun.core.api.Group)44 Facility (cz.metacentrum.perun.core.api.Facility)41 Resource (cz.metacentrum.perun.core.api.Resource)37 Member (cz.metacentrum.perun.core.api.Member)30 LinkedHashMap (java.util.LinkedHashMap)23 Vo (cz.metacentrum.perun.core.api.Vo)22 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)21 GroupResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)20 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)19 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)17 VoNotExistsException (cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)17