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