Search in sources :

Example 56 with UserExtSource

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

the class AttributesManagerEntryIntegrationTest method getUserExtSourceAttributeByIdWhenWrongAttrAssignment.

@Test(expected = WrongAttributeAssignmentException.class)
public void getUserExtSourceAttributeByIdWhenWrongAttrAssignment() throws Exception {
    System.out.println(CLASS_NAME + "getUserExtSourceAttributeByIdWhenWrongAttrAssignment");
    UserExtSource ues = setUpUserExtSourceTest();
    attributes = setUpMemberAttribute();
    int id = attributes.get(0).getId();
    attributesManager.getAttributeById(sess, ues, id);
// shouldn't return userExtSource attribute when ID belong to different type of attribute
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 57 with UserExtSource

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

the class AttributesManagerEntryIntegrationTest method setUserExtSourceAttributesWhenWrongAttrAssigment.

@Test(expected = WrongAttributeAssignmentException.class)
public void setUserExtSourceAttributesWhenWrongAttrAssigment() throws Exception {
    System.out.println(CLASS_NAME + "setUserExtSourceAttributesWhenWrongAttrAssigment");
    UserExtSource ues = setUpUserExtSourceTest();
    attributes = setUpVoAttribute();
    // create Vo attribute instead UserExtSource attribute to raise exception
    attributesManager.setAttributes(sess, ues, attributes);
// shouldn't set wrong attribute
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 58 with UserExtSource

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

the class AttributesManagerEntryIntegrationTest method setUserExtSourceAttributesWhenAttributeNotExists.

@Test(expected = AttributeNotExistsException.class)
public void setUserExtSourceAttributesWhenAttributeNotExists() throws Exception {
    System.out.println(CLASS_NAME + "setUserExtSourceAttributesWhenAttributeNotExists");
    UserExtSource ues = setUpUserExtSourceTest();
    attributes = setUpUserExtSourceAttribute();
    attributes.get(0).setId(0);
    // make valid attribute into not existing by setting ID = 0
    attributesManager.setAttributes(sess, ues, attributes);
// shouldn't find attribute
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 59 with UserExtSource

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

the class ExtSourcePerun method findRichUser.

private RichUser findRichUser(String login) throws InternalErrorException, SubjectNotExistsException {
    Map<String, Object> params = new HashMap<String, Object>();
    List<RichUser> richUsers = this.findRichUsers(login);
    List<RichUser> matchesRichUsers = new ArrayList<>();
    for (RichUser richUser : richUsers) {
        List<UserExtSource> userExtSources = richUser.getUserExtSources();
        for (UserExtSource userExtSource : userExtSources) {
            if (extSourceNameForLogin.equals(userExtSource.getExtSource().getName())) {
                if (login.equals(userExtSource.getLogin()))
                    matchesRichUsers.add(richUser);
            }
        }
    }
    if (matchesRichUsers.isEmpty())
        throw new SubjectNotExistsException("There is no subject with login " + login + " in extSource " + extSourceNameForLogin + " in System perun with RPC url: " + perunUrl);
    if (matchesRichUsers.size() > 1)
        throw new InternalErrorException("There are more then one subject with login " + login + " in extSource " + extSourceNameForLogin + " in System perun with RPC url: " + perunUrl);
    return richUsers.get(0);
}
Also used : HashMap(java.util.HashMap) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) RichUser(cz.metacentrum.perun.core.api.RichUser) ArrayList(java.util.ArrayList) SubjectNotExistsException(cz.metacentrum.perun.core.api.exceptions.SubjectNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 60 with UserExtSource

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

the class ExtSourcePerun method findRichUsers.

private List<RichUser> findRichUsers(String substring) throws InternalErrorException {
    String query;
    try {
        // encode query params
        query = "searchString=" + URLEncoder.encode(substring, "UTF-8");
    } catch (UnsupportedEncodingException ex) {
        // sent query params not encoded
        query = "searchString=" + substring;
    }
    List<RichUser> richUsers;
    try {
        richUsers = this.call("usersManager", "findRichUsers", query).readList(RichUser.class);
    } catch (PerunException ex) {
        throw new InternalErrorException(ex);
    }
    Iterator<RichUser> iterator = richUsers.iterator();
    while (iterator.hasNext()) {
        RichUser richUser = iterator.next();
        boolean hasLogin = false;
        for (UserExtSource ues : richUser.getUserExtSources()) {
            if (ues.getExtSource() != null && ues.getExtSource().getName().equals(extSourceNameForLogin)) {
                hasLogin = true;
                continue;
            }
        }
        if (!hasLogin)
            iterator.remove();
    }
    return richUsers;
}
Also used : UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) RichUser(cz.metacentrum.perun.core.api.RichUser) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PerunException(cz.metacentrum.perun.core.api.exceptions.PerunException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)79 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)34 Test (org.junit.Test)34 ExtSource (cz.metacentrum.perun.core.api.ExtSource)28 Attribute (cz.metacentrum.perun.core.api.Attribute)19 Candidate (cz.metacentrum.perun.core.api.Candidate)18 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)14 User (cz.metacentrum.perun.core.api.User)12 Member (cz.metacentrum.perun.core.api.Member)11 ArrayList (java.util.ArrayList)11 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)8 Group (cz.metacentrum.perun.core.api.Group)7 ExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)6 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)5 HashMap (java.util.HashMap)5 RichUser (cz.metacentrum.perun.core.api.RichUser)4 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)4 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)4 Matcher (java.util.regex.Matcher)4 RichMember (cz.metacentrum.perun.core.api.RichMember)3