use of cz.metacentrum.perun.core.api.exceptions.VoNotExistsException in project perun by CESNET.
the class FacilitiesManagerBlImpl method getAllowedVos.
public List<Vo> getAllowedVos(PerunSession sess, Facility facility) throws InternalErrorException {
List<Vo> vos = new ArrayList<Vo>();
List<Integer> voIds = getFacilitiesManagerImpl().getAllowedVosIds(sess, facility);
try {
for (Integer id : voIds) {
vos.add(getPerunBl().getVosManagerBl().getVoById(sess, id));
}
} catch (VoNotExistsException ex) {
throw new ConsistencyErrorException("Non-existent VO is allowed on the facility", ex);
}
return vos;
}
use of cz.metacentrum.perun.core.api.exceptions.VoNotExistsException in project perun by CESNET.
the class VOOT method getGroupByName.
/**
* Return group by name, which is consist of short name of VO, short name of parents group and short name of current group, e.g. 'vo1:group1:group2'.
*
* @param name name of group, e.g. 'vo1:group1:group2'
* @return group
* @throws VOOTException if can not read group
*/
private Group getGroupByName(String name) throws VOOTException {
String voName = name.split(":")[0];
Vo vo = null;
try {
vo = perun.getVosManagerBl().getVoByShortName(session, voName);
} catch (InternalErrorException ex) {
throw new VOOTException("internal_server_error");
} catch (VoNotExistsException ex) {
throw new VOOTException("internal_server_error", "vo not exists");
}
Group group = null;
try {
group = perun.getGroupsManagerBl().getGroupByName(session, vo, name.substring(name.indexOf(":") + 1, name.length()));
} catch (GroupNotExistsException ex) {
throw new VOOTException("internal_server_error", "group not exists");
} catch (InternalErrorException ex) {
throw new VOOTException("internal_server_error");
}
return group;
}
use of cz.metacentrum.perun.core.api.exceptions.VoNotExistsException in project perun by CESNET.
the class RTMessagesManagerBlImpl method prepareDataAndGetHttpRequest.
private HttpUriRequest prepareDataAndGetHttpRequest(PerunSession sess, int voId, String queue, String requestor, String subject, String text) {
// Ticket from this part is already evidet like 'new'
String id = "ticket/new";
// If there is no requestor, it is uknown requestor
if (requestor == null || requestor.isEmpty()) {
requestor = "unknown";
}
// If queue is null, try to check if exist value in attribute rtVoQueue, if not, use default
if (queue == null || queue.isEmpty()) {
Vo vo;
if (voId != 0) {
try {
vo = perunBl.getVosManagerBl().getVoById(sess, voId);
} catch (VoNotExistsException ex) {
throw new InternalErrorException("VoId with Id=" + voId + " not exists.", ex);
}
Attribute voQueue;
try {
voQueue = perunBl.getAttributesManagerBl().getAttribute(sess, vo, AttributesManager.NS_VO_ATTR_DEF + ":RTVoQueue");
} catch (AttributeNotExistsException ex) {
throw new InternalErrorException("Attribute RTVoQueue not exists.", ex);
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
if (voQueue.getValue() != null) {
queue = (String) voQueue.getValue();
} else
queue = rtDefaultQueue;
} else
queue = rtDefaultQueue;
}
// If subject is null or empty, use Unspecified instead
if (subject == null || subject.isEmpty())
subject = "(No subject)";
// Text can be null so if it is, put empty string
if (text == null)
text = "";
// Prepare credentials
String username = BeansUtils.getCoreConfig().getRtServiceuserUsername();
String password = BeansUtils.getCoreConfig().getRtServiceuserPassword();
// Prepare content of message
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
try {
entityBuilder.addPart("Content-Type", new StringBody("application/x-www-form-urlencoded", ContentType.create("text/plain", Consts.UTF_8)));
entityBuilder.addPart("charset", new StringBody(StandardCharsets.UTF_8.toString(), ContentType.create("text/plain", Consts.UTF_8)));
entityBuilder.addPart("Connection", new StringBody("Close", ContentType.create("text/plain", Consts.UTF_8)));
StringBody content = new StringBody("id: " + id + '\n' + "Queue: " + queue + '\n' + "Requestor: " + requestor + '\n' + "Subject: " + subject + '\n' + "Text: " + text, ContentType.create("text/plain", Consts.UTF_8));
entityBuilder.addPart("content", content);
} catch (Exception e) {
throw new RuntimeException(e);
}
// Test rtURL for null
if (rtURL == null || rtURL.length() == 0)
throw new InternalErrorException("rtURL is not prepared and is null in the moment of posting.");
// prepare post request
HttpPost post = new HttpPost(rtURL);
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
post.addHeader(BasicScheme.authenticate(credentials, "utf-8", false));
post.setEntity(entityBuilder.build());
return post;
}
use of cz.metacentrum.perun.core.api.exceptions.VoNotExistsException in project perun by CESNET.
the class MembersManagerBlImpl method findMembersInParentGroup.
@Override
public List<Member> findMembersInParentGroup(PerunSession sess, Group group, String searchString) {
List<User> users = getPerunBl().getUsersManagerBl().findUsers(sess, searchString);
List<Member> allGroupMembers;
if (group.getParentGroupId() == null) {
Vo vo;
try {
vo = getPerunBl().getVosManagerBl().getVoById(sess, group.getVoId());
} catch (VoNotExistsException ex) {
throw new ConsistencyErrorException("Vo for group " + group + " does not exist.");
}
allGroupMembers = getPerunBl().getMembersManagerBl().getMembers(sess, vo);
} else {
allGroupMembers = getPerunBl().getGroupsManagerBl().getParentGroupMembers(sess, group);
}
List<Member> allFoundMembers = new ArrayList<>();
for (User user : users) {
allFoundMembers.addAll(getMembersByUser(sess, user));
}
allGroupMembers.retainAll(allFoundMembers);
return allGroupMembers;
}
use of cz.metacentrum.perun.core.api.exceptions.VoNotExistsException in project perun by CESNET.
the class GroupsManagerBlImpl method getNewParentGroup.
/**
* Return parent group for the candidate group
*
* @param sess perun session
* @param candidateGroup candidate group
* @param baseGroup base group in structure
* @param loginAttributeName attribute name of login in the structure
* @return parent group of candidate group, if there is none, return base group
*/
private Group getNewParentGroup(PerunSession sess, CandidateGroup candidateGroup, Group baseGroup, String loginAttributeName) {
Group newParentGroup = baseGroup;
// if parent group login is not null, we need to find this new parent group (otherwise it is base group)
if (candidateGroup.getParentGroupLogin() != null) {
try {
// we need to have vo to filter groups, base group has to be from the same vo as new parent of candidate group
Vo baseGroupVo = getPerunBl().getVosManagerBl().getVoById(sess, baseGroup.getVoId());
List<Group> groupsWithLogin = getPerunBl().getSearcherBl().getGroups(sess, baseGroupVo, Collections.singletonMap(loginAttributeName, candidateGroup.getParentGroupLogin()));
// if there is missing the destination parent group, set base group as parent, there could be missing parent group in the extSource data
if (!groupsWithLogin.isEmpty()) {
// if there are more than one group with login, there is no way how to choose correct behavior
if (groupsWithLogin.size() > 1)
throw new InternalErrorException("More than 1 group has login attribute '" + loginAttributeName + "' set with the same login " + candidateGroup.getParentGroupLogin());
// our new parent group is exactly the one with the login set
return groupsWithLogin.get(0);
}
} catch (VoNotExistsException ex) {
throw new InternalErrorException("Vo of base group: " + baseGroup + " can't be found. Unexpected situation, can't continue.");
} catch (AttributeNotExistsException ex) {
throw new InternalErrorException("Can't find attribute definition for '" + loginAttributeName + "'.");
}
}
return newParentGroup;
}
Aggregations