Search in sources :

Example 21 with SocialActivitiesEvent

use of org.ext.uberfire.social.activities.model.SocialActivitiesEvent in project kie-wb-common by kiegroup.

the class SocialEventRepositoryConstraintTest method hasRestrictionsTest.

@Test
public void hasRestrictionsTest() throws Exception {
    final SocialActivitiesEvent event = new SocialActivitiesEvent(socialUser, OrganizationalUnitEventType.NEW_ORGANIZATIONAL_UNIT, new Date()).withLink("otherName", "otherName", SocialActivitiesEvent.LINK_TYPE.VFS);
    socialEventRepositoryConstraint.init();
    assertTrue(socialEventRepositoryConstraint.hasRestrictions(event));
}
Also used : SocialActivitiesEvent(org.ext.uberfire.social.activities.model.SocialActivitiesEvent) Date(java.util.Date) Test(org.junit.Test)

Example 22 with SocialActivitiesEvent

use of org.ext.uberfire.social.activities.model.SocialActivitiesEvent in project kie-wb-common by kiegroup.

the class SocialEventRepositoryConstraintTest method hasRestrictionsBecauseThrowsAnExceptionTest.

@Test
public void hasRestrictionsBecauseThrowsAnExceptionTest() throws Exception {
    returnRepo = repository;
    SocialEventRepositoryConstraint socialEventRepositoryConstraintSpy = spy(this.socialEventRepositoryConstraint);
    final SocialActivitiesEvent vfsEvent = new SocialActivitiesEvent(socialUser, "type", new Date());
    socialEventRepositoryConstraintSpy.init();
    assertFalse(socialEventRepositoryConstraintSpy.hasRestrictions(vfsEvent));
    when(socialEventRepositoryConstraintSpy.getEventRepository(vfsEvent)).thenThrow(RuntimeException.class);
    assertTrue(socialEventRepositoryConstraintSpy.hasRestrictions(vfsEvent));
}
Also used : SocialActivitiesEvent(org.ext.uberfire.social.activities.model.SocialActivitiesEvent) Date(java.util.Date) Test(org.junit.Test)

Example 23 with SocialActivitiesEvent

use of org.ext.uberfire.social.activities.model.SocialActivitiesEvent in project kie-wb-common by kiegroup.

the class SocialTimelineRulesQuery method getNEventsFromEachType.

@Override
public List<SocialActivitiesEvent> getNEventsFromEachType(int numberOfEvents, String... typeNames) {
    List<SocialActivitiesEvent> events = new ArrayList<>();
    for (String type : typeNames) {
        PagedSocialQuery query = socialTypeTimelinePagedRepositoryAPI.getEventTimeline(type, new SocialPaged(numberOfEvents), new HashMap());
        events.addAll(query.socialEvents());
    }
    return events;
}
Also used : SocialPaged(org.ext.uberfire.social.activities.model.SocialPaged) HashMap(java.util.HashMap) SocialActivitiesEvent(org.ext.uberfire.social.activities.model.SocialActivitiesEvent) ArrayList(java.util.ArrayList) PagedSocialQuery(org.ext.uberfire.social.activities.model.PagedSocialQuery)

Example 24 with SocialActivitiesEvent

use of org.ext.uberfire.social.activities.model.SocialActivitiesEvent in project kie-wb-common by kiegroup.

the class SocialTimelineRulesQuery method executeSpecificRule.

@Override
@SuppressWarnings("unchecked")
public List<SocialActivitiesEvent> executeSpecificRule(Map<String, String> globals, final String drlName, String maxResults) {
    List<SocialActivitiesEvent> events = new ArrayList<>();
    try {
        KieServices ks = KieServices.Factory.get();
        KieContainer kContainer = ks.getKieClasspathContainer();
        KieSession kSession = kContainer.newKieSession("social-session");
        List<SocialActivitiesEvent> socialEvents = new ArrayList<>();
        kSession.setGlobal("socialEvents", socialEvents);
        kSession.setGlobal("queryAPI", this);
        kSession.setGlobal("maxResults", new Integer(maxResults));
        for (String key : globals.keySet()) {
            kSession.setGlobal(key, globals.get(key));
        }
        kSession.fireAllRules(new AgendaFilter() {

            @Override
            public boolean accept(Match match) {
                String rulename = match.getRule().getName();
                if (rulename.equals(drlName)) {
                    return true;
                }
                return false;
            }
        });
        events = (List<SocialActivitiesEvent>) kSession.getGlobal("socialEvents");
    } catch (Exception e) {
        throw new RulesExecutionQueryException(e);
    }
    return events;
}
Also used : ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) Match(org.kie.api.runtime.rule.Match) SocialActivitiesEvent(org.ext.uberfire.social.activities.model.SocialActivitiesEvent) KieSession(org.kie.api.runtime.KieSession) AgendaFilter(org.kie.api.runtime.rule.AgendaFilter) KieContainer(org.kie.api.runtime.KieContainer)

Aggregations

SocialActivitiesEvent (org.ext.uberfire.social.activities.model.SocialActivitiesEvent)24 Date (java.util.Date)20 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)4 SocialUser (org.ext.uberfire.social.activities.model.SocialUser)4 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)3 HashMap (java.util.HashMap)2 Repository (org.guvnor.structure.repositories.Repository)2 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)2 KieServices (org.kie.api.KieServices)2 KieContainer (org.kie.api.runtime.KieContainer)2 KieSession (org.kie.api.runtime.KieSession)2 ContextNotActiveException (javax.enterprise.context.ContextNotActiveException)1 PagedSocialQuery (org.ext.uberfire.social.activities.model.PagedSocialQuery)1 SocialPaged (org.ext.uberfire.social.activities.model.SocialPaged)1 SocialAdapter (org.ext.uberfire.social.activities.service.SocialAdapter)1 NewRepositoryEvent (org.guvnor.structure.repositories.NewRepositoryEvent)1 AgendaFilter (org.kie.api.runtime.rule.AgendaFilter)1 Match (org.kie.api.runtime.rule.Match)1 CommentAddedEvent (org.kie.workbench.common.services.shared.discussion.CommentAddedEvent)1