/** * Create some instances for a given BO and validate if they can be queried: * * <ul> * <li>where the qualified business object id is set * <li>the primary key is passed to findForBusinessObject() * <li>the qualified business object id is passed to findForBusinessObject and the primary key * is set as a data filter * <li>the qualified business object id is passed to findForBusinessObject and an attribute of * the BO is set as a data filter * </ul> */ @Test public void CheckFiltering() throws Exception { DeployedModelDescription model = sf.getQueryService().getModels(DeployedModelQuery.findActiveForId(MODEL_NAME3)).get(0); String businessObjectQualifiedId = new QName(model.getId(), "Fund").toString(); for (int i = 1; i <= 9; i++) { final Map<String, Object> fund = CollectionUtils.newMap(); fund.put("AccountNumber", "100100" + i); fund.put("AccountName", "Fund" + i); sf.getWorkflowService() .createBusinessObjectInstance(businessObjectQualifiedId, (Serializable) fund); } BusinessObjectQuery query = BusinessObjectQuery.findForBusinessObject(businessObjectQualifiedId); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); BusinessObjects bos = sf.getQueryService().getAllBusinessObjects(query); Assert.assertEquals("Objects", 1, bos.getSize()); BusinessObject bo = bos.get(0); List<BusinessObject.Value> values = bo.getValues(); Assert.assertEquals("Values", 9, values.size()); query = BusinessObjectQuery.findWithPrimaryKey(businessObjectQualifiedId, "1001003"); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); bos = sf.getQueryService().getAllBusinessObjects(query); Assert.assertEquals("Objects", 1, bos.getSize()); bo = bos.get(0); values = bo.getValues(); Assert.assertEquals("Values", 1, values.size()); checkValue(values, true, "AccountNumber", "1001003"); query = BusinessObjectQuery.findForBusinessObject(businessObjectQualifiedId); query.where(DataFilter.isEqual("Fund", "AccountNumber", "1001005")); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); bos = sf.getQueryService().getAllBusinessObjects(query); Assert.assertEquals("Objects", 1, bos.getSize()); bo = bos.get(0); values = bo.getValues(); Assert.assertEquals("Values", 1, values.size()); checkValue(values, true, "AccountNumber", "1001005"); query = BusinessObjectQuery.findForBusinessObject(businessObjectQualifiedId); query.where(DataFilter.isEqual("Fund", "AccountName", "Fund7")); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); bos = sf.getQueryService().getAllBusinessObjects(query); Assert.assertEquals("Objects", 1, bos.getSize()); bo = bos.get(0); values = bo.getValues(); Assert.assertEquals("Values", 1, values.size()); checkValue(values, true, "AccountName", "Fund7"); }
/** * Validate if BO instances can be created once only with the same primary key and that they can * be queried either via findWithPrimaryKey() or with help of data filters. */ @Test public void CreateOrdersCheck() { DeployedModelDescription model = sf.getQueryService().getModels(DeployedModelQuery.findActiveForId(MODEL_NAME2)).get(0); createOrder(model, 666); try { createOrder(model, 666); Assert.fail("Extected BPMRT03825 error message"); } catch (ObjectExistsException ex) { Assert.assertEquals("Error code", "BPMRT03825", ex.getError().getId()); } String businessObjectQualifiedId = new QName(model.getId(), "Order").toString(); BusinessObjectQuery query = BusinessObjectQuery.findWithPrimaryKey(businessObjectQualifiedId, 666); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); BusinessObjects bos = sf.getQueryService().getAllBusinessObjects(query); Assert.assertEquals("Objects", 1, bos.getSize()); BusinessObject bo = bos.get(0); List<Value> values = bo.getValues(); Assert.assertEquals("Values", 1, values.size()); checkValue(values, true, "customerId", 666); query = BusinessObjectQuery.findForBusinessObject(businessObjectQualifiedId); query .getFilter() .addOrTerm() .or(DataFilter.isEqual("Order", "customerId", 2)) .or(DataFilter.isEqual("Order", "customerId", 4)); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); bos = sf.getQueryService().getAllBusinessObjects(query); Assert.assertEquals("Objects", 1, bos.getSize()); bo = bos.get(0); values = bo.getValues(); Assert.assertEquals("Values", 2, values.size()); checkValue(values, true, "customerId", 2, 4); }
/** * The following test case should ensure that * * <ul> * <li>Any modifications to an attribute of a BOI via API isn't reflected to process data which * are using the BO * <li>Any modifications to an attribute of a BOI via the process data is only reflected to the * BOI which is attached to the synthetic process instance and that it doesn't affect other * BOIs which are used in other processes * </ul> */ @Test public void checkFilteringOnBusinessObjectAttrChange() { // setup final int customerIdOffset = 100; final int customerCount = 3; for (int customerId = 1; customerId <= customerCount; customerId++) { ProcessInstance pi = sf.getWorkflowService() .startProcess(new QName(MODEL_NAME2, "DistributedOrder").toString(), null, true); List<ActivityInstance> w = getWorklist(pi); Assert.assertEquals("worklist", 1, w.size()); ActivityInstance ai = w.get(0); Assert.assertEquals("activity instance", "CreateOrder", ai.getActivity().getId()); Map<String, Object> order = CollectionUtils.newMap(); order.put("date", new Date()); order.put("customerId", customerIdOffset + customerId); order.put("items", "item " + customerId); ai = complete( ai, PredefinedConstants.DEFAULT_CONTEXT, Collections.singletonMap("Order", order)); try { ActivityInstanceStateBarrier.instance().await(ai.getOID(), ActivityInstanceState.Completed); } catch (Exception e) { } } // after DistributeCreation activity is completed we have the following state: // * 2 asynchronous subprocesses are started: one which copies the data and the // other one which doesn't // * 3 synchronous subprocesses are triggered: one with shared data, one with separate // but copied data and the last one with separate data without copying // This results into the following state: // * Each process has created four business object instances // * One which is attached to a synthetic process instance // * 3 other BOIs which are attached to a real process instance String businessObjectQualifiedId = new QName(MODEL_NAME2, "Order").toString(); BusinessObjectQuery businessObjectQuery = BusinessObjectQuery.findForBusinessObject(businessObjectQualifiedId); businessObjectQuery .getFilter() .addAndTerm() .add(DataFilter.greaterThan("Order", "customerId", customerIdOffset)); businessObjectQuery.setPolicy( new BusinessObjectQuery.Policy( BusinessObjectQuery.Option.WITH_VALUES, BusinessObjectQuery.Option.WITH_DESCRIPTION)); BusinessObjects bos = sf.getQueryService().getAllBusinessObjects(businessObjectQuery); Assert.assertEquals("Only one business object, namely Order, is expected", 1, bos.getSize()); Assert.assertEquals( "Business object instances count isn't the same as started process ergo the count of the synthetic process instances", customerCount, getTotalSize(bos)); // Wait that all ShowOrder processes are started (unfortunately we cannot use // ProcessInstanceStateBarrier here // because of the async processes. ProcessInstanceQuery piQuery = ProcessInstanceQuery.findAlive("ShowOrder"); boolean waitForPIs = true; while (waitForPIs) { long instanceCount = sf.getQueryService().getProcessInstancesCount(piQuery); waitForPIs = instanceCount != (customerCount * 5); if (waitForPIs) { try { Thread.sleep(100); } catch (InterruptedException e) { } } } BusinessObject bo = bos.get(0); BusinessObject.Value customer101 = null; for (BusinessObject.Value boValue : bo.getValues()) { Map<?, ?> boAttr = (Map<?, ?>) boValue.getValue(); Integer customerId = (Integer) boAttr.get("customerId"); if (Integer.valueOf(customerIdOffset + 1).equals(customerId)) { customer101 = boValue; } } Assert.assertNotNull("Customer " + customerIdOffset + 1 + " not found", customer101); // Update BOI via API... ((Map) customer101.getValue()).put("items", "newitems"); sf.getWorkflowService() .updateBusinessObjectInstance(businessObjectQualifiedId, customer101.getValue()); // ...and validate if no process data is modified piQuery = ProcessInstanceQuery.findActive(); FilterTerm filter = piQuery.getFilter().addAndTerm(); filter.add( DataFilter.between( "Order", "customerId", customerIdOffset, customerIdOffset + customerCount)); filter.add(DataFilter.like("Order", "items", "item%")); filter.addAndTerm().add(ProcessInstanceHierarchyFilter.ROOT_PROCESS); piQuery.setPolicy(SubsetPolicy.UNRESTRICTED); ProcessInstances rootPIs = sf.getQueryService().getAllProcessInstances(piQuery); // Root process instances are the DistributedOrder processes and the ShowOrder processes which // was started // as async processes and which had copied the data Assert.assertEquals( "Changes in BOIs must not be reflected in process instance data", customerCount * 2, rootPIs.getTotalCount()); // Update BOI for a given process via data path... long piOid = rootPIs.get(0).getOID(); ((Map) customer101.getValue()).put("items", "newitems1"); sf.getWorkflowService().setOutDataPath(piOid, "OrderDataPath", (Map) customer101.getValue()); // ...and validate if the BOI is updated... businessObjectQuery = BusinessObjectQuery.findWithPrimaryKey( businessObjectQualifiedId, ((Map) customer101.getValue()).get("customerId")); businessObjectQuery.setPolicy( new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); bos = sf.getQueryService().getAllBusinessObjects(businessObjectQuery); Assert.assertEquals("Only one business object, namely Order, is expected", 1, bos.getSize()); List<BusinessObject.Value> boValues = bos.get(0).getValues(); Assert.assertEquals(1, boValues.size()); Assert.assertEquals("newitems1", ((Map) boValues.get(0).getValue()).get("items")); // ...but the other process instance data should be untouched piQuery = ProcessInstanceQuery.findActive(); filter = piQuery.getFilter().addAndTerm(); filter.add( DataFilter.between( "Order", "customerId", customerIdOffset, customerIdOffset + customerCount)); filter.add(DataFilter.like("Order", "items", "item%")); filter.addAndTerm().add(ProcessInstanceHierarchyFilter.ROOT_PROCESS); piQuery.setPolicy(SubsetPolicy.UNRESTRICTED); rootPIs = sf.getQueryService().getAllProcessInstances(piQuery); Assert.assertEquals( "Changes in BOIs must not be reflected in process instance data", (customerCount * 2) - 1, rootPIs.getTotalCount()); }
/** * Create some instances for a given BO and validate if they can be queried where: * * <ul> * <li>the qualified business object id is set * <li>the primary key is passed to findForBusinessObject() * <li>the qualified business object id is passed to findForBusinessObject and an attribute of * the BO is set as a data filter * <li>the qualified business object id is passed to findForBusinessObject and the query is * restricted to the currently active model * <li>the qualified business object id is passed to findForBusinessObject and across all * deployed model versions * <li>the qualified business object id is passed to findForBusinessObject and the query is * restricted to a given modelOid * </ul> */ @Test public void CheckFiltering2() throws Exception { DeployedModelDescription model = sf.getQueryService().getModels(DeployedModelQuery.findActiveForId(MODEL_NAME3)).get(0); String businessObjectQualifiedId = new QName(model.getId(), "Employee").toString(); createEmployee(businessObjectQualifiedId, "1", "Florin"); createEmployee(businessObjectQualifiedId, "Sid", "2"); BusinessObjectQuery query = BusinessObjectQuery.findForBusinessObject(businessObjectQualifiedId); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); BusinessObjects bos = sf.getQueryService().getAllBusinessObjects(query); Assert.assertEquals("Objects", 1, bos.getSize()); BusinessObject bo = bos.get(0); List<BusinessObject.Value> values = bo.getValues(); Assert.assertEquals("Values", 2, values.size()); query = BusinessObjectQuery.findWithPrimaryKey(businessObjectQualifiedId, "1"); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); bos = sf.getQueryService().getAllBusinessObjects(query); Assert.assertEquals("Objects", 1, bos.getSize()); bo = bos.get(0); values = bo.getValues(); Assert.assertEquals("Values", 1, values.size()); checkValue(values, true, "EmpID", "1"); query = BusinessObjectQuery.findWithPrimaryKey(businessObjectQualifiedId, "Sid"); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); bos = sf.getQueryService().getAllBusinessObjects(query); Assert.assertEquals("Objects", 1, bos.getSize()); bo = bos.get(0); values = bo.getValues(); Assert.assertEquals("Values", 1, values.size()); checkValue(values, true, "EmpID", "Sid"); query = BusinessObjectQuery.findForBusinessObject(businessObjectQualifiedId); query.where(DataFilter.isEqual("Employee", "EmpName", "2")); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); bos = sf.getQueryService().getAllBusinessObjects(query); Assert.assertEquals("Objects", 1, bos.getSize()); bo = bos.get(0); values = bo.getValues(); Assert.assertEquals("Values", 1, values.size()); checkValue(values, true, "EmpName", "2"); query = BusinessObjectQuery.findForBusinessObject(businessObjectQualifiedId); query.where(DataFilter.isEqual("Employee", "EmpName", "Florin")); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); bos = sf.getQueryService().getAllBusinessObjects(query); Assert.assertEquals("Objects", 1, bos.getSize()); bo = bos.get(0); values = bo.getValues(); Assert.assertEquals("Values", 1, values.size()); checkValue(values, true, "EmpName", "Florin"); RtEnvHome.deployModel(sf.getAdministrationService(), null, MODEL_NAME3); createEmployee(businessObjectQualifiedId, "3", "Meyer"); query = BusinessObjectQuery.findForBusinessObject( PredefinedConstants.ACTIVE_MODEL, businessObjectQualifiedId); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); bos = sf.getQueryService().getAllBusinessObjects(query); Assert.assertEquals("Objects", 1, bos.getSize()); bo = bos.get(0); values = bo.getValues(); Assert.assertEquals("Values", 1, values.size()); query = BusinessObjectQuery.findForBusinessObject(businessObjectQualifiedId); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); bos = sf.getQueryService().getAllBusinessObjects(query); Assert.assertEquals("Objects", 2, bos.getSize()); Assert.assertEquals("Values", 3, getTotalSize(bos)); query = BusinessObjectQuery.findForBusinessObject(model.getModelOID(), businessObjectQualifiedId); query.setPolicy(new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); bos = sf.getQueryService().getAllBusinessObjects(query); Assert.assertEquals("Objects", 1, bos.getSize()); bo = bos.get(0); values = bo.getValues(); Assert.assertEquals("Values", 2, values.size()); }
public static String getSimplePieChart(Map dataSource, String objectName, HttpSession session) throws Throwable { DefaultPieDataset dataset = new DefaultPieDataset(); Element chartObject = XMLHandler.getElementByAttribute(getChartObjectList(), "name", objectName); String title = chartObject.getAttributeValue("title"); int width = Integer.parseInt(chartObject.getAttributeValue("width")); int height = Integer.parseInt(chartObject.getAttributeValue("height")); Element LabelKeys = chartObject.getChild("Labels"); Element ValueKeys = chartObject.getChild("Values"); String valueKey = ValueKeys.getText(); String valueType = ValueKeys.getAttributeValue("type"); List labelKeys = LabelKeys.getChildren("Label"); String labelKey = LabelKeys.getText(); if (valueType.equalsIgnoreCase("number")) { for (int i = 0; i < dataSource.size(); i++) { Map rec = (Map) dataSource.get("ROW" + i); Number value = (Number) rec.get(valueKey); String label; if (labelKeys.isEmpty()) { label = DataFilter.show(rec, labelKey); } else { label = ((Element) labelKeys.get(i)).getText(); } dataset.setValue(label, value); } } else { for (int i = 0; i < dataSource.size(); i++) { Map rec = (Map) dataSource.get("ROW" + i); double value = (Double) rec.get(valueKey); String label; if (labelKeys.isEmpty()) { label = DataFilter.show(rec, labelKey); } else { label = ((Element) labelKeys.get(i)).getText(); } dataset.setValue(label, value); } } JFreeChart chart = ChartFactory.createPieChart3D( title, dataset, chartObject.getAttribute("showLegend").getBooleanValue(), chartObject.getAttribute("showToolTips").getBooleanValue(), chartObject.getAttribute("urls").getBooleanValue()); PiePlot3D pie3dplot = (PiePlot3D) chart.getPlot(); float alpha = 0.7F; if (chartObject.getAttribute("alpha") != null) { alpha = chartObject.getAttribute("alpha").getFloatValue(); } pie3dplot.setForegroundAlpha(alpha); return ServletUtilities.saveChartAsPNG(chart, width, height, null, session); }
public static String getBarSeries(Map dataSource, String objectName, HttpSession session) throws Exception { DefaultKeyedValues barValues = new DefaultKeyedValues(); DefaultKeyedValues seriesValues = new DefaultKeyedValues(); Element chartObject = XMLHandler.getElementByAttribute(getChartObjectList(), "name", objectName); Element barField = chartObject.getChild("BarFields").getChild("Field"); Element seriesField = chartObject.getChild("SeriesFields").getChild("Field"); for (int i = 0; i < dataSource.size(); i++) { Map rec = (Map) dataSource.get("ROW" + i); barValues.addValue( DataFilter.show(rec, chartObject.getChildText("ColumnLabel")), Double.parseDouble(rec.get(barField.getAttributeValue("name")).toString())); seriesValues.addValue( DataFilter.show(rec, chartObject.getChildText("ColumnLabel")), Double.parseDouble(rec.get(seriesField.getAttributeValue("name")).toString())); } CategoryDataset dataset = DatasetUtilities.createCategoryDataset(barField.getAttributeValue("label"), barValues); PlotOrientation plotOrientation = chartObject.getAttributeValue("plotOrientation").equalsIgnoreCase("VERTICAL") ? PlotOrientation.VERTICAL : PlotOrientation.HORIZONTAL; JFreeChart chart = ChartFactory.createBarChart3D( chartObject.getAttributeValue("title"), chartObject.getAttributeValue("categoryAxisLabel"), chartObject.getAttributeValue("valueAxisLabel"), dataset, plotOrientation, chartObject.getAttribute("showLegend").getBooleanValue(), chartObject.getAttribute("showToolTips").getBooleanValue(), chartObject.getAttribute("urls").getBooleanValue()); CategoryPlot categoryplot = chart.getCategoryPlot(); LineRenderer3D lineRenderer = new LineRenderer3D(); CategoryDataset datasetSeries = DatasetUtilities.createCategoryDataset( seriesField.getAttributeValue("label"), seriesValues); categoryplot.setDataset(1, datasetSeries); categoryplot.setRangeAxis(1, new NumberAxis3D(seriesField.getAttributeValue("label"))); categoryplot.setRenderer(1, lineRenderer); categoryplot.mapDatasetToRangeAxis(1, 1); BarRenderer3D barrenderer = (BarRenderer3D) categoryplot.getRenderer(); barrenderer.setLabelGenerator(new StandardCategoryLabelGenerator()); barrenderer.setItemLabelsVisible(true); barrenderer.setPositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.BASELINE_CENTER)); // lineRenderer.setLabelGenerator(new StandardCategoryLabelGenerator()); // lineRenderer.setItemLabelsVisible(true); // lineRenderer.setPositiveItemLabelPosition( // new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.CENTER)); float alpha = 0.7F; if (chartObject.getAttribute("alpha") != null) { alpha = chartObject.getAttribute("alpha").getFloatValue(); } categoryplot.setForegroundAlpha(alpha); int width, height; if (chartObject.getAttributeValue("width").equalsIgnoreCase("auto")) { width = (50 * dataSource.size()) + 100; } else { width = Integer.parseInt(chartObject.getAttributeValue("width")); } if (chartObject.getAttributeValue("height").equalsIgnoreCase("auto")) { height = (50 * dataSource.size()) + 100; } else { height = Integer.parseInt(chartObject.getAttributeValue("height")); } return ServletUtilities.saveChartAsPNG(chart, width, height, session); }
public static String getSimpleBarChart(Map dataSource, String objectName, HttpSession session) throws Throwable { Element chartObject = XMLHandler.getElementByAttribute(getChartObjectList(), "name", objectName); List invokeFields = chartObject.getChild("InvokeFields").getChildren("Field"); double[][] data = new double[invokeFields.size()][dataSource.size()]; String[] rowKeys = new String[invokeFields.size()]; String[] columnKeys = new String[dataSource.size()]; String columnLabel = chartObject.getChildText("ColumnLabel"); for (int i = 0; i < dataSource.size(); i++) { Map rec = (Map) dataSource.get("ROW" + i); columnKeys[i] = DataFilter.show(rec, columnLabel); for (int j = 0; j < invokeFields.size(); j++) { data[j][i] = Double.parseDouble( rec.get(((Element) invokeFields.get(j)).getAttributeValue("name")).toString()); } } for (int i = 0; i < invokeFields.size(); i++) { rowKeys[i] = ((Element) invokeFields.get(i)).getAttributeValue("label"); } CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data); PlotOrientation plotOrientation = chartObject.getAttributeValue("plotOrientation").equalsIgnoreCase("VERTICAL") ? PlotOrientation.VERTICAL : PlotOrientation.HORIZONTAL; JFreeChart chart = ChartFactory.createBarChart3D( chartObject.getAttributeValue("title"), chartObject.getAttributeValue("categoryAxisLabel"), chartObject.getAttributeValue("valueAxisLabel"), dataset, plotOrientation, chartObject.getAttribute("showLegend").getBooleanValue(), chartObject.getAttribute("showToolTips").getBooleanValue(), chartObject.getAttribute("urls").getBooleanValue()); CategoryPlot C3dplot = (CategoryPlot) chart.getPlot(); if (chartObject.getAttribute("alpha") != null) { C3dplot.setForegroundAlpha(chartObject.getAttribute("alpha").getFloatValue()); } BarRenderer3D barrenderer = (BarRenderer3D) C3dplot.getRenderer(); barrenderer.setLabelGenerator(new StandardCategoryLabelGenerator()); barrenderer.setItemLabelsVisible(true); barrenderer.setPositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.BASELINE_CENTER)); int width, height; if (chartObject.getAttributeValue("width").equalsIgnoreCase("auto")) { width = (50 * dataSource.size()) * invokeFields.size() + 100; } else { width = Integer.parseInt(chartObject.getAttributeValue("width")); } if (chartObject.getAttributeValue("height").equalsIgnoreCase("auto")) { height = (50 * dataSource.size()) * invokeFields.size() + 100; } else { height = Integer.parseInt(chartObject.getAttributeValue("height")); } return ServletUtilities.saveChartAsPNG(chart, width, height, session); }