Search in sources :

Example 46 with InternalErrorException

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

the class DatabaseManagerImpl method getChangelogVersions.

public List<DBVersion> getChangelogVersions(String currentDBVersion, String fileName) throws InternalErrorException {
    Pattern versionPattern = Pattern.compile("^[1-9][0-9]*[.][0-9]+[.][0-9]+");
    Pattern commentPattern = Pattern.compile("^--.*");
    List<DBVersion> versions = new ArrayList<>();
    boolean versionFound = false;
    Resource resource = new ClassPathResource(fileName);
    try (BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream()))) {
        String line = br.readLine();
        while (line != null) {
            line = line.trim();
            // ignore empty lines and comments at the start of the file and between versions
            if (line.isEmpty() || commentPattern.matcher(line).matches()) {
                line = br.readLine();
                continue;
            }
            if (versionPattern.matcher(line).matches()) {
                //saving version
                DBVersion version = new DBVersion(line);
                //comparing two last version numbers
                if (!versions.isEmpty()) {
                    DBVersion previousVersion = versions.get(versions.size() - 1);
                    if (version.compareTo(previousVersion) >= 0) {
                        throw new InternalErrorException("Version numbers in changelog file are not increasing properly. " + "Version " + previousVersion.getVersion() + " should be higher than " + version.getVersion());
                    }
                }
                //the current db version was found, all new versions and their commands were saved to versions list
                if (line.equals(currentDBVersion)) {
                    versionFound = true;
                    break;
                }
                List<String> commands = new ArrayList<>();
                while ((line = br.readLine()) != null) {
                    line = line.trim();
                    // empty line means end of current version
                    if (line.isEmpty()) {
                        break;
                    }
                    commands.add(line);
                }
                //saving version commands
                version.setCommands(commands);
                versions.add(version);
            } else {
                throw new InternalErrorException("Version does not match the pattern required in " + fileName);
            }
        }
        if (!versionFound) {
            throw new InternalErrorException("Version " + currentDBVersion + " not found in " + fileName);
        }
    } catch (IOException e) {
        throw new InternalErrorException("Error reading " + fileName, e);
    }
    return versions;
}
Also used : Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) DBVersion(cz.metacentrum.perun.core.api.DBVersion) BufferedReader(java.io.BufferedReader)

Example 47 with InternalErrorException

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

the class MembersManagerEntry method createSpecificMember.

public Member createSpecificMember(PerunSession sess, Vo vo, Candidate candidate, List<User> specificUserOwners, SpecificUserType specificUserType, List<Group> groups) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, VoNotExistsException, PrivilegeException, UserNotExistsException, ExtendMembershipException, GroupNotExistsException, GroupOperationsException {
    Utils.checkPerunSession(sess);
    Utils.notNull(specificUserType, "specificUserType");
    //normal type is not allowed when creating specific member
    if (specificUserType.equals(SpecificUserType.NORMAL))
        throw new InternalErrorException("Type of specific user must be defined.");
    // if any group is not from the vo, throw an exception
    if (groups != null) {
        for (Group group : groups) {
            perunBl.getGroupsManagerBl().checkGroupExists(sess, group);
            if (group.getVoId() != vo.getId())
                throw new InternalErrorException("Group " + group + " is not from the vo " + vo + " where candidate " + candidate + " should be added.");
        }
    }
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo)) {
        throw new PrivilegeException(sess, "createSpecificMember (Specific User) - from candidate");
    }
    Utils.notNull(candidate, "candidate");
    getPerunBl().getVosManagerBl().checkVoExists(sess, vo);
    if (specificUserOwners.isEmpty())
        throw new InternalErrorException("List of specificUserOwners of " + candidate + " can't be empty.");
    for (User u : specificUserOwners) {
        getPerunBl().getUsersManagerBl().checkUserExists(sess, u);
    }
    return getMembersManagerBl().createSpecificMember(sess, vo, candidate, specificUserOwners, specificUserType, groups);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) User(cz.metacentrum.perun.core.api.User) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 48 with InternalErrorException

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

the class MembersManagerEntry method createMember.

public Member createMember(PerunSession sess, Vo vo, User user, List<Group> groups) throws InternalErrorException, AlreadyMemberException, WrongAttributeValueException, WrongReferenceAttributeValueException, VoNotExistsException, UserNotExistsException, PrivilegeException, ExtendMembershipException, GroupNotExistsException, GroupOperationsException {
    Utils.checkPerunSession(sess);
    getPerunBl().getUsersManagerBl().checkUserExists(sess, user);
    getPerunBl().getVosManagerBl().checkVoExists(sess, vo);
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo)) {
        throw new PrivilegeException(sess, "createMember - from user");
    }
    // if any group is not from the vo, throw an exception
    if (groups != null) {
        for (Group group : groups) {
            perunBl.getGroupsManagerBl().checkGroupExists(sess, group);
            if (group.getVoId() != vo.getId())
                throw new InternalErrorException("Group " + group + " is not from the vo " + vo + " where user " + user + " should be added.");
        }
    }
    return getMembersManagerBl().createMember(sess, vo, user, groups);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 49 with InternalErrorException

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

the class ExtSourceEGISSO method querySource.

@Override
protected List<Map<String, String>> querySource(String query, String base, int maxResults) throws InternalErrorException {
    List<Map<String, String>> subjects = new ArrayList<Map<String, String>>();
    NamingEnumeration<SearchResult> results = null;
    if (base == null || base.isEmpty()) {
        base = "ou=People,dc=egi,dc=eu";
    }
    if (query == null || query.isEmpty())
        throw new InternalErrorException("Query can't be null when searching through EGI SSO.");
    try {
        SearchControls controls = new SearchControls();
        controls.setTimeLimit(5000);
        if (maxResults > 0) {
            controls.setCountLimit(maxResults);
        }
        results = getContext().search(base, query, controls);
        while (results.hasMore()) {
            SearchResult searchResult = (SearchResult) results.next();
            subjects.add(processResultToSubject(searchResult));
        }
        log.trace("Returning [{}] subjects", subjects.size());
    } catch (NamingException e) {
        log.error("LDAP exception during running query '{}'", query);
        throw new InternalErrorException("LDAP exception during running query: " + query + ".", e);
    } finally {
        try {
            if (results != null) {
                results.close();
            }
        } catch (Exception e) {
            log.error("LDAP exception during closing result, while running query '{}'", query);
            throw new InternalErrorException(e);
        }
    }
    return subjects;
}
Also used : ArrayList(java.util.ArrayList) SearchResult(javax.naming.directory.SearchResult) SearchControls(javax.naming.directory.SearchControls) NamingException(javax.naming.NamingException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) HashMap(java.util.HashMap) Map(java.util.Map) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) IOException(java.io.IOException) NamingException(javax.naming.NamingException)

Example 50 with InternalErrorException

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

the class ServicesManagerImpl method deleteService.

public void deleteService(PerunSession sess, Service service) throws InternalErrorException, ServiceAlreadyRemovedException {
    try {
        // Delete authz entries for this service
        AuthzResolverBlImpl.removeAllAuthzForService(sess, service);
        int numAffected = jdbc.update("delete from services where id=?", service.getId());
        if (numAffected == 0)
            throw new ServiceAlreadyRemovedException("Service: " + service);
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : ServiceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.ServiceAlreadyRemovedException) 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