Search in sources :

Example 1 with DirectMemberAddedToGroup

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);
    }
}
Also used : DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) AlreadyMemberException(cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) ExtendMembershipException(cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException)

Example 2 with DirectMemberAddedToGroup

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));
}
Also used : DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) Set(java.util.Set) Event(cz.metacentrum.perun.dispatcher.model.Event) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) Service(cz.metacentrum.perun.core.api.Service) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) Facility(cz.metacentrum.perun.core.api.Facility) AbstractDispatcherTest(cz.metacentrum.perun.dispatcher.AbstractDispatcherTest) Test(org.junit.Test)

Example 3 with DirectMemberAddedToGroup

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);
}
Also used : DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) MemberRemovedFromGroupTotally(cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberRemovedFromGroupTotally) Before(org.junit.Before)

Example 4 with DirectMemberAddedToGroup

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");
    }
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) EngineMessageProducer(cz.metacentrum.perun.dispatcher.jms.EngineMessageProducer) DirectMemberAddedToGroup(cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup) Event(cz.metacentrum.perun.dispatcher.model.Event) Facility(cz.metacentrum.perun.core.api.Facility) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) LinkedList(java.util.LinkedList) AbstractDispatcherTest(cz.metacentrum.perun.dispatcher.AbstractDispatcherTest) Test(org.junit.Test)

Aggregations

DirectMemberAddedToGroup (cz.metacentrum.perun.audit.events.GroupManagerEvents.DirectMemberAddedToGroup)4 Facility (cz.metacentrum.perun.core.api.Facility)2 AbstractDispatcherTest (cz.metacentrum.perun.dispatcher.AbstractDispatcherTest)2 Event (cz.metacentrum.perun.dispatcher.model.Event)2 Test (org.junit.Test)2 AuditEvent (cz.metacentrum.perun.audit.events.AuditEvent)1 MemberRemovedFromGroupTotally (cz.metacentrum.perun.audit.events.GroupManagerEvents.MemberRemovedFromGroupTotally)1 Service (cz.metacentrum.perun.core.api.Service)1 AlreadyMemberException (cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException)1 ExtendMembershipException (cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 EngineMessageProducer (cz.metacentrum.perun.dispatcher.jms.EngineMessageProducer)1 Task (cz.metacentrum.perun.taskslib.model.Task)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1