@Override public Object getFieldValue(JRField field) throws JRException { HrmsLogin user = userList.get(index); if(field.getName().equals("empId")) { return user.getHrmsEmployeeDetails().getEmpId()+""; } else if(field.getName().equals("username")) { return user.getUsername(); } else if(field.getName().equals("password")) { return user.getPassword(); } else if(field.getName().equals("role")) { return user.getRole(); } return null; }
@Override public Object getFieldValue(JRField field) throws JRException { Object value = null; String fieldName = field.getName(); if ("the_city".equals(fieldName)) { value = data[index][0]; } else if ("id".equals(fieldName)) { value = data[index][1]; } else if ("name".equals(fieldName)) { value = data[index][2]; } else if ("street".equals(fieldName)) { value = data[index][3]; } return value; }
@Override public Object getFieldValue(JRField field) throws JRException { Object value = null; String fieldName = field.getName(); if ("City".equals(fieldName)) { value = data[index][0]; } else if ("Id".equals(fieldName)) { value = data[index][1]; } else if ("Name".equals(fieldName)) { value = data[index][2]; } else if ("Street".equals(fieldName)) { value = data[index][3]; } return value; }
/** * */ public Object getFieldValue(JRField field) throws JRException { Object value = null; String fieldName = field.getName(); if ("City".equals(fieldName)) { value = data[index][0]; } else if ("Id".equals(fieldName)) { value = data[index][1]; } else if ("Name".equals(fieldName)) { value = data[index][2]; } else if ("Street".equals(fieldName)) { value = data[index][3]; } return value; }
@Override public Object getFieldValue(JRField field) throws DataSnapshotException { ColumnValuesIterator iterator = iterators.get(field.getName()); if (iterator == null) { throw new DataSnapshotException( EXCEPTION_MESSAGE_KEY_NO_SUCH_SNAPSHOT_FIELD, new Object[]{field.getName()}); } Object value = iterator.get(); if (value != null && !field.getValueClass().isInstance(value)) { throw new DataSnapshotException( EXCEPTION_MESSAGE_KEY_INVALID_SNAPSHOT_FIELD_TYPE, new Object[]{field.getName(), field.getValueClassName(), value.getClass().getName()}); } return value; }
/** * */ protected JRBaseField getField(JRField field) { JRBaseField baseField = null; if (field != null) { baseField = (JRBaseField)get(field); if (baseField == null) { baseField = new JRBaseField(field, this); } } return baseField; }
@Override public Object getFieldValue(JRField jrField) throws JRException { if(currentJsonNode == null) { return null; } String expression; if (fieldExpressions.containsKey(jrField.getName())) { expression = fieldExpressions.get(jrField.getName()); } else { expression = getFieldExpression(jrField); fieldExpressions.put(jrField.getName(), expression); } if (expression == null || expression.length() == 0) { return null; } JRJsonNode selectedNode = jsonQLExecuter.selectNode(currentJsonNode, root, expression); if (selectedNode != null) { return getConvertedValue(selectedNode, jrField); } return null; }
protected String getFieldExpression(JRField field) { String fieldExpression = null; if (field.hasProperties()) { fieldExpression = field.getPropertiesMap().getProperty(PROPERTY_FIELD_EXPRESSION); } if (fieldExpression == null) { fieldExpression = field.getDescription(); if (fieldExpression == null || fieldExpression.length() == 0) { fieldExpression = field.getName(); } } return fieldExpression; }
@Override public Object getFieldValue(JRField jrField) throws JRException { String fieldName = jrField.getName(); Integer columnIndex = this.columnNames.get(fieldName); if (columnIndex != null) { return this.tableModel.getValueAt(index, columnIndex.intValue()); } else if (fieldName.startsWith("COLUMN_")) { return this.tableModel.getValueAt(index, Integer.parseInt(fieldName.substring(7))); } else { throw new JRException( EXCEPTION_MESSAGE_KEY_UNKNOWN_COLUMN_NAME, new Object[]{fieldName}); } }
protected String getFieldExpression(JRField field) { String fieldExpression = null; if (field.hasProperties()) { fieldExpression = field.getPropertiesMap().getProperty(PROPERTY_FIELD_EXPRESSION); } if (fieldExpression == null || fieldExpression.length() == 0) { fieldExpression = field.getDescription(); if (fieldExpression == null || fieldExpression.length() == 0) { fieldExpression = field.getName(); } } return fieldExpression; }
/** * */ private void writeField(JRField field) throws IOException { writer.startElement(JRXmlConstants.ELEMENT_field); writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_name, field.getName()); writer.addAttribute(JRXmlConstants.ATTRIBUTE_class, field.getValueClassName()); writeProperties(field); if (isNewerVersionOrEqual(JRConstants.VERSION_6_3_1)) { writePropertyExpressions(field.getPropertyExpressions()); } writer.writeCDATAElement(JRXmlConstants.ELEMENT_fieldDescription, field.getDescription()); writer.closeElement(); }
protected JRSourceCompileTask( JasperDesign jasperDesign, String unitName, JRExpressionCollector expressionCollector, Map<String, ? extends JRParameter> parametersMap, Map<String, JRField> fieldsMap, Map<String, JRVariable> variablesMap, JRVariable[] variables, boolean onlyDefaultEvaluation ) { this.jasperDesign = jasperDesign; this.unitName = unitName; this.expressionCollector = expressionCollector; this.parametersMap = parametersMap; this.fieldsMap = fieldsMap; this.variablesMap = variablesMap; this.variables = variables; this.expressions = expressionCollector.getCompiledExpressions(); this.onlyDefaultEvaluation = onlyDefaultEvaluation; }
/** * Inserts a field at the specified position into the dataset. * @param index the field position * @param field the field to insert * @throws JRException * @see net.sf.jasperreports.engine.JRDataset#getFields() */ public void addField(int index, JRField field) throws JRException { if (fieldsMap.containsKey(field.getName())) { throw new JRException( EXCEPTION_MESSAGE_KEY_DUPLICATE_FIELD, new Object[]{field.getName()}); } fieldsList.add(index, field); fieldsMap.put(field.getName(), field); getEventSupport().fireCollectionElementAddedEvent(PROPERTY_FIELDS, field, index); }
/** * Removes a field from the dataset. * * @param field the field to be removed * @return the field to be removed */ public JRField removeField(JRField field) { if (field != null) { int idx = fieldsList.indexOf(field); if (idx >= 0) { fieldsList.remove(idx); fieldsMap.remove(field.getName()); getEventSupport().fireCollectionElementRemovedEvent(PROPERTY_FIELDS, field, idx); } } return field; }
/** * */ protected JRFillField( JRField field, JRFillObjectFactory factory ) { factory.put(field, this); parent = field; expressionEvaluator = factory.getExpressionEvaluator(); staticProperties = field.hasProperties() ? field.getPropertiesMap().cloneProperties() : null; mergedProperties = staticProperties; JRPropertyExpression[] fieldPropertyExpressions = field.getPropertyExpressions(); propertyExpressions = fieldPropertyExpressions == null ? new ArrayList<JRPropertyExpression>(0) : new ArrayList<JRPropertyExpression>(Arrays.asList(fieldPropertyExpressions)); }
/** * */ protected JRFillField getField(JRField field) { JRFillField fillField = null; if (field != null) { fillField = (JRFillField)get(field); if (fillField == null) { fillField = new JRFillField(field, this); } } return fillField; }
private FieldMatcher createFieldMatcher(JRField field, Mapping mapping) { FieldMatcher fieldMatcher; if (mapping instanceof MemberMapping) { fieldMatcher = new MemberFieldMatcher((MemberMapping) mapping); } else if (mapping instanceof DataMapping) { dataField = true; fieldMatcher = new DataFieldMatcher(field, (DataMapping) mapping); } else { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_OLAP_INTERNAL_ERROR, (Object[])null); } return fieldMatcher; }
@Override public JRField[] getFields(JasperReport jr) throws JRException { ESSearch esSearch = getESSearch(jr); if ( esSearch == null) { throw new JRException("No ElasticSearch connection for this report!!"); } Map<String, Class<?>> fields = esSearch.getFields(); JRField[] result = new JRField[fields.size()]; int idx=0; for (String field: fields.keySet()) { result[idx] = new ESField(field, field, fields.get(field)); idx++; } return result; }
@Override public void setReportDataAdapter(ReportBundle bundle, DataAdapterDescriptor dataadapter, JRPropertiesMap properties) { JRDesignDataset tableDataset = (JRDesignDataset)bundle.getJasperDesign().getDatasetMap().get("tableDataset"); //$NON-NLS-1$ JasperDesign jd = bundle.getJasperDesign(); for (String key : properties.getPropertyNames()){ jd.setProperty(key, properties.getProperty(key)); if (key.contains("ireport")) tableDataset.setProperty(key, properties.getProperty(key)); //$NON-NLS-1$ } tableDataset.setProperty(DataQueryAdapters.DEFAULT_DATAADAPTER, dataadapter.getName()); jd.setProperty(DataQueryAdapters.DEFAULT_DATAADAPTER, dataadapter.getName()); //Remove the main dataset query JRDesignDataset mainDataset = jd.getMainDesignDataset(); ((JRDesignQuery) mainDataset.getQuery()).setText(null); ((JRDesignQuery) mainDataset.getQuery()).setLanguage(null); for (JRField field : mainDataset.getFields()) mainDataset.removeField(field); }
public DatasetDialog(Shell shell, MDataset mdataset, JasperReportsConfiguration jConfig, CommandStack cmdStack) { super(shell); this.cmdStack = cmdStack; this.mdataset = mdataset; this.jConfig = jConfig; newdataset = (JRDesignDataset) ((JRDesignDataset) mdataset.getValue()).clone(); mapfields = new HashMap<JRField, JRField>(); List<JRField> newFieldsList = newdataset.getFieldsList(); List<JRField> oldFieldsList = mdataset.getValue().getFieldsList(); for (int i = 0; i < oldFieldsList.size(); i++) mapfields.put(oldFieldsList.get(i), newFieldsList.get(i)); mapparam = new HashMap<JRParameter, JRParameter>(); List<JRParameter> newParamList = newdataset.getParametersList(); List<JRParameter> oldParamList = mdataset.getValue().getParametersList(); for (int i = 0; i < oldParamList.size(); i++) mapparam.put(oldParamList.get(i), newParamList.get(i)); }
/** * Creates a valid name for a JRField element. * <p> * It searches the existing fields in order to check for field name validity. If no other field is found with the same * name, then the <code>namePrefix</code> itself is used. * * @param fields * list of already existing fields * @param namePrefix * name prefix for new field name * @return a valid name for the JRField */ public static String getNameForField(List<JRDesignField> fields, String namePrefix) { boolean match = false; String tmp = namePrefix; for (int i = 0; i < 100000; i++) { if (i != 0) tmp = ModelUtils.getNameFormat(namePrefix, i); for (JRField f : fields) { match = f.getName().equals(tmp); if (match) break; } if (!match) break; } return tmp; }
/** * Set the listener (only where they are not already set) to listen the changes * to a dataset and discard the cached interpreter for that dataset when they happen. * The listeners are set on both the dataset and his children * * @param parentDataset */ private static void setDatasetListners(JRDesignDataset parentDataset){ addEventIfnecessary(parentDataset, parentDataset); for(JRVariable var : parentDataset.getVariables()){ if (var instanceof JRChangeEventsSupport) addEventIfnecessary((JRChangeEventsSupport)var, parentDataset); } for(JRSortField sortField : parentDataset.getSortFields()){ if (sortField instanceof JRChangeEventsSupport) addEventIfnecessary((JRChangeEventsSupport)sortField, parentDataset); } for(JRParameter parameter : parentDataset.getParameters()){ if (parameter instanceof JRChangeEventsSupport) addEventIfnecessary((JRChangeEventsSupport)parameter, parentDataset); } for(JRField field : parentDataset.getFields()){ if (field instanceof JRChangeEventsSupport) addEventIfnecessary((JRChangeEventsSupport)field, parentDataset); } }
public ExpObject(Object obj) { if (obj instanceof JRField) { this.name = ((JRField) obj).getName(); this.type = TYPE_FIELD; this.classType = ((JRField) obj).getValueClassName(); } else if (obj instanceof JRParameter) { this.name = ((JRParameter) obj).getName(); this.type = TYPE_PARAM; this.classType = ((JRParameter) obj).getValueClassName(); } else if (obj instanceof JRVariable) { this.name = ((JRVariable) obj).getName(); this.type = TYPE_VARIABLE; this.classType = ((JRVariable) obj).getValueClassName(); } else { this.name = "" + obj; } }
public String getGroupMeasureName() { Object obj = jComboBoxGroup.getSelectedItem(); if (obj instanceof JRField) { return ((JRField)obj).getName(); } else if (obj instanceof JRParameter) { return ((JRParameter)obj).getName(); } else if (obj instanceof JRVariable) { return ((JRVariable)obj).getName(); } return ""+obj; }
public String getExpressionClass(String groupByType) { Object obj = jComboBoxGroup.getSelectedItem(); if (groupByType !=null && !groupByType.equals(I18n.getString("GroupPanel.Function.Unique")) ) { return "java.lang.String"; } if (obj instanceof JRField) { return ((JRField)obj).getValueClassName(); } else if (obj instanceof JRParameter) { return ((JRParameter)obj).getValueClassName(); } else if (obj instanceof JRVariable) { return ((JRVariable)obj).getValueClassName(); } return "java.lang.String"; }
@Override protected Transferable createTransferable(JComponent c) { if (c instanceof JTree) { JTree tree = (JTree)c; TreePath path = tree.getLeadSelectionPath(); DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode)path.getLastPathComponent(); JRField field = getXmlEditor().createField(path, true); return new TransferableObject(field); } return new TransferableObject(c); }
public boolean importData(JComponent c, Transferable t) { if (canImport(c, t.getTransferDataFlavors())) { try { // We assume it is the first flavor... JRField field = (JRField)t.getTransferData(t.getTransferDataFlavors()[0]); if (fieldsContainer != null) { fieldsContainer.addField(field); } return true; } catch (UnsupportedFlavorException ufe) { } catch (IOException ioe) { } } return false; }
public List<JRDesignField> readFields(String query) throws Exception { SQLFieldsProvider provider = new SQLFieldsProvider(); List<JRDesignField> result = new ArrayList<JRDesignField>(); JRDesignDataset dataset = new JRDesignDataset(true); JRDesignQuery dquery = new JRDesignQuery(); dquery.setLanguage("SQL"); dquery.setText(query); dataset.setQuery(dquery); JRField[] fields = provider.getFields(this, dataset, new HashMap()); for (int i=0; i<fields.length; ++i) { result.add((JRDesignField)fields[i]); } return result; }
public ExpObject(Object obj) { if (obj instanceof JRField) { this.name = ((JRField)obj).getName(); this.type = TYPE_FIELD; this.classType = ((JRField)obj).getValueClassName(); } else if (obj instanceof JRParameter) { this.name = ((JRParameter)obj).getName(); this.type = TYPE_PARAM; this.classType = ((JRParameter)obj).getValueClassName(); } else if (obj instanceof JRVariable) { this.name = ((JRVariable)obj).getName(); this.type = TYPE_VARIABLE; this.classType = ((JRVariable)obj).getValueClassName(); } else { this.name = "" + obj; } }
public List<CompletionItem> getExpressionContextFields() { List<CompletionItem> list = new ArrayList<CompletionItem>(); ExpressionContext ec = ExpressionContext.getGlobalContext(); if (ec == null) return list; for (JRDesignDataset dataset : ec.getDatasets()) { JRField[] fields = dataset.getFields(); for (int i=0; i<fields.length; ++i) { list.add(CompletionItem.create("$F{" + fields[i].getName() + "}", "<font color=\"#ababab\">" + getPrintableTypeName(fields[i].getValueClassName()), null,Type.CONSTANT,0)); } } return list; }
@Override public List<JRDesignField> readFields(String query) throws Exception { MongoDbFieldsProvider provider = new MongoDbFieldsProvider(); List<JRDesignField> result = new ArrayList<JRDesignField>(); JRDesignDataset dataset = new JRDesignDataset(true); JRDesignQuery designQuery = new JRDesignQuery(); designQuery.setLanguage(MongoDbDataSource.QUERY_LANGUAGE); designQuery.setText(query); dataset.setQuery(designQuery); Map<String, String> parameters = new HashMap<String, String>(); JRField[] fields = provider.getFields(this, dataset, parameters); for (int i = 0; i < fields.length; ++i) { result.add((JRDesignField) fields[i]); } return result; }
@Override public Object getFieldValue(JRField jrField) throws JRException { if (objects.get(row) instanceof String) { if (column == 0) { column++; return objects.get(row); } else { return null; } } Object[] columnas = (Object[]) objects.get(row); if (columnas.length <= column) { column++; return null; } Object object = ((Object[]) objects.get(row))[column]; column++; return object; }
@Test public void testQueryWithManyDsNames() throws UnsupportedOperationException, JRException { TestDatasetImpl reportDataset = new TestDatasetImpl(); reportDataset.setQueryText("--rrdDir share/rrd/snmp --nodeId 47 --resourceName opennms-jvm --dsName TotalMemory,DsName1,DsName2,DsName3"); ResourceQueryFieldsProvider provider = new ResourceQueryFieldsProvider(); JRField[] fields = provider.getFields(null, reportDataset, null); assertNotNull(fields); assertEquals(5, fields.length); assertEquals("Path", fields[0].getName()); assertEquals("TotalMemory", fields[1].getName()); assertEquals("DsName1", fields[2].getName()); assertEquals("DsName2", fields[3].getName()); assertEquals("DsName3", fields[4].getName()); }
@Test public void testQueryWithStringProperties() throws UnsupportedOperationException, JRException { TestDatasetImpl reportDataset = new TestDatasetImpl(); reportDataset.setQueryText("--rrdDir share/rrd/snmp --nodeId 47 --resourceName opennms-jvm --dsName TotalMemory,DsName1,DsName2,DsName3 --string nsVpnMonVpnName"); ResourceQueryFieldsProvider provider = new ResourceQueryFieldsProvider(); JRField[] fields = provider.getFields(null, reportDataset, null); assertNotNull(fields); assertEquals(6, fields.length); assertEquals("Path", fields[0].getName()); assertEquals("TotalMemory", fields[1].getName()); assertEquals("DsName1", fields[2].getName()); assertEquals("DsName2", fields[3].getName()); assertEquals("DsName3", fields[4].getName()); assertEquals("nsVpnMonVpnName", fields[5].getName()); }
@Test public void testQueryWithMultipleStringProperties() throws UnsupportedOperationException, JRException { TestDatasetImpl reportDataset = new TestDatasetImpl(); reportDataset.setQueryText("--rrdDir share/rrd/snmp --nodeId 47 --resourceName opennms-jvm --dsName TotalMemory,DsName1,DsName2,DsName3 --string nsVpnMonVpnName,name2,name3"); ResourceQueryFieldsProvider provider = new ResourceQueryFieldsProvider(); JRField[] fields = provider.getFields(null, reportDataset, null); assertNotNull(fields); assertEquals(8, fields.length); assertEquals("Path", fields[0].getName()); assertEquals("TotalMemory", fields[1].getName()); assertEquals("DsName1", fields[2].getName()); assertEquals("DsName2", fields[3].getName()); assertEquals("DsName3", fields[4].getName()); assertEquals("nsVpnMonVpnName", fields[5].getName()); assertEquals("name2", fields[6].getName()); assertEquals("name3", fields[7].getName()); }
/** * Returns a field value * */ public Object getFieldValue(JRField field) throws JRException { UserSettlementBean usb = usbList.get(index); Object value = null; String fieldName = field.getName(); if ("amount".equals(fieldName)) { value = usb.getAmount(); } else if ("userName".equals(fieldName)) { value = usb.getUserName(); } else if ("userShare".equals(fieldName)) { value = usb.getUserShare(); } else if ("userPaid".equals(fieldName)) { value = usb.getUserPaid(); } return value; }
@Test public void testManyToOneAttribute() throws Exception { List<InternalFeature> features = service.getFeatures(LAYER_BEANS, geoService.getCrs2("EPSG:4326"), null, null, GeomajasConstant.FEATURE_INCLUDE_ALL); JRRewindableDataSource data = new InternalFeatureDataSource(features); data.moveFirst(); JRField stringAttribute = createField("stringAttr", String.class); JRField many2OneString = createField("manyToOneAttr.stringAttr", String.class); int index = 0; while (index < features.size()) { Assert.assertTrue(data.next()); InternalFeature feature = features.get(index++); Assert.assertEquals(feature.getAttributes().get("stringAttr").getValue(), data.getFieldValue(stringAttribute)); ManyToOneAttribute manyToOne = (ManyToOneAttribute) feature.getAttributes().get("manyToOneAttr"); if (null != manyToOne.getValue()) { Assert.assertEquals(manyToOne.getValue().getAttributeValue("stringAttr"), data.getFieldValue(many2OneString)); } else { Assert.assertEquals(null, data.getFieldValue(many2OneString)); } } }
private void init(JasperDesign jasperDesign) throws DRException { Validate.notNull(jasperDesign, "jasperDesign must not be null"); this.jasperDesign = jasperDesign; this.fields = new ArrayList<DRIField<?>>(); for (JRField jrField : jasperDesign.getFields()) { @SuppressWarnings({ "unchecked", "rawtypes" }) DRField<?> field = new DRField(jrField.getName(), jrField.getValueClass()); fields.add(field); } this.margin = new DRMargin(); margin.setTop(jasperDesign.getTopMargin()); margin.setLeft(jasperDesign.getLeftMargin()); margin.setBottom(jasperDesign.getBottomMargin()); margin.setRight(jasperDesign.getRightMargin()); }