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;
}
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);
}
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);
}
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;
}
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);
}
}
Aggregations