Search in sources :

Example 16 with Person

use of org.jbpm.bpmn2.objects.Person in project jbpm by kiegroup.

the class StartEventTest method testConditionalStart.

@Test
public void testConditionalStart() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-ConditionalStart.bpmn2");
    ksession = createKnowledgeSession(kbase);
    Person person = new Person();
    person.setName("jack");
    ksession.insert(person);
    person = new Person();
    person.setName("john");
    ksession.insert(person);
}
Also used : KieBase(org.kie.api.KieBase) Person(org.jbpm.bpmn2.objects.Person) Test(org.junit.Test)

Example 17 with Person

use of org.jbpm.bpmn2.objects.Person in project jbpm by kiegroup.

the class StructureRefTest method testNoStructureRef.

@Test
public void testNoStructureRef() throws Exception {
    Person person = new Person();
    person.setId(1L);
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-NoStructureRef.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("StructureRef");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    Map<String, Object> res = new HashMap<String, Object>();
    res.put("testHT", person);
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), res);
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Person(org.jbpm.bpmn2.objects.Person) StartEventTest(org.jbpm.bpmn2.StartEventTest) Test(org.junit.Test)

Example 18 with Person

use of org.jbpm.bpmn2.objects.Person in project jbpm by kiegroup.

the class BusinessRuleTaskHandlerTest method testDrlStatefulBusinessRuleTaskWithScanner.

@Ignore("ignored as it is unstable on jenkins for unknown reason")
@Test
public void testDrlStatefulBusinessRuleTaskWithScanner() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    BusinessRuleTaskHandler handler = new BusinessRuleTaskHandler(GROUP_ID, ARTIFACT_ID, VERSION, 2000);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setId(999);
    Person person = new Person("john");
    workItem.setParameter("person", person);
    workItem.setParameter("KieSessionType", BusinessRuleTaskHandler.STATEFULL_TYPE);
    handler.executeWorkItem(workItem, manager);
    Map<String, Object> results = manager.getResults(workItem.getId());
    assertNotNull(results);
    assertEquals(1, results.size());
    assertEquals(35, ((Person) results.get("person")).getAge().intValue());
    // build and deploy new version
    createAndDeployJar(ks, ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION), ks.getResources().newClassPathResource("businessRule2.drl"));
    // setup waiting mechanism to wait for scanner update
    CountDownLatch latch = new CountDownLatch(1);
    handler.getKieContainer().getKieBase().addEventListener(new DefaultKieBaseEventListener() {

        @Override
        public void afterRuleAdded(AfterRuleAddedEvent event) {
            latch.countDown();
        }
    });
    latch.await(10, TimeUnit.SECONDS);
    person = new Person("john");
    workItem.setParameter("person", person);
    workItem.setParameter("KieSessionType", BusinessRuleTaskHandler.STATEFULL_TYPE);
    handler.executeWorkItem(workItem, manager);
    results = manager.getResults(workItem.getId());
    assertNotNull(results);
    assertEquals(1, results.size());
    assertEquals(45, ((Person) results.get("person")).getAge().intValue());
}
Also used : DefaultKieBaseEventListener(org.kie.api.event.kiebase.DefaultKieBaseEventListener) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) AfterRuleAddedEvent(org.kie.api.event.kiebase.AfterRuleAddedEvent) CountDownLatch(java.util.concurrent.CountDownLatch) Person(org.jbpm.process.workitem.bpmn2.objects.Person) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with Person

use of org.jbpm.bpmn2.objects.Person in project jbpm by kiegroup.

the class BusinessRuleTaskHandlerTest method testDrlStatefulBusinessRuleTaskNoScanner.

@Test
public void testDrlStatefulBusinessRuleTaskNoScanner() {
    TestWorkItemManager manager = new TestWorkItemManager();
    BusinessRuleTaskHandler handler = new BusinessRuleTaskHandler(GROUP_ID, ARTIFACT_ID, VERSION);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setId(999);
    Person person = new Person("john");
    workItem.setParameter("person", person);
    workItem.setParameter("KieSessionType", BusinessRuleTaskHandler.STATEFULL_TYPE);
    handler.executeWorkItem(workItem, manager);
    Map<String, Object> results = manager.getResults(workItem.getId());
    assertNotNull(results);
    assertEquals(1, results.size());
    assertEquals(35, ((Person) results.get("person")).getAge().intValue());
}
Also used : TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) Person(org.jbpm.process.workitem.bpmn2.objects.Person) Test(org.junit.Test)

Example 20 with Person

use of org.jbpm.bpmn2.objects.Person in project ultimate-java by pantinor.

the class Utils method setTMXMap.

public static void setTMXMap(BaseMap map, Maps id, String tmxFile, TileSet ts) {
    List<Person> people = new ArrayList<>();
    Tile[] tiles = new Tile[map.getWidth() * map.getHeight()];
    TmxMapLoader loader = new TmxMapLoader();
    TiledMap tm = loader.load("assets/tilemaps/" + tmxFile);
    TiledMapTileLayer ml = (TiledMapTileLayer) tm.getLayers().get(map.getId() + "-map");
    if (ml != null) {
        FileHandle f = new FileHandle("assets/tilemaps/latest-atlas.txt");
        TextureAtlas.TextureAtlasData atlas = new TextureAtlas.TextureAtlasData(f, f.parent(), false);
        int png_grid_width = 24;
        Tile[] mapTileIds = new Tile[png_grid_width * Constants.tilePixelWidth + 1];
        for (Region r : atlas.getRegions()) {
            int x = r.left / r.width;
            int y = r.top / r.height;
            int i = x + (y * png_grid_width) + 1;
            mapTileIds[i] = ts.getTileByName(r.name);
        }
        for (int y = 0; y < map.getHeight(); y++) {
            for (int x = 0; x < map.getWidth(); x++) {
                StaticTiledMapTile tr = (StaticTiledMapTile) ml.getCell(x, map.getWidth() - 1 - y).getTile();
                Tile tile = mapTileIds[tr.getId()];
                if (tile == null) {
                    tile = ts.getTileByIndex(127);
                }
                tiles[x + (y * map.getWidth())] = tile;
            }
        }
    }
    MapLayer objectsLayer = tm.getLayers().get(map.getId() + "-people");
    if (objectsLayer != null) {
        Iterator<MapObject> iter = objectsLayer.getObjects().iterator();
        while (iter.hasNext()) {
            MapObject obj = iter.next();
            Person p = new Person();
            Conversation conv = new Conversation();
            conv.setName(obj.getName());
            conv.setMap(id);
            p.setConversation(conv);
            people.add(p);
            Iterator<String> keys = obj.getProperties().getKeys();
            while (keys.hasNext()) {
                String key = keys.next();
                String value = obj.getProperties().get(key).toString();
                if (key.equals("tileType")) {
                    Tile tile = ts.getTileByName(value);
                    p.setTileIndex(tile.getIndex());
                    p.setTile(tile);
                } else if (key.equals("startX")) {
                    p.setStart_x(new Float(value).intValue());
                } else if (key.equals("startY")) {
                    p.setStart_y(new Float(value).intValue());
                } else if (key.equals("role")) {
                    PersonRole role = new PersonRole();
                    role.setInventoryType(InventoryType.valueOf(value));
                    p.setRole(role);
                } else if (key.equals("movement")) {
                    p.setMovement(ObjectMovementBehavior.valueOf(value));
                } else if (key.startsWith("description")) {
                    conv.setDescription(value);
                    conv.getTopics().add(conv.new Topic(standardQuery[2], value, null, null, null));
                } else if (key.startsWith("topic")) {
                    String[] splits = value.split(",");
                    if (splits.length == 5) {
                        conv.getTopics().add(conv.new Topic(splits[0], splits[1], splits[2], splits[3], splits[4]));
                    } else {
                        conv.getTopics().add(conv.new Topic(splits[0], splits[1], null, null, null));
                    }
                }
            }
        }
    }
    map.getCity().setPeople(people);
    map.setTiles(tiles);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) MapLayer(com.badlogic.gdx.maps.MapLayer) ArrayList(java.util.ArrayList) Conversation(objects.Conversation) HawkwindConversation(objects.HawkwindConversation) LordBritishConversation(objects.LordBritishConversation) PersonRole(objects.PersonRole) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) MapObject(com.badlogic.gdx.maps.MapObject) TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) DungeonTile(ultima.Constants.DungeonTile) Tile(objects.Tile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Region(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) Person(objects.Person)

Aggregations

Test (org.junit.Test)32 Person (org.jbpm.bpmn2.objects.Person)29 KieBase (org.kie.api.KieBase)28 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)22 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)21 HashMap (java.util.HashMap)10 Person (objects.Person)8 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)8 ArrayList (java.util.ArrayList)6 Tile (objects.Tile)4 Ignore (org.junit.Ignore)4 KieSession (org.kie.api.runtime.KieSession)4 BaseMap (objects.BaseMap)3 DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)3 FileHandle (com.badlogic.gdx.files.FileHandle)2 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)2 TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)2 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)2