use of cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup in project perun by CESNET.
the class GroupsManagerBlImpl method addDirectMember.
/**
* Add a record of the member with a DIRECT membership type to the group.
*
* @param sess perun session
* @param group group to add member to
* @param member member to be added as DIRECT
* @throws InternalErrorException
* @throws AlreadyMemberException
* @throws WrongAttributeValueException
* @throws WrongReferenceAttributeValueException
* @throws GroupNotExistsException
*/
protected void addDirectMember(PerunSession sess, Group group, Member member) throws AlreadyMemberException, WrongAttributeValueException, WrongReferenceAttributeValueException, GroupNotExistsException {
lockGroupMembership(group, Collections.singletonList(member));
if (this.groupsManagerImpl.isDirectGroupMember(sess, group, member))
throw new AlreadyMemberException(member);
boolean memberWasIndirectInGroup = this.isGroupMember(sess, group, member);
Map<Integer, Map<Integer, MemberGroupStatus>> previousStatuses = getPreviousStatuses(sess, group, List.of(member));
member = getGroupsManagerImpl().addMember(sess, group, member, MembershipType.DIRECT, group.getId());
getPerunBl().getAuditer().log(sess, new DirectMemberAddedToGroup(member, group));
// If member was indirect in group before, we don't need to change anything in other groups
if (memberWasIndirectInGroup)
return;
// check all relations with this group and call addRelationMembers to reflect changes of adding member to group
List<Integer> relations = groupsManagerImpl.getResultGroupsIds(sess, group.getId());
for (Integer groupId : relations) {
addRelationMembers(sess, groupsManagerImpl.getGroupById(sess, groupId), Collections.singletonList(member), group.getId());
}
setRequiredAttributes(sess, member, group);
// try to set init expiration
try {
extendMembershipInGroup(sess, member, group);
} catch (ExtendMembershipException e) {
throw new InternalErrorException("Failed to set initial member-group expiration date.");
}
if (!VosManager.MEMBERS_GROUP.equals(group.getName())) {
// recalculate member group state
recalculateMemberGroupStatusRecursively(sess, member, group, previousStatuses);
}
}
use of cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup in project perun by CESNET.
the class EventServiceResolverTest method parseEventTest.
@Test
public void parseEventTest() throws ServiceNotExistsException, InvalidEventMessageException, PrivilegeException {
System.out.println("EventServiceResolver.parseEventTest()");
AuditEvent auditEvent = new DirectMemberAddedToGroup(member1, group1);
Event event = new Event();
event.setTimeStamp(System.currentTimeMillis());
event.setHeader("portishead");
event.setData(auditEvent);
Map<Facility, Set<Service>> resolvedServices = eventServiceResolver.resolveEvent(event.getData());
Assert.assertTrue("We should resolved only one facility-service", resolvedServices.size() == 1);
Set<Service> resolved = resolvedServices.get(facility1);
Assert.assertTrue("We should have 2 service", resolved.size() == 2);
Assert.assertTrue("Our Service 1 is missing", resolved.contains(service1));
Assert.assertTrue("Our Service 2 is missing", resolved.contains(service2));
}
use of cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_studentIdentifiersTest method setUp.
@Before
public void setUp() throws Exception {
setUpUser();
setUpVo();
setUpMember();
setUpGroup();
setUpExtSource();
createUserExtSourceAttributes();
memberAddedEvent = new DirectMemberAddedToGroup(member, group);
memberRemovedEvent = new MemberRemovedFromGroupTotally(member, group);
}
use of cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup in project perun by CESNET.
the class EventProcessorTest method eventProcessorTest.
@Test
public void eventProcessorTest() {
System.out.println("EventProcessor.eventProcessorTest()");
EngineMessageProducer engineMessageProducer = new EngineMessageProducerMock("testQueue");
eventProcessor.getEngineMessageProducerFactory().setProducer(engineMessageProducer);
LinkedBlockingQueue<Event> mockQueue = new LinkedBlockingQueue<>();
Event event = new Event();
event.setTimeStamp(System.currentTimeMillis());
event.setHeader("portishead");
event.setData(new DirectMemberAddedToGroup(member1, group1));
mockQueue.add(event);
eventProcessor.setEventQueue(mockQueue);
SchedulingPoolMock pool = new SchedulingPoolMock(2);
eventProcessor.setSchedulingPool(pool);
// runs inside this thread, should end when message is delivered
// this necessitates the use of test timeout
eventProcessor.run();
List<Task> addedTasks = pool.getTasks();
List<Facility> facilities = new LinkedList<>();
for (Task task : addedTasks) {
Assert.isTrue(service1.equals(task.getService()) || service2.equals(task.getService()), "task service is different");
Assert.isTrue(facility1.equals(task.getFacility()), "task Facility is different");
Assert.isTrue(task.getStatus().equals(TaskStatus.WAITING), "task status is not waiting");
}
}
Aggregations