Search in sources :

Example 1 with VoNotExistsException

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;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) ArrayList(java.util.ArrayList) Vo(cz.metacentrum.perun.core.api.Vo) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)

Example 2 with VoNotExistsException

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;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) Vo(cz.metacentrum.perun.core.api.Vo) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)

Example 3 with VoNotExistsException

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;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) MultipartEntityBuilder(org.apache.http.entity.mime.MultipartEntityBuilder) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) IOException(java.io.IOException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) MailException(org.springframework.mail.MailException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) StringBody(org.apache.http.entity.mime.content.StringBody) Vo(cz.metacentrum.perun.core.api.Vo)

Example 4 with VoNotExistsException

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;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) ArrayList(java.util.ArrayList) Vo(cz.metacentrum.perun.core.api.Vo) BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)

Example 5 with VoNotExistsException

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;
}
Also used : EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) IndirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberRemovedFromGroup) CandidateGroup(cz.metacentrum.perun.core.api.CandidateGroup) RichGroup(cz.metacentrum.perun.core.api.RichGroup) MemberExpiredInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberExpiredInGroup) MemberValidatedInGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberValidatedInGroup) DirectMemberRemovedFromGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberRemovedFromGroup) Group(cz.metacentrum.perun.core.api.Group) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) IndirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.IndirectMemberAddedToGroup) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Vo(cz.metacentrum.perun.core.api.Vo) GroupCreatedInVo(cz.metacentrum.perun.audit.events.GroupManagerEvents.GroupCreatedInVo) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)

Aggregations

VoNotExistsException (cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)26 Vo (cz.metacentrum.perun.core.api.Vo)24 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)18 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)14 Member (cz.metacentrum.perun.core.api.Member)10 ArrayList (java.util.ArrayList)9 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)8 Attribute (cz.metacentrum.perun.core.api.Attribute)7 ExtSource (cz.metacentrum.perun.core.api.ExtSource)7 User (cz.metacentrum.perun.core.api.User)7 ExtendMembershipException (cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException)7 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)7 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)7 Group (cz.metacentrum.perun.core.api.Group)6 AlreadyMemberException (cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException)6 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)6 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)5 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)5 Map (java.util.Map)5 BanOnVo (cz.metacentrum.perun.core.api.BanOnVo)4