use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.
the class urn_perun_entityless_attribute_def_def_namespace_maxUIDTest method setUp.
@Before
public void setUp() throws Exception {
classInstance = new urn_perun_entityless_attribute_def_def_namespace_maxUID();
session = mock(PerunSessionImpl.class);
attributeToCheck = new Attribute(classInstance.getAttributeDefinition());
reqAttribute = new Attribute(classInstance.getAttributeDefinition());
PerunBl perunBl = mock(PerunBl.class);
when(session.getPerunBl()).thenReturn(perunBl);
AttributesManagerBl attributesManagerBl = mock(AttributesManagerBl.class);
when(perunBl.getAttributesManagerBl()).thenReturn(attributesManagerBl);
when(session.getPerunBl().getAttributesManagerBl().getAttribute(session, key, AttributesManager.NS_ENTITYLESS_ATTR_DEF + ":namespace-minUID")).thenReturn(reqAttribute);
}
use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.
the class urn_perun_facility_attribute_def_def_googleGroupsDomainTest method setUp.
@Before
public void setUp() throws Exception {
classInstance = new urn_perun_facility_attribute_def_def_googleGroupsDomain();
session = mock(PerunSessionImpl.class);
facility = new Facility();
attributeToCheck = new Attribute();
reqAttribute = new Attribute();
PerunBl perunBl = mock(PerunBl.class);
when(session.getPerunBl()).thenReturn(perunBl);
AttributesManagerBl attributesManagerBl = mock(AttributesManagerBl.class);
when(perunBl.getAttributesManagerBl()).thenReturn(attributesManagerBl);
}
use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.
the class urn_perun_group_attribute_def_def_synchronizationEnabledTest method setUp.
@Before
public void setUp() throws Exception {
classInstance = new urn_perun_group_attribute_def_def_synchronizationEnabled();
attributeToCheck = new Attribute(classInstance.getAttributeDefinition());
reqAttribute = new Attribute(classInstance.getAttributeDefinition());
sess = mock(PerunSessionImpl.class);
PerunBl perunBl = mock(PerunBl.class);
when(sess.getPerunBl()).thenReturn(perunBl);
GroupsManagerBl groupsManagerBl = mock(GroupsManagerBl.class);
when(sess.getPerunBl().getGroupsManagerBl()).thenReturn(groupsManagerBl);
when(sess.getPerunBl().getGroupsManagerBl().isGroupSynchronizedFromExternallSource(sess, group)).thenReturn(false);
AttributesManagerBl attributesManagerBl;
attributesManagerBl = mock(AttributesManagerBl.class);
when(perunBl.getAttributesManagerBl()).thenReturn(attributesManagerBl);
when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, GroupsManager.GROUPMEMBERSQUERY_ATTRNAME)).thenReturn(reqAttribute);
when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, GroupsManager.GROUPEXTSOURCE_ATTRNAME)).thenReturn(reqAttribute);
}
use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.
the class UsersManagerBlImpl method setCandidateAttributes.
/**
* For given user, set user attributes from given candidate.
* Can set only user-def and user-opt attributes.
*
* @param sess session
* @param user user
* @param candidate candidate to take attributes
* @throws AttributeNotExistsException if some of the given attributes dont exist
* @throws WrongAttributeAssignmentException if some of the given attributes have unsupported namespace
* @throws WrongReferenceAttributeValueException if some of the given attribute value cannot be set because of
* some other attribute constraint
* @throws WrongAttributeValueException if some of the given attribute value is invalid
*/
private void setCandidateAttributes(PerunSession sess, User user, Candidate candidate) throws WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException, AttributeNotExistsException {
if (candidate.getAttributes() == null) {
return;
}
List<Attribute> attributesToSet = new ArrayList<>();
AttributesManagerBl attrsManager = perunBl.getAttributesManagerBl();
for (String attributeName : candidate.getAttributes().keySet()) {
if (!attributeName.startsWith(AttributesManager.NS_USER_ATTR_DEF) && !attributeName.startsWith(AttributesManager.NS_USER_ATTR_OPT)) {
throw new WrongAttributeAssignmentException("Cannot set non-(user DEF/OPT) attribute: " + attributeName);
}
AttributeDefinition definition = attrsManager.getAttributeDefinition(sess, attributeName);
Attribute attribute = new Attribute(definition);
attribute.setValue(attrsManager.stringToAttributeValue(candidate.getAttributes().get(attributeName), attribute.getType()));
attributesToSet.add(attribute);
}
attrsManager.setAttributes(sess, user, attributesToSet);
}
use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.
the class ResourcesManagerBlImpl method fillAndSetRequiredAttributesForGroups.
/**
* Fill and set group and group-resource attributes required by given services
* for all groups which are assigned to the given resource.
*
* @param sess session
* @param services services of which required attributes are set
* @param resource resource
* @throws GroupResourceMismatchException GroupResourceMismatchException
* @throws WrongAttributeAssignmentException WrongAttributeAssignmentException
* @throws WrongAttributeValueException WrongAttributeValueException
* @throws WrongReferenceAttributeValueException WrongReferenceAttributeValueException
*/
public void fillAndSetRequiredAttributesForGroups(PerunSession sess, List<Service> services, Resource resource) throws GroupResourceMismatchException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
AttributesManagerBl attributesManagerBl = getPerunBl().getAttributesManagerBl();
List<Group> groups = getAssignedGroups(sess, resource);
for (Group group : groups) {
List<Attribute> attributes;
attributes = attributesManagerBl.getRequiredAttributes(sess, services, resource, group, true);
attributes = attributesManagerBl.fillAttributes(sess, resource, group, attributes, true);
attributesManagerBl.setAttributes(sess, resource, group, attributes, true);
}
}
Aggregations